esbuild 0.25.2 → 0.25.4

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
@@ -200,7 +200,7 @@ for your current platform.`);
200
200
  "node_modules",
201
201
  ".cache",
202
202
  "esbuild",
203
- `pnpapi-${pkg.replace("/", "-")}-${"0.25.2"}-${path.basename(subpath)}`
203
+ `pnpapi-${pkg.replace("/", "-")}-${"0.25.4"}-${path.basename(subpath)}`
204
204
  );
205
205
  if (!fs.existsSync(binTargetPath)) {
206
206
  fs.mkdirSync(path.dirname(binTargetPath), { recursive: true });
package/lib/main.d.ts CHANGED
@@ -241,9 +241,15 @@ export interface ServeOptions {
241
241
  keyfile?: string
242
242
  certfile?: string
243
243
  fallback?: string
244
+ cors?: CORSOptions
244
245
  onRequest?: (args: ServeOnRequestArgs) => void
245
246
  }
246
247
 
248
+ /** Documentation: https://esbuild.github.io/api/#cors */
249
+ export interface CORSOptions {
250
+ origin?: string | string[]
251
+ }
252
+
247
253
  export interface ServeOnRequestArgs {
248
254
  remoteAddress: string
249
255
  method: string
package/lib/main.js CHANGED
@@ -218,10 +218,14 @@ function writeUInt32LE(buffer, value, offset) {
218
218
  var quote = JSON.stringify;
219
219
  var buildLogLevelDefault = "warning";
220
220
  var transformLogLevelDefault = "silent";
221
- function validateTarget(target) {
222
- validateStringValue(target, "target");
223
- if (target.indexOf(",") >= 0) throw new Error(`Invalid target: ${target}`);
224
- return target;
221
+ function validateAndJoinStringArray(values, what) {
222
+ const toJoin = [];
223
+ for (const value of values) {
224
+ validateStringValue(value, what);
225
+ if (value.indexOf(",") >= 0) throw new Error(`Invalid ${what}: ${value}`);
226
+ toJoin.push(value);
227
+ }
228
+ return toJoin.join(",");
225
229
  }
226
230
  var canBeAnything = () => null;
227
231
  var mustBeBoolean = (value) => typeof value === "boolean" ? null : "a boolean";
@@ -231,13 +235,14 @@ var mustBeInteger = (value) => typeof value === "number" && value === (value | 0
231
235
  var mustBeValidPortNumber = (value) => typeof value === "number" && value === (value | 0) && value >= 0 && value <= 65535 ? null : "a valid port number";
232
236
  var mustBeFunction = (value) => typeof value === "function" ? null : "a function";
233
237
  var mustBeArray = (value) => Array.isArray(value) ? null : "an array";
238
+ var mustBeArrayOfStrings = (value) => Array.isArray(value) && value.every((x) => typeof x === "string") ? null : "an array of strings";
234
239
  var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object";
235
240
  var mustBeEntryPoints = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
236
241
  var mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module";
237
242
  var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null";
238
243
  var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean";
239
244
  var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object";
240
- var mustBeStringOrArray = (value) => typeof value === "string" || Array.isArray(value) ? null : "a string or an array";
245
+ var mustBeStringOrArrayOfStrings = (value) => typeof value === "string" || Array.isArray(value) && value.every((x) => typeof x === "string") ? null : "a string or an array of strings";
241
246
  var mustBeStringOrUint8Array = (value) => typeof value === "string" || value instanceof Uint8Array ? null : "a string or a Uint8Array";
242
247
  var mustBeStringOrURL = (value) => typeof value === "string" || value instanceof URL ? null : "a string or a URL";
243
248
  function getFlag(object, keys, key, mustBeFn) {
@@ -301,7 +306,7 @@ function pushCommonFlags(flags, options, keys) {
301
306
  let legalComments = getFlag(options, keys, "legalComments", mustBeString);
302
307
  let sourceRoot = getFlag(options, keys, "sourceRoot", mustBeString);
303
308
  let sourcesContent = getFlag(options, keys, "sourcesContent", mustBeBoolean);
304
- let target = getFlag(options, keys, "target", mustBeStringOrArray);
309
+ let target = getFlag(options, keys, "target", mustBeStringOrArrayOfStrings);
305
310
  let format = getFlag(options, keys, "format", mustBeString);
306
311
  let globalName = getFlag(options, keys, "globalName", mustBeString);
307
312
  let mangleProps = getFlag(options, keys, "mangleProps", mustBeRegExp);
@@ -312,8 +317,8 @@ function pushCommonFlags(flags, options, keys) {
312
317
  let minifyWhitespace = getFlag(options, keys, "minifyWhitespace", mustBeBoolean);
313
318
  let minifyIdentifiers = getFlag(options, keys, "minifyIdentifiers", mustBeBoolean);
314
319
  let lineLimit = getFlag(options, keys, "lineLimit", mustBeInteger);
315
- let drop = getFlag(options, keys, "drop", mustBeArray);
316
- let dropLabels = getFlag(options, keys, "dropLabels", mustBeArray);
320
+ let drop = getFlag(options, keys, "drop", mustBeArrayOfStrings);
321
+ let dropLabels = getFlag(options, keys, "dropLabels", mustBeArrayOfStrings);
317
322
  let charset = getFlag(options, keys, "charset", mustBeString);
318
323
  let treeShaking = getFlag(options, keys, "treeShaking", mustBeBoolean);
319
324
  let ignoreAnnotations = getFlag(options, keys, "ignoreAnnotations", mustBeBoolean);
@@ -326,17 +331,14 @@ function pushCommonFlags(flags, options, keys) {
326
331
  let define = getFlag(options, keys, "define", mustBeObject);
327
332
  let logOverride = getFlag(options, keys, "logOverride", mustBeObject);
328
333
  let supported = getFlag(options, keys, "supported", mustBeObject);
329
- let pure = getFlag(options, keys, "pure", mustBeArray);
334
+ let pure = getFlag(options, keys, "pure", mustBeArrayOfStrings);
330
335
  let keepNames = getFlag(options, keys, "keepNames", mustBeBoolean);
331
336
  let platform = getFlag(options, keys, "platform", mustBeString);
332
337
  let tsconfigRaw = getFlag(options, keys, "tsconfigRaw", mustBeStringOrObject);
333
338
  if (legalComments) flags.push(`--legal-comments=${legalComments}`);
334
339
  if (sourceRoot !== void 0) flags.push(`--source-root=${sourceRoot}`);
335
340
  if (sourcesContent !== void 0) flags.push(`--sources-content=${sourcesContent}`);
336
- if (target) {
337
- if (Array.isArray(target)) flags.push(`--target=${Array.from(target).map(validateTarget).join(",")}`);
338
- else flags.push(`--target=${validateTarget(target)}`);
339
- }
341
+ if (target) flags.push(`--target=${validateAndJoinStringArray(Array.isArray(target) ? target : [target], "target")}`);
340
342
  if (format) flags.push(`--format=${format}`);
341
343
  if (globalName) flags.push(`--global-name=${globalName}`);
342
344
  if (platform) flags.push(`--platform=${platform}`);
@@ -350,7 +352,7 @@ function pushCommonFlags(flags, options, keys) {
350
352
  if (treeShaking !== void 0) flags.push(`--tree-shaking=${treeShaking}`);
351
353
  if (ignoreAnnotations) flags.push(`--ignore-annotations`);
352
354
  if (drop) for (let what of drop) flags.push(`--drop:${validateStringValue(what, "drop")}`);
353
- if (dropLabels) flags.push(`--drop-labels=${Array.from(dropLabels).map((what) => validateStringValue(what, "dropLabels")).join(",")}`);
355
+ if (dropLabels) flags.push(`--drop-labels=${validateAndJoinStringArray(dropLabels, "drop label")}`);
354
356
  if (mangleProps) flags.push(`--mangle-props=${jsRegExpToGoRegExp(mangleProps)}`);
355
357
  if (reserveProps) flags.push(`--reserve-props=${jsRegExpToGoRegExp(reserveProps)}`);
356
358
  if (mangleQuoted !== void 0) flags.push(`--mangle-quoted=${mangleQuoted}`);
@@ -401,11 +403,11 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
401
403
  let outdir = getFlag(options, keys, "outdir", mustBeString);
402
404
  let outbase = getFlag(options, keys, "outbase", mustBeString);
403
405
  let tsconfig = getFlag(options, keys, "tsconfig", mustBeString);
404
- let resolveExtensions = getFlag(options, keys, "resolveExtensions", mustBeArray);
405
- let nodePathsInput = getFlag(options, keys, "nodePaths", mustBeArray);
406
- let mainFields = getFlag(options, keys, "mainFields", mustBeArray);
407
- let conditions = getFlag(options, keys, "conditions", mustBeArray);
408
- let external = getFlag(options, keys, "external", mustBeArray);
406
+ let resolveExtensions = getFlag(options, keys, "resolveExtensions", mustBeArrayOfStrings);
407
+ let nodePathsInput = getFlag(options, keys, "nodePaths", mustBeArrayOfStrings);
408
+ let mainFields = getFlag(options, keys, "mainFields", mustBeArrayOfStrings);
409
+ let conditions = getFlag(options, keys, "conditions", mustBeArrayOfStrings);
410
+ let external = getFlag(options, keys, "external", mustBeArrayOfStrings);
409
411
  let packages = getFlag(options, keys, "packages", mustBeString);
410
412
  let alias = getFlag(options, keys, "alias", mustBeObject);
411
413
  let loader = getFlag(options, keys, "loader", mustBeObject);
@@ -414,7 +416,7 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
414
416
  let entryNames = getFlag(options, keys, "entryNames", mustBeString);
415
417
  let chunkNames = getFlag(options, keys, "chunkNames", mustBeString);
416
418
  let assetNames = getFlag(options, keys, "assetNames", mustBeString);
417
- let inject = getFlag(options, keys, "inject", mustBeArray);
419
+ let inject = getFlag(options, keys, "inject", mustBeArrayOfStrings);
418
420
  let banner = getFlag(options, keys, "banner", mustBeObject);
419
421
  let footer = getFlag(options, keys, "footer", mustBeObject);
420
422
  let entryPoints = getFlag(options, keys, "entryPoints", mustBeEntryPoints);
@@ -436,37 +438,13 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
436
438
  if (outbase) flags.push(`--outbase=${outbase}`);
437
439
  if (tsconfig) flags.push(`--tsconfig=${tsconfig}`);
438
440
  if (packages) flags.push(`--packages=${packages}`);
439
- if (resolveExtensions) {
440
- let values = [];
441
- for (let value of resolveExtensions) {
442
- validateStringValue(value, "resolve extension");
443
- if (value.indexOf(",") >= 0) throw new Error(`Invalid resolve extension: ${value}`);
444
- values.push(value);
445
- }
446
- flags.push(`--resolve-extensions=${values.join(",")}`);
447
- }
441
+ if (resolveExtensions) flags.push(`--resolve-extensions=${validateAndJoinStringArray(resolveExtensions, "resolve extension")}`);
448
442
  if (publicPath) flags.push(`--public-path=${publicPath}`);
449
443
  if (entryNames) flags.push(`--entry-names=${entryNames}`);
450
444
  if (chunkNames) flags.push(`--chunk-names=${chunkNames}`);
451
445
  if (assetNames) flags.push(`--asset-names=${assetNames}`);
452
- if (mainFields) {
453
- let values = [];
454
- for (let value of mainFields) {
455
- validateStringValue(value, "main field");
456
- if (value.indexOf(",") >= 0) throw new Error(`Invalid main field: ${value}`);
457
- values.push(value);
458
- }
459
- flags.push(`--main-fields=${values.join(",")}`);
460
- }
461
- if (conditions) {
462
- let values = [];
463
- for (let value of conditions) {
464
- validateStringValue(value, "condition");
465
- if (value.indexOf(",") >= 0) throw new Error(`Invalid condition: ${value}`);
466
- values.push(value);
467
- }
468
- flags.push(`--conditions=${values.join(",")}`);
469
- }
446
+ if (mainFields) flags.push(`--main-fields=${validateAndJoinStringArray(mainFields, "main field")}`);
447
+ if (conditions) flags.push(`--conditions=${validateAndJoinStringArray(conditions, "condition")}`);
470
448
  if (external) for (let name of external) flags.push(`--external:${validateStringValue(name, "external")}`);
471
449
  if (alias) {
472
450
  for (let old in alias) {
@@ -663,8 +641,8 @@ function createChannel(streamIn) {
663
641
  if (isFirstPacket) {
664
642
  isFirstPacket = false;
665
643
  let binaryVersion = String.fromCharCode(...bytes);
666
- if (binaryVersion !== "0.25.2") {
667
- throw new Error(`Cannot start service: Host version "${"0.25.2"}" does not match binary version ${quote(binaryVersion)}`);
644
+ if (binaryVersion !== "0.25.4") {
645
+ throw new Error(`Cannot start service: Host version "${"0.25.4"}" does not match binary version ${quote(binaryVersion)}`);
668
646
  }
669
647
  return;
670
648
  }
@@ -1025,6 +1003,7 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
1025
1003
  const keyfile = getFlag(options2, keys, "keyfile", mustBeString);
1026
1004
  const certfile = getFlag(options2, keys, "certfile", mustBeString);
1027
1005
  const fallback = getFlag(options2, keys, "fallback", mustBeString);
1006
+ const cors = getFlag(options2, keys, "cors", mustBeObject);
1028
1007
  const onRequest = getFlag(options2, keys, "onRequest", mustBeFunction);
1029
1008
  checkForInvalidFlags(options2, keys, `in serve() call`);
1030
1009
  const request2 = {
@@ -1038,6 +1017,13 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
1038
1017
  if (keyfile !== void 0) request2.keyfile = keyfile;
1039
1018
  if (certfile !== void 0) request2.certfile = certfile;
1040
1019
  if (fallback !== void 0) request2.fallback = fallback;
1020
+ if (cors) {
1021
+ const corsKeys = {};
1022
+ const origin = getFlag(cors, corsKeys, "origin", mustBeStringOrArrayOfStrings);
1023
+ checkForInvalidFlags(cors, corsKeys, `on "cors" object`);
1024
+ if (Array.isArray(origin)) request2.corsOrigin = origin;
1025
+ else if (origin !== void 0) request2.corsOrigin = [origin];
1026
+ }
1041
1027
  sendRequest(refs, request2, (error2, response2) => {
1042
1028
  if (error2) return reject(new Error(error2));
1043
1029
  if (onRequest) {
@@ -1245,8 +1231,8 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
1245
1231
  let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
1246
1232
  let errors = getFlag(result, keys, "errors", mustBeArray);
1247
1233
  let warnings = getFlag(result, keys, "warnings", mustBeArray);
1248
- let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
1249
- let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
1234
+ let watchFiles = getFlag(result, keys, "watchFiles", mustBeArrayOfStrings);
1235
+ let watchDirs = getFlag(result, keys, "watchDirs", mustBeArrayOfStrings);
1250
1236
  checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${quote(name)}`);
