esbuild 0.8.43 → 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.43";
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* () {
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;
@@ -74,12 +75,18 @@ export interface StdinOptions {
74
75
  export interface Message {
75
76
  text: string;
76
77
  location: Location | null;
78
+ notes: Note[];
77
79
 
78
80
  // Optional user-specified data that is passed through unmodified. You can
79
81
  // use this to stash the original error, for example.
80
82
  detail: any;
81
83
  }
82
84
 
85
+ export interface Note {
86
+ text: string;
87
+ location: Location | null;
88
+ }
89
+
83
90
  export interface Location {
84
91
  file: string;
85
92
  namespace: string;
@@ -225,9 +232,15 @@ export interface OnLoadResult {
225
232
  export interface PartialMessage {
226
233
  text?: string;
227
234
  location?: Partial<Location> | null;
235
+ notes?: PartialNote[];
228
236
  detail?: any;
229
237
  }
230
238
 
239
+ export interface PartialNote {
240
+ text?: string;
241
+ location?: Partial<Location> | null;
242
+ }
243
+
231
244
  export type MetadataImportKind =
232
245
  // JS
233
246
  | 'import-statement'
package/lib/main.js CHANGED
@@ -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);
@@ -371,6 +372,8 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
371
372
  }
372
373
  if (splitting)
373
374
  flags.push("--splitting");
375
+ if (preserveSymlinks)
376
+ flags.push("--preserve-symlinks");
374
377
  if (metafile)
375
378
  flags.push(`--metafile=${metafile}`);
376
379
  if (outfile)
@@ -614,7 +617,7 @@ function createChannel(streamIn) {
614
617
  throw new Error(`Invalid command: ` + request.command);
615
618
  }
616
619
  } catch (e) {
617
- sendResponse(id, {errors: [extractErrorMessageV8(e, streamIn, null)]});
620
+ sendResponse(id, {errors: [extractErrorMessageV8(e, streamIn, null, void 0)]});
618
621
  }
619
622
  });
620
623
  let isFirstPacket = true;
