isomorfeus-asset-manager 0.16.4 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,11 +11,11 @@ __export(browser_exports, {
11
11
  analyzeMetafileSync: () => analyzeMetafileSync,
12
12
  build: () => build,
13
13
  buildSync: () => buildSync,
14
+ context: () => context,
14
15
  default: () => browser_default,
15
16
  formatMessages: () => formatMessages,
16
17
  formatMessagesSync: () => formatMessagesSync,
17
18
  initialize: () => initialize,
18
- serve: () => serve,
19
19
  transform: () => transform,
20
20
  transformSync: () => transformSync,
21
21
  version: () => version
@@ -201,15 +201,14 @@ function validateTarget(target) {
201
201
  }
202
202
  var canBeAnything = () => null;
203
203
  var mustBeBoolean = (value) => typeof value === "boolean" ? null : "a boolean";
204
- var mustBeBooleanOrObject = (value) => typeof value === "boolean" || typeof value === "object" && !Array.isArray(value) ? null : "a boolean or an object";
205
204
  var mustBeString = (value) => typeof value === "string" ? null : "a string";
206
205
  var mustBeRegExp = (value) => value instanceof RegExp ? null : "a RegExp object";
207
206
  var mustBeInteger = (value) => typeof value === "number" && value === (value | 0) ? null : "an integer";
208
207
  var mustBeFunction = (value) => typeof value === "function" ? null : "a function";
209
208
  var mustBeArray = (value) => Array.isArray(value) ? null : "an array";
210
209
  var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object";
210
+ var mustBeEntryPoints = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
211
211
  var mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module";
212
- var mustBeArrayOrRecord = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
213
212
  var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null";
214
213
  var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean";
215
214
  var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object";
@@ -397,12 +396,10 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
397
396
  let keys = /* @__PURE__ */ Object.create(null);
398
397
  let stdinContents = null;
399
398
  let stdinResolveDir = null;
400
- let watchMode = null;
401
399
  pushLogFlags(flags, options, keys, isTTY, logLevelDefault);
402
400
  pushCommonFlags(flags, options, keys);
403
401
  let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean);
404
402
  let bundle = getFlag(options, keys, "bundle", mustBeBoolean);
405
- let watch = getFlag(options, keys, "watch", mustBeBooleanOrObject);
406
403
  let splitting = getFlag(options, keys, "splitting", mustBeBoolean);
407
404
  let preserveSymlinks = getFlag(options, keys, "preserveSymlinks", mustBeBoolean);
408
405
  let metafile = getFlag(options, keys, "metafile", mustBeBoolean);
@@ -426,12 +423,11 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
426
423
  let inject = getFlag(options, keys, "inject", mustBeArray);
427
424
  let banner = getFlag(options, keys, "banner", mustBeObject);
428
425
  let footer = getFlag(options, keys, "footer", mustBeObject);
429
- let entryPoints = getFlag(options, keys, "entryPoints", mustBeArrayOrRecord);
426
+ let entryPoints = getFlag(options, keys, "entryPoints", mustBeEntryPoints);
430
427
  let absWorkingDir = getFlag(options, keys, "absWorkingDir", mustBeString);
431
428
  let stdin = getFlag(options, keys, "stdin", mustBeObject);
432
429
  let write = (_a = getFlag(options, keys, "write", mustBeBoolean)) != null ? _a : writeDefault;
433
430
  let allowOverwrite = getFlag(options, keys, "allowOverwrite", mustBeBoolean);
434
- let incremental = getFlag(options, keys, "incremental", mustBeBoolean) === true;
435
431
  let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
436
432
  keys.plugins = true;
437
433
  checkForInvalidFlags(options, keys, `in ${callName}() call`);
@@ -441,17 +437,6 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
441
437
  flags.push("--bundle");
442
438
  if (allowOverwrite)
443
439
  flags.push("--allow-overwrite");
444
- if (watch) {
445
- flags.push("--watch");
446
- if (typeof watch === "boolean") {
447
- watchMode = {};
448
- } else {
449
- let watchKeys = /* @__PURE__ */ Object.create(null);
450
- let onRebuild = getFlag(watch, watchKeys, "onRebuild", mustBeFunction);
451
- checkForInvalidFlags(watch, watchKeys, `on "watch" in ${callName}() call`);
452
- watchMode = { onRebuild };
453
- }
454
- }
455
440
  if (splitting)
456
441
  flags.push("--splitting");
457
442
  if (preserveSymlinks)
@@ -549,8 +534,21 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
549
534
  }
