isomorfeus-asset-manager 0.15.10 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -155,26 +155,30 @@ var ByteBuffer = class {
155
155
  };
156
156
  var encodeUTF8;
157
157
  var decodeUTF8;
158
+ var encodeInvariant;
158
159
  if (typeof TextEncoder !== "undefined" && typeof TextDecoder !== "undefined") {
159
160
  let encoder = new TextEncoder();
160
161
  let decoder = new TextDecoder();
161
162
  encodeUTF8 = (text) => encoder.encode(text);
162
163
  decodeUTF8 = (bytes) => decoder.decode(bytes);
164
+ encodeInvariant = 'new TextEncoder().encode("")';
163
165
  } else if (typeof Buffer !== "undefined") {
164
- encodeUTF8 = (text) => {
165
- let buffer = Buffer.from(text);
166
- if (!(buffer instanceof Uint8Array)) {
167
- buffer = new Uint8Array(buffer);
168
- }
169
- return buffer;
170
- };
166
+ encodeUTF8 = (text) => Buffer.from(text);
171
167
  decodeUTF8 = (bytes) => {
172
168
  let { buffer, byteOffset, byteLength } = bytes;
173
169
  return Buffer.from(buffer, byteOffset, byteLength).toString();
174
170
  };
171
+ encodeInvariant = 'Buffer.from("")';
175
172
  } else {
176
173
  throw new Error("No UTF-8 codec found");
177
174
  }
175
+ if (!(encodeUTF8("") instanceof Uint8Array))
176
+ throw new Error(`Invariant violation: "${encodeInvariant} instanceof Uint8Array" is incorrectly false
177
+
178
+ This indicates that your JavaScript environment is broken. You cannot use
179
+ esbuild in this environment because esbuild relies on this invariant. This
180
+ is not a problem with esbuild. You need to fix your environment instead.
181
+ `);
178
182
  function readUInt32LE(buffer, offset) {
179
183
  return buffer[offset++] | buffer[offset++] << 8 | buffer[offset++] << 16 | buffer[offset++] << 24;
180
184
  }
@@ -186,10 +190,11 @@ function writeUInt32LE(buffer, value, offset) {
186
190
  }
187
191
 
188
192
  // lib/shared/common.ts
193
+ var quote = JSON.stringify;
189
194
  var buildLogLevelDefault = "warning";
190
195
  var transformLogLevelDefault = "silent";
