jiek 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. package/bin/jiek-dev.js +4 -0
  2. package/bin/jiek.js +2 -0
  3. package/dist/commands/build.esm.js +68 -0
  4. package/dist/commands/build.esm.js.map +1 -0
  5. package/dist/commands/build.esm.min.js +2 -0
  6. package/dist/commands/build.esm.min.js.map +1 -0
  7. package/dist/commands/publish.esm.js +60 -0
  8. package/dist/commands/publish.esm.js.map +1 -0
  9. package/dist/commands/publish.esm.min.js +2 -0
  10. package/dist/commands/publish.esm.min.js.map +1 -0
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.esm.d.ts +2 -0
  13. package/dist/index.esm.js +6 -0
  14. package/dist/index.esm.js.map +1 -0
  15. package/dist/index.esm.min.js +2 -0
  16. package/dist/index.esm.min.js.map +1 -0
  17. package/dist/index.iife.js +155 -0
  18. package/dist/index.iife.js.map +1 -0
  19. package/dist/index.iife.min.js +2 -0
  20. package/dist/index.iife.min.js.map +1 -0
  21. package/dist/index.umd.js +158 -0
  22. package/dist/index.umd.js.map +1 -0
  23. package/dist/index.umd.min.js +2 -0
  24. package/dist/index.umd.min.js.map +1 -0
  25. package/dist/inner.esm.js +10 -0
  26. package/dist/inner.esm.js.map +1 -0
  27. package/dist/inner.esm.min.js +2 -0
  28. package/dist/inner.esm.min.js.map +1 -0
  29. package/dist/merge-package-json.esm.js +16 -0
  30. package/dist/merge-package-json.esm.js.map +1 -0
  31. package/dist/merge-package-json.esm.min.js +2 -0
  32. package/dist/merge-package-json.esm.min.js.map +1 -0
  33. package/package.json +56 -0
  34. package/src/commands/build.ts +91 -0
  35. package/src/commands/publish.ts +79 -0
  36. package/src/index.ts +6 -0
  37. package/src/inner.ts +11 -0
  38. package/src/merge-package-json.ts +19 -0
  39. package/src/rollup/index.ts +162 -0
  40. package/src/rollup/plugins/globals.ts +34 -0
  41. package/src/rollup/plugins/skip.ts +23 -0
  42. package/src/rollup/utils/commonOptions.ts +9 -0
  43. package/src/rollup/utils/externalResolver.ts +11 -0
  44. package/src/rollup/utils/globalResolver.ts +24 -0
  45. package/src/rollup/utils/withMinify.ts +16 -0
  46. package/tests/build.spec.ts +28 -0
  47. package/tests/fixtures/node_modules/.bin/jiek +17 -0
  48. package/tests/fixtures/node_modules/.jiek/jiek+test-foo.rollup.config.js +31 -0
  49. package/tests/fixtures/node_modules/.modules.yaml +95 -0
  50. package/tests/fixtures/node_modules/.pnpm/@esbuild+darwin-arm64@0.20.2/node_modules/@esbuild/darwin-arm64/README.md +3 -0
  51. package/tests/fixtures/node_modules/.pnpm/@esbuild+darwin-arm64@0.20.2/node_modules/@esbuild/darwin-arm64/bin/esbuild +0 -0
  52. package/tests/fixtures/node_modules/.pnpm/@esbuild+darwin-arm64@0.20.2/node_modules/@esbuild/darwin-arm64/package.json +20 -0
  53. package/tests/fixtures/node_modules/.pnpm/@jiek+loader-esbuild@1.0.0_esbuild@0.20.2/node_modules/@jiek/loader-esbuild/LICENSE +21 -0
  54. package/tests/fixtures/node_modules/.pnpm/@jiek+loader-esbuild@1.0.0_esbuild@0.20.2/node_modules/@jiek/loader-esbuild/loader.js +3 -0
  55. package/tests/fixtures/node_modules/.pnpm/@jiek+loader-esbuild@1.0.0_esbuild@0.20.2/node_modules/@jiek/loader-esbuild/package.json +8 -0
  56. package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/LICENSE +20 -0
  57. package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/README.md +481 -0
  58. package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/package.json +59 -0
  59. package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/browser.js +269 -0
  60. package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/common.js +274 -0
  61. package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/index.js +10 -0
  62. package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/node.js +263 -0
  63. package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/LICENSE +21 -0
  64. package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/README.md +50 -0
  65. package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/dist/loader.d.ts +3 -0
  66. package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/dist/loader.js +15 -0
  67. package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/dist/node.d.ts +23 -0
  68. package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/dist/node.js +4926 -0
  69. package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/loader.js +1 -0
  70. package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/node_modules/.bin/esbuild +14 -0
  71. package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/package.json +46 -0
  72. package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/register.js +3 -0
  73. package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/LICENSE.md +21 -0
  74. package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/README.md +3 -0
  75. package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/bin/esbuild +0 -0
  76. package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/install.js +288 -0
  77. package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.d.ts +703 -0
  78. package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js +2436 -0
  79. package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/node_modules/.bin/esbuild +14 -0
  80. package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/package.json +46 -0
  81. package/tests/fixtures/node_modules/.pnpm/lock.yaml +291 -0
  82. package/tests/fixtures/node_modules/.pnpm/ms@2.1.2/node_modules/ms/index.js +162 -0
  83. package/tests/fixtures/node_modules/.pnpm/ms@2.1.2/node_modules/ms/license.md +21 -0
  84. package/tests/fixtures/node_modules/.pnpm/ms@2.1.2/node_modules/ms/package.json +37 -0
  85. package/tests/fixtures/node_modules/.pnpm/ms@2.1.2/node_modules/ms/readme.md +60 -0
  86. package/tests/fixtures/node_modules/.pnpm/node_modules/.bin/esbuild +14 -0
  87. package/tests/fixtures/package.json +8 -0
  88. package/tests/fixtures/packages/bar/package.json +4 -0
  89. package/tests/fixtures/packages/foo/dist/index.d.ts +3 -0
  90. package/tests/fixtures/packages/foo/dist/index.esm.d.ts +3 -0
  91. package/tests/fixtures/packages/foo/dist/index.esm.js +6 -0
  92. package/tests/fixtures/packages/foo/dist/index.esm.js.map +1 -0
  93. package/tests/fixtures/packages/foo/dist/index.esm.min.js +2 -0
  94. package/tests/fixtures/packages/foo/dist/index.esm.min.js.map +1 -0
  95. package/tests/fixtures/packages/foo/dist/index.iife.js +15 -0
  96. package/tests/fixtures/packages/foo/dist/index.iife.js.map +1 -0
  97. package/tests/fixtures/packages/foo/dist/index.iife.min.js +2 -0
  98. package/tests/fixtures/packages/foo/dist/index.iife.min.js.map +1 -0
  99. package/tests/fixtures/packages/foo/dist/index.umd.js +16 -0
  100. package/tests/fixtures/packages/foo/dist/index.umd.js.map +1 -0
  101. package/tests/fixtures/packages/foo/dist/index.umd.min.js +2 -0
  102. package/tests/fixtures/packages/foo/dist/index.umd.min.js.map +1 -0
  103. package/tests/fixtures/packages/foo/package.json +7 -0
  104. package/tests/fixtures/packages/foo/src/index.ts +3 -0
  105. package/tests/fixtures/pnpm-workspace.yaml +2 -0
  106. package/tests/publish.spec.ts +31 -0