@@ -622,8 +625,8 @@ function createChannel(streamIn) {
622
625
  if (isFirstPacket) {
623
626
  isFirstPacket = false;
624
627
  let binaryVersion = String.fromCharCode(...bytes);
625
- if (binaryVersion !== "0.8.43") {
626
- throw new Error(`Cannot start service: Host version "${"0.8.43"}" 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)}`);
627
630
  }
628
631
  return;
629
632
  }
@@ -666,6 +669,8 @@ function createChannel(streamIn) {
666
669
  i++;
667
670
  setup({
668
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");
669
674
  let keys2 = {};
670
675
  let filter = getFlag(options, keys2, "filter", mustBeRegExp);
671
676
  let namespace = getFlag(options, keys2, "namespace", mustBeString);
@@ -673,10 +678,12 @@ function createChannel(streamIn) {
673
678
  if (filter == null)
674
679
  throw new Error(`[${plugin.name}] onResolve() call is missing a filter`);
675
680
  let id = nextCallbackID++;
676
- onResolveCallbacks[id] = {name, callback: callback2};
681
+ onResolveCallbacks[id] = {name, callback: callback2, note: registeredNote};
677
682
  plugin.onResolve.push({id, filter: filter.source, namespace: namespace || ""});
678
683
  },
679
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");
680
687
  let keys2 = {};
681
688
  let filter = getFlag(options, keys2, "filter", mustBeRegExp);
682
689
  let namespace = getFlag(options, keys2, "namespace", mustBeString);
@@ -684,7 +691,7 @@ function createChannel(streamIn) {
684
691
  if (filter == null)
685
692
  throw new Error(`[${plugin.name}] onLoad() call is missing a filter`);
686
693
  let id = nextCallbackID++;
687
- onLoadCallbacks[id] = {name, callback: callback2};
694
+ onLoadCallbacks[id] = {name, callback: callback2, note: registeredNote};
688
695
  plugin.onLoad.push({id, filter: filter.source, namespace: namespace || ""});
689
696
  }
690
697
  });
@@ -693,10 +700,10 @@ function createChannel(streamIn) {
693
700
  const callback = (request2) => __async(this, null, function* () {
694
701
  switch (request2.command) {
695
702
  case "resolve": {
696
- let response = {};
703
+ let response = {}, name, callback2, note;
697
704
  for (let id of request2.ids) {
698
705
  try {
699
- let {name, callback: callback2} = onResolveCallbacks[id];
706
+ ({name, callback: callback2, note} = onResolveCallbacks[id]);
700
707
  let result = yield callback2({
701
708
  path: request2.path,
702
709
  importer: request2.importer,
@@ -734,16 +741,16 @@ function createChannel(streamIn) {
734
741
  break;
735
742
  }
736
743
  } catch (e) {
737
- return {id, errors: [extractErrorMessageV8(e, streamIn, stash)]};
744
+ return {id, errors: [extractErrorMessageV8(e, streamIn, stash, note)]};
738
745
  }
739
746
  }
740
747
  return response;
741
748
  }
742
749
  case "load": {
743
- let response = {};
750
+ let response = {}, name, callback2, note;
744
751
  for (let id of request2.ids) {
745
752
  try {
746
- let {name, callback: callback2} = onLoadCallbacks[id];
753
+ ({name, callback: callback2, note} = onLoadCallbacks[id]);
747
754
  let result = yield callback2({
748
755
  path: request2.path,
749
756
  namespace: request2.namespace,
@@ -781,7 +788,7 @@ function createChannel(streamIn) {
781
788
  break;
782
789
  }
783
790
  } catch (e) {
784
- return {id, errors: [extractErrorMessageV8(e, streamIn, stash)]};
791
+ return {id, errors: [extractErrorMessageV8(e, streamIn, stash, note)]};
785
792
  }
786
793
  }
787
794
  return response;
@@ -996,7 +1003,7 @@ function createChannel(streamIn) {
996
1003
  pushLogFlags(flags, options, {}, isTTY2, logLevelDefault);
997
1004
  } catch (e2) {
998
1005
  }
999
- const error = extractErrorMessageV8(e, streamIn, details);
1006
+ const error = extractErrorMessageV8(e, streamIn, details, void 0);
1000
1007
  sendRequest(refs, {command: "error", flags, error}, () => {
1001
1008
  error.detail = details.load(error.detail);
1002
1009
  callback(failureErrorWithLog("Build failed", [error], []), null);
@@ -1054,7 +1061,7 @@ function createChannel(streamIn) {
1054
1061
  pushLogFlags(flags, options, {}, isTTY2, logLevelDefault);
1055
1062
  } catch (e2) {
1056
1063
  }
1057
- const error = extractErrorMessageV8(e, streamIn, details);
1064
+ const error = extractErrorMessageV8(e, streamIn, details, void 0);
1058
1065
  sendRequest(refs, {command: "error", flags, error}, () => {
1059
1066
  error.detail = details.load(error.detail);
1060
1067
  callback(failureErrorWithLog("Transform failed", [error], []), null);
@@ -1086,7 +1093,18 @@ function createObjectStash() {
1086
1093
  }
1087
1094
  };
1088
1095
  }
1089
- 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) {
1090
1108
  let text = "Internal error";
1091
1109
  let location = null;
1092
1110
  try {
@@ -1094,41 +1112,45 @@ function extractErrorMessageV8(e, streamIn, stash) {
1094
1112
  } catch (e2) {
1095
1113
  }
1096
1114
  try {
1097
- let stack = e.stack + "";
1098
- let lines = stack.split("\n", 3);
1099
- let at = " at ";
1100
- if (streamIn.readFileSync && !lines[0].startsWith(at) && lines[1].startsWith(at)) {
1101
- let line = lines[1].slice(at.length);
1102
- while (true) {
1103
- let match = /^\S+ \((.*)\)$/.exec(line);
1104
- if (match) {
1105
- line = match[1];
1106
- continue;
1107
- }
1108
- match = /^eval at \S+ \((.*)\)(?:, \S+:\d+:\d+)?$/.exec(line);
1109
- if (match) {
1110
- line = match[1];
1111
- continue;
1112
- }
1113
- match = /^(\S+):(\d+):(\d+)$/.exec(line);
1114
- if (match) {
1115
- let contents = streamIn.readFileSync(match[1], "utf8");
1116
- let lineText = contents.split(/\r\n|\r|\n|\u2028|\u2029/)[+match[2] - 1] || "";
1117
- location = {
1118
- file: match[1],
1119
- namespace: "file",
1120
- line: +match[2],
1121
- column: +match[3] - 1,
1122
- length: 0,
1123
- lineText: lineText + "\n" + lines.slice(1).join("\n")
1124
- };
1125
- }
1126
- 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;
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
+ };
1127
1149
  }
1150
+ break;
1128
1151
  }
1129
- } catch (e2) {
1130
1152
  }
1131
- return {text, location, detail: stash ? stash.store(e) : -1};
1153
+ return null;
1132
1154
  }
1133
1155
  function failureErrorWithLog(text, errors, warnings) {
1134
1156
  let limit = 5;
@@ -1153,6 +1175,26 @@ function replaceDetailsInMessages(messages, stash) {
1153
1175
  }
1154
1176
  return messages;
1155
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
+ }
1156
1198
  function sanitizeMessages(messages, property, stash) {
1157
1199
  let messagesClone = [];
1158
1200
  let index = 0;
@@ -1160,30 +1202,27 @@ function sanitizeMessages(messages, property, stash) {
1160
1202
  let keys = {};
1161
1203
  let text = getFlag(message, keys, "text", mustBeString);
1162
1204
  let location = getFlag(message, keys, "location", mustBeObjectOrNull);
1205
+ let notes = getFlag(message, keys, "notes", mustBeArray);
1163
1206
  let detail = getFlag(message, keys, "detail", canBeAnything);
1164
- checkForInvalidFlags(message, keys, `in element ${index} of "${property}"`);
1165
- let locationClone = null;
1166
- if (location != null) {
1167
- let keys2 = {};
1168
- let file = getFlag(location, keys2, "file", mustBeString);
1169
- let namespace = getFlag(location, keys2, "namespace", mustBeString);
1170
- let line = getFlag(location, keys2, "line", mustBeInteger);
1171
- let column = getFlag(location, keys2, "column", mustBeInteger);
1172
- let length = getFlag(location, keys2, "length", mustBeInteger);
1173
- let lineText = getFlag(location, keys2, "lineText", mustBeString);
1174
- checkForInvalidFlags(location, keys2, `in element ${index} of "${property}"`);
1175
- locationClone = {
1176
- file: file || "",
1177
- namespace: namespace || "",
1178
- line: line || 0,
1179
- column: column || 0,
1180
- length: length || 0,
1181
- lineText: lineText || ""
1182
- };
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
+ }
1183
1221
  }
1184
1222
  messagesClone.push({
1185
1223
  text: text || "",
1186
- location: locationClone,
1224
+ location: sanitizeLocation(location, where),
1225
+ notes: notesClone,
1187
1226
  detail: stash.store(detail)
1188
1227
  });
1189
1228
  index++;
@@ -1269,7 +1308,7 @@ var esbuildCommandAndArgs = () => {
1269
1308
  return [path.join(__dirname, "..", "bin", "esbuild"), []];
1270
1309
  };
1271
1310
  var isTTY = () => tty.isatty(2);
1272
- var version = "0.8.43";
1311
+ var version = "0.8.44";
1273
1312
  var build = (options) => startService().then((service) => service.build(options));
1274
1313
  var serve = (serveOptions, buildOptions) => startService().then((service) => service.serve(serveOptions, buildOptions));
1275
1314
  var transform = (input, options) => {
@@ -1325,7 +1364,7 @@ var startService = longLivedService(() => process.cwd(), (options) => {
1325
1364
  throw new Error(`The "worker" option only works in the browser`);
1326
1365
  let [command, args] = esbuildCommandAndArgs();
1327
1366
  let defaultWD = process.cwd();
1328
- let child = child_process.spawn(command, args.concat(`--service=${"0.8.43"}`), {
1367
+ let child = child_process.spawn(command, args.concat(`--service=${"0.8.44"}`, "--ping"), {
1329
1368
  windowsHide: true,
1330
1369
  stdio: ["pipe", "pipe", "inherit"]
1331
1370
  });
@@ -1426,7 +1465,7 @@ var runServiceSync = (callback) => {
1426
1465
  isBrowser: false
1427
1466
  });
1428
1467
  callback(service);
1429
- let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.8.43"}`), {
1468
+ let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.8.44"}`), {
1430
1469
  cwd: process.cwd(),
1431
1470
  windowsHide: true,
1432
1471
  input: stdin,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esbuild",
3
- "version": "0.8.43",
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": {