isomorfeus-asset-manager 0.15.1 → 0.15.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,26 +1,9 @@
1
1
  (module=>{
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
7
  var __export = (target, all) => {
25
8
  for (var name in all)
26
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -238,6 +221,8 @@ function writeUInt32LE(buffer, value, offset) {
238
221
  }
239
222
 
240
223
  // lib/shared/common.ts
224
+ var buildLogLevelDefault = "warning";
225
+ var transformLogLevelDefault = "silent";
241
226
  function validateTarget(target) {
242
227
  target += "";
243
228
  if (target.indexOf(",") >= 0)
@@ -338,6 +323,7 @@ function pushCommonFlags(flags, options, keys) {
338
323
  let jsxFragment = getFlag(options, keys, "jsxFragment", mustBeString);
339
324
  let jsxImportSource = getFlag(options, keys, "jsxImportSource", mustBeString);
340
325
  let jsxDev = getFlag(options, keys, "jsxDev", mustBeBoolean);
326
+ let jsxSideEffects = getFlag(options, keys, "jsxSideEffects", mustBeBoolean);
341
327
  let define = getFlag(options, keys, "define", mustBeObject);
342
328
  let logOverride = getFlag(options, keys, "logOverride", mustBeObject);
343
329
  let supported = getFlag(options, keys, "supported", mustBeObject);
@@ -395,6 +381,8 @@ function pushCommonFlags(flags, options, keys) {
395
381
  flags.push(`--jsx-import-source=${jsxImportSource}`);
396
382
  if (jsxDev)
397
383
  flags.push(`--jsx-dev`);
384
+ if (jsxSideEffects)
385
+ flags.push(`--jsx-side-effects`);
398
386
  if (define) {
399
387
  for (let key in define) {
400
388
  if (key.indexOf("=") >= 0)
@@ -648,11 +636,9 @@ function flagsForTransformOptions(callName, options, isTTY, logLevelDefault) {
648
636
  };
649
637
  }
650
638
  function createChannel(streamIn) {
651
- let responseCallbacks = /* @__PURE__ */ new Map();
652
- let pluginCallbacks = /* @__PURE__ */ new Map();
653
- let watchCallbacks = /* @__PURE__ */ new Map();
654
- let serveCallbacks = /* @__PURE__ */ new Map();
655
- let closeData = null;
639
+ const requestCallbacksByKey = {};
640
+ const closeData = { didClose: false, reason: "" };
641
+ let responseCallbacks = {};
656
642
  let nextRequestID = 0;
657
643
  let nextBuildKey = 0;
658
644
  let stdout = new Uint8Array(16 * 1024);
@@ -682,105 +668,53 @@ function createChannel(streamIn) {
682
668
  }
683
669
  };
684
670
  let afterClose = (error) => {
685
- closeData = { reason: error ? ": " + (error.message || error) : "" };
671
+ closeData.didClose = true;
672
+ if (error)
673
+ closeData.reason = ": " + (error.message || error);
686
674
  const text = "The service was stopped" + closeData.reason;
687
- for (let callback of responseCallbacks.values()) {
688
- callback(text, null);
689
- }
690
- responseCallbacks.clear();
691
- for (let callbacks of serveCallbacks.values()) {
692
- callbacks.onWait(text);
693
- }
694
- serveCallbacks.clear();
695
- for (let callback of watchCallbacks.values()) {
696
- try {
697
- callback(new Error(text), null);
698
- } catch (e) {
699
- console.error(e);
700
- }
675
+ for (let id in responseCallbacks) {
676
+ responseCallbacks[id](text, null);
701
677
  }
702
- watchCallbacks.clear();
678
+ responseCallbacks = {};
703
679
  };
704
680
  let sendRequest = (refs, value, callback) => {
705
- if (closeData)
681
+ if (closeData.didClose)
706
682
  return callback("The service is no longer running" + closeData.reason, null);
707
683
  let id = nextRequestID++;
708
- responseCallbacks.set(id, (error, response) => {
684
+ responseCallbacks[id] = (error, response) => {
709
685
  try {
710
686
  callback(error, response);
711
687
  } finally {
712
688
  if (refs)
713
689
  refs.unref();
714
690
  }
715
- });
691
+ };
716
692
  if (refs)
717
693
  refs.ref();
718
694
  streamIn.writeToStdin(encodePacket({ id, isRequest: true, value }));
719
695
  };
720
696
  let sendResponse = (id, value) => {
721
- if (closeData)
697
+ if (closeData.didClose)
722
698
  throw new Error("The service is no longer running" + closeData.reason);
723
699
  streamIn.writeToStdin(encodePacket({ id, isRequest: false, value }));
724
700
  };
725
701
  let handleRequest = (id, request) => __async(this, null, function* () {
726
702
  try {
727
- switch (request.command) {
728
- case "ping": {
729
- sendResponse(id, {});
730
- break;
731
- }
732
- case "on-start": {
733
- let callback = pluginCallbacks.get(request.key);
734
- if (!callback)
735
- sendResponse(id, {});
736
- else
737
- sendResponse(id, yield callback(request));
738
- break;
739
- }
740
- case "on-resolve": {
741
- let callback = pluginCallbacks.get(request.key);
742
- if (!callback)
743
- sendResponse(id, {});
744
- else
745
- sendResponse(id, yield callback(request));
746
- break;
747
- }
748
- case "on-load": {
749
- let callback = pluginCallbacks.get(request.key);
750
- if (!callback)
751
- sendResponse(id, {});
752
- else
753
- sendResponse(id, yield callback(request));
754
- break;
755
- }
756
- case "serve-request": {
757
- let callbacks = serveCallbacks.get(request.key);
758
- if (callbacks && callbacks.onRequest)
759
- callbacks.onRequest(request.args);
760
- sendResponse(id, {});
761
- break;
762
- }
763
- case "serve-wait": {
764
- let callbacks = serveCallbacks.get(request.key);
765
- if (callbacks)
766
- callbacks.onWait(request.error);
767
- sendResponse(id, {});
768
- break;
769
- }
770
- case "watch-rebuild": {
771
- let callback = watchCallbacks.get(request.key);
772
- try {
773
- if (callback)
774
- callback(null, request.args);
775
- } catch (err) {
776
- console.error(err);
703
+ if (request.command === "ping") {
704
+ sendResponse(id, {});
705
+ return;
706
+ }
707
+ if (typeof request.key === "number") {
708
+ const requestCallbacks = requestCallbacksByKey[request.key];
709
+ if (requestCallbacks) {
710
+ const callback = requestCallbacks[request.command];
711
+ if (callback) {
712
+ yield callback(id, request);
713
+ return;
777
714
  }
778
- sendResponse(id, {});
779
- break;
780
715
  }
781
- default:
782
- throw new Error(`Invalid command: ` + request.command);
783
716
  }
717
+ throw new Error(`Invalid command: ` + request.command);
784
718
  } catch (e) {
785
719
  sendResponse(id, { errors: [extractErrorMessageV8(e, streamIn, null, void 0, "")] });
786
720
  }
@@ -790,8 +724,8 @@ function createChannel(streamIn) {
790
724
  if (isFirstPacket) {
791
725
  isFirstPacket = false;
792
726
  let binaryVersion = String.fromCharCode(...bytes);
793
- if (binaryVersion !== "0.15.4") {
794
- throw new Error(`Cannot start service: Host version "${"0.15.4"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
727
+ if (binaryVersion !== "0.15.8") {
728
+ throw new Error(`Cannot start service: Host version "${"0.15.8"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
795
729
  }
796
730
  return;
797
731
  }
@@ -799,450 +733,259 @@ function createChannel(streamIn) {
799
733
  if (packet.isRequest) {
800
734
  handleRequest(packet.id, packet.value);
801
735
  } else {
802
- let callback = responseCallbacks.get(packet.id);
803
- responseCallbacks.delete(packet.id);
736
+ let callback = responseCallbacks[packet.id];
737
+ delete responseCallbacks[packet.id];
804
738
  if (packet.value.error)
805
739
  callback(packet.value.error, {});
806
740
  else
807
741
  callback(null, packet.value);
808
742
  }
809
743
  };
810
- let handlePlugins = (initialOptions, plugins, buildKey, stash, refs) => __async(this, null, function* () {
811
- let onStartCallbacks = [];
812
- let onEndCallbacks = [];
813
- let onResolveCallbacks = {};
814
- let onLoadCallbacks = {};
815
- let nextCallbackID = 0;
816
- let i = 0;
817
- let requestPlugins = [];
818
- let isSetupDone = false;
819
- plugins = [...plugins];
820
- for (let item of plugins) {
821
- let keys = {};
822
- if (typeof item !== "object")
823
- throw new Error(`Plugin at index ${i} must be an object`);
824
- const name = getFlag(item, keys, "name", mustBeString);
825
- if (typeof name !== "string" || name === "")
826
- throw new Error(`Plugin at index ${i} is missing a name`);
744
+ let buildOrServe = ({ callName, refs, serveOptions, options, isTTY, defaultWD, callback }) => {
745
+ let refCount = 0;
746
+ const buildKey = nextBuildKey++;
747
+ const requestCallbacks = {};
748
+ const buildRefs = {
749
+ ref() {
750
+ if (++refCount === 1) {
751
+ if (refs)
752
+ refs.ref();
753
+ }
754
+ },
755
+ unref() {
756
+ if (--refCount === 0) {
757
+ delete requestCallbacksByKey[buildKey];
758
+ if (refs)
759
+ refs.unref();
760
+ }
761
+ }
762
+ };
763
+ requestCallbacksByKey[buildKey] = requestCallbacks;
764
+ buildRefs.ref();
765
+ buildOrServeImpl(
766
+ callName,
767
+ buildKey,
768
+ sendRequest,
769
+ sendResponse,
770
+ buildRefs,
771
+ streamIn,
772
+ requestCallbacks,
773
+ options,
774
+ serveOptions,
775
+ isTTY,
776
+ defaultWD,
777
+ closeData,
778
+ (err, res) => {
779
+ try {
780
+ callback(err, res);
781
+ } finally {
782
+ buildRefs.unref();
783
+ }
784
+ }
785
+ );
786
+ };
787
+ let transform2 = ({ callName, refs, input, options, isTTY, fs, callback }) => {
788
+ const details = createObjectStash();
789
+ let start = (inputPath) => {
827
790
  try {
828
- let setup = getFlag(item, keys, "setup", mustBeFunction);
829
- if (typeof setup !== "function")
830
- throw new Error(`Plugin is missing a setup function`);
831
- checkForInvalidFlags(item, keys, `on plugin ${JSON.stringify(name)}`);
832
- let plugin = {
833
- name,
834
- onResolve: [],
835
- onLoad: []
836
- };
837
- i++;
838
- let resolve = (path, options = {}) => {
839
- if (!isSetupDone)
840
- throw new Error('Cannot call "resolve" before plugin setup has completed');
841
- if (typeof path !== "string")
842
- throw new Error(`The path to resolve must be a string`);
843
- let keys2 = /* @__PURE__ */ Object.create(null);
844
- let pluginName = getFlag(options, keys2, "pluginName", mustBeString);
845
- let importer = getFlag(options, keys2, "importer", mustBeString);
846
- let namespace = getFlag(options, keys2, "namespace", mustBeString);
847
- let resolveDir = getFlag(options, keys2, "resolveDir", mustBeString);
848
- let kind = getFlag(options, keys2, "kind", mustBeString);
849
- let pluginData = getFlag(options, keys2, "pluginData", canBeAnything);
850
- checkForInvalidFlags(options, keys2, "in resolve() call");
851
- return new Promise((resolve2, reject) => {
852
- const request = {
853
- command: "resolve",
854
- path,
855
- key: buildKey,
856
- pluginName: name
857
- };
858
- if (pluginName != null)
859
- request.pluginName = pluginName;
860
- if (importer != null)
861
- request.importer = importer;
862
- if (namespace != null)
863
- request.namespace = namespace;
864
- if (resolveDir != null)
865
- request.resolveDir = resolveDir;
866
- if (kind != null)
867
- request.kind = kind;
868
- if (pluginData != null)
869
- request.pluginData = stash.store(pluginData);
870
- sendRequest(refs, request, (error, response) => {
871
- if (error !== null)
872
- reject(new Error(error));
873
- else
874
- resolve2({
875
- errors: replaceDetailsInMessages(response.errors, stash),
876
- warnings: replaceDetailsInMessages(response.warnings, stash),
877
- path: response.path,
878
- external: response.external,
879
- sideEffects: response.sideEffects,
880
- namespace: response.namespace,
881
- suffix: response.suffix,
882
- pluginData: stash.load(response.pluginData)
883
- });
884
- });
885
- });
791
+ if (typeof input !== "string" && !(input instanceof Uint8Array))
792
+ throw new Error('The input to "transform" must be a string or a Uint8Array');
793
+ let {
794
+ flags,
795
+ mangleCache
796
+ } = flagsForTransformOptions(callName, options, isTTY, transformLogLevelDefault);
797
+ let request = {
798
+ command: "transform",
799
+ flags,
800
+ inputFS: inputPath !== null,
801
+ input: inputPath !== null ? encodeUTF8(inputPath) : typeof input === "string" ? encodeUTF8(input) : input
886
802
  };
887
- let promise = setup({
888
- initialOptions,
889
- resolve,
890
- onStart(callback2) {
891
- let registeredText = `This error came from the "onStart" callback registered here:`;
892
- let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onStart");
893
- onStartCallbacks.push({ name, callback: callback2, note: registeredNote });
894
- },
895
- onEnd(callback2) {
896
- let registeredText = `This error came from the "onEnd" callback registered here:`;
897
- let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onEnd");
898
- onEndCallbacks.push({ name, callback: callback2, note: registeredNote });
899
- },
900
- onResolve(options, callback2) {
901
- let registeredText = `This error came from the "onResolve" callback registered here:`;
902
- let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onResolve");
903
- let keys2 = {};
904
- let filter = getFlag(options, keys2, "filter", mustBeRegExp);
905
- let namespace = getFlag(options, keys2, "namespace", mustBeString);
906
- checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${JSON.stringify(name)}`);
907
- if (filter == null)
908
- throw new Error(`onResolve() call is missing a filter`);
909
- let id = nextCallbackID++;
910
- onResolveCallbacks[id] = { name, callback: callback2, note: registeredNote };
911
- plugin.onResolve.push({ id, filter: filter.source, namespace: namespace || "" });
912
- },
913
- onLoad(options, callback2) {
914
- let registeredText = `This error came from the "onLoad" callback registered here:`;
915
- let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onLoad");
916
- let keys2 = {};
917
- let filter = getFlag(options, keys2, "filter", mustBeRegExp);
918
- let namespace = getFlag(options, keys2, "namespace", mustBeString);
919
- checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${JSON.stringify(name)}`);
920
- if (filter == null)
921
- throw new Error(`onLoad() call is missing a filter`);
922
- let id = nextCallbackID++;
923
- onLoadCallbacks[id] = { name, callback: callback2, note: registeredNote };
924
- plugin.onLoad.push({ id, filter: filter.source, namespace: namespace || "" });
925
- },
926
- esbuild: streamIn.esbuild
927
- });
928
- if (promise)
929
- yield promise;
930
- requestPlugins.push(plugin);
931
- } catch (e) {
932
- return { ok: false, error: e, pluginName: name };
933
- }
934
- }
935
- const callback = (request) => __async(this, null, function* () {
936
- switch (request.command) {
937
- case "on-start": {
938
- let response = { errors: [], warnings: [] };
939
- yield Promise.all(onStartCallbacks.map((_0) => __async(this, [_0], function* ({ name, callback: callback2, note }) {
940
- try {
941
- let result = yield callback2();
942
- if (result != null) {
943
- if (typeof result !== "object")
944
- throw new Error(`Expected onStart() callback in plugin ${JSON.stringify(name)} to return an object`);
945
- let keys = {};
946
- let errors = getFlag(result, keys, "errors", mustBeArray);
947
- let warnings = getFlag(result, keys, "warnings", mustBeArray);
948
- checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${JSON.stringify(name)}`);
949
- if (errors != null)
950
- response.errors.push(...sanitizeMessages(errors, "errors", stash, name));
951
- if (warnings != null)
952
- response.warnings.push(...sanitizeMessages(warnings, "warnings", stash, name));
953
- }
954
- } catch (e) {
955
- response.errors.push(extractErrorMessageV8(e, streamIn, stash, note && note(), name));
803
+ if (mangleCache)
804
+ request.mangleCache = mangleCache;
805
+ sendRequest(refs, request, (error, response) => {
806
+ if (error)
807
+ return callback(new Error(error), null);
808
+ let errors = replaceDetailsInMessages(response.errors, details);
809
+ let warnings = replaceDetailsInMessages(response.warnings, details);
810
+ let outstanding = 1;
811
+ let next = () => {
812
+ if (--outstanding === 0) {
813
+ let result = { warnings, code: response.code, map: response.map };
814
+ if (response.mangleCache)
815
+ result.mangleCache = response == null ? void 0 : response.mangleCache;
816
+ callback(null, result);
956
817
  }
957
- })));
958
- return response;
959
- }
960
- case "on-resolve": {
961
- let response = {}, name = "", callback2, note;
962
- for (let id of request.ids) {
963
- try {
964
- ({ name, callback: callback2, note } = onResolveCallbacks[id]);
965
- let result = yield callback2({
966
- path: request.path,
967
- importer: request.importer,
968
- namespace: request.namespace,
969
- resolveDir: request.resolveDir,
970
- kind: request.kind,
971
- pluginData: stash.load(request.pluginData)
972
- });
973
- if (result != null) {
974
- if (typeof result !== "object")
975
- throw new Error(`Expected onResolve() callback in plugin ${JSON.stringify(name)} to return an object`);
976
- let keys = {};
977
- let pluginName = getFlag(result, keys, "pluginName", mustBeString);
978
- let path = getFlag(result, keys, "path", mustBeString);
979
- let namespace = getFlag(result, keys, "namespace", mustBeString);
980
- let suffix = getFlag(result, keys, "suffix", mustBeString);
981
- let external = getFlag(result, keys, "external", mustBeBoolean);
982
- let sideEffects = getFlag(result, keys, "sideEffects", mustBeBoolean);
983
- let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
984
- let errors = getFlag(result, keys, "errors", mustBeArray);
985
- let warnings = getFlag(result, keys, "warnings", mustBeArray);
986
- let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
987
- let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
988
- checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${JSON.stringify(name)}`);
989
- response.id = id;
990
- if (pluginName != null)
991
- response.pluginName = pluginName;
992
- if (path != null)
993
- response.path = path;
994
- if (namespace != null)
995
- response.namespace = namespace;
996
- if (suffix != null)
997
- response.suffix = suffix;
998
- if (external != null)
999
- response.external = external;
1000
- if (sideEffects != null)
1001
- response.sideEffects = sideEffects;
1002
- if (pluginData != null)
1003
- response.pluginData = stash.store(pluginData);
1004
- if (errors != null)
1005
- response.errors = sanitizeMessages(errors, "errors", stash, name);
1006
- if (warnings != null)
1007
- response.warnings = sanitizeMessages(warnings, "warnings", stash, name);
1008
- if (watchFiles != null)
1009
- response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
1010
- if (watchDirs != null)
1011
- response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
1012
- break;
818
+ };
819
+ if (errors.length > 0)
820
+ return callback(failureErrorWithLog("Transform failed", errors, warnings), null);
821
+ if (response.codeFS) {
822
+ outstanding++;
823
+ fs.readFile(response.code, (err, contents) => {
824
+ if (err !== null) {
825
+ callback(err, null);
826
+ } else {
827
+ response.code = contents;
828
+ next();
1013
829
  }
1014
- } catch (e) {
1015
- return { id, errors: [extractErrorMessageV8(e, streamIn, stash, note && note(), name)] };
1016
- }
830
+ });
1017
831
  }
1018
- return response;
1019
- }
1020
- case "on-load": {
1021
- let response = {}, name = "", callback2, note;
1022
- for (let id of request.ids) {
1023
- try {
1024
- ({ name, callback: callback2, note } = onLoadCallbacks[id]);
1025
- let result = yield callback2({
1026
- path: request.path,
1027
- namespace: request.namespace,
1028
- suffix: request.suffix,
1029
- pluginData: stash.load(request.pluginData)
1030
- });
1031
- if (result != null) {
1032
- if (typeof result !== "object")
1033
- throw new Error(`Expected onLoad() callback in plugin ${JSON.stringify(name)} to return an object`);
1034
- let keys = {};
1035
- let pluginName = getFlag(result, keys, "pluginName", mustBeString);
1036
- let contents = getFlag(result, keys, "contents", mustBeStringOrUint8Array);
1037
- let resolveDir = getFlag(result, keys, "resolveDir", mustBeString);
1038
- let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
1039
- let loader = getFlag(result, keys, "loader", mustBeString);
1040
- let errors = getFlag(result, keys, "errors", mustBeArray);
1041
- let warnings = getFlag(result, keys, "warnings", mustBeArray);
1042
- let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
1043
- let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
1044
- checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${JSON.stringify(name)}`);
1045
- response.id = id;
1046
- if (pluginName != null)
1047
- response.pluginName = pluginName;
1048
- if (contents instanceof Uint8Array)
1049
- response.contents = contents;
1050
- else if (contents != null)
1051
- response.contents = encodeUTF8(contents);
1052
- if (resolveDir != null)
1053
- response.resolveDir = resolveDir;
1054
- if (pluginData != null)
1055
- response.pluginData = stash.store(pluginData);
1056
- if (loader != null)
1057
- response.loader = loader;
1058
- if (errors != null)
1059
- response.errors = sanitizeMessages(errors, "errors", stash, name);
1060
- if (warnings != null)
1061
- response.warnings = sanitizeMessages(warnings, "warnings", stash, name);
1062
- if (watchFiles != null)
1063
- response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
1064
- if (watchDirs != null)
1065
- response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
1066
- break;
832
+ if (response.mapFS) {
833
+ outstanding++;
834
+ fs.readFile(response.map, (err, contents) => {
835
+ if (err !== null) {
836
+ callback(err, null);
837
+ } else {
838
+ response.map = contents;
839
+ next();
1067
840
  }
1068
- } catch (e) {
1069
- return { id, errors: [extractErrorMessageV8(e, streamIn, stash, note && note(), name)] };
1070
- }
1071
- }
1072
- return response;
1073
- }
1074
- default:
1075
- throw new Error(`Invalid command: ` + request.command);
1076
- }
1077
- });
1078
- let runOnEndCallbacks = (result, logPluginError, done) => done();
1079
- if (onEndCallbacks.length > 0) {
1080
- runOnEndCallbacks = (result, logPluginError, done) => {
1081
- (() => __async(this, null, function* () {
1082
- for (const { name, callback: callback2, note } of onEndCallbacks) {
1083
- try {
1084
- yield callback2(result);
1085
- } catch (e) {
1086
- result.errors.push(yield new Promise((resolve) => logPluginError(e, name, note && note(), resolve)));
1087
- }
841
+ });
1088
842
  }
1089
- }))().then(done);
1090
- };
1091
- }
1092
- isSetupDone = true;
1093
- let refCount = 0;
1094
- return {
1095
- ok: true,
1096
- requestPlugins,
1097
- runOnEndCallbacks,
1098
- pluginRefs: {
1099
- ref() {
1100
- if (++refCount === 1)
1101
- pluginCallbacks.set(buildKey, callback);
1102
- },
1103
- unref() {
1104
- if (--refCount === 0)
1105
- pluginCallbacks.delete(buildKey);
843
+ next();
844
+ });
845
+ } catch (e) {
846
+ let flags = [];
847
+ try {
848
+ pushLogFlags(flags, options, {}, isTTY, transformLogLevelDefault);
849
+ } catch (e2) {
1106
850
  }
851
+ const error = extractErrorMessageV8(e, streamIn, details, void 0, "");
852
+ sendRequest(refs, { command: "error", flags, error }, () => {
853
+ error.detail = details.load(error.detail);
854
+ callback(failureErrorWithLog("Transform failed", [error], []), null);
855
+ });
1107
856
  }
1108
857
  };
1109
- });
1110
- let buildServeData = (refs, options, request, key) => {
858
+ if ((typeof input === "string" || input instanceof Uint8Array) && input.length > 1024 * 1024) {
859
+ let next = start;
860
+ start = () => fs.writeFile(input, next);
861
+ }
862
+ start(null);
863
+ };
864
+ let formatMessages2 = ({ callName, refs, messages, options, callback }) => {
865
+ let result = sanitizeMessages(messages, "messages", null, "");
866
+ if (!options)
867
+ throw new Error(`Missing second argument in ${callName}() call`);
1111
868
  let keys = {};
1112
- let port = getFlag(options, keys, "port", mustBeInteger);
1113
- let host = getFlag(options, keys, "host", mustBeString);
1114
- let servedir = getFlag(options, keys, "servedir", mustBeString);
1115
- let onRequest = getFlag(options, keys, "onRequest", mustBeFunction);
1116
- let onWait;
1117
- let wait = new Promise((resolve, reject) => {
1118
- onWait = (error) => {
1119
- serveCallbacks.delete(key);
1120
- if (error !== null)
1121
- reject(new Error(error));
1122
- else
1123
- resolve();
1124
- };
1125
- });
1126
- request.serve = {};
1127
- checkForInvalidFlags(options, keys, `in serve() call`);
1128
- if (port !== void 0)
1129
- request.serve.port = port;
1130
- if (host !== void 0)
1131
- request.serve.host = host;
1132
- if (servedir !== void 0)
1133
- request.serve.servedir = servedir;
1134
- serveCallbacks.set(key, {
1135
- onRequest,
1136
- onWait
869
+ let kind = getFlag(options, keys, "kind", mustBeString);
870
+ let color = getFlag(options, keys, "color", mustBeBoolean);
871
+ let terminalWidth = getFlag(options, keys, "terminalWidth", mustBeInteger);
872
+ checkForInvalidFlags(options, keys, `in ${callName}() call`);
873
+ if (kind === void 0)
874
+ throw new Error(`Missing "kind" in ${callName}() call`);
875
+ if (kind !== "error" && kind !== "warning")
876
+ throw new Error(`Expected "kind" to be "error" or "warning" in ${callName}() call`);
877
+ let request = {
878
+ command: "format-msgs",
879
+ messages: result,
880
+ isWarning: kind === "warning"
881
+ };
882
+ if (color !== void 0)
883
+ request.color = color;
884
+ if (terminalWidth !== void 0)
885
+ request.terminalWidth = terminalWidth;
886
+ sendRequest(refs, request, (error, response) => {
887
+ if (error)
888
+ return callback(new Error(error), null);
889
+ callback(null, response.messages);
1137
890
  });
1138
- return {
1139
- wait,
1140
- stop() {
1141
- sendRequest(refs, { command: "serve-stop", key }, () => {
1142
- });
1143
- }
891
+ };
892
+ let analyzeMetafile2 = ({ callName, refs, metafile, options, callback }) => {
893
+ if (options === void 0)
894
+ options = {};
895
+ let keys = {};
896
+ let color = getFlag(options, keys, "color", mustBeBoolean);
897
+ let verbose = getFlag(options, keys, "verbose", mustBeBoolean);
898
+ checkForInvalidFlags(options, keys, `in ${callName}() call`);
899
+ let request = {
900
+ command: "analyze-metafile",
901
+ metafile
1144
902
  };
903
+ if (color !== void 0)
904
+ request.color = color;
905
+ if (verbose !== void 0)
906
+ request.verbose = verbose;
907
+ sendRequest(refs, request, (error, response) => {
908
+ if (error)
909
+ return callback(new Error(error), null);
910
+ callback(null, response.result);
911
+ });
1145
912
  };
1146
- const buildLogLevelDefault = "warning";
1147
- const transformLogLevelDefault = "silent";
1148
- let buildOrServe = (args) => {
1149
- let key = nextBuildKey++;
1150
- const details = createObjectStash();
1151
- let plugins;
1152
- let { refs, options, isTTY, callback } = args;
1153
- if (typeof options === "object") {
1154
- let value = options.plugins;
1155
- if (value !== void 0) {
1156
- if (!Array.isArray(value))
1157
- throw new Error(`"plugins" must be an array`);
1158
- plugins = value;
1159
- }
913
+ return {
914
+ readFromStdout,
915
+ afterClose,
916
+ service: {
917
+ buildOrServe,
918
+ transform: transform2,
919
+ formatMessages: formatMessages2,
920
+ analyzeMetafile: analyzeMetafile2
1160
921
  }
1161
- let logPluginError = (e, pluginName, note, done) => {
1162
- let flags = [];
1163
- try {
1164
- pushLogFlags(flags, options, {}, isTTY, buildLogLevelDefault);
1165
- } catch (e2) {
1166
- }
1167
- const message = extractErrorMessageV8(e, streamIn, details, note, pluginName);
1168
- sendRequest(refs, { command: "error", flags, error: message }, () => {
1169
- message.detail = details.load(message.detail);
1170
- done(message);
1171
- });
1172
- };
1173
- let handleError = (e, pluginName) => {
1174
- logPluginError(e, pluginName, void 0, (error) => {
1175
- callback(failureErrorWithLog("Build failed", [error], []), null);
1176
- });
1177
- };
1178
- if (plugins && plugins.length > 0) {
1179
- if (streamIn.isSync)
1180
- return handleError(new Error("Cannot use plugins in synchronous API calls"), "");
1181
- handlePlugins(options, plugins, key, details, refs).then(
1182
- (result) => {
1183
- if (!result.ok) {
1184
- handleError(result.error, result.pluginName);
1185
- } else {
1186
- try {
1187
- buildOrServeContinue(__spreadProps(__spreadValues({}, args), {
1188
- key,
1189
- details,
1190
- logPluginError,
1191
- requestPlugins: result.requestPlugins,
1192
- runOnEndCallbacks: result.runOnEndCallbacks,
1193
- pluginRefs: result.pluginRefs
1194
- }));
1195
- } catch (e) {
1196
- handleError(e, "");
1197
- }
1198
- }
1199
- },
1200
- (e) => handleError(e, "")
1201
- );
1202
- } else {
1203
- try {
1204
- buildOrServeContinue(__spreadProps(__spreadValues({}, args), {
1205
- key,
1206
- details,
1207
- logPluginError,
1208
- requestPlugins: null,
1209
- runOnEndCallbacks: (result, logPluginError2, done) => done(),
1210
- pluginRefs: null
1211
- }));
1212
- } catch (e) {
1213
- handleError(e, "");
1214
- }
922
+ };
923
+ }
924
+ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, options, serveOptions, isTTY, defaultWD, closeData, callback) {
925
+ const details = createObjectStash();
926
+ const logPluginError = (e, pluginName, note, done) => {
927
+ const flags = [];
928
+ try {
929
+ pushLogFlags(flags, options, {}, isTTY, buildLogLevelDefault);
930
+ } catch (e2) {
1215
931
  }
932
+ const message = extractErrorMessageV8(e, streamIn, details, note, pluginName);
933
+ sendRequest(refs, { command: "error", flags, error: message }, () => {
934
+ message.detail = details.load(message.detail);
935
+ done(message);
936
+ });
1216
937
  };
1217
- let buildOrServeContinue = ({
1218
- callName,
1219
- refs: callerRefs,
1220
- serveOptions,
1221
- options,
1222
- isTTY,
1223
- defaultWD,
1224
- callback,
1225
- key,
1226
- details,
1227
- logPluginError,
1228
- requestPlugins,
1229
- runOnEndCallbacks,
1230
- pluginRefs
1231
- }) => {
1232
- const refs = {
1233
- ref() {
1234
- if (pluginRefs)
1235
- pluginRefs.ref();
1236
- if (callerRefs)
1237
- callerRefs.ref();
938
+ const handleError = (e, pluginName) => {
939
+ logPluginError(e, pluginName, void 0, (error) => {
940
+ callback(failureErrorWithLog("Build failed", [error], []), null);
941
+ });
942
+ };
943
+ let plugins;
944
+ if (typeof options === "object") {
945
+ const value = options.plugins;
946
+ if (value !== void 0) {
947
+ if (!Array.isArray(value))
948
+ throw new Error(`"plugins" must be an array`);
949
+ plugins = value;
950
+ }
951
+ }
952
+ if (plugins && plugins.length > 0) {
953
+ if (streamIn.isSync) {
954
+ handleError(new Error("Cannot use plugins in synchronous API calls"), "");
955
+ return;
956
+ }
957
+ handlePlugins(
958
+ buildKey,
959
+ sendRequest,
960
+ sendResponse,
961
+ refs,
962
+ streamIn,
963
+ requestCallbacks,
964
+ options,
965
+ plugins,
966
+ details
967
+ ).then(
968
+ (result) => {
969
+ if (!result.ok) {
970
+ handleError(result.error, result.pluginName);
971
+ return;
972
+ }
973
+ try {
974
+ buildOrServeContinue(result.requestPlugins, result.runOnEndCallbacks);
975
+ } catch (e) {
976
+ handleError(e, "");
977
+ }
1238
978
  },
1239
- unref() {
1240
- if (pluginRefs)
1241
- pluginRefs.unref();
1242
- if (callerRefs)
1243
- callerRefs.unref();
1244
- }
1245
- };
979
+ (e) => handleError(e, "")
980
+ );
981
+ return;
982
+ }
983
+ try {
984
+ buildOrServeContinue(null, (result, logPluginError2, done) => done());
985
+ } catch (e) {
986
+ handleError(e, "");
987
+ }
988
+ function buildOrServeContinue(requestPlugins, runOnEndCallbacks) {
1246
989
  let writeDefault = !streamIn.isWriteUnavailable;
1247
990
  let {
1248
991
  entries,
@@ -1258,7 +1001,7 @@ function createChannel(streamIn) {
1258
1001
  } = flagsForBuildOptions(callName, options, isTTY, buildLogLevelDefault, writeDefault);
1259
1002
  let request = {
1260
1003
  command: "build",
1261
- key,
1004
+ key: buildKey,
1262
1005
  entries,
1263
1006
  flags,
1264
1007
  write,
@@ -1272,7 +1015,7 @@ function createChannel(streamIn) {
1272
1015
  request.plugins = requestPlugins;
1273
1016
  if (mangleCache)
1274
1017
  request.mangleCache = mangleCache;
1275
- let serve2 = serveOptions && buildServeData(refs, serveOptions, request, key);
1018
+ let serve2 = serveOptions && buildServeData(buildKey, sendRequest, sendResponse, refs, requestCallbacks, serveOptions, request);
1276
1019
  let rebuild;
1277
1020
  let stop;
1278
1021
  let copyResponseToResult = (response, result) => {
@@ -1299,11 +1042,11 @@ function createChannel(streamIn) {
1299
1042
  if (!rebuild) {
1300
1043
  let isDisposed = false;
1301
1044
  rebuild = () => new Promise((resolve, reject) => {
1302
- if (isDisposed || closeData)
1045
+ if (isDisposed || closeData.didClose)
1303
1046
  throw new Error("Cannot rebuild");
1304
1047
  sendRequest(
1305
1048
  refs,
1306
- { command: "rebuild", key },
1049
+ { command: "rebuild", key: buildKey },
1307
1050
  (error2, response2) => {
1308
1051
  if (error2) {
1309
1052
  const message = { id: "", pluginName: "", text: error2, location: null, notes: [], detail: void 0 };
@@ -1323,7 +1066,7 @@ function createChannel(streamIn) {
1323
1066
  if (isDisposed)
1324
1067
  return;
1325
1068
  isDisposed = true;
1326
- sendRequest(refs, { command: "rebuild-dispose", key }, () => {
1069
+ sendRequest(refs, { command: "rebuild-dispose", key: buildKey }, () => {
1327
1070
  });
1328
1071
  refs.unref();
1329
1072
  };
@@ -1338,36 +1081,35 @@ function createChannel(streamIn) {
1338
1081
  if (isStopped)
1339
1082
  return;
1340
1083
  isStopped = true;
1341
- watchCallbacks.delete(key);
1342
- sendRequest(refs, { command: "watch-stop", key }, () => {
1084
+ delete requestCallbacks["watch-rebuild"];
1085
+ sendRequest(refs, { command: "watch-stop", key: buildKey }, () => {
1343
1086
  });
1344
1087
  refs.unref();
1345
1088
  };
1346
1089
  if (watch) {
1347
- watchCallbacks.set(key, (serviceStopError, watchResponse) => {
1348
- if (serviceStopError) {
1349
- if (watch.onRebuild)
1350
- watch.onRebuild(serviceStopError, null);
1351
- return;
1352
- }
1353
- let result2 = {
1354
- errors: replaceDetailsInMessages(watchResponse.errors, details),
1355
- warnings: replaceDetailsInMessages(watchResponse.warnings, details)
1356
- };
1357
- copyResponseToResult(watchResponse, result2);
1358
- runOnEndCallbacks(result2, logPluginError, () => {
1359
- if (result2.errors.length > 0) {
1090
+ requestCallbacks["watch-rebuild"] = (id, request2) => {
1091
+ try {
1092
+ let watchResponse = request2.args;
1093
+ let result2 = {
1094
+ errors: replaceDetailsInMessages(watchResponse.errors, details),
1095
+ warnings: replaceDetailsInMessages(watchResponse.warnings, details)
1096
+ };
1097
+ copyResponseToResult(watchResponse, result2);
1098
+ runOnEndCallbacks(result2, logPluginError, () => {
1099
+ if (result2.errors.length > 0) {
1100
+ if (watch.onRebuild)
1101
+ watch.onRebuild(failureErrorWithLog("Build failed", result2.errors, result2.warnings), null);
1102
+ return;
1103
+ }
1104
+ result2.stop = stop;
1360
1105
  if (watch.onRebuild)
1361
- watch.onRebuild(failureErrorWithLog("Build failed", result2.errors, result2.warnings), null);
1362
- return;
1363
- }
1364
- if (watchResponse.rebuildID !== void 0)
1365
- result2.rebuild = rebuild;
1366
- result2.stop = stop;
1367
- if (watch.onRebuild)
1368
- watch.onRebuild(null, result2);
1369
- });
1370
- });
1106
+ watch.onRebuild(null, result2);
1107
+ });
1108
+ } catch (err) {
1109
+ console.error(err);
1110
+ }
1111
+ sendResponse(id, {});
1112
+ };
1371
1113
  }
1372
1114
  }
1373
1115
  result.stop = stop;
@@ -1406,144 +1148,329 @@ function createChannel(streamIn) {
1406
1148
  }
1407
1149
  return buildResponseToResult(response, callback);
1408
1150
  });
1151
+ }
1152
+ }
1153
+ var buildServeData = (buildKey, sendRequest, sendResponse, refs, requestCallbacks, options, request) => {
1154
+ let keys = {};
1155
+ let port = getFlag(options, keys, "port", mustBeInteger);
1156
+ let host = getFlag(options, keys, "host", mustBeString);
1157
+ let servedir = getFlag(options, keys, "servedir", mustBeString);
1158
+ let onRequest = getFlag(options, keys, "onRequest", mustBeFunction);
1159
+ let wait = new Promise((resolve, reject) => {
1160
+ requestCallbacks["serve-wait"] = (id, request2) => {
1161
+ if (request2.error !== null)
1162
+ reject(new Error(request2.error));
1163
+ else
1164
+ resolve();
1165
+ sendResponse(id, {});
1166
+ };
1167
+ });
1168
+ request.serve = {};
1169
+ checkForInvalidFlags(options, keys, `in serve() call`);
1170
+ if (port !== void 0)
1171
+ request.serve.port = port;
1172
+ if (host !== void 0)
1173
+ request.serve.host = host;
1174
+ if (servedir !== void 0)
1175
+ request.serve.servedir = servedir;
1176
+ requestCallbacks["serve-request"] = (id, request2) => {
1177
+ if (onRequest)
1178
+ onRequest(request2.args);
1179
+ sendResponse(id, {});
1409
1180
  };
1410
- let transform2 = ({ callName, refs, input, options, isTTY, fs, callback }) => {
1411
- const details = createObjectStash();
1412
- let start = (inputPath) => {
1413
- try {
1414
- if (typeof input !== "string" && !(input instanceof Uint8Array))
1415
- throw new Error('The input to "transform" must be a string or a Uint8Array');
1416
- let {
1417
- flags,
1418
- mangleCache
1419
- } = flagsForTransformOptions(callName, options, isTTY, transformLogLevelDefault);
1420
- let request = {
1421
- command: "transform",
1422
- flags,
1423
- inputFS: inputPath !== null,
1424
- input: inputPath !== null ? encodeUTF8(inputPath) : typeof input === "string" ? encodeUTF8(input) : input
1425
- };
1426
- if (mangleCache)
1427
- request.mangleCache = mangleCache;
1428
- sendRequest(refs, request, (error, response) => {
1429
- if (error)
1430
- return callback(new Error(error), null);
1431
- let errors = replaceDetailsInMessages(response.errors, details);
1432
- let warnings = replaceDetailsInMessages(response.warnings, details);
1433
- let outstanding = 1;
1434
- let next = () => {
1435
- if (--outstanding === 0) {
1436
- let result = { warnings, code: response.code, map: response.map };
1437
- if (response.mangleCache)
1438
- result.mangleCache = response == null ? void 0 : response.mangleCache;
1439
- callback(null, result);
1440
- }
1181
+ return {
1182
+ wait,
1183
+ stop() {
1184
+ sendRequest(refs, { command: "serve-stop", key: buildKey }, () => {
1185
+ });
1186
+ }
1187
+ };
1188
+ };
1189
+ var handlePlugins = (buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, initialOptions, plugins, details) => __async(void 0, null, function* () {
1190
+ let onStartCallbacks = [];
1191
+ let onEndCallbacks = [];
1192
+ let onResolveCallbacks = {};
1193
+ let onLoadCallbacks = {};
1194
+ let nextCallbackID = 0;
1195
+ let i = 0;
1196
+ let requestPlugins = [];
1197
+ let isSetupDone = false;
1198
+ plugins = [...plugins];
1199
+ for (let item of plugins) {
1200
+ let keys = {};
1201
+ if (typeof item !== "object")
1202
+ throw new Error(`Plugin at index ${i} must be an object`);
1203
+ const name = getFlag(item, keys, "name", mustBeString);
1204
+ if (typeof name !== "string" || name === "")
1205
+ throw new Error(`Plugin at index ${i} is missing a name`);
1206
+ try {
1207
+ let setup = getFlag(item, keys, "setup", mustBeFunction);
1208
+ if (typeof setup !== "function")
1209
+ throw new Error(`Plugin is missing a setup function`);
1210
+ checkForInvalidFlags(item, keys, `on plugin ${JSON.stringify(name)}`);
1211
+ let plugin = {
1212
+ name,
1213
+ onResolve: [],
1214
+ onLoad: []
1215
+ };
1216
+ i++;
1217
+ let resolve = (path, options = {}) => {
1218
+ if (!isSetupDone)
1219
+ throw new Error('Cannot call "resolve" before plugin setup has completed');
1220
+ if (typeof path !== "string")
1221
+ throw new Error(`The path to resolve must be a string`);
1222
+ let keys2 = /* @__PURE__ */ Object.create(null);
1223
+ let pluginName = getFlag(options, keys2, "pluginName", mustBeString);
1224
+ let importer = getFlag(options, keys2, "importer", mustBeString);
1225
+ let namespace = getFlag(options, keys2, "namespace", mustBeString);
1226
+ let resolveDir = getFlag(options, keys2, "resolveDir", mustBeString);
1227
+ let kind = getFlag(options, keys2, "kind", mustBeString);
1228
+ let pluginData = getFlag(options, keys2, "pluginData", canBeAnything);
1229
+ checkForInvalidFlags(options, keys2, "in resolve() call");
1230
+ return new Promise((resolve2, reject) => {
1231
+ const request = {
1232
+ command: "resolve",
1233
+ path,
1234
+ key: buildKey,
1235
+ pluginName: name
1441
1236
  };
1442
- if (errors.length > 0)
1443
- return callback(failureErrorWithLog("Transform failed", errors, warnings), null);
1444
- if (response.codeFS) {
1445
- outstanding++;
1446
- fs.readFile(response.code, (err, contents) => {
1447
- if (err !== null) {
1448
- callback(err, null);
1449
- } else {
1450
- response.code = contents;
1451
- next();
1452
- }
1453
- });
1454
- }
1455
- if (response.mapFS) {
1456
- outstanding++;
1457
- fs.readFile(response.map, (err, contents) => {
1458
- if (err !== null) {
1459
- callback(err, null);
1460
- } else {
1461
- response.map = contents;
1462
- next();
1463
- }
1464
- });
1465
- }
1466
- next();
1237
+ if (pluginName != null)
1238
+ request.pluginName = pluginName;
1239
+ if (importer != null)
1240
+ request.importer = importer;
1241
+ if (namespace != null)
1242
+ request.namespace = namespace;
1243
+ if (resolveDir != null)
1244
+ request.resolveDir = resolveDir;
1245
+ if (kind != null)
1246
+ request.kind = kind;
1247
+ if (pluginData != null)
1248
+ request.pluginData = details.store(pluginData);
1249
+ sendRequest(refs, request, (error, response) => {
1250
+ if (error !== null)
1251
+ reject(new Error(error));
1252
+ else
1253
+ resolve2({
1254
+ errors: replaceDetailsInMessages(response.errors, details),
1255
+ warnings: replaceDetailsInMessages(response.warnings, details),
1256
+ path: response.path,
1257
+ external: response.external,
1258
+ sideEffects: response.sideEffects,
1259
+ namespace: response.namespace,
1260
+ suffix: response.suffix,
1261
+ pluginData: details.load(response.pluginData)
1262
+ });
1263
+ });
1467
1264
  });
1265
+ };
1266
+ let promise = setup({
1267
+ initialOptions,
1268
+ resolve,
1269
+ onStart(callback) {
1270
+ let registeredText = `This error came from the "onStart" callback registered here:`;
1271
+ let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onStart");
1272
+ onStartCallbacks.push({ name, callback, note: registeredNote });
1273
+ },
1274
+ onEnd(callback) {
1275
+ let registeredText = `This error came from the "onEnd" callback registered here:`;
1276
+ let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onEnd");
1277
+ onEndCallbacks.push({ name, callback, note: registeredNote });
1278
+ },
1279
+ onResolve(options, callback) {
1280
+ let registeredText = `This error came from the "onResolve" callback registered here:`;
1281
+ let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onResolve");
1282
+ let keys2 = {};
1283
+ let filter = getFlag(options, keys2, "filter", mustBeRegExp);
1284
+ let namespace = getFlag(options, keys2, "namespace", mustBeString);
1285
+ checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${JSON.stringify(name)}`);
1286
+ if (filter == null)
1287
+ throw new Error(`onResolve() call is missing a filter`);
1288
+ let id = nextCallbackID++;
1289
+ onResolveCallbacks[id] = { name, callback, note: registeredNote };
1290
+ plugin.onResolve.push({ id, filter: filter.source, namespace: namespace || "" });
1291
+ },
1292
+ onLoad(options, callback) {
1293
+ let registeredText = `This error came from the "onLoad" callback registered here:`;
1294
+ let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onLoad");
1295
+ let keys2 = {};
1296
+ let filter = getFlag(options, keys2, "filter", mustBeRegExp);
1297
+ let namespace = getFlag(options, keys2, "namespace", mustBeString);
1298
+ checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${JSON.stringify(name)}`);
1299
+ if (filter == null)
1300
+ throw new Error(`onLoad() call is missing a filter`);
1301
+ let id = nextCallbackID++;
1302
+ onLoadCallbacks[id] = { name, callback, note: registeredNote };
1303
+ plugin.onLoad.push({ id, filter: filter.source, namespace: namespace || "" });
1304
+ },
1305
+ esbuild: streamIn.esbuild
1306
+ });
1307
+ if (promise)
1308
+ yield promise;
1309
+ requestPlugins.push(plugin);
1310
+ } catch (e) {
1311
+ return { ok: false, error: e, pluginName: name };
1312
+ }
1313
+ }
1314
+ requestCallbacks["on-start"] = (id, request) => __async(void 0, null, function* () {
1315
+ let response = { errors: [], warnings: [] };
1316
+ yield Promise.all(onStartCallbacks.map((_0) => __async(void 0, [_0], function* ({ name, callback, note }) {
1317
+ try {
1318
+ let result = yield callback();
1319
+ if (result != null) {
1320
+ if (typeof result !== "object")
1321
+ throw new Error(`Expected onStart() callback in plugin ${JSON.stringify(name)} to return an object`);
1322
+ let keys = {};
1323
+ let errors = getFlag(result, keys, "errors", mustBeArray);
1324
+ let warnings = getFlag(result, keys, "warnings", mustBeArray);
1325
+ checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${JSON.stringify(name)}`);
1326
+ if (errors != null)
1327
+ response.errors.push(...sanitizeMessages(errors, "errors", details, name));
1328
+ if (warnings != null)
1329
+ response.warnings.push(...sanitizeMessages(warnings, "warnings", details, name));
1330
+ }
1468
1331
  } catch (e) {
1469
- let flags = [];
1470
- try {
1471
- pushLogFlags(flags, options, {}, isTTY, transformLogLevelDefault);
1472
- } catch (e2) {
1332
+ response.errors.push(extractErrorMessageV8(e, streamIn, details, note && note(), name));
1333
+ }
1334
+ })));
1335
+ sendResponse(id, response);
1336
+ });
1337
+ requestCallbacks["on-resolve"] = (id, request) => __async(void 0, null, function* () {
1338
+ let response = {}, name = "", callback, note;
1339
+ for (let id2 of request.ids) {
1340
+ try {
1341
+ ({ name, callback, note } = onResolveCallbacks[id2]);
1342
+ let result = yield callback({
1343
+ path: request.path,
1344
+ importer: request.importer,
1345
+ namespace: request.namespace,
1346
+ resolveDir: request.resolveDir,
1347
+ kind: request.kind,
1348
+ pluginData: details.load(request.pluginData)
1349
+ });
1350
+ if (result != null) {
1351
+ if (typeof result !== "object")
1352
+ throw new Error(`Expected onResolve() callback in plugin ${JSON.stringify(name)} to return an object`);
1353
+ let keys = {};
1354
+ let pluginName = getFlag(result, keys, "pluginName", mustBeString);
1355
+ let path = getFlag(result, keys, "path", mustBeString);
1356
+ let namespace = getFlag(result, keys, "namespace", mustBeString);
1357
+ let suffix = getFlag(result, keys, "suffix", mustBeString);
1358
+ let external = getFlag(result, keys, "external", mustBeBoolean);
1359
+ let sideEffects = getFlag(result, keys, "sideEffects", mustBeBoolean);
1360
+ let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
1361
+ let errors = getFlag(result, keys, "errors", mustBeArray);
1362
+ let warnings = getFlag(result, keys, "warnings", mustBeArray);
1363
+ let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
1364
+ let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
1365
+ checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${JSON.stringify(name)}`);
1366
+ response.id = id2;
1367
+ if (pluginName != null)
1368
+ response.pluginName = pluginName;
1369
+ if (path != null)
1370
+ response.path = path;
1371
+ if (namespace != null)
1372
+ response.namespace = namespace;
1373
+ if (suffix != null)
1374
+ response.suffix = suffix;
1375
+ if (external != null)
1376
+ response.external = external;
1377
+ if (sideEffects != null)
1378
+ response.sideEffects = sideEffects;
1379
+ if (pluginData != null)
1380
+ response.pluginData = details.store(pluginData);
1381
+ if (errors != null)
1382
+ response.errors = sanitizeMessages(errors, "errors", details, name);
1383
+ if (warnings != null)
1384
+ response.warnings = sanitizeMessages(warnings, "warnings", details, name);
1385
+ if (watchFiles != null)
1386
+ response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
1387
+ if (watchDirs != null)
1388
+ response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
1389
+ break;
1473
1390
  }
1474
- const error = extractErrorMessageV8(e, streamIn, details, void 0, "");
1475
- sendRequest(refs, { command: "error", flags, error }, () => {
1476
- error.detail = details.load(error.detail);
1477
- callback(failureErrorWithLog("Transform failed", [error], []), null);
1391
+ } catch (e) {
1392
+ response = { id: id2, errors: [extractErrorMessageV8(e, streamIn, details, note && note(), name)] };
1393
+ break;
1394
+ }
1395
+ }
1396
+ sendResponse(id, response);
1397
+ });
1398
+ requestCallbacks["on-load"] = (id, request) => __async(void 0, null, function* () {
1399
+ let response = {}, name = "", callback, note;
1400
+ for (let id2 of request.ids) {
1401
+ try {
1402
+ ({ name, callback, note } = onLoadCallbacks[id2]);
1403
+ let result = yield callback({
1404
+ path: request.path,
1405
+ namespace: request.namespace,
1406
+ suffix: request.suffix,
1407
+ pluginData: details.load(request.pluginData)
1478
1408
  });
1409
+ if (result != null) {
1410
+ if (typeof result !== "object")
1411
+ throw new Error(`Expected onLoad() callback in plugin ${JSON.stringify(name)} to return an object`);
1412
+ let keys = {};
1413
+ let pluginName = getFlag(result, keys, "pluginName", mustBeString);
1414
+ let contents = getFlag(result, keys, "contents", mustBeStringOrUint8Array);
1415
+ let resolveDir = getFlag(result, keys, "resolveDir", mustBeString);
1416
+ let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
1417
+ let loader = getFlag(result, keys, "loader", mustBeString);
1418
+ let errors = getFlag(result, keys, "errors", mustBeArray);
1419
+ let warnings = getFlag(result, keys, "warnings", mustBeArray);
1420
+ let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
1421
+ let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
1422
+ checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${JSON.stringify(name)}`);
1423
+ response.id = id2;
1424
+ if (pluginName != null)
1425
+ response.pluginName = pluginName;
1426
+ if (contents instanceof Uint8Array)
1427
+ response.contents = contents;
1428
+ else if (contents != null)
1429
+ response.contents = encodeUTF8(contents);
1430
+ if (resolveDir != null)
1431
+ response.resolveDir = resolveDir;
1432
+ if (pluginData != null)
1433
+ response.pluginData = details.store(pluginData);
1434
+ if (loader != null)
1435
+ response.loader = loader;
1436
+ if (errors != null)
1437
+ response.errors = sanitizeMessages(errors, "errors", details, name);
1438
+ if (warnings != null)
1439
+ response.warnings = sanitizeMessages(warnings, "warnings", details, name);
1440
+ if (watchFiles != null)
1441
+ response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
1442
+ if (watchDirs != null)
1443
+ response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
1444
+ break;
1445
+ }
1446
+ } catch (e) {
1447
+ response = { id: id2, errors: [extractErrorMessageV8(e, streamIn, details, note && note(), name)] };
1448
+ break;
1479
1449
  }
1480
- };
1481
- if ((typeof input === "string" || input instanceof Uint8Array) && input.length > 1024 * 1024) {
1482
- let next = start;
1483
- start = () => fs.writeFile(input, next);
1484
1450
  }
1485
- start(null);
1486
- };
1487
- let formatMessages2 = ({ callName, refs, messages, options, callback }) => {
1488
- let result = sanitizeMessages(messages, "messages", null, "");
1489
- if (!options)
1490
- throw new Error(`Missing second argument in ${callName}() call`);
1491
- let keys = {};
1492
- let kind = getFlag(options, keys, "kind", mustBeString);
1493
- let color = getFlag(options, keys, "color", mustBeBoolean);
1494
- let terminalWidth = getFlag(options, keys, "terminalWidth", mustBeInteger);
1495
- checkForInvalidFlags(options, keys, `in ${callName}() call`);
1496
- if (kind === void 0)
1497
- throw new Error(`Missing "kind" in ${callName}() call`);
1498
- if (kind !== "error" && kind !== "warning")
1499
- throw new Error(`Expected "kind" to be "error" or "warning" in ${callName}() call`);
1500
- let request = {
1501
- command: "format-msgs",
1502
- messages: result,
1503
- isWarning: kind === "warning"
1504
- };
1505
- if (color !== void 0)
1506
- request.color = color;
1507
- if (terminalWidth !== void 0)
1508
- request.terminalWidth = terminalWidth;
1509
- sendRequest(refs, request, (error, response) => {
1510
- if (error)
1511
- return callback(new Error(error), null);
1512
- callback(null, response.messages);
1513
- });
1514
- };
1515
- let analyzeMetafile2 = ({ callName, refs, metafile, options, callback }) => {
1516
- if (options === void 0)
1517
- options = {};
1518
- let keys = {};
1519
- let color = getFlag(options, keys, "color", mustBeBoolean);
1520
- let verbose = getFlag(options, keys, "verbose", mustBeBoolean);
1521
- checkForInvalidFlags(options, keys, `in ${callName}() call`);
1522
- let request = {
1523
- command: "analyze-metafile",
1524
- metafile
1451
+ sendResponse(id, response);
1452
+ });
1453
+ let runOnEndCallbacks = (result, logPluginError, done) => done();
1454
+ if (onEndCallbacks.length > 0) {
1455
+ runOnEndCallbacks = (result, logPluginError, done) => {
1456
+ (() => __async(void 0, null, function* () {
1457
+ for (const { name, callback, note } of onEndCallbacks) {
1458
+ try {
1459
+ yield callback(result);
1460
+ } catch (e) {
1461
+ result.errors.push(yield new Promise((resolve) => logPluginError(e, name, note && note(), resolve)));
1462
+ }
1463
+ }
1464
+ }))().then(done);
1525
1465
  };
1526
- if (color !== void 0)
1527
- request.color = color;
1528
- if (verbose !== void 0)
1529
- request.verbose = verbose;
1530
- sendRequest(refs, request, (error, response) => {
1531
- if (error)
1532
- return callback(new Error(error), null);
1533
- callback(null, response.result);
1534
- });
1535
- };
1466
+ }
1467
+ isSetupDone = true;
1536
1468
  return {
1537
- readFromStdout,
1538
- afterClose,
1539
- service: {
1540
- buildOrServe,
1541
- transform: transform2,
1542
- formatMessages: formatMessages2,
1543
- analyzeMetafile: analyzeMetafile2
1544
- }
1469
+ ok: true,
1470
+ requestPlugins,
1471
+ runOnEndCallbacks
1545
1472
  };
1546
- }
1473
+ });
1547
1474
  function createObjectStash() {
1548
1475
  const map = /* @__PURE__ */ new Map();
1549
1476
  let nextID = 0;
@@ -1748,7 +1675,7 @@ function convertOutputFiles({ path, contents }) {
1748
1675
  }
1749
1676
 
1750
1677
  // lib/npm/browser.ts
1751
- var version = "0.15.4";
1678
+ var version = "0.15.8";
1752
1679
  var build = (options) => ensureServiceIsRunning().build(options);
1753
1680
  var serve = () => {
1754
1681
  throw new Error(`The "serve" API only works in node`);
@@ -1804,7 +1731,7 @@ var startRunningService = (wasmURL, wasmModule, useWorker) => __async(void 0, nu
1804
1731
  }
1805
1732
  let worker;
1806
1733
  if (useWorker) {
1807
- let blob = new Blob([`onmessage=${'((postMessage) => {\n // Copyright 2018 The Go Authors. All rights reserved.\n // Use of this source code is governed by a BSD-style\n // license that can be found in the LICENSE file.\n var __async = (__this, __arguments, generator) => {\n return new Promise((resolve, reject) => {\n var fulfilled = (value) => {\n try {\n step(generator.next(value));\n } catch (e) {\n reject(e);\n }\n };\n var rejected = (value) => {\n try {\n step(generator.throw(value));\n } catch (e) {\n reject(e);\n }\n };\n var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);\n step((generator = generator.apply(__this, __arguments)).next());\n });\n };\n let onmessage;\n let globalThis = {};\n for (let o = self; o; o = Object.getPrototypeOf(o))\n for (let k of Object.getOwnPropertyNames(o))\n if (!(k in globalThis))\n Object.defineProperty(globalThis, k, { get: () => self[k] });\n "use strict";\n (() => {\n const enosys = () => {\n const err = new Error("not implemented");\n err.code = "ENOSYS";\n return err;\n };\n if (!globalThis.fs) {\n let outputBuf = "";\n globalThis.fs = {\n constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },\n writeSync(fd, buf) {\n outputBuf += decoder.decode(buf);\n const nl = outputBuf.lastIndexOf("\\n");\n if (nl != -1) {\n console.log(outputBuf.substr(0, nl));\n outputBuf = outputBuf.substr(nl + 1);\n }\n return buf.length;\n },\n write(fd, buf, offset, length, position, callback) {\n if (offset !== 0 || length !== buf.length || position !== null) {\n callback(enosys());\n return;\n }\n const n = this.writeSync(fd, buf);\n callback(null, n);\n },\n chmod(path, mode, callback) {\n callback(enosys());\n },\n chown(path, uid, gid, callback) {\n callback(enosys());\n },\n close(fd, callback) {\n callback(enosys());\n },\n fchmod(fd, mode, callback) {\n callback(enosys());\n },\n fchown(fd, uid, gid, callback) {\n callback(enosys());\n },\n fstat(fd, callback) {\n callback(enosys());\n },\n fsync(fd, callback) {\n callback(null);\n },\n ftruncate(fd, length, callback) {\n callback(enosys());\n },\n lchown(path, uid, gid, callback) {\n callback(enosys());\n },\n link(path, link, callback) {\n callback(enosys());\n },\n lstat(path, callback) {\n callback(enosys());\n },\n mkdir(path, perm, callback) {\n callback(enosys());\n },\n open(path, flags, mode, callback) {\n callback(enosys());\n },\n read(fd, buffer, offset, length, position, callback) {\n callback(enosys());\n },\n readdir(path, callback) {\n callback(enosys());\n },\n readlink(path, callback) {\n callback(enosys());\n },\n rename(from, to, callback) {\n callback(enosys());\n },\n rmdir(path, callback) {\n callback(enosys());\n },\n stat(path, callback) {\n callback(enosys());\n },\n symlink(path, link, callback) {\n callback(enosys());\n },\n truncate(path, length, callback) {\n callback(enosys());\n },\n unlink(path, callback) {\n callback(enosys());\n },\n utimes(path, atime, mtime, callback) {\n callback(enosys());\n }\n };\n }\n if (!globalThis.process) {\n globalThis.process = {\n getuid() {\n return -1;\n },\n getgid() {\n return -1;\n },\n geteuid() {\n return -1;\n },\n getegid() {\n return -1;\n },\n getgroups() {\n throw enosys();\n },\n pid: -1,\n ppid: -1,\n umask() {\n throw enosys();\n },\n cwd() {\n throw enosys();\n },\n chdir() {\n throw enosys();\n }\n };\n }\n if (!globalThis.crypto) {\n throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");\n }\n if (!globalThis.performance) {\n throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");\n }\n if (!globalThis.TextEncoder) {\n throw new Error("globalThis.TextEncoder is not available, polyfill required");\n }\n if (!globalThis.TextDecoder) {\n throw new Error("globalThis.TextDecoder is not available, polyfill required");\n }\n const encoder = new TextEncoder("utf-8");\n const decoder = new TextDecoder("utf-8");\n globalThis.Go = class {\n constructor() {\n this.argv = ["js"];\n this.env = {};\n this.exit = (code) => {\n if (code !== 0) {\n console.warn("exit code:", code);\n }\n };\n this._exitPromise = new Promise((resolve) => {\n this._resolveExitPromise = resolve;\n });\n this._pendingEvent = null;\n this._scheduledTimeouts = /* @__PURE__ */ new Map();\n this._nextCallbackTimeoutID = 1;\n const setInt64 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);\n };\n const getInt64 = (addr) => {\n const low = this.mem.getUint32(addr + 0, true);\n const high = this.mem.getInt32(addr + 4, true);\n return low + high * 4294967296;\n };\n const loadValue = (addr) => {\n const f = this.mem.getFloat64(addr, true);\n if (f === 0) {\n return void 0;\n }\n if (!isNaN(f)) {\n return f;\n }\n const id = this.mem.getUint32(addr, true);\n return this._values[id];\n };\n const storeValue = (addr, v) => {\n const nanHead = 2146959360;\n if (typeof v === "number" && v !== 0) {\n if (isNaN(v)) {\n this.mem.setUint32(addr + 4, nanHead, true);\n this.mem.setUint32(addr, 0, true);\n return;\n }\n this.mem.setFloat64(addr, v, true);\n return;\n }\n if (v === void 0) {\n this.mem.setFloat64(addr, 0, true);\n return;\n }\n let id = this._ids.get(v);\n if (id === void 0) {\n id = this._idPool.pop();\n if (id === void 0) {\n id = this._values.length;\n }\n this._values[id] = v;\n this._goRefCounts[id] = 0;\n this._ids.set(v, id);\n }\n this._goRefCounts[id]++;\n let typeFlag = 0;\n switch (typeof v) {\n case "object":\n if (v !== null) {\n typeFlag = 1;\n }\n break;\n case "string":\n typeFlag = 2;\n break;\n case "symbol":\n typeFlag = 3;\n break;\n case "function":\n typeFlag = 4;\n break;\n }\n this.mem.setUint32(addr + 4, nanHead | typeFlag, true);\n this.mem.setUint32(addr, id, true);\n };\n const loadSlice = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return new Uint8Array(this._inst.exports.mem.buffer, array, len);\n };\n const loadSliceOfValues = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n const a = new Array(len);\n for (let i = 0; i < len; i++) {\n a[i] = loadValue(array + i * 8);\n }\n return a;\n };\n const loadString = (addr) => {\n const saddr = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));\n };\n const timeOrigin = Date.now() - performance.now();\n this.importObject = {\n go: {\n "runtime.wasmExit": (sp) => {\n sp >>>= 0;\n const code = this.mem.getInt32(sp + 8, true);\n this.exited = true;\n delete this._inst;\n delete this._values;\n delete this._goRefCounts;\n delete this._ids;\n delete this._idPool;\n this.exit(code);\n },\n "runtime.wasmWrite": (sp) => {\n sp >>>= 0;\n const fd = getInt64(sp + 8);\n const p = getInt64(sp + 16);\n const n = this.mem.getInt32(sp + 24, true);\n globalThis.fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));\n },\n "runtime.resetMemoryDataView": (sp) => {\n sp >>>= 0;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n },\n "runtime.nanotime1": (sp) => {\n sp >>>= 0;\n setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);\n },\n "runtime.walltime": (sp) => {\n sp >>>= 0;\n const msec = new Date().getTime();\n setInt64(sp + 8, msec / 1e3);\n this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);\n },\n "runtime.scheduleTimeoutEvent": (sp) => {\n sp >>>= 0;\n const id = this._nextCallbackTimeoutID;\n this._nextCallbackTimeoutID++;\n this._scheduledTimeouts.set(id, setTimeout(\n () => {\n this._resume();\n while (this._scheduledTimeouts.has(id)) {\n console.warn("scheduleTimeoutEvent: missed timeout event");\n this._resume();\n }\n },\n getInt64(sp + 8) + 1\n ));\n this.mem.setInt32(sp + 16, id, true);\n },\n "runtime.clearTimeoutEvent": (sp) => {\n sp >>>= 0;\n const id = this.mem.getInt32(sp + 8, true);\n clearTimeout(this._scheduledTimeouts.get(id));\n this._scheduledTimeouts.delete(id);\n },\n "runtime.getRandomData": (sp) => {\n sp >>>= 0;\n crypto.getRandomValues(loadSlice(sp + 8));\n },\n "syscall/js.finalizeRef": (sp) => {\n sp >>>= 0;\n const id = this.mem.getUint32(sp + 8, true);\n this._goRefCounts[id]--;\n if (this._goRefCounts[id] === 0) {\n const v = this._values[id];\n this._values[id] = null;\n this._ids.delete(v);\n this._idPool.push(id);\n }\n },\n "syscall/js.stringVal": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, loadString(sp + 8));\n },\n "syscall/js.valueGet": (sp) => {\n sp >>>= 0;\n const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 32, result);\n },\n "syscall/js.valueSet": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n },\n "syscall/js.valueDelete": (sp) => {\n sp >>>= 0;\n Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n },\n "syscall/js.valueIndex": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n },\n "syscall/js.valueSetIndex": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n },\n "syscall/js.valueCall": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const m = Reflect.get(v, loadString(sp + 16));\n const args = loadSliceOfValues(sp + 32);\n const result = Reflect.apply(m, v, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 56, result);\n this.mem.setUint8(sp + 64, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 56, err);\n this.mem.setUint8(sp + 64, 0);\n }\n },\n "syscall/js.valueInvoke": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.apply(v, void 0, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n "syscall/js.valueNew": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.construct(v, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n "syscall/js.valueLength": (sp) => {\n sp >>>= 0;\n setInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n },\n "syscall/js.valuePrepareString": (sp) => {\n sp >>>= 0;\n const str = encoder.encode(String(loadValue(sp + 8)));\n storeValue(sp + 16, str);\n setInt64(sp + 24, str.length);\n },\n "syscall/js.valueLoadString": (sp) => {\n sp >>>= 0;\n const str = loadValue(sp + 8);\n loadSlice(sp + 16).set(str);\n },\n "syscall/js.valueInstanceOf": (sp) => {\n sp >>>= 0;\n this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);\n },\n "syscall/js.copyBytesToGo": (sp) => {\n sp >>>= 0;\n const dst = loadSlice(sp + 8);\n const src = loadValue(sp + 32);\n if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "syscall/js.copyBytesToJS": (sp) => {\n sp >>>= 0;\n const dst = loadValue(sp + 8);\n const src = loadSlice(sp + 16);\n if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "debug": (value) => {\n console.log(value);\n }\n }\n };\n }\n run(instance) {\n return __async(this, null, function* () {\n if (!(instance instanceof WebAssembly.Instance)) {\n throw new Error("Go.run: WebAssembly.Instance expected");\n }\n this._inst = instance;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n this._values = [\n NaN,\n 0,\n null,\n true,\n false,\n globalThis,\n this\n ];\n this._goRefCounts = new Array(this._values.length).fill(Infinity);\n this._ids = /* @__PURE__ */ new Map([\n [0, 1],\n [null, 2],\n [true, 3],\n [false, 4],\n [globalThis, 5],\n [this, 6]\n ]);\n this._idPool = [];\n this.exited = false;\n let offset = 4096;\n const strPtr = (str) => {\n const ptr = offset;\n const bytes = encoder.encode(str + "\\0");\n new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);\n offset += bytes.length;\n if (offset % 8 !== 0) {\n offset += 8 - offset % 8;\n }\n return ptr;\n };\n const argc = this.argv.length;\n const argvPtrs = [];\n this.argv.forEach((arg) => {\n argvPtrs.push(strPtr(arg));\n });\n argvPtrs.push(0);\n const keys = Object.keys(this.env).sort();\n keys.forEach((key) => {\n argvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n });\n argvPtrs.push(0);\n const argv = offset;\n argvPtrs.forEach((ptr) => {\n this.mem.setUint32(offset, ptr, true);\n this.mem.setUint32(offset + 4, 0, true);\n offset += 8;\n });\n const wasmMinDataAddr = 4096 + 8192;\n if (offset >= wasmMinDataAddr) {\n throw new Error("total length of command line and environment variables exceeds limit");\n }\n this._inst.exports.run(argc, argv);\n if (this.exited) {\n this._resolveExitPromise();\n }\n yield this._exitPromise;\n });\n }\n _resume() {\n if (this.exited) {\n throw new Error("Go program has already exited");\n }\n this._inst.exports.resume();\n if (this.exited) {\n this._resolveExitPromise();\n }\n }\n _makeFuncWrapper(id) {\n const go = this;\n return function() {\n const event = { id, this: this, args: arguments };\n go._pendingEvent = event;\n go._resume();\n return event.result;\n };\n }\n };\n })();\n onmessage = ({ data: wasm }) => {\n let decoder = new TextDecoder();\n let fs = globalThis.fs;\n let stderr = "";\n fs.writeSync = (fd, buffer) => {\n if (fd === 1) {\n postMessage(buffer);\n } else if (fd === 2) {\n stderr += decoder.decode(buffer);\n let parts = stderr.split("\\n");\n if (parts.length > 1)\n console.log(parts.slice(0, -1).join("\\n"));\n stderr = parts[parts.length - 1];\n } else {\n throw new Error("Bad write");\n }\n return buffer.length;\n };\n let stdin = [];\n let resumeStdin;\n let stdinPos = 0;\n onmessage = ({ data }) => {\n if (data.length > 0) {\n stdin.push(data);\n if (resumeStdin)\n resumeStdin();\n }\n };\n fs.read = (fd, buffer, offset, length, position, callback) => {\n if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) {\n throw new Error("Bad read");\n }\n if (stdin.length === 0) {\n resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback);\n return;\n }\n let first = stdin[0];\n let count = Math.max(0, Math.min(length, first.length - stdinPos));\n buffer.set(first.subarray(stdinPos, stdinPos + count), offset);\n stdinPos += count;\n if (stdinPos === first.length) {\n stdin.shift();\n stdinPos = 0;\n }\n callback(null, count);\n };\n let go = new globalThis.Go();\n go.argv = ["", `--service=${"0.15.4"}`];\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" });
1734
+ let blob = new Blob([`onmessage=${'((postMessage) => {\n // Copyright 2018 The Go Authors. All rights reserved.\n // Use of this source code is governed by a BSD-style\n // license that can be found in the LICENSE file.\n var __async = (__this, __arguments, generator) => {\n return new Promise((resolve, reject) => {\n var fulfilled = (value) => {\n try {\n step(generator.next(value));\n } catch (e) {\n reject(e);\n }\n };\n var rejected = (value) => {\n try {\n step(generator.throw(value));\n } catch (e) {\n reject(e);\n }\n };\n var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);\n step((generator = generator.apply(__this, __arguments)).next());\n });\n };\n let onmessage;\n let globalThis = {};\n for (let o = self; o; o = Object.getPrototypeOf(o))\n for (let k of Object.getOwnPropertyNames(o))\n if (!(k in globalThis))\n Object.defineProperty(globalThis, k, { get: () => self[k] });\n "use strict";\n (() => {\n const enosys = () => {\n const err = new Error("not implemented");\n err.code = "ENOSYS";\n return err;\n };\n if (!globalThis.fs) {\n let outputBuf = "";\n globalThis.fs = {\n constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },\n writeSync(fd, buf) {\n outputBuf += decoder.decode(buf);\n const nl = outputBuf.lastIndexOf("\\n");\n if (nl != -1) {\n console.log(outputBuf.substr(0, nl));\n outputBuf = outputBuf.substr(nl + 1);\n }\n return buf.length;\n },\n write(fd, buf, offset, length, position, callback) {\n if (offset !== 0 || length !== buf.length || position !== null) {\n callback(enosys());\n return;\n }\n const n = this.writeSync(fd, buf);\n callback(null, n);\n },\n chmod(path, mode, callback) {\n callback(enosys());\n },\n chown(path, uid, gid, callback) {\n callback(enosys());\n },\n close(fd, callback) {\n callback(enosys());\n },\n fchmod(fd, mode, callback) {\n callback(enosys());\n },\n fchown(fd, uid, gid, callback) {\n callback(enosys());\n },\n fstat(fd, callback) {\n callback(enosys());\n },\n fsync(fd, callback) {\n callback(null);\n },\n ftruncate(fd, length, callback) {\n callback(enosys());\n },\n lchown(path, uid, gid, callback) {\n callback(enosys());\n },\n link(path, link, callback) {\n callback(enosys());\n },\n lstat(path, callback) {\n callback(enosys());\n },\n mkdir(path, perm, callback) {\n callback(enosys());\n },\n open(path, flags, mode, callback) {\n callback(enosys());\n },\n read(fd, buffer, offset, length, position, callback) {\n callback(enosys());\n },\n readdir(path, callback) {\n callback(enosys());\n },\n readlink(path, callback) {\n callback(enosys());\n },\n rename(from, to, callback) {\n callback(enosys());\n },\n rmdir(path, callback) {\n callback(enosys());\n },\n stat(path, callback) {\n callback(enosys());\n },\n symlink(path, link, callback) {\n callback(enosys());\n },\n truncate(path, length, callback) {\n callback(enosys());\n },\n unlink(path, callback) {\n callback(enosys());\n },\n utimes(path, atime, mtime, callback) {\n callback(enosys());\n }\n };\n }\n if (!globalThis.process) {\n globalThis.process = {\n getuid() {\n return -1;\n },\n getgid() {\n return -1;\n },\n geteuid() {\n return -1;\n },\n getegid() {\n return -1;\n },\n getgroups() {\n throw enosys();\n },\n pid: -1,\n ppid: -1,\n umask() {\n throw enosys();\n },\n cwd() {\n throw enosys();\n },\n chdir() {\n throw enosys();\n }\n };\n }\n if (!globalThis.crypto) {\n throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");\n }\n if (!globalThis.performance) {\n throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");\n }\n if (!globalThis.TextEncoder) {\n throw new Error("globalThis.TextEncoder is not available, polyfill required");\n }\n if (!globalThis.TextDecoder) {\n throw new Error("globalThis.TextDecoder is not available, polyfill required");\n }\n const encoder = new TextEncoder("utf-8");\n const decoder = new TextDecoder("utf-8");\n globalThis.Go = class {\n constructor() {\n this.argv = ["js"];\n this.env = {};\n this.exit = (code) => {\n if (code !== 0) {\n console.warn("exit code:", code);\n }\n };\n this._exitPromise = new Promise((resolve) => {\n this._resolveExitPromise = resolve;\n });\n this._pendingEvent = null;\n this._scheduledTimeouts = /* @__PURE__ */ new Map();\n this._nextCallbackTimeoutID = 1;\n const setInt64 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);\n };\n const getInt64 = (addr) => {\n const low = this.mem.getUint32(addr + 0, true);\n const high = this.mem.getInt32(addr + 4, true);\n return low + high * 4294967296;\n };\n const loadValue = (addr) => {\n const f = this.mem.getFloat64(addr, true);\n if (f === 0) {\n return void 0;\n }\n if (!isNaN(f)) {\n return f;\n }\n const id = this.mem.getUint32(addr, true);\n return this._values[id];\n };\n const storeValue = (addr, v) => {\n const nanHead = 2146959360;\n if (typeof v === "number" && v !== 0) {\n if (isNaN(v)) {\n this.mem.setUint32(addr + 4, nanHead, true);\n this.mem.setUint32(addr, 0, true);\n return;\n }\n this.mem.setFloat64(addr, v, true);\n return;\n }\n if (v === void 0) {\n this.mem.setFloat64(addr, 0, true);\n return;\n }\n let id = this._ids.get(v);\n if (id === void 0) {\n id = this._idPool.pop();\n if (id === void 0) {\n id = this._values.length;\n }\n this._values[id] = v;\n this._goRefCounts[id] = 0;\n this._ids.set(v, id);\n }\n this._goRefCounts[id]++;\n let typeFlag = 0;\n switch (typeof v) {\n case "object":\n if (v !== null) {\n typeFlag = 1;\n }\n break;\n case "string":\n typeFlag = 2;\n break;\n case "symbol":\n typeFlag = 3;\n break;\n case "function":\n typeFlag = 4;\n break;\n }\n this.mem.setUint32(addr + 4, nanHead | typeFlag, true);\n this.mem.setUint32(addr, id, true);\n };\n const loadSlice = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return new Uint8Array(this._inst.exports.mem.buffer, array, len);\n };\n const loadSliceOfValues = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n const a = new Array(len);\n for (let i = 0; i < len; i++) {\n a[i] = loadValue(array + i * 8);\n }\n return a;\n };\n const loadString = (addr) => {\n const saddr = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));\n };\n const timeOrigin = Date.now() - performance.now();\n this.importObject = {\n go: {\n "runtime.wasmExit": (sp) => {\n sp >>>= 0;\n const code = this.mem.getInt32(sp + 8, true);\n this.exited = true;\n delete this._inst;\n delete this._values;\n delete this._goRefCounts;\n delete this._ids;\n delete this._idPool;\n this.exit(code);\n },\n "runtime.wasmWrite": (sp) => {\n sp >>>= 0;\n const fd = getInt64(sp + 8);\n const p = getInt64(sp + 16);\n const n = this.mem.getInt32(sp + 24, true);\n globalThis.fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));\n },\n "runtime.resetMemoryDataView": (sp) => {\n sp >>>= 0;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n },\n "runtime.nanotime1": (sp) => {\n sp >>>= 0;\n setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);\n },\n "runtime.walltime": (sp) => {\n sp >>>= 0;\n const msec = new Date().getTime();\n setInt64(sp + 8, msec / 1e3);\n this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);\n },\n "runtime.scheduleTimeoutEvent": (sp) => {\n sp >>>= 0;\n const id = this._nextCallbackTimeoutID;\n this._nextCallbackTimeoutID++;\n this._scheduledTimeouts.set(id, setTimeout(\n () => {\n this._resume();\n while (this._scheduledTimeouts.has(id)) {\n console.warn("scheduleTimeoutEvent: missed timeout event");\n this._resume();\n }\n },\n getInt64(sp + 8) + 1\n ));\n this.mem.setInt32(sp + 16, id, true);\n },\n "runtime.clearTimeoutEvent": (sp) => {\n sp >>>= 0;\n const id = this.mem.getInt32(sp + 8, true);\n clearTimeout(this._scheduledTimeouts.get(id));\n this._scheduledTimeouts.delete(id);\n },\n "runtime.getRandomData": (sp) => {\n sp >>>= 0;\n crypto.getRandomValues(loadSlice(sp + 8));\n },\n "syscall/js.finalizeRef": (sp) => {\n sp >>>= 0;\n const id = this.mem.getUint32(sp + 8, true);\n this._goRefCounts[id]--;\n if (this._goRefCounts[id] === 0) {\n const v = this._values[id];\n this._values[id] = null;\n this._ids.delete(v);\n this._idPool.push(id);\n }\n },\n "syscall/js.stringVal": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, loadString(sp + 8));\n },\n "syscall/js.valueGet": (sp) => {\n sp >>>= 0;\n const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 32, result);\n },\n "syscall/js.valueSet": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n },\n "syscall/js.valueDelete": (sp) => {\n sp >>>= 0;\n Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n },\n "syscall/js.valueIndex": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n },\n "syscall/js.valueSetIndex": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n },\n "syscall/js.valueCall": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const m = Reflect.get(v, loadString(sp + 16));\n const args = loadSliceOfValues(sp + 32);\n const result = Reflect.apply(m, v, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 56, result);\n this.mem.setUint8(sp + 64, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 56, err);\n this.mem.setUint8(sp + 64, 0);\n }\n },\n "syscall/js.valueInvoke": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.apply(v, void 0, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n "syscall/js.valueNew": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.construct(v, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n "syscall/js.valueLength": (sp) => {\n sp >>>= 0;\n setInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n },\n "syscall/js.valuePrepareString": (sp) => {\n sp >>>= 0;\n const str = encoder.encode(String(loadValue(sp + 8)));\n storeValue(sp + 16, str);\n setInt64(sp + 24, str.length);\n },\n "syscall/js.valueLoadString": (sp) => {\n sp >>>= 0;\n const str = loadValue(sp + 8);\n loadSlice(sp + 16).set(str);\n },\n "syscall/js.valueInstanceOf": (sp) => {\n sp >>>= 0;\n this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);\n },\n "syscall/js.copyBytesToGo": (sp) => {\n sp >>>= 0;\n const dst = loadSlice(sp + 8);\n const src = loadValue(sp + 32);\n if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "syscall/js.copyBytesToJS": (sp) => {\n sp >>>= 0;\n const dst = loadValue(sp + 8);\n const src = loadSlice(sp + 16);\n if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "debug": (value) => {\n console.log(value);\n }\n }\n };\n }\n run(instance) {\n return __async(this, null, function* () {\n if (!(instance instanceof WebAssembly.Instance)) {\n throw new Error("Go.run: WebAssembly.Instance expected");\n }\n this._inst = instance;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n this._values = [\n NaN,\n 0,\n null,\n true,\n false,\n globalThis,\n this\n ];\n this._goRefCounts = new Array(this._values.length).fill(Infinity);\n this._ids = /* @__PURE__ */ new Map([\n [0, 1],\n [null, 2],\n [true, 3],\n [false, 4],\n [globalThis, 5],\n [this, 6]\n ]);\n this._idPool = [];\n this.exited = false;\n let offset = 4096;\n const strPtr = (str) => {\n const ptr = offset;\n const bytes = encoder.encode(str + "\\0");\n new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);\n offset += bytes.length;\n if (offset % 8 !== 0) {\n offset += 8 - offset % 8;\n }\n return ptr;\n };\n const argc = this.argv.length;\n const argvPtrs = [];\n this.argv.forEach((arg) => {\n argvPtrs.push(strPtr(arg));\n });\n argvPtrs.push(0);\n const keys = Object.keys(this.env).sort();\n keys.forEach((key) => {\n argvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n });\n argvPtrs.push(0);\n const argv = offset;\n argvPtrs.forEach((ptr) => {\n this.mem.setUint32(offset, ptr, true);\n this.mem.setUint32(offset + 4, 0, true);\n offset += 8;\n });\n const wasmMinDataAddr = 4096 + 8192;\n if (offset >= wasmMinDataAddr) {\n throw new Error("total length of command line and environment variables exceeds limit");\n }\n this._inst.exports.run(argc, argv);\n if (this.exited) {\n this._resolveExitPromise();\n }\n yield this._exitPromise;\n });\n }\n _resume() {\n if (this.exited) {\n throw new Error("Go program has already exited");\n }\n this._inst.exports.resume();\n if (this.exited) {\n this._resolveExitPromise();\n }\n }\n _makeFuncWrapper(id) {\n const go = this;\n return function() {\n const event = { id, this: this, args: arguments };\n go._pendingEvent = event;\n go._resume();\n return event.result;\n };\n }\n };\n })();\n onmessage = ({ data: wasm }) => {\n let decoder = new TextDecoder();\n let fs = globalThis.fs;\n let stderr = "";\n fs.writeSync = (fd, buffer) => {\n if (fd === 1) {\n postMessage(buffer);\n } else if (fd === 2) {\n stderr += decoder.decode(buffer);\n let parts = stderr.split("\\n");\n if (parts.length > 1)\n console.log(parts.slice(0, -1).join("\\n"));\n stderr = parts[parts.length - 1];\n } else {\n throw new Error("Bad write");\n }\n return buffer.length;\n };\n let stdin = [];\n let resumeStdin;\n let stdinPos = 0;\n onmessage = ({ data }) => {\n if (data.length > 0) {\n stdin.push(data);\n if (resumeStdin)\n resumeStdin();\n }\n };\n fs.read = (fd, buffer, offset, length, position, callback) => {\n if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) {\n throw new Error("Bad read");\n }\n if (stdin.length === 0) {\n resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback);\n return;\n }\n let first = stdin[0];\n let count = Math.max(0, Math.min(length, first.length - stdinPos));\n buffer.set(first.subarray(stdinPos, stdinPos + count), offset);\n stdinPos += count;\n if (stdinPos === first.length) {\n stdin.shift();\n stdinPos = 0;\n }\n callback(null, count);\n };\n let go = new globalThis.Go();\n go.argv = ["", `--service=${"0.15.8"}`];\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" });
1808
1735
  worker = new Worker(URL.createObjectURL(blob));
1809
1736
  } else {
1810
1737
  let onmessage = ((postMessage) => {
@@ -2408,7 +2335,7 @@ var startRunningService = (wasmURL, wasmModule, useWorker) => __async(void 0, nu
2408
2335
  callback(null, count);
2409
2336
  };
2410
2337
  let go = new globalThis.Go();
2411
- go.argv = ["", `--service=${"0.15.4"}`];
2338
+ go.argv = ["", `--service=${"0.15.8"}`];
2412
2339
  if (wasm instanceof WebAssembly.Module) {
2413
2340
  WebAssembly.instantiate(wasm, go.importObject).then((instance) => go.run(instance));
2414
2341
  } else {