Revert "chore: opt-out of installation lock by default (#35436)" (#35577)

This commit is contained in:
Max Schmitt 2025-04-10 15:35:24 +01:00 committed by GitHub
parent 51a7b8f27f
commit c5b3bf1d8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1018,12 +1018,10 @@ export class Registry {
}
async install(executablesToInstall: Executable[], forceReinstall: boolean) {
if (!process.env.PLAYWRIGHT_USE_INSTALLATION_LOCK)
return await this._installImpl(executablesToInstall, forceReinstall);
// TODO: Remove the following if we have confidence that we don't need the lock anymore.
const executables = this._dedupe(executablesToInstall);
await fs.promises.mkdir(registryDirectory, { recursive: true });
const lockfilePath = path.join(registryDirectory, '__dirlock');
const linksDir = path.join(registryDirectory, '.links');
let releaseLock;
try {
@ -1040,37 +1038,6 @@ export class Registry {
},
lockfilePath,
});
await this._installImpl(executablesToInstall, forceReinstall);
} catch (e) {
if (e.code === 'ELOCKED') {
const rmCommand = process.platform === 'win32' ? 'rm -R' : 'rm -rf';
throw new Error('\n' + wrapInASCIIBox([
`An active lockfile is found at:`,
``,
` ${lockfilePath}`,
``,
`Either:`,
`- wait a few minutes if other Playwright is installing browsers in parallel`,
`- remove lock manually with:`,
``,
` ${rmCommand} ${lockfilePath}`,
``,
`<3 Playwright Team`,
].join('\n'), 1));
} else {
throw e;
}
} finally {
if (releaseLock)
await releaseLock();
}
}
async _installImpl(executablesToInstall: Executable[], forceReinstall: boolean) {
const executables = this._dedupe(executablesToInstall);
await fs.promises.mkdir(registryDirectory, { recursive: true });
const linksDir = path.join(registryDirectory, '.links');
// Create a link first, so that cache validation does not remove our own browsers.
await fs.promises.mkdir(linksDir, { recursive: true });
await fs.promises.writeFile(path.join(linksDir, calculateSha1(PACKAGE_PATH)), PACKAGE_PATH);
@ -1104,6 +1071,29 @@ export class Registry {
}
await executable._install();
}
} catch (e) {
if (e.code === 'ELOCKED') {
const rmCommand = process.platform === 'win32' ? 'rm -R' : 'rm -rf';
throw new Error('\n' + wrapInASCIIBox([
`An active lockfile is found at:`,
``,
` ${lockfilePath}`,
``,
`Either:`,
`- wait a few minutes if other Playwright is installing browsers in parallel`,
`- remove lock manually with:`,
``,
` ${rmCommand} ${lockfilePath}`,
``,
`<3 Playwright Team`,
].join('\n'), 1));
} else {
throw e;
}
} finally {
if (releaseLock)
await releaseLock();
}
}
async uninstall(all: boolean): Promise<{ numberOfBrowsersLeft: number }> {