From 56aac9a9147e159f07fec0c01eb3750f224fe37b Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Fri, 4 Dec 2020 23:29:33 -0800 Subject: [PATCH] more helpful error if rosetta 2 is missing (#564) --- lib/install.ts | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/install.ts b/lib/install.ts index 6910b4b0418..4499823212b 100644 --- a/lib/install.ts +++ b/lib/install.ts @@ -83,7 +83,20 @@ async function installBinaryFromPackage(name: string, fromPath: string, toPath: } function validateBinaryVersion(binaryPath: string): void { - const stdout = child_process.execFileSync(binaryPath, ['--version']).toString().trim(); + let stdout; + try { + stdout = child_process.execFileSync(binaryPath, ['--version']).toString().trim(); + } catch (err) { + if (platformKey === 'darwin arm64 LE') + throw new Error(`${err && err.message || err} + +This install script is trying to install the x64 esbuild executable because the +arm64 esbuild executable is not available yet. Running this executable requires +the Rosetta 2 binary translator. Please make sure you have Rosetta 2 installed +before installing esbuild. +`); + throw err; + } if (stdout !== version) { throw new Error(`Expected ${JSON.stringify(version)} but got ${JSON.stringify(stdout)}`); } @@ -212,6 +225,7 @@ function installDirectly(name: string) { if (process.env.ESBUILD_BIN_PATH_FOR_TESTS) { fs.unlinkSync(binPath); fs.symlinkSync(process.env.ESBUILD_BIN_PATH_FOR_TESTS, binPath); + validateBinaryVersion(process.env.ESBUILD_BIN_PATH_FOR_TESTS); } else { installBinaryFromPackage(name, 'bin/esbuild', binPath) .catch(e => setImmediate(() => { throw e; })); @@ -231,6 +245,7 @@ process.exitCode = status === null ? 1 : status; const absToPath = path.join(__dirname, toPath); if (process.env.ESBUILD_BIN_PATH_FOR_TESTS) { fs.copyFileSync(process.env.ESBUILD_BIN_PATH_FOR_TESTS, absToPath); + validateBinaryVersion(process.env.ESBUILD_BIN_PATH_FOR_TESTS); } else { installBinaryFromPackage(name, fromPath, absToPath) .catch(e => setImmediate(() => { throw e; })); @@ -258,7 +273,7 @@ function installOnWindows(name: string): void { installWithWrapper(name, "esbuild.exe", "esbuild.exe"); } -const key = `${process.platform} ${os.arch()} ${os.endianness()}`; +const platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`; const knownWindowsPackages: Record = { 'win32 ia32 LE': 'esbuild-windows-32', 'win32 x64 LE': 'esbuild-windows-64', @@ -276,11 +291,11 @@ const knownUnixlikePackages: Record = { }; // Pick a package to install -if (key in knownWindowsPackages) { - installOnWindows(knownWindowsPackages[key]); -} else if (key in knownUnixlikePackages) { - installOnUnix(knownUnixlikePackages[key]); +if (platformKey in knownWindowsPackages) { + installOnWindows(knownWindowsPackages[platformKey]); +} else if (platformKey in knownUnixlikePackages) { + installOnUnix(knownUnixlikePackages[platformKey]); } else { - console.error(`Unsupported platform: ${key}`); + console.error(`Unsupported platform: ${platformKey}`); process.exit(1); }