| #!/usr/bin/env node |
| var __create = Object.create; |
| var __defProp = Object.defineProperty; |
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
| var __getOwnPropNames = Object.getOwnPropertyNames; |
| var __getProtoOf = Object.getPrototypeOf; |
| var __hasOwnProp = Object.prototype.hasOwnProperty; |
| var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); |
| var __reExport = (target, module2, copyDefault, desc) => { |
| if (module2 && typeof module2 === "object" || typeof module2 === "function") { |
| for (let key of __getOwnPropNames(module2)) |
| if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default")) |
| __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable }); |
| } |
| return target; |
| }; |
| var __toESM = (module2, isNodeMode) => { |
| return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2); |
| }; |
| |
| // lib/npm/node-platform.ts |
| var fs = require("fs"); |
| var os = require("os"); |
| var path = require("path"); |
| var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH; |
| var knownWindowsPackages = { |
| "win32 arm64 LE": "esbuild-windows-arm64", |
| "win32 ia32 LE": "esbuild-windows-32", |
| "win32 x64 LE": "esbuild-windows-64" |
| }; |
| var knownUnixlikePackages = { |
| "android arm64 LE": "esbuild-android-arm64", |
| "darwin arm64 LE": "esbuild-darwin-arm64", |
| "darwin x64 LE": "esbuild-darwin-64", |
| "freebsd arm64 LE": "esbuild-freebsd-arm64", |
| "freebsd x64 LE": "esbuild-freebsd-64", |
| "linux arm LE": "esbuild-linux-arm", |
| "linux arm64 LE": "esbuild-linux-arm64", |
| "linux ia32 LE": "esbuild-linux-32", |
| "linux mips64el LE": "esbuild-linux-mips64le", |
| "linux ppc64 LE": "esbuild-linux-ppc64le", |
| "linux s390x BE": "esbuild-linux-s390x", |
| "linux x64 LE": "esbuild-linux-64", |
| "netbsd x64 LE": "esbuild-netbsd-64", |
| "openbsd x64 LE": "esbuild-openbsd-64", |
| "sunos x64 LE": "esbuild-sunos-64" |
| }; |
| function pkgAndSubpathForCurrentPlatform() { |
| let pkg; |
| let subpath; |
| let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`; |
| if (platformKey in knownWindowsPackages) { |
| pkg = knownWindowsPackages[platformKey]; |
| subpath = "esbuild.exe"; |
| } else if (platformKey in knownUnixlikePackages) { |
| pkg = knownUnixlikePackages[platformKey]; |
| subpath = "bin/esbuild"; |
| } else { |
| throw new Error(`Unsupported platform: ${platformKey}`); |
| } |
| return { pkg, subpath }; |
| } |
| function pkgForSomeOtherPlatform() { |
| const libMainJS = require.resolve("esbuild"); |
| const nodeModulesDirectory = path.dirname(path.dirname(path.dirname(libMainJS))); |
| if (path.basename(nodeModulesDirectory) === "node_modules") { |
| for (const unixKey in knownUnixlikePackages) { |
| try { |
| const pkg = knownUnixlikePackages[unixKey]; |
| if (fs.existsSync(path.join(nodeModulesDirectory, pkg))) |
| return pkg; |
| } catch { |
| } |
| } |
| for (const windowsKey in knownWindowsPackages) { |
| try { |
| const pkg = knownWindowsPackages[windowsKey]; |
| if (fs.existsSync(path.join(nodeModulesDirectory, pkg))) |
| return pkg; |
| } catch { |
| } |
| } |
| } |
| return null; |
| } |
| function downloadedBinPath(pkg, subpath) { |
| const esbuildLibDir = path.dirname(require.resolve("esbuild")); |
| return path.join(esbuildLibDir, `downloaded-${pkg}-${path.basename(subpath)}`); |
| } |
| function generateBinPath() { |
| if (ESBUILD_BINARY_PATH) { |
| return ESBUILD_BINARY_PATH; |
| } |
| const { pkg, subpath } = pkgAndSubpathForCurrentPlatform(); |
| let binPath; |
| try { |
| binPath = require.resolve(`${pkg}/${subpath}`); |
| } catch (e) { |
| binPath = downloadedBinPath(pkg, subpath); |
| if (!fs.existsSync(binPath)) { |
| try { |
| require.resolve(pkg); |
| } catch { |
| const otherPkg = pkgForSomeOtherPlatform(); |
| if (otherPkg) { |
| throw new Error(` |
| You installed esbuild on another platform than the one you're currently using. |
| This won't work because esbuild is written with native code and needs to |
| install a platform-specific binary executable. |
| |
| Specifically the "${otherPkg}" package is present but this platform |
| needs the "${pkg}" package instead. People often get into this |
| situation by installing esbuild on Windows or macOS and copying "node_modules" |
| into a Docker image that runs Linux, or by copying "node_modules" between |
| Windows and WSL environments. |
| |
| If you are installing with npm, you can try not copying the "node_modules" |
| directory when you copy the files over, and running "npm ci" or "npm install" |
| on the destination platform after the copy. Or you could consider using yarn |
| instead which has built-in support for installing a package on multiple |
| platforms simultaneously. |
| |
| If you are installing with yarn, you can try listing both this platform and the |
| other platform in your ".yarnrc.yml" file using the "supportedArchitectures" |
| feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures |
| Keep in mind that this means multiple copies of esbuild will be present. |
| |
| Another alternative is to use the "esbuild-wasm" package instead, which works |
| the same way on all platforms. But it comes with a heavy performance cost and |
| can sometimes be 10x slower than the "esbuild" package, so you may also not |
| want to do that. |
| `); |
| } |
| throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild. |
| |
| If you are installing esbuild with npm, make sure that you don't specify the |
| "--no-optional" flag. The "optionalDependencies" package.json feature is used |
| by esbuild to install the correct binary executable for your current platform.`); |
| } |
| throw e; |
| } |
| } |
| let isYarnPnP = false; |
| try { |
| require("pnpapi"); |
| isYarnPnP = true; |
| } catch (e) { |
| } |
| if (isYarnPnP) { |
| const esbuildLibDir = path.dirname(require.resolve("esbuild")); |
| const binTargetPath = path.join(esbuildLibDir, `pnpapi-${pkg}-${path.basename(subpath)}`); |
| if (!fs.existsSync(binTargetPath)) { |
| fs.copyFileSync(binPath, binTargetPath); |
| fs.chmodSync(binTargetPath, 493); |
| } |
| return binTargetPath; |
| } |
| return binPath; |
| } |
| |
| // lib/npm/node-shim.ts |
| require("child_process").execFileSync(generateBinPath(), process.argv.slice(2), { stdio: "inherit" }); |