550
535
  if (entryPoints) {
551
536
  if (Array.isArray(entryPoints)) {
552
- for (let entryPoint of entryPoints) {
553
- entries.push(["", validateStringValue(entryPoint, "entry point")]);
537
+ for (let i = 0, n = entryPoints.length; i < n; i++) {
538
+ let entryPoint = entryPoints[i];
539
+ if (typeof entryPoint === "object" && entryPoint !== null) {
540
+ let entryPointKeys = /* @__PURE__ */ Object.create(null);
541
+ let input = getFlag(entryPoint, entryPointKeys, "in", mustBeString);
542
+ let output = getFlag(entryPoint, entryPointKeys, "out", mustBeString);
543
+ checkForInvalidFlags(entryPoint, entryPointKeys, "in entry point at index " + i);
544
+ if (input === void 0)
545
+ throw new Error('Missing property "in" for entry point at index ' + i);
546
+ if (output === void 0)
547
+ throw new Error('Missing property "out" for entry point at index ' + i);
548
+ entries.push([output, input]);
549
+ } else {
550
+ entries.push(["", validateStringValue(entryPoint, "entry point at index " + i)]);
551
+ }
554
552
  }
555
553
  } else {
556
554
  for (let key in entryPoints) {
@@ -590,9 +588,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
590
588
  stdinContents,
591
589
  stdinResolveDir,
592
590
  absWorkingDir,
593
- incremental,
594
591
  nodePaths,
595
- watch: watchMode,
596
592
  mangleCache: validateMangleCache(mangleCache)
597
593
  };
598
594
  }
@@ -715,8 +711,8 @@ function createChannel(streamIn) {
715
711
  if (isFirstPacket) {
716
712
  isFirstPacket = false;
717
713
  let binaryVersion = String.fromCharCode(...bytes);
718
- if (binaryVersion !== "0.16.17") {
719
- throw new Error(`Cannot start service: Host version "${"0.16.17"}" does not match binary version ${quote(binaryVersion)}`);
714
+ if (binaryVersion !== "0.17.12") {
715
+ throw new Error(`Cannot start service: Host version "${"0.17.12"}" does not match binary version ${quote(binaryVersion)}`);
720
716
  }
721
717
  return;
722
718
  }
@@ -732,7 +728,7 @@ function createChannel(streamIn) {
732
728
  callback(null, packet.value);
733
729
  }
734
730
  };
735
- let buildOrServe = ({ callName, refs, serveOptions, options, isTTY, defaultWD, callback }) => {
731
+ let buildOrContext = ({ callName, refs, options, isTTY, defaultWD, callback }) => {
736
732
  let refCount = 0;
737
733
  const buildKey = nextBuildKey++;
738
734
  const requestCallbacks = {};
@@ -753,7 +749,7 @@ function createChannel(streamIn) {
753
749
  };
754
750
  requestCallbacksByKey[buildKey] = requestCallbacks;
755
751
  buildRefs.ref();
756
- buildOrServeImpl(
752
+ buildOrContextImpl(
757
753
  callName,
758
754
  buildKey,
759
755
  sendRequest,
@@ -762,10 +758,8 @@ function createChannel(streamIn) {
762
758
  streamIn,
763
759
  requestCallbacks,
764
760
  options,
765
- serveOptions,
766
761
  isTTY,
767
762
  defaultWD,
768
- closeData,
769
763
  (err, res) => {
770
764
  try {
771
765
  callback(err, res);
@@ -801,7 +795,13 @@ function createChannel(streamIn) {
801
795
  let outstanding = 1;
802
796
  let next = () => {
803
797
  if (--outstanding === 0) {
804
- let result = { warnings, code: response.code, map: response.map };
798
+ let result = {
799
+ warnings,
800
+ code: response.code,
801
+ map: response.map,
802
+ mangleCache: void 0,
803
+ legalComments: void 0
804
+ };
805
805
  if ("legalComments" in response)
806
806
  result.legalComments = response == null ? void 0 : response.legalComments;
807
807
  if (response.mangleCache)
@@ -907,30 +907,26 @@ function createChannel(streamIn) {
907
907
  readFromStdout,
908
908
  afterClose,
909
909
  service: {
910
- buildOrServe,
910
+ buildOrContext,
911
911
  transform: transform2,
912
912
  formatMessages: formatMessages2,
913
913
  analyzeMetafile: analyzeMetafile2
914
914
  }
915
915
  };
916
916
  }
917
- function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, options, serveOptions, isTTY, defaultWD, closeData, callback) {
917
+ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, options, isTTY, defaultWD, callback) {
918
918
  const details = createObjectStash();
919
- const logPluginError = (e, pluginName, note, done) => {
919
+ const isContext = callName === "context";
920
+ const handleError = (e, pluginName) => {
920
921
  const flags = [];
921
922
  try {
922
923
  pushLogFlags(flags, options, {}, isTTY, buildLogLevelDefault);
923
924
  } catch (e2) {
924
925
  }
925
- const message = extractErrorMessageV8(e, streamIn, details, note, pluginName);
926
+ const message = extractErrorMessageV8(e, streamIn, details, void 0, pluginName);
926
927
  sendRequest(refs, { command: "error", flags, error: message }, () => {
927
928
  message.detail = details.load(message.detail);
928
- done(message);
929
- });
930
- };
931
- const handleError = (e, pluginName) => {
932
- logPluginError(e, pluginName, void 0, (error) => {
933
- callback(failureErrorWithLog("Build failed", [error], []), null);
929
+ callback(failureErrorWithLog(isContext ? "Context failed" : "Build failed", [message], []), null);
934
930
  });
935
931
  };
936
932
  let plugins;
@@ -938,15 +934,13 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
938
934
  const value = options.plugins;
939
935
  if (value !== void 0) {
940
936
  if (!Array.isArray(value))
941
- throw new Error(`"plugins" must be an array`);
937
+ return handleError(new Error(`"plugins" must be an array`), "");
942
938
  plugins = value;
943
939
  }
944
940
  }
945
941
  if (plugins && plugins.length > 0) {
946
- if (streamIn.isSync) {
947
- handleError(new Error("Cannot use plugins in synchronous API calls"), "");
948
- return;
949
- }
942
+ if (streamIn.isSync)
943
+ return handleError(new Error("Cannot use plugins in synchronous API calls"), "");
950
944
  handlePlugins(
951
945
  buildKey,
952
946
  sendRequest,
@@ -959,12 +953,10 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
959
953
  details
960
954
  ).then(
961
955
  (result) => {
962
- if (!result.ok) {
963
- handleError(result.error, result.pluginName);
964
- return;
965
- }
956
+ if (!result.ok)
957
+ return handleError(result.error, result.pluginName);
966
958
  try {
967
- buildOrServeContinue(result.requestPlugins, result.runOnEndCallbacks);
959
+ buildOrContextContinue(result.requestPlugins, result.runOnEndCallbacks, result.scheduleOnDisposeCallbacks);
968
960
  } catch (e) {
969
961
  handleError(e, "");
970
962
  }
@@ -974,25 +966,26 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
974
966
  return;
975
967
  }
976
968
  try {
977
- buildOrServeContinue(null, (result, logPluginError2, done) => done());
969
+ buildOrContextContinue(null, (result, done) => done([], []), () => {
970
+ });
978
971
  } catch (e) {
979
972
  handleError(e, "");
980
973
  }
981
- function buildOrServeContinue(requestPlugins, runOnEndCallbacks) {
982
- let writeDefault = !streamIn.isWriteUnavailable;
983
- let {
974
+ function buildOrContextContinue(requestPlugins, runOnEndCallbacks, scheduleOnDisposeCallbacks) {
975
+ const writeDefault = streamIn.hasFS;
976
+ const {
984
977
  entries,
985
978
  flags,
986
979
  write,
987
980
  stdinContents,
988
981
  stdinResolveDir,
989
982
  absWorkingDir,
990
- incremental,
991
983
  nodePaths,
992
- watch,
993
984
  mangleCache
994
985
  } = flagsForBuildOptions(callName, options, isTTY, buildLogLevelDefault, writeDefault);
995
- let request = {
986
+ if (write && !streamIn.hasFS)
987
+ throw new Error(`The "write" option is unavailable in this environment`);
988
+ const request = {
996
989
  command: "build",
997
990
  key: buildKey,
998
991
  entries,
@@ -1001,17 +994,23 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
1001
994
  stdinContents,
1002
995
  stdinResolveDir,
1003
996
  absWorkingDir: absWorkingDir || defaultWD,
1004
- incremental,
1005
- nodePaths
997
+ nodePaths,
998
+ context: isContext
1006
999
  };
1007
1000
  if (requestPlugins)
1008
1001
  request.plugins = requestPlugins;
1009
1002
  if (mangleCache)
1010
1003
  request.mangleCache = mangleCache;
1011
- let serve2 = serveOptions && buildServeData(buildKey, sendRequest, sendResponse, refs, requestCallbacks, serveOptions, request);
1012
- let rebuild;
1013
- let stop;
1014
- let copyResponseToResult = (response, result) => {
1004
+ const buildResponseToResult = (response, callback2) => {
1005
+ const result = {
1006
+ errors: replaceDetailsInMessages(response.errors, details),
1007
+ warnings: replaceDetailsInMessages(response.warnings, details),
1008
+ outputFiles: void 0,
1009
+ metafile: void 0,
1010
+ mangleCache: void 0
1011
+ };
1012
+ const originalErrors = result.errors.slice();
1013
+ const originalWarnings = result.warnings.slice();
1015
1014
  if (response.outputFiles)
1016
1015
  result.outputFiles = response.outputFiles.map(convertOutputFiles);
1017
1016
  if (response.metafile)
@@ -1020,170 +1019,163 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
1020
1019
  result.mangleCache = response.mangleCache;
1021
1020
  if (response.writeToStdout !== void 0)
1022
1021
  console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, ""));
1023
- };
1024
- let buildResponseToResult = (response, callback2) => {
1025
- let result = {
1026
- errors: replaceDetailsInMessages(response.errors, details),
1027
- warnings: replaceDetailsInMessages(response.warnings, details)
1028
- };
1029
- copyResponseToResult(response, result);
1030
- runOnEndCallbacks(result, logPluginError, () => {
1031
- if (result.errors.length > 0) {
1032
- return callback2(failureErrorWithLog("Build failed", result.errors, result.warnings), null);
1022
+ runOnEndCallbacks(result, (onEndErrors, onEndWarnings) => {
1023
+ if (originalErrors.length > 0 || onEndErrors.length > 0) {
1024
+ const error = failureErrorWithLog("Build failed", originalErrors.concat(onEndErrors), originalWarnings.concat(onEndWarnings));
1025
+ return callback2(error, null, onEndErrors, onEndWarnings);
1033
1026
  }
1034
- if (response.rebuild) {
1035
- if (!rebuild) {
1036
- let isDisposed = false;
1037
- rebuild = () => new Promise((resolve, reject) => {
1038
- if (isDisposed || closeData.didClose)
1039
- throw new Error("Cannot rebuild");
1040
- sendRequest(
1041
- refs,
1042
- { command: "rebuild", key: buildKey },
1043
- (error2, response2) => {
1027
+ callback2(null, result, onEndErrors, onEndWarnings);
1028
+ });
1029
+ };
1030
+ let latestResultPromise;
1031
+ let provideLatestResult;
1032
+ if (isContext)
1033
+ requestCallbacks["on-end"] = (id, request2) => new Promise((resolve) => {
1034
+ buildResponseToResult(request2, (err, result, onEndErrors, onEndWarnings) => {
1035
+ const response = {
1036
+ errors: onEndErrors,
1037
+ warnings: onEndWarnings
1038
+ };
1039
+ if (provideLatestResult)
1040
+ provideLatestResult(err, result);
1041
+ latestResultPromise = void 0;
1042
+ provideLatestResult = void 0;
1043
+ sendResponse(id, response);
1044
+ resolve();
1045
+ });
1046
+ });
1047
+ sendRequest(refs, request, (error, response) => {
1048
+ if (error)
1049
+ return callback(new Error(error), null);
1050
+ if (!isContext) {
1051
+ return buildResponseToResult(response, (err, res) => {
1052
+ scheduleOnDisposeCallbacks();
1053
+ return callback(err, res);
1054
+ });
1055
+ }
1056
+ if (response.errors.length > 0) {
1057
+ return callback(failureErrorWithLog("Context failed", response.errors, response.warnings), null);
1058
+ }
1059
+ let didDispose = false;
1060
+ const result = {
1061
+ rebuild: () => {
1062
+ if (!latestResultPromise)
1063
+ latestResultPromise = new Promise((resolve, reject) => {
1064
+ let settlePromise;
1065
+ provideLatestResult = (err, result2) => {
1066
+ if (!settlePromise)
1067
+ settlePromise = () => err ? reject(err) : resolve(result2);
1068
+ };
1069
+ const triggerAnotherBuild = () => {
1070
+ const request2 = {
1071
+ command: "rebuild",
1072
+ key: buildKey
1073
+ };
1074
+ sendRequest(refs, request2, (error2, response2) => {
1044
1075
  if (error2) {
1045
- const message = { id: "", pluginName: "", text: error2, location: null, notes: [], detail: void 0 };
1046
- return callback2(failureErrorWithLog("Build failed", [message], []), null);
1076
+ reject(new Error(error2));
1077
+ } else if (settlePromise) {
1078
+ settlePromise();
1079
+ } else {
1080
+ triggerAnotherBuild();
1047
1081
  }
1048
- buildResponseToResult(response2, (error3, result3) => {
1049
- if (error3)
1050
- reject(error3);
1051
- else
1052
- resolve(result3);
1053
- });
1054
- }
1055
- );
1082
+ });
1083
+ };
1084
+ triggerAnotherBuild();
1056
1085
  });
1057
- refs.ref();
1058
- rebuild.dispose = () => {
1059
- if (isDisposed)
1060
- return;
1061
- isDisposed = true;
1062
- sendRequest(refs, { command: "rebuild-dispose", key: buildKey }, () => {
1063
- });
1064
- refs.unref();
1065
- };
1066
- }
1067
- result.rebuild = rebuild;
1068
- }
1069
- if (response.watch) {
1070
- if (!stop) {
1071
- let isStopped = false;
1072
- refs.ref();
1073
- stop = () => {
1074
- if (isStopped)
1075
- return;
1076
- isStopped = true;
1077
- delete requestCallbacks["watch-rebuild"];
1078
- sendRequest(refs, { command: "watch-stop", key: buildKey }, () => {
1079
- });
1080
- refs.unref();
1081
- };
1082
- if (watch) {
1083
- requestCallbacks["watch-rebuild"] = (id, request2) => {
1084
- try {
1085
- let watchResponse = request2.args;
1086
- let result2 = {
1087
- errors: replaceDetailsInMessages(watchResponse.errors, details),
1088
- warnings: replaceDetailsInMessages(watchResponse.warnings, details)
1089
- };
1090
- copyResponseToResult(watchResponse, result2);
1091
- runOnEndCallbacks(result2, logPluginError, () => {
1092
- if (result2.errors.length > 0) {
1093
- if (watch.onRebuild)
1094
- watch.onRebuild(failureErrorWithLog("Build failed", result2.errors, result2.warnings), null);
1095
- return;
1096
- }
1097
- result2.stop = stop;
1098
- if (watch.onRebuild)
1099
- watch.onRebuild(null, result2);
1100
- });
1101
- } catch (err) {
1102
- console.error(err);
1103
- }
1086
+ return latestResultPromise;
1087
+ },
1088
+ watch: (options2 = {}) => new Promise((resolve, reject) => {
1089
+ if (!streamIn.hasFS)
1090
+ throw new Error(`Cannot use the "watch" API in this environment`);
1091
+ const keys = {};
1092
+ checkForInvalidFlags(options2, keys, `in watch() call`);
1093
+ const request2 = {
1094
+ command: "watch",
1095
+ key: buildKey
1096
+ };
1097
+ sendRequest(refs, request2, (error2) => {
1098
+ if (error2)
1099
+ reject(new Error(error2));
1100
+ else
1101
+ resolve(void 0);
1102
+ });
1103
+ }),
1104
+ serve: (options2 = {}) => new Promise((resolve, reject) => {
1105
+ if (!streamIn.hasFS)
1106
+ throw new Error(`Cannot use the "serve" API in this environment`);
1107
+ const keys = {};
1108
+ const port = getFlag(options2, keys, "port", mustBeInteger);
1109
+ const host = getFlag(options2, keys, "host", mustBeString);
1110
+ const servedir = getFlag(options2, keys, "servedir", mustBeString);
1111
+ const keyfile = getFlag(options2, keys, "keyfile", mustBeString);
1112
+ const certfile = getFlag(options2, keys, "certfile", mustBeString);
1113
+ const onRequest = getFlag(options2, keys, "onRequest", mustBeFunction);
1114
+ checkForInvalidFlags(options2, keys, `in serve() call`);
1115
+ const request2 = {
1116
+ command: "serve",
1117
+ key: buildKey,
1118
+ onRequest: !!onRequest
1119
+ };
1120
+ if (port !== void 0)
1121
+ request2.port = port;
1122
+ if (host !== void 0)
1123
+ request2.host = host;
1124
+ if (servedir !== void 0)
1125
+ request2.servedir = servedir;
1126
+ if (keyfile !== void 0)
1127
+ request2.keyfile = keyfile;
1128
+ if (certfile !== void 0)
1129
+ request2.certfile = certfile;
1130
+ sendRequest(refs, request2, (error2, response2) => {
1131
+ if (error2)
1132
+ return reject(new Error(error2));
1133
+ if (onRequest) {
1134
+ requestCallbacks["serve-request"] = (id, request3) => {
1135
+ onRequest(request3.args);
1104
1136
  sendResponse(id, {});
1105
1137
  };
1106
1138
  }
1107
- }
1108
- result.stop = stop;
1109
- }
1110
- callback2(null, result);
1111
- });
1112
- };
1113
- if (write && streamIn.isWriteUnavailable)
1114
- throw new Error(`The "write" option is unavailable in this environment`);
1115
- if (incremental && streamIn.isSync)
1116
- throw new Error(`Cannot use "incremental" with a synchronous build`);
1117
- if (watch && streamIn.isSync)
1118
- throw new Error(`Cannot use "watch" with a synchronous build`);
1119
- sendRequest(refs, request, (error, response) => {
1120
- if (error)
1121
- return callback(new Error(error), null);
1122
- if (serve2) {
1123
- let serveResponse = response;
1124
- let isStopped = false;
1125
- refs.ref();
1126
- let result = {
1127
- port: serveResponse.port,
1128
- host: serveResponse.host,
1129
- wait: serve2.wait,
1130
- stop() {
1131
- if (isStopped)
1132
- return;
1133
- isStopped = true;
1134
- serve2.stop();
1139
+ resolve(response2);
1140
+ });
1141
+ }),
1142
+ cancel: () => new Promise((resolve) => {
1143
+ if (didDispose)
1144
+ return resolve();
1145
+ const request2 = {
1146
+ command: "cancel",
1147
+ key: buildKey
1148
+ };
1149
+ sendRequest(refs, request2, () => {
1150
+ resolve();
1151
+ });
1152
+ }),
1153
+ dispose: () => new Promise((resolve) => {
1154
+ if (didDispose)
1155
+ return resolve();
1156
+ didDispose = true;
1157
+ const request2 = {
1158
+ command: "dispose",
1159
+ key: buildKey
1160
+ };
1161
+ sendRequest(refs, request2, () => {
1162
+ resolve();
1163
+ scheduleOnDisposeCallbacks();
1135
1164
  refs.unref();
1136
- }
1137
- };
1138
- refs.ref();
1139
- serve2.wait.then(refs.unref, refs.unref);
1140
- return callback(null, result);
1141
- }
1142
- return buildResponseToResult(response, callback);
1165
+ });
1166
+ })
1167
+ };
1168
+ refs.ref();
1169
+ callback(null, result);
1143
1170
  });
1144
1171
  }
1145
1172
  }
1146
- var buildServeData = (buildKey, sendRequest, sendResponse, refs, requestCallbacks, options, request) => {
1147
- let keys = {};
1148
- let port = getFlag(options, keys, "port", mustBeInteger);
1149
- let host = getFlag(options, keys, "host", mustBeString);
1150
- let servedir = getFlag(options, keys, "servedir", mustBeString);
1151
- let onRequest = getFlag(options, keys, "onRequest", mustBeFunction);
1152
- let wait = new Promise((resolve, reject) => {
1153
- requestCallbacks["serve-wait"] = (id, request2) => {
1154
- if (request2.error !== null)
1155
- reject(new Error(request2.error));
1156
- else
1157
- resolve();
1158
- sendResponse(id, {});
1159
- };
1160
- });
1161
- request.serve = {};
1162
- checkForInvalidFlags(options, keys, `in serve() call`);
1163
- if (port !== void 0)
1164
- request.serve.port = port;
1165
- if (host !== void 0)
1166
- request.serve.host = host;
1167
- if (servedir !== void 0)
1168
- request.serve.servedir = servedir;
1169
- requestCallbacks["serve-request"] = (id, request2) => {
1170
- if (onRequest)
1171
- onRequest(request2.args);
1172
- sendResponse(id, {});
1173
- };
1174
- return {
1175
- wait,
1176
- stop() {
1177
- sendRequest(refs, { command: "serve-stop", key: buildKey }, () => {
1178
- });
1179
- }
1180
- };
1181
- };
1182
1173
  var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, initialOptions, plugins, details) => {
1183
1174
  let onStartCallbacks = [];
1184
1175
  let onEndCallbacks = [];
1185
1176
  let onResolveCallbacks = {};
1186
1177
  let onLoadCallbacks = {};
1178
+ let onDisposeCallbacks = [];
1187
1179
  let nextCallbackID = 0;
1188
1180
  let i = 0;
1189
1181
  let requestPlugins = [];
@@ -1301,6 +1293,9 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
1301
1293
  onLoadCallbacks[id] = { name, callback, note: registeredNote };
1302
1294
  plugin.onLoad.push({ id, filter: filter.source, namespace: namespace || "" });
1303
1295
  },
1296
+ onDispose(callback) {
1297
+ onDisposeCallbacks.push(callback);
1298
+ },
1304
1299
  esbuild: streamIn.esbuild
1305
1300
  });
1306
1301
  if (promise)
@@ -1449,25 +1444,62 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
1449
1444
  }
1450
1445
  sendResponse(id, response);
1451
1446
  };
1452
- let runOnEndCallbacks = (result, logPluginError, done) => done();
1447
+ let runOnEndCallbacks = (result, done) => done([], []);
1453
1448
  if (onEndCallbacks.length > 0) {
1454
- runOnEndCallbacks = (result, logPluginError, done) => {
1449
+ runOnEndCallbacks = (result, done) => {
1455
1450
  (async () => {
1451
+ const onEndErrors = [];
1452
+ const onEndWarnings = [];
1456
1453
  for (const { name, callback, note } of onEndCallbacks) {
1454
+ let newErrors;
1455
+ let newWarnings;
1457
1456
  try {
1458
- await callback(result);
1457
+ const value = await callback(result);
1458
+ if (value != null) {
1459
+ if (typeof value !== "object")
1460
+ throw new Error(`Expected onEnd() callback in plugin ${quote(name)} to return an object`);
1461
+ let keys = {};
1462
+ let errors = getFlag(value, keys, "errors", mustBeArray);
1463
+ let warnings = getFlag(value, keys, "warnings", mustBeArray);
1464
+ checkForInvalidFlags(value, keys, `from onEnd() callback in plugin ${quote(name)}`);
1465
+ if (errors != null)
1466
+ newErrors = sanitizeMessages(errors, "errors", details, name);
1467
+ if (warnings != null)
1468
+ newWarnings = sanitizeMessages(warnings, "warnings", details, name);
1469
+ }
1459
1470
  } catch (e) {
1460
- result.errors.push(await new Promise((resolve) => logPluginError(e, name, note && note(), resolve)));
1471
+ newErrors = [extractErrorMessageV8(e, streamIn, details, note && note(), name)];
1472
+ }
1473
+ if (newErrors) {
1474
+ onEndErrors.push(...newErrors);
1475
+ try {
1476
+ result.errors.push(...newErrors);
1477
+ } catch (e) {
1478
+ }
1479
+ }
1480
+ if (newWarnings) {
1481
+ onEndWarnings.push(...newWarnings);
1482
+ try {
1483
+ result.warnings.push(...newWarnings);
1484
+ } catch (e) {
1485
+ }
1461
1486
  }
1462
1487
  }
1463
- })().then(done);
1488
+ done(onEndErrors, onEndWarnings);
1489
+ })();
1464
1490
  };
1465
1491
  }
1492
+ let scheduleOnDisposeCallbacks = () => {
1493
+ for (const cb of onDisposeCallbacks) {
1494
+ setTimeout(() => cb(), 0);
1495
+ }
1496
+ };
1466
1497
  isSetupDone = true;
1467
1498
  return {
1468
1499
  ok: true,
1469
1500
  requestPlugins,
1470
- runOnEndCallbacks
1501
+ runOnEndCallbacks,
1502
+ scheduleOnDisposeCallbacks
1471
1503
  };
1472
1504
  };
1473
1505
  function createObjectStash() {
@@ -1674,11 +1706,9 @@ function convertOutputFiles({ path, contents }) {
1674
1706
  }
1675
1707
 
1676
1708
  // lib/npm/browser.ts
1677
- var version = "0.16.17";
1709
+ var version = "0.17.12";
1678
1710
  var build = (options) => ensureServiceIsRunning().build(options);
1679
- var serve = () => {
1680
- throw new Error(`The "serve" API only works in node`);
1681
- };
1711
+ var context = (options) => ensureServiceIsRunning().context(options);
1682
1712
  var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
1683
1713
  var formatMessages = (messages, options) => ensureServiceIsRunning().formatMessages(messages, options);
1684
1714
  var analyzeMetafile = (metafile, options) => ensureServiceIsRunning().analyzeMetafile(metafile, options);
@@ -1721,7 +1751,7 @@ var initialize = (options) => {
1721
1751
  var startRunningService = async (wasmURL, wasmModule, useWorker) => {
1722
1752
  let worker;
1723
1753
  if (useWorker) {
1724
- 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 // unused\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 // Go\'s SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)\n // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported\n // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).\n // This changes the SP, thus we have to update the SP used by the imported function.\n // func wasmExit(code int32)\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 // func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)\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 // func resetMemoryDataView()\n "runtime.resetMemoryDataView": (sp) => {\n sp >>>= 0;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n },\n // func nanotime1() int64\n "runtime.nanotime1": (sp) => {\n sp >>>= 0;\n setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);\n },\n // func walltime() (sec int64, nsec int32)\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 // func scheduleTimeoutEvent(delay int64) int32\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 // setTimeout has been seen to fire up to 1 millisecond early\n ));\n this.mem.setInt32(sp + 16, id, true);\n },\n // func clearTimeoutEvent(id int32)\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 // func getRandomData(r []byte)\n "runtime.getRandomData": (sp) => {\n sp >>>= 0;\n crypto.getRandomValues(loadSlice(sp + 8));\n },\n // func finalizeRef(v ref)\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 // func stringVal(value string) ref\n "syscall/js.stringVal": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, loadString(sp + 8));\n },\n // func valueGet(v ref, p string) ref\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 // func valueSet(v ref, p string, x ref)\n "syscall/js.valueSet": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n },\n // func valueDelete(v ref, p string)\n "syscall/js.valueDelete": (sp) => {\n sp >>>= 0;\n Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n },\n // func valueIndex(v ref, i int) ref\n "syscall/js.valueIndex": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n },\n // valueSetIndex(v ref, i int, x ref)\n "syscall/js.valueSetIndex": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n },\n // func valueCall(v ref, m string, args []ref) (ref, bool)\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 // func valueInvoke(v ref, args []ref) (ref, bool)\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 // func valueNew(v ref, args []ref) (ref, bool)\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 // func valueLength(v ref) int\n "syscall/js.valueLength": (sp) => {\n sp >>>= 0;\n setInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n },\n // valuePrepareString(v ref) (ref, int)\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 // valueLoadString(v ref, b []byte)\n "syscall/js.valueLoadString": (sp) => {\n sp >>>= 0;\n const str = loadValue(sp + 8);\n loadSlice(sp + 16).set(str);\n },\n // func valueInstanceOf(v ref, t ref) bool\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 // func copyBytesToGo(dst []byte, src ref) (int, bool)\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 // func copyBytesToJS(dst ref, src []byte) (int, bool)\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 // JS values that Go currently has references to, indexed by reference id\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 // mapping from JS values to reference ids\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.17"}`];\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" });
1754
+ 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 // unused\n writeSync(fd, buf) {\n outputBuf += decoder.decode(buf);\n const nl = outputBuf.lastIndexOf("\\n");\n if (nl != -1) {\n console.log(outputBuf.substring(0, nl));\n outputBuf = outputBuf.substring(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 // Go\'s SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)\n // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported\n // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).\n // This changes the SP, thus we have to update the SP used by the imported function.\n // func wasmExit(code int32)\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 // func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)\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 // func resetMemoryDataView()\n "runtime.resetMemoryDataView": (sp) => {\n sp >>>= 0;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n },\n // func nanotime1() int64\n "runtime.nanotime1": (sp) => {\n sp >>>= 0;\n setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);\n },\n // func walltime() (sec int64, nsec int32)\n "runtime.walltime": (sp) => {\n sp >>>= 0;\n const msec = (/* @__PURE__ */ new Date()).getTime();\n setInt64(sp + 8, msec / 1e3);\n this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);\n },\n // func scheduleTimeoutEvent(delay int64) int32\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 // setTimeout has been seen to fire up to 1 millisecond early\n ));\n this.mem.setInt32(sp + 16, id, true);\n },\n // func clearTimeoutEvent(id int32)\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 // func getRandomData(r []byte)\n "runtime.getRandomData": (sp) => {\n sp >>>= 0;\n crypto.getRandomValues(loadSlice(sp + 8));\n },\n // func finalizeRef(v ref)\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 // func stringVal(value string) ref\n "syscall/js.stringVal": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, loadString(sp + 8));\n },\n // func valueGet(v ref, p string) ref\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 // func valueSet(v ref, p string, x ref)\n "syscall/js.valueSet": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n },\n // func valueDelete(v ref, p string)\n "syscall/js.valueDelete": (sp) => {\n sp >>>= 0;\n Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n },\n // func valueIndex(v ref, i int) ref\n "syscall/js.valueIndex": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n },\n // valueSetIndex(v ref, i int, x ref)\n "syscall/js.valueSetIndex": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n },\n // func valueCall(v ref, m string, args []ref) (ref, bool)\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 // func valueInvoke(v ref, args []ref) (ref, bool)\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 // func valueNew(v ref, args []ref) (ref, bool)\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 // func valueLength(v ref) int\n "syscall/js.valueLength": (sp) => {\n sp >>>= 0;\n setInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n },\n // valuePrepareString(v ref) (ref, int)\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 // valueLoadString(v ref, b []byte)\n "syscall/js.valueLoadString": (sp) => {\n sp >>>= 0;\n const str = loadValue(sp + 8);\n loadSlice(sp + 16).set(str);\n },\n // func valueInstanceOf(v ref, t ref) bool\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 // func copyBytesToGo(dst []byte, src ref) (int, bool)\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 // func copyBytesToJS(dst ref, src []byte) (int, bool)\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 // JS values that Go currently has references to, indexed by reference id\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 // mapping from JS values to reference ids\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.17.12"}`];\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" });
1725
1755
  worker = new Worker(URL.createObjectURL(blob));
1726
1756
  } else {
1727
1757
  let onmessage = ((postMessage) => {
@@ -1750,8 +1780,8 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
1750
1780
  outputBuf += decoder.decode(buf);
1751
1781
  const nl = outputBuf.lastIndexOf("\n");
1752
1782
  if (nl != -1) {
1753
- console.log(outputBuf.substr(0, nl));
1754
- outputBuf = outputBuf.substr(nl + 1);
1783
+ console.log(outputBuf.substring(0, nl));
1784
+ outputBuf = outputBuf.substring(nl + 1);
1755
1785
  }
1756
1786
  return buf.length;
1757
1787
  },
@@ -2018,7 +2048,7 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
2018
2048
  // func walltime() (sec int64, nsec int32)
2019
2049
  "runtime.walltime": (sp) => {
2020
2050
  sp >>>= 0;
2021
- const msec = new Date().getTime();
2051
+ const msec = (/* @__PURE__ */ new Date()).getTime();
2022
2052
  setInt64(sp + 8, msec / 1e3);
2023
2053
  this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);
2024
2054
  },
@@ -2335,7 +2365,7 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
2335
2365
  callback(null, count);
2336
2366
  };
2337
2367
  let go = new globalThis.Go();
2338
- go.argv = ["", `--service=${"0.16.17"}`];
2368
+ go.argv = ["", `--service=${"0.17.12"}`];
2339
2369
  tryToInstantiateModule(wasm, go).then(
2340
2370
  (instance) => {
2341
2371
  postMessage(null);
@@ -2389,15 +2419,22 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
2389
2419
  worker.postMessage(bytes);
2390
2420
  },
2391
2421
  isSync: false,
2392
- isWriteUnavailable: true,
2422
+ hasFS: false,
2393
2423
  esbuild: browser_exports
2394
2424
  });
2395
2425
  await firstMessagePromise;
2396
2426
  longLivedService = {
2397
- build: (options) => new Promise((resolve, reject) => service.buildOrServe({
2427
+ build: (options) => new Promise((resolve, reject) => service.buildOrContext({
2398
2428
  callName: "build",
2399
2429
  refs: null,
2400
- serveOptions: null,
2430
+ options,
2431
+ isTTY: false,
2432
+ defaultWD: "/",
2433
+ callback: (err, res) => err ? reject(err) : resolve(res)
2434
+ })),
2435
+ context: (options) => new Promise((resolve, reject) => service.buildOrContext({
2436
+ callName: "context",
2437
+ refs: null,
2401
2438
  options,
2402
2439
  isTTY: false,
2403
2440
  defaultWD: "/",
@@ -2441,11 +2478,11 @@ export {
2441
2478
  analyzeMetafileSync,
2442
2479
  build,
2443
2480
  buildSync,
2481
+ context,
2444
2482
  browser_default as default,
2445
2483
  formatMessages,
2446
2484
  formatMessagesSync,
2447
2485
  initialize,
2448
- serve,
2449
2486
  transform,
2450
2487
  transformSync,
2451
2488
  version