1251
1237
  response.id = id2;
1252
1238
  if (pluginName != null) response.pluginName = pluginName;
@@ -1291,8 +1277,8 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
1291
1277
  let loader = getFlag(result, keys, "loader", mustBeString);
1292
1278
  let errors = getFlag(result, keys, "errors", mustBeArray);
1293
1279
  let warnings = getFlag(result, keys, "warnings", mustBeArray);
1294
- let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
1295
- let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
1280
+ let watchFiles = getFlag(result, keys, "watchFiles", mustBeArrayOfStrings);
1281
+ let watchDirs = getFlag(result, keys, "watchDirs", mustBeArrayOfStrings);
1296
1282
  checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${quote(name)}`);
1297
1283
  response.id = id2;
1298
1284
  if (pluginName != null) response.pluginName = pluginName;
@@ -1779,7 +1765,7 @@ for your current platform.`);
1779
1765
  "node_modules",
1780
1766
  ".cache",
1781
1767
  "esbuild",
1782
- `pnpapi-${pkg.replace("/", "-")}-${"0.25.2"}-${path.basename(subpath)}`
1768
+ `pnpapi-${pkg.replace("/", "-")}-${"0.25.4"}-${path.basename(subpath)}`
1783
1769
  );
1784
1770
  if (!fs.existsSync(binTargetPath)) {
1785
1771
  fs.mkdirSync(path.dirname(binTargetPath), { recursive: true });
@@ -1814,7 +1800,7 @@ if (process.env.ESBUILD_WORKER_THREADS !== "0") {
1814
1800
  }
1815
1801
  }
