esbuild 0.12.29 → 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,184 +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
- const fs = require("fs");
21
- const os = require("os");
22
- const path = require("path");
23
- const zlib = require("zlib");
24
- const https = require("https");
25
- const child_process = require("child_process");
26
- const version = "0.12.29";
27
- const binPath = path.join(__dirname, "bin", "esbuild");
28
- async function installBinaryFromPackage(name, fromPath, toPath) {
29
- const cachePath = getCachePath(name);
30
- try {
31
- fs.copyFileSync(cachePath, toPath);
32
- fs.chmodSync(toPath, 493);
33
- validateBinaryVersion(toPath);
34
- const now = new Date();
35
- fs.utimesSync(cachePath, now, now);
36
- return;
37
- } catch (e) {
38
- }
39
- let buffer;
40
- let didFail = false;
41
- try {
42
- buffer = installUsingNPM(name, fromPath);
43
- } catch (err) {
44
- didFail = true;
45
- console.error(`Trying to install "${name}" using npm`);
46
- console.error(`Failed to install "${name}" using npm: ${err && err.message || err}`);
47
- }
48
- if (!buffer) {
49
- const url = `https://registry.npmjs.org/${name}/-/${name}-${version}.tgz`;
50
- console.error(`Trying to download ${JSON.stringify(url)}`);
51
- try {
52
- buffer = extractFileFromTarGzip(await fetch(url), fromPath);
53
- } catch (err) {
54
- console.error(`Failed to download ${JSON.stringify(url)}: ${err && err.message || err}`);
55
- }
56
- }
57
- if (!buffer) {
58
- console.error(`Install unsuccessful`);
59
- process.exit(1);
60
- }
61
- fs.writeFileSync(toPath, buffer, { mode: 493 });
62
- try {
63
- validateBinaryVersion(toPath);
64
- } catch (err) {
65
- console.error(`The version of the downloaded binary is incorrect: ${err && err.message || err}`);
66
- console.error(`Install unsuccessful`);
67
- process.exit(1);
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"
25
+ };
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}`);
68
38
  }
69
39
  try {
70
- fs.mkdirSync(path.dirname(cachePath), {
71
- recursive: true,
72
- mode: 448
73
- });
74
- fs.copyFileSync(toPath, cachePath);
75
- cleanCacheLRU(cachePath);
40
+ bin = require.resolve(bin);
76
41
  } catch (e) {
77
- }
78
- if (didFail)
79
- console.error(`Install successful`);
80
- }
81
- function validateBinaryVersion(binaryPath) {
82
- const stdout = child_process.execFileSync(binaryPath, ["--version"]).toString().trim();
83
- if (stdout !== version) {
84
- throw new Error(`Expected ${JSON.stringify(version)} but got ${JSON.stringify(stdout)}`);
85
- }
86
- }
87
- function getCachePath(name) {
88
- const home = os.homedir();
89
- const common = ["esbuild", "bin", `${name}@${version}`];
90
- if (process.platform === "darwin")
91
- return path.join(home, "Library", "Caches", ...common);
92
- if (process.platform === "win32")
93
- return path.join(home, "AppData", "Local", "Cache", ...common);
94
- const XDG_CACHE_HOME = process.env.XDG_CACHE_HOME;
95
- if (process.platform === "linux" && XDG_CACHE_HOME && path.isAbsolute(XDG_CACHE_HOME))
96
- return path.join(XDG_CACHE_HOME, ...common);
97
- return path.join(home, ".cache", ...common);
98
- }
99
- function cleanCacheLRU(fileToKeep) {
100
- const dir = path.dirname(fileToKeep);
101
- const entries = [];
102
- for (const entry of fs.readdirSync(dir)) {
103
- const entryPath = path.join(dir, entry);
104
42
  try {
105
- const stats = fs.statSync(entryPath);
106
- entries.push({ path: entryPath, mtime: stats.mtime });
107
- } catch (e) {
108
- }
109
- }
110
- entries.sort((a, b) => +b.mtime - +a.mtime);
111
- for (const entry of entries.slice(5)) {
112
- try {
113
- fs.unlinkSync(entry.path);
114
- } catch (e) {
115
- }
116
- }
117
- }
118
- function fetch(url) {
119
- return new Promise((resolve, reject) => {
120
- https.get(url, (res) => {
121
- if ((res.statusCode === 301 || res.statusCode === 302) && res.headers.location)
122
- return fetch(res.headers.location).then(resolve, reject);
123
- if (res.statusCode !== 200)
124
- return reject(new Error(`Server responded with ${res.statusCode}`));
125
- let chunks = [];
126
- res.on("data", (chunk) => chunks.push(chunk));
127
- res.on("end", () => resolve(Buffer.concat(chunks)));
128
- }).on("error", reject);
129
- });
130
- }
131
- function extractFileFromTarGzip(buffer, file) {
132
- try {
133
- buffer = zlib.unzipSync(buffer);
134
- } catch (err) {
135
- throw new Error(`Invalid gzip data in archive: ${err && err.message || err}`);
136
- }
137
- let str = (i, n) => String.fromCharCode(...buffer.subarray(i, i + n)).replace(/\0.*$/, "");
138
- let offset = 0;
139
- file = `package/${file}`;
140
- while (offset < buffer.length) {
141
- let name = str(offset, 100);
142
- let size = parseInt(str(offset + 124, 12), 8);
143
- offset += 512;
144
- if (!isNaN(size)) {
145
- if (name === file)
146
- return buffer.subarray(offset, offset + size);
147
- offset += size + 511 & ~511;
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.`);
148
50
  }
