isomorfeus-asset-manager 0.16.2 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +268 -243
- data/node_modules/esbuild-wasm/esm/browser.js +302 -229
- data/node_modules/esbuild-wasm/esm/browser.min.js +10 -10
- data/node_modules/esbuild-wasm/lib/browser.d.ts +268 -243
- data/node_modules/esbuild-wasm/lib/browser.js +301 -228
- data/node_modules/esbuild-wasm/lib/browser.min.js +11 -11
- data/node_modules/esbuild-wasm/lib/main.d.ts +268 -243
- data/node_modules/esbuild-wasm/lib/main.js +316 -285
- data/node_modules/esbuild-wasm/package.json +1 -1
- data/node_modules/esbuild-wasm/wasm_exec.js +2 -2
- data/package.json +1 -1
- metadata +28 -25
@@ -11,11 +11,11 @@ __export(browser_exports, {
|
|
11
11
|
analyzeMetafileSync: () => analyzeMetafileSync,
|
12
12
|
build: () => build,
|
13
13
|
buildSync: () => buildSync,
|
14
|
+
context: () => context,
|
14
15
|
default: () => browser_default,
|
15
16
|
formatMessages: () => formatMessages,
|
16
17
|
formatMessagesSync: () => formatMessagesSync,
|
17
18
|
initialize: () => initialize,
|
18
|
-
serve: () => serve,
|
19
19
|
transform: () => transform,
|
20
20
|
transformSync: () => transformSync,
|
21
21
|
version: () => version
|
@@ -201,15 +201,14 @@ function validateTarget(target) {
|
|
201
201
|
}
|
202
202
|
var canBeAnything = () => null;
|
203
203
|
var mustBeBoolean = (value) => typeof value === "boolean" ? null : "a boolean";
|
204
|
-
var mustBeBooleanOrObject = (value) => typeof value === "boolean" || typeof value === "object" && !Array.isArray(value) ? null : "a boolean or an object";
|
205
204
|
var mustBeString = (value) => typeof value === "string" ? null : "a string";
|
206
205
|
var mustBeRegExp = (value) => value instanceof RegExp ? null : "a RegExp object";
|
207
206
|
var mustBeInteger = (value) => typeof value === "number" && value === (value | 0) ? null : "an integer";
|
208
207
|
var mustBeFunction = (value) => typeof value === "function" ? null : "a function";
|
209
208
|
var mustBeArray = (value) => Array.isArray(value) ? null : "an array";
|
210
209
|
var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object";
|
210
|
+
var mustBeEntryPoints = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
|
211
211
|
var mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module";
|
212
|
-
var mustBeArrayOrRecord = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
|
213
212
|
var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null";
|
214
213
|
var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean";
|
215
214
|
var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object";
|
@@ -397,12 +396,10 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
|
|
397
396
|
let keys = /* @__PURE__ */ Object.create(null);
|
398
397
|
let stdinContents = null;
|
399
398
|
let stdinResolveDir = null;
|
400
|
-
let watchMode = null;
|
401
399
|
pushLogFlags(flags, options, keys, isTTY, logLevelDefault);
|
402
400
|
pushCommonFlags(flags, options, keys);
|
403
401
|
let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean);
|
404
402
|
let bundle = getFlag(options, keys, "bundle", mustBeBoolean);
|
405
|
-
let watch = getFlag(options, keys, "watch", mustBeBooleanOrObject);
|
406
403
|
let splitting = getFlag(options, keys, "splitting", mustBeBoolean);
|
407
404
|
let preserveSymlinks = getFlag(options, keys, "preserveSymlinks", mustBeBoolean);
|
408
405
|
let metafile = getFlag(options, keys, "metafile", mustBeBoolean);
|
@@ -426,12 +423,11 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
|
|
426
423
|
let inject = getFlag(options, keys, "inject", mustBeArray);
|
427
424
|
let banner = getFlag(options, keys, "banner", mustBeObject);
|
428
425
|
let footer = getFlag(options, keys, "footer", mustBeObject);
|
429
|
-
let entryPoints = getFlag(options, keys, "entryPoints",
|
426
|
+
let entryPoints = getFlag(options, keys, "entryPoints", mustBeEntryPoints);
|
430
427
|
let absWorkingDir = getFlag(options, keys, "absWorkingDir", mustBeString);
|
431
428
|
let stdin = getFlag(options, keys, "stdin", mustBeObject);
|
432
429
|
let write = (_a = getFlag(options, keys, "write", mustBeBoolean)) != null ? _a : writeDefault;
|
433
430
|
let allowOverwrite = getFlag(options, keys, "allowOverwrite", mustBeBoolean);
|
434
|
-
let incremental = getFlag(options, keys, "incremental", mustBeBoolean) === true;
|
435
431
|
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
436
432
|
keys.plugins = true;
|
437
433
|
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
@@ -441,17 +437,6 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
|
|
441
437
|
flags.push("--bundle");
|
442
438
|
if (allowOverwrite)
|
443
439
|
flags.push("--allow-overwrite");
|
444
|
-
if (watch) {
|
445
|
-
flags.push("--watch");
|
446
|
-
if (typeof watch === "boolean") {
|
447
|
-
watchMode = {};
|
448
|
-
} else {
|
449
|
-
let watchKeys = /* @__PURE__ */ Object.create(null);
|
450
|
-
let onRebuild = getFlag(watch, watchKeys, "onRebuild", mustBeFunction);
|
451
|
-
checkForInvalidFlags(watch, watchKeys, `on "watch" in ${callName}() call`);
|
452
|
-
watchMode = { onRebuild };
|
453
|
-
}
|
454
|
-
}
|
455
440
|
if (splitting)
|
456
441
|
flags.push("--splitting");
|
457
442
|
if (preserveSymlinks)
|
@@ -549,8 +534,21 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
|
|
549
534
|
}
|
550
535
|
if (entryPoints) {
|
551
536
|
if (Array.isArray(entryPoints)) {
|
552
|
-
for (let
|
553
|
-
|
537
|
+
for (let i = 0, n = entryPoints.length; i < n; i++) {
|
538
|
+
let entryPoint = entryPoints[i];
|
539
|
+
if (typeof entryPoint === "object" && entryPoint !== null) {
|
540
|
+
let entryPointKeys = /* @__PURE__ */ Object.create(null);
|
541
|
+
let input = getFlag(entryPoint, entryPointKeys, "in", mustBeString);
|
542
|
+
let output = getFlag(entryPoint, entryPointKeys, "out", mustBeString);
|
543
|
+
checkForInvalidFlags(entryPoint, entryPointKeys, "in entry point at index " + i);
|
544
|
+
if (input === void 0)
|
545
|
+
throw new Error('Missing property "in" for entry point at index ' + i);
|
546
|
+
if (output === void 0)
|
547
|
+
throw new Error('Missing property "out" for entry point at index ' + i);
|
548
|
+
entries.push([output, input]);
|
549
|
+
} else {
|
550
|
+
entries.push(["", validateStringValue(entryPoint, "entry point at index " + i)]);
|
551
|
+
}
|
554
552
|
}
|
555
553
|
} else {
|
556
554
|
for (let key in entryPoints) {
|
@@ -590,9 +588,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
|
|
590
588
|
stdinContents,
|
591
589
|
stdinResolveDir,
|
592
590
|
absWorkingDir,
|
593
|
-
incremental,
|
594
591
|
nodePaths,
|
595
|
-
watch: watchMode,
|
596
592
|
mangleCache: validateMangleCache(mangleCache)
|
597
593
|
};
|
598
594
|
}
|
@@ -715,8 +711,8 @@ function createChannel(streamIn) {
|
|
715
711
|
if (isFirstPacket) {
|
716
712
|
isFirstPacket = false;
|
717
713
|
let binaryVersion = String.fromCharCode(...bytes);
|
718
|
-
if (binaryVersion !== "0.
|
719
|
-
throw new Error(`Cannot start service: Host version "${"0.
|
714
|
+
if (binaryVersion !== "0.17.12") {
|
715
|
+
throw new Error(`Cannot start service: Host version "${"0.17.12"}" does not match binary version ${quote(binaryVersion)}`);
|
720
716
|
}
|
721
717
|
return;
|
722
718
|
}
|
@@ -732,7 +728,7 @@ function createChannel(streamIn) {
|
|
732
728
|
callback(null, packet.value);
|
733
729
|
}
|
734
730
|
};
|
735
|
-
let
|
731
|
+
let buildOrContext = ({ callName, refs, options, isTTY, defaultWD, callback }) => {
|
736
732
|
let refCount = 0;
|
737
733
|
const buildKey = nextBuildKey++;
|
738
734
|
const requestCallbacks = {};
|
@@ -753,7 +749,7 @@ function createChannel(streamIn) {
|
|
753
749
|
};
|
754
750
|
requestCallbacksByKey[buildKey] = requestCallbacks;
|
755
751
|
buildRefs.ref();
|
756
|
-
|
752
|
+
buildOrContextImpl(
|
757
753
|
callName,
|
758
754
|
buildKey,
|
759
755
|
sendRequest,
|
@@ -762,10 +758,8 @@ function createChannel(streamIn) {
|
|
762
758
|
streamIn,
|
763
759
|
requestCallbacks,
|
764
760
|
options,
|
765
|
-
serveOptions,
|
766
761
|
isTTY,
|
767
762
|
defaultWD,
|
768
|
-
closeData,
|
769
763
|
(err, res) => {
|
770
764
|
try {
|
771
765
|
callback(err, res);
|
@@ -801,7 +795,13 @@ function createChannel(streamIn) {
|
|
801
795
|
let outstanding = 1;
|
802
796
|
let next = () => {
|
803
797
|
if (--outstanding === 0) {
|
804
|
-
let result = {
|
798
|
+
let result = {
|
799
|
+
warnings,
|
800
|
+
code: response.code,
|
801
|
+
map: response.map,
|
802
|
+
mangleCache: void 0,
|
803
|
+
legalComments: void 0
|
804
|
+
};
|
805
805
|
if ("legalComments" in response)
|
806
806
|
result.legalComments = response == null ? void 0 : response.legalComments;
|
807
807
|
if (response.mangleCache)
|
@@ -907,30 +907,26 @@ function createChannel(streamIn) {
|
|
907
907
|
readFromStdout,
|
908
908
|
afterClose,
|
909
909
|
service: {
|
910
|
-
|
910
|
+
buildOrContext,
|
911
911
|
transform: transform2,
|
912
912
|
formatMessages: formatMessages2,
|
913
913
|
analyzeMetafile: analyzeMetafile2
|
914
914
|
}
|
915
915
|
};
|
916
916
|
}
|
917
|
-
function
|
917
|
+
function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, options, isTTY, defaultWD, callback) {
|
918
918
|
const details = createObjectStash();
|
919
|
-
const
|
919
|
+
const isContext = callName === "context";
|
920
|
+
const handleError = (e, pluginName) => {
|
920
921
|
const flags = [];
|
921
922
|
try {
|
922
923
|
pushLogFlags(flags, options, {}, isTTY, buildLogLevelDefault);
|
923
924
|
} catch (e2) {
|
924
925
|
}
|
925
|
-
const message = extractErrorMessageV8(e, streamIn, details,
|
926
|
+
const message = extractErrorMessageV8(e, streamIn, details, void 0, pluginName);
|
926
927
|
sendRequest(refs, { command: "error", flags, error: message }, () => {
|
927
928
|
message.detail = details.load(message.detail);
|
928
|
-
|
929
|
-
});
|
930
|
-
};
|
931
|
-
const handleError = (e, pluginName) => {
|
932
|
-
logPluginError(e, pluginName, void 0, (error) => {
|
933
|
-
callback(failureErrorWithLog("Build failed", [error], []), null);
|
929
|
+
callback(failureErrorWithLog(isContext ? "Context failed" : "Build failed", [message], []), null);
|
934
930
|
});
|
935
931
|
};
|
936
932
|
let plugins;
|
@@ -938,15 +934,13 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
|
|
938
934
|
const value = options.plugins;
|
939
935
|
if (value !== void 0) {
|
940
936
|
if (!Array.isArray(value))
|
941
|
-
|
937
|
+
return handleError(new Error(`"plugins" must be an array`), "");
|
942
938
|
plugins = value;
|
943
939
|
}
|
944
940
|
}
|
945
941
|
if (plugins && plugins.length > 0) {
|
946
|
-
if (streamIn.isSync)
|
947
|
-
handleError(new Error("Cannot use plugins in synchronous API calls"), "");
|
948
|
-
return;
|
949
|
-
}
|
942
|
+
if (streamIn.isSync)
|
943
|
+
return handleError(new Error("Cannot use plugins in synchronous API calls"), "");
|
950
944
|
handlePlugins(
|
951
945
|
buildKey,
|
952
946
|
sendRequest,
|
@@ -959,12 +953,10 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
|
|
959
953
|
details
|
960
954
|
).then(
|
961
955
|
(result) => {
|
962
|
-
if (!result.ok)
|
963
|
-
handleError(result.error, result.pluginName);
|
964
|
-
return;
|
965
|
-
}
|
956
|
+
if (!result.ok)
|
957
|
+
return handleError(result.error, result.pluginName);
|
966
958
|
try {
|
967
|
-
|
959
|
+
buildOrContextContinue(result.requestPlugins, result.runOnEndCallbacks, result.scheduleOnDisposeCallbacks);
|
968
960
|
} catch (e) {
|
969
961
|
handleError(e, "");
|
970
962
|
}
|
@@ -974,25 +966,26 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
|
|
974
966
|
return;
|
975
967
|
}
|
976
968
|
try {
|
977
|
-
|
969
|
+
buildOrContextContinue(null, (result, done) => done([], []), () => {
|
970
|
+
});
|
978
971
|
} catch (e) {
|
979
972
|
handleError(e, "");
|
980
973
|
}
|
981
|
-
function
|
982
|
-
|
983
|
-
|
974
|
+
function buildOrContextContinue(requestPlugins, runOnEndCallbacks, scheduleOnDisposeCallbacks) {
|
975
|
+
const writeDefault = streamIn.hasFS;
|
976
|
+
const {
|
984
977
|
entries,
|
985
978
|
flags,
|
986
979
|
write,
|
987
980
|
stdinContents,
|
988
981
|
stdinResolveDir,
|
989
982
|
absWorkingDir,
|
990
|
-
incremental,
|
991
983
|
nodePaths,
|
992
|
-
watch,
|
993
984
|
mangleCache
|
994
985
|
} = flagsForBuildOptions(callName, options, isTTY, buildLogLevelDefault, writeDefault);
|
995
|
-
|
986
|
+
if (write && !streamIn.hasFS)
|
987
|
+
throw new Error(`The "write" option is unavailable in this environment`);
|
988
|
+
const request = {
|
996
989
|
command: "build",
|
997
990
|
key: buildKey,
|
998
991
|
entries,
|
@@ -1001,17 +994,23 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
|
|
1001
994
|
stdinContents,
|
1002
995
|
stdinResolveDir,
|
1003
996
|
absWorkingDir: absWorkingDir || defaultWD,
|
1004
|
-
|
1005
|
-
|
997
|
+
nodePaths,
|
998
|
+
context: isContext
|
1006
999
|
};
|
1007
1000
|
if (requestPlugins)
|
1008
1001
|
request.plugins = requestPlugins;
|
1009
1002
|
if (mangleCache)
|
1010
1003
|
request.mangleCache = mangleCache;
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1004
|
+
const buildResponseToResult = (response, callback2) => {
|
1005
|
+
const result = {
|
1006
|
+
errors: replaceDetailsInMessages(response.errors, details),
|
1007
|
+
warnings: replaceDetailsInMessages(response.warnings, details),
|
1008
|
+
outputFiles: void 0,
|
1009
|
+
metafile: void 0,
|
1010
|
+
mangleCache: void 0
|
1011
|
+
};
|
1012
|
+
const originalErrors = result.errors.slice();
|
1013
|
+
const originalWarnings = result.warnings.slice();
|
1015
1014
|
if (response.outputFiles)
|
1016
1015
|
result.outputFiles = response.outputFiles.map(convertOutputFiles);
|
1017
1016
|
if (response.metafile)
|
@@ -1020,170 +1019,163 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
|
|
1020
1019
|
result.mangleCache = response.mangleCache;
|
1021
1020
|
if (response.writeToStdout !== void 0)
|
1022
1021
|
console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, ""));
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
warnings: replaceDetailsInMessages(response.warnings, details)
|
1028
|
-
};
|
1029
|
-
copyResponseToResult(response, result);
|
1030
|
-
runOnEndCallbacks(result, logPluginError, () => {
|
1031
|
-
if (result.errors.length > 0) {
|
1032
|
-
return callback2(failureErrorWithLog("Build failed", result.errors, result.warnings), null);
|
1022
|
+
runOnEndCallbacks(result, (onEndErrors, onEndWarnings) => {
|
1023
|
+
if (originalErrors.length > 0 || onEndErrors.length > 0) {
|
1024
|
+
const error = failureErrorWithLog("Build failed", originalErrors.concat(onEndErrors), originalWarnings.concat(onEndWarnings));
|
1025
|
+
return callback2(error, null, onEndErrors, onEndWarnings);
|
1033
1026
|
}
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1027
|
+
callback2(null, result, onEndErrors, onEndWarnings);
|
1028
|
+
});
|
1029
|
+
};
|
1030
|
+
let latestResultPromise;
|
1031
|
+
let provideLatestResult;
|
1032
|
+
if (isContext)
|
1033
|
+
requestCallbacks["on-end"] = (id, request2) => new Promise((resolve) => {
|
1034
|
+
buildResponseToResult(request2, (err, result, onEndErrors, onEndWarnings) => {
|
1035
|
+
const response = {
|
1036
|
+
errors: onEndErrors,
|
1037
|
+
warnings: onEndWarnings
|
1038
|
+
};
|
1039
|
+
if (provideLatestResult)
|
1040
|
+
provideLatestResult(err, result);
|
1041
|
+
latestResultPromise = void 0;
|
1042
|
+
provideLatestResult = void 0;
|
1043
|
+
sendResponse(id, response);
|
1044
|
+
resolve();
|
1045
|
+
});
|
1046
|
+
});
|
1047
|
+
sendRequest(refs, request, (error, response) => {
|
1048
|
+
if (error)
|
1049
|
+
return callback(new Error(error), null);
|
1050
|
+
if (!isContext) {
|
1051
|
+
return buildResponseToResult(response, (err, res) => {
|
1052
|
+
scheduleOnDisposeCallbacks();
|
1053
|
+
return callback(err, res);
|
1054
|
+
});
|
1055
|
+
}
|
1056
|
+
if (response.errors.length > 0) {
|
1057
|
+
return callback(failureErrorWithLog("Context failed", response.errors, response.warnings), null);
|
1058
|
+
}
|
1059
|
+
let didDispose = false;
|
1060
|
+
const result = {
|
1061
|
+
rebuild: () => {
|
1062
|
+
if (!latestResultPromise)
|
1063
|
+
latestResultPromise = new Promise((resolve, reject) => {
|
1064
|
+
let settlePromise;
|
1065
|
+
provideLatestResult = (err, result2) => {
|
1066
|
+
if (!settlePromise)
|
1067
|
+
settlePromise = () => err ? reject(err) : resolve(result2);
|
1068
|
+
};
|
1069
|
+
const triggerAnotherBuild = () => {
|
1070
|
+
const request2 = {
|
1071
|
+
command: "rebuild",
|
1072
|
+
key: buildKey
|
1073
|
+
};
|
1074
|
+
sendRequest(refs, request2, (error2, response2) => {
|
1044
1075
|
if (error2) {
|
1045
|
-
|
1046
|
-
|
1076
|
+
reject(new Error(error2));
|
1077
|
+
} else if (settlePromise) {
|
1078
|
+
settlePromise();
|
1079
|
+
} else {
|
1080
|
+
triggerAnotherBuild();
|
1047
1081
|
}
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
else
|
1052
|
-
resolve(result3);
|
1053
|
-
});
|
1054
|
-
}
|
1055
|
-
);
|
1082
|
+
});
|
1083
|
+
};
|
1084
|
+
triggerAnotherBuild();
|
1056
1085
|
});
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1086
|
+
return latestResultPromise;
|
1087
|
+
},
|
1088
|
+
watch: (options2 = {}) => new Promise((resolve, reject) => {
|
1089
|
+
if (!streamIn.hasFS)
|
1090
|
+
throw new Error(`Cannot use the "watch" API in this environment`);
|
1091
|
+
const keys = {};
|
1092
|
+
checkForInvalidFlags(options2, keys, `in watch() call`);
|
1093
|
+
const request2 = {
|
1094
|
+
command: "watch",
|
1095
|
+
key: buildKey
|
1096
|
+
};
|
1097
|
+
sendRequest(refs, request2, (error2) => {
|
1098
|
+
if (error2)
|
1099
|
+
reject(new Error(error2));
|
1100
|
+
else
|
1101
|
+
resolve(void 0);
|
1102
|
+
});
|
1103
|
+
}),
|
1104
|
+
serve: (options2 = {}) => new Promise((resolve, reject) => {
|
1105
|
+
if (!streamIn.hasFS)
|
1106
|
+
throw new Error(`Cannot use the "serve" API in this environment`);
|
1107
|
+
const keys = {};
|
1108
|
+
const port = getFlag(options2, keys, "port", mustBeInteger);
|
1109
|
+
const host = getFlag(options2, keys, "host", mustBeString);
|
1110
|
+
const servedir = getFlag(options2, keys, "servedir", mustBeString);
|
1111
|
+
const keyfile = getFlag(options2, keys, "keyfile", mustBeString);
|
1112
|
+
const certfile = getFlag(options2, keys, "certfile", mustBeString);
|
1113
|
+
const onRequest = getFlag(options2, keys, "onRequest", mustBeFunction);
|
1114
|
+
checkForInvalidFlags(options2, keys, `in serve() call`);
|
1115
|
+
const request2 = {
|
1116
|
+
command: "serve",
|
1117
|
+
key: buildKey,
|
1118
|
+
onRequest: !!onRequest
|
1119
|
+
};
|
1120
|
+
if (port !== void 0)
|
1121
|
+
request2.port = port;
|
1122
|
+
if (host !== void 0)
|
1123
|
+
request2.host = host;
|
1124
|
+
if (servedir !== void 0)
|
1125
|
+
request2.servedir = servedir;
|
1126
|
+
if (keyfile !== void 0)
|
1127
|
+
request2.keyfile = keyfile;
|
1128
|
+
if (certfile !== void 0)
|
1129
|
+
request2.certfile = certfile;
|
1130
|
+
sendRequest(refs, request2, (error2, response2) => {
|
1131
|
+
if (error2)
|
1132
|
+
return reject(new Error(error2));
|
1133
|
+
if (onRequest) {
|
1134
|
+
requestCallbacks["serve-request"] = (id, request3) => {
|
1135
|
+
onRequest(request3.args);
|
1104
1136
|
sendResponse(id, {});
|
1105
1137
|
};
|
1106
1138
|
}
|
1107
|
-
|
1108
|
-
|
1109
|
-
}
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
return;
|
1133
|
-
isStopped = true;
|
1134
|
-
serve2.stop();
|
1139
|
+
resolve(response2);
|
1140
|
+
});
|
1141
|
+
}),
|
1142
|
+
cancel: () => new Promise((resolve) => {
|
1143
|
+
if (didDispose)
|
1144
|
+
return resolve();
|
1145
|
+
const request2 = {
|
1146
|
+
command: "cancel",
|
1147
|
+
key: buildKey
|
1148
|
+
};
|
1149
|
+
sendRequest(refs, request2, () => {
|
1150
|
+
resolve();
|
1151
|
+
});
|
1152
|
+
}),
|
1153
|
+
dispose: () => new Promise((resolve) => {
|
1154
|
+
if (didDispose)
|
1155
|
+
return resolve();
|
1156
|
+
didDispose = true;
|
1157
|
+
const request2 = {
|
1158
|
+
command: "dispose",
|
1159
|
+
key: buildKey
|
1160
|
+
};
|
1161
|
+
sendRequest(refs, request2, () => {
|
1162
|
+
resolve();
|
1163
|
+
scheduleOnDisposeCallbacks();
|
1135
1164
|
refs.unref();
|
1136
|
-
}
|
1137
|
-
}
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
}
|
1142
|
-
return buildResponseToResult(response, callback);
|
1165
|
+
});
|
1166
|
+
})
|
1167
|
+
};
|
1168
|
+
refs.ref();
|
1169
|
+
callback(null, result);
|
1143
1170
|
});
|
1144
1171
|
}
|
1145
1172
|
}
|
1146
|
-
var buildServeData = (buildKey, sendRequest, sendResponse, refs, requestCallbacks, options, request) => {
|
1147
|
-
let keys = {};
|
1148
|
-
let port = getFlag(options, keys, "port", mustBeInteger);
|
1149
|
-
let host = getFlag(options, keys, "host", mustBeString);
|
1150
|
-
let servedir = getFlag(options, keys, "servedir", mustBeString);
|
1151
|
-
let onRequest = getFlag(options, keys, "onRequest", mustBeFunction);
|
1152
|
-
let wait = new Promise((resolve, reject) => {
|
1153
|
-
requestCallbacks["serve-wait"] = (id, request2) => {
|
1154
|
-
if (request2.error !== null)
|
1155
|
-
reject(new Error(request2.error));
|
1156
|
-
else
|
1157
|
-
resolve();
|
1158
|
-
sendResponse(id, {});
|
1159
|
-
};
|
1160
|
-
});
|
1161
|
-
request.serve = {};
|
1162
|
-
checkForInvalidFlags(options, keys, `in serve() call`);
|
1163
|
-
if (port !== void 0)
|
1164
|
-
request.serve.port = port;
|
1165
|
-
if (host !== void 0)
|
1166
|
-
request.serve.host = host;
|
1167
|
-
if (servedir !== void 0)
|
1168
|
-
request.serve.servedir = servedir;
|
1169
|
-
requestCallbacks["serve-request"] = (id, request2) => {
|
1170
|
-
if (onRequest)
|
1171
|
-
onRequest(request2.args);
|
1172
|
-
sendResponse(id, {});
|
1173
|
-
};
|
1174
|
-
return {
|
1175
|
-
wait,
|
1176
|
-
stop() {
|
1177
|
-
sendRequest(refs, { command: "serve-stop", key: buildKey }, () => {
|
1178
|
-
});
|
1179
|
-
}
|
1180
|
-
};
|
1181
|
-
};
|
1182
1173
|
var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, initialOptions, plugins, details) => {
|
1183
1174
|
let onStartCallbacks = [];
|
1184
1175
|
let onEndCallbacks = [];
|
1185
1176
|
let onResolveCallbacks = {};
|
1186
1177
|
let onLoadCallbacks = {};
|
1178
|
+
let onDisposeCallbacks = [];
|
1187
1179
|
let nextCallbackID = 0;
|
1188
1180
|
let i = 0;
|
1189
1181
|
let requestPlugins = [];
|
@@ -1203,6 +1195,8 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
1203
1195
|
checkForInvalidFlags(item, keys, `on plugin ${quote(name)}`);
|
1204
1196
|
let plugin = {
|
1205
1197
|
name,
|
1198
|
+
onStart: false,
|
1199
|
+
onEnd: false,
|
1206
1200
|
onResolve: [],
|
1207
1201
|
onLoad: []
|
1208
1202
|
};
|
@@ -1265,11 +1259,13 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
1265
1259
|
let registeredText = `This error came from the "onStart" callback registered here:`;
|
1266
1260
|
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onStart");
|
1267
1261
|
onStartCallbacks.push({ name, callback, note: registeredNote });
|
1262
|
+
plugin.onStart = true;
|
1268
1263
|
},
|
1269
1264
|
onEnd(callback) {
|
1270
1265
|
let registeredText = `This error came from the "onEnd" callback registered here:`;
|
1271
1266
|
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onEnd");
|
1272
1267
|
onEndCallbacks.push({ name, callback, note: registeredNote });
|
1268
|
+
plugin.onEnd = true;
|
1273
1269
|
},
|
1274
1270
|
onResolve(options, callback) {
|
1275
1271
|
let registeredText = `This error came from the "onResolve" callback registered here:`;
|
@@ -1297,6 +1293,9 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
1297
1293
|
onLoadCallbacks[id] = { name, callback, note: registeredNote };
|
1298
1294
|
plugin.onLoad.push({ id, filter: filter.source, namespace: namespace || "" });
|
1299
1295
|
},
|
1296
|
+
onDispose(callback) {
|
1297
|
+
onDisposeCallbacks.push(callback);
|
1298
|
+
},
|
1300
1299
|
esbuild: streamIn.esbuild
|
1301
1300
|
});
|
1302
1301
|
if (promise)
|
@@ -1445,25 +1444,62 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
1445
1444
|
}
|
1446
1445
|
sendResponse(id, response);
|
1447
1446
|
};
|
1448
|
-
let runOnEndCallbacks = (result,
|
1447
|
+
let runOnEndCallbacks = (result, done) => done([], []);
|
1449
1448
|
if (onEndCallbacks.length > 0) {
|
1450
|
-
runOnEndCallbacks = (result,
|
1449
|
+
runOnEndCallbacks = (result, done) => {
|
1451
1450
|
(async () => {
|
1451
|
+
const onEndErrors = [];
|
1452
|
+
const onEndWarnings = [];
|
1452
1453
|
for (const { name, callback, note } of onEndCallbacks) {
|
1454
|
+
let newErrors;
|
1455
|
+
let newWarnings;
|
1453
1456
|
try {
|
1454
|
-
await callback(result);
|
1457
|
+
const value = await callback(result);
|
1458
|
+
if (value != null) {
|
1459
|
+
if (typeof value !== "object")
|
1460
|
+
throw new Error(`Expected onEnd() callback in plugin ${quote(name)} to return an object`);
|
1461
|
+
let keys = {};
|
1462
|
+
let errors = getFlag(value, keys, "errors", mustBeArray);
|
1463
|
+
let warnings = getFlag(value, keys, "warnings", mustBeArray);
|
1464
|
+
checkForInvalidFlags(value, keys, `from onEnd() callback in plugin ${quote(name)}`);
|
1465
|
+
if (errors != null)
|
1466
|
+
newErrors = sanitizeMessages(errors, "errors", details, name);
|
1467
|
+
if (warnings != null)
|
1468
|
+
newWarnings = sanitizeMessages(warnings, "warnings", details, name);
|
1469
|
+
}
|
1455
1470
|
} catch (e) {
|
1456
|
-
|
1471
|
+
newErrors = [extractErrorMessageV8(e, streamIn, details, note && note(), name)];
|
1472
|
+
}
|
1473
|
+
if (newErrors) {
|
1474
|
+
onEndErrors.push(...newErrors);
|
1475
|
+
try {
|
1476
|
+
result.errors.push(...newErrors);
|
1477
|
+
} catch (e) {
|
1478
|
+
}
|
1479
|
+
}
|
1480
|
+
if (newWarnings) {
|
1481
|
+
onEndWarnings.push(...newWarnings);
|
1482
|
+
try {
|
1483
|
+
result.warnings.push(...newWarnings);
|
1484
|
+
} catch (e) {
|
1485
|
+
}
|
1457
1486
|
}
|
1458
1487
|
}
|
1459
|
-
|
1488
|
+
done(onEndErrors, onEndWarnings);
|
1489
|
+
})();
|
1460
1490
|
};
|
1461
1491
|
}
|
1492
|
+
let scheduleOnDisposeCallbacks = () => {
|
1493
|
+
for (const cb of onDisposeCallbacks) {
|
1494
|
+
setTimeout(() => cb(), 0);
|
1495
|
+
}
|
1496
|
+
};
|
1462
1497
|
isSetupDone = true;
|
1463
1498
|
return {
|
1464
1499
|
ok: true,
|
1465
1500
|
requestPlugins,
|
1466
|
-
runOnEndCallbacks
|
1501
|
+
runOnEndCallbacks,
|
1502
|
+
scheduleOnDisposeCallbacks
|
1467
1503
|
};
|
1468
1504
|
};
|
1469
1505
|
function createObjectStash() {
|
@@ -1670,11 +1706,9 @@ function convertOutputFiles({ path, contents }) {
|
|
1670
1706
|
}
|
1671
1707
|
|
1672
1708
|
// lib/npm/browser.ts
|
1673
|
-
var version = "0.
|
1709
|
+
var version = "0.17.12";
|
1674
1710
|
var build = (options) => ensureServiceIsRunning().build(options);
|
1675
|
-
var
|
1676
|
-
throw new Error(`The "serve" API only works in node`);
|
1677
|
-
};
|
1711
|
+
var context = (options) => ensureServiceIsRunning().context(options);
|
1678
1712
|
var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
|
1679
1713
|
var formatMessages = (messages, options) => ensureServiceIsRunning().formatMessages(messages, options);
|
1680
1714
|
var analyzeMetafile = (metafile, options) => ensureServiceIsRunning().analyzeMetafile(metafile, options);
|
@@ -1717,7 +1751,7 @@ var initialize = (options) => {
|
|
1717
1751
|
var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
1718
1752
|
let worker;
|
1719
1753
|
if (useWorker) {
|
1720
|
-
let blob = new Blob([`onmessage=${'((postMessage) => {\n // Copyright 2018 The Go Authors. All rights reserved.\n // Use of this source code is governed by a BSD-style\n // license that can be found in the LICENSE file.\n let onmessage;\n let globalThis = {};\n for (let o = self; o; o = Object.getPrototypeOf(o))\n for (let k of Object.getOwnPropertyNames(o))\n if (!(k in globalThis))\n Object.defineProperty(globalThis, k, { get: () => self[k] });\n "use strict";\n (() => {\n const enosys = () => {\n const err = new Error("not implemented");\n err.code = "ENOSYS";\n return err;\n };\n if (!globalThis.fs) {\n let outputBuf = "";\n globalThis.fs = {\n constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },\n writeSync(fd, buf) {\n outputBuf += decoder.decode(buf);\n const nl = outputBuf.lastIndexOf("\\n");\n if (nl != -1) {\n console.log(outputBuf.substr(0, nl));\n outputBuf = outputBuf.substr(nl + 1);\n }\n return buf.length;\n },\n write(fd, buf, offset, length, position, callback) {\n if (offset !== 0 || length !== buf.length || position !== null) {\n callback(enosys());\n return;\n }\n const n = this.writeSync(fd, buf);\n callback(null, n);\n },\n chmod(path, mode, callback) {\n callback(enosys());\n },\n chown(path, uid, gid, callback) {\n callback(enosys());\n },\n close(fd, callback) {\n callback(enosys());\n },\n fchmod(fd, mode, callback) {\n callback(enosys());\n },\n fchown(fd, uid, gid, callback) {\n callback(enosys());\n },\n fstat(fd, callback) {\n callback(enosys());\n },\n fsync(fd, callback) {\n callback(null);\n },\n ftruncate(fd, length, callback) {\n callback(enosys());\n },\n lchown(path, uid, gid, callback) {\n callback(enosys());\n },\n link(path, link, callback) {\n callback(enosys());\n },\n lstat(path, callback) {\n callback(enosys());\n },\n mkdir(path, perm, callback) {\n callback(enosys());\n },\n open(path, flags, mode, callback) {\n callback(enosys());\n },\n read(fd, buffer, offset, length, position, callback) {\n callback(enosys());\n },\n readdir(path, callback) {\n callback(enosys());\n },\n readlink(path, callback) {\n callback(enosys());\n },\n rename(from, to, callback) {\n callback(enosys());\n },\n rmdir(path, callback) {\n callback(enosys());\n },\n stat(path, callback) {\n callback(enosys());\n },\n symlink(path, link, callback) {\n callback(enosys());\n },\n truncate(path, length, callback) {\n callback(enosys());\n },\n unlink(path, callback) {\n callback(enosys());\n },\n utimes(path, atime, mtime, callback) {\n callback(enosys());\n }\n };\n }\n if (!globalThis.process) {\n globalThis.process = {\n getuid() {\n return -1;\n },\n getgid() {\n return -1;\n },\n geteuid() {\n return -1;\n },\n getegid() {\n return -1;\n },\n getgroups() {\n throw enosys();\n },\n pid: -1,\n ppid: -1,\n umask() {\n throw enosys();\n },\n cwd() {\n throw enosys();\n },\n chdir() {\n throw enosys();\n }\n };\n }\n if (!globalThis.crypto) {\n throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");\n }\n if (!globalThis.performance) {\n throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");\n }\n if (!globalThis.TextEncoder) {\n throw new Error("globalThis.TextEncoder is not available, polyfill required");\n }\n if (!globalThis.TextDecoder) {\n throw new Error("globalThis.TextDecoder is not available, polyfill required");\n }\n const encoder = new TextEncoder("utf-8");\n const decoder = new TextDecoder("utf-8");\n globalThis.Go = class {\n constructor() {\n this.argv = ["js"];\n this.env = {};\n this.exit = (code) => {\n if (code !== 0) {\n console.warn("exit code:", code);\n }\n };\n this._exitPromise = new Promise((resolve) => {\n this._resolveExitPromise = resolve;\n });\n this._pendingEvent = null;\n this._scheduledTimeouts = /* @__PURE__ */ new Map();\n this._nextCallbackTimeoutID = 1;\n const setInt64 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);\n };\n const getInt64 = (addr) => {\n const low = this.mem.getUint32(addr + 0, true);\n const high = this.mem.getInt32(addr + 4, true);\n return low + high * 4294967296;\n };\n const loadValue = (addr) => {\n const f = this.mem.getFloat64(addr, true);\n if (f === 0) {\n return void 0;\n }\n if (!isNaN(f)) {\n return f;\n }\n const id = this.mem.getUint32(addr, true);\n return this._values[id];\n };\n const storeValue = (addr, v) => {\n const nanHead = 2146959360;\n if (typeof v === "number" && v !== 0) {\n if (isNaN(v)) {\n this.mem.setUint32(addr + 4, nanHead, true);\n this.mem.setUint32(addr, 0, true);\n return;\n }\n this.mem.setFloat64(addr, v, true);\n return;\n }\n if (v === void 0) {\n this.mem.setFloat64(addr, 0, true);\n return;\n }\n let id = this._ids.get(v);\n if (id === void 0) {\n id = this._idPool.pop();\n if (id === void 0) {\n id = this._values.length;\n }\n this._values[id] = v;\n this._goRefCounts[id] = 0;\n this._ids.set(v, id);\n }\n this._goRefCounts[id]++;\n let typeFlag = 0;\n switch (typeof v) {\n case "object":\n if (v !== null) {\n typeFlag = 1;\n }\n break;\n case "string":\n typeFlag = 2;\n break;\n case "symbol":\n typeFlag = 3;\n break;\n case "function":\n typeFlag = 4;\n break;\n }\n this.mem.setUint32(addr + 4, nanHead | typeFlag, true);\n this.mem.setUint32(addr, id, true);\n };\n const loadSlice = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return new Uint8Array(this._inst.exports.mem.buffer, array, len);\n };\n const loadSliceOfValues = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n const a = new Array(len);\n for (let i = 0; i < len; i++) {\n a[i] = loadValue(array + i * 8);\n }\n return a;\n };\n const loadString = (addr) => {\n const saddr = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));\n };\n const timeOrigin = Date.now() - performance.now();\n this.importObject = {\n go: {\n "runtime.wasmExit": (sp) => {\n sp >>>= 0;\n const code = this.mem.getInt32(sp + 8, true);\n this.exited = true;\n delete this._inst;\n delete this._values;\n delete this._goRefCounts;\n delete this._ids;\n delete this._idPool;\n this.exit(code);\n },\n "runtime.wasmWrite": (sp) => {\n sp >>>= 0;\n const fd = getInt64(sp + 8);\n const p = getInt64(sp + 16);\n const n = this.mem.getInt32(sp + 24, true);\n globalThis.fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));\n },\n "runtime.resetMemoryDataView": (sp) => {\n sp >>>= 0;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n },\n "runtime.nanotime1": (sp) => {\n sp >>>= 0;\n setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);\n },\n "runtime.walltime": (sp) => {\n sp >>>= 0;\n const msec = new Date().getTime();\n setInt64(sp + 8, msec / 1e3);\n this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);\n },\n "runtime.scheduleTimeoutEvent": (sp) => {\n sp >>>= 0;\n const id = this._nextCallbackTimeoutID;\n this._nextCallbackTimeoutID++;\n this._scheduledTimeouts.set(id, setTimeout(\n () => {\n this._resume();\n while (this._scheduledTimeouts.has(id)) {\n console.warn("scheduleTimeoutEvent: missed timeout event");\n this._resume();\n }\n },\n getInt64(sp + 8) + 1\n ));\n this.mem.setInt32(sp + 16, id, true);\n },\n "runtime.clearTimeoutEvent": (sp) => {\n sp >>>= 0;\n const id = this.mem.getInt32(sp + 8, true);\n clearTimeout(this._scheduledTimeouts.get(id));\n this._scheduledTimeouts.delete(id);\n },\n "runtime.getRandomData": (sp) => {\n sp >>>= 0;\n crypto.getRandomValues(loadSlice(sp + 8));\n },\n "syscall/js.finalizeRef": (sp) => {\n sp >>>= 0;\n const id = this.mem.getUint32(sp + 8, true);\n this._goRefCounts[id]--;\n if (this._goRefCounts[id] === 0) {\n const v = this._values[id];\n this._values[id] = null;\n this._ids.delete(v);\n this._idPool.push(id);\n }\n },\n "syscall/js.stringVal": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, loadString(sp + 8));\n },\n "syscall/js.valueGet": (sp) => {\n sp >>>= 0;\n const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 32, result);\n },\n "syscall/js.valueSet": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n },\n "syscall/js.valueDelete": (sp) => {\n sp >>>= 0;\n Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n },\n "syscall/js.valueIndex": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n },\n "syscall/js.valueSetIndex": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n },\n "syscall/js.valueCall": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const m = Reflect.get(v, loadString(sp + 16));\n const args = loadSliceOfValues(sp + 32);\n const result = Reflect.apply(m, v, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 56, result);\n this.mem.setUint8(sp + 64, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 56, err);\n this.mem.setUint8(sp + 64, 0);\n }\n },\n "syscall/js.valueInvoke": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.apply(v, void 0, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n "syscall/js.valueNew": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.construct(v, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n "syscall/js.valueLength": (sp) => {\n sp >>>= 0;\n setInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n },\n "syscall/js.valuePrepareString": (sp) => {\n sp >>>= 0;\n const str = encoder.encode(String(loadValue(sp + 8)));\n storeValue(sp + 16, str);\n setInt64(sp + 24, str.length);\n },\n "syscall/js.valueLoadString": (sp) => {\n sp >>>= 0;\n const str = loadValue(sp + 8);\n loadSlice(sp + 16).set(str);\n },\n "syscall/js.valueInstanceOf": (sp) => {\n sp >>>= 0;\n this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);\n },\n "syscall/js.copyBytesToGo": (sp) => {\n sp >>>= 0;\n const dst = loadSlice(sp + 8);\n const src = loadValue(sp + 32);\n if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "syscall/js.copyBytesToJS": (sp) => {\n sp >>>= 0;\n const dst = loadValue(sp + 8);\n const src = loadSlice(sp + 16);\n if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "debug": (value) => {\n console.log(value);\n }\n }\n };\n }\n async run(instance) {\n if (!(instance instanceof WebAssembly.Instance)) {\n throw new Error("Go.run: WebAssembly.Instance expected");\n }\n this._inst = instance;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n this._values = [\n NaN,\n 0,\n null,\n true,\n false,\n globalThis,\n this\n ];\n this._goRefCounts = new Array(this._values.length).fill(Infinity);\n this._ids = /* @__PURE__ */ new Map([\n [0, 1],\n [null, 2],\n [true, 3],\n [false, 4],\n [globalThis, 5],\n [this, 6]\n ]);\n this._idPool = [];\n this.exited = false;\n let offset = 4096;\n const strPtr = (str) => {\n const ptr = offset;\n const bytes = encoder.encode(str + "\\0");\n new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);\n offset += bytes.length;\n if (offset % 8 !== 0) {\n offset += 8 - offset % 8;\n }\n return ptr;\n };\n const argc = this.argv.length;\n const argvPtrs = [];\n this.argv.forEach((arg) => {\n argvPtrs.push(strPtr(arg));\n });\n argvPtrs.push(0);\n const keys = Object.keys(this.env).sort();\n keys.forEach((key) => {\n argvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n });\n argvPtrs.push(0);\n const argv = offset;\n argvPtrs.forEach((ptr) => {\n this.mem.setUint32(offset, ptr, true);\n this.mem.setUint32(offset + 4, 0, true);\n offset += 8;\n });\n const wasmMinDataAddr = 4096 + 8192;\n if (offset >= wasmMinDataAddr) {\n throw new Error("total length of command line and environment variables exceeds limit");\n }\n this._inst.exports.run(argc, argv);\n if (this.exited) {\n this._resolveExitPromise();\n }\n await this._exitPromise;\n }\n _resume() {\n if (this.exited) {\n throw new Error("Go program has already exited");\n }\n this._inst.exports.resume();\n if (this.exited) {\n this._resolveExitPromise();\n }\n }\n _makeFuncWrapper(id) {\n const go = this;\n return function() {\n const event = { id, this: this, args: arguments };\n go._pendingEvent = event;\n go._resume();\n return event.result;\n };\n }\n };\n })();\n onmessage = ({ data: wasm }) => {\n let decoder = new TextDecoder();\n let fs = globalThis.fs;\n let stderr = "";\n fs.writeSync = (fd, buffer) => {\n if (fd === 1) {\n postMessage(buffer);\n } else if (fd === 2) {\n stderr += decoder.decode(buffer);\n let parts = stderr.split("\\n");\n if (parts.length > 1)\n console.log(parts.slice(0, -1).join("\\n"));\n stderr = parts[parts.length - 1];\n } else {\n throw new Error("Bad write");\n }\n return buffer.length;\n };\n let stdin = [];\n let resumeStdin;\n let stdinPos = 0;\n onmessage = ({ data }) => {\n if (data.length > 0) {\n stdin.push(data);\n if (resumeStdin)\n resumeStdin();\n }\n };\n fs.read = (fd, buffer, offset, length, position, callback) => {\n if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) {\n throw new Error("Bad read");\n }\n if (stdin.length === 0) {\n resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback);\n return;\n }\n let first = stdin[0];\n let count = Math.max(0, Math.min(length, first.length - stdinPos));\n buffer.set(first.subarray(stdinPos, stdinPos + count), offset);\n stdinPos += count;\n if (stdinPos === first.length) {\n stdin.shift();\n stdinPos = 0;\n }\n callback(null, count);\n };\n let go = new globalThis.Go();\n go.argv = ["", `--service=${"0.16.10"}`];\n tryToInstantiateModule(wasm, go).then(\n (instance) => {\n postMessage(null);\n go.run(instance);\n },\n (error) => {\n postMessage(error);\n }\n );\n };\n async function tryToInstantiateModule(wasm, go) {\n if (wasm instanceof WebAssembly.Module) {\n return WebAssembly.instantiate(wasm, go.importObject);\n }\n const res = await fetch(wasm);\n if (!res.ok)\n throw new Error(`Failed to download ${JSON.stringify(wasm)}`);\n if ("instantiateStreaming" in WebAssembly && /^application\\/wasm($|;)/i.test(res.headers.get("Content-Type") || "")) {\n const result2 = await WebAssembly.instantiateStreaming(res, go.importObject);\n return result2.instance;\n }\n const bytes = await res.arrayBuffer();\n const result = await WebAssembly.instantiate(bytes, go.importObject);\n return result.instance;\n }\n return (m) => onmessage(m);\n })'}(postMessage)`], { type: "text/javascript" });
|
1754
|
+
let blob = new Blob([`onmessage=${'((postMessage) => {\n // Copyright 2018 The Go Authors. All rights reserved.\n // Use of this source code is governed by a BSD-style\n // license that can be found in the LICENSE file.\n let onmessage;\n let globalThis = {};\n for (let o = self; o; o = Object.getPrototypeOf(o))\n for (let k of Object.getOwnPropertyNames(o))\n if (!(k in globalThis))\n Object.defineProperty(globalThis, k, { get: () => self[k] });\n "use strict";\n (() => {\n const enosys = () => {\n const err = new Error("not implemented");\n err.code = "ENOSYS";\n return err;\n };\n if (!globalThis.fs) {\n let outputBuf = "";\n globalThis.fs = {\n constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },\n // unused\n writeSync(fd, buf) {\n outputBuf += decoder.decode(buf);\n const nl = outputBuf.lastIndexOf("\\n");\n if (nl != -1) {\n console.log(outputBuf.substring(0, nl));\n outputBuf = outputBuf.substring(nl + 1);\n }\n return buf.length;\n },\n write(fd, buf, offset, length, position, callback) {\n if (offset !== 0 || length !== buf.length || position !== null) {\n callback(enosys());\n return;\n }\n const n = this.writeSync(fd, buf);\n callback(null, n);\n },\n chmod(path, mode, callback) {\n callback(enosys());\n },\n chown(path, uid, gid, callback) {\n callback(enosys());\n },\n close(fd, callback) {\n callback(enosys());\n },\n fchmod(fd, mode, callback) {\n callback(enosys());\n },\n fchown(fd, uid, gid, callback) {\n callback(enosys());\n },\n fstat(fd, callback) {\n callback(enosys());\n },\n fsync(fd, callback) {\n callback(null);\n },\n ftruncate(fd, length, callback) {\n callback(enosys());\n },\n lchown(path, uid, gid, callback) {\n callback(enosys());\n },\n link(path, link, callback) {\n callback(enosys());\n },\n lstat(path, callback) {\n callback(enosys());\n },\n mkdir(path, perm, callback) {\n callback(enosys());\n },\n open(path, flags, mode, callback) {\n callback(enosys());\n },\n read(fd, buffer, offset, length, position, callback) {\n callback(enosys());\n },\n readdir(path, callback) {\n callback(enosys());\n },\n readlink(path, callback) {\n callback(enosys());\n },\n rename(from, to, callback) {\n callback(enosys());\n },\n rmdir(path, callback) {\n callback(enosys());\n },\n stat(path, callback) {\n callback(enosys());\n },\n symlink(path, link, callback) {\n callback(enosys());\n },\n truncate(path, length, callback) {\n callback(enosys());\n },\n unlink(path, callback) {\n callback(enosys());\n },\n utimes(path, atime, mtime, callback) {\n callback(enosys());\n }\n };\n }\n if (!globalThis.process) {\n globalThis.process = {\n getuid() {\n return -1;\n },\n getgid() {\n return -1;\n },\n geteuid() {\n return -1;\n },\n getegid() {\n return -1;\n },\n getgroups() {\n throw enosys();\n },\n pid: -1,\n ppid: -1,\n umask() {\n throw enosys();\n },\n cwd() {\n throw enosys();\n },\n chdir() {\n throw enosys();\n }\n };\n }\n if (!globalThis.crypto) {\n throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");\n }\n if (!globalThis.performance) {\n throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");\n }\n if (!globalThis.TextEncoder) {\n throw new Error("globalThis.TextEncoder is not available, polyfill required");\n }\n if (!globalThis.TextDecoder) {\n throw new Error("globalThis.TextDecoder is not available, polyfill required");\n }\n const encoder = new TextEncoder("utf-8");\n const decoder = new TextDecoder("utf-8");\n globalThis.Go = class {\n constructor() {\n this.argv = ["js"];\n this.env = {};\n this.exit = (code) => {\n if (code !== 0) {\n console.warn("exit code:", code);\n }\n };\n this._exitPromise = new Promise((resolve) => {\n this._resolveExitPromise = resolve;\n });\n this._pendingEvent = null;\n this._scheduledTimeouts = /* @__PURE__ */ new Map();\n this._nextCallbackTimeoutID = 1;\n const setInt64 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);\n };\n const getInt64 = (addr) => {\n const low = this.mem.getUint32(addr + 0, true);\n const high = this.mem.getInt32(addr + 4, true);\n return low + high * 4294967296;\n };\n const loadValue = (addr) => {\n const f = this.mem.getFloat64(addr, true);\n if (f === 0) {\n return void 0;\n }\n if (!isNaN(f)) {\n return f;\n }\n const id = this.mem.getUint32(addr, true);\n return this._values[id];\n };\n const storeValue = (addr, v) => {\n const nanHead = 2146959360;\n if (typeof v === "number" && v !== 0) {\n if (isNaN(v)) {\n this.mem.setUint32(addr + 4, nanHead, true);\n this.mem.setUint32(addr, 0, true);\n return;\n }\n this.mem.setFloat64(addr, v, true);\n return;\n }\n if (v === void 0) {\n this.mem.setFloat64(addr, 0, true);\n return;\n }\n let id = this._ids.get(v);\n if (id === void 0) {\n id = this._idPool.pop();\n if (id === void 0) {\n id = this._values.length;\n }\n this._values[id] = v;\n this._goRefCounts[id] = 0;\n this._ids.set(v, id);\n }\n this._goRefCounts[id]++;\n let typeFlag = 0;\n switch (typeof v) {\n case "object":\n if (v !== null) {\n typeFlag = 1;\n }\n break;\n case "string":\n typeFlag = 2;\n break;\n case "symbol":\n typeFlag = 3;\n break;\n case "function":\n typeFlag = 4;\n break;\n }\n this.mem.setUint32(addr + 4, nanHead | typeFlag, true);\n this.mem.setUint32(addr, id, true);\n };\n const loadSlice = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return new Uint8Array(this._inst.exports.mem.buffer, array, len);\n };\n const loadSliceOfValues = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n const a = new Array(len);\n for (let i = 0; i < len; i++) {\n a[i] = loadValue(array + i * 8);\n }\n return a;\n };\n const loadString = (addr) => {\n const saddr = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));\n };\n const timeOrigin = Date.now() - performance.now();\n this.importObject = {\n go: {\n // Go\'s SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)\n // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported\n // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).\n // This changes the SP, thus we have to update the SP used by the imported function.\n // func wasmExit(code int32)\n "runtime.wasmExit": (sp) => {\n sp >>>= 0;\n const code = this.mem.getInt32(sp + 8, true);\n this.exited = true;\n delete this._inst;\n delete this._values;\n delete this._goRefCounts;\n delete this._ids;\n delete this._idPool;\n this.exit(code);\n },\n // func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)\n "runtime.wasmWrite": (sp) => {\n sp >>>= 0;\n const fd = getInt64(sp + 8);\n const p = getInt64(sp + 16);\n const n = this.mem.getInt32(sp + 24, true);\n globalThis.fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));\n },\n // func resetMemoryDataView()\n "runtime.resetMemoryDataView": (sp) => {\n sp >>>= 0;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n },\n // func nanotime1() int64\n "runtime.nanotime1": (sp) => {\n sp >>>= 0;\n setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);\n },\n // func walltime() (sec int64, nsec int32)\n "runtime.walltime": (sp) => {\n sp >>>= 0;\n const msec = (/* @__PURE__ */ new Date()).getTime();\n setInt64(sp + 8, msec / 1e3);\n this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);\n },\n // func scheduleTimeoutEvent(delay int64) int32\n "runtime.scheduleTimeoutEvent": (sp) => {\n sp >>>= 0;\n const id = this._nextCallbackTimeoutID;\n this._nextCallbackTimeoutID++;\n this._scheduledTimeouts.set(id, setTimeout(\n () => {\n this._resume();\n while (this._scheduledTimeouts.has(id)) {\n console.warn("scheduleTimeoutEvent: missed timeout event");\n this._resume();\n }\n },\n getInt64(sp + 8) + 1\n // setTimeout has been seen to fire up to 1 millisecond early\n ));\n this.mem.setInt32(sp + 16, id, true);\n },\n // func clearTimeoutEvent(id int32)\n "runtime.clearTimeoutEvent": (sp) => {\n sp >>>= 0;\n const id = this.mem.getInt32(sp + 8, true);\n clearTimeout(this._scheduledTimeouts.get(id));\n this._scheduledTimeouts.delete(id);\n },\n // func getRandomData(r []byte)\n "runtime.getRandomData": (sp) => {\n sp >>>= 0;\n crypto.getRandomValues(loadSlice(sp + 8));\n },\n // func finalizeRef(v ref)\n "syscall/js.finalizeRef": (sp) => {\n sp >>>= 0;\n const id = this.mem.getUint32(sp + 8, true);\n this._goRefCounts[id]--;\n if (this._goRefCounts[id] === 0) {\n const v = this._values[id];\n this._values[id] = null;\n this._ids.delete(v);\n this._idPool.push(id);\n }\n },\n // func stringVal(value string) ref\n "syscall/js.stringVal": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, loadString(sp + 8));\n },\n // func valueGet(v ref, p string) ref\n "syscall/js.valueGet": (sp) => {\n sp >>>= 0;\n const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 32, result);\n },\n // func valueSet(v ref, p string, x ref)\n "syscall/js.valueSet": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n },\n // func valueDelete(v ref, p string)\n "syscall/js.valueDelete": (sp) => {\n sp >>>= 0;\n Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n },\n // func valueIndex(v ref, i int) ref\n "syscall/js.valueIndex": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n },\n // valueSetIndex(v ref, i int, x ref)\n "syscall/js.valueSetIndex": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n },\n // func valueCall(v ref, m string, args []ref) (ref, bool)\n "syscall/js.valueCall": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const m = Reflect.get(v, loadString(sp + 16));\n const args = loadSliceOfValues(sp + 32);\n const result = Reflect.apply(m, v, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 56, result);\n this.mem.setUint8(sp + 64, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 56, err);\n this.mem.setUint8(sp + 64, 0);\n }\n },\n // func valueInvoke(v ref, args []ref) (ref, bool)\n "syscall/js.valueInvoke": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.apply(v, void 0, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n // func valueNew(v ref, args []ref) (ref, bool)\n "syscall/js.valueNew": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.construct(v, args);\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0;\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n // func valueLength(v ref) int\n "syscall/js.valueLength": (sp) => {\n sp >>>= 0;\n setInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n },\n // valuePrepareString(v ref) (ref, int)\n "syscall/js.valuePrepareString": (sp) => {\n sp >>>= 0;\n const str = encoder.encode(String(loadValue(sp + 8)));\n storeValue(sp + 16, str);\n setInt64(sp + 24, str.length);\n },\n // valueLoadString(v ref, b []byte)\n "syscall/js.valueLoadString": (sp) => {\n sp >>>= 0;\n const str = loadValue(sp + 8);\n loadSlice(sp + 16).set(str);\n },\n // func valueInstanceOf(v ref, t ref) bool\n "syscall/js.valueInstanceOf": (sp) => {\n sp >>>= 0;\n this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);\n },\n // func copyBytesToGo(dst []byte, src ref) (int, bool)\n "syscall/js.copyBytesToGo": (sp) => {\n sp >>>= 0;\n const dst = loadSlice(sp + 8);\n const src = loadValue(sp + 32);\n if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n // func copyBytesToJS(dst ref, src []byte) (int, bool)\n "syscall/js.copyBytesToJS": (sp) => {\n sp >>>= 0;\n const dst = loadValue(sp + 8);\n const src = loadSlice(sp + 16);\n if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n "debug": (value) => {\n console.log(value);\n }\n }\n };\n }\n async run(instance) {\n if (!(instance instanceof WebAssembly.Instance)) {\n throw new Error("Go.run: WebAssembly.Instance expected");\n }\n this._inst = instance;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n this._values = [\n // JS values that Go currently has references to, indexed by reference id\n NaN,\n 0,\n null,\n true,\n false,\n globalThis,\n this\n ];\n this._goRefCounts = new Array(this._values.length).fill(Infinity);\n this._ids = /* @__PURE__ */ new Map([\n // mapping from JS values to reference ids\n [0, 1],\n [null, 2],\n [true, 3],\n [false, 4],\n [globalThis, 5],\n [this, 6]\n ]);\n this._idPool = [];\n this.exited = false;\n let offset = 4096;\n const strPtr = (str) => {\n const ptr = offset;\n const bytes = encoder.encode(str + "\\0");\n new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);\n offset += bytes.length;\n if (offset % 8 !== 0) {\n offset += 8 - offset % 8;\n }\n return ptr;\n };\n const argc = this.argv.length;\n const argvPtrs = [];\n this.argv.forEach((arg) => {\n argvPtrs.push(strPtr(arg));\n });\n argvPtrs.push(0);\n const keys = Object.keys(this.env).sort();\n keys.forEach((key) => {\n argvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n });\n argvPtrs.push(0);\n const argv = offset;\n argvPtrs.forEach((ptr) => {\n this.mem.setUint32(offset, ptr, true);\n this.mem.setUint32(offset + 4, 0, true);\n offset += 8;\n });\n const wasmMinDataAddr = 4096 + 8192;\n if (offset >= wasmMinDataAddr) {\n throw new Error("total length of command line and environment variables exceeds limit");\n }\n this._inst.exports.run(argc, argv);\n if (this.exited) {\n this._resolveExitPromise();\n }\n await this._exitPromise;\n }\n _resume() {\n if (this.exited) {\n throw new Error("Go program has already exited");\n }\n this._inst.exports.resume();\n if (this.exited) {\n this._resolveExitPromise();\n }\n }\n _makeFuncWrapper(id) {\n const go = this;\n return function() {\n const event = { id, this: this, args: arguments };\n go._pendingEvent = event;\n go._resume();\n return event.result;\n };\n }\n };\n })();\n onmessage = ({ data: wasm }) => {\n let decoder = new TextDecoder();\n let fs = globalThis.fs;\n let stderr = "";\n fs.writeSync = (fd, buffer) => {\n if (fd === 1) {\n postMessage(buffer);\n } else if (fd === 2) {\n stderr += decoder.decode(buffer);\n let parts = stderr.split("\\n");\n if (parts.length > 1)\n console.log(parts.slice(0, -1).join("\\n"));\n stderr = parts[parts.length - 1];\n } else {\n throw new Error("Bad write");\n }\n return buffer.length;\n };\n let stdin = [];\n let resumeStdin;\n let stdinPos = 0;\n onmessage = ({ data }) => {\n if (data.length > 0) {\n stdin.push(data);\n if (resumeStdin)\n resumeStdin();\n }\n };\n fs.read = (fd, buffer, offset, length, position, callback) => {\n if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) {\n throw new Error("Bad read");\n }\n if (stdin.length === 0) {\n resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback);\n return;\n }\n let first = stdin[0];\n let count = Math.max(0, Math.min(length, first.length - stdinPos));\n buffer.set(first.subarray(stdinPos, stdinPos + count), offset);\n stdinPos += count;\n if (stdinPos === first.length) {\n stdin.shift();\n stdinPos = 0;\n }\n callback(null, count);\n };\n let go = new globalThis.Go();\n go.argv = ["", `--service=${"0.17.12"}`];\n tryToInstantiateModule(wasm, go).then(\n (instance) => {\n postMessage(null);\n go.run(instance);\n },\n (error) => {\n postMessage(error);\n }\n );\n };\n async function tryToInstantiateModule(wasm, go) {\n if (wasm instanceof WebAssembly.Module) {\n return WebAssembly.instantiate(wasm, go.importObject);\n }\n const res = await fetch(wasm);\n if (!res.ok)\n throw new Error(`Failed to download ${JSON.stringify(wasm)}`);\n if ("instantiateStreaming" in WebAssembly && /^application\\/wasm($|;)/i.test(res.headers.get("Content-Type") || "")) {\n const result2 = await WebAssembly.instantiateStreaming(res, go.importObject);\n return result2.instance;\n }\n const bytes = await res.arrayBuffer();\n const result = await WebAssembly.instantiate(bytes, go.importObject);\n return result.instance;\n }\n return (m) => onmessage(m);\n })'}(postMessage)`], { type: "text/javascript" });
|
1721
1755
|
worker = new Worker(URL.createObjectURL(blob));
|
1722
1756
|
} else {
|
1723
1757
|
let onmessage = ((postMessage) => {
|
@@ -1741,12 +1775,13 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
1741
1775
|
let outputBuf = "";
|
1742
1776
|
globalThis.fs = {
|
1743
1777
|
constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },
|
1778
|
+
// unused
|
1744
1779
|
writeSync(fd, buf) {
|
1745
1780
|
outputBuf += decoder.decode(buf);
|
1746
1781
|
const nl = outputBuf.lastIndexOf("\n");
|
1747
1782
|
if (nl != -1) {
|
1748
|
-
console.log(outputBuf.
|
1749
|
-
outputBuf = outputBuf.
|
1783
|
+
console.log(outputBuf.substring(0, nl));
|
1784
|
+
outputBuf = outputBuf.substring(nl + 1);
|
1750
1785
|
}
|
1751
1786
|
return buf.length;
|
1752
1787
|
},
|
@@ -1976,6 +2011,11 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
1976
2011
|
const timeOrigin = Date.now() - performance.now();
|
1977
2012
|
this.importObject = {
|
1978
2013
|
go: {
|
2014
|
+
// Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
|
2015
|
+
// may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
|
2016
|
+
// function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
|
2017
|
+
// This changes the SP, thus we have to update the SP used by the imported function.
|
2018
|
+
// func wasmExit(code int32)
|
1979
2019
|
"runtime.wasmExit": (sp) => {
|
1980
2020
|
sp >>>= 0;
|
1981
2021
|
const code = this.mem.getInt32(sp + 8, true);
|
@@ -1987,6 +2027,7 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
1987
2027
|
delete this._idPool;
|
1988
2028
|
this.exit(code);
|
1989
2029
|
},
|
2030
|
+
// func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
|
1990
2031
|
"runtime.wasmWrite": (sp) => {
|
1991
2032
|
sp >>>= 0;
|
1992
2033
|
const fd = getInt64(sp + 8);
|
@@ -1994,20 +2035,24 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
1994
2035
|
const n = this.mem.getInt32(sp + 24, true);
|
1995
2036
|
globalThis.fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
|
1996
2037
|
},
|
2038
|
+
// func resetMemoryDataView()
|
1997
2039
|
"runtime.resetMemoryDataView": (sp) => {
|
1998
2040
|
sp >>>= 0;
|
1999
2041
|
this.mem = new DataView(this._inst.exports.mem.buffer);
|
2000
2042
|
},
|
2043
|
+
// func nanotime1() int64
|
2001
2044
|
"runtime.nanotime1": (sp) => {
|
2002
2045
|
sp >>>= 0;
|
2003
2046
|
setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);
|
2004
2047
|
},
|
2048
|
+
// func walltime() (sec int64, nsec int32)
|
2005
2049
|
"runtime.walltime": (sp) => {
|
2006
2050
|
sp >>>= 0;
|
2007
|
-
const msec = new Date().getTime();
|
2051
|
+
const msec = (/* @__PURE__ */ new Date()).getTime();
|
2008
2052
|
setInt64(sp + 8, msec / 1e3);
|
2009
2053
|
this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);
|
2010
2054
|
},
|
2055
|
+
// func scheduleTimeoutEvent(delay int64) int32
|
2011
2056
|
"runtime.scheduleTimeoutEvent": (sp) => {
|
2012
2057
|
sp >>>= 0;
|
2013
2058
|
const id = this._nextCallbackTimeoutID;
|
@@ -2021,19 +2066,23 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
2021
2066
|
}
|
2022
2067
|
},
|
2023
2068
|
getInt64(sp + 8) + 1
|
2069
|
+
// setTimeout has been seen to fire up to 1 millisecond early
|
2024
2070
|
));
|
2025
2071
|
this.mem.setInt32(sp + 16, id, true);
|
2026
2072
|
},
|
2073
|
+
// func clearTimeoutEvent(id int32)
|
2027
2074
|
"runtime.clearTimeoutEvent": (sp) => {
|
2028
2075
|
sp >>>= 0;
|
2029
2076
|
const id = this.mem.getInt32(sp + 8, true);
|
2030
2077
|
clearTimeout(this._scheduledTimeouts.get(id));
|
2031
2078
|
this._scheduledTimeouts.delete(id);
|
2032
2079
|
},
|
2080
|
+
// func getRandomData(r []byte)
|
2033
2081
|
"runtime.getRandomData": (sp) => {
|
2034
2082
|
sp >>>= 0;
|
2035
2083
|
crypto.getRandomValues(loadSlice(sp + 8));
|
2036
2084
|
},
|
2085
|
+
// func finalizeRef(v ref)
|
2037
2086
|
"syscall/js.finalizeRef": (sp) => {
|
2038
2087
|
sp >>>= 0;
|
2039
2088
|
const id = this.mem.getUint32(sp + 8, true);
|
@@ -2045,32 +2094,39 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
2045
2094
|
this._idPool.push(id);
|
2046
2095
|
}
|
2047
2096
|
},
|
2097
|
+
// func stringVal(value string) ref
|
2048
2098
|
"syscall/js.stringVal": (sp) => {
|
2049
2099
|
sp >>>= 0;
|
2050
2100
|
storeValue(sp + 24, loadString(sp + 8));
|
2051
2101
|
},
|
2102
|
+
// func valueGet(v ref, p string) ref
|
2052
2103
|
"syscall/js.valueGet": (sp) => {
|
2053
2104
|
sp >>>= 0;
|
2054
2105
|
const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
|
2055
2106
|
sp = this._inst.exports.getsp() >>> 0;
|
2056
2107
|
storeValue(sp + 32, result);
|
2057
2108
|
},
|
2109
|
+
// func valueSet(v ref, p string, x ref)
|
2058
2110
|
"syscall/js.valueSet": (sp) => {
|
2059
2111
|
sp >>>= 0;
|
2060
2112
|
Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
|
2061
2113
|
},
|
2114
|
+
// func valueDelete(v ref, p string)
|
2062
2115
|
"syscall/js.valueDelete": (sp) => {
|
2063
2116
|
sp >>>= 0;
|
2064
2117
|
Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
|
2065
2118
|
},
|
2119
|
+
// func valueIndex(v ref, i int) ref
|
2066
2120
|
"syscall/js.valueIndex": (sp) => {
|
2067
2121
|
sp >>>= 0;
|
2068
2122
|
storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
|
2069
2123
|
},
|
2124
|
+
// valueSetIndex(v ref, i int, x ref)
|
2070
2125
|
"syscall/js.valueSetIndex": (sp) => {
|
2071
2126
|
sp >>>= 0;
|
2072
2127
|
Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
|
2073
2128
|
},
|
2129
|
+
// func valueCall(v ref, m string, args []ref) (ref, bool)
|
2074
2130
|
"syscall/js.valueCall": (sp) => {
|
2075
2131
|
sp >>>= 0;
|
2076
2132
|
try {
|
@@ -2087,6 +2143,7 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
2087
2143
|
this.mem.setUint8(sp + 64, 0);
|
2088
2144
|
}
|
2089
2145
|
},
|
2146
|
+
// func valueInvoke(v ref, args []ref) (ref, bool)
|
2090
2147
|
"syscall/js.valueInvoke": (sp) => {
|
2091
2148
|
sp >>>= 0;
|
2092
2149
|
try {
|
@@ -2102,6 +2159,7 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
2102
2159
|
this.mem.setUint8(sp + 48, 0);
|
2103
2160
|
}
|
2104
2161
|
},
|
2162
|
+
// func valueNew(v ref, args []ref) (ref, bool)
|
2105
2163
|
"syscall/js.valueNew": (sp) => {
|
2106
2164
|
sp >>>= 0;
|
2107
2165
|
try {
|
@@ -2117,25 +2175,30 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
2117
2175
|
this.mem.setUint8(sp + 48, 0);
|
2118
2176
|
}
|
2119
2177
|
},
|
2178
|
+
// func valueLength(v ref) int
|
2120
2179
|
"syscall/js.valueLength": (sp) => {
|
2121
2180
|
sp >>>= 0;
|
2122
2181
|
setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
|
2123
2182
|
},
|
2183
|
+
// valuePrepareString(v ref) (ref, int)
|
2124
2184
|
"syscall/js.valuePrepareString": (sp) => {
|
2125
2185
|
sp >>>= 0;
|
2126
2186
|
const str = encoder.encode(String(loadValue(sp + 8)));
|
2127
2187
|
storeValue(sp + 16, str);
|
2128
2188
|
setInt64(sp + 24, str.length);
|
2129
2189
|
},
|
2190
|
+
// valueLoadString(v ref, b []byte)
|
2130
2191
|
"syscall/js.valueLoadString": (sp) => {
|
2131
2192
|
sp >>>= 0;
|
2132
2193
|
const str = loadValue(sp + 8);
|
2133
2194
|
loadSlice(sp + 16).set(str);
|
2134
2195
|
},
|
2196
|
+
// func valueInstanceOf(v ref, t ref) bool
|
2135
2197
|
"syscall/js.valueInstanceOf": (sp) => {
|
2136
2198
|
sp >>>= 0;
|
2137
2199
|
this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);
|
2138
2200
|
},
|
2201
|
+
// func copyBytesToGo(dst []byte, src ref) (int, bool)
|
2139
2202
|
"syscall/js.copyBytesToGo": (sp) => {
|
2140
2203
|
sp >>>= 0;
|
2141
2204
|
const dst = loadSlice(sp + 8);
|
@@ -2149,6 +2212,7 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
2149
2212
|
setInt64(sp + 40, toCopy.length);
|
2150
2213
|
this.mem.setUint8(sp + 48, 1);
|
2151
2214
|
},
|
2215
|
+
// func copyBytesToJS(dst ref, src []byte) (int, bool)
|
2152
2216
|
"syscall/js.copyBytesToJS": (sp) => {
|
2153
2217
|
sp >>>= 0;
|
2154
2218
|
const dst = loadValue(sp + 8);
|
@@ -2175,6 +2239,7 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
2175
2239
|
this._inst = instance;
|
2176
2240
|
this.mem = new DataView(this._inst.exports.mem.buffer);
|
2177
2241
|
this._values = [
|
2242
|
+
// JS values that Go currently has references to, indexed by reference id
|
2178
2243
|
NaN,
|
2179
2244
|
0,
|
2180
2245
|
null,
|
@@ -2185,6 +2250,7 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
2185
2250
|
];
|
2186
2251
|
this._goRefCounts = new Array(this._values.length).fill(Infinity);
|
2187
2252
|
this._ids = /* @__PURE__ */ new Map([
|
2253
|
+
// mapping from JS values to reference ids
|
2188
2254
|
[0, 1],
|
2189
2255
|
[null, 2],
|
2190
2256
|
[true, 3],
|
@@ -2299,7 +2365,7 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
2299
2365
|
callback(null, count);
|
2300
2366
|
};
|
2301
2367
|
let go = new globalThis.Go();
|
2302
|
-
go.argv = ["", `--service=${"0.
|
2368
|
+
go.argv = ["", `--service=${"0.17.12"}`];
|
2303
2369
|
tryToInstantiateModule(wasm, go).then(
|
2304
2370
|
(instance) => {
|
2305
2371
|
postMessage(null);
|
@@ -2353,15 +2419,22 @@ var startRunningService = async (wasmURL, wasmModule, useWorker) => {
|
|
2353
2419
|
worker.postMessage(bytes);
|
2354
2420
|
},
|
2355
2421
|
isSync: false,
|
2356
|
-
|
2422
|
+
hasFS: false,
|
2357
2423
|
esbuild: browser_exports
|
2358
2424
|
});
|
2359
2425
|
await firstMessagePromise;
|
2360
2426
|
longLivedService = {
|
2361
|
-
build: (options) => new Promise((resolve, reject) => service.
|
2427
|
+
build: (options) => new Promise((resolve, reject) => service.buildOrContext({
|
2362
2428
|
callName: "build",
|
2363
2429
|
refs: null,
|
2364
|
-
|
2430
|
+
options,
|
2431
|
+
isTTY: false,
|
2432
|
+
defaultWD: "/",
|
2433
|
+
callback: (err, res) => err ? reject(err) : resolve(res)
|
2434
|
+
})),
|
2435
|
+
context: (options) => new Promise((resolve, reject) => service.buildOrContext({
|
2436
|
+
callName: "context",
|
2437
|
+
refs: null,
|
2365
2438
|
options,
|
2366
2439
|
isTTY: false,
|
2367
2440
|
defaultWD: "/",
|
@@ -2405,11 +2478,11 @@ export {
|
|
2405
2478
|
analyzeMetafileSync,
|
2406
2479
|
build,
|
2407
2480
|
buildSync,
|
2481
|
+
context,
|
2408
2482
|
browser_default as default,
|
2409
2483
|
formatMessages,
|
2410
2484
|
formatMessagesSync,
|
2411
2485
|
initialize,
|
2412
|
-
serve,
|
2413
2486
|
transform,
|
2414
2487
|
transformSync,
|
2415
2488
|
version
|