@@ -19,13 +19,10 @@ function validateBinaryVersion(...command: string[]): void {
19
19
}
20
20
}
21
21
22
- function isYarn2OrAbove ( ) : boolean {
22
+ function isYarn ( ) : boolean {
23
23
const { npm_config_user_agent } = process . env ;
24
24
if ( npm_config_user_agent ) {
25
- const match = npm_config_user_agent . match ( / y a r n \/ ( \d + ) / ) ;
26
- if ( match && match [ 1 ] ) {
27
- return parseInt ( match [ 1 ] , 10 ) >= 2 ;
28
- }
25
+ return / \b y a r n \/ / . test ( npm_config_user_agent ) ;
29
26
}
30
27
return false ;
31
28
}
@@ -146,12 +143,17 @@ function maybeOptimizePackage(binPath: string): void {
146
143
// Here we optimize for this by replacing the JavaScript file with the binary
147
144
// executable at install time. This optimization does not work on Windows
148
145
// 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 ( ) ) {
155
157
const tempPath = path . join ( __dirname , 'bin-esbuild' ) ;
156
158
try {
157
159
// First link the binary with a temporary file. If this fails and throws an
0 commit comments