isomorfeus-asset-manager 0.15.10 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -190,26 +190,30 @@ var ByteBuffer = class {
190
190
  };
191
191
  var encodeUTF8;
192
192
  var decodeUTF8;
193
+ var encodeInvariant;
193
194
  if (typeof TextEncoder !== "undefined" && typeof TextDecoder !== "undefined") {
194
195
  let encoder = new TextEncoder();
195
196
  let decoder = new TextDecoder();
196
197
  encodeUTF8 = (text) => encoder.encode(text);
197
198
  decodeUTF8 = (bytes) => decoder.decode(bytes);
199
+ encodeInvariant = 'new TextEncoder().encode("")';
198
200
  } else if (typeof Buffer !== "undefined") {
199
- encodeUTF8 = (text) => {
200
- let buffer = Buffer.from(text);
201
- if (!(buffer instanceof Uint8Array)) {
202
- buffer = new Uint8Array(buffer);
203
- }
204
- return buffer;
205
- };
201
+ encodeUTF8 = (text) => Buffer.from(text);
206
202
  decodeUTF8 = (bytes) => {
207
203
  let { buffer, byteOffset, byteLength } = bytes;
208
204
  return Buffer.from(buffer, byteOffset, byteLength).toString();
209
205
  };
206
+ encodeInvariant = 'Buffer.from("")';
210
207
  } else {
211
208
  throw new Error("No UTF-8 codec found");
212
209
  }
210
+ if (!(encodeUTF8("") instanceof Uint8Array))
211
+ throw new Error(`Invariant violation: "${encodeInvariant} instanceof Uint8Array" is incorrectly false
212
+
213
+ This indicates that your JavaScript environment is broken. You cannot use
214
+ esbuild in this environment because esbuild relies on this invariant. This
215
+ is not a problem with esbuild. You need to fix your environment instead.
216
+ `);
213
217
  function readUInt32LE(buffer, offset) {
214
218
  return buffer[offset++] | buffer[offset++] << 8 | buffer[offset++] << 16 | buffer[offset++] << 24;
215
219
  }
@@ -221,10 +225,11 @@ function writeUInt32LE(buffer, value, offset) {
221
225
  }
222
226
 
223
227
  // lib/shared/common.ts
228
+ var quote = JSON.stringify;
224
229
  var buildLogLevelDefault = "warning";
225
230
  var transformLogLevelDefault = "silent";
