fix(registry): evaluate defaultCacheDirectory lazily - #41942
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| let _defaultCacheDirectory: string | undefined; | ||
|
|
||
| export const defaultRegistryDirectory = path.join(defaultCacheDirectory, 'ms-playwright'); | ||
| // Evaluated lazily so an explicit PLAYWRIGHT_BROWSERS_PATH lets Playwright run on |
There was a problem hiding this comment.
Please drop all these useless comments!
Pavel Feldman (pavelfeldman)
left a comment
There was a problem hiding this comment.
Let's strip the useless comments.
`defaultCacheDirectory` used to be computed inside the `PLAYWRIGHT_BROWSERS_PATH` branch of `registryDirectory`, so setting that variable skipped the platform check a later refactor hoisted it into an eagerly evaluated module constant, so it now throws `Unsupported platform: <platform>` at import, before `registryDirectory` consults `PLAYWRIGHT_BROWSERS_PATH` this regressed setups that point `PLAYWRIGHT_BROWSERS_PATH` at their own browsers on platforms without a default cache directory, such as Android/Termux evaluate `defaultCacheDirectory`, `defaultRegistryDirectory`, and `baseDaemonDir` lazily so an explicit `PLAYWRIGHT_BROWSERS_PATH` is honored before any default cache directory is computed `registryDirectory` still throws eagerly when no override is set, since there is nowhere to place browsers
a444544 to
4af292d
Compare
Test results for "tests 1"5 flaky50308 passed, 1190 skipped Merge workflow run. |
Test results for "MCP"1 failed 7794 passed, 1266 skipped Merge workflow run. |
|
Hi, I'm the Playwright bot and I took a first look at the CI failures here. 🟢 The one failure is a pre-existing flake — the PR looks clear
DetailsPre-existing flake / infra
The diff is confined to browser cache-directory resolution — Triaged by the Playwright bot - agent run |
3e14efd
into
microsoft:main
|
Why this not updated in npm |
`registry.defaultRegistryDirectory` became a function upstream in microsoft/playwright#41942 and arrived here with the roll to 1.63.0-alpha-2026-08-05. `cacheFile()` still used it as a string, so `path.join()` threw, `readCache()`/`writeCache()` swallowed the TypeError, and the update check was never cached: every single CLI invocation fetched the npm registry and re-ran the installed-skill check. Locally that is ~480ms per command instead of ~125ms. Tests always set PLAYWRIGHT_CLI_INSTALLATION_FOR_TEST, so the default branch was never exercised. Add a regression test that points HOME at a temp directory and asserts the cache file is written. Also hoist `cacheFile()` out of the try blocks so only I/O and parse failures are swallowed there, instead of masking a path-computation bug as "no cache".
…le (#454) `registry.defaultRegistryDirectory` became a function upstream in microsoft/playwright#41942 and arrived here with the roll to 1.63.0-alpha-2026-08-05. `cacheFile()` still used it as a string, so `path.join()` threw, `readCache()`/`writeCache()` swallowed the TypeError, and the update check was never cached: every single CLI invocation fetched the npm registry and re-ran the installed-skill check. Locally that is ~480ms per command instead of ~125ms. Tests always set PLAYWRIGHT_CLI_INSTALLATION_FOR_TEST, so the default branch was never exercised. Add a regression test that points HOME at a temp directory and asserts the cache file is written. Also hoist `cacheFile()` out of the try blocks so only I/O and parse failures are swallowed there, instead of masking a path-computation bug as "no cache".
defaultCacheDirectoryused to be computed inside thePLAYWRIGHT_BROWSERS_PATHbranch ofregistryDirectory, so setting that variable skipped the platform check#39423 hoisted it into an eagerly evaluated module constant, so it now throws
Unsupported platform: <platform>at import, beforeregistryDirectoryconsultsPLAYWRIGHT_BROWSERS_PATHthis regressed setups that point
PLAYWRIGHT_BROWSERS_PATHat their own browsers on platforms without a default cache directory, such as Android/Termuxevaluate
defaultCacheDirectory,defaultRegistryDirectory, andbaseDaemonDirlazily so an explicitPLAYWRIGHT_BROWSERS_PATHis honored before any default cache directory is computedregistryDirectorystill throws eagerly when no override is set, since there is nowhere to place browsersfixes #41852