@@ -7,7 +7,7 @@ import zlib = require('zlib')
77import https = require( 'https' )
88import child_process = require( 'child_process' )
99
10- declare const ESBUILD_VERSION : string
10+ const versionFromPackageJSON : string = require ( path . join ( __dirname , 'package.json' ) ) . version
1111const toPath = path . join ( __dirname , 'bin' , 'esbuild' )
1212let isToPathJS = true
1313
@@ -48,8 +48,8 @@ which means the "esbuild" binary executable can't be run. You can either:
4848 }
4949 throw err
5050 }
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 ) } ` )
5353 }
5454}
5555
@@ -115,7 +115,7 @@ function installUsingNPM(pkg: string, subpath: string, binPath: string): void {
115115 // command instead of a HTTP request so that it hopefully works in situations
116116 // where HTTP requests are blocked but the "npm" command still works due to,
117117 // 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 } ` ,
119119 { cwd : installDir , stdio : 'pipe' , env } )
120120
121121 // Move the downloaded binary executable into place. The destination path
@@ -218,7 +218,7 @@ function maybeOptimizePackage(binPath: string): void {
218218async function downloadDirectlyFromNPM ( pkg : string , subpath : string , binPath : string ) : Promise < void > {
219219 // If that fails, the user could have npm configured incorrectly or could not
220220 // 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`
222222 console . error ( `[esbuild] Trying to download ${ JSON . stringify ( url ) } ` )
223223 try {
224224 fs . writeFileSync ( binPath , extractFileFromTarGzip ( await fetch ( url ) , subpath ) )
0 commit comments