51
+ throw e;
149
52
  }
150
- throw new Error(`Could not find ${JSON.stringify(file)} in archive`);
151
- }
152
- function installUsingNPM(name, file) {
153
- const installDir = path.join(os.tmpdir(), "esbuild-" + Math.random().toString(36).slice(2));
154
- fs.mkdirSync(installDir, { recursive: true });
155
- fs.writeFileSync(path.join(installDir, "package.json"), "{}");
156
- const env = __spreadProps(__spreadValues({}, process.env), { npm_config_global: void 0 });
157
- child_process.execSync(`npm install --loglevel=error --prefer-offline --no-audit --progress=false ${name}@${version}`, { cwd: installDir, stdio: "pipe", env });
158
- const buffer = fs.readFileSync(path.join(installDir, "node_modules", name, file));
159
- try {
160
- removeRecursive(installDir);
161
- } catch (e) {
162
- }
163
- return buffer;
53
+ return { pkg, bin };
164
54
  }
165
- function removeRecursive(dir) {
166
- for (const entry of fs.readdirSync(dir)) {
167
- const entryPath = path.join(dir, entry);
168
- let stats;
169
- try {
170
- stats = fs.lstatSync(entryPath);
171
- } catch (e) {
172
- continue;
173
- }
174
- if (stats.isDirectory())
175
- removeRecursive(entryPath);
176
- else
177
- fs.unlinkSync(entryPath);
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)}`);
178
67
  }
179
- fs.rmdirSync(dir);
180
68
  }
181
- function isYarnBerryOrNewer() {
69
+ function isYarn2OrAbove() {
182
70
  const { npm_config_user_agent } = process.env;
183
71
  if (npm_config_user_agent) {
184
72
  const match = npm_config_user_agent.match(/yarn\/(\d+)/);
@@ -188,71 +76,24 @@ function isYarnBerryOrNewer() {
188
76
  }
189
77
  return false;
190
78
  }
191
- function installDirectly(name) {
192
- if (process.env.ESBUILD_BINARY_PATH) {
193
- fs.copyFileSync(process.env.ESBUILD_BINARY_PATH, binPath);
194
- validateBinaryVersion(binPath);
195
- } else {
196
- const tempBinPath = binPath + "__";
197
- installBinaryFromPackage(name, "bin/esbuild", tempBinPath).then(() => fs.renameSync(tempBinPath, binPath)).catch((e) => setImmediate(() => {
198
- throw e;
199
- }));
200
- }
201
- }
202
- function installWithWrapper(name, fromPath, toPath) {
203
- fs.writeFileSync(binPath, `#!/usr/bin/env node
204
- const path = require('path');
205
- const esbuild_exe = path.join(__dirname, '..', ${JSON.stringify(toPath)});
206
- const child_process = require('child_process');
207
- const { status } = child_process.spawnSync(esbuild_exe, process.argv.slice(2), { stdio: 'inherit' });
208
- 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' });
209
83
  `);
210
- const absToPath = path.join(__dirname, toPath);
211
- if (process.env.ESBUILD_BINARY_PATH) {
212
- fs.copyFileSync(process.env.ESBUILD_BINARY_PATH, absToPath);
213
- validateBinaryVersion(absToPath);
214
- } else {
215
- installBinaryFromPackage(name, fromPath, absToPath).catch((e) => setImmediate(() => {
216
- throw e;
217
- }));
218
- }
219
- }
220
- function installOnUnix(name) {
221
- if (isYarnBerryOrNewer()) {
222
- installWithWrapper(name, "bin/esbuild", "esbuild");
223
- } else {
224
- 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) {
225
95
  }
226
- }
227
- function installOnWindows(name) {
228
- installWithWrapper(name, "esbuild.exe", "esbuild.exe");
229
- }
230
- const platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
231
- const knownWindowsPackages = {
232
- "win32 arm64 LE": "esbuild-windows-arm64",
233
- "win32 ia32 LE": "esbuild-windows-32",
234
- "win32 x64 LE": "esbuild-windows-64"
235
- };
236
- const knownUnixlikePackages = {
237
- "android arm64 LE": "esbuild-android-arm64",
238
- "darwin arm64 LE": "esbuild-darwin-arm64",
239
- "darwin x64 LE": "esbuild-darwin-64",
240
- "freebsd arm64 LE": "esbuild-freebsd-arm64",
241
- "freebsd x64 LE": "esbuild-freebsd-64",
242
- "openbsd x64 LE": "esbuild-openbsd-64",
243
- "linux arm LE": "esbuild-linux-arm",
244
- "linux arm64 LE": "esbuild-linux-arm64",
245
- "linux ia32 LE": "esbuild-linux-32",
246
- "linux mips64el LE": "esbuild-linux-mips64le",
247
- "linux ppc64 LE": "esbuild-linux-ppc64le",
248
- "linux x64 LE": "esbuild-linux-64",
249
- "sunos x64 LE": "esbuild-sunos-64"
250
- };
251
- if (platformKey in knownWindowsPackages) {
252
- installOnWindows(knownWindowsPackages[platformKey]);
253
- } else if (platformKey in knownUnixlikePackages) {
254
- installOnUnix(knownUnixlikePackages[platformKey]);
96
+ validateBinaryVersion(toPath);
255
97
  } else {
256
- console.error(`Unsupported platform: ${platformKey}`);
257
- process.exit(1);
98
+ validateBinaryVersion("node", toPath);
258
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
@@ -275,7 +275,8 @@ function pushCommonFlags(flags, options, keys) {
275
275
  let minifyWhitespace = getFlag(options, keys, "minifyWhitespace", mustBeBoolean);
276
276
  let minifyIdentifiers = getFlag(options, keys, "minifyIdentifiers", mustBeBoolean);
277
277
  let charset = getFlag(options, keys, "charset", mustBeString);
278
- let treeShaking = getFlag(options, keys, "treeShaking", mustBeStringOrBoolean);
278
+ let treeShaking = getFlag(options, keys, "treeShaking", mustBeBoolean);
279
+ let ignoreAnnotations = getFlag(options, keys, "ignoreAnnotations", mustBeBoolean);
279
280
  let jsx = getFlag(options, keys, "jsx", mustBeString);
280
281
  let jsxFactory = getFlag(options, keys, "jsxFactory", mustBeString);
281
282
  let jsxFragment = getFlag(options, keys, "jsxFragment", mustBeString);
@@ -308,8 +309,10 @@ function pushCommonFlags(flags, options, keys) {
308
309
  flags.push("--minify-identifiers");
309
310
  if (charset)
310
311
  flags.push(`--charset=${charset}`);
311
- if (treeShaking !== void 0 && treeShaking !== true)
312
+ if (treeShaking !== void 0)
312
313
  flags.push(`--tree-shaking=${treeShaking}`);
314
+ if (ignoreAnnotations)
315
+ flags.push(`--ignore-annotations`);
313
316
  if (jsx)
314
317
  flags.push(`--jsx=${jsx}`);
315
318
  if (jsxFactory)
@@ -461,8 +464,8 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
461
464
  }
462
465
  }
463
466
  if (inject)
464
- for (let path2 of inject)
465
- flags.push(`--inject:${path2}`);
467
+ for (let path3 of inject)
468
+ flags.push(`--inject:${path3}`);
466
469
  if (loader) {
467
470
  for (let ext in loader) {
468
471
  if (ext.indexOf("=") >= 0)
@@ -691,8 +694,8 @@ function createChannel(streamIn) {
691
694
  if (isFirstPacket) {
692
695
  isFirstPacket = false;
693
696
  let binaryVersion = String.fromCharCode(...bytes);
694
- if (binaryVersion !== "0.12.29") {
695
- throw new Error(`Cannot start service: Host version "${"0.12.29"}" 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)}`);
696
699
  }
697
700
  return;
698
701
  }
@@ -824,7 +827,7 @@ function createChannel(streamIn) {
824
827
  throw new Error(`Expected onResolve() callback in plugin ${JSON.stringify(name)} to return an object`);
825
828
  let keys = {};
826
829
  let pluginName = getFlag(result, keys, "pluginName", mustBeString);
827
- let path2 = getFlag(result, keys, "path", mustBeString);
830
+ let path3 = getFlag(result, keys, "path", mustBeString);
828
831
  let namespace = getFlag(result, keys, "namespace", mustBeString);
829
832
  let external = getFlag(result, keys, "external", mustBeBoolean);
830
833
  let sideEffects = getFlag(result, keys, "sideEffects", mustBeBoolean);
@@ -837,8 +840,8 @@ function createChannel(streamIn) {
837
840
  response.id = id;
838
841
  if (pluginName != null)
839
842
  response.pluginName = pluginName;
840
- if (path2 != null)
841
- response.path = path2;
843
+ if (path3 != null)
844
+ response.path = path3;
842
845
  if (namespace != null)
843
846
  response.namespace = namespace;
844
847
  if (external != null)
@@ -1240,7 +1243,7 @@ function createChannel(streamIn) {
1240
1243
  return buildResponseToResult(response, callback);
1241
1244
  });
1242
1245
  };
1243
- let transform2 = ({ callName, refs, input, options, isTTY: isTTY2, fs: fs2, callback }) => {
1246
+ let transform2 = ({ callName, refs, input, options, isTTY: isTTY2, fs: fs3, callback }) => {
1244
1247
  const details = createObjectStash();
1245
1248
  let start = (inputPath) => {
1246
1249
  try {
@@ -1264,7 +1267,7 @@ function createChannel(streamIn) {
1264
1267
  return callback(failureErrorWithLog("Transform failed", errors, warnings), null);
1265
1268
  if (response.codeFS) {
1266
1269
  outstanding++;
1267
- fs2.readFile(response.code, (err, contents) => {
1270
+ fs3.readFile(response.code, (err, contents) => {
1268
1271
  if (err !== null) {
1269
1272
  callback(err, null);
1270
1273
  } else {
@@ -1275,7 +1278,7 @@ function createChannel(streamIn) {
1275
1278
  }
1276
1279
  if (response.mapFS) {
1277
1280
  outstanding++;
1278
- fs2.readFile(response.map, (err, contents) => {
1281
+ fs3.readFile(response.map, (err, contents) => {
1279
1282
  if (err !== null) {
1280
1283
  callback(err, null);
1281
1284
  } else {
@@ -1301,7 +1304,7 @@ function createChannel(streamIn) {
1301
1304
  };
1302
1305
  if (typeof input === "string" && input.length > 1024 * 1024) {
1303
1306
  let next = start;
1304
- start = () => fs2.writeFile(input, next);
1307
+ start = () => fs3.writeFile(input, next);
1305
1308
  }
1306
1309
  start(null);
1307
1310
  };
@@ -1550,10 +1553,10 @@ function sanitizeStringArray(values, property) {
1550
1553
  }
1551
1554
  return result;
1552
1555
  }
1553
- function convertOutputFiles({ path: path2, contents }) {
1556
+ function convertOutputFiles({ path: path3, contents }) {
1554
1557
  let text = null;
1555
1558
  return {
1556
- path: path2,
1559
+ path: path3,
1557
1560
  contents,
1558
1561
  get text() {
1559
1562
  if (text === null)
@@ -1563,12 +1566,100 @@ function convertOutputFiles({ path: path2, contents }) {
1563
1566
  };
1564
1567
  }
1565
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
+
1566
1657
  // lib/npm/node.ts
1567
1658
  var child_process = require("child_process");
1568
1659
  var crypto = require("crypto");
1569
- var path = require("path");
1570
- var fs = require("fs");
1571
- var os = require("os");
1660
+ var path2 = require("path");
1661
+ var fs2 = require("fs");
1662
+ var os2 = require("os");
1572
1663
  var tty = require("tty");
1573
1664
  var worker_threads;
1574
1665
  if (process.env.ESBUILD_WORKER_THREADS !== "0") {
@@ -1582,35 +1673,25 @@ if (process.env.ESBUILD_WORKER_THREADS !== "0") {
1582
1673
  }
1583
1674
  }
1584
1675
  var _a;
1585
- var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.12.29";
1676
+ var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.13.0";
1586
1677
  var esbuildCommandAndArgs = () => {
1587
- if (process.env.ESBUILD_BINARY_PATH) {
1588
- return [path.resolve(process.env.ESBUILD_BINARY_PATH), []];
1589
- }
1590
- if (path.basename(__filename) !== "main.js" || path.basename(__dirname) !== "lib") {
1678
+ if (path2.basename(__filename) !== "main.js" || path2.basename(__dirname) !== "lib") {
1591
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.
1592
1680
 
1593
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.`);
1594
1682
  }
