Skip to content

Commit

Permalink
build: update install scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ArrayZoneYour committed May 4, 2023
1 parent c691ba4 commit 6970633
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/npm/node-install.ts
Expand Up @@ -104,7 +104,7 @@ function installUsingNPM(pkg: string, subpath: string, binPath: string): void {

// Create a temporary directory inside the "esbuild" package with an empty
// "package.json" file. We'll use this to run "npm install" in.
const esbuildLibDir = path.dirname(require.resolve('esbuild'))
const esbuildLibDir = path.dirname(require.resolve('@speedy-js/esbuild'))
const installDir = path.join(esbuildLibDir, 'npm-install')
fs.mkdirSync(installDir)
try {
Expand Down Expand Up @@ -218,7 +218,7 @@ function maybeOptimizePackage(binPath: string): void {
async function downloadDirectlyFromNPM(pkg: string, subpath: string, binPath: string): Promise<void> {
// If that fails, the user could have npm configured incorrectly or could not
// have npm installed. Try downloading directly from npm as a last resort.
const url = `https://registry.npmjs.org/${pkg}/-/${pkg.replace('@esbuild/', '')}-${versionFromPackageJSON}.tgz`
const url = `https://registry.npmjs.org/${pkg}/-/${pkg.replace('@speedy-js/esbuild/', '')}-${versionFromPackageJSON}.tgz`
console.error(`[esbuild] Trying to download ${JSON.stringify(url)}`)
try {
fs.writeFileSync(binPath, extractFileFromTarGzip(await fetch(url), subpath))
Expand Down Expand Up @@ -248,7 +248,7 @@ async function checkAndPreparePackage(): Promise<void> {
try {
// First check for the binary package from our "optionalDependencies". This
// package should have been installed alongside this package at install time.
binPath = require.resolve(`${pkg.replace('@esbuild', '@speedy-js/esbuild')}/${subpath}`)
binPath = require.resolve(`${pkg.replace('@esbuild', '@speedy-js/esbuild')}-${subpath}`)
} catch (e) {
console.error(`[esbuild] Failed to find package "${pkg}" on the file system
Expand Down
4 changes: 2 additions & 2 deletions lib/npm/node-platform.ts
Expand Up @@ -105,7 +105,7 @@ function pkgForSomeOtherPlatform(): string | null {
}

export function downloadedBinPath(pkg: string, subpath: string): string {
const esbuildLibDir = path.dirname(require.resolve('esbuild'))
const esbuildLibDir = path.dirname(require.resolve('@speedy-js/esbuild'))
return path.join(esbuildLibDir, `downloaded-${pkg.replace('/', '-')}-${path.basename(subpath)}`)
}

Expand All @@ -127,7 +127,7 @@ export function generateBinPath(): { binPath: string, isWASM: boolean } {
try {
// First check for the binary package from our "optionalDependencies". This
// package should have been installed alongside this package at install time.
binPath = require.resolve(`${pkg.replace('@esbuild', '@speedy-js/esbuild')}/${subpath}`)
binPath = require.resolve(`${pkg.replace('@esbuild', '@speedy-js/esbuild')}-${subpath}`)
} catch (e) {
// If that didn't work, then someone probably installed esbuild with the
// "--no-optional" flag. Our install script attempts to compensate for this
Expand Down
10 changes: 5 additions & 5 deletions scripts/esbuild.js
Expand Up @@ -28,7 +28,7 @@ const buildNeutralLib = (esbuildPath) => {
// making it seem like esbuild's install script code changes with every
// esbuild release. So now we read it from "package.json" instead.
// '--define:ESBUILD_VERSION=' + JSON.stringify(version),
'--external:esbuild',
'--external:@speedy-js/esbuild,esbuild',
'--platform=node',
'--log-level=warning',
], { cwd: repoDir })
Expand All @@ -41,7 +41,7 @@ const buildNeutralLib = (esbuildPath) => {
'--target=' + nodeTarget,
'--define:WASM=false',
'--define:ESBUILD_VERSION=' + JSON.stringify(version),
'--external:esbuild',
'--external:@speedy-js/esbuild,esbuild',
'--platform=node',
'--log-level=warning',
], { cwd: repoDir })
Expand Down Expand Up @@ -76,7 +76,7 @@ const buildNeutralLib = (esbuildPath) => {
...platforms.exports.knownWindowsPackages,
...platforms.exports.knownUnixlikePackages,
...platforms.exports.knownWebAssemblyFallbackPackages,
}).sort().map(x => [x, version]))
}).sort().map(x => [x.replace('@esbuild/', '@speedy-js/esbuild-'), version]))

// Update "npm/esbuild/package.json"
const pjPath = path.join(npmDir, 'package.json')
Expand Down Expand Up @@ -329,10 +329,10 @@ exports.installForTests = () => {
fs.mkdirSync(installDir)
fs.writeFileSync(path.join(installDir, 'package.json'), '{}')
childProcess.execSync(`npm pack --silent "${npmDir}"`, { cwd: installDir, stdio: 'inherit' })
childProcess.execSync(`npm install --silent --no-audit --no-optional --progress=false esbuild-${version}.tgz`, { cwd: installDir, env, stdio: 'inherit' })
childProcess.execSync(`npm install --silent --no-audit --no-optional --progress=false speedy-js-esbuild-${version}.tgz`, { cwd: installDir, env, stdio: 'inherit' })

// Evaluate the code
const ESBUILD_PACKAGE_PATH = path.join(installDir, 'node_modules', 'esbuild')
const ESBUILD_PACKAGE_PATH = path.join(installDir, 'node_modules', '@speedy-js/esbuild')
const mod = require(ESBUILD_PACKAGE_PATH)
Object.defineProperty(mod, 'ESBUILD_PACKAGE_PATH', { value: ESBUILD_PACKAGE_PATH })
return mod
Expand Down

0 comments on commit 6970633

Please sign in to comment.