@@ -0,0 +1,14 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
+ esac
7
+
8
+ if [ -z "$NODE_PATH" ]; then
9
+ export NODE_PATH="/Users/yijie/codes/projects/jiek/packages/jiek/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/bin/node_modules:/Users/yijie/codes/projects/jiek/packages/jiek/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/node_modules:/Users/yijie/codes/projects/jiek/packages/jiek/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules:/Users/yijie/codes/projects/jiek/packages/jiek/tests/fixtures/node_modules/.pnpm/node_modules"
10
+ else
11
+ export NODE_PATH="/Users/yijie/codes/projects/jiek/packages/jiek/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/bin/node_modules:/Users/yijie/codes/projects/jiek/packages/jiek/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/node_modules:/Users/yijie/codes/projects/jiek/packages/jiek/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules:/Users/yijie/codes/projects/jiek/packages/jiek/tests/fixtures/node_modules/.pnpm/node_modules:$NODE_PATH"
12
+ fi
13
+ "$basedir/../../../../../esbuild@0.20.2/node_modules/esbuild/bin/esbuild" "$@"
14
+ exit $?
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "esbuild-register",
3
+ "description": "Transpile JSX, TypeScript and esnext features on the fly with esbuild",
4
+ "version": "3.5.0",
5
+ "main": "register.js",
6
+ "license": "MIT",
7
+ "files": [
8
+ "dist",
9
+ "/register.js",
10
+ "/loader.js"
11
+ ],
12
+ "exports": {
13
+ ".": "./register.js",
14
+ "./loader": "./loader.js",
15
+ "./dist/node": "./dist/node.js",
16
+ "./dist/*": "./dist/*"
17
+ },
18
+ "scripts": {
19
+ "build": "tsup src/node.ts src/loader.ts --dts",
20
+ "test": "npm run build && node -r ./register.js tests/test.ts",
21
+ "prepublishOnly": "npm run build"
22
+ },
23
+ "devDependencies": {
24
+ "@egoist/prettier-config": "^0.1.0",
25
+ "@types/debug": "^4.1.7",
26
+ "@types/node": "^14.0.23",
27
+ "@types/source-map-support": "^0.5.3",
28
+ "esbuild": "0.15.13",
29
+ "execa": "^4.0.3",
30
+ "joycon": "^2.2.5",
31
+ "pirates": "^4.0.1",
32
+ "source-map": "0.7.3",
33
+ "source-map-support": "^0.5.19",
34
+ "strip-json-comments": "^4.0.0",
35
+ "tsconfig-paths": "^4.2.0",
36
+ "tsup": "^4.7.1",
37
+ "typescript": "^4.8.4",
38
+ "uvu": "0.5.2"
39
+ },
40
+ "peerDependencies": {
41
+ "esbuild": ">=0.12 <1"
42
+ },
43
+ "dependencies": {
44
+ "debug": "^4.3.4"
45
+ }
46
+ }
@@ -0,0 +1,3 @@
1
+ require('./dist/node.js').register({
2
+ target: `node${process.version.slice(1)}`,
3
+ })
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Evan Wallace
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ # esbuild
2
+
3
+ This is a JavaScript bundler and minifier. See https://github.com/evanw/esbuild and the [JavaScript API documentation](https://esbuild.github.io/api/) for details.
@@ -0,0 +1,288 @@
1
+ "use strict";
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 __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+
25
+ // lib/npm/node-platform.ts
26
+ var fs = require("fs");
27
+ var os = require("os");
28
+ var path = require("path");
29
+ var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
30
+ var isValidBinaryPath = (x) => !!x && x !== "/usr/bin/esbuild";
31
+ var knownWindowsPackages = {
32
+ "win32 arm64 LE": "@esbuild/win32-arm64",
33
+ "win32 ia32 LE": "@esbuild/win32-ia32",
34
+ "win32 x64 LE": "@esbuild/win32-x64"
35
+ };
36
+ var knownUnixlikePackages = {
37
+ "aix ppc64 BE": "@esbuild/aix-ppc64",
38
+ "android arm64 LE": "@esbuild/android-arm64",
39
+ "darwin arm64 LE": "@esbuild/darwin-arm64",
40
+ "darwin x64 LE": "@esbuild/darwin-x64",
41
+ "freebsd arm64 LE": "@esbuild/freebsd-arm64",
42
+ "freebsd x64 LE": "@esbuild/freebsd-x64",
43
+ "linux arm LE": "@esbuild/linux-arm",
44
+ "linux arm64 LE": "@esbuild/linux-arm64",
45
+ "linux ia32 LE": "@esbuild/linux-ia32",
46
+ "linux mips64el LE": "@esbuild/linux-mips64el",
47
+ "linux ppc64 LE": "@esbuild/linux-ppc64",
48
+ "linux riscv64 LE": "@esbuild/linux-riscv64",
49
+ "linux s390x BE": "@esbuild/linux-s390x",
50
+ "linux x64 LE": "@esbuild/linux-x64",
51
+ "linux loong64 LE": "@esbuild/linux-loong64",
52
+ "netbsd x64 LE": "@esbuild/netbsd-x64",
53
+ "openbsd x64 LE": "@esbuild/openbsd-x64",
54
+ "sunos x64 LE": "@esbuild/sunos-x64"
55
+ };
56
+ var knownWebAssemblyFallbackPackages = {
57
+ "android arm LE": "@esbuild/android-arm",
58
+ "android x64 LE": "@esbuild/android-x64"
59
+ };
60
+ function pkgAndSubpathForCurrentPlatform() {
61
+ let pkg;
62
+ let subpath;
63
+ let isWASM = false;
64
+ let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
65
+ if (platformKey in knownWindowsPackages) {
66
+ pkg = knownWindowsPackages[platformKey];
67
+ subpath = "esbuild.exe";
68
+ } else if (platformKey in knownUnixlikePackages) {
69
+ pkg = knownUnixlikePackages[platformKey];
70
+ subpath = "bin/esbuild";
71
+ } else if (platformKey in knownWebAssemblyFallbackPackages) {
72
+ pkg = knownWebAssemblyFallbackPackages[platformKey];
73
+ subpath = "bin/esbuild";
74
+ isWASM = true;
75
+ } else {
76
+ throw new Error(`Unsupported platform: ${platformKey}`);
77
+ }
78
+ return { pkg, subpath, isWASM };
79
+ }
80
+ function downloadedBinPath(pkg, subpath) {
81
+ const esbuildLibDir = path.dirname(require.resolve("esbuild"));
82
+ return path.join(esbuildLibDir, `downloaded-${pkg.replace("/", "-")}-${path.basename(subpath)}`);
83
+ }
84
+
85
+ // lib/npm/node-install.ts
86
+ var fs2 = require("fs");
87
+ var os2 = require("os");
88
+ var path2 = require("path");
89
+ var zlib = require("zlib");
90
+ var https = require("https");
91
+ var child_process = require("child_process");
92
+ var versionFromPackageJSON = require(path2.join(__dirname, "package.json")).version;
93
+ var toPath = path2.join(__dirname, "bin", "esbuild");
94
+ var isToPathJS = true;
95
+ function validateBinaryVersion(...command) {
96
+ command.push("--version");
97
+ let stdout;
98
+ try {
99
+ stdout = child_process.execFileSync(command.shift(), command, {
100
+ // Without this, this install script strangely crashes with the error
101
+ // "EACCES: permission denied, write" but only on Ubuntu Linux when node is
102
+ // installed from the Snap Store. This is not a problem when you download
103
+ // the official version of node. The problem appears to be that stderr
104
+ // (i.e. file descriptor 2) isn't writable?
105
+ //
106
+ // More info:
107
+ // - https://snapcraft.io/ (what the Snap Store is)
108
+ // - https://nodejs.org/dist/ (download the official version of node)
109
+ // - https://github.com/evanw/esbuild/issues/1711#issuecomment-1027554035
110
+ //
111
+ stdio: "pipe"
112
+ }).toString().trim();
113
+ } catch (err) {
114
+ if (os2.platform() === "darwin" && /_SecTrustEvaluateWithError/.test(err + "")) {
115
+ let os3 = "this version of macOS";
116
+ try {
117
+ os3 = "macOS " + child_process.execFileSync("sw_vers", ["-productVersion"]).toString().trim();
118
+ } catch {
119
+ }
120
+ throw new Error(`The "esbuild" package cannot be installed because ${os3} is too outdated.
121
+
122
+ The Go compiler (which esbuild relies on) no longer supports ${os3},
123
+ which means the "esbuild" binary executable can't be run. You can either:
124
+
125
+ * Update your version of macOS to one that the Go compiler supports
126
+ * Use the "esbuild-wasm" package instead of the "esbuild" package
127
+ * Build esbuild yourself using an older version of the Go compiler
128
+ `);
129
+ }
130
+ throw err;
131
+ }
132
+ if (stdout !== versionFromPackageJSON) {
133
+ throw new Error(`Expected ${JSON.stringify(versionFromPackageJSON)} but got ${JSON.stringify(stdout)}`);
134
+ }
135
+ }
136
+ function isYarn() {
137
+ const { npm_config_user_agent } = process.env;
138
+ if (npm_config_user_agent) {
139
+ return /\byarn\//.test(npm_config_user_agent);
140
+ }
141
+ return false;
142
+ }
143
+ function fetch(url) {
144
+ return new Promise((resolve, reject) => {
145
+ https.get(url, (res) => {
146
+ if ((res.statusCode === 301 || res.statusCode === 302) && res.headers.location)
147
+ return fetch(res.headers.location).then(resolve, reject);
148
+ if (res.statusCode !== 200)
149
+ return reject(new Error(`Server responded with ${res.statusCode}`));
150
+ let chunks = [];
151
+ res.on("data", (chunk) => chunks.push(chunk));
152
+ res.on("end", () => resolve(Buffer.concat(chunks)));
153
+ }).on("error", reject);
154
+ });
155
+ }
156
+ function extractFileFromTarGzip(buffer, subpath) {
157
+ try {
158
+ buffer = zlib.unzipSync(buffer);
159
+ } catch (err) {
160
+ throw new Error(`Invalid gzip data in archive: ${err && err.message || err}`);
161
+ }
162
+ let str = (i, n) => String.fromCharCode(...buffer.subarray(i, i + n)).replace(/\0.*$/, "");
163
+ let offset = 0;
164
+ subpath = `package/${subpath}`;
165
+ while (offset < buffer.length) {
166
+ let name = str(offset, 100);
167
+ let size = parseInt(str(offset + 124, 12), 8);
168
+ offset += 512;
169
+ if (!isNaN(size)) {
170
+ if (name === subpath)
171
+ return buffer.subarray(offset, offset + size);
172
+ offset += size + 511 & ~511;
173
+ }
174
+ }
175
+ throw new Error(`Could not find ${JSON.stringify(subpath)} in archive`);
176
+ }
177
+ function installUsingNPM(pkg, subpath, binPath) {
178
+ const env = { ...process.env, npm_config_global: void 0 };
179
+ const esbuildLibDir = path2.dirname(require.resolve("esbuild"));
180
+ const installDir = path2.join(esbuildLibDir, "npm-install");
181
+ fs2.mkdirSync(installDir);
182
+ try {
183
+ fs2.writeFileSync(path2.join(installDir, "package.json"), "{}");
184
+ child_process.execSync(
185
+ `npm install --loglevel=error --prefer-offline --no-audit --progress=false ${pkg}@${versionFromPackageJSON}`,
186
+ { cwd: installDir, stdio: "pipe", env }
187
+ );
188
+ const installedBinPath = path2.join(installDir, "node_modules", pkg, subpath);
189
+ fs2.renameSync(installedBinPath, binPath);
190
+ } finally {
191
+ try {
192
+ removeRecursive(installDir);
193
+ } catch {
194
+ }
195
+ }
196
+ }
197
+ function removeRecursive(dir) {
198
+ for (const entry of fs2.readdirSync(dir)) {
199
+ const entryPath = path2.join(dir, entry);
200
+ let stats;
201
+ try {
202
+ stats = fs2.lstatSync(entryPath);
203
+ } catch {
204
+ continue;
205
+ }
206
+ if (stats.isDirectory())
207
+ removeRecursive(entryPath);
208
+ else
209
+ fs2.unlinkSync(entryPath);
210
+ }
211
+ fs2.rmdirSync(dir);
212
+ }
213
+ function applyManualBinaryPathOverride(overridePath) {
214
+ const pathString = JSON.stringify(overridePath);
215
+ fs2.writeFileSync(toPath, `#!/usr/bin/env node
216
+ require('child_process').execFileSync(${pathString}, process.argv.slice(2), { stdio: 'inherit' });
217
+ `);
218
+ const libMain = path2.join(__dirname, "lib", "main.js");
219
+ const code = fs2.readFileSync(libMain, "utf8");
220
+ fs2.writeFileSync(libMain, `var ESBUILD_BINARY_PATH = ${pathString};
221
+ ${code}`);
222
+ }
223
+ function maybeOptimizePackage(binPath) {
224
+ if (os2.platform() !== "win32" && !isYarn()) {
225
+ const tempPath = path2.join(__dirname, "bin-esbuild");
226
+ try {
227
+ fs2.linkSync(binPath, tempPath);
228
+ fs2.renameSync(tempPath, toPath);
229
+ isToPathJS = false;
230
+ fs2.unlinkSync(tempPath);
231
+ } catch {
232
+ }
233
+ }
234
+ }
235
+ async function downloadDirectlyFromNPM(pkg, subpath, binPath) {
236
+ const url = `https://registry.npmjs.org/${pkg}/-/${pkg.replace("@esbuild/", "")}-${versionFromPackageJSON}.tgz`;
237
+ console.error(`[esbuild] Trying to download ${JSON.stringify(url)}`);
238
+ try {
239
+ fs2.writeFileSync(binPath, extractFileFromTarGzip(await fetch(url), subpath));
240
+ fs2.chmodSync(binPath, 493);
241
+ } catch (e) {
242
+ console.error(`[esbuild] Failed to download ${JSON.stringify(url)}: ${e && e.message || e}`);
243
+ throw e;
244
+ }
245
+ }
246
+ async function checkAndPreparePackage() {
247
+ if (isValidBinaryPath(ESBUILD_BINARY_PATH)) {
248
+ if (!fs2.existsSync(ESBUILD_BINARY_PATH)) {
249
+ console.warn(`[esbuild] Ignoring bad configuration: ESBUILD_BINARY_PATH=${ESBUILD_BINARY_PATH}`);
250
+ } else {
251
+ applyManualBinaryPathOverride(ESBUILD_BINARY_PATH);
252
+ return;
253
+ }
254
+ }
255
+ const { pkg, subpath } = pkgAndSubpathForCurrentPlatform();
256
+ let binPath;
257
+ try {
258
+ binPath = require.resolve(`${pkg}/${subpath}`);
259
+ } catch (e) {
260
+ console.error(`[esbuild] Failed to find package "${pkg}" on the file system
261
+
262
+ This can happen if you use the "--no-optional" flag. The "optionalDependencies"
263
+ package.json feature is used by esbuild to install the correct binary executable
264
+ for your current platform. This install script will now attempt to work around
265
+ this. If that fails, you need to remove the "--no-optional" flag to use esbuild.
266
+ `);
267
+ binPath = downloadedBinPath(pkg, subpath);
268
+ try {
269
+ console.error(`[esbuild] Trying to install package "${pkg}" using npm`);
270
+ installUsingNPM(pkg, subpath, binPath);
271
+ } catch (e2) {
272
+ console.error(`[esbuild] Failed to install package "${pkg}" using npm: ${e2 && e2.message || e2}`);
273
+ try {
274
+ await downloadDirectlyFromNPM(pkg, subpath, binPath);
275
+ } catch (e3) {
276
+ throw new Error(`Failed to install package "${pkg}"`);
277
+ }
278
+ }
279
+ }
280
+ maybeOptimizePackage(binPath);
281
+ }
282
+ checkAndPreparePackage().then(() => {
283
+ if (isToPathJS) {
284
+ validateBinaryVersion(process.execPath, toPath);
285
+ } else {
286
+ validateBinaryVersion(toPath);
287
+ }
288
+ });