191
196
  function validateTarget(target) {
192
- target += "";
197
+ validateStringValue(target, "target");
193
198
  if (target.indexOf(",") >= 0)
194
199
  throw new Error(`Invalid target: ${target}`);
195
200
  return target;
@@ -210,6 +215,7 @@ var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value
210
215
  var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object";
211
216
  var mustBeStringOrArray = (value) => typeof value === "string" || Array.isArray(value) ? null : "a string or an array";
212
217
  var mustBeStringOrUint8Array = (value) => typeof value === "string" || value instanceof Uint8Array ? null : "a string or a Uint8Array";
218
+ var mustBeStringOrURL = (value) => typeof value === "string" || value instanceof URL ? null : "a string or a URL";
213
219
  function getFlag(object, keys, key, mustBeFn) {
214
220
  let value = object[key];
215
221
  keys[key + ""] = true;
@@ -217,19 +223,19 @@ function getFlag(object, keys, key, mustBeFn) {
217
223
  return void 0;
218
224
  let mustBe = mustBeFn(value);
219
225
  if (mustBe !== null)
220
- throw new Error(`"${key}" must be ${mustBe}`);
226
+ throw new Error(`${quote(key)} must be ${mustBe}`);
221
227
  return value;
222
228
  }
223
229
  function checkForInvalidFlags(object, keys, where) {
224
230
  for (let key in object) {
225
231
  if (!(key in keys)) {
226
- throw new Error(`Invalid option ${where}: "${key}"`);
232
+ throw new Error(`Invalid option ${where}: ${quote(key)}`);
227
233
  }
228
234
  }
229
235
  }
230
236
  function validateInitializeOptions(options) {
231
237
  let keys = /* @__PURE__ */ Object.create(null);
232
- let wasmURL = getFlag(options, keys, "wasmURL", mustBeString);
238
+ let wasmURL = getFlag(options, keys, "wasmURL", mustBeStringOrURL);
233
239
  let wasmModule = getFlag(options, keys, "wasmModule", mustBeWebAssemblyModule);
234
240
  let worker = getFlag(options, keys, "worker", mustBeBoolean);
235
241
  checkForInvalidFlags(options, keys, "in initialize() call");
@@ -243,12 +249,12 @@ function validateMangleCache(mangleCache) {
243
249
  let validated;
244
250
  if (mangleCache !== void 0) {
245
251
  validated = /* @__PURE__ */ Object.create(null);
246
- for (let key of Object.keys(mangleCache)) {
252
+ for (let key in mangleCache) {
247
253
  let value = mangleCache[key];
248
254
  if (typeof value === "string" || value === false) {
249
255
  validated[key] = value;
250
256
  } else {
251
- throw new Error(`Expected ${JSON.stringify(key)} in mangle cache to map to either a string or false`);
257
+ throw new Error(`Expected ${quote(key)} in mangle cache to map to either a string or false`);
252
258
  }
253
259
  }
254
260
  }
@@ -265,6 +271,12 @@ function pushLogFlags(flags, options, keys, isTTY, logLevelDefault) {
265
271
  flags.push(`--log-level=${logLevel || logLevelDefault}`);
266
272
  flags.push(`--log-limit=${logLimit || 0}`);
267
273
  }
274
+ function validateStringValue(value, what, key) {
275
+ if (typeof value !== "string") {
276
+ throw new Error(`Expected value for ${what}${key !== void 0 ? " " + quote(key) : ""} to be a string, got ${typeof value} instead`);
277
+ }
278
+ return value;
279
+ }
268
280
  function pushCommonFlags(flags, options, keys) {
269
281
  let legalComments = getFlag(options, keys, "legalComments", mustBeString);
270
282
  let sourceRoot = getFlag(options, keys, "sourceRoot", mustBeString);
@@ -329,7 +341,7 @@ function pushCommonFlags(flags, options, keys) {
329
341
  flags.push(`--ignore-annotations`);
330
342
  if (drop)
331
343
  for (let what of drop)
332
- flags.push(`--drop:${what}`);
344
+ flags.push(`--drop:${validateStringValue(what, "drop")}`);
333
345
  if (mangleProps)
334
346
  flags.push(`--mangle-props=${mangleProps.source}`);
335
347
  if (reserveProps)
@@ -352,26 +364,29 @@ function pushCommonFlags(flags, options, keys) {
352
364
  for (let key in define) {
353
365
  if (key.indexOf("=") >= 0)
354
366
  throw new Error(`Invalid define: ${key}`);
355
- flags.push(`--define:${key}=${define[key]}`);
367
+ flags.push(`--define:${key}=${validateStringValue(define[key], "define", key)}`);
356
368
  }
357
369
  }
358
370
  if (logOverride) {
359
371
  for (let key in logOverride) {
360
372
  if (key.indexOf("=") >= 0)
361
373
  throw new Error(`Invalid log override: ${key}`);
362
- flags.push(`--log-override:${key}=${logOverride[key]}`);
374
+ flags.push(`--log-override:${key}=${validateStringValue(logOverride[key], "log override", key)}`);
363
375
  }
364
376
  }
365
377
  if (supported) {
366
378
  for (let key in supported) {
367
379
  if (key.indexOf("=") >= 0)
368
380
  throw new Error(`Invalid supported: ${key}`);
369
- flags.push(`--supported:${key}=${supported[key]}`);
381
+ const value = supported[key];
382
+ if (typeof value !== "boolean")
383
+ throw new Error(`Expected value for supported ${quote(key)} to be a boolean, got ${typeof value} instead`);
384
+ flags.push(`--supported:${key}=${value}`);
370
385
  }
371
386
  }
372
387
  if (pure)
373
388
  for (let fn of pure)
374
- flags.push(`--pure:${fn}`);
389
+ flags.push(`--pure:${validateStringValue(fn, "pure")}`);
375
390
  if (keepNames)
376
391
  flags.push(`--keep-names`);
377
392
  }
@@ -400,6 +415,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
400
415
  let mainFields = getFlag(options, keys, "mainFields", mustBeArray);
401
416
  let conditions = getFlag(options, keys, "conditions", mustBeArray);
402
417
  let external = getFlag(options, keys, "external", mustBeArray);
418
+ let alias = getFlag(options, keys, "alias", mustBeObject);
403
419
  let loader = getFlag(options, keys, "loader", mustBeObject);
404
420
  let outExtension = getFlag(options, keys, "outExtension", mustBeObject);
405
421
  let publicPath = getFlag(options, keys, "publicPath", mustBeString);
@@ -452,7 +468,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
452
468
  if (resolveExtensions) {
453
469
  let values = [];
454
470
  for (let value of resolveExtensions) {
455
- value += "";
471
+ validateStringValue(value, "resolve extension");
456
472
  if (value.indexOf(",") >= 0)
457
473
  throw new Error(`Invalid resolve extension: ${value}`);
458
474
  values.push(value);
@@ -470,7 +486,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
470
486
  if (mainFields) {
471
487
  let values = [];
472
488
  for (let value of mainFields) {
473
- value += "";
489
+ validateStringValue(value, "main field");
474
490
  if (value.indexOf(",") >= 0)
475
491
  throw new Error(`Invalid main field: ${value}`);
476
492
  values.push(value);
@@ -480,7 +496,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
480
496
  if (conditions) {
481
497
  let values = [];
482
498
  for (let value of conditions) {
483
- value += "";
499
+ validateStringValue(value, "condition");
484
500
  if (value.indexOf(",") >= 0)
485
501
  throw new Error(`Invalid condition: ${value}`);
486
502
  values.push(value);
@@ -489,46 +505,53 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
489
505
  }
490
506
  if (external)
491
507
  for (let name of external)
492
- flags.push(`--external:${name}`);
508
+ flags.push(`--external:${validateStringValue(name, "external")}`);
509
+ if (alias) {
510
+ for (let old in alias) {
511
+ if (old.indexOf("=") >= 0)
512
+ throw new Error(`Invalid package name in alias: ${old}`);
513
+ flags.push(`--alias:${old}=${validateStringValue(alias[old], "alias", old)}`);
514
+ }
515
+ }
493
516
  if (banner) {
494
517
  for (let type in banner) {
495
518
  if (type.indexOf("=") >= 0)
496
519
  throw new Error(`Invalid banner file type: ${type}`);
497
- flags.push(`--banner:${type}=${banner[type]}`);
520
+ flags.push(`--banner:${type}=${validateStringValue(banner[type], "banner", type)}`);
498
521
  }
499
522
  }
500
523
  if (footer) {
501
524
  for (let type in footer) {
502
525
  if (type.indexOf("=") >= 0)
503
526
  throw new Error(`Invalid footer file type: ${type}`);
504
- flags.push(`--footer:${type}=${footer[type]}`);
527
+ flags.push(`--footer:${type}=${validateStringValue(footer[type], "footer", type)}`);
505
528
  }
506
529
  }
507
530
  if (inject)
508
531
  for (let path of inject)
509
- flags.push(`--inject:${path}`);
532
+ flags.push(`--inject:${validateStringValue(path, "inject")}`);
510
533
  if (loader) {
511
534
  for (let ext in loader) {
512
535
  if (ext.indexOf("=") >= 0)
513
536
  throw new Error(`Invalid loader extension: ${ext}`);
514
- flags.push(`--loader:${ext}=${loader[ext]}`);
537
+ flags.push(`--loader:${ext}=${validateStringValue(loader[ext], "loader", ext)}`);
515
538
  }
516
539
  }
517
540
  if (outExtension) {
518
541
  for (let ext in outExtension) {
519
542
  if (ext.indexOf("=") >= 0)
520
543
  throw new Error(`Invalid out extension: ${ext}`);
521
- flags.push(`--out-extension:${ext}=${outExtension[ext]}`);
544
+ flags.push(`--out-extension:${ext}=${validateStringValue(outExtension[ext], "out extension", ext)}`);
522
545
  }
523
546
  }
524
547
  if (entryPoints) {
525
548
  if (Array.isArray(entryPoints)) {
526
549
  for (let entryPoint of entryPoints) {
527
- entries.push(["", entryPoint + ""]);
550
+ entries.push(["", validateStringValue(entryPoint, "entry point")]);
528
551
  }
529
552
  } else {
530
- for (let [key, value] of Object.entries(entryPoints)) {
531
- entries.push([key + "", value + ""]);
553
+ for (let key in entryPoints) {
554
+ entries.push([key, validateStringValue(entryPoints[key], "entry point", key)]);
532
555
  }
533
556
  }
534
557
  }
@@ -544,7 +567,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
544
567
  if (loader2)
545
568
  flags.push(`--loader=${loader2}`);
546
569
  if (resolveDir)
547
- stdinResolveDir = resolveDir + "";
570
+ stdinResolveDir = resolveDir;
548
571
  if (typeof contents === "string")
549
572
  stdinContents = encodeUTF8(contents);
550
573
  else if (contents instanceof Uint8Array)
@@ -689,8 +712,8 @@ function createChannel(streamIn) {
689
712
  if (isFirstPacket) {
690
713
  isFirstPacket = false;
691
714
  let binaryVersion = String.fromCharCode(...bytes);
692
- if (binaryVersion !== "0.15.15") {
693
- throw new Error(`Cannot start service: Host version "${"0.15.15"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
715
+ if (binaryVersion !== "0.16.1") {
716
+ throw new Error(`Cannot start service: Host version "${"0.16.1"}" does not match binary version ${quote(binaryVersion)}`);
694
717
  }
695
718
  return;
696
719
  }
@@ -1172,7 +1195,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
1172
1195
  let setup = getFlag(item, keys, "setup", mustBeFunction);
1173
1196
  if (typeof setup !== "function")
1174
1197
  throw new Error(`Plugin is missing a setup function`);
1175
- checkForInvalidFlags(item, keys, `on plugin ${JSON.stringify(name)}`);
1198
+ checkForInvalidFlags(item, keys, `on plugin ${quote(name)}`);
1176
1199
  let plugin = {
1177
1200
  name,
1178
1201
  onResolve: [],
@@ -1209,6 +1232,8 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
1209
1232
  request.resolveDir = resolveDir;
1210
1233
  if (kind != null)
1211
1234
  request.kind = kind;
1235
+ else
1236
+ throw new Error(`Must specify "kind" when calling "resolve"`);
1212
1237
  if (pluginData != null)
1213
1238
  request.pluginData = details.store(pluginData);
1214
1239
  sendRequest(refs, request, (error, response) => {
@@ -1247,7 +1272,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
1247
1272
  let keys2 = {};
1248
1273
  let filter = getFlag(options, keys2, "filter", mustBeRegExp);
1249
1274
  let namespace = getFlag(options, keys2, "namespace", mustBeString);
1250
- checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${JSON.stringify(name)}`);
1275
+ checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${quote(name)}`);
1251
1276
  if (filter == null)
1252
1277
  throw new Error(`onResolve() call is missing a filter`);
1253
1278
  let id = nextCallbackID++;
@@ -1260,7 +1285,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
1260
1285
  let keys2 = {};
1261
1286
  let filter = getFlag(options, keys2, "filter", mustBeRegExp);
1262
1287
  let namespace = getFlag(options, keys2, "namespace", mustBeString);
1263
- checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${JSON.stringify(name)}`);
1288
+ checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${quote(name)}`);
1264
1289
  if (filter == null)
1265
1290
  throw new Error(`onLoad() call is missing a filter`);
1266
1291
  let id = nextCallbackID++;
@@ -1283,11 +1308,11 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
1283
1308
  let result = await callback();
1284
1309
  if (result != null) {
1285
1310
  if (typeof result !== "object")
1286
- throw new Error(`Expected onStart() callback in plugin ${JSON.stringify(name)} to return an object`);
1311
+ throw new Error(`Expected onStart() callback in plugin ${quote(name)} to return an object`);
1287
1312
  let keys = {};
1288
1313
  let errors = getFlag(result, keys, "errors", mustBeArray);
1289
1314
  let warnings = getFlag(result, keys, "warnings", mustBeArray);
1290
- checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${JSON.stringify(name)}`);
1315
+ checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${quote(name)}`);
1291
1316
  if (errors != null)
1292
1317
  response.errors.push(...sanitizeMessages(errors, "errors", details, name));
1293
1318
  if (warnings != null)
@@ -1314,7 +1339,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
1314
1339
  });
1315
1340
  if (result != null) {
1316
1341
  if (typeof result !== "object")
1317
- throw new Error(`Expected onResolve() callback in plugin ${JSON.stringify(name)} to return an object`);
1342
+ throw new Error(`Expected onResolve() callback in plugin ${quote(name)} to return an object`);
1318
1343
  let keys = {};
1319
1344
  let pluginName = getFlag(result, keys, "pluginName", mustBeString);
1320
1345
  let path = getFlag(result, keys, "path", mustBeString);
@@ -1327,7 +1352,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
1327
1352
  let warnings = getFlag(result, keys, "warnings", mustBeArray);
1328
1353
  let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
1329
1354
  let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
1330
- checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${JSON.stringify(name)}`);
1355
+ checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${quote(name)}`);
1331
1356
  response.id = id2;
1332
1357
  if (pluginName != null)
1333
1358
  response.pluginName = pluginName;
@@ -1373,7 +1398,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
1373
1398
  });
1374
1399
  if (result != null) {
1375
1400
  if (typeof result !== "object")
1376
- throw new Error(`Expected onLoad() callback in plugin ${JSON.stringify(name)} to return an object`);
1401
+ throw new Error(`Expected onLoad() callback in plugin ${quote(name)} to return an object`);
1377
1402
  let keys = {};
1378
1403
  let pluginName = getFlag(result, keys, "pluginName", mustBeString);
1379
1404
  let contents = getFlag(result, keys, "contents", mustBeStringOrUint8Array);
@@ -1384,7 +1409,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
1384
1409
  let warnings = getFlag(result, keys, "warnings", mustBeArray);
1385
1410
  let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
1386
1411
  let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
1387
- checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${JSON.stringify(name)}`);
1412
+ checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${quote(name)}`);
1388
1413
  response.id = id2;
1389
1414
  if (pluginName != null)
1390
1415
  response.pluginName = pluginName;
@@ -1462,9 +1487,9 @@ function extractCallerV8(e, streamIn, ident) {
1462
1487
  try {
1463
1488
  let lines = (e.stack + "").split("\n");
1464
1489
  lines.splice(1, 1);
1465
- let location = parseStackLinesV8(streamIn, lines, ident);
1466
- if (location) {
1467
- note = { text: e.message, location };
1490
+ let location2 = parseStackLinesV8(streamIn, lines, ident);
1491
+ if (location2) {
1492
+ note = { text: e.message, location: location2 };
1468
1493
  return note;
1469
1494
  }
1470
1495
  } catch (e2) {
@@ -1473,16 +1498,16 @@ function extractCallerV8(e, streamIn, ident) {
1473
1498
  }
1474
1499
  function extractErrorMessageV8(e, streamIn, stash, note, pluginName) {
1475
1500
  let text = "Internal error";
1476
- let location = null;
1501
+ let location2 = null;
1477
1502
  try {
1478
1503
  text = (e && e.message || e) + "";
1479
1504
  } catch (e2) {
1480
1505
  }
1481
1506
  try {
1482
- location = parseStackLinesV8(streamIn, (e.stack + "").split("\n"), "");
1507
+ location2 = parseStackLinesV8(streamIn, (e.stack + "").split("\n"), "");
1483
1508
  } catch (e2) {
1484
1509
  }
1485
- return { id: "", pluginName, text, location, notes: note ? [note] : [], detail: stash ? stash.store(e) : -1 };
1510
+ return { id: "", pluginName, text, location: location2, notes: note ? [note] : [], detail: stash ? stash.store(e) : -1 };
1486
1511
  }
1487
1512
  function parseStackLinesV8(streamIn, lines, ident) {
1488
1513
  let at = " at ";
@@ -1554,18 +1579,18 @@ function replaceDetailsInMessages(messages, stash) {
1554
1579
  }
1555
1580
  return messages;
1556
1581
  }
1557
- function sanitizeLocation(location, where) {
1558
- if (location == null)
1582
+ function sanitizeLocation(location2, where) {
1583
+ if (location2 == null)
1559
1584
  return null;
1560
1585
  let keys = {};
1561
- let file = getFlag(location, keys, "file", mustBeString);
1562
- let namespace = getFlag(location, keys, "namespace", mustBeString);
1563
- let line = getFlag(location, keys, "line", mustBeInteger);
1564
- let column = getFlag(location, keys, "column", mustBeInteger);
1565
- let length = getFlag(location, keys, "length", mustBeInteger);
1566
- let lineText = getFlag(location, keys, "lineText", mustBeString);
1567
- let suggestion = getFlag(location, keys, "suggestion", mustBeString);
1568
- checkForInvalidFlags(location, keys, where);
1586
+ let file = getFlag(location2, keys, "file", mustBeString);
1587
+ let namespace = getFlag(location2, keys, "namespace", mustBeString);
1588
+ let line = getFlag(location2, keys, "line", mustBeInteger);
1589
+ let column = getFlag(location2, keys, "column", mustBeInteger);
1590
+ let length = getFlag(location2, keys, "length", mustBeInteger);
1591
+ let lineText = getFlag(location2, keys, "lineText", mustBeString);
1592
+ let suggestion = getFlag(location2, keys, "suggestion", mustBeString);
1593
+ checkForInvalidFlags(location2, keys, where);
1569
1594
  return {
1570
1595
  file: file || "",
1571
1596
  namespace: namespace || "",
@@ -1584,7 +1609,7 @@ function sanitizeMessages(messages, property, stash, fallbackPluginName) {
1584
1609
  let id = getFlag(message, keys, "id", mustBeString);
1585
1610
  let pluginName = getFlag(message, keys, "pluginName", mustBeString);
1586
1611
  let text = getFlag(message, keys, "text", mustBeString);
1587
- let location = getFlag(message, keys, "location", mustBeObjectOrNull);
1612
+ let location2 = getFlag(message, keys, "location", mustBeObjectOrNull);
1588
1613
  let notes = getFlag(message, keys, "notes", mustBeArray);
1589
1614
  let detail = getFlag(message, keys, "detail", canBeAnything);
1590
1615
  let where = `in element ${index} of "${property}"`;
@@ -1606,7 +1631,7 @@ function sanitizeMessages(messages, property, stash, fallbackPluginName) {
1606
1631
  id: id || "",
1607
1632
  pluginName: pluginName || fallbackPluginName,
1608
1633
  text: text || "",
1609
- location: sanitizeLocation(location, where),
1634
+ location: sanitizeLocation(location2, where),
1610
1635
  notes: notesClone,
1611
1636
  detail: stash ? stash.store(detail) : -1
1612
1637
  });
@@ -1618,7 +1643,7 @@ function sanitizeStringArray(values, property) {
1618
1643
  const result = [];
1619
1644
  for (const value of values) {
1620
1645
  if (typeof value !== "string")
1621
- throw new Error(`${JSON.stringify(property)} must be an array of strings`);
1646
+ throw new Error(`${quote(property)} must be an array of strings`);
1622
1647
  result.push(value);
1623
1648
  }
1624
1649
  return result;
@@ -1640,7 +1665,7 @@ function convertOutputFiles({ path, contents }) {
1640
1665
  }
1641
1666
 
1642
1667
  // lib/npm/browser.ts
1643
- var version = "0.15.15";
1668
+ var version = "0.16.1";
1644
1669
  var build = (options) => ensureServiceIsRunning().build(options);
1645
1670
  var serve = () => {
1646
1671
  throw new Error(`The "serve" API only works in node`);
@@ -1685,18 +1710,9 @@ var initialize = (options) => {
1685
1710
  return initializePromise;
1686
1711
  };
1687
1712
  var startRunningService = async (wasmURL, wasmModule, useWorker) => {
1688
- let wasm;
1689
- if (wasmModule) {
1690
- wasm = wasmModule;
1691
- } else {
1692
- let res = await fetch(wasmURL);
1693
- if (!res.ok)
1694
- throw new Error(`Failed to download ${JSON.stringify(wasmURL)}`);
1695
- wasm = await res.arrayBuffer();
1696
- }
1697
1713
  let worker;
1698
1714
  if (useWorker) {
1699
- 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 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 async run(instance) {\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 await this._exitPromise;\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" });
1715
+ 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 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 async run(instance) {\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 await this._exitPromise;\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 async function tryToInstantiateModule(wasm, go) {\n if (wasm instanceof WebAssembly.Module) {\n return WebAssembly.instantiate(wasm, go.importObject);\n }\n const res = await 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 = await WebAssembly.instantiateStreaming(res, go.importObject);\n return result2.instance;\n }\n const bytes = await res.arrayBuffer();\n const result = await WebAssembly.instantiate(bytes, go.importObject);\n return result.instance;\n }\n return (m) => onmessage(m);\n })'}(postMessage)`], { type: "text/javascript" });
1700
1716
  worker = new Worker(URL.createObjectURL(blob));
1701
1717
  } else {
1702
1718
  let onmessage = ((postMessage) => {
@@ -2278,13 +2294,32 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
2278
2294
  callback(null, count);
2279
2295
  };
2280
2296
  let go = new globalThis.Go();
2281
- go.argv = ["", `--service=${"0.15.15"}`];
2297
+ go.argv = ["", `--service=${"0.16.1"}`];
2298
+ tryToInstantiateModule(wasm, go).then(
2299
+ (instance) => {
2300
+ postMessage(null);
2301
+ go.run(instance);
2302
+ },
2303
+ (error) => {
2304
+ postMessage(error);
2305
+ }
2306
+ );
2307
+ };
2308
+ async function tryToInstantiateModule(wasm, go) {
2282
2309
  if (wasm instanceof WebAssembly.Module) {
2283
- WebAssembly.instantiate(wasm, go.importObject).then((instance) => go.run(instance));
2284
- } else {
2285
- WebAssembly.instantiate(wasm, go.importObject).then(({ instance }) => go.run(instance));
2310
+ return WebAssembly.instantiate(wasm, go.importObject);
2286
2311
  }
2287
- };
2312
+ const res = await fetch(wasm);
2313
+ if (!res.ok)
2314
+ throw new Error(`Failed to download ${JSON.stringify(wasm)}`);
2315
+ if ("instantiateStreaming" in WebAssembly && /^application\/wasm($|;)/i.test(res.headers.get("Content-Type") || "")) {
2316
+ const result2 = await WebAssembly.instantiateStreaming(res, go.importObject);
2317
+ return result2.instance;
2318
+ }
2319
+ const bytes = await res.arrayBuffer();
2320
+ const result = await WebAssembly.instantiate(bytes, go.importObject);
2321
+ return result.instance;
2322
+ }
2288
2323
  return (m) => onmessage(m);
2289
2324
  })((data) => worker.onmessage({ data }));
2290
2325
  worker = {
@@ -2294,8 +2329,20 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
2294
2329
  }
2295
2330
  };
2296
2331
  }
2297
- worker.postMessage(wasm);
2298
- worker.onmessage = ({ data }) => readFromStdout(data);
2332
+ let firstMessageResolve;
2333
+ let firstMessageReject;
2334
+ const firstMessagePromise = new Promise((resolve, reject) => {
2335
+ firstMessageResolve = resolve;
2336
+ firstMessageReject = reject;
2337
+ });
2338
+ worker.onmessage = ({ data: error }) => {
2339
+ worker.onmessage = ({ data }) => readFromStdout(data);
2340
+ if (error)
2341
+ firstMessageReject(error);
2342
+ else
2343
+ firstMessageResolve();
2344
+ };
2345
+ worker.postMessage(wasmModule || new URL(wasmURL, location.href).toString());
2299
2346
  let { readFromStdout, service } = createChannel({
2300
2347
  writeToStdin(bytes) {
2301
2348
  worker.postMessage(bytes);
@@ -2304,6 +2351,7 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
2304
2351
  isWriteUnavailable: true,
2305
2352
  esbuild: browser_exports
2306
2353
  });
2354
+ await firstMessagePromise;
2307
2355
  longLivedService = {
2308
2356
  build: (options) => new Promise((resolve, reject) => service.buildOrServe({
2309
2357
  callName: "build",