1816
1802
  var _a;
1817
- var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.25.2";
1803
+ var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.25.4";
1818
1804
  var esbuildCommandAndArgs = () => {
1819
1805
  if ((!ESBUILD_BINARY_PATH || false) && (path2.basename(__filename) !== "main.js" || path2.basename(__dirname) !== "lib")) {
1820
1806
  throw new Error(
@@ -1881,7 +1867,7 @@ var fsAsync = {
1881
1867
  }
1882
1868
  }
1883
1869
  };
1884
- var version = "0.25.2";
1870
+ var version = "0.25.4";
1885
1871
  var build = (options) => ensureServiceIsRunning().build(options);
1886
1872
  var context = (buildOptions) => ensureServiceIsRunning().context(buildOptions);
1887
1873
  var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
@@ -1984,7 +1970,7 @@ var stopService;
1984
1970
  var ensureServiceIsRunning = () => {
1985
1971
  if (longLivedService) return longLivedService;
1986
1972
  let [command, args] = esbuildCommandAndArgs();
1987
- let child = child_process.spawn(command, args.concat(`--service=${"0.25.2"}`, "--ping"), {
1973
+ let child = child_process.spawn(command, args.concat(`--service=${"0.25.4"}`, "--ping"), {
1988
1974
  windowsHide: true,
1989
1975
  stdio: ["pipe", "pipe", "inherit"],
1990
1976
  cwd: defaultWD
@@ -2088,7 +2074,7 @@ var runServiceSync = (callback) => {
2088
2074
  esbuild: node_exports
2089
2075
  });
2090
2076
  callback(service);
2091
- let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.25.2"}`), {
2077
+ let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.25.4"}`), {
2092
2078
  cwd: defaultWD,
2093
2079
  windowsHide: true,
2094
2080
  input: stdin,
@@ -2108,7 +2094,7 @@ var workerThreadService = null;
2108
2094
  var startWorkerThreadService = (worker_threads2) => {
2109
2095
  let { port1: mainPort, port2: workerPort } = new worker_threads2.MessageChannel();
2110
2096
  let worker = new worker_threads2.Worker(__filename, {
2111
- workerData: { workerPort, defaultWD, esbuildVersion: "0.25.2" },
2097
+ workerData: { workerPort, defaultWD, esbuildVersion: "0.25.4" },
2112
2098
  transferList: [workerPort],
2113
2099
  // From node's documentation: https://nodejs.org/api/worker_threads.html
2114
2100
  //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esbuild",
3
- "version": "0.25.2",
3
+ "version": "0.25.4",
4
4
  "description": "An extremely fast JavaScript and CSS bundler and minifier.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,31 +18,31 @@
18
18
  "esbuild": "bin/esbuild"
19
19
  },
20
20
  "optionalDependencies": {
21
- "@esbuild/aix-ppc64": "0.25.2",
22
- "@esbuild/android-arm": "0.25.2",
23
- "@esbuild/android-arm64": "0.25.2",
24
- "@esbuild/android-x64": "0.25.2",
25
- "@esbuild/darwin-arm64": "0.25.2",
26
- "@esbuild/darwin-x64": "0.25.2",
27
- "@esbuild/freebsd-arm64": "0.25.2",
28
- "@esbuild/freebsd-x64": "0.25.2",
29
- "@esbuild/linux-arm": "0.25.2",
30
- "@esbuild/linux-arm64": "0.25.2",
31
- "@esbuild/linux-ia32": "0.25.2",
32
- "@esbuild/linux-loong64": "0.25.2",
33
- "@esbuild/linux-mips64el": "0.25.2",
34
- "@esbuild/linux-ppc64": "0.25.2",
35
- "@esbuild/linux-riscv64": "0.25.2",
36
- "@esbuild/linux-s390x": "0.25.2",
37
- "@esbuild/linux-x64": "0.25.2",
38
- "@esbuild/netbsd-arm64": "0.25.2",
39
- "@esbuild/netbsd-x64": "0.25.2",
40
- "@esbuild/openbsd-arm64": "0.25.2",
41
- "@esbuild/openbsd-x64": "0.25.2",
42
- "@esbuild/sunos-x64": "0.25.2",
43
- "@esbuild/win32-arm64": "0.25.2",
44
- "@esbuild/win32-ia32": "0.25.2",
45
- "@esbuild/win32-x64": "0.25.2"
21
+ "@esbuild/aix-ppc64": "0.25.4",
22
+ "@esbuild/android-arm": "0.25.4",
23
+ "@esbuild/android-arm64": "0.25.4",
24
+ "@esbuild/android-x64": "0.25.4",
25
+ "@esbuild/darwin-arm64": "0.25.4",
26
+ "@esbuild/darwin-x64": "0.25.4",
27
+ "@esbuild/freebsd-arm64": "0.25.4",
28
+ "@esbuild/freebsd-x64": "0.25.4",
29
+ "@esbuild/linux-arm": "0.25.4",
30
+ "@esbuild/linux-arm64": "0.25.4",
31
+ "@esbuild/linux-ia32": "0.25.4",
32
+ "@esbuild/linux-loong64": "0.25.4",
33
+ "@esbuild/linux-mips64el": "0.25.4",
34
+ "@esbuild/linux-ppc64": "0.25.4",
35
+ "@esbuild/linux-riscv64": "0.25.4",
36
+ "@esbuild/linux-s390x": "0.25.4",
37
+ "@esbuild/linux-x64": "0.25.4",
38
+ "@esbuild/netbsd-arm64": "0.25.4",
39
+ "@esbuild/netbsd-x64": "0.25.4",
40
+ "@esbuild/openbsd-arm64": "0.25.4",
41
+ "@esbuild/openbsd-x64": "0.25.4",
42
+ "@esbuild/sunos-x64": "0.25.4",
43
+ "@esbuild/win32-arm64": "0.25.4",
44
+ "@esbuild/win32-ia32": "0.25.4",
45
+ "@esbuild/win32-x64": "0.25.4"
46
46
  },
47
47
  "license": "MIT"
48
48
  }