1595
1683
  if (false) {
1596
- return ["node", [path.join(__dirname, "..", "bin", "esbuild")]];
1597
- }
1598
- if (process.platform === "win32") {
1599
- return [path.join(__dirname, "..", "esbuild.exe"), []];
1600
- }
1601
- let pathForYarn2 = path.join(__dirname, "..", "esbuild");
1602
- if (fs.existsSync(pathForYarn2)) {
1603
- return [pathForYarn2, []];
1684
+ return ["node", [path2.join(__dirname, "..", "bin", "esbuild")]];
1604
1685
  }
1605
- return [path.join(__dirname, "..", "bin", "esbuild"), []];
1686
+ return [extractedBinPath(), []];
1606
1687
  };
1607
1688
  var isTTY = () => tty.isatty(2);
1608
1689
  var fsSync = {
1609
1690
  readFile(tempFile, callback) {
1610
1691
  try {
1611
- let contents = fs.readFileSync(tempFile, "utf8");
1692
+ let contents = fs2.readFileSync(tempFile, "utf8");
1612
1693
  try {
1613
- fs.unlinkSync(tempFile);
1694
+ fs2.unlinkSync(tempFile);
1614
1695
  } catch (e) {
1615
1696
  }
1616
1697
  callback(null, contents);
@@ -1621,7 +1702,7 @@ var fsSync = {
1621
1702
  writeFile(contents, callback) {
1622
1703
  try {
1623
1704
  let tempFile = randomFileName();
1624
- fs.writeFileSync(tempFile, contents);
1705
+ fs2.writeFileSync(tempFile, contents);
1625
1706
  callback(tempFile);
1626
1707
  } catch (e) {
1627
1708
  callback(null);
@@ -1631,9 +1712,9 @@ var fsSync = {
1631
1712
  var fsAsync = {
1632
1713
  readFile(tempFile, callback) {
1633
1714
  try {
1634
- fs.readFile(tempFile, "utf8", (err, contents) => {
1715
+ fs2.readFile(tempFile, "utf8", (err, contents) => {
1635
1716
  try {
1636
- fs.unlink(tempFile, () => callback(err, contents));
1717
+ fs2.unlink(tempFile, () => callback(err, contents));
1637
1718
  } catch (e) {
1638
1719
  callback(err, contents);
1639
1720
  }
@@ -1645,13 +1726,13 @@ var fsAsync = {
1645
1726
  writeFile(contents, callback) {
1646
1727
  try {
1647
1728
  let tempFile = randomFileName();
1648
- fs.writeFile(tempFile, contents, (err) => err !== null ? callback(null) : callback(tempFile));
1729
+ fs2.writeFile(tempFile, contents, (err) => err !== null ? callback(null) : callback(tempFile));
1649
1730
  } catch (e) {
1650
1731
  callback(null);
1651
1732
  }
1652
1733
  }
1653
1734
  };
1654
- var version = "0.12.29";
1735
+ var version = "0.13.0";
1655
1736
  var build = (options) => ensureServiceIsRunning().build(options);
1656
1737
  var serve = (serveOptions, buildOptions) => ensureServiceIsRunning().serve(serveOptions, buildOptions);
1657
1738
  var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
@@ -1760,7 +1841,7 @@ var ensureServiceIsRunning = () => {
1760
1841
  if (longLivedService)
1761
1842
  return longLivedService;
1762
1843
  let [command, args] = esbuildCommandAndArgs();
1763
- let child = child_process.spawn(command, args.concat(`--service=${"0.12.29"}`, "--ping"), {
1844
+ let child = child_process.spawn(command, args.concat(`--service=${"0.13.0"}`, "--ping"), {
1764
1845
  windowsHide: true,
1765
1846
  stdio: ["pipe", "pipe", "inherit"],
1766
1847
  cwd: defaultWD
@@ -1769,7 +1850,7 @@ var ensureServiceIsRunning = () => {
1769
1850
  writeToStdin(bytes) {
1770
1851
  child.stdin.write(bytes);
1771
1852
  },
1772
- readFileSync: fs.readFileSync,
1853
+ readFileSync: fs2.readFileSync,
1773
1854
  isSync: false,
1774
1855
  isBrowser: false
1775
1856
  });
@@ -1867,7 +1948,7 @@ var runServiceSync = (callback) => {
1867
1948
  isBrowser: false
1868
1949
  });
1869
1950
  callback(service);
1870
- let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.12.29"}`), {
1951
+ let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.13.0"}`), {
1871
1952
  cwd: defaultWD,
1872
1953
  windowsHide: true,
1873
1954
  input: stdin,
@@ -1877,13 +1958,13 @@ var runServiceSync = (callback) => {
1877
1958
  afterClose();
1878
1959
  };
1879
1960
  var randomFileName = () => {
1880
- return path.join(os.tmpdir(), `esbuild-${crypto.randomBytes(32).toString("hex")}`);
1961
+ return path2.join(os2.tmpdir(), `esbuild-${crypto.randomBytes(32).toString("hex")}`);
1881
1962
  };
1882
1963
  var workerThreadService = null;
1883
1964
  var startWorkerThreadService = (worker_threads2) => {
1884
1965
  let { port1: mainPort, port2: workerPort } = new worker_threads2.MessageChannel();
1885
1966
  let worker = new worker_threads2.Worker(__filename, {
1886
- workerData: { workerPort, defaultWD, esbuildVersion: "0.12.29" },
1967
+ workerData: { workerPort, defaultWD, esbuildVersion: "0.13.0" },
1887
1968
  transferList: [workerPort],
1888
1969
  execArgv: []
1889
1970
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esbuild",
3
- "version": "0.12.29",
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
  }