@@ -7,7 +7,7 @@ import zlib = require('zlib')
7
7
import https = require( 'https' )
8
8
import child_process = require( 'child_process' )
9
9
10
- declare const ESBUILD_VERSION : string
10
+ const versionFromPackageJSON : string = require ( path . join ( __dirname , 'package.json' ) ) . version
11
11
const toPath = path . join ( __dirname , 'bin' , 'esbuild' )
12
12
let isToPathJS = true
13
13
@@ -48,8 +48,8 @@ which means the "esbuild" binary executable can't be run. You can either:
48
48
}
49
49
throw err
50
50
}
51
- if ( stdout !== ESBUILD_VERSION ) {
52
- throw new Error ( `Expected ${ JSON . stringify ( ESBUILD_VERSION ) } but got ${ JSON . stringify ( stdout ) } ` )
51
+ if ( stdout !== versionFromPackageJSON ) {
52
+ throw new Error ( `Expected ${ JSON . stringify ( versionFromPackageJSON ) } but got ${ JSON . stringify ( stdout ) } ` )
53
53
}
54
54
}
55
55
@@ -115,7 +115,7 @@ function installUsingNPM(pkg: string, subpath: string, binPath: string): void {
115
115
// command instead of a HTTP request so that it hopefully works in situations
116
116
// where HTTP requests are blocked but the "npm" command still works due to,
117
117
// for example, a custom configured npm registry and special firewall rules.
118
- child_process . execSync ( `npm install --loglevel=error --prefer-offline --no-audit --progress=false ${ pkg } @${ ESBUILD_VERSION } ` ,
118
+ child_process . execSync ( `npm install --loglevel=error --prefer-offline --no-audit --progress=false ${ pkg } @${ versionFromPackageJSON } ` ,
119
119
{ cwd : installDir , stdio : 'pipe' , env } )
120
120
121
121
// Move the downloaded binary executable into place. The destination path
@@ -218,7 +218,7 @@ function maybeOptimizePackage(binPath: string): void {
218
218
async function downloadDirectlyFromNPM ( pkg : string , subpath : string , binPath : string ) : Promise < void > {
219
219
// If that fails, the user could have npm configured incorrectly or could not
220
220
// have npm installed. Try downloading directly from npm as a last resort.
221
- const url = `https://registry.npmjs.org/${ pkg } /-/${ pkg . replace ( '@esbuild/' , '' ) } -${ ESBUILD_VERSION } .tgz`
221
+ const url = `https://registry.npmjs.org/${ pkg } /-/${ pkg . replace ( '@esbuild/' , '' ) } -${ versionFromPackageJSON } .tgz`
222
222
console . error ( `[esbuild] Trying to download ${ JSON . stringify ( url ) } ` )
223
223
try {
224
224
fs . writeFileSync ( binPath , extractFileFromTarGzip ( await fetch ( url ) , subpath ) )
0 commit comments