esbuild 0.12.26 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/esbuild CHANGED
@@ -1,13 +1,92 @@
1
1
  #!/usr/bin/env node
2
- throw new Error(`esbuild: Failed to install correctly
3
2
 
4
- Make sure you don't have "ignore-scripts" set to true. You can check this with
5
- "npm config get ignore-scripts". If that returns true you can reset it back to
6
- false using "npm config set ignore-scripts false" and then reinstall esbuild.
3
+ // lib/npm/node-platform.ts
4
+ var fs = require("fs");
5
+ var os = require("os");
6
+ var path = require("path");
7
+ var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
8
+ var knownWindowsPackages = {
9
+ "win32 arm64 LE": "esbuild-windows-arm64",
10
+ "win32 ia32 LE": "esbuild-windows-32",
11
+ "win32 x64 LE": "esbuild-windows-64"
12
+ };
13
+ var knownUnixlikePackages = {
14
+ "android arm64 LE": "esbuild-android-arm64",
15
+ "darwin arm64 LE": "esbuild-darwin-arm64",
16
+ "darwin x64 LE": "esbuild-darwin-64",
17
+ "freebsd arm64 LE": "esbuild-freebsd-arm64",
18
+ "freebsd x64 LE": "esbuild-freebsd-64",
19
+ "openbsd x64 LE": "esbuild-openbsd-64",
20
+ "linux arm LE": "esbuild-linux-arm",
21
+ "linux arm64 LE": "esbuild-linux-arm64",
22
+ "linux ia32 LE": "esbuild-linux-32",
23
+ "linux mips64el LE": "esbuild-linux-mips64le",
24
+ "linux ppc64 LE": "esbuild-linux-ppc64le",
25
+ "linux x64 LE": "esbuild-linux-64",
26
+ "sunos x64 LE": "esbuild-sunos-64"
27
+ };
28
+ function pkgAndBinForCurrentPlatform() {
29
+ let pkg;
30
+ let bin;
31
+ let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
32
+ if (platformKey in knownWindowsPackages) {
33
+ pkg = knownWindowsPackages[platformKey];
34
+ bin = `${pkg}/esbuild.exe`;
35
+ } else if (platformKey in knownUnixlikePackages) {
36
+ pkg = knownUnixlikePackages[platformKey];
37
+ bin = `${pkg}/bin/esbuild`;
38
+ } else {
39
+ throw new Error(`Unsupported platform: ${platformKey}`);
40
+ }
41
+ try {
42
+ bin = require.resolve(bin);
43
+ } catch (e) {
44
+ try {
45
+ require.resolve(pkg);
46
+ } catch (e2) {
47
+ throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild.
7
48
 
8
- If you're using npm v7, make sure your package-lock.json file contains either
9
- "lockfileVersion": 1 or the code "hasInstallScript": true. If it doesn't have
10
- either of those, then it is likely the case that a known bug in npm v7 has
11
- corrupted your package-lock.json file. Regenerating your package-lock.json file
12
- should fix this issue.
13
- `);
49
+ If you are installing esbuild with npm, make sure that you don't specify the
50
+ "--no-optional" flag. The "optionalDependencies" package.json feature is used
51
+ by esbuild to install the correct binary executable for your current platform.`);
52
+ }
53
+ throw e;
54
+ }
55
+ return { pkg, bin };
56
+ }
57
+ function getCachePath(name) {
58
+ const home = os.homedir();
59
+ const common = ["esbuild", "bin", `${name}@${"0.13.0"}`];
60
+ if (process.platform === "darwin")
61
+ return path.join(home, "Library", "Caches", ...common);
62
+ if (process.platform === "win32")
63
+ return path.join(home, "AppData", "Local", "Cache", ...common);
64
+ const XDG_CACHE_HOME = process.env.XDG_CACHE_HOME;
65
+ if (process.platform === "linux" && XDG_CACHE_HOME && path.isAbsolute(XDG_CACHE_HOME))
66
+ return path.join(XDG_CACHE_HOME, ...common);
67
+ return path.join(home, ".cache", ...common);
68
+ }
69
+ function extractedBinPath() {
70
+ if (ESBUILD_BINARY_PATH) {
71
+ return ESBUILD_BINARY_PATH;
72
+ }
73
+ const { pkg, bin } = pkgAndBinForCurrentPlatform();
74
+ let isYarnPnP = false;
75
+ try {
76
+ require("pnpapi");
77
+ isYarnPnP = true;
78
+ } catch (e) {
79
+ }
80
+ if (isYarnPnP) {
81
+ const binTargetPath = getCachePath(pkg);
82
+ if (!fs.existsSync(binTargetPath)) {
83
+ fs.copyFileSync(bin, binTargetPath);
84
+ fs.chmodSync(binTargetPath, 493);
85
+ }
86
+ return binTargetPath;
87
+ }
88
+ return bin;
89
+ }
90
+
91
+ // lib/npm/node-shim.ts
92
+ require("child_process").execFileSync(extractedBinPath(), process.argv.slice(2), { stdio: "inherit" });
package/install.js CHANGED
@@ -1,187 +1,72 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
1
+ // lib/npm/node-platform.ts
2
+ var fs = require("fs");
3
+ var os = require("os");
4
+ var path = require("path");
5
+ var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
6
+ var knownWindowsPackages = {
7
+ "win32 arm64 LE": "esbuild-windows-arm64",
8
+ "win32 ia32 LE": "esbuild-windows-32",
9
+ "win32 x64 LE": "esbuild-windows-64"
18
10
  };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __require = typeof require !== "undefined" ? require : (x) => {
21
- throw new Error('Dynamic require of "' + x + '" is not supported');
11
+ var knownUnixlikePackages = {
12
+ "android arm64 LE": "esbuild-android-arm64",
13
+ "darwin arm64 LE": "esbuild-darwin-arm64",
14
+ "darwin x64 LE": "esbuild-darwin-64",
15
+ "freebsd arm64 LE": "esbuild-freebsd-arm64",
16
+ "freebsd x64 LE": "esbuild-freebsd-64",
17
+ "openbsd x64 LE": "esbuild-openbsd-64",
18
+ "linux arm LE": "esbuild-linux-arm",
19
+ "linux arm64 LE": "esbuild-linux-arm64",
20
+ "linux ia32 LE": "esbuild-linux-32",
21
+ "linux mips64el LE": "esbuild-linux-mips64le",
22
+ "linux ppc64 LE": "esbuild-linux-ppc64le",
23
+ "linux x64 LE": "esbuild-linux-64",
24
+ "sunos x64 LE": "esbuild-sunos-64"
22
25
  };
23
- const fs = require("fs");
24
- const os = require("os");
25
- const path = require("path");
26
- const zlib = require("zlib");
27
- const https = require("https");
28
- const child_process = require("child_process");
29
- const version = "0.12.26";
30
- const binPath = path.join(__dirname, "bin", "esbuild");
31
- async function installBinaryFromPackage(name, fromPath, toPath) {
32
- const cachePath = getCachePath(name);
33
- try {
34
- fs.copyFileSync(cachePath, toPath);
35
- fs.chmodSync(toPath, 493);
36
- validateBinaryVersion(toPath);
37
- const now = new Date();
38
- fs.utimesSync(cachePath, now, now);
39
- return;
40
- } catch (e) {
41
- }
42
- let buffer;
43
- let didFail = false;
44
- try {
45
- buffer = installUsingNPM(name, fromPath);
46
- } catch (err) {
47
- didFail = true;
48
- console.error(`Trying to install "${name}" using npm`);
49
- console.error(`Failed to install "${name}" using npm: ${err && err.message || err}`);
50
- }
51
- if (!buffer) {
52
- const url = `https://registry.npmjs.org/${name}/-/${name}-${version}.tgz`;
53
- console.error(`Trying to download ${JSON.stringify(url)}`);
54
- try {
55
- buffer = extractFileFromTarGzip(await fetch(url), fromPath);
56
- } catch (err) {
57
- console.error(`Failed to download ${JSON.stringify(url)}: ${err && err.message || err}`);
58
- }
59
- }
60
- if (!buffer) {
61
- console.error(`Install unsuccessful`);
62
- process.exit(1);
63
- }
64
- fs.writeFileSync(toPath, buffer, { mode: 493 });
65
- try {
66
- validateBinaryVersion(toPath);
67
- } catch (err) {
68
- console.error(`The version of the downloaded binary is incorrect: ${err && err.message || err}`);
69
- console.error(`Install unsuccessful`);
70
- process.exit(1);
26
+ function pkgAndBinForCurrentPlatform() {
27
+ let pkg;
28
+ let bin;
29
+ let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
30
+ if (platformKey in knownWindowsPackages) {
31
+ pkg = knownWindowsPackages[platformKey];
32
+ bin = `${pkg}/esbuild.exe`;
33
+ } else if (platformKey in knownUnixlikePackages) {
34
+ pkg = knownUnixlikePackages[platformKey];
35
+ bin = `${pkg}/bin/esbuild`;
36
+ } else {
37
+ throw new Error(`Unsupported platform: ${platformKey}`);
71
38
  }
72
39
  try {
73
- fs.mkdirSync(path.dirname(cachePath), {
74
- recursive: true,
75
- mode: 448
76
- });
77
- fs.copyFileSync(toPath, cachePath);
78
- cleanCacheLRU(cachePath);
40
+ bin = require.resolve(bin);
79
41
  } catch (e) {
80
- }
81
- if (didFail)
82
- console.error(`Install successful`);
83
- }
84
- function validateBinaryVersion(binaryPath) {
85
- const stdout = child_process.execFileSync(binaryPath, ["--version"]).toString().trim();
86
- if (stdout !== version) {
87
- throw new Error(`Expected ${JSON.stringify(version)} but got ${JSON.stringify(stdout)}`);
88
- }
89
- }
90
- function getCachePath(name) {
91
- const home = os.homedir();
92
- const common = ["esbuild", "bin", `${name}@${version}`];
93
- if (process.platform === "darwin")
94
- return path.join(home, "Library", "Caches", ...common);
95
- if (process.platform === "win32")
96
- return path.join(home, "AppData", "Local", "Cache", ...common);
97
- const XDG_CACHE_HOME = process.env.XDG_CACHE_HOME;
98
- if (process.platform === "linux" && XDG_CACHE_HOME && path.isAbsolute(XDG_CACHE_HOME))
99
- return path.join(XDG_CACHE_HOME, ...common);
100
- return path.join(home, ".cache", ...common);
101
- }
102
- function cleanCacheLRU(fileToKeep) {
103
- const dir = path.dirname(fileToKeep);
104
- const entries = [];
105
- for (const entry of fs.readdirSync(dir)) {
106
- const entryPath = path.join(dir, entry);
107
42
  try {
108
- const stats = fs.statSync(entryPath);
109
- entries.push({ path: entryPath, mtime: stats.mtime });
110
- } catch (e) {
43
+ require.resolve(pkg);
44
+ } catch (e2) {
45
+ throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild.
46
+
47
+ If you are installing esbuild with npm, make sure that you don't specify the
48
+ "--no-optional" flag. The "optionalDependencies" package.json feature is used
49
+ by esbuild to install the correct binary executable for your current platform.`);
111
50
  }
51
+ throw e;
112
52
  }
113
- entries.sort((a, b) => +b.mtime - +a.mtime);
114
- for (const entry of entries.slice(5)) {
115
- try {
116
- fs.unlinkSync(entry.path);
117
- } catch (e) {
118
- }
119
- }
120
- }
121
- function fetch(url) {
122
- return new Promise((resolve, reject) => {
123
- https.get(url, (res) => {
124
- if ((res.statusCode === 301 || res.statusCode === 302) && res.headers.location)
125
- return fetch(res.headers.location).then(resolve, reject);
126
- if (res.statusCode !== 200)
127
- return reject(new Error(`Server responded with ${res.statusCode}`));
128
- let chunks = [];
129
- res.on("data", (chunk) => chunks.push(chunk));
130
- res.on("end", () => resolve(Buffer.concat(chunks)));
131
- }).on("error", reject);
132
- });
53
+ return { pkg, bin };
133
54
  }
134
- function extractFileFromTarGzip(buffer, file) {
135
- try {
136
- buffer = zlib.unzipSync(buffer);
137
- } catch (err) {
138
- throw new Error(`Invalid gzip data in archive: ${err && err.message || err}`);
55
+
56
+ // lib/npm/node-install.ts
57
+ var fs2 = require("fs");
58
+ var os2 = require("os");
59
+ var path2 = require("path");
60
+ var child_process = require("child_process");
61
+ var toPath = path2.join(__dirname, "bin", "esbuild");
62
+ function validateBinaryVersion(...command) {
63
+ command.push("--version");
64
+ const stdout = child_process.execFileSync(command.shift(), command).toString().trim();
65
+ if (stdout !== "0.13.0") {
66
+ throw new Error(`Expected ${JSON.stringify("0.13.0")} but got ${JSON.stringify(stdout)}`);
139
67
  }
140
- let str = (i, n) => String.fromCharCode(...buffer.subarray(i, i + n)).replace(/\0.*$/, "");
141
- let offset = 0;
142
- file = `package/${file}`;
143
- while (offset < buffer.length) {
144
- let name = str(offset, 100);
145
- let size = parseInt(str(offset + 124, 12), 8);
146
- offset += 512;
147
- if (!isNaN(size)) {
148
- if (name === file)
149
- return buffer.subarray(offset, offset + size);
150
- offset += size + 511 & ~511;
151
- }
152
- }
153
- throw new Error(`Could not find ${JSON.stringify(file)} in archive`);
154
- }
155
- function installUsingNPM(name, file) {
156
- const installDir = path.join(os.tmpdir(), "esbuild-" + Math.random().toString(36).slice(2));
157
- fs.mkdirSync(installDir, { recursive: true });
158
- fs.writeFileSync(path.join(installDir, "package.json"), "{}");
159
- const env = __spreadProps(__spreadValues({}, process.env), { npm_config_global: void 0 });
160
- child_process.execSync(`npm install --loglevel=error --prefer-offline --no-audit --progress=false ${name}@${version}`, { cwd: installDir, stdio: "pipe", env });
161
- const buffer = fs.readFileSync(path.join(installDir, "node_modules", name, file));
162
- try {
163
- removeRecursive(installDir);
164
- } catch (e) {
165
- }
166
- return buffer;
167
68
  }
168
- function removeRecursive(dir) {
169
- for (const entry of fs.readdirSync(dir)) {
170
- const entryPath = path.join(dir, entry);
171
- let stats;
172
- try {
173
- stats = fs.lstatSync(entryPath);
174
- } catch (e) {
175
- continue;
176
- }
177
- if (stats.isDirectory())
178
- removeRecursive(entryPath);
179
- else
180
- fs.unlinkSync(entryPath);
181
- }
182
- fs.rmdirSync(dir);
183
- }
184
- function isYarnBerryOrNewer() {
69
+ function isYarn2OrAbove() {
185
70
  const { npm_config_user_agent } = process.env;
186
71
  if (npm_config_user_agent) {
187
72
  const match = npm_config_user_agent.match(/yarn\/(\d+)/);
@@ -191,71 +76,24 @@ function isYarnBerryOrNewer() {
191
76
  }
192
77
  return false;
193
78
  }
194
- function installDirectly(name) {
195
- if (process.env.ESBUILD_BINARY_PATH) {
196
- fs.copyFileSync(process.env.ESBUILD_BINARY_PATH, binPath);
197
- validateBinaryVersion(binPath);
198
- } else {
199
- const tempBinPath = binPath + "__";
200
- installBinaryFromPackage(name, "bin/esbuild", tempBinPath).then(() => fs.renameSync(tempBinPath, binPath)).catch((e) => setImmediate(() => {
201
- throw e;
202
- }));
203
- }
204
- }
205
- function installWithWrapper(name, fromPath, toPath) {
206
- fs.writeFileSync(binPath, `#!/usr/bin/env node
207
- const path = require('path');
208
- const esbuild_exe = path.join(__dirname, '..', ${JSON.stringify(toPath)});
209
- const child_process = require('child_process');
210
- const { status } = child_process.spawnSync(esbuild_exe, process.argv.slice(2), { stdio: 'inherit' });
211
- process.exitCode = status === null ? 1 : status;
79
+ if (process.env.ESBUILD_BINARY_PATH) {
80
+ const pathString = JSON.stringify(process.env.ESBUILD_BINARY_PATH);
81
+ fs2.writeFileSync(toPath, `#!/usr/bin/env node
82
+ require('child_process').execFileSync(${pathString}, process.argv.slice(2), { stdio: 'inherit' });
212
83
  `);
213
- const absToPath = path.join(__dirname, toPath);
214
- if (process.env.ESBUILD_BINARY_PATH) {
215
- fs.copyFileSync(process.env.ESBUILD_BINARY_PATH, absToPath);
216
- validateBinaryVersion(absToPath);
217
- } else {
218
- installBinaryFromPackage(name, fromPath, absToPath).catch((e) => setImmediate(() => {
219
- throw e;
220
- }));
221
- }
222
- }
223
- function installOnUnix(name) {
224
- if (isYarnBerryOrNewer()) {
225
- installWithWrapper(name, "bin/esbuild", "esbuild");
226
- } else {
227
- installDirectly(name);
84
+ const libMain = path2.join(__dirname, "lib", "main.js");
85
+ const code = fs2.readFileSync(libMain, "utf8");
86
+ fs2.writeFileSync(libMain, `var ESBUILD_BINARY_PATH = ${pathString};
87
+ ${code}`);
88
+ validateBinaryVersion("node", toPath);
89
+ } else if (os2.platform() !== "win32" && !isYarn2OrAbove()) {
90
+ const { bin } = pkgAndBinForCurrentPlatform();
91
+ try {
92
+ fs2.unlinkSync(toPath);
93
+ fs2.linkSync(bin, toPath);
94
+ } catch (e) {
228
95
  }
229
- }
230
- function installOnWindows(name) {
231
- installWithWrapper(name, "esbuild.exe", "esbuild.exe");
232
- }
233
- const platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
234
- const knownWindowsPackages = {
235
- "win32 arm64 LE": "esbuild-windows-arm64",
236
- "win32 ia32 LE": "esbuild-windows-32",
237
- "win32 x64 LE": "esbuild-windows-64"
238
- };
239
- const knownUnixlikePackages = {
240
- "android arm64 LE": "esbuild-android-arm64",
241
- "darwin arm64 LE": "esbuild-darwin-arm64",
242
- "darwin x64 LE": "esbuild-darwin-64",
243
- "freebsd arm64 LE": "esbuild-freebsd-arm64",
244
- "freebsd x64 LE": "esbuild-freebsd-64",
245
- "openbsd x64 LE": "esbuild-openbsd-64",
246
- "linux arm LE": "esbuild-linux-arm",
247
- "linux arm64 LE": "esbuild-linux-arm64",
248
- "linux ia32 LE": "esbuild-linux-32",
249
- "linux mips64el LE": "esbuild-linux-mips64le",
250
- "linux ppc64 LE": "esbuild-linux-ppc64le",
251
- "linux x64 LE": "esbuild-linux-64",
252
- "sunos x64 LE": "esbuild-sunos-64"
253
- };
254
- if (platformKey in knownWindowsPackages) {
255
- installOnWindows(knownWindowsPackages[platformKey]);
256
- } else if (platformKey in knownUnixlikePackages) {
257
- installOnUnix(knownUnixlikePackages[platformKey]);
96
+ validateBinaryVersion(toPath);
258
97
  } else {
259
- console.error(`Unsupported platform: ${platformKey}`);
260
- process.exit(1);
98
+ validateBinaryVersion("node", toPath);
261
99
  }
package/lib/main.d.ts CHANGED
@@ -3,7 +3,6 @@ export type Format = 'iife' | 'cjs' | 'esm';
3
3
  export type Loader = 'js' | 'jsx' | 'ts' | 'tsx' | 'css' | 'json' | 'text' | 'base64' | 'file' | 'dataurl' | 'binary' | 'default';
4
4
  export type LogLevel = 'verbose' | 'debug' | 'info' | 'warning' | 'error' | 'silent';
5
5
  export type Charset = 'ascii' | 'utf8';
6
- export type TreeShaking = true | 'ignore-annotations';
7
6
 
8
7
  interface CommonOptions {
9
8
  sourcemap?: boolean | 'inline' | 'external' | 'both';
@@ -20,7 +19,8 @@ interface CommonOptions {
20
19
  minifyIdentifiers?: boolean;
21
20
  minifySyntax?: boolean;
22
21
  charset?: Charset;
23
- treeShaking?: TreeShaking;
22
+ treeShaking?: boolean;
23
+ ignoreAnnotations?: boolean;
24
24
 
25
25
  jsx?: 'transform' | 'preserve';
26
26
  jsxFactory?: string;
package/lib/main.js CHANGED
@@ -18,9 +18,6 @@ var __spreadValues = (a, b) => {
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
21
- var __require = typeof require !== "undefined" ? require : (x) => {
22
- throw new Error('Dynamic require of "' + x + '" is not supported');
23
- };
24
21
  var __export = (target, all) => {
25
22
  __markAsModule(target);
26
23
  for (var name in all)
@@ -278,7 +275,8 @@ function pushCommonFlags(flags, options, keys) {
278
275
  let minifyWhitespace = getFlag(options, keys, "minifyWhitespace", mustBeBoolean);
279
276
  let minifyIdentifiers = getFlag(options, keys, "minifyIdentifiers", mustBeBoolean);
280
277
  let charset = getFlag(options, keys, "charset", mustBeString);
281
- let treeShaking = getFlag(options, keys, "treeShaking", mustBeStringOrBoolean);
278
+ let treeShaking = getFlag(options, keys, "treeShaking", mustBeBoolean);
279
+ let ignoreAnnotations = getFlag(options, keys, "ignoreAnnotations", mustBeBoolean);
282
280
  let jsx = getFlag(options, keys, "jsx", mustBeString);
283
281
  let jsxFactory = getFlag(options, keys, "jsxFactory", mustBeString);
284
282
  let jsxFragment = getFlag(options, keys, "jsxFragment", mustBeString);
@@ -311,8 +309,10 @@ function pushCommonFlags(flags, options, keys) {
311
309
  flags.push("--minify-identifiers");
312
310
  if (charset)
313
311
  flags.push(`--charset=${charset}`);
314
- if (treeShaking !== void 0 && treeShaking !== true)
312
+ if (treeShaking !== void 0)
315
313
  flags.push(`--tree-shaking=${treeShaking}`);
314
+ if (ignoreAnnotations)
315
+ flags.push(`--ignore-annotations`);
316
316
  if (jsx)
317
317
  flags.push(`--jsx=${jsx}`);
318
318
  if (jsxFactory)
@@ -464,8 +464,8 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
464
464
  }
465
465
  }
466
466
  if (inject)
467
- for (let path2 of inject)
468
- flags.push(`--inject:${path2}`);
467
+ for (let path3 of inject)
468
+ flags.push(`--inject:${path3}`);
469
469
  if (loader) {
470
470
  for (let ext in loader) {
471
471
  if (ext.indexOf("=") >= 0)
@@ -694,8 +694,8 @@ function createChannel(streamIn) {
694
694
  if (isFirstPacket) {
695
695
  isFirstPacket = false;
696
696
  let binaryVersion = String.fromCharCode(...bytes);
697
- if (binaryVersion !== "0.12.26") {
698
- throw new Error(`Cannot start service: Host version "${"0.12.26"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
697
+ if (binaryVersion !== "0.13.0") {
698
+ throw new Error(`Cannot start service: Host version "${"0.13.0"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
699
699
  }
700
700
  return;
701
701
  }
@@ -827,7 +827,7 @@ function createChannel(streamIn) {
827
827
  throw new Error(`Expected onResolve() callback in plugin ${JSON.stringify(name)} to return an object`);
828
828
  let keys = {};
829
829
  let pluginName = getFlag(result, keys, "pluginName", mustBeString);
830
- let path2 = getFlag(result, keys, "path", mustBeString);
830
+ let path3 = getFlag(result, keys, "path", mustBeString);
831
831
  let namespace = getFlag(result, keys, "namespace", mustBeString);
832
832
  let external = getFlag(result, keys, "external", mustBeBoolean);
833
833
  let sideEffects = getFlag(result, keys, "sideEffects", mustBeBoolean);
@@ -840,8 +840,8 @@ function createChannel(streamIn) {
840
840
  response.id = id;
841
841
  if (pluginName != null)
842
842
  response.pluginName = pluginName;
843
- if (path2 != null)
844
- response.path = path2;
843
+ if (path3 != null)
844
+ response.path = path3;
845
845
  if (namespace != null)
846
846
  response.namespace = namespace;
847
847
  if (external != null)
@@ -1243,7 +1243,7 @@ function createChannel(streamIn) {
1243
1243
  return buildResponseToResult(response, callback);
1244
1244
  });
1245
1245
  };
1246
- let transform2 = ({ callName, refs, input, options, isTTY: isTTY2, fs: fs2, callback }) => {
1246
+ let transform2 = ({ callName, refs, input, options, isTTY: isTTY2, fs: fs3, callback }) => {
1247
1247
  const details = createObjectStash();
1248
1248
  let start = (inputPath) => {
1249
1249
  try {
@@ -1267,7 +1267,7 @@ function createChannel(streamIn) {
1267
1267
  return callback(failureErrorWithLog("Transform failed", errors, warnings), null);
1268
1268
  if (response.codeFS) {
1269
1269
  outstanding++;
1270
- fs2.readFile(response.code, (err, contents) => {
1270
+ fs3.readFile(response.code, (err, contents) => {
1271
1271
  if (err !== null) {
1272
1272
  callback(err, null);
1273
1273
  } else {
@@ -1278,7 +1278,7 @@ function createChannel(streamIn) {
1278
1278
  }
1279
1279
  if (response.mapFS) {
1280
1280
  outstanding++;
1281
- fs2.readFile(response.map, (err, contents) => {
1281
+ fs3.readFile(response.map, (err, contents) => {
1282
1282
  if (err !== null) {
1283
1283
  callback(err, null);
1284
1284
  } else {
@@ -1304,7 +1304,7 @@ function createChannel(streamIn) {
1304
1304
  };
1305
1305
  if (typeof input === "string" && input.length > 1024 * 1024) {
1306
1306
  let next = start;
1307
- start = () => fs2.writeFile(input, next);
1307
+ start = () => fs3.writeFile(input, next);
1308
1308
  }
1309
1309
  start(null);
1310
1310
  };
@@ -1553,10 +1553,10 @@ function sanitizeStringArray(values, property) {
1553
1553
  }
1554
1554
  return result;
1555
1555
  }
1556
- function convertOutputFiles({ path: path2, contents }) {
1556
+ function convertOutputFiles({ path: path3, contents }) {
1557
1557
  let text = null;
1558
1558
  return {
1559
- path: path2,
1559
+ path: path3,
1560
1560
  contents,
1561
1561
  get text() {
1562
1562
  if (text === null)
@@ -1566,12 +1566,100 @@ function convertOutputFiles({ path: path2, contents }) {
1566
1566
  };
1567
1567
  }
1568
1568
 
1569
+ // lib/npm/node-platform.ts
1570
+ var fs = require("fs");
1571
+ var os = require("os");
1572
+ var path = require("path");
1573
+ var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
1574
+ var knownWindowsPackages = {
1575
+ "win32 arm64 LE": "esbuild-windows-arm64",
1576
+ "win32 ia32 LE": "esbuild-windows-32",
1577
+ "win32 x64 LE": "esbuild-windows-64"
1578
+ };
1579
+ var knownUnixlikePackages = {
1580
+ "android arm64 LE": "esbuild-android-arm64",
1581
+ "darwin arm64 LE": "esbuild-darwin-arm64",
1582
+ "darwin x64 LE": "esbuild-darwin-64",
1583
+ "freebsd arm64 LE": "esbuild-freebsd-arm64",
1584
+ "freebsd x64 LE": "esbuild-freebsd-64",
1585
+ "openbsd x64 LE": "esbuild-openbsd-64",
1586
+ "linux arm LE": "esbuild-linux-arm",
1587
+ "linux arm64 LE": "esbuild-linux-arm64",
1588
+ "linux ia32 LE": "esbuild-linux-32",
1589
+ "linux mips64el LE": "esbuild-linux-mips64le",
1590
+ "linux ppc64 LE": "esbuild-linux-ppc64le",
1591
+ "linux x64 LE": "esbuild-linux-64",
1592
+ "sunos x64 LE": "esbuild-sunos-64"
1593
+ };
1594
+ function pkgAndBinForCurrentPlatform() {
1595
+ let pkg;
1596
+ let bin;
1597
+ let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
1598
+ if (platformKey in knownWindowsPackages) {
1599
+ pkg = knownWindowsPackages[platformKey];
1600
+ bin = `${pkg}/esbuild.exe`;
1601
+ } else if (platformKey in knownUnixlikePackages) {
1602
+ pkg = knownUnixlikePackages[platformKey];
1603
+ bin = `${pkg}/bin/esbuild`;
1604
+ } else {
1605
+ throw new Error(`Unsupported platform: ${platformKey}`);
1606
+ }
1607
+ try {
1608
+ bin = require.resolve(bin);
1609
+ } catch (e) {
1610
+ try {
1611
+ require.resolve(pkg);
1612
+ } catch (e2) {
1613
+ throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild.
1614
+
1615
+ If you are installing esbuild with npm, make sure that you don't specify the
1616
+ "--no-optional" flag. The "optionalDependencies" package.json feature is used
1617
+ by esbuild to install the correct binary executable for your current platform.`);
1618
+ }
1619
+ throw e;
1620
+ }
1621
+ return { pkg, bin };
1622
+ }
1623
+ function getCachePath(name) {
1624
+ const home = os.homedir();
1625
+ const common2 = ["esbuild", "bin", `${name}@${"0.13.0"}`];
1626
+ if (process.platform === "darwin")
1627
+ return path.join(home, "Library", "Caches", ...common2);
1628
+ if (process.platform === "win32")
1629
+ return path.join(home, "AppData", "Local", "Cache", ...common2);
1630
+ const XDG_CACHE_HOME = process.env.XDG_CACHE_HOME;
1631
+ if (process.platform === "linux" && XDG_CACHE_HOME && path.isAbsolute(XDG_CACHE_HOME))
1632
+ return path.join(XDG_CACHE_HOME, ...common2);
1633
+ return path.join(home, ".cache", ...common2);
1634
+ }
1635
+ function extractedBinPath() {
1636
+ if (ESBUILD_BINARY_PATH) {
1637
+ return ESBUILD_BINARY_PATH;
1638
+ }
1639
+ const { pkg, bin } = pkgAndBinForCurrentPlatform();
1640
+ let isYarnPnP = false;
1641
+ try {
1642
+ require("pnpapi");
1643
+ isYarnPnP = true;
1644
+ } catch (e) {
1645
+ }
1646
+ if (isYarnPnP) {
1647
+ const binTargetPath = getCachePath(pkg);
1648
+ if (!fs.existsSync(binTargetPath)) {
1649
+ fs.copyFileSync(bin, binTargetPath);
1650
+ fs.chmodSync(binTargetPath, 493);
1651
+ }
1652
+ return binTargetPath;
1653
+ }
1654
+ return bin;
1655
+ }
1656
+
1569
1657
  // lib/npm/node.ts
1570
1658
  var child_process = require("child_process");
1571
1659
  var crypto = require("crypto");
1572
- var path = require("path");
1573
- var fs = require("fs");
1574
- var os = require("os");
1660
+ var path2 = require("path");
1661
+ var fs2 = require("fs");
1662
+ var os2 = require("os");
1575
1663
  var tty = require("tty");
1576
1664
  var worker_threads;
1577
1665
  if (process.env.ESBUILD_WORKER_THREADS !== "0") {
@@ -1585,35 +1673,25 @@ if (process.env.ESBUILD_WORKER_THREADS !== "0") {
1585
1673
  }
1586
1674
  }
1587
1675
  var _a;
1588
- var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.12.26";
1676
+ var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.13.0";
1589
1677
  var esbuildCommandAndArgs = () => {
1590
- if (process.env.ESBUILD_BINARY_PATH) {
1591
- return [path.resolve(process.env.ESBUILD_BINARY_PATH), []];
1592
- }
1593
- if (path.basename(__filename) !== "main.js" || path.basename(__dirname) !== "lib") {
1678
+ if (path2.basename(__filename) !== "main.js" || path2.basename(__dirname) !== "lib") {
1594
1679
  throw new Error(`The esbuild JavaScript API cannot be bundled. Please mark the "esbuild" package as external so it's not included in the bundle.
1595
1680
 
1596
1681
  More information: The file containing the code for esbuild's JavaScript API (${__filename}) does not appear to be inside the esbuild package on the file system, which usually means that the esbuild package was bundled into another file. This is problematic because the API needs to run a binary executable inside the esbuild package which is located using a relative path from the API code to the executable. If the esbuild package is bundled, the relative path will be incorrect and the executable won't be found.`);
1597
1682
  }
1598
1683
  if (false) {
1599
- return ["node", [path.join(__dirname, "..", "bin", "esbuild")]];
1600
- }
1601
- if (process.platform === "win32") {
1602
- return [path.join(__dirname, "..", "esbuild.exe"), []];
1603
- }
1604
- let pathForYarn2 = path.join(__dirname, "..", "esbuild");
1605
- if (fs.existsSync(pathForYarn2)) {
1606
- return [pathForYarn2, []];
1684
+ return ["node", [path2.join(__dirname, "..", "bin", "esbuild")]];
1607
1685
  }
1608
- return [path.join(__dirname, "..", "bin", "esbuild"), []];
1686
+ return [extractedBinPath(), []];
1609
1687
  };
1610
1688
  var isTTY = () => tty.isatty(2);
1611
1689
  var fsSync = {
1612
1690
  readFile(tempFile, callback) {
1613
1691
  try {
1614
- let contents = fs.readFileSync(tempFile, "utf8");
1692
+ let contents = fs2.readFileSync(tempFile, "utf8");
1615
1693
  try {
1616
- fs.unlinkSync(tempFile);
1694
+ fs2.unlinkSync(tempFile);
1617
1695
  } catch (e) {
1618
1696
  }
1619
1697
  callback(null, contents);
@@ -1624,7 +1702,7 @@ var fsSync = {
1624
1702
  writeFile(contents, callback) {
1625
1703
  try {
1626
1704
  let tempFile = randomFileName();
1627
- fs.writeFileSync(tempFile, contents);
1705
+ fs2.writeFileSync(tempFile, contents);
1628
1706
  callback(tempFile);
1629
1707
  } catch (e) {
1630
1708
  callback(null);
@@ -1634,9 +1712,9 @@ var fsSync = {
1634
1712
  var fsAsync = {
1635
1713
  readFile(tempFile, callback) {
1636
1714
  try {
1637
- fs.readFile(tempFile, "utf8", (err, contents) => {
1715
+ fs2.readFile(tempFile, "utf8", (err, contents) => {
1638
1716
  try {
1639
- fs.unlink(tempFile, () => callback(err, contents));
1717
+ fs2.unlink(tempFile, () => callback(err, contents));
1640
1718
  } catch (e) {
1641
1719
  callback(err, contents);
1642
1720
  }
@@ -1648,13 +1726,13 @@ var fsAsync = {
1648
1726
  writeFile(contents, callback) {
1649
1727
  try {
1650
1728
  let tempFile = randomFileName();
1651
- fs.writeFile(tempFile, contents, (err) => err !== null ? callback(null) : callback(tempFile));
1729
+ fs2.writeFile(tempFile, contents, (err) => err !== null ? callback(null) : callback(tempFile));
1652
1730
  } catch (e) {
1653
1731
  callback(null);
1654
1732
  }
1655
1733
  }
1656
1734
  };
1657
- var version = "0.12.26";
1735
+ var version = "0.13.0";
1658
1736
  var build = (options) => ensureServiceIsRunning().build(options);
1659
1737
  var serve = (serveOptions, buildOptions) => ensureServiceIsRunning().serve(serveOptions, buildOptions);
1660
1738
  var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
@@ -1763,7 +1841,7 @@ var ensureServiceIsRunning = () => {
1763
1841
  if (longLivedService)
1764
1842
  return longLivedService;
1765
1843
  let [command, args] = esbuildCommandAndArgs();
1766
- let child = child_process.spawn(command, args.concat(`--service=${"0.12.26"}`, "--ping"), {
1844
+ let child = child_process.spawn(command, args.concat(`--service=${"0.13.0"}`, "--ping"), {
1767
1845
  windowsHide: true,
1768
1846
  stdio: ["pipe", "pipe", "inherit"],
1769
1847
  cwd: defaultWD
@@ -1772,7 +1850,7 @@ var ensureServiceIsRunning = () => {
1772
1850
  writeToStdin(bytes) {
1773
1851
  child.stdin.write(bytes);
1774
1852
  },
1775
- readFileSync: fs.readFileSync,
1853
+ readFileSync: fs2.readFileSync,
1776
1854
  isSync: false,
1777
1855
  isBrowser: false
1778
1856
  });
@@ -1870,7 +1948,7 @@ var runServiceSync = (callback) => {
1870
1948
  isBrowser: false
1871
1949
  });
1872
1950
  callback(service);
1873
- let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.12.26"}`), {
1951
+ let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.13.0"}`), {
1874
1952
  cwd: defaultWD,
1875
1953
  windowsHide: true,
1876
1954
  input: stdin,
@@ -1880,13 +1958,13 @@ var runServiceSync = (callback) => {
1880
1958
  afterClose();
1881
1959
  };
1882
1960
  var randomFileName = () => {
1883
- return path.join(os.tmpdir(), `esbuild-${crypto.randomBytes(32).toString("hex")}`);
1961
+ return path2.join(os2.tmpdir(), `esbuild-${crypto.randomBytes(32).toString("hex")}`);
1884
1962
  };
1885
1963
  var workerThreadService = null;
1886
1964
  var startWorkerThreadService = (worker_threads2) => {
1887
1965
  let { port1: mainPort, port2: workerPort } = new worker_threads2.MessageChannel();
1888
1966
  let worker = new worker_threads2.Worker(__filename, {
1889
- workerData: { workerPort, defaultWD, esbuildVersion: "0.12.26" },
1967
+ workerData: { workerPort, defaultWD, esbuildVersion: "0.13.0" },
1890
1968
  transferList: [workerPort],
1891
1969
  execArgv: []
1892
1970
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esbuild",
3
- "version": "0.12.26",
3
+ "version": "0.13.0",
4
4
  "description": "An extremely fast JavaScript bundler and minifier.",
5
5
  "repository": "https://github.com/evanw/esbuild",
6
6
  "scripts": {
@@ -11,5 +11,23 @@
11
11
  "bin": {
12
12
  "esbuild": "bin/esbuild"
13
13
  },
14
+ "optionalDependencies": {
15
+ "esbuild-android-arm64": "0.13.0",
16
+ "esbuild-darwin-64": "0.13.0",
17
+ "esbuild-darwin-arm64": "0.13.0",
18
+ "esbuild-freebsd-64": "0.13.0",
19
+ "esbuild-freebsd-arm64": "0.13.0",
20
+ "esbuild-linux-32": "0.13.0",
21
+ "esbuild-linux-64": "0.13.0",
22
+ "esbuild-linux-arm": "0.13.0",
23
+ "esbuild-linux-arm64": "0.13.0",
24
+ "esbuild-linux-mips64le": "0.13.0",
25
+ "esbuild-linux-ppc64le": "0.13.0",
26
+ "esbuild-openbsd-64": "0.13.0",
27
+ "esbuild-sunos-64": "0.13.0",
28
+ "esbuild-windows-32": "0.13.0",
29
+ "esbuild-windows-64": "0.13.0",
30
+ "esbuild-windows-arm64": "0.13.0"
31
+ },
14
32
  "license": "MIT"
15
33
  }