1 | #!/usr/bin/env node
|
---|
2 | var __create = Object.create;
|
---|
3 | var __defProp = Object.defineProperty;
|
---|
4 | var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
---|
5 | var __getOwnPropNames = Object.getOwnPropertyNames;
|
---|
6 | var __getProtoOf = Object.getPrototypeOf;
|
---|
7 | var __hasOwnProp = Object.prototype.hasOwnProperty;
|
---|
8 | var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
---|
9 | var __reExport = (target, module2, desc) => {
|
---|
10 | if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
---|
11 | for (let key of __getOwnPropNames(module2))
|
---|
12 | if (!__hasOwnProp.call(target, key) && key !== "default")
|
---|
13 | __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
---|
14 | }
|
---|
15 | return target;
|
---|
16 | };
|
---|
17 | var __toModule = (module2) => {
|
---|
18 | return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
---|
19 | };
|
---|
20 |
|
---|
21 | // lib/npm/node-platform.ts
|
---|
22 | var fs = require("fs");
|
---|
23 | var os = require("os");
|
---|
24 | var path = require("path");
|
---|
25 | var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
|
---|
26 | var knownWindowsPackages = {
|
---|
27 | "win32 arm64 LE": "esbuild-windows-arm64",
|
---|
28 | "win32 ia32 LE": "esbuild-windows-32",
|
---|
29 | "win32 x64 LE": "esbuild-windows-64"
|
---|
30 | };
|
---|
31 | var knownUnixlikePackages = {
|
---|
32 | "android arm64 LE": "esbuild-android-arm64",
|
---|
33 | "darwin arm64 LE": "esbuild-darwin-arm64",
|
---|
34 | "darwin x64 LE": "esbuild-darwin-64",
|
---|
35 | "freebsd arm64 LE": "esbuild-freebsd-arm64",
|
---|
36 | "freebsd x64 LE": "esbuild-freebsd-64",
|
---|
37 | "linux arm LE": "esbuild-linux-arm",
|
---|
38 | "linux arm64 LE": "esbuild-linux-arm64",
|
---|
39 | "linux ia32 LE": "esbuild-linux-32",
|
---|
40 | "linux mips64el LE": "esbuild-linux-mips64le",
|
---|
41 | "linux ppc64 LE": "esbuild-linux-ppc64le",
|
---|
42 | "linux x64 LE": "esbuild-linux-64",
|
---|
43 | "netbsd x64 LE": "esbuild-netbsd-64",
|
---|
44 | "openbsd x64 LE": "esbuild-openbsd-64",
|
---|
45 | "sunos x64 LE": "esbuild-sunos-64"
|
---|
46 | };
|
---|
47 | function pkgAndSubpathForCurrentPlatform() {
|
---|
48 | let pkg;
|
---|
49 | let subpath;
|
---|
50 | let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
|
---|
51 | if (platformKey in knownWindowsPackages) {
|
---|
52 | pkg = knownWindowsPackages[platformKey];
|
---|
53 | subpath = "esbuild.exe";
|
---|
54 | } else if (platformKey in knownUnixlikePackages) {
|
---|
55 | pkg = knownUnixlikePackages[platformKey];
|
---|
56 | subpath = "bin/esbuild";
|
---|
57 | } else {
|
---|
58 | throw new Error(`Unsupported platform: ${platformKey}`);
|
---|
59 | }
|
---|
60 | return { pkg, subpath };
|
---|
61 | }
|
---|
62 | function downloadedBinPath(pkg, subpath) {
|
---|
63 | const esbuildLibDir = path.dirname(require.resolve("esbuild"));
|
---|
64 | return path.join(esbuildLibDir, `downloaded-${pkg}-${path.basename(subpath)}`);
|
---|
65 | }
|
---|
66 | function generateBinPath() {
|
---|
67 | if (ESBUILD_BINARY_PATH) {
|
---|
68 | return ESBUILD_BINARY_PATH;
|
---|
69 | }
|
---|
70 | const { pkg, subpath } = pkgAndSubpathForCurrentPlatform();
|
---|
71 | let binPath;
|
---|
72 | try {
|
---|
73 | binPath = require.resolve(`${pkg}/${subpath}`);
|
---|
74 | } catch (e) {
|
---|
75 | binPath = downloadedBinPath(pkg, subpath);
|
---|
76 | if (!fs.existsSync(binPath)) {
|
---|
77 | try {
|
---|
78 | require.resolve(pkg);
|
---|
79 | } catch (e2) {
|
---|
80 | throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild.
|
---|
81 |
|
---|
82 | If you are installing esbuild with npm, make sure that you don't specify the
|
---|
83 | "--no-optional" flag. The "optionalDependencies" package.json feature is used
|
---|
84 | by esbuild to install the correct binary executable for your current platform.`);
|
---|
85 | }
|
---|
86 | throw e;
|
---|
87 | }
|
---|
88 | }
|
---|
89 | let isYarnPnP = false;
|
---|
90 | try {
|
---|
91 | require("pnpapi");
|
---|
92 | isYarnPnP = true;
|
---|
93 | } catch (e) {
|
---|
94 | }
|
---|
95 | if (isYarnPnP) {
|
---|
96 | const esbuildLibDir = path.dirname(require.resolve("esbuild"));
|
---|
97 | const binTargetPath = path.join(esbuildLibDir, `pnpapi-${pkg}-${path.basename(subpath)}`);
|
---|
98 | if (!fs.existsSync(binTargetPath)) {
|
---|
99 | fs.copyFileSync(binPath, binTargetPath);
|
---|
100 | fs.chmodSync(binTargetPath, 493);
|
---|
101 | }
|
---|
102 | return binTargetPath;
|
---|
103 | }
|
---|
104 | return binPath;
|
---|
105 | }
|
---|
106 |
|
---|
107 | // lib/npm/node-shim.ts
|
---|
108 | require("child_process").execFileSync(generateBinPath(), process.argv.slice(2), { stdio: "inherit" });
|
---|