226
231
  function validateTarget(target) {
227
- target += "";
232
+ validateStringValue(target, "target");
228
233
  if (target.indexOf(",") >= 0)
229
234
  throw new Error(`Invalid target: ${target}`);
230
235
  return target;
@@ -245,6 +250,7 @@ var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value
245
250
  var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object";
246
251
  var mustBeStringOrArray = (value) => typeof value === "string" || Array.isArray(value) ? null : "a string or an array";
247
252
  var mustBeStringOrUint8Array = (value) => typeof value === "string" || value instanceof Uint8Array ? null : "a string or a Uint8Array";
253
+ var mustBeStringOrURL = (value) => typeof value === "string" || value instanceof URL ? null : "a string or a URL";
248
254
  function getFlag(object, keys, key, mustBeFn) {
249
255
  let value = object[key];
250
256
  keys[key + ""] = true;
@@ -252,19 +258,19 @@ function getFlag(object, keys, key, mustBeFn) {
252
258
  return void 0;
253
259
  let mustBe = mustBeFn(value);
254
260
  if (mustBe !== null)
255
- throw new Error(`"${key}" must be ${mustBe}`);
261
+ throw new Error(`${quote(key)} must be ${mustBe}`);
256
262
  return value;
257
263
  }
258
264
  function checkForInvalidFlags(object, keys, where) {
259
265
  for (let key in object) {
260
266
  if (!(key in keys)) {
261
- throw new Error(`Invalid option ${where}: "${key}"`);
267
+ throw new Error(`Invalid option ${where}: ${quote(key)}`);
262
268
  }
263
269
  }
264
270
  }
265
271
  function validateInitializeOptions(options) {
266
272
  let keys = /* @__PURE__ */ Object.create(null);
267
- let wasmURL = getFlag(options, keys, "wasmURL", mustBeString);
273
+ let wasmURL = getFlag(options, keys, "wasmURL", mustBeStringOrURL);
268
274
  let wasmModule = getFlag(options, keys, "wasmModule", mustBeWebAssemblyModule);
269
275
  let worker = getFlag(options, keys, "worker", mustBeBoolean);
270
276
  checkForInvalidFlags(options, keys, "in initialize() call");
@@ -278,12 +284,12 @@ function validateMangleCache(mangleCache) {
278
284
  let validated;
279
285
  if (mangleCache !== void 0) {
280
286
  validated = /* @__PURE__ */ Object.create(null);
281
- for (let key of Object.keys(mangleCache)) {
287
+ for (let key in mangleCache) {
282
288
  let value = mangleCache[key];
283
289
  if (typeof value === "string" || value === false) {
284
290
  validated[key] = value;
285
291
  } else {
286
- throw new Error(`Expected ${JSON.stringify(key)} in mangle cache to map to either a string or false`);
292
+ throw new Error(`Expected ${quote(key)} in mangle cache to map to either a string or false`);
287
293
  }
288
294
  }
289
295
  }
@@ -300,6 +306,12 @@ function pushLogFlags(flags, options, keys, isTTY, logLevelDefault) {
300
306
  flags.push(`--log-level=${logLevel || logLevelDefault}`);
301
307
  flags.push(`--log-limit=${logLimit || 0}`);
302
308
  }
309
+ function validateStringValue(value, what, key) {
310
+ if (typeof value !== "string") {
311
+ throw new Error(`Expected value for ${what}${key !== void 0 ? " " + quote(key) : ""} to be a string, got ${typeof value} instead`);
312
+ }
313
+ return value;
314
+ }
303
315
  function pushCommonFlags(flags, options, keys) {
304
316
  let legalComments = getFlag(options, keys, "legalComments", mustBeString);
305
317
  let sourceRoot = getFlag(options, keys, "sourceRoot", mustBeString);
@@ -364,7 +376,7 @@ function pushCommonFlags(flags, options, keys) {
364
376
  flags.push(`--ignore-annotations`);
365
377
  if (drop)
366
378
  for (let what of drop)
367
- flags.push(`--drop:${what}`);
379
+ flags.push(`--drop:${validateStringValue(what, "drop")}`);
368
380
  if (mangleProps)
369
381
  flags.push(`--mangle-props=${mangleProps.source}`);
370
382
  if (reserveProps)
@@ -387,26 +399,29 @@ function pushCommonFlags(flags, options, keys) {
387
399
  for (let key in define) {
388
400
  if (key.indexOf("=") >= 0)
389
401
  throw new Error(`Invalid define: ${key}`);
390
- flags.push(`--define:${key}=${define[key]}`);
402
+ flags.push(`--define:${key}=${validateStringValue(define[key], "define", key)}`);
391
403
  }
392
404
  }
393
405
  if (logOverride) {
394
406
  for (let key in logOverride) {
395
407
  if (key.indexOf("=") >= 0)
396
408
  throw new Error(`Invalid log override: ${key}`);
397
- flags.push(`--log-override:${key}=${logOverride[key]}`);
409
+ flags.push(`--log-override:${key}=${validateStringValue(logOverride[key], "log override", key)}`);
398
410
  }
399
411
  }
400
412
  if (supported) {
401
413
  for (let key in supported) {
402
414
  if (key.indexOf("=") >= 0)
403
415
  throw new Error(`Invalid supported: ${key}`);
404
- flags.push(`--supported:${key}=${supported[key]}`);
416
+ const value = supported[key];
417
+ if (typeof value !== "boolean")
418
+ throw new Error(`Expected value for supported ${quote(key)} to be a boolean, got ${typeof value} instead`);
419
+ flags.push(`--supported:${key}=${value}`);
405
420
  }
406
421
  }
407
422
  if (pure)
408
423
  for (let fn of pure)
409
- flags.push(`--pure:${fn}`);
424
+ flags.push(`--pure:${validateStringValue(fn, "pure")}`);
410
425
  if (keepNames)
411
426
  flags.push(`--keep-names`);
412
427
  }
@@ -435,6 +450,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
435
450
  let mainFields = getFlag(options, keys, "mainFields", mustBeArray);
436
451
  let conditions = getFlag(options, keys, "conditions", mustBeArray);
437
452
  let external = getFlag(options, keys, "external", mustBeArray);
453
+ let alias = getFlag(options, keys, "alias", mustBeObject);
438
454
  let loader = getFlag(options, keys, "loader", mustBeObject);
439
455
  let outExtension = getFlag(options, keys, "outExtension", mustBeObject);
440
456
  let publicPath = getFlag(options, keys, "publicPath", mustBeString);
@@ -487,7 +503,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
487
503
  if (resolveExtensions) {
488
504
  let values = [];
489
505
  for (let value of resolveExtensions) {
490
- value += "";
506
+ validateStringValue(value, "resolve extension");
491
507
  if (value.indexOf(",") >= 0)
492
508
  throw new Error(`Invalid resolve extension: ${value}`);
493
509
  values.push(value);
@@ -505,7 +521,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
505
521
  if (mainFields) {
506
522
  let values = [];
507
523
  for (let value of mainFields) {
508
- value += "";
524
+ validateStringValue(value, "main field");
509
525
  if (value.indexOf(",") >= 0)
510
526
  throw new Error(`Invalid main field: ${value}`);
511
527
  values.push(value);
@@ -515,7 +531,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
515
531
  if (conditions) {
516
532
  let values = [];
517
533
  for (let value of conditions) {
518
- value += "";
534
+ validateStringValue(value, "condition");
519
535
  if (value.indexOf(",") >= 0)
520
536
  throw new Error(`Invalid condition: ${value}`);
521
537
  values.push(value);
@@ -524,46 +540,53 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
524
540
  }
525
541
  if (external)
526
542
  for (let name of external)
527
- flags.push(`--external:${name}`);
543
+ flags.push(`--external:${validateStringValue(name, "external")}`);
544
+ if (alias) {
545
+ for (let old in alias) {
546
+ if (old.indexOf("=") >= 0)
547
+ throw new Error(`Invalid package name in alias: ${old}`);
548
+ flags.push(`--alias:${old}=${validateStringValue(alias[old], "alias", old)}`);
549
+ }
550
+ }
528
551
  if (banner) {
529
552
  for (let type in banner) {
530
553
  if (type.indexOf("=") >= 0)
531
554
  throw new Error(`Invalid banner file type: ${type}`);
532
- flags.push(`--banner:${type}=${banner[type]}`);
555
+ flags.push(`--banner:${type}=${validateStringValue(banner[type], "banner", type)}`);
533
556
  }
534
557
  }
535
558
  if (footer) {
536
559
  for (let type in footer) {
537
560
  if (type.indexOf("=") >= 0)
538
561
  throw new Error(`Invalid footer file type: ${type}`);
539
- flags.push(`--footer:${type}=${footer[type]}`);
562
+ flags.push(`--footer:${type}=${validateStringValue(footer[type], "footer", type)}`);
540
563
  }
541
564
  }
542
565
  if (inject)
543
566
  for (let path of inject)
544
- flags.push(`--inject:${path}`);
567
+ flags.push(`--inject:${validateStringValue(path, "inject")}`);
545
568
  if (loader) {
546
569
  for (let ext in loader) {
547
570
  if (ext.indexOf("=") >= 0)
548
571
  throw new Error(`Invalid loader extension: ${ext}`);
549
- flags.push(`--loader:${ext}=${loader[ext]}`);
572
+ flags.push(`--loader:${ext}=${validateStringValue(loader[ext], "loader", ext)}`);
550
573
  }
551
574
  }
552
575
  if (outExtension) {
553
576
  for (let ext in outExtension) {
554
577
  if (ext.indexOf("=") >= 0)
555
578
  throw new Error(`Invalid out extension: ${ext}`);
556
- flags.push(`--out-extension:${ext}=${outExtension[ext]}`);
579
+ flags.push(`--out-extension:${ext}=${validateStringValue(outExtension[ext], "out extension", ext)}`);
557
580
  }
558
581
  }
559
582
  if (entryPoints) {
560
583
  if (Array.isArray(entryPoints)) {
561
584
  for (let entryPoint of entryPoints) {
562
- entries.push(["", entryPoint + ""]);
585
+ entries.push(["", validateStringValue(entryPoint, "entry point")]);
563
586
  }
564
587
  } else {
565
- for (let [key, value] of Object.entries(entryPoints)) {
566
- entries.push([key + "", value + ""]);
588
+ for (let key in entryPoints) {
589
+ entries.push([key, validateStringValue(entryPoints[key], "entry point", key)]);
567
590
  }
568
591
  }
569
592
  }
@@ -579,7 +602,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
579
602
  if (loader2)
580
603
  flags.push(`--loader=${loader2}`);
581
604
  if (resolveDir)
582
- stdinResolveDir = resolveDir + "";
605
+ stdinResolveDir = resolveDir;
583
606
  if (typeof contents === "string")
584
607
  stdinContents = encodeUTF8(contents);
585
608
  else if (contents instanceof Uint8Array)
@@ -724,8 +747,8 @@ function createChannel(streamIn) {
724
747
  if (isFirstPacket) {
725
748
  isFirstPacket = false;
726
749
  let binaryVersion = String.fromCharCode(...bytes);
727
- if (binaryVersion !== "0.15.15") {
728
- throw new Error(`Cannot start service: Host version "${"0.15.15"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
750
+ if (binaryVersion !== "0.16.1") {
751
+ throw new Error(`Cannot start service: Host version "${"0.16.1"}" does not match binary version ${quote(binaryVersion)}`);
729
752
  }
730
753
  return;
731
754
  }
@@ -1207,7 +1230,7 @@ var handlePlugins = (buildKey, sendRequest, sendResponse, refs, streamIn, reques
1207
1230
  let setup = getFlag(item, keys, "setup", mustBeFunction);
1208
1231
  if (typeof setup !== "function")
1209
1232
  throw new Error(`Plugin is missing a setup function`);
1210
- checkForInvalidFlags(item, keys, `on plugin ${JSON.stringify(name)}`);
1233
+ checkForInvalidFlags(item, keys, `on plugin ${quote(name)}`);
1211
1234
  let plugin = {
1212
1235
  name,
1213
1236
  onResolve: [],
@@ -1244,6 +1267,8 @@ var handlePlugins = (buildKey, sendRequest, sendResponse, refs, streamIn, reques
1244
1267
  request.resolveDir = resolveDir;
1245
1268
  if (kind != null)
1246
1269
  request.kind = kind;
1270
+ else
1271
+ throw new Error(`Must specify "kind" when calling "resolve"`);
1247
1272
  if (pluginData != null)
1248
1273
  request.pluginData = details.store(pluginData);
1249
1274
  sendRequest(refs, request, (error, response) => {
@@ -1282,7 +1307,7 @@ var handlePlugins = (buildKey, sendRequest, sendResponse, refs, streamIn, reques
1282
1307
  let keys2 = {};
1283
1308
  let filter = getFlag(options, keys2, "filter", mustBeRegExp);
1284
1309
  let namespace = getFlag(options, keys2, "namespace", mustBeString);
1285
- checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${JSON.stringify(name)}`);
1310
+ checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${quote(name)}`);
1286
1311
  if (filter == null)
1287
1312
  throw new Error(`onResolve() call is missing a filter`);
1288
1313
  let id = nextCallbackID++;
@@ -1295,7 +1320,7 @@ var handlePlugins = (buildKey, sendRequest, sendResponse, refs, streamIn, reques
1295
1320
  let keys2 = {};
1296
1321
  let filter = getFlag(options, keys2, "filter", mustBeRegExp);
1297
1322
  let namespace = getFlag(options, keys2, "namespace", mustBeString);
1298
- checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${JSON.stringify(name)}`);
1323
+ checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${quote(name)}`);
1299
1324
  if (filter == null)
1300
1325
  throw new Error(`onLoad() call is missing a filter`);
1301
1326
  let id = nextCallbackID++;
@@ -1318,11 +1343,11 @@ var handlePlugins = (buildKey, sendRequest, sendResponse, refs, streamIn, reques
1318
1343
  let result = yield callback();
1319
1344
  if (result != null) {
1320
1345
  if (typeof result !== "object")
1321
- throw new Error(`Expected onStart() callback in plugin ${JSON.stringify(name)} to return an object`);
1346
+ throw new Error(`Expected onStart() callback in plugin ${quote(name)} to return an object`);
1322
1347
  let keys = {};
1323
1348
  let errors = getFlag(result, keys, "errors", mustBeArray);
1324
1349
  let warnings = getFlag(result, keys, "warnings", mustBeArray);
1325
- checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${JSON.stringify(name)}`);
1350
+ checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${quote(name)}`);
1326
1351
  if (errors != null)
1327
1352
  response.errors.push(...sanitizeMessages(errors, "errors", details, name));
1328
1353
  if (warnings != null)
@@ -1349,7 +1374,7 @@ var handlePlugins = (buildKey, sendRequest, sendResponse, refs, streamIn, reques
1349
1374
  });
1350
1375
  if (result != null) {
1351
1376
  if (typeof result !== "object")
1352
- throw new Error(`Expected onResolve() callback in plugin ${JSON.stringify(name)} to return an object`);
1377
+ throw new Error(`Expected onResolve() callback in plugin ${quote(name)} to return an object`);
1353
1378
  let keys = {};
1354
1379
  let pluginName = getFlag(result, keys, "pluginName", mustBeString);
1355
1380
  let path = getFlag(result, keys, "path", mustBeString);
@@ -1362,7 +1387,7 @@ var handlePlugins = (buildKey, sendRequest, sendResponse, refs, streamIn, reques
1362
1387
  let warnings = getFlag(result, keys, "warnings", mustBeArray);
1363
1388
  let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
1364
1389
  let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
1365
- checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${JSON.stringify(name)}`);
1390
+ checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${quote(name)}`);
1366
1391
  response.id = id2;
1367
1392
  if (pluginName != null)
1368
1393
  response.pluginName = pluginName;
@@ -1408,7 +1433,7 @@ var handlePlugins = (buildKey, sendRequest, sendResponse, refs, streamIn, reques
1408
1433
  });
1409
1434
  if (result != null) {
1410
1435
  if (typeof result !== "object")
1411
- throw new Error(`Expected onLoad() callback in plugin ${JSON.stringify(name)} to return an object`);
1436
+ throw new Error(`Expected onLoad() callback in plugin ${quote(name)} to return an object`);
1412
1437
  let keys = {};
1413
1438
  let pluginName = getFlag(result, keys, "pluginName", mustBeString);
1414
1439
  let contents = getFlag(result, keys, "contents", mustBeStringOrUint8Array);
@@ -1419,7 +1444,7 @@ var handlePlugins = (buildKey, sendRequest, sendResponse, refs, streamIn, reques
1419
1444
  let warnings = getFlag(result, keys, "warnings", mustBeArray);
1420
1445
  let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
1421
1446
  let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
1422
- checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${JSON.stringify(name)}`);
1447
+ checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${quote(name)}`);
1423
1448
  response.id = id2;
1424
1449
  if (pluginName != null)
1425
1450
  response.pluginName = pluginName;
@@ -1497,9 +1522,9 @@ function extractCallerV8(e, streamIn, ident) {
1497
1522
  try {
1498
1523
  let lines = (e.stack + "").split("\n");
1499
1524
  lines.splice(1, 1);
1500
- let location = parseStackLinesV8(streamIn, lines, ident);
1501
- if (location) {
1502
- note = { text: e.message, location };
1525
+ let location2 = parseStackLinesV8(streamIn, lines, ident);
1526
+ if (location2) {
1527
+ note = { text: e.message, location: location2 };
1503
1528
  return note;
1504
1529
  }
1505
1530
  } catch (e2) {
@@ -1508,16 +1533,16 @@ function extractCallerV8(e, streamIn, ident) {
1508
1533
  }
1509
1534
  function extractErrorMessageV8(e, streamIn, stash, note, pluginName) {
1510
1535
  let text = "Internal error";
1511
- let location = null;
1536
+ let location2 = null;
1512
1537
  try {
1513
1538
  text = (e && e.message || e) + "";
1514
1539
  } catch (e2) {
1515
1540
  }
1516
1541
  try {
1517
- location = parseStackLinesV8(streamIn, (e.stack + "").split("\n"), "");
1542
+ location2 = parseStackLinesV8(streamIn, (e.stack + "").split("\n"), "");
1518
1543
  } catch (e2) {
1519
1544
  }
1520
- return { id: "", pluginName, text, location, notes: note ? [note] : [], detail: stash ? stash.store(e) : -1 };
1545
+ return { id: "", pluginName, text, location: location2, notes: note ? [note] : [], detail: stash ? stash.store(e) : -1 };
1521
1546
  }
1522
1547
  function parseStackLinesV8(streamIn, lines, ident) {
1523
1548
  let at = " at ";
@@ -1589,18 +1614,18 @@ function replaceDetailsInMessages(messages, stash) {
1589
1614
  }
1590
1615
  return messages;
1591
1616
  }
1592
- function sanitizeLocation(location, where) {
1593
- if (location == null)
1617
+ function sanitizeLocation(location2, where) {
1618
+ if (location2 == null)
1594
1619
  return null;
1595
1620
  let keys = {};
1596
- let file = getFlag(location, keys, "file", mustBeString);
1597
- let namespace = getFlag(location, keys, "namespace", mustBeString);
1598
- let line = getFlag(location, keys, "line", mustBeInteger);
1599
- let column = getFlag(location, keys, "column", mustBeInteger);
1600
- let length = getFlag(location, keys, "length", mustBeInteger);
1601
- let lineText = getFlag(location, keys, "lineText", mustBeString);
1602
- let suggestion = getFlag(location, keys, "suggestion", mustBeString);
1603
- checkForInvalidFlags(location, keys, where);
1621
+ let file = getFlag(location2, keys, "file", mustBeString);
1622
+ let namespace = getFlag(location2, keys, "namespace", mustBeString);
1623
+ let line = getFlag(location2, keys, "line", mustBeInteger);
1624
+ let column = getFlag(location2, keys, "column", mustBeInteger);
1625
+ let length = getFlag(location2, keys, "length", mustBeInteger);
1626
+ let lineText = getFlag(location2, keys, "lineText", mustBeString);
1627
+ let suggestion = getFlag(location2, keys, "suggestion", mustBeString);
1628
+ checkForInvalidFlags(location2, keys, where);
1604
1629
  return {
1605
1630
  file: file || "",
1606
1631
  namespace: namespace || "",
@@ -1619,7 +1644,7 @@ function sanitizeMessages(messages, property, stash, fallbackPluginName) {
1619
1644
  let id = getFlag(message, keys, "id", mustBeString);
1620
1645
  let pluginName = getFlag(message, keys, "pluginName", mustBeString);
1621
1646
  let text = getFlag(message, keys, "text", mustBeString);
1622
- let location = getFlag(message, keys, "location", mustBeObjectOrNull);
1647
+ let location2 = getFlag(message, keys, "location", mustBeObjectOrNull);
1623
1648
  let notes = getFlag(message, keys, "notes", mustBeArray);
1624
1649
  let detail = getFlag(message, keys, "detail", canBeAnything);
1625
1650
  let where = `in element ${index} of "${property}"`;
@@ -1641,7 +1666,7 @@ function sanitizeMessages(messages, property, stash, fallbackPluginName) {
1641
1666
  id: id || "",
1642
1667
  pluginName: pluginName || fallbackPluginName,
1643
1668
  text: text || "",
1644
- location: sanitizeLocation(location, where),
1669
+ location: sanitizeLocation(location2, where),
1645
1670
  notes: notesClone,
1646
1671
  detail: stash ? stash.store(detail) : -1
1647
1672
  });
@@ -1653,7 +1678,7 @@ function sanitizeStringArray(values, property) {
1653
1678
  const result = [];
1654
1679
  for (const value of values) {
1655
1680
  if (typeof value !== "string")
1656
- throw new Error(`${JSON.stringify(property)} must be an array of strings`);
1681
+ throw new Error(`${quote(property)} must be an array of strings`);
1657
1682
  result.push(value);
1658
1683
  }
1659
1684
  return result;
@@ -1675,7 +1700,7 @@ function convertOutputFiles({ path, contents }) {
1675
1700
  }
1676
1701
 
1677
1702
  // lib/npm/browser.ts
1678
- var version = "0.15.15";
1703
+ var version = "0.16.1";
1679
1704
  var build = (options) => ensureServiceIsRunning().build(options);
1680
1705
  var serve = () => {
1681
1706
  throw new Error(`The "serve" API only works in node`);
@@ -1720,18 +1745,9 @@ var initialize = (options) => {
1720
1745
  return initializePromise;
1721
1746
  };
1722
1747
  var startRunningService = (wasmURL, wasmModule, useWorker) => __async(void 0, null, function* () {
1723
- let wasm;
1724
- if (wasmModule) {
1725
- wasm = wasmModule;
1726
- } else {
1727
- let res = yield fetch(wasmURL);
1728
- if (!res.ok)
1729
- throw new Error(`Failed to download ${JSON.stringify(wasmURL)}`);
1730
- wasm = yield res.arrayBuffer();
1731
- }
1732
1748
  let worker;
1733
1749
  if (useWorker) {
1734
- let blob = new Blob([`onmessage=${'((postMessage) => {\n // Copyright 2018 The Go Authors. All rights reserved.\n // Use of this source code is governed by a BSD-style\n // license that can be found in the LICENSE file.\n var __async = (__this, __arguments, generator) => {\n return new Promise((resolve, reject) => {\n var fulfilled = (value) => {\n try {\n step(generator.next(value));\n } catch (e) {\n reject(e);\n }\n };\n var rejected = (value) => {\n try {\n step(generator.throw(value));\n } catch (e) {\n reject(e);\n }\n };\n var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);\n step((generator = generator.apply(__this, __arguments)).next());\n });\n };\n let onmessage;\n let globalThis = {};\n for (let o = self; o; o = Object.getPrototypeOf(o))\n for (let k of Object.getOwnPropertyNames(o))\n if (!(k in globalThis))\n Object.defineProperty(globalThis, k, { get: () => self[k] });\n "use strict";\n (() => {\n const enosys = () => {\n const err = new Error("not implemented");\n err.code = "ENOSYS";\n return err;\n };\n if (!globalThis.fs) {\n let outputBuf = "";\n globalThis.fs = {\n constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },\n writeSync(fd, buf) {\n outputBuf += decoder.decode(buf);\n const nl = outputBuf.lastIndexOf("\\n");\n if (nl != -1) {\n console.log(outputBuf.substr(0, nl));\n outputBuf = outputBuf.substr(nl + 1);\n }\n return buf.length;\n },\n write(fd, buf, offset, length, position, callback) {\n if (offset !== 0 || length !== buf.length || position !== null) {\n callback(enosys());\n return;\n }\n const n = this.writeSync(fd, buf);\n callback(null, n);\n },\n chmod(path, mode, callback) {\n callback(enosys());\n },\n chown(path, uid, gid, callback) {\n callback(enosys());\n },\n close(fd, callback) {\n callback(enosys());\n },\n fchmod(fd, mode, callback) {\n callback(enosys());\n },\n fchown(fd, uid, gid, callback) {\n callback(enosys());\n },\n fstat(fd, callback) {\n callback(enosys());\n },\n fsync(fd, callback) {\n callback(null);\n },\n ftruncate(fd, length, callback) {\n callback(enosys());\n },\n lchown(path, uid, gid, callback) {\n callback(enosys());\n },\n link(path, link, callback) {\n callback(enosys());\n },\n lstat(path, callback) {\n callback(enosys());\n },\n mkdir(path, perm, callback) {\n callback(enosys());\n },\n open(path, flags, mode, callback) {\n callback(enosys());\n },\n read(fd, buffer, offset, length, position, callback) {\n callback(enosys());\n },\n readdir(path, callback) {\n callback(enosys());\n },\n readlink(path, callback) {\n callback(enosys());\n },\n rename(from, to, callback) {\n callback(enosys());\n },\n rmdir(path, callback) {\n callback(enosys());\n },\n stat(path, callback) {\n callback(enosys());\n },\n symlink(path, link, callback) {\n callback(enosys());\n },\n truncate(path, length, callback) {\n callback(enosys());\n },\n unlink(path, callback) {\n callback(enosys());\n },\n utimes(path, atime, mtime, callback) {\n callback(enosys());\n }\n };\n }\n if (!globalThis.process) {\n globalThis.process = {\n getuid() {\n return -1;\n },\n getgid() {\n return -1;\n },\n geteuid() {\n return -1;\n },\n getegid() {\n return -1;\n },\n getgroups() {\n throw enosys();\n },\n pid: -1,\n ppid: -1,\n umask() {\n throw enosys();\n },\n cwd() {\n throw enosys();\n },\n chdir() {\n throw enosys();\n }\n };\n }\n if (!globalThis.crypto) {\n throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");\n }\n if (!globalThis.performance) {\n throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");\n }\n if (!globalThis.TextEncoder) {\n throw new Error("globalThis.TextEncoder is not available, polyfill required");\n }\n if (!globalThis.TextDecoder) {\n throw new Error("globalThis.TextDecoder is not available, polyfill required");\n }\n const encoder = new TextEncoder("utf-8");\n const decoder = new TextDecoder("utf-8");\n globalThis.Go = class {\n constructor() {\n this.argv = ["js"];\n this.env = {};\n this.exit = (code) => {\n if (code !== 0) {\n console.warn("exit code:", code);\n }\n };\n this._exitPromise = new Promise((resolve) => {\n this._resolveExitPromise = resolve;\n });\n this._pendingEvent = null;\n this._scheduledTimeouts = /* @__PURE__ */ new Map();\n this._nextCallbackTimeoutID = 1;\n const setInt64 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);\n };\n const getInt64 = (addr) => {\n const low = this.mem.getUint32(addr + 0, true);\n const high = this.mem.getInt32(addr + 4, true);\n return low + high * 4294967296;\n };\n const loadValue = (addr) => {\n const f = this.mem.getFloat64(addr, true);\n if (f === 0) {\n return void 0;\n }\n if (!isNaN(f)) {\n return f;\n }\n const id = this.mem.getUint32(addr, true);\n return this._values[id];\n };\n const storeValue = (addr, v) => {\n const nanHead = 2146959360;\n if (typeof v === "number" && v !== 0) {\n if (isNaN(v)) {\n this.mem.setUint32(addr + 4, nanHead, true);\n this.mem.setUint32(addr, 0, true);\n return;\n }\n this.mem.setFloat64(addr, v, true);\n return;\n }\n if (v === void 0) {\n this.mem.setFloat64(addr, 0, true);\n return;\n }\n let id = this._ids.get(v);\n if (id === void 0) {\n id = this._idPool.pop();\n if (id === void 0) {\n id = this._values.length;\n }\n this._values[id] = v;\n this._goRefCounts[id] = 0;\n this._ids.set(v, id);\n }\n this._goRefCounts[id]++;\n let typeFlag = 0;\n switch (typeof v) {\n case "object":\n if (v !== null) {\n typeFlag = 1;\n }\n break;\n case "string":\n typeFlag = 2;\n break;\n case "symbol":\n typeFlag = 3;\n break;\n case "function":\n typeFlag = 4;\n break;\n }\n this.mem.setUint32(addr + 4, nanHead | typeFlag, true);\n this.mem.setUint32(addr, id, true);\n };\n const loadSlice = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return new Uint8Array(this._inst.exports.mem.buffer, array, len);\n };\n const loadSliceOfValues = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n const a = new Array(len);\n for (let i = 0; i < len; i++) {\n a[i] = loadValue(array + i * 8);\n }\n return a;\n };\n const loadString = (addr) => {\n const saddr = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));\n };\n const timeOrigin = Date.now() - performance.now();\n this.importObject = {\n go: {\n "runtime.wasmExit": (sp) => {\n sp >>>= 0;\n const code = this.mem.getInt32(sp + 8, true);\n this.exited = true;\n delete this._inst;\n delete this._values;\n delete this._goRefCounts;\n delete this._ids;\n delete this._idPool;\n this.exit(code);\n },\n "runtime.wasmWrite": (sp) => {\n sp >>>= 0;\n const fd = getInt64(sp + 8);\n const p = getInt64(sp + 16);\n const n = this.mem.getInt32(sp + 24, true);\n globalThis.fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));\n },\n "runtime.resetMemoryDataView": (sp) => {\n sp >>>= 0;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n },\n "runtime.nanotime1": (sp) => {\n sp >>>= 0;\n setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);\n },\n "runtime.walltime": (sp) => {\n sp >>>= 0;\n const msec = new Date().getTime();\n setInt64(sp + 8, msec / 1e3);\n this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);\n },\n "runtime.scheduleTimeoutEvent": (sp) => {\n sp >>>= 0;\n const id = this._nextCallbackTimeoutID;\n this._nextCallbackTimeoutID++;\n this._scheduledTimeouts.set(id, setTimeout(\n () => {\n this._resume();\n while (this._scheduledTimeouts.has(id)) {\n console.warn("scheduleTimeoutEvent: missed timeout event");\n this._resume();\n }\n },\n getInt64(sp + 8) + 1\n ));\n this.mem.setInt32(sp + 16, id, true);\n },\n "runtime.clearTimeoutEvent": (sp) => {\n sp >>>= 0;\n const id = this.mem.getInt32(sp + 8, true);\n clearTimeout(this._scheduledTimeouts.get(id));\n this._scheduledTimeouts.delete(id);\n },\n "runtime.getRandomData": (sp) => {\n sp >>>= 0;\n crypto.getRandomValues(loadSlice(sp + 8));\n },\n "syscall/js.finalizeRef": (sp) => {\n sp >>>= 0;\n const id = this.mem.getUint32(sp + 8, true);\n this._goRefCounts[id]--;\n if (this._goRefCounts[id] === 0) {\n const v = this._values[id];\n this._values[id] = null;\n this._ids.delete(v);\n this._idPool.push(id);\n }\n },\n "syscall/js.stringVal": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, loadString(sp + 8));\n },\n "syscall/js.valueGet": (sp) => {\n sp >>>= 0;\n const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 32, result);\n },\n "syscall/js.valueSet": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n },\n "syscall/js.valueDelete": (sp) => {\n sp >>>= 0;\n Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n },\n "syscall/js.valueIndex": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n },\n "syscall/js.valueSetIndex": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n },\n "syscall/js.valueCall": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const m = Reflect.get(v, loadString(sp + 16));\n const args = loadSliceOfValues(sp + 32);\n const result = Reflect.apply(m, v, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 56, result);\n this.mem.setUint8(sp + 64, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 56, err);\n this.mem.setUint8(sp + 64, 0);\n }\n },\n "syscall/js.valueInvoke": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.apply(v, void 0, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n "syscall/js.valueNew": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.construct(v, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n "syscall/js.valueLength": (sp) => {\n sp >>>= 0;\n setInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n },\n "syscall/js.valuePrepareString": (sp) => {\n sp >>>= 0;\n const str = encoder.encode(String(loadValue(sp + 8)));\n storeValue(sp + 16, str);\n setInt64(sp + 24, str.length);\n },\n "syscall/js.valueLoadString": (sp) => {\n sp >>>= 0;\n const str = loadValue(sp + 8);\n loadSlice(sp + 16).set(str);\n },\n "syscall/js.valueInstanceOf": (sp) => {\n sp >>>= 0;\n this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);\n },\n "syscall/js.copyBytesToGo": (sp) => {\n sp >>>= 0;\n const dst = loadSlice(sp + 8);\n const src = loadValue(sp + 32);\n if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "syscall/js.copyBytesToJS": (sp) => {\n sp >>>= 0;\n const dst = loadValue(sp + 8);\n const src = loadSlice(sp + 16);\n if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "debug": (value) => {\n console.log(value);\n }\n }\n };\n }\n run(instance) {\n return __async(this, null, function* () {\n if (!(instance instanceof WebAssembly.Instance)) {\n throw new Error("Go.run: WebAssembly.Instance expected");\n }\n this._inst = instance;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n this._values = [\n NaN,\n 0,\n null,\n true,\n false,\n globalThis,\n this\n ];\n this._goRefCounts = new Array(this._values.length).fill(Infinity);\n this._ids = /* @__PURE__ */ new Map([\n [0, 1],\n [null, 2],\n [true, 3],\n [false, 4],\n [globalThis, 5],\n [this, 6]\n ]);\n this._idPool = [];\n this.exited = false;\n let offset = 4096;\n const strPtr = (str) => {\n const ptr = offset;\n const bytes = encoder.encode(str + "\\0");\n new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);\n offset += bytes.length;\n if (offset % 8 !== 0) {\n offset += 8 - offset % 8;\n }\n return ptr;\n };\n const argc = this.argv.length;\n const argvPtrs = [];\n this.argv.forEach((arg) => {\n argvPtrs.push(strPtr(arg));\n });\n argvPtrs.push(0);\n const keys = Object.keys(this.env).sort();\n keys.forEach((key) => {\n argvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n });\n argvPtrs.push(0);\n const argv = offset;\n argvPtrs.forEach((ptr) => {\n this.mem.setUint32(offset, ptr, true);\n this.mem.setUint32(offset + 4, 0, true);\n offset += 8;\n });\n const wasmMinDataAddr = 4096 + 8192;\n if (offset >= wasmMinDataAddr) {\n throw new Error("total length of command line and environment variables exceeds limit");\n }\n this._inst.exports.run(argc, argv);\n if (this.exited) {\n this._resolveExitPromise();\n }\n yield this._exitPromise;\n });\n }\n _resume() {\n if (this.exited) {\n throw new Error("Go program has already exited");\n }\n this._inst.exports.resume();\n if (this.exited) {\n this._resolveExitPromise();\n }\n }\n _makeFuncWrapper(id) {\n const go = this;\n return function() {\n const event = { id, this: this, args: arguments };\n go._pendingEvent = event;\n go._resume();\n return event.result;\n };\n }\n };\n })();\n onmessage = ({ data: wasm }) => {\n let decoder = new TextDecoder();\n let fs = globalThis.fs;\n let stderr = "";\n fs.writeSync = (fd, buffer) => {\n if (fd === 1) {\n postMessage(buffer);\n } else if (fd === 2) {\n stderr += decoder.decode(buffer);\n let parts = stderr.split("\\n");\n if (parts.length > 1)\n console.log(parts.slice(0, -1).join("\\n"));\n stderr = parts[parts.length - 1];\n } else {\n throw new Error("Bad write");\n }\n return buffer.length;\n };\n let stdin = [];\n let resumeStdin;\n let stdinPos = 0;\n onmessage = ({ data }) => {\n if (data.length > 0) {\n stdin.push(data);\n if (resumeStdin)\n resumeStdin();\n }\n };\n fs.read = (fd, buffer, offset, length, position, callback) => {\n if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) {\n throw new Error("Bad read");\n }\n if (stdin.length === 0) {\n resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback);\n return;\n }\n let first = stdin[0];\n let count = Math.max(0, Math.min(length, first.length - stdinPos));\n buffer.set(first.subarray(stdinPos, stdinPos + count), offset);\n stdinPos += count;\n if (stdinPos === first.length) {\n stdin.shift();\n stdinPos = 0;\n }\n callback(null, count);\n };\n let go = new globalThis.Go();\n go.argv = ["", `--service=${"0.15.15"}`];\n if (wasm instanceof WebAssembly.Module) {\n WebAssembly.instantiate(wasm, go.importObject).then((instance) => go.run(instance));\n } else {\n WebAssembly.instantiate(wasm, go.importObject).then(({ instance }) => go.run(instance));\n }\n };\n return (m) => onmessage(m);\n })'}(postMessage)`], { type: "text/javascript" });
1750
+ let blob = new Blob([`onmessage=${'((postMessage) => {\n // Copyright 2018 The Go Authors. All rights reserved.\n // Use of this source code is governed by a BSD-style\n // license that can be found in the LICENSE file.\n var __async = (__this, __arguments, generator) => {\n return new Promise((resolve, reject) => {\n var fulfilled = (value) => {\n try {\n step(generator.next(value));\n } catch (e) {\n reject(e);\n }\n };\n var rejected = (value) => {\n try {\n step(generator.throw(value));\n } catch (e) {\n reject(e);\n }\n };\n var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);\n step((generator = generator.apply(__this, __arguments)).next());\n });\n };\n let onmessage;\n let globalThis = {};\n for (let o = self; o; o = Object.getPrototypeOf(o))\n for (let k of Object.getOwnPropertyNames(o))\n if (!(k in globalThis))\n Object.defineProperty(globalThis, k, { get: () => self[k] });\n "use strict";\n (() => {\n const enosys = () => {\n const err = new Error("not implemented");\n err.code = "ENOSYS";\n return err;\n };\n if (!globalThis.fs) {\n let outputBuf = "";\n globalThis.fs = {\n constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },\n writeSync(fd, buf) {\n outputBuf += decoder.decode(buf);\n const nl = outputBuf.lastIndexOf("\\n");\n if (nl != -1) {\n console.log(outputBuf.substr(0, nl));\n outputBuf = outputBuf.substr(nl + 1);\n }\n return buf.length;\n },\n write(fd, buf, offset, length, position, callback) {\n if (offset !== 0 || length !== buf.length || position !== null) {\n callback(enosys());\n return;\n }\n const n = this.writeSync(fd, buf);\n callback(null, n);\n },\n chmod(path, mode, callback) {\n callback(enosys());\n },\n chown(path, uid, gid, callback) {\n callback(enosys());\n },\n close(fd, callback) {\n callback(enosys());\n },\n fchmod(fd, mode, callback) {\n callback(enosys());\n },\n fchown(fd, uid, gid, callback) {\n callback(enosys());\n },\n fstat(fd, callback) {\n callback(enosys());\n },\n fsync(fd, callback) {\n callback(null);\n },\n ftruncate(fd, length, callback) {\n callback(enosys());\n },\n lchown(path, uid, gid, callback) {\n callback(enosys());\n },\n link(path, link, callback) {\n callback(enosys());\n },\n lstat(path, callback) {\n callback(enosys());\n },\n mkdir(path, perm, callback) {\n callback(enosys());\n },\n open(path, flags, mode, callback) {\n callback(enosys());\n },\n read(fd, buffer, offset, length, position, callback) {\n callback(enosys());\n },\n readdir(path, callback) {\n callback(enosys());\n },\n readlink(path, callback) {\n callback(enosys());\n },\n rename(from, to, callback) {\n callback(enosys());\n },\n rmdir(path, callback) {\n callback(enosys());\n },\n stat(path, callback) {\n callback(enosys());\n },\n symlink(path, link, callback) {\n callback(enosys());\n },\n truncate(path, length, callback) {\n callback(enosys());\n },\n unlink(path, callback) {\n callback(enosys());\n },\n utimes(path, atime, mtime, callback) {\n callback(enosys());\n }\n };\n }\n if (!globalThis.process) {\n globalThis.process = {\n getuid() {\n return -1;\n },\n getgid() {\n return -1;\n },\n geteuid() {\n return -1;\n },\n getegid() {\n return -1;\n },\n getgroups() {\n throw enosys();\n },\n pid: -1,\n ppid: -1,\n umask() {\n throw enosys();\n },\n cwd() {\n throw enosys();\n },\n chdir() {\n throw enosys();\n }\n };\n }\n if (!globalThis.crypto) {\n throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");\n }\n if (!globalThis.performance) {\n throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");\n }\n if (!globalThis.TextEncoder) {\n throw new Error("globalThis.TextEncoder is not available, polyfill required");\n }\n if (!globalThis.TextDecoder) {\n throw new Error("globalThis.TextDecoder is not available, polyfill required");\n }\n const encoder = new TextEncoder("utf-8");\n const decoder = new TextDecoder("utf-8");\n globalThis.Go = class {\n constructor() {\n this.argv = ["js"];\n this.env = {};\n this.exit = (code) => {\n if (code !== 0) {\n console.warn("exit code:", code);\n }\n };\n this._exitPromise = new Promise((resolve) => {\n this._resolveExitPromise = resolve;\n });\n this._pendingEvent = null;\n this._scheduledTimeouts = /* @__PURE__ */ new Map();\n this._nextCallbackTimeoutID = 1;\n const setInt64 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);\n };\n const getInt64 = (addr) => {\n const low = this.mem.getUint32(addr + 0, true);\n const high = this.mem.getInt32(addr + 4, true);\n return low + high * 4294967296;\n };\n const loadValue = (addr) => {\n const f = this.mem.getFloat64(addr, true);\n if (f === 0) {\n return void 0;\n }\n if (!isNaN(f)) {\n return f;\n }\n const id = this.mem.getUint32(addr, true);\n return this._values[id];\n };\n const storeValue = (addr, v) => {\n const nanHead = 2146959360;\n if (typeof v === "number" && v !== 0) {\n if (isNaN(v)) {\n this.mem.setUint32(addr + 4, nanHead, true);\n this.mem.setUint32(addr, 0, true);\n return;\n }\n this.mem.setFloat64(addr, v, true);\n return;\n }\n if (v === void 0) {\n this.mem.setFloat64(addr, 0, true);\n return;\n }\n let id = this._ids.get(v);\n if (id === void 0) {\n id = this._idPool.pop();\n if (id === void 0) {\n id = this._values.length;\n }\n this._values[id] = v;\n this._goRefCounts[id] = 0;\n this._ids.set(v, id);\n }\n this._goRefCounts[id]++;\n let typeFlag = 0;\n switch (typeof v) {\n case "object":\n if (v !== null) {\n typeFlag = 1;\n }\n break;\n case "string":\n typeFlag = 2;\n break;\n case "symbol":\n typeFlag = 3;\n break;\n case "function":\n typeFlag = 4;\n break;\n }\n this.mem.setUint32(addr + 4, nanHead | typeFlag, true);\n this.mem.setUint32(addr, id, true);\n };\n const loadSlice = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return new Uint8Array(this._inst.exports.mem.buffer, array, len);\n };\n const loadSliceOfValues = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n const a = new Array(len);\n for (let i = 0; i < len; i++) {\n a[i] = loadValue(array + i * 8);\n }\n return a;\n };\n const loadString = (addr) => {\n const saddr = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));\n };\n const timeOrigin = Date.now() - performance.now();\n this.importObject = {\n go: {\n "runtime.wasmExit": (sp) => {\n sp >>>= 0;\n const code = this.mem.getInt32(sp + 8, true);\n this.exited = true;\n delete this._inst;\n delete this._values;\n delete this._goRefCounts;\n delete this._ids;\n delete this._idPool;\n this.exit(code);\n },\n "runtime.wasmWrite": (sp) => {\n sp >>>= 0;\n const fd = getInt64(sp + 8);\n const p = getInt64(sp + 16);\n const n = this.mem.getInt32(sp + 24, true);\n globalThis.fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));\n },\n "runtime.resetMemoryDataView": (sp) => {\n sp >>>= 0;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n },\n "runtime.nanotime1": (sp) => {\n sp >>>= 0;\n setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);\n },\n "runtime.walltime": (sp) => {\n sp >>>= 0;\n const msec = new Date().getTime();\n setInt64(sp + 8, msec / 1e3);\n this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);\n },\n "runtime.scheduleTimeoutEvent": (sp) => {\n sp >>>= 0;\n const id = this._nextCallbackTimeoutID;\n this._nextCallbackTimeoutID++;\n this._scheduledTimeouts.set(id, setTimeout(\n () => {\n this._resume();\n while (this._scheduledTimeouts.has(id)) {\n console.warn("scheduleTimeoutEvent: missed timeout event");\n this._resume();\n }\n },\n getInt64(sp + 8) + 1\n ));\n this.mem.setInt32(sp + 16, id, true);\n },\n "runtime.clearTimeoutEvent": (sp) => {\n sp >>>= 0;\n const id = this.mem.getInt32(sp + 8, true);\n clearTimeout(this._scheduledTimeouts.get(id));\n this._scheduledTimeouts.delete(id);\n },\n "runtime.getRandomData": (sp) => {\n sp >>>= 0;\n crypto.getRandomValues(loadSlice(sp + 8));\n },\n "syscall/js.finalizeRef": (sp) => {\n sp >>>= 0;\n const id = this.mem.getUint32(sp + 8, true);\n this._goRefCounts[id]--;\n if (this._goRefCounts[id] === 0) {\n const v = this._values[id];\n this._values[id] = null;\n this._ids.delete(v);\n this._idPool.push(id);\n }\n },\n "syscall/js.stringVal": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, loadString(sp + 8));\n },\n "syscall/js.valueGet": (sp) => {\n sp >>>= 0;\n const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 32, result);\n },\n "syscall/js.valueSet": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n },\n "syscall/js.valueDelete": (sp) => {\n sp >>>= 0;\n Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n },\n "syscall/js.valueIndex": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n },\n "syscall/js.valueSetIndex": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n },\n "syscall/js.valueCall": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const m = Reflect.get(v, loadString(sp + 16));\n const args = loadSliceOfValues(sp + 32);\n const result = Reflect.apply(m, v, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 56, result);\n this.mem.setUint8(sp + 64, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 56, err);\n this.mem.setUint8(sp + 64, 0);\n }\n },\n "syscall/js.valueInvoke": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.apply(v, void 0, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n "syscall/js.valueNew": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.construct(v, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n "syscall/js.valueLength": (sp) => {\n sp >>>= 0;\n setInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n },\n "syscall/js.valuePrepareString": (sp) => {\n sp >>>= 0;\n const str = encoder.encode(String(loadValue(sp + 8)));\n storeValue(sp + 16, str);\n setInt64(sp + 24, str.length);\n },\n "syscall/js.valueLoadString": (sp) => {\n sp >>>= 0;\n const str = loadValue(sp + 8);\n loadSlice(sp + 16).set(str);\n },\n "syscall/js.valueInstanceOf": (sp) => {\n sp >>>= 0;\n this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);\n },\n "syscall/js.copyBytesToGo": (sp) => {\n sp >>>= 0;\n const dst = loadSlice(sp + 8);\n const src = loadValue(sp + 32);\n if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "syscall/js.copyBytesToJS": (sp) => {\n sp >>>= 0;\n const dst = loadValue(sp + 8);\n const src = loadSlice(sp + 16);\n if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "debug": (value) => {\n console.log(value);\n }\n }\n };\n }\n run(instance) {\n return __async(this, null, function* () {\n if (!(instance instanceof WebAssembly.Instance)) {\n throw new Error("Go.run: WebAssembly.Instance expected");\n }\n this._inst = instance;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n this._values = [\n NaN,\n 0,\n null,\n true,\n false,\n globalThis,\n this\n ];\n this._goRefCounts = new Array(this._values.length).fill(Infinity);\n this._ids = /* @__PURE__ */ new Map([\n [0, 1],\n [null, 2],\n [true, 3],\n [false, 4],\n [globalThis, 5],\n [this, 6]\n ]);\n this._idPool = [];\n this.exited = false;\n let offset = 4096;\n const strPtr = (str) => {\n const ptr = offset;\n const bytes = encoder.encode(str + "\\0");\n new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);\n offset += bytes.length;\n if (offset % 8 !== 0) {\n offset += 8 - offset % 8;\n }\n return ptr;\n };\n const argc = this.argv.length;\n const argvPtrs = [];\n this.argv.forEach((arg) => {\n argvPtrs.push(strPtr(arg));\n });\n argvPtrs.push(0);\n const keys = Object.keys(this.env).sort();\n keys.forEach((key) => {\n argvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n });\n argvPtrs.push(0);\n const argv = offset;\n argvPtrs.forEach((ptr) => {\n this.mem.setUint32(offset, ptr, true);\n this.mem.setUint32(offset + 4, 0, true);\n offset += 8;\n });\n const wasmMinDataAddr = 4096 + 8192;\n if (offset >= wasmMinDataAddr) {\n throw new Error("total length of command line and environment variables exceeds limit");\n }\n this._inst.exports.run(argc, argv);\n if (this.exited) {\n this._resolveExitPromise();\n }\n yield this._exitPromise;\n });\n }\n _resume() {\n if (this.exited) {\n throw new Error("Go program has already exited");\n }\n this._inst.exports.resume();\n if (this.exited) {\n this._resolveExitPromise();\n }\n }\n _makeFuncWrapper(id) {\n const go = this;\n return function() {\n const event = { id, this: this, args: arguments };\n go._pendingEvent = event;\n go._resume();\n return event.result;\n };\n }\n };\n })();\n onmessage = ({ data: wasm }) => {\n let decoder = new TextDecoder();\n let fs = globalThis.fs;\n let stderr = "";\n fs.writeSync = (fd, buffer) => {\n if (fd === 1) {\n postMessage(buffer);\n } else if (fd === 2) {\n stderr += decoder.decode(buffer);\n let parts = stderr.split("\\n");\n if (parts.length > 1)\n console.log(parts.slice(0, -1).join("\\n"));\n stderr = parts[parts.length - 1];\n } else {\n throw new Error("Bad write");\n }\n return buffer.length;\n };\n let stdin = [];\n let resumeStdin;\n let stdinPos = 0;\n onmessage = ({ data }) => {\n if (data.length > 0) {\n stdin.push(data);\n if (resumeStdin)\n resumeStdin();\n }\n };\n fs.read = (fd, buffer, offset, length, position, callback) => {\n if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) {\n throw new Error("Bad read");\n }\n if (stdin.length === 0) {\n resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback);\n return;\n }\n let first = stdin[0];\n let count = Math.max(0, Math.min(length, first.length - stdinPos));\n buffer.set(first.subarray(stdinPos, stdinPos + count), offset);\n stdinPos += count;\n if (stdinPos === first.length) {\n stdin.shift();\n stdinPos = 0;\n }\n callback(null, count);\n };\n let go = new globalThis.Go();\n go.argv = ["", `--service=${"0.16.1"}`];\n tryToInstantiateModule(wasm, go).then(\n (instance) => {\n postMessage(null);\n go.run(instance);\n },\n (error) => {\n postMessage(error);\n }\n );\n };\n function tryToInstantiateModule(wasm, go) {\n return __async(this, null, function* () {\n if (wasm instanceof WebAssembly.Module) {\n return WebAssembly.instantiate(wasm, go.importObject);\n }\n const res = yield fetch(wasm);\n if (!res.ok)\n throw new Error(`Failed to download ${JSON.stringify(wasm)}`);\n if ("instantiateStreaming" in WebAssembly && /^application\\/wasm($|;)/i.test(res.headers.get("Content-Type") || "")) {\n const result2 = yield WebAssembly.instantiateStreaming(res, go.importObject);\n return result2.instance;\n }\n const bytes = yield res.arrayBuffer();\n const result = yield WebAssembly.instantiate(bytes, go.importObject);\n return result.instance;\n });\n }\n return (m) => onmessage(m);\n })'}(postMessage)`], { type: "text/javascript" });
1735
1751
  worker = new Worker(URL.createObjectURL(blob));
1736
1752
  } else {
1737
1753
  let onmessage = ((postMessage) => {
@@ -2335,13 +2351,34 @@ var startRunningService = (wasmURL, wasmModule, useWorker) => __async(void 0, nu
2335
2351
  callback(null, count);
2336
2352
  };
2337
2353
  let go = new globalThis.Go();
2338
- go.argv = ["", `--service=${"0.15.15"}`];
2339
- if (wasm instanceof WebAssembly.Module) {
2340
- WebAssembly.instantiate(wasm, go.importObject).then((instance) => go.run(instance));
2341
- } else {
2342
- WebAssembly.instantiate(wasm, go.importObject).then(({ instance }) => go.run(instance));
2343
- }
2354
+ go.argv = ["", `--service=${"0.16.1"}`];
2355
+ tryToInstantiateModule(wasm, go).then(
2356
+ (instance) => {
2357
+ postMessage(null);
2358
+ go.run(instance);
2359
+ },
2360
+ (error) => {
2361
+ postMessage(error);
2362
+ }
2363
+ );
2344
2364
  };
2365
+ function tryToInstantiateModule(wasm, go) {
2366
+ return __async(this, null, function* () {
2367
+ if (wasm instanceof WebAssembly.Module) {
2368
+ return WebAssembly.instantiate(wasm, go.importObject);
2369
+ }
2370
+ const res = yield fetch(wasm);
2371
+ if (!res.ok)
2372
+ throw new Error(`Failed to download ${JSON.stringify(wasm)}`);
2373
+ if ("instantiateStreaming" in WebAssembly && /^application\/wasm($|;)/i.test(res.headers.get("Content-Type") || "")) {
2374
+ const result2 = yield WebAssembly.instantiateStreaming(res, go.importObject);
2375
+ return result2.instance;
2376
+ }
2377
+ const bytes = yield res.arrayBuffer();
2378
+ const result = yield WebAssembly.instantiate(bytes, go.importObject);
2379
+ return result.instance;
2380
+ });
2381
+ }
2345
2382
  return (m) => onmessage(m);
2346
2383
  })((data) => worker.onmessage({ data }));
2347
2384
  worker = {
@@ -2351,8 +2388,20 @@ var startRunningService = (wasmURL, wasmModule, useWorker) => __async(void 0, nu
2351
2388
  }
2352
2389
  };
2353
2390
  }
2354
- worker.postMessage(wasm);
2355
- worker.onmessage = ({ data }) => readFromStdout(data);
2391
+ let firstMessageResolve;
2392
+ let firstMessageReject;
2393
+ const firstMessagePromise = new Promise((resolve, reject) => {
2394
+ firstMessageResolve = resolve;
2395
+ firstMessageReject = reject;
2396
+ });
2397
+ worker.onmessage = ({ data: error }) => {
2398
+ worker.onmessage = ({ data }) => readFromStdout(data);
2399
+ if (error)
2400
+ firstMessageReject(error);
2401
+ else
2402
+ firstMessageResolve();
2403
+ };
2404
+ worker.postMessage(wasmModule || new URL(wasmURL, location.href).toString());
2356
2405
  let { readFromStdout, service } = createChannel({
2357
2406
  writeToStdin(bytes) {
2358
2407
  worker.postMessage(bytes);
@@ -2361,6 +2410,7 @@ var startRunningService = (wasmURL, wasmModule, useWorker) => __async(void 0, nu
2361
2410
  isWriteUnavailable: true,
2362
2411
  esbuild: browser_exports
2363
2412
  });
2413
+ yield firstMessagePromise;
2364
2414
  longLivedService = {
2365
2415
  build: (options) => new Promise((resolve, reject) => service.buildOrServe({
2366
2416
  callName: "build",