Skip to content

Commit cab83c9

Browse files
committed
no optimizations with yarn 1 just in case (#1656)
1 parent 695ddb9 commit cab83c9

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/npm/node-install.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@ function validateBinaryVersion(...command: string[]): void {
1919
}
2020
}
2121

22-
function isYarn2OrAbove(): boolean {
22+
function isYarn(): boolean {
2323
const { npm_config_user_agent } = process.env;
2424
if (npm_config_user_agent) {
25-
const match = npm_config_user_agent.match(/yarn\/(\d+)/);
26-
if (match && match[1]) {
27-
return parseInt(match[1], 10) >= 2;
28-
}
25+
return /\byarn\//.test(npm_config_user_agent);
2926
}
3027
return false;
3128
}
@@ -146,12 +143,17 @@ function maybeOptimizePackage(binPath: string): void {
146143
// Here we optimize for this by replacing the JavaScript file with the binary
147144
// executable at install time. This optimization does not work on Windows
148145
// because on Windows the binary executable must be called "esbuild.exe"
149-
// instead of "esbuild". This also doesn't work with Yarn 2+ because the Yarn
150-
// developers don't think binary modules should be used. See this thread for
151-
// details: https://github.com/yarnpkg/berry/issues/882. This optimization also
152-
// doesn't apply when npm's "--ignore-scripts" flag is used since in that case
153-
// this install script will not be run.
154-
if (os.platform() !== 'win32' && !isYarn2OrAbove()) {
146+
// instead of "esbuild".
147+
//
148+
// This also doesn't work with Yarn both because of lack of support for binary
149+
// files in Yarn 2+ (see https://github.com/yarnpkg/berry/issues/882) and
150+
// because Yarn (even Yarn 1?) may run the same install scripts in the same
151+
// place multiple times from different platforms, especially when people use
152+
// Docker. Avoid idempotency issues by just not optimizing when using Yarn.
153+
//
154+
// This optimization also doesn't apply when npm's "--ignore-scripts" flag is
155+
// used since in that case this install script will not be run.
156+
if (os.platform() !== 'win32' && !isYarn()) {
155157
const tempPath = path.join(__dirname, 'bin-esbuild');
156158
try {
157159
// First link the binary with a temporary file. If this fails and throws an

0 commit comments

Comments
 (0)