esbuild 0.8.40 → 0.8.44

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/install.js CHANGED
@@ -27,7 +27,7 @@ const path = require("path");
27
27
  const zlib = require("zlib");
28
28
  const https = require("https");
29
29
  const child_process = require("child_process");
30
- const version = "0.8.40";
30
+ const version = "0.8.44";
31
31
  const binPath = path.join(__dirname, "bin", "esbuild");
32
32
  function installBinaryFromPackage(name, fromPath, toPath) {
33
33
  return __async(this, null, function* () {
@@ -72,7 +72,10 @@ function installBinaryFromPackage(name, fromPath, toPath) {
72
72
  process.exit(1);
73
73
  }
74
74
  try {
75
- fs.mkdirSync(path.dirname(cachePath), {recursive: true});
75
+ fs.mkdirSync(path.dirname(cachePath), {
76
+ recursive: true,
77
+ mode: 448
78
+ });
76
79
  fs.copyFileSync(toPath, cachePath);
77
80
  cleanCacheLRU(cachePath);
78
81
  } catch (e) {
@@ -107,6 +110,9 @@ function getCachePath(name) {
107
110
  return path.join(home, "Library", "Caches", ...common);
108
111
  if (process.platform === "win32")
109
112
  return path.join(home, "AppData", "Local", "Cache", ...common);
113
+ const XDG_CACHE_HOME = process.env.XDG_CACHE_HOME;
114
+ if (process.platform === "linux" && XDG_CACHE_HOME && path.isAbsolute(XDG_CACHE_HOME))
115
+ return path.join(XDG_CACHE_HOME, ...common);
110
116
  return path.join(home, ".cache", ...common);
111
117
  }
112
118
  function cleanCacheLRU(fileToKeep) {
package/lib/main.d.ts CHANGED
@@ -37,6 +37,7 @@ interface CommonOptions {
37
37
  export interface BuildOptions extends CommonOptions {
38
38
  bundle?: boolean;
39
39
  splitting?: boolean;
40
+ preserveSymlinks?: boolean;
40
41
  outfile?: string;
41
42
  metafile?: string;
42
43
  outdir?: string;
@@ -56,6 +57,7 @@ export interface BuildOptions extends CommonOptions {
56
57
  stdin?: StdinOptions;
57
58
  plugins?: Plugin[];
58
59
  absWorkingDir?: string;
60
+ nodePaths?: string[]; // The "NODE_PATH" variable from Node.js
59
61
  watch?: boolean | WatchMode;
60
62
  }
61
63
 
@@ -73,12 +75,18 @@ export interface StdinOptions {
73
75
  export interface Message {
74
76
  text: string;
75
77
  location: Location | null;
78
+ notes: Note[];
76
79
 
77
80
  // Optional user-specified data that is passed through unmodified. You can
78
81
  // use this to stash the original error, for example.
79
82
  detail: any;
80
83
  }
81
84
 
85
+ export interface Note {
86
+ text: string;
87
+ location: Location | null;
88
+ }
89
+
82
90
  export interface Location {
83
91
  file: string;
84
92
  namespace: string;
@@ -224,9 +232,15 @@ export interface OnLoadResult {
224
232
  export interface PartialMessage {
225
233
  text?: string;
226
234
  location?: Partial<Location> | null;
235
+ notes?: PartialNote[];
227
236
  detail?: any;
228
237
  }
229
238
 
239
+ export interface PartialNote {
240
+ text?: string;
241
+ location?: Partial<Location> | null;
242
+ }
243
+
230
244
  export type MetadataImportKind =
231
245
  // JS
232
246
  | 'import-statement'
package/lib/main.js CHANGED
@@ -2,7 +2,6 @@ var __defProp = Object.defineProperty;
2
2
  var __assign = Object.assign;
3
3
  var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
4
4
  var __export = (target, all) => {
5
- __markAsModule(target);
6
5
  for (var name in all)
7
6
  __defProp(target, name, {get: all[name], enumerable: true});
8
7
  };
@@ -30,6 +29,7 @@ var __async = (__this, __arguments, generator) => {
30
29
  };
31
30
 
32
31
  // lib/node.ts
32
+ __markAsModule(exports);
33
33
  __export(exports, {
34
34
  build: () => build,
35
35
  buildSync: () => buildSync,
@@ -333,6 +333,7 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
333
333
  let bundle = getFlag(options, keys, "bundle", mustBeBoolean);
334
334
  let watch = getFlag(options, keys, "watch", mustBeBooleanOrObject);
335
335
  let splitting = getFlag(options, keys, "splitting", mustBeBoolean);
336
+ let preserveSymlinks = getFlag(options, keys, "preserveSymlinks", mustBeBoolean);
336
337
  let metafile = getFlag(options, keys, "metafile", mustBeString);
337
338
  let outfile = getFlag(options, keys, "outfile", mustBeString);
338
339
  let outdir = getFlag(options, keys, "outdir", mustBeString);
@@ -340,6 +341,7 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
340
341
  let platform = getFlag(options, keys, "platform", mustBeString);
341
342
  let tsconfig = getFlag(options, keys, "tsconfig", mustBeString);
342
343
  let resolveExtensions = getFlag(options, keys, "resolveExtensions", mustBeArray);
344
+ let nodePathsInput = getFlag(options, keys, "nodePaths", mustBeArray);
343
345
  let mainFields = getFlag(options, keys, "mainFields", mustBeArray);
344
346
  let external = getFlag(options, keys, "external", mustBeArray);
345
347
  let loader = getFlag(options, keys, "loader", mustBeObject);
@@ -370,6 +372,8 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
370
372
  }
371
373
  if (splitting)
372
374
  flags.push("--splitting");
375
+ if (preserveSymlinks)
376
+ flags.push("--preserve-symlinks");
373
377
  if (metafile)
374
378
  flags.push(`--metafile=${metafile}`);
375
379
  if (outfile)
@@ -447,6 +451,13 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
447
451
  stdinResolveDir = resolveDir + "";
448
452
  stdinContents = contents ? contents + "" : "";
449
453
  }
454
+ let nodePaths = [];
455
+ if (nodePathsInput) {
456
+ for (let value of nodePathsInput) {
457
+ value += "";
458
+ nodePaths.push(value);
459
+ }
460
+ }
450
461
  return {
451
462
  flags,
452
463
  write,
@@ -455,6 +466,7 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
455
466
  stdinResolveDir,
456
467
  absWorkingDir,
457
468
  incremental,
469
+ nodePaths,
458
470
  watch: watchMode
459
471
  };
460
472
  }
@@ -562,12 +574,18 @@ function createChannel(streamIn) {
562
574
  }
563
575
  case "resolve": {
564
576
  let callback = pluginCallbacks.get(request.key);
565
- sendResponse(id, yield callback(request));
577
+ if (!callback)
578
+ sendResponse(id, {});
579
+ else
580
+ sendResponse(id, yield callback(request));
566
581
  break;
567
582
  }
568
583
  case "load": {
569
584
  let callback = pluginCallbacks.get(request.key);
570
- sendResponse(id, yield callback(request));
585
+ if (!callback)
586
+ sendResponse(id, {});
587
+ else
588
+ sendResponse(id, yield callback(request));
571
589
  break;
572
590
  }
573
591
  case "serve-request": {
@@ -599,7 +617,7 @@ function createChannel(streamIn) {
599
617
  throw new Error(`Invalid command: ` + request.command);
600
618
  }
601
619
  } catch (e) {
602
- sendResponse(id, {errors: [extractErrorMessageV8(e, streamIn, null)]});
620
+ sendResponse(id, {errors: [extractErrorMessageV8(e, streamIn, null, void 0)]});
603
621
  }
604
622
  });
605
623
  let isFirstPacket = true;
@@ -607,8 +625,8 @@ function createChannel(streamIn) {
607
625
  if (isFirstPacket) {
608
626
  isFirstPacket = false;
609
627
  let binaryVersion = String.fromCharCode(...bytes);
610
- if (binaryVersion !== "0.8.40") {
611
- throw new Error(`Cannot start service: Host version "${"0.8.40"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
628
+ if (binaryVersion !== "0.8.44") {
629
+ throw new Error(`Cannot start service: Host version "${"0.8.44"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
612
630
  }
613
631
  return;
614
632
  }
@@ -651,6 +669,8 @@ function createChannel(streamIn) {
651
669
  i++;
652
670
  setup({
653
671
  onResolve(options, callback2) {
672
+ let registeredText = `This error came from the "onResolve" callback registered here`;
673
+ let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onResolve");
654
674
  let keys2 = {};
655
675
  let filter = getFlag(options, keys2, "filter", mustBeRegExp);
656
676
  let namespace = getFlag(options, keys2, "namespace", mustBeString);
@@ -658,10 +678,12 @@ function createChannel(streamIn) {
658
678
  if (filter == null)
659
679
  throw new Error(`[${plugin.name}] onResolve() call is missing a filter`);
660
680
  let id = nextCallbackID++;
661
- onResolveCallbacks[id] = {name, callback: callback2};
681
+ onResolveCallbacks[id] = {name, callback: callback2, note: registeredNote};
662
682
  plugin.onResolve.push({id, filter: filter.source, namespace: namespace || ""});
663
683
  },
664
684
  onLoad(options, callback2) {
685
+ let registeredText = `This error came from the "onLoad" callback registered here`;
686
+ let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onLoad");
665
687
  let keys2 = {};
666
688
  let filter = getFlag(options, keys2, "filter", mustBeRegExp);
667
689
  let namespace = getFlag(options, keys2, "namespace", mustBeString);
@@ -669,7 +691,7 @@ function createChannel(streamIn) {
669
691
  if (filter == null)
670
692
  throw new Error(`[${plugin.name}] onLoad() call is missing a filter`);
671
693
  let id = nextCallbackID++;
672
- onLoadCallbacks[id] = {name, callback: callback2};
694
+ onLoadCallbacks[id] = {name, callback: callback2, note: registeredNote};
673
695
  plugin.onLoad.push({id, filter: filter.source, namespace: namespace || ""});
674
696
  }
675
697
  });
@@ -678,10 +700,10 @@ function createChannel(streamIn) {
678
700
  const callback = (request2) => __async(this, null, function* () {
679
701
  switch (request2.command) {
680
702
  case "resolve": {
681
- let response = {};
703
+ let response = {}, name, callback2, note;
682
704
  for (let id of request2.ids) {
683
705
  try {
684
- let {name, callback: callback2} = onResolveCallbacks[id];
706
+ ({name, callback: callback2, note} = onResolveCallbacks[id]);
685
707
  let result = yield callback2({
686
708
  path: request2.path,
687
709
  importer: request2.importer,
@@ -719,16 +741,16 @@ function createChannel(streamIn) {
719
741
  break;
720
742
  }
721
743
  } catch (e) {
722
- return {id, errors: [extractErrorMessageV8(e, streamIn, stash)]};
744
+ return {id, errors: [extractErrorMessageV8(e, streamIn, stash, note)]};
723
745
  }
724
746
  }
725
747
  return response;
726
748
  }
727
749
  case "load": {
728
- let response = {};
750
+ let response = {}, name, callback2, note;
729
751
  for (let id of request2.ids) {
730
752
  try {
731
- let {name, callback: callback2} = onLoadCallbacks[id];
753
+ ({name, callback: callback2, note} = onLoadCallbacks[id]);
732
754
  let result = yield callback2({
733
755
  path: request2.path,
734
756
  namespace: request2.namespace,
@@ -766,7 +788,7 @@ function createChannel(streamIn) {
766
788
  break;
767
789
  }
768
790
  } catch (e) {
769
- return {id, errors: [extractErrorMessageV8(e, streamIn, stash)]};
791
+ return {id, errors: [extractErrorMessageV8(e, streamIn, stash, note)]};
770
792
  }
771
793
  }
772
794
  return response;
@@ -854,6 +876,7 @@ function createChannel(streamIn) {
854
876
  stdinResolveDir,
855
877
  absWorkingDir,
856
878
  incremental,
879
+ nodePaths,
857
880
  watch
858
881
  } = flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeDefault);
859
882
  let request = {
@@ -865,6 +888,7 @@ function createChannel(streamIn) {
865
888
  stdinResolveDir,
866
889
  absWorkingDir: absWorkingDir || defaultWD,
867
890
  incremental,
891
+ nodePaths,
868
892
  hasOnRebuild: !!(watch && watch.onRebuild)
869
893
  };
870
894
  let serve2 = serveOptions && buildServeData(refs, serveOptions, request);
@@ -979,8 +1003,10 @@ function createChannel(streamIn) {
979
1003
  pushLogFlags(flags, options, {}, isTTY2, logLevelDefault);
980
1004
  } catch (e2) {
981
1005
  }
982
- sendRequest(refs, {command: "error", flags, error: extractErrorMessageV8(e, streamIn, details)}, () => {
983
- callback(e, null);
1006
+ const error = extractErrorMessageV8(e, streamIn, details, void 0);
1007
+ sendRequest(refs, {command: "error", flags, error}, () => {
1008
+ error.detail = details.load(error.detail);
1009
+ callback(failureErrorWithLog("Build failed", [error], []), null);
984
1010
  });
985
1011
  }
986
1012
  },
@@ -1035,8 +1061,10 @@ function createChannel(streamIn) {
1035
1061
  pushLogFlags(flags, options, {}, isTTY2, logLevelDefault);
1036
1062
  } catch (e2) {
1037
1063
  }
1038
- sendRequest(refs, {command: "error", flags, error: extractErrorMessageV8(e, streamIn, details)}, () => {
1039
- callback(e, null);
1064
+ const error = extractErrorMessageV8(e, streamIn, details, void 0);
1065
+ sendRequest(refs, {command: "error", flags, error}, () => {
1066
+ error.detail = details.load(error.detail);
1067
+ callback(failureErrorWithLog("Transform failed", [error], []), null);
1040
1068
  });
1041
1069
  }
1042
1070
  };
@@ -1065,7 +1093,18 @@ function createObjectStash() {
1065
1093
  }
1066
1094
  };
1067
1095
  }
1068
- function extractErrorMessageV8(e, streamIn, stash) {
1096
+ function extractCallerV8(e, streamIn, ident) {
1097
+ try {
1098
+ let lines = (e.stack + "").split("\n", 4);
1099
+ lines.splice(1, 1);
1100
+ let location = parseStackLinesV8(streamIn, lines, ident);
1101
+ if (location) {
1102
+ return {text: e.message, location};
1103
+ }
1104
+ } catch (e2) {
1105
+ }
1106
+ }
1107
+ function extractErrorMessageV8(e, streamIn, stash, note) {
1069
1108
  let text = "Internal error";
1070
1109
  let location = null;
1071
1110
  try {
@@ -1073,41 +1112,45 @@ function extractErrorMessageV8(e, streamIn, stash) {
1073
1112
  } catch (e2) {
1074
1113
  }
1075
1114
  try {
1076
- let stack = e.stack + "";
1077
- let lines = stack.split("\n", 3);
1078
- let at = " at ";
1079
- if (streamIn.readFileSync && !lines[0].startsWith(at) && lines[1].startsWith(at)) {
1080
- let line = lines[1].slice(at.length);
1081
- while (true) {
1082
- let match = /^\S+ \((.*)\)$/.exec(line);
1083
- if (match) {
1084
- line = match[1];
1085
- continue;
1086
- }
1087
- match = /^eval at \S+ \((.*)\)(?:, \S+:\d+:\d+)?$/.exec(line);
1088
- if (match) {
1089
- line = match[1];
1090
- continue;
1091
- }
1092
- match = /^(\S+):(\d+):(\d+)$/.exec(line);
1093
- if (match) {
1094
- let contents = streamIn.readFileSync(match[1], "utf8");
1095
- let lineText = contents.split(/\r\n|\r|\n|\u2028|\u2029/)[+match[2] - 1] || "";
1096
- location = {
1097
- file: match[1],
1098
- namespace: "file",
1099
- line: +match[2],
1100
- column: +match[3] - 1,
1101
- length: 0,
1102
- lineText: lineText + "\n" + lines.slice(1).join("\n")
1103
- };
1104
- }
1105
- break;
1115
+ location = parseStackLinesV8(streamIn, (e.stack + "").split("\n", 3), "");
1116
+ } catch (e2) {
1117
+ }
1118
+ return {text, location, notes: note ? [note] : [], detail: stash ? stash.store(e) : -1};
1119
+ }
1120
+ function parseStackLinesV8(streamIn, lines, ident) {
1121
+ let at = " at ";
1122
+ if (streamIn.readFileSync && !lines[0].startsWith(at) && lines[1].startsWith(at)) {
1123
+ let line = lines[1].slice(at.length);
1124
+ while (true) {
1125
+ let match = /^\S+ \((.*)\)$/.exec(line);
1126
+ if (match) {
1127
+ line = match[1];
1128
+ continue;
1129
+ }
1130
+ match = /^eval at \S+ \((.*)\)(?:, \S+:\d+:\d+)?$/.exec(line);
1131
+ if (match) {
1132
+ line = match[1];
1133
+ continue;
1106
1134
  }
1135
+ match = /^(\S+):(\d+):(\d+)$/.exec(line);
1136
+ if (match) {
1137
+ let contents = streamIn.readFileSync(match[1], "utf8");
1138
+ let lineText = contents.split(/\r\n|\r|\n|\u2028|\u2029/)[+match[2] - 1] || "";
1139
+ let column = +match[3] - 1;
1140
+ let length = lineText.slice(column, column + ident.length) === ident ? ident.length : 0;
1141
+ return {
1142
+ file: match[1],
1143
+ namespace: "file",
1144
+ line: +match[2],
1145
+ column: encodeUTF8(lineText.slice(0, column)).length,
1146
+ length: encodeUTF8(lineText.slice(column, column + length)).length,
1147
+ lineText: lineText + "\n" + lines.slice(1).join("\n")
1148
+ };
1149
+ }
1150
+ break;
1107
1151
  }
1108
- } catch (e2) {
1109
1152
  }
1110
- return {text, location, detail: stash ? stash.store(e) : -1};
1153
+ return null;
1111
1154
  }
1112
1155
  function failureErrorWithLog(text, errors, warnings) {
1113
1156
  let limit = 5;
@@ -1132,6 +1175,26 @@ function replaceDetailsInMessages(messages, stash) {
1132
1175
  }
1133
1176
  return messages;
1134
1177
  }
1178
+ function sanitizeLocation(location, where) {
1179
+ if (location == null)
1180
+ return null;
1181
+ let keys = {};
1182
+ let file = getFlag(location, keys, "file", mustBeString);
1183
+ let namespace = getFlag(location, keys, "namespace", mustBeString);
1184
+ let line = getFlag(location, keys, "line", mustBeInteger);
1185
+ let column = getFlag(location, keys, "column", mustBeInteger);
1186
+ let length = getFlag(location, keys, "length", mustBeInteger);
1187
+ let lineText = getFlag(location, keys, "lineText", mustBeString);
1188
+ checkForInvalidFlags(location, keys, where);
1189
+ return {
1190
+ file: file || "",
1191
+ namespace: namespace || "",
1192
+ line: line || 0,
1193
+ column: column || 0,
1194
+ length: length || 0,
1195
+ lineText: lineText || ""
1196
+ };
1197
+ }
1135
1198
  function sanitizeMessages(messages, property, stash) {
1136
1199
  let messagesClone = [];
1137
1200
  let index = 0;
@@ -1139,30 +1202,27 @@ function sanitizeMessages(messages, property, stash) {
1139
1202
  let keys = {};
1140
1203
  let text = getFlag(message, keys, "text", mustBeString);
1141
1204
  let location = getFlag(message, keys, "location", mustBeObjectOrNull);
1205
+ let notes = getFlag(message, keys, "notes", mustBeArray);
1142
1206
  let detail = getFlag(message, keys, "detail", canBeAnything);
1143
- checkForInvalidFlags(message, keys, `in element ${index} of "${property}"`);
1144
- let locationClone = null;
1145
- if (location != null) {
1146
- let keys2 = {};
1147
- let file = getFlag(location, keys2, "file", mustBeString);
1148
- let namespace = getFlag(location, keys2, "namespace", mustBeString);
1149
- let line = getFlag(location, keys2, "line", mustBeInteger);
1150
- let column = getFlag(location, keys2, "column", mustBeInteger);
1151
- let length = getFlag(location, keys2, "length", mustBeInteger);
1152
- let lineText = getFlag(location, keys2, "lineText", mustBeString);
1153
- checkForInvalidFlags(location, keys2, `in element ${index} of "${property}"`);
1154
- locationClone = {
1155
- file: file || "",
1156
- namespace: namespace || "",
1157
- line: line || 0,
1158
- column: column || 0,
1159
- length: length || 0,
1160
- lineText: lineText || ""
1161
- };
1207
+ let where = `in element ${index} of "${property}"`;
1208
+ checkForInvalidFlags(message, keys, where);
1209
+ let notesClone = [];
1210
+ if (notes) {
1211
+ for (const note of notes) {
1212
+ let noteKeys = {};
1213
+ let noteText = getFlag(note, noteKeys, "text", mustBeString);
1214
+ let noteLocation = getFlag(note, noteKeys, "location", mustBeObjectOrNull);
1215
+ checkForInvalidFlags(note, noteKeys, where);
1216
+ notesClone.push({
1217
+ text: noteText || "",
1218
+ location: sanitizeLocation(noteLocation, where)
1219
+ });
1220
+ }
1162
1221
  }
1163
1222
  messagesClone.push({
1164
1223
  text: text || "",
1165
- location: locationClone,
1224
+ location: sanitizeLocation(location, where),
1225
+ notes: notesClone,
1166
1226
  detail: stash.store(detail)
1167
1227
  });
1168
1228
  index++;
@@ -1248,7 +1308,7 @@ var esbuildCommandAndArgs = () => {
1248
1308
  return [path.join(__dirname, "..", "bin", "esbuild"), []];
1249
1309
  };
1250
1310
  var isTTY = () => tty.isatty(2);
1251
- var version = "0.8.40";
1311
+ var version = "0.8.44";
1252
1312
  var build = (options) => startService().then((service) => service.build(options));
1253
1313
  var serve = (serveOptions, buildOptions) => startService().then((service) => service.serve(serveOptions, buildOptions));
1254
1314
  var transform = (input, options) => {
@@ -1304,7 +1364,7 @@ var startService = longLivedService(() => process.cwd(), (options) => {
1304
1364
  throw new Error(`The "worker" option only works in the browser`);
1305
1365
  let [command, args] = esbuildCommandAndArgs();
1306
1366
  let defaultWD = process.cwd();
1307
- let child = child_process.spawn(command, args.concat(`--service=${"0.8.40"}`), {
1367
+ let child = child_process.spawn(command, args.concat(`--service=${"0.8.44"}`, "--ping"), {
1308
1368
  windowsHide: true,
1309
1369
  stdio: ["pipe", "pipe", "inherit"]
1310
1370
  });
@@ -1405,7 +1465,7 @@ var runServiceSync = (callback) => {
1405
1465
  isBrowser: false
1406
1466
  });
1407
1467
  callback(service);
1408
- let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.8.40"}`), {
1468
+ let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.8.44"}`), {
1409
1469
  cwd: process.cwd(),
1410
1470
  windowsHide: true,
1411
1471
  input: stdin,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esbuild",
3
- "version": "0.8.40",
3
+ "version": "0.8.44",
4
4
  "description": "An extremely fast JavaScript bundler and minifier.",
5
5
  "repository": "https://github.com/evanw/esbuild",
6
6
  "scripts": {