Skip to content

Commit 3f51381

Browse files
committed
fix #2964: install script reads version from file
1 parent 1978946 commit 3f51381

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/npm/node-install.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import zlib = require('zlib')
77
import https = require('https')
88
import child_process = require('child_process')
99

10-
declare const ESBUILD_VERSION: string
10+
const versionFromPackageJSON: string = require(path.join(__dirname, 'package.json')).version
1111
const toPath = path.join(__dirname, 'bin', 'esbuild')
1212
let 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 {
218218
async 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))

scripts/esbuild.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const childProcess = require('child_process')
22
const path = require('path')
3-
const zlib = require('zlib')
43
const fs = require('fs')
54
const os = require('os')
65

@@ -24,7 +23,11 @@ const buildNeutralLib = (esbuildPath) => {
2423
'--outfile=' + path.join(npmDir, 'install.js'),
2524
'--bundle',
2625
'--target=' + nodeTarget,
27-
'--define:ESBUILD_VERSION=' + JSON.stringify(version),
26+
// Note: https://socket.dev have complained that inlining the version into
27+
// the install script messes up some internal scanning that they do by
28+
// making it seem like esbuild's install script code changes with every
29+
// esbuild release. So now we read it from "package.json" instead.
30+
// '--define:ESBUILD_VERSION=' + JSON.stringify(version),
2831
'--external:esbuild',
2932
'--platform=node',
3033
'--log-level=warning',

0 commit comments

Comments
 (0)