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