@nimbus-sh/worker 0.12.0 → 0.13.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.
- package/dist/esbuild-cli-artifact.generated.d.ts +1 -1
- package/dist/esbuild-cli-artifact.generated.js +4 -4
- package/dist/esbuild-wasm-bundle.generated.d.ts +11 -10
- package/dist/esbuild-wasm-bundle.generated.d.ts.map +1 -1
- package/dist/esbuild-wasm-bundle.generated.js +11 -10
- package/dist/facets/build-facet.d.ts +53 -0
- package/dist/facets/build-facet.d.ts.map +1 -0
- package/dist/facets/build-facet.js +346 -0
- package/dist/facets/cirrus-real.d.ts +3 -0
- package/dist/facets/cirrus-real.d.ts.map +1 -1
- package/dist/facets/cirrus-real.js +1 -2
- package/dist/facets/compose.d.ts +1 -0
- package/dist/facets/compose.d.ts.map +1 -1
- package/dist/facets/compose.js +3 -0
- package/dist/facets/data-plan.d.ts +14 -30
- package/dist/facets/data-plan.d.ts.map +1 -1
- package/dist/facets/data-plan.js +153 -13
- package/dist/facets/dev-stylesheet.d.ts +27 -0
- package/dist/facets/dev-stylesheet.d.ts.map +1 -0
- package/dist/facets/dev-stylesheet.js +65 -0
- package/dist/facets/esbuild-transform.d.ts +23 -18
- package/dist/facets/esbuild-transform.d.ts.map +1 -1
- package/dist/facets/esbuild-transform.js +63 -109
- package/dist/facets/manager.d.ts +49 -9
- package/dist/facets/manager.d.ts.map +1 -1
- package/dist/facets/manager.js +238 -69
- package/dist/facets/oxc-transform.d.ts +29 -0
- package/dist/facets/oxc-transform.d.ts.map +1 -0
- package/dist/facets/oxc-transform.js +198 -0
- package/dist/facets/prebundle-pool.d.ts +23 -0
- package/dist/facets/prebundle-pool.d.ts.map +1 -0
- package/dist/facets/prebundle-pool.js +55 -0
- package/dist/facets/process.d.ts +13 -6
- package/dist/facets/process.d.ts.map +1 -1
- package/dist/facets/process.js +37 -31
- package/dist/facets/transform-store.d.ts +4 -4
- package/dist/facets/transform-store.js +4 -4
- package/dist/facets/vite-dev-server.d.ts +89 -12
- package/dist/facets/vite-dev-server.d.ts.map +1 -1
- package/dist/facets/vite-dev-server.js +66 -43
- package/dist/hosted/commands.d.ts.map +1 -1
- package/dist/hosted/commands.js +20 -4
- package/dist/hosted/runtime.d.ts.map +1 -1
- package/dist/hosted/runtime.js +7 -2
- package/dist/hosted/services.d.ts +3 -3
- package/dist/hosted/services.d.ts.map +1 -1
- package/dist/hosted/services.js +102 -95
- package/dist/hosted/session.d.ts +1 -0
- package/dist/hosted/session.d.ts.map +1 -1
- package/dist/loaders/generated-workers.d.ts +3 -0
- package/dist/loaders/generated-workers.d.ts.map +1 -1
- package/dist/loaders/generated-workers.js +3 -0
- package/dist/napi-wasm-artifacts.generated.js +2 -2
- package/dist/node-shims-artifact.generated.d.ts +14 -1
- package/dist/node-shims-artifact.generated.d.ts.map +1 -1
- package/dist/node-shims-artifact.generated.js +23 -10
- package/dist/npm/bin-links.d.ts +7 -4
- package/dist/npm/bin-links.d.ts.map +1 -1
- package/dist/npm/bin-links.js +14 -55
- package/dist/npm/cache.d.ts +6 -0
- package/dist/npm/cache.d.ts.map +1 -1
- package/dist/npm/cache.js +26 -4
- package/dist/npm/installer.d.ts +1 -1
- package/dist/npm/installer.d.ts.map +1 -1
- package/dist/npm/installer.js +26 -52
- package/dist/npm/pre-bundle-facet.d.ts +15 -117
- package/dist/npm/pre-bundle-facet.d.ts.map +1 -1
- package/dist/npm/pre-bundle-facet.js +13 -511
- package/dist/oxc-facet-artifact.generated.d.ts +18 -0
- package/dist/oxc-facet-artifact.generated.d.ts.map +1 -0
- package/dist/oxc-facet-artifact.generated.js +17 -0
- package/dist/oxc-wasm-artifact.generated.d.ts +20 -0
- package/dist/oxc-wasm-artifact.generated.d.ts.map +1 -0
- package/dist/oxc-wasm-artifact.generated.js +19 -0
- package/dist/rolldown-facet-artifact.generated.d.ts +18 -0
- package/dist/rolldown-facet-artifact.generated.d.ts.map +1 -0
- package/dist/rolldown-facet-artifact.generated.js +17 -0
- package/dist/router/remote-api.d.ts.map +1 -1
- package/dist/router/remote-api.js +9 -0
- package/dist/runtime/bash-repl.d.ts.map +1 -1
- package/dist/runtime/bash-repl.js +1 -4
- package/dist/runtime/cpython-resident.d.ts.map +1 -1
- package/dist/runtime/cpython-resident.js +1 -0
- package/dist/runtime/esbuild-wasm-bytes.d.ts +25 -23
- package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -1
- package/dist/runtime/esbuild-wasm-bytes.js +30 -25
- package/dist/runtime/facet-loader-host.d.ts +5 -4
- package/dist/runtime/facet-loader-host.d.ts.map +1 -1
- package/dist/runtime/facet-loader-host.js +5 -4
- package/dist/runtime/node-runner.d.ts +2 -0
- package/dist/runtime/node-runner.d.ts.map +1 -1
- package/dist/runtime/node-runner.js +1 -0
- package/dist/runtime/node-shims-artifact.d.ts +8 -1
- package/dist/runtime/node-shims-artifact.d.ts.map +1 -1
- package/dist/runtime/node-shims-artifact.js +32 -4
- package/dist/runtime/node-shims.d.ts.map +1 -1
- package/dist/runtime/node-shims.js +145 -109
- package/dist/runtime/opencode-facet-runner.d.ts.map +1 -1
- package/dist/runtime/opencode-facet-runner.js +6 -2
- package/dist/runtime/oxc-wasm-bytes.d.ts +19 -0
- package/dist/runtime/oxc-wasm-bytes.d.ts.map +1 -0
- package/dist/runtime/oxc-wasm-bytes.js +39 -0
- package/dist/runtime/package-manager.js +1 -1
- package/dist/runtime/process-logs-api.d.ts.map +1 -1
- package/dist/runtime/process-logs-api.js +2 -0
- package/dist/runtime/project-fs.d.ts +8 -1
- package/dist/runtime/project-fs.d.ts.map +1 -1
- package/dist/runtime/project-fs.js +15 -1
- package/dist/runtime/python-repl.d.ts +40 -1
- package/dist/runtime/python-repl.d.ts.map +1 -1
- package/dist/runtime/python-repl.js +19 -11
- package/dist/runtime/ruby-repl.d.ts +38 -0
- package/dist/runtime/ruby-repl.d.ts.map +1 -1
- package/dist/runtime/ruby-repl.js +24 -5
- package/dist/runtime/ruby-resident.d.ts.map +1 -1
- package/dist/runtime/ruby-resident.js +2 -0
- package/dist/session/nimbus-session.d.ts +13 -8
- package/dist/session/nimbus-session.d.ts.map +1 -1
- package/dist/session/nimbus-session.js +11 -5
- package/dist/session/programmatic.d.ts +25 -30
- package/dist/session/programmatic.d.ts.map +1 -1
- package/dist/session/programmatic.js +65 -93
- package/dist/session/routes.d.ts.map +1 -1
- package/dist/session/routes.js +23 -7
- package/dist/session/rpc.d.ts +16 -6
- package/dist/session/rpc.d.ts.map +1 -1
- package/dist/session/rpc.js +53 -13
- package/dist/session/start-real-vite.d.ts +24 -9
- package/dist/session/start-real-vite.d.ts.map +1 -1
- package/dist/session/start-real-vite.js +40 -4
- package/dist/session/supervisor-op.d.ts +14 -0
- package/dist/session/supervisor-op.d.ts.map +1 -1
- package/dist/session/supervisor-op.js +49 -0
- package/dist/session/supervisor-rpc.d.ts +11 -0
- package/dist/session/supervisor-rpc.d.ts.map +1 -1
- package/dist/session/supervisor-rpc.js +18 -0
- package/dist/session/vite-command.d.ts.map +1 -1
- package/dist/session/vite-command.js +23 -19
- package/dist/session/ws-relay.d.ts.map +1 -1
- package/dist/session/ws-relay.js +13 -1
- package/dist/shell/npm-bin-entrypoints.d.ts +3 -1
- package/dist/shell/npm-bin-entrypoints.d.ts.map +1 -1
- package/dist/shell/npm-bin-entrypoints.js +53 -25
- package/dist/vfs/facet-resident-store.d.ts.map +1 -1
- package/dist/vfs/facet-resident-store.js +11 -5
- package/dist/wrangler/nimbus-wrangler.d.ts +8 -0
- package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -1
- package/dist/wrangler/nimbus-wrangler.js +54 -57
- package/package.json +6 -4
- package/public/_assets/esbuild-0.24.2.wasm +0 -0
- package/public/_assets/napi-wasm/loader/{99efae93dd1dcc2b → ab7e57fe9e8750c2}/napi-wasm-loader.mjs +4 -4
- package/public/_assets/napi-wasm/loader/{99efae93dd1dcc2b → ab7e57fe9e8750c2}/provenance.json +2 -2
- package/public/_assets/oxc/nimbus-oxc-1aa8c4c7057c6c28.provenance.json +72 -0
- package/public/_assets/oxc/nimbus-oxc-1aa8c4c7057c6c28.wasm +0 -0
- package/public/_assets/runtime/esbuild-cli-f13e6a112b03ac07.js +1143 -0
- package/public/_assets/runtime/js-interpreter-3c37c48024f0f651.js +23 -0
- package/public/_assets/runtime/js-interpreter-ops-2f4dfec6798e70fc.js +290 -0
- package/public/_assets/runtime/js-interpreter-primordials-e620a61b7e9800fa.js +1 -0
- package/public/_assets/runtime/{node-shims-f92f16c7d7c532e9.js → node-shims-e3adc4576da31e6e.js} +651 -103
- package/public/_assets/runtime/{esbuild-cli-b7aecffd4c6a36fe.js → oxc-facet-fd86fefcdf16bf9c.js} +217 -1047
- package/public/_assets/runtime/{resident-store-92386265e8b306dc.js → resident-store-009f39539ac989fc.js} +11 -5
- package/public/_assets/runtime/rolldown-facet-09983434e2dbe93e.js +15165 -0
- package/public/_assets/runtime/{vfs-write-ledger-d33ee0034446c3e0.js → vfs-write-ledger-9e9594591425a9b8.js} +4 -1
- package/scripts/acorn-primordials.mjs +637 -0
- package/scripts/bundle-esbuild-wasm.mjs +42 -50
- package/scripts/bundle-facet-workers.mjs +247 -18
- package/scripts/bundle-node-shims.mjs +29 -2
- package/scripts/bundle-oxc-wasm.mjs +105 -0
- package/scripts/interpreter-bundle.mjs +105 -0
- package/scripts/napi-wasm/build.mjs +4 -1
- package/scripts/napi-wasm/loader/napi-wasm-loader.ts +38 -3
- package/scripts/oxc-wasm/Cargo.lock +1246 -0
- package/scripts/oxc-wasm/Cargo.toml +30 -0
- package/scripts/oxc-wasm/build.mjs +249 -0
- package/scripts/oxc-wasm/examples/memory.rs +51 -0
- package/scripts/oxc-wasm/examples/transform.rs +20 -0
- package/scripts/oxc-wasm/inputs.mjs +32 -0
- package/scripts/oxc-wasm/rust-toolchain.toml +5 -0
- package/scripts/oxc-wasm/src/abi.rs +136 -0
- package/scripts/oxc-wasm/src/diagnostics.rs +49 -0
- package/scripts/oxc-wasm/src/helpers.rs +139 -0
- package/scripts/oxc-wasm/src/lib.rs +247 -0
- package/scripts/oxc-wasm/src/module.rs +978 -0
- package/scripts/oxc-wasm/src/names.rs +175 -0
- package/scripts/oxc-wasm/src/options.rs +154 -0
- package/scripts/parser-audit.mjs +492 -0
- package/scripts/rolldown-facet/entry.mjs +21 -0
- package/scripts/rolldown-facet/shims.mjs +64 -0
- package/dist/facets/esbuild-bundle-pool.d.ts +0 -43
- package/dist/facets/esbuild-bundle-pool.d.ts.map +0 -1
- package/dist/facets/esbuild-bundle-pool.js +0 -80
- package/dist/loaders/pre-bundle-preamble.d.ts +0 -44
- package/dist/loaders/pre-bundle-preamble.d.ts.map +0 -1
- package/dist/loaders/pre-bundle-preamble.js +0 -116
- package/dist/runtime/host-wasm.d.ts +0 -8
- package/dist/runtime/host-wasm.d.ts.map +0 -1
- package/dist/runtime/host-wasm.js +0 -33
- /package/public/_assets/napi-wasm/loader/{99efae93dd1dcc2b → ab7e57fe9e8750c2}/wasi-trampoline.wasm +0 -0
|
@@ -0,0 +1,1143 @@
|
|
|
1
|
+
const __esbuildGoRuntime = function (globalThis, fs) {
|
|
2
|
+
// Copyright 2018 The Go Authors. All rights reserved.
|
|
3
|
+
// Use of this source code is governed by a BSD-style
|
|
4
|
+
// license that can be found in the LICENSE file.
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
(() => {
|
|
9
|
+
const enosys = () => {
|
|
10
|
+
const err = new Error("not implemented");
|
|
11
|
+
err.code = "ENOSYS";
|
|
12
|
+
return err;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
if (!globalThis.fs) {
|
|
16
|
+
let outputBuf = "";
|
|
17
|
+
globalThis.fs = {
|
|
18
|
+
constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 }, // unused
|
|
19
|
+
writeSync(fd, buf) {
|
|
20
|
+
outputBuf += decoder.decode(buf);
|
|
21
|
+
const nl = outputBuf.lastIndexOf("\n");
|
|
22
|
+
if (nl != -1) {
|
|
23
|
+
console.log(outputBuf.substring(0, nl));
|
|
24
|
+
outputBuf = outputBuf.substring(nl + 1);
|
|
25
|
+
}
|
|
26
|
+
return buf.length;
|
|
27
|
+
},
|
|
28
|
+
write(fd, buf, offset, length, position, callback) {
|
|
29
|
+
if (offset !== 0 || length !== buf.length || position !== null) {
|
|
30
|
+
callback(enosys());
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const n = this.writeSync(fd, buf);
|
|
34
|
+
callback(null, n);
|
|
35
|
+
},
|
|
36
|
+
chmod(path, mode, callback) { callback(enosys()); },
|
|
37
|
+
chown(path, uid, gid, callback) { callback(enosys()); },
|
|
38
|
+
close(fd, callback) { callback(enosys()); },
|
|
39
|
+
fchmod(fd, mode, callback) { callback(enosys()); },
|
|
40
|
+
fchown(fd, uid, gid, callback) { callback(enosys()); },
|
|
41
|
+
fstat(fd, callback) { callback(enosys()); },
|
|
42
|
+
fsync(fd, callback) { callback(null); },
|
|
43
|
+
ftruncate(fd, length, callback) { callback(enosys()); },
|
|
44
|
+
lchown(path, uid, gid, callback) { callback(enosys()); },
|
|
45
|
+
link(path, link, callback) { callback(enosys()); },
|
|
46
|
+
lstat(path, callback) { callback(enosys()); },
|
|
47
|
+
mkdir(path, perm, callback) { callback(enosys()); },
|
|
48
|
+
open(path, flags, mode, callback) { callback(enosys()); },
|
|
49
|
+
read(fd, buffer, offset, length, position, callback) { callback(enosys()); },
|
|
50
|
+
readdir(path, callback) { callback(enosys()); },
|
|
51
|
+
readlink(path, callback) { callback(enosys()); },
|
|
52
|
+
rename(from, to, callback) { callback(enosys()); },
|
|
53
|
+
rmdir(path, callback) { callback(enosys()); },
|
|
54
|
+
stat(path, callback) { callback(enosys()); },
|
|
55
|
+
symlink(path, link, callback) { callback(enosys()); },
|
|
56
|
+
truncate(path, length, callback) { callback(enosys()); },
|
|
57
|
+
unlink(path, callback) { callback(enosys()); },
|
|
58
|
+
utimes(path, atime, mtime, callback) { callback(enosys()); },
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!globalThis.process) {
|
|
63
|
+
globalThis.process = {
|
|
64
|
+
getuid() { return -1; },
|
|
65
|
+
getgid() { return -1; },
|
|
66
|
+
geteuid() { return -1; },
|
|
67
|
+
getegid() { return -1; },
|
|
68
|
+
getgroups() { throw enosys(); },
|
|
69
|
+
pid: -1,
|
|
70
|
+
ppid: -1,
|
|
71
|
+
umask() { throw enosys(); },
|
|
72
|
+
cwd() { throw enosys(); },
|
|
73
|
+
chdir() { throw enosys(); },
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!globalThis.crypto) {
|
|
78
|
+
throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!globalThis.performance) {
|
|
82
|
+
throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!globalThis.TextEncoder) {
|
|
86
|
+
throw new Error("globalThis.TextEncoder is not available, polyfill required");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!globalThis.TextDecoder) {
|
|
90
|
+
throw new Error("globalThis.TextDecoder is not available, polyfill required");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const encoder = new TextEncoder("utf-8");
|
|
94
|
+
const decoder = new TextDecoder("utf-8");
|
|
95
|
+
|
|
96
|
+
globalThis.Go = class {
|
|
97
|
+
constructor() {
|
|
98
|
+
this.argv = ["js"];
|
|
99
|
+
this.env = {};
|
|
100
|
+
this.exit = (code) => {
|
|
101
|
+
if (code !== 0) {
|
|
102
|
+
console.warn("exit code:", code);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
this._exitPromise = new Promise((resolve) => {
|
|
106
|
+
this._resolveExitPromise = resolve;
|
|
107
|
+
});
|
|
108
|
+
this._pendingEvent = null;
|
|
109
|
+
this._scheduledTimeouts = new Map();
|
|
110
|
+
this._nextCallbackTimeoutID = 1;
|
|
111
|
+
|
|
112
|
+
const setInt64 = (addr, v) => {
|
|
113
|
+
this.mem.setUint32(addr + 0, v, true);
|
|
114
|
+
this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const setInt32 = (addr, v) => {
|
|
118
|
+
this.mem.setUint32(addr + 0, v, true);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const getInt64 = (addr) => {
|
|
122
|
+
const low = this.mem.getUint32(addr + 0, true);
|
|
123
|
+
const high = this.mem.getInt32(addr + 4, true);
|
|
124
|
+
return low + high * 4294967296;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const loadValue = (addr) => {
|
|
128
|
+
const f = this.mem.getFloat64(addr, true);
|
|
129
|
+
if (f === 0) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
if (!isNaN(f)) {
|
|
133
|
+
return f;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const id = this.mem.getUint32(addr, true);
|
|
137
|
+
return this._values[id];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const storeValue = (addr, v) => {
|
|
141
|
+
const nanHead = 0x7FF80000;
|
|
142
|
+
|
|
143
|
+
if (typeof v === "number" && v !== 0) {
|
|
144
|
+
if (isNaN(v)) {
|
|
145
|
+
this.mem.setUint32(addr + 4, nanHead, true);
|
|
146
|
+
this.mem.setUint32(addr, 0, true);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
this.mem.setFloat64(addr, v, true);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (v === undefined) {
|
|
154
|
+
this.mem.setFloat64(addr, 0, true);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let id = this._ids.get(v);
|
|
159
|
+
if (id === undefined) {
|
|
160
|
+
id = this._idPool.pop();
|
|
161
|
+
if (id === undefined) {
|
|
162
|
+
id = this._values.length;
|
|
163
|
+
}
|
|
164
|
+
this._values[id] = v;
|
|
165
|
+
this._goRefCounts[id] = 0;
|
|
166
|
+
this._ids.set(v, id);
|
|
167
|
+
}
|
|
168
|
+
this._goRefCounts[id]++;
|
|
169
|
+
let typeFlag = 0;
|
|
170
|
+
switch (typeof v) {
|
|
171
|
+
case "object":
|
|
172
|
+
if (v !== null) {
|
|
173
|
+
typeFlag = 1;
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
case "string":
|
|
177
|
+
typeFlag = 2;
|
|
178
|
+
break;
|
|
179
|
+
case "symbol":
|
|
180
|
+
typeFlag = 3;
|
|
181
|
+
break;
|
|
182
|
+
case "function":
|
|
183
|
+
typeFlag = 4;
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
|
|
187
|
+
this.mem.setUint32(addr, id, true);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const loadSlice = (addr) => {
|
|
191
|
+
const array = getInt64(addr + 0);
|
|
192
|
+
const len = getInt64(addr + 8);
|
|
193
|
+
return new Uint8Array(this._inst.exports.mem.buffer, array, len);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const loadSliceOfValues = (addr) => {
|
|
197
|
+
const array = getInt64(addr + 0);
|
|
198
|
+
const len = getInt64(addr + 8);
|
|
199
|
+
const a = new Array(len);
|
|
200
|
+
for (let i = 0; i < len; i++) {
|
|
201
|
+
a[i] = loadValue(array + i * 8);
|
|
202
|
+
}
|
|
203
|
+
return a;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const loadString = (addr) => {
|
|
207
|
+
const saddr = getInt64(addr + 0);
|
|
208
|
+
const len = getInt64(addr + 8);
|
|
209
|
+
return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const timeOrigin = Date.now() - performance.now();
|
|
213
|
+
this.importObject = {
|
|
214
|
+
_gotest: {
|
|
215
|
+
add: (a, b) => a + b,
|
|
216
|
+
},
|
|
217
|
+
gojs: {
|
|
218
|
+
// Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
|
|
219
|
+
// may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
|
|
220
|
+
// function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
|
|
221
|
+
// This changes the SP, thus we have to update the SP used by the imported function.
|
|
222
|
+
|
|
223
|
+
// func wasmExit(code int32)
|
|
224
|
+
"runtime.wasmExit": (sp) => {
|
|
225
|
+
sp >>>= 0;
|
|
226
|
+
const code = this.mem.getInt32(sp + 8, true);
|
|
227
|
+
this.exited = true;
|
|
228
|
+
delete this._inst;
|
|
229
|
+
delete this._values;
|
|
230
|
+
delete this._goRefCounts;
|
|
231
|
+
delete this._ids;
|
|
232
|
+
delete this._idPool;
|
|
233
|
+
this.exit(code);
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
// func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
|
|
237
|
+
"runtime.wasmWrite": (sp) => {
|
|
238
|
+
sp >>>= 0;
|
|
239
|
+
const fd = getInt64(sp + 8);
|
|
240
|
+
const p = getInt64(sp + 16);
|
|
241
|
+
const n = this.mem.getInt32(sp + 24, true);
|
|
242
|
+
fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
// func resetMemoryDataView()
|
|
246
|
+
"runtime.resetMemoryDataView": (sp) => {
|
|
247
|
+
sp >>>= 0;
|
|
248
|
+
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
// func nanotime1() int64
|
|
252
|
+
"runtime.nanotime1": (sp) => {
|
|
253
|
+
sp >>>= 0;
|
|
254
|
+
setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
// func walltime() (sec int64, nsec int32)
|
|
258
|
+
"runtime.walltime": (sp) => {
|
|
259
|
+
sp >>>= 0;
|
|
260
|
+
const msec = (new Date).getTime();
|
|
261
|
+
setInt64(sp + 8, msec / 1000);
|
|
262
|
+
this.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
// func scheduleTimeoutEvent(delay int64) int32
|
|
266
|
+
"runtime.scheduleTimeoutEvent": (sp) => {
|
|
267
|
+
sp >>>= 0;
|
|
268
|
+
const id = this._nextCallbackTimeoutID;
|
|
269
|
+
this._nextCallbackTimeoutID++;
|
|
270
|
+
this._scheduledTimeouts.set(id, setTimeout(
|
|
271
|
+
() => {
|
|
272
|
+
this._resume();
|
|
273
|
+
while (this._scheduledTimeouts.has(id)) {
|
|
274
|
+
// for some reason Go failed to register the timeout event, log and try again
|
|
275
|
+
// (temporary workaround for https://github.com/golang/go/issues/28975)
|
|
276
|
+
console.warn("scheduleTimeoutEvent: missed timeout event");
|
|
277
|
+
this._resume();
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
getInt64(sp + 8),
|
|
281
|
+
));
|
|
282
|
+
this.mem.setInt32(sp + 16, id, true);
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
// func clearTimeoutEvent(id int32)
|
|
286
|
+
"runtime.clearTimeoutEvent": (sp) => {
|
|
287
|
+
sp >>>= 0;
|
|
288
|
+
const id = this.mem.getInt32(sp + 8, true);
|
|
289
|
+
clearTimeout(this._scheduledTimeouts.get(id));
|
|
290
|
+
this._scheduledTimeouts.delete(id);
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
// func getRandomData(r []byte)
|
|
294
|
+
"runtime.getRandomData": (sp) => {
|
|
295
|
+
sp >>>= 0;
|
|
296
|
+
crypto.getRandomValues(loadSlice(sp + 8));
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
// func finalizeRef(v ref)
|
|
300
|
+
"syscall/js.finalizeRef": (sp) => {
|
|
301
|
+
sp >>>= 0;
|
|
302
|
+
const id = this.mem.getUint32(sp + 8, true);
|
|
303
|
+
this._goRefCounts[id]--;
|
|
304
|
+
if (this._goRefCounts[id] === 0) {
|
|
305
|
+
const v = this._values[id];
|
|
306
|
+
this._values[id] = null;
|
|
307
|
+
this._ids.delete(v);
|
|
308
|
+
this._idPool.push(id);
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
|
|
312
|
+
// func stringVal(value string) ref
|
|
313
|
+
"syscall/js.stringVal": (sp) => {
|
|
314
|
+
sp >>>= 0;
|
|
315
|
+
storeValue(sp + 24, loadString(sp + 8));
|
|
316
|
+
},
|
|
317
|
+
|
|
318
|
+
// func valueGet(v ref, p string) ref
|
|
319
|
+
"syscall/js.valueGet": (sp) => {
|
|
320
|
+
sp >>>= 0;
|
|
321
|
+
const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
|
|
322
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
323
|
+
storeValue(sp + 32, result);
|
|
324
|
+
},
|
|
325
|
+
|
|
326
|
+
// func valueSet(v ref, p string, x ref)
|
|
327
|
+
"syscall/js.valueSet": (sp) => {
|
|
328
|
+
sp >>>= 0;
|
|
329
|
+
Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
// func valueDelete(v ref, p string)
|
|
333
|
+
"syscall/js.valueDelete": (sp) => {
|
|
334
|
+
sp >>>= 0;
|
|
335
|
+
Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
// func valueIndex(v ref, i int) ref
|
|
339
|
+
"syscall/js.valueIndex": (sp) => {
|
|
340
|
+
sp >>>= 0;
|
|
341
|
+
storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
|
|
342
|
+
},
|
|
343
|
+
|
|
344
|
+
// valueSetIndex(v ref, i int, x ref)
|
|
345
|
+
"syscall/js.valueSetIndex": (sp) => {
|
|
346
|
+
sp >>>= 0;
|
|
347
|
+
Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
// func valueCall(v ref, m string, args []ref) (ref, bool)
|
|
351
|
+
"syscall/js.valueCall": (sp) => {
|
|
352
|
+
sp >>>= 0;
|
|
353
|
+
try {
|
|
354
|
+
const v = loadValue(sp + 8);
|
|
355
|
+
const m = Reflect.get(v, loadString(sp + 16));
|
|
356
|
+
const args = loadSliceOfValues(sp + 32);
|
|
357
|
+
const result = Reflect.apply(m, v, args);
|
|
358
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
359
|
+
storeValue(sp + 56, result);
|
|
360
|
+
this.mem.setUint8(sp + 64, 1);
|
|
361
|
+
} catch (err) {
|
|
362
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
363
|
+
storeValue(sp + 56, err);
|
|
364
|
+
this.mem.setUint8(sp + 64, 0);
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
|
|
368
|
+
// func valueInvoke(v ref, args []ref) (ref, bool)
|
|
369
|
+
"syscall/js.valueInvoke": (sp) => {
|
|
370
|
+
sp >>>= 0;
|
|
371
|
+
try {
|
|
372
|
+
const v = loadValue(sp + 8);
|
|
373
|
+
const args = loadSliceOfValues(sp + 16);
|
|
374
|
+
const result = Reflect.apply(v, undefined, args);
|
|
375
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
376
|
+
storeValue(sp + 40, result);
|
|
377
|
+
this.mem.setUint8(sp + 48, 1);
|
|
378
|
+
} catch (err) {
|
|
379
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
380
|
+
storeValue(sp + 40, err);
|
|
381
|
+
this.mem.setUint8(sp + 48, 0);
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
|
|
385
|
+
// func valueNew(v ref, args []ref) (ref, bool)
|
|
386
|
+
"syscall/js.valueNew": (sp) => {
|
|
387
|
+
sp >>>= 0;
|
|
388
|
+
try {
|
|
389
|
+
const v = loadValue(sp + 8);
|
|
390
|
+
const args = loadSliceOfValues(sp + 16);
|
|
391
|
+
const result = Reflect.construct(v, args);
|
|
392
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
393
|
+
storeValue(sp + 40, result);
|
|
394
|
+
this.mem.setUint8(sp + 48, 1);
|
|
395
|
+
} catch (err) {
|
|
396
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
397
|
+
storeValue(sp + 40, err);
|
|
398
|
+
this.mem.setUint8(sp + 48, 0);
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
|
|
402
|
+
// func valueLength(v ref) int
|
|
403
|
+
"syscall/js.valueLength": (sp) => {
|
|
404
|
+
sp >>>= 0;
|
|
405
|
+
setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
|
|
406
|
+
},
|
|
407
|
+
|
|
408
|
+
// valuePrepareString(v ref) (ref, int)
|
|
409
|
+
"syscall/js.valuePrepareString": (sp) => {
|
|
410
|
+
sp >>>= 0;
|
|
411
|
+
const str = encoder.encode(String(loadValue(sp + 8)));
|
|
412
|
+
storeValue(sp + 16, str);
|
|
413
|
+
setInt64(sp + 24, str.length);
|
|
414
|
+
},
|
|
415
|
+
|
|
416
|
+
// valueLoadString(v ref, b []byte)
|
|
417
|
+
"syscall/js.valueLoadString": (sp) => {
|
|
418
|
+
sp >>>= 0;
|
|
419
|
+
const str = loadValue(sp + 8);
|
|
420
|
+
loadSlice(sp + 16).set(str);
|
|
421
|
+
},
|
|
422
|
+
|
|
423
|
+
// func valueInstanceOf(v ref, t ref) bool
|
|
424
|
+
"syscall/js.valueInstanceOf": (sp) => {
|
|
425
|
+
sp >>>= 0;
|
|
426
|
+
this.mem.setUint8(sp + 24, (loadValue(sp + 8) instanceof loadValue(sp + 16)) ? 1 : 0);
|
|
427
|
+
},
|
|
428
|
+
|
|
429
|
+
// func copyBytesToGo(dst []byte, src ref) (int, bool)
|
|
430
|
+
"syscall/js.copyBytesToGo": (sp) => {
|
|
431
|
+
sp >>>= 0;
|
|
432
|
+
const dst = loadSlice(sp + 8);
|
|
433
|
+
const src = loadValue(sp + 32);
|
|
434
|
+
if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
|
|
435
|
+
this.mem.setUint8(sp + 48, 0);
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
const toCopy = src.subarray(0, dst.length);
|
|
439
|
+
dst.set(toCopy);
|
|
440
|
+
setInt64(sp + 40, toCopy.length);
|
|
441
|
+
this.mem.setUint8(sp + 48, 1);
|
|
442
|
+
},
|
|
443
|
+
|
|
444
|
+
// func copyBytesToJS(dst ref, src []byte) (int, bool)
|
|
445
|
+
"syscall/js.copyBytesToJS": (sp) => {
|
|
446
|
+
sp >>>= 0;
|
|
447
|
+
const dst = loadValue(sp + 8);
|
|
448
|
+
const src = loadSlice(sp + 16);
|
|
449
|
+
if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
|
|
450
|
+
this.mem.setUint8(sp + 48, 0);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const toCopy = src.subarray(0, dst.length);
|
|
454
|
+
dst.set(toCopy);
|
|
455
|
+
setInt64(sp + 40, toCopy.length);
|
|
456
|
+
this.mem.setUint8(sp + 48, 1);
|
|
457
|
+
},
|
|
458
|
+
|
|
459
|
+
"debug": (value) => {
|
|
460
|
+
console.log(value);
|
|
461
|
+
},
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
async run(instance) {
|
|
467
|
+
if (!(instance instanceof WebAssembly.Instance)) {
|
|
468
|
+
throw new Error("Go.run: WebAssembly.Instance expected");
|
|
469
|
+
}
|
|
470
|
+
this._inst = instance;
|
|
471
|
+
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
472
|
+
this._values = [ // JS values that Go currently has references to, indexed by reference id
|
|
473
|
+
NaN,
|
|
474
|
+
0,
|
|
475
|
+
null,
|
|
476
|
+
true,
|
|
477
|
+
false,
|
|
478
|
+
globalThis,
|
|
479
|
+
this,
|
|
480
|
+
];
|
|
481
|
+
this._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id
|
|
482
|
+
this._ids = new Map([ // mapping from JS values to reference ids
|
|
483
|
+
[0, 1],
|
|
484
|
+
[null, 2],
|
|
485
|
+
[true, 3],
|
|
486
|
+
[false, 4],
|
|
487
|
+
[globalThis, 5],
|
|
488
|
+
[this, 6],
|
|
489
|
+
]);
|
|
490
|
+
this._idPool = []; // unused ids that have been garbage collected
|
|
491
|
+
this.exited = false; // whether the Go program has exited
|
|
492
|
+
|
|
493
|
+
// Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.
|
|
494
|
+
let offset = 4096;
|
|
495
|
+
|
|
496
|
+
const strPtr = (str) => {
|
|
497
|
+
const ptr = offset;
|
|
498
|
+
const bytes = encoder.encode(str + "\0");
|
|
499
|
+
new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
|
|
500
|
+
offset += bytes.length;
|
|
501
|
+
if (offset % 8 !== 0) {
|
|
502
|
+
offset += 8 - (offset % 8);
|
|
503
|
+
}
|
|
504
|
+
return ptr;
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
const argc = this.argv.length;
|
|
508
|
+
|
|
509
|
+
const argvPtrs = [];
|
|
510
|
+
this.argv.forEach((arg) => {
|
|
511
|
+
argvPtrs.push(strPtr(arg));
|
|
512
|
+
});
|
|
513
|
+
argvPtrs.push(0);
|
|
514
|
+
|
|
515
|
+
const keys = Object.keys(this.env).sort();
|
|
516
|
+
keys.forEach((key) => {
|
|
517
|
+
argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
|
|
518
|
+
});
|
|
519
|
+
argvPtrs.push(0);
|
|
520
|
+
|
|
521
|
+
const argv = offset;
|
|
522
|
+
argvPtrs.forEach((ptr) => {
|
|
523
|
+
this.mem.setUint32(offset, ptr, true);
|
|
524
|
+
this.mem.setUint32(offset + 4, 0, true);
|
|
525
|
+
offset += 8;
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
// The linker guarantees global data starts from at least wasmMinDataAddr.
|
|
529
|
+
// Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.
|
|
530
|
+
const wasmMinDataAddr = 4096 + 8192;
|
|
531
|
+
if (offset >= wasmMinDataAddr) {
|
|
532
|
+
throw new Error("total length of command line and environment variables exceeds limit");
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
this._inst.exports.run(argc, argv);
|
|
536
|
+
if (this.exited) {
|
|
537
|
+
this._resolveExitPromise();
|
|
538
|
+
}
|
|
539
|
+
await this._exitPromise;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
_resume() {
|
|
543
|
+
if (this.exited) {
|
|
544
|
+
throw new Error("Go program has already exited");
|
|
545
|
+
}
|
|
546
|
+
this._inst.exports.resume();
|
|
547
|
+
if (this.exited) {
|
|
548
|
+
this._resolveExitPromise();
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
_makeFuncWrapper(id) {
|
|
553
|
+
const go = this;
|
|
554
|
+
return function () {
|
|
555
|
+
const event = { id: id, this: this, args: arguments };
|
|
556
|
+
go._pendingEvent = event;
|
|
557
|
+
go._resume();
|
|
558
|
+
return event.result;
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
})();
|
|
563
|
+
|
|
564
|
+
return globalThis.Go;
|
|
565
|
+
};
|
|
566
|
+
"use strict";
|
|
567
|
+
(() => {
|
|
568
|
+
function disposeRpcResource(value) {
|
|
569
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null)
|
|
570
|
+
return false;
|
|
571
|
+
const disposerKey = Symbol.dispose;
|
|
572
|
+
if (!disposerKey)
|
|
573
|
+
return false;
|
|
574
|
+
const disposer = Reflect.get(value, disposerKey);
|
|
575
|
+
if (typeof disposer !== "function")
|
|
576
|
+
return false;
|
|
577
|
+
try {
|
|
578
|
+
Reflect.apply(disposer, value, []);
|
|
579
|
+
return true;
|
|
580
|
+
} catch {
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
var FILESYSTEM_RPC_METHODS = {
|
|
586
|
+
stat: "stat",
|
|
587
|
+
readFile: "readFileBytes",
|
|
588
|
+
writeFile: "writeFile",
|
|
589
|
+
readRange: "fsReadRange",
|
|
590
|
+
writeRange: "fsWriteRange",
|
|
591
|
+
truncate: "fsTruncate",
|
|
592
|
+
utimes: "utimes",
|
|
593
|
+
chmod: "chmod",
|
|
594
|
+
access: "access",
|
|
595
|
+
chown: "chown",
|
|
596
|
+
open: "fsOpen",
|
|
597
|
+
read: "fsRead",
|
|
598
|
+
write: "fsWrite",
|
|
599
|
+
close: "fsClose",
|
|
600
|
+
readdir: "readdir",
|
|
601
|
+
mkdir: "mkdir",
|
|
602
|
+
unlink: "unlink",
|
|
603
|
+
rmdir: "rmdir",
|
|
604
|
+
rename: "rename",
|
|
605
|
+
readlink: "readlink",
|
|
606
|
+
linkLeadsTo: "fsLinkLeadsTo",
|
|
607
|
+
symlink: "symlink",
|
|
608
|
+
fsync: "fsSync",
|
|
609
|
+
revision: "fsRevision",
|
|
610
|
+
acquire: "fsAcquire",
|
|
611
|
+
list: "fsList",
|
|
612
|
+
realpath: "fsRealpath",
|
|
613
|
+
remove: "fsRemove",
|
|
614
|
+
copyFile: "fsCopyFile",
|
|
615
|
+
copyTree: "fsCopyTree",
|
|
616
|
+
fstat: "fsFstat",
|
|
617
|
+
dup: "fsDup",
|
|
618
|
+
seek: "fsSeek",
|
|
619
|
+
setStatus: "fsSetStatus",
|
|
620
|
+
readdirHandle: "fsReaddirHandle",
|
|
621
|
+
ftruncate: "fsFtruncate",
|
|
622
|
+
fchmod: "fsFchmod",
|
|
623
|
+
fchown: "fsFchown",
|
|
624
|
+
futimes: "fsFutimes",
|
|
625
|
+
appendOnce: "fsAppend",
|
|
626
|
+
acknowledgeAppend: "fsAppendAck",
|
|
627
|
+
writeBatch: "writeBatch",
|
|
628
|
+
writeStream: "writeBatchStream",
|
|
629
|
+
acquireExclusiveMutation: "fsAcquireExclusiveMutation",
|
|
630
|
+
releaseExclusiveMutation: "fsReleaseExclusiveMutation"
|
|
631
|
+
};
|
|
632
|
+
function pending(result) {
|
|
633
|
+
return (typeof result === "object" || typeof result === "function") && result !== null && typeof result.then === "function";
|
|
634
|
+
}
|
|
635
|
+
function hop(result) {
|
|
636
|
+
return pending(result) ? Promise.resolve(result) : result;
|
|
637
|
+
}
|
|
638
|
+
function bytes(result) {
|
|
639
|
+
return pending(result) ? Promise.resolve(result).then(asBytes) : asBytes(result);
|
|
640
|
+
}
|
|
641
|
+
function asBytes(value) {
|
|
642
|
+
return value instanceof ArrayBuffer ? new Uint8Array(value) : value;
|
|
643
|
+
}
|
|
644
|
+
var NODE_SHIM_RPC_METHODS = [
|
|
645
|
+
"readFile",
|
|
646
|
+
"writeFileStat",
|
|
647
|
+
"lstat",
|
|
648
|
+
"exists",
|
|
649
|
+
"hasLegacySymlinkUnder",
|
|
650
|
+
"setUmask",
|
|
651
|
+
"fsAcquired",
|
|
652
|
+
"fsStorageGrant",
|
|
653
|
+
"fsReadRangeUncached",
|
|
654
|
+
"fsReadBatch"
|
|
655
|
+
];
|
|
656
|
+
var SUPERVISOR_ANSWERED_METHODS = [
|
|
657
|
+
...Object.values(FILESYSTEM_RPC_METHODS).filter(
|
|
658
|
+
(name) => name !== FILESYSTEM_RPC_METHODS.writeStream
|
|
659
|
+
),
|
|
660
|
+
...NODE_SHIM_RPC_METHODS
|
|
661
|
+
];
|
|
662
|
+
var ANSWERED = new Set(SUPERVISOR_ANSWERED_METHODS);
|
|
663
|
+
function isSupervisorAnsweredMethod(name) {
|
|
664
|
+
return typeof name === "string" && ANSWERED.has(name);
|
|
665
|
+
}
|
|
666
|
+
var STANDARD_ERRORS = {
|
|
667
|
+
EvalError,
|
|
668
|
+
RangeError,
|
|
669
|
+
ReferenceError,
|
|
670
|
+
SyntaxError,
|
|
671
|
+
TypeError,
|
|
672
|
+
URIError
|
|
673
|
+
};
|
|
674
|
+
function supervisorRefusalError(refusal) {
|
|
675
|
+
const Standard = Object.hasOwn(STANDARD_ERRORS, refusal.name) ? STANDARD_ERRORS[refusal.name] : void 0;
|
|
676
|
+
const error = new (Standard ?? Error)(refusal.message);
|
|
677
|
+
if (!Standard && refusal.name !== "Error") {
|
|
678
|
+
Object.defineProperty(error, "name", { value: refusal.name, configurable: true, writable: true });
|
|
679
|
+
}
|
|
680
|
+
for (const [key, value] of Object.entries(refusal.properties)) {
|
|
681
|
+
Object.defineProperty(error, key, { value, configurable: true, enumerable: true, writable: true });
|
|
682
|
+
}
|
|
683
|
+
for (const [key, value] of Object.entries(refusal.errors)) {
|
|
684
|
+
Object.defineProperty(error, key, { value: supervisorRefusalError(value), configurable: true, enumerable: true, writable: true });
|
|
685
|
+
}
|
|
686
|
+
return error;
|
|
687
|
+
}
|
|
688
|
+
function isAnsweringStub(supervisor) {
|
|
689
|
+
return typeof Reflect.get(supervisor, "answer") === "function";
|
|
690
|
+
}
|
|
691
|
+
function answeringSupervisor(supervisor) {
|
|
692
|
+
if (!isAnsweringStub(supervisor)) return supervisor;
|
|
693
|
+
const stub = supervisor;
|
|
694
|
+
return new Proxy(supervisor, {
|
|
695
|
+
get(target, name) {
|
|
696
|
+
if (!isSupervisorAnsweredMethod(name)) return Reflect.get(target, name);
|
|
697
|
+
return async (...args) => {
|
|
698
|
+
const answer = await stub.answer(name, args);
|
|
699
|
+
try {
|
|
700
|
+
if ("refusal" in answer) throw supervisorRefusalError(answer.refusal);
|
|
701
|
+
return answer.value;
|
|
702
|
+
} finally {
|
|
703
|
+
disposeRpcResource(answer);
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
function supervisorFilesystem(remote, local) {
|
|
710
|
+
const supervisor = answeringSupervisor(remote);
|
|
711
|
+
return {
|
|
712
|
+
synchronous: local,
|
|
713
|
+
stat: (...args) => hop(supervisor.stat(...args)),
|
|
714
|
+
readFile: (...args) => bytes(supervisor.readFileBytes(...args)),
|
|
715
|
+
writeFile: (...args) => hop(supervisor.writeFile(...args)),
|
|
716
|
+
readRange: (...args) => bytes(supervisor.fsReadRange(...args)),
|
|
717
|
+
writeRange: (...args) => hop(supervisor.fsWriteRange(...args)),
|
|
718
|
+
truncate: (...args) => hop(supervisor.fsTruncate(...args)),
|
|
719
|
+
utimes: (...args) => hop(supervisor.utimes(...args)),
|
|
720
|
+
chmod: (...args) => hop(supervisor.chmod(...args)),
|
|
721
|
+
access: (...args) => hop(supervisor.access(...args)),
|
|
722
|
+
chown: (...args) => hop(supervisor.chown(...args)),
|
|
723
|
+
open: (...args) => hop(supervisor.fsOpen(...args)),
|
|
724
|
+
read: (...args) => bytes(supervisor.fsRead(...args)),
|
|
725
|
+
write: (...args) => hop(supervisor.fsWrite(...args)),
|
|
726
|
+
close: (...args) => hop(supervisor.fsClose(...args)),
|
|
727
|
+
readdir: (...args) => hop(supervisor.readdir(...args)),
|
|
728
|
+
mkdir: (...args) => hop(supervisor.mkdir(...args)),
|
|
729
|
+
unlink: (...args) => hop(supervisor.unlink(...args)),
|
|
730
|
+
rmdir: (...args) => hop(supervisor.rmdir(...args)),
|
|
731
|
+
rename: (...args) => hop(supervisor.rename(...args)),
|
|
732
|
+
readlink: (...args) => hop(supervisor.readlink(...args)),
|
|
733
|
+
linkLeadsTo: (...args) => hop(supervisor.fsLinkLeadsTo(...args)),
|
|
734
|
+
symlink: (...args) => hop(supervisor.symlink(...args)),
|
|
735
|
+
fsync: (...args) => hop(supervisor.fsSync(...args)),
|
|
736
|
+
revision: (...args) => hop(supervisor.fsRevision(...args)),
|
|
737
|
+
acquire: (...args) => hop(supervisor.fsAcquire(...args)),
|
|
738
|
+
list: (...args) => hop(supervisor.fsList(...args)),
|
|
739
|
+
realpath: (...args) => hop(supervisor.fsRealpath(...args)),
|
|
740
|
+
remove: (...args) => hop(supervisor.fsRemove(...args)),
|
|
741
|
+
copyFile: (...args) => hop(supervisor.fsCopyFile(...args)),
|
|
742
|
+
copyTree: (...args) => hop(supervisor.fsCopyTree(...args)),
|
|
743
|
+
fstat: (...args) => hop(supervisor.fsFstat(...args)),
|
|
744
|
+
dup: (...args) => hop(supervisor.fsDup(...args)),
|
|
745
|
+
seek: (...args) => hop(supervisor.fsSeek(...args)),
|
|
746
|
+
setStatus: (...args) => hop(supervisor.fsSetStatus(...args)),
|
|
747
|
+
readdirHandle: (...args) => hop(supervisor.fsReaddirHandle(...args)),
|
|
748
|
+
ftruncate: (...args) => hop(supervisor.fsFtruncate(...args)),
|
|
749
|
+
fchmod: (...args) => hop(supervisor.fsFchmod(...args)),
|
|
750
|
+
fchown: (...args) => hop(supervisor.fsFchown(...args)),
|
|
751
|
+
futimes: (...args) => hop(supervisor.fsFutimes(...args)),
|
|
752
|
+
appendOnce: (...args) => hop(supervisor.fsAppend(...args)),
|
|
753
|
+
acknowledgeAppend: (...args) => hop(supervisor.fsAppendAck(...args)),
|
|
754
|
+
writeBatch: (...args) => hop(supervisor.writeBatch(...args)),
|
|
755
|
+
writeStream: (...args) => Promise.resolve(supervisor.writeBatchStream(...args)),
|
|
756
|
+
writeFileFrom: async (path) => {
|
|
757
|
+
const name = typeof path === "string" ? path : path.path;
|
|
758
|
+
throw Object.assign(new Error(`ENOTSUP: a streamed whole-file write is a host operation, write '${name}' as a W7 stream`), { code: "ENOTSUP" });
|
|
759
|
+
},
|
|
760
|
+
acquireExclusiveMutation: (...args) => hop(supervisor.fsAcquireExclusiveMutation(...args)),
|
|
761
|
+
releaseExclusiveMutation: (...args) => hop(supervisor.fsReleaseExclusiveMutation(...args))
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
var O_WRONLY = 1;
|
|
766
|
+
var O_RDWR = 2;
|
|
767
|
+
var O_CREAT = 64;
|
|
768
|
+
var O_EXCL = 128;
|
|
769
|
+
var O_TRUNC = 512;
|
|
770
|
+
var O_APPEND = 1024;
|
|
771
|
+
var O_DIRECTORY = 65536;
|
|
772
|
+
var CONSTANTS = { O_RDONLY: 0, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND, O_DIRECTORY };
|
|
773
|
+
var GO_ERRNO_CODES = {
|
|
774
|
+
EPERM: true,
|
|
775
|
+
ENOENT: true,
|
|
776
|
+
EINTR: true,
|
|
777
|
+
EIO: true,
|
|
778
|
+
EBADF: true,
|
|
779
|
+
EAGAIN: true,
|
|
780
|
+
ENOMEM: true,
|
|
781
|
+
EACCES: true,
|
|
782
|
+
EBUSY: true,
|
|
783
|
+
EEXIST: true,
|
|
784
|
+
EXDEV: true,
|
|
785
|
+
ENOTDIR: true,
|
|
786
|
+
EISDIR: true,
|
|
787
|
+
EINVAL: true,
|
|
788
|
+
EMFILE: true,
|
|
789
|
+
ENOTTY: true,
|
|
790
|
+
EFBIG: true,
|
|
791
|
+
ENOSPC: true,
|
|
792
|
+
ESPIPE: true,
|
|
793
|
+
EROFS: true,
|
|
794
|
+
EMLINK: true,
|
|
795
|
+
EPIPE: true,
|
|
796
|
+
ENAMETOOLONG: true,
|
|
797
|
+
ENOTEMPTY: true,
|
|
798
|
+
ENOSYS: true
|
|
799
|
+
};
|
|
800
|
+
var WRITE_SLICE_BYTES = 1 << 20;
|
|
801
|
+
var S_IFREG = 32768;
|
|
802
|
+
var S_IFDIR = 16384;
|
|
803
|
+
var S_IFLNK = 40960;
|
|
804
|
+
var S_IFIFO = 4096;
|
|
805
|
+
function errno(code, detail) {
|
|
806
|
+
return Object.assign(new Error(`${code}: ${detail}`), { code });
|
|
807
|
+
}
|
|
808
|
+
function goError(error) {
|
|
809
|
+
const code = typeof error === "object" && error !== null ? Reflect.get(error, "code") : void 0;
|
|
810
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
811
|
+
return Object.assign(new Error(message), {
|
|
812
|
+
code: typeof code === "string" && GO_ERRNO_CODES[code] ? code : "EIO"
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
function resolvePath(cwd, path) {
|
|
816
|
+
const parts = [];
|
|
817
|
+
for (const part of (path.startsWith("/") ? path : `${cwd}/${path}`).split("/")) {
|
|
818
|
+
if (part === "" || part === ".") continue;
|
|
819
|
+
if (part === "..") parts.pop();
|
|
820
|
+
else parts.push(part);
|
|
821
|
+
}
|
|
822
|
+
return `/${parts.join("/")}`;
|
|
823
|
+
}
|
|
824
|
+
function goStats(stat, size = stat.size) {
|
|
825
|
+
const type = stat.type === "directory" ? S_IFDIR : stat.type === "symlink" ? S_IFLNK : S_IFREG;
|
|
826
|
+
return {
|
|
827
|
+
dev: stat.dev,
|
|
828
|
+
ino: stat.ino,
|
|
829
|
+
mode: type | stat.mode & 4095,
|
|
830
|
+
nlink: stat.nlink,
|
|
831
|
+
uid: stat.uid,
|
|
832
|
+
gid: stat.gid,
|
|
833
|
+
rdev: 0,
|
|
834
|
+
size,
|
|
835
|
+
blksize: 4096,
|
|
836
|
+
blocks: Math.ceil(size / 512),
|
|
837
|
+
atimeMs: stat.atime,
|
|
838
|
+
mtimeMs: stat.mtime,
|
|
839
|
+
ctimeMs: stat.ctime,
|
|
840
|
+
isDirectory: () => stat.type === "directory"
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
var Stdio = class {
|
|
844
|
+
constructor(stdin, output) {
|
|
845
|
+
this.stdin = stdin;
|
|
846
|
+
this.output = output;
|
|
847
|
+
}
|
|
848
|
+
stdin;
|
|
849
|
+
output;
|
|
850
|
+
stdinOffset = 0;
|
|
851
|
+
held = [];
|
|
852
|
+
hold(fd, bytes2) {
|
|
853
|
+
this.held.push({ fd, bytes: bytes2 });
|
|
854
|
+
}
|
|
855
|
+
async write(fd, bytes2) {
|
|
856
|
+
await this.flush();
|
|
857
|
+
for (let done = 0; done < bytes2.length; done += WRITE_SLICE_BYTES) {
|
|
858
|
+
await this.output(fd, bytes2.slice(done, done + WRITE_SLICE_BYTES));
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
async flush() {
|
|
862
|
+
for (let next = this.held.shift(); next; next = this.held.shift()) {
|
|
863
|
+
await this.output(next.fd, next.bytes);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
read(buffer, offset, length) {
|
|
867
|
+
const input = this.stdin ?? new Uint8Array(0);
|
|
868
|
+
const chunk = input.subarray(this.stdinOffset, this.stdinOffset + length);
|
|
869
|
+
buffer.set(chunk, offset);
|
|
870
|
+
this.stdinOffset += chunk.length;
|
|
871
|
+
return chunk.length;
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
var isOutput = (fd) => fd === 1 || fd === 2;
|
|
875
|
+
function goFilesystem(vfs, stdio, state, live, crash) {
|
|
876
|
+
const files = new Map();
|
|
877
|
+
let nextFd = 3;
|
|
878
|
+
const at = (path) => resolvePath(state.cwd, path);
|
|
879
|
+
const add = (file2) => {
|
|
880
|
+
const fd = nextFd++;
|
|
881
|
+
files.set(fd, file2);
|
|
882
|
+
return fd;
|
|
883
|
+
};
|
|
884
|
+
const file = (fd) => {
|
|
885
|
+
const open = files.get(fd);
|
|
886
|
+
if (!open) throw errno("EBADF", `fd ${fd}`);
|
|
887
|
+
return open;
|
|
888
|
+
};
|
|
889
|
+
const settle = (work, callback) => {
|
|
890
|
+
Promise.resolve().then(work).then(
|
|
891
|
+
(value) => {
|
|
892
|
+
if (live()) deliver(callback, null, value);
|
|
893
|
+
},
|
|
894
|
+
(error) => {
|
|
895
|
+
if (live()) deliver(callback, goError(error), void 0);
|
|
896
|
+
}
|
|
897
|
+
);
|
|
898
|
+
};
|
|
899
|
+
const deliver = (callback, error, value) => {
|
|
900
|
+
try {
|
|
901
|
+
callback(error, value);
|
|
902
|
+
} catch (trap) {
|
|
903
|
+
crash(trap);
|
|
904
|
+
}
|
|
905
|
+
};
|
|
906
|
+
const stat = async (path, followSymlinks) => {
|
|
907
|
+
const found = await vfs.stat(path, { followSymlinks });
|
|
908
|
+
if (!found) throw errno("ENOENT", path);
|
|
909
|
+
return goStats(found);
|
|
910
|
+
};
|
|
911
|
+
const fs = {
|
|
912
|
+
constants: CONSTANTS,
|
|
913
|
+
writeSync(fd, buffer) {
|
|
914
|
+
if (isOutput(fd)) stdio.hold(fd, buffer.slice());
|
|
915
|
+
return buffer.length;
|
|
916
|
+
},
|
|
917
|
+
write(fd, buffer, offset, length, position, callback) {
|
|
918
|
+
settle(async () => {
|
|
919
|
+
const data = buffer.subarray(offset, offset + length);
|
|
920
|
+
if (isOutput(fd)) {
|
|
921
|
+
await stdio.write(fd, data);
|
|
922
|
+
return length;
|
|
923
|
+
}
|
|
924
|
+
const open = file(fd);
|
|
925
|
+
if (open.kind !== "handle") throw errno("EBADF", `fd ${fd} is not open for writing`);
|
|
926
|
+
for (let done = 0; done < length; ) {
|
|
927
|
+
const slice = data.slice(done, Math.min(length, done + WRITE_SLICE_BYTES));
|
|
928
|
+
const written = await vfs.write(open.handle, position === null ? null : position + done, slice);
|
|
929
|
+
if (written <= 0) throw errno("EIO", `short write to ${open.path}`);
|
|
930
|
+
done += written;
|
|
931
|
+
}
|
|
932
|
+
return length;
|
|
933
|
+
}, callback);
|
|
934
|
+
},
|
|
935
|
+
read(fd, buffer, offset, length, position, callback) {
|
|
936
|
+
settle(async () => {
|
|
937
|
+
if (fd === 0) return stdio.read(buffer, offset, length);
|
|
938
|
+
const open = file(fd);
|
|
939
|
+
if (open.kind === "directory") throw errno("EISDIR", open.path);
|
|
940
|
+
if (open.kind === "bytes") {
|
|
941
|
+
const start = position ?? open.position;
|
|
942
|
+
const chunk = open.bytes.subarray(start, start + length);
|
|
943
|
+
buffer.set(chunk, offset);
|
|
944
|
+
if (position === null) open.position += chunk.length;
|
|
945
|
+
return chunk.length;
|
|
946
|
+
}
|
|
947
|
+
const bytes2 = await vfs.read(open.handle, position, length);
|
|
948
|
+
buffer.set(bytes2, offset);
|
|
949
|
+
return bytes2.length;
|
|
950
|
+
}, callback);
|
|
951
|
+
},
|
|
952
|
+
open(path, flags, mode, callback) {
|
|
953
|
+
settle(async () => {
|
|
954
|
+
const target = at(path);
|
|
955
|
+
const access = flags & 3;
|
|
956
|
+
if (access === 0 && (flags & (O_CREAT | O_TRUNC | O_APPEND)) === 0) {
|
|
957
|
+
const found = await vfs.stat(target);
|
|
958
|
+
if (!found) throw errno("ENOENT", target);
|
|
959
|
+
if (found.type === "directory") return add({ kind: "directory", path: target, stat: goStats(found) });
|
|
960
|
+
if (flags & O_DIRECTORY) throw errno("ENOTDIR", target);
|
|
961
|
+
const bytes2 = await vfs.readFile(target);
|
|
962
|
+
if (!bytes2) throw errno("ENOENT", target);
|
|
963
|
+
return add({ kind: "bytes", path: target, bytes: bytes2, stat: goStats(found, bytes2.length), position: 0 });
|
|
964
|
+
}
|
|
965
|
+
const openFlags = {
|
|
966
|
+
read: access === O_RDWR,
|
|
967
|
+
write: true,
|
|
968
|
+
create: (flags & O_CREAT) !== 0,
|
|
969
|
+
exclusive: (flags & O_EXCL) !== 0,
|
|
970
|
+
truncate: (flags & O_TRUNC) !== 0,
|
|
971
|
+
append: (flags & O_APPEND) !== 0,
|
|
972
|
+
mode
|
|
973
|
+
};
|
|
974
|
+
const handle = await vfs.open(target, openFlags);
|
|
975
|
+
return add({ kind: "handle", path: target, handle: handle.id });
|
|
976
|
+
}, callback);
|
|
977
|
+
},
|
|
978
|
+
close(fd, callback) {
|
|
979
|
+
settle(async () => {
|
|
980
|
+
const open = file(fd);
|
|
981
|
+
files.delete(fd);
|
|
982
|
+
if (open.kind === "handle") await vfs.close(open.handle);
|
|
983
|
+
}, callback);
|
|
984
|
+
},
|
|
985
|
+
fstat(fd, callback) {
|
|
986
|
+
settle(async () => {
|
|
987
|
+
if (fd <= 2) {
|
|
988
|
+
return {
|
|
989
|
+
dev: 0,
|
|
990
|
+
ino: fd,
|
|
991
|
+
mode: S_IFIFO | 384,
|
|
992
|
+
nlink: 1,
|
|
993
|
+
uid: 0,
|
|
994
|
+
gid: 0,
|
|
995
|
+
rdev: 0,
|
|
996
|
+
size: 0,
|
|
997
|
+
blksize: 4096,
|
|
998
|
+
blocks: 0,
|
|
999
|
+
atimeMs: 0,
|
|
1000
|
+
mtimeMs: 0,
|
|
1001
|
+
ctimeMs: 0,
|
|
1002
|
+
isDirectory: () => false
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
const open = file(fd);
|
|
1006
|
+
return open.kind === "handle" ? goStats(await vfs.fstat(open.handle)) : open.stat;
|
|
1007
|
+
}, callback);
|
|
1008
|
+
},
|
|
1009
|
+
stat(path, callback) {
|
|
1010
|
+
settle(() => stat(at(path), true), callback);
|
|
1011
|
+
},
|
|
1012
|
+
lstat(path, callback) {
|
|
1013
|
+
settle(() => stat(at(path), false), callback);
|
|
1014
|
+
},
|
|
1015
|
+
readdir(path, callback) {
|
|
1016
|
+
settle(async () => (await vfs.readdir(at(path))).map((entry) => entry.name), callback);
|
|
1017
|
+
},
|
|
1018
|
+
mkdir(path, perm, callback) {
|
|
1019
|
+
settle(() => vfs.mkdir(at(path), { mode: perm }), callback);
|
|
1020
|
+
},
|
|
1021
|
+
rmdir(path, callback) {
|
|
1022
|
+
settle(() => vfs.rmdir(at(path)), callback);
|
|
1023
|
+
},
|
|
1024
|
+
unlink(path, callback) {
|
|
1025
|
+
settle(() => vfs.unlink(at(path)), callback);
|
|
1026
|
+
},
|
|
1027
|
+
rename(from, to, callback) {
|
|
1028
|
+
settle(() => vfs.rename(at(from), at(to)), callback);
|
|
1029
|
+
},
|
|
1030
|
+
readlink(path, callback) {
|
|
1031
|
+
settle(async () => {
|
|
1032
|
+
const target = await vfs.readlink(at(path));
|
|
1033
|
+
if (target === null) throw errno("EINVAL", `${path} is not a symbolic link`);
|
|
1034
|
+
return target;
|
|
1035
|
+
}, callback);
|
|
1036
|
+
},
|
|
1037
|
+
symlink(target, path, callback) {
|
|
1038
|
+
settle(() => vfs.symlink(target, at(path)), callback);
|
|
1039
|
+
},
|
|
1040
|
+
link(_existing, path, callback) {
|
|
1041
|
+
settle(() => {
|
|
1042
|
+
throw errno("ENOSYS", `hard links are not supported: ${path}`);
|
|
1043
|
+
}, callback);
|
|
1044
|
+
},
|
|
1045
|
+
chmod(path, mode, callback) {
|
|
1046
|
+
settle(() => vfs.chmod(at(path), mode), callback);
|
|
1047
|
+
},
|
|
1048
|
+
fchmod(fd, mode, callback) {
|
|
1049
|
+
settle(() => {
|
|
1050
|
+
const open = file(fd);
|
|
1051
|
+
return open.kind === "handle" ? vfs.fchmod(open.handle, mode) : vfs.chmod(open.path, mode);
|
|
1052
|
+
}, callback);
|
|
1053
|
+
},
|
|
1054
|
+
chown(path, uid, gid, callback) {
|
|
1055
|
+
settle(() => vfs.chown(at(path), uid, gid), callback);
|
|
1056
|
+
},
|
|
1057
|
+
lchown(path, uid, gid, callback) {
|
|
1058
|
+
settle(() => vfs.chown(at(path), uid, gid, { followSymlinks: false }), callback);
|
|
1059
|
+
},
|
|
1060
|
+
fchown(fd, uid, gid, callback) {
|
|
1061
|
+
settle(() => {
|
|
1062
|
+
const open = file(fd);
|
|
1063
|
+
return open.kind === "handle" ? vfs.fchown(open.handle, uid, gid) : vfs.chown(open.path, uid, gid);
|
|
1064
|
+
}, callback);
|
|
1065
|
+
},
|
|
1066
|
+
utimes(path, atime, mtime, callback) {
|
|
1067
|
+
settle(() => vfs.utimes(at(path), atime * 1e3, mtime * 1e3), callback);
|
|
1068
|
+
},
|
|
1069
|
+
truncate(path, length, callback) {
|
|
1070
|
+
settle(() => vfs.truncate(at(path), length), callback);
|
|
1071
|
+
},
|
|
1072
|
+
ftruncate(fd, length, callback) {
|
|
1073
|
+
settle(() => {
|
|
1074
|
+
const open = file(fd);
|
|
1075
|
+
if (open.kind !== "handle") throw errno("EBADF", `fd ${fd} is not open for writing`);
|
|
1076
|
+
return vfs.ftruncate(open.handle, length);
|
|
1077
|
+
}, callback);
|
|
1078
|
+
},
|
|
1079
|
+
fsync(fd, callback) {
|
|
1080
|
+
settle(() => {
|
|
1081
|
+
const open = file(fd);
|
|
1082
|
+
return open.kind === "handle" ? vfs.fsync(open.handle) : void 0;
|
|
1083
|
+
}, callback);
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
return { fs, files };
|
|
1087
|
+
}
|
|
1088
|
+
globalThis.__esbuildCliRun = async function __esbuildCliRun(args, supervisor, output, module) {
|
|
1089
|
+
const stdio = new Stdio(args.stdin, output);
|
|
1090
|
+
const vfs = supervisorFilesystem(supervisor);
|
|
1091
|
+
const state = { cwd: args.cwd, umask: args.umask };
|
|
1092
|
+
let go = null;
|
|
1093
|
+
let crash = () => {
|
|
1094
|
+
};
|
|
1095
|
+
const crashed = new Promise((_, reject) => {
|
|
1096
|
+
crash = reject;
|
|
1097
|
+
});
|
|
1098
|
+
const { fs, files } = goFilesystem(vfs, stdio, state, () => go !== null && !go.exited, (error) => crash(error));
|
|
1099
|
+
const process = {
|
|
1100
|
+
pid: 1,
|
|
1101
|
+
ppid: 0,
|
|
1102
|
+
getuid: () => args.uid,
|
|
1103
|
+
geteuid: () => args.uid,
|
|
1104
|
+
getgid: () => args.gid,
|
|
1105
|
+
getegid: () => args.gid,
|
|
1106
|
+
getgroups: () => args.groups,
|
|
1107
|
+
umask(mask) {
|
|
1108
|
+
const prior = state.umask;
|
|
1109
|
+
if (typeof mask === "number") state.umask = mask;
|
|
1110
|
+
return prior;
|
|
1111
|
+
},
|
|
1112
|
+
cwd: () => state.cwd,
|
|
1113
|
+
chdir(path) {
|
|
1114
|
+
state.cwd = resolvePath(state.cwd, path);
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
const Go = __esbuildGoRuntime({ Object, Array, Uint8Array, TextEncoder, TextDecoder, crypto, performance, fs, process }, fs);
|
|
1118
|
+
const program = new Go();
|
|
1119
|
+
go = program;
|
|
1120
|
+
program.argv = ["esbuild", ...args.argv];
|
|
1121
|
+
program.env = args.env;
|
|
1122
|
+
let exitCode = 0;
|
|
1123
|
+
program.exit = (code) => {
|
|
1124
|
+
exitCode = code;
|
|
1125
|
+
};
|
|
1126
|
+
try {
|
|
1127
|
+
const instance = await WebAssembly.instantiate(module, program.importObject);
|
|
1128
|
+
await Promise.race([program.run(instance), crashed]);
|
|
1129
|
+
} catch (error) {
|
|
1130
|
+
stdio.hold(2, new TextEncoder().encode(`esbuild: ${error instanceof Error ? error.message : String(error)}
|
|
1131
|
+
`));
|
|
1132
|
+
exitCode = exitCode || 1;
|
|
1133
|
+
} finally {
|
|
1134
|
+
for (const timer of program._scheduledTimeouts.values()) clearTimeout(timer);
|
|
1135
|
+
for (const open of files.values()) {
|
|
1136
|
+
if (open.kind === "handle") await Promise.resolve(vfs.close(open.handle)).catch(() => void 0);
|
|
1137
|
+
}
|
|
1138
|
+
files.clear();
|
|
1139
|
+
}
|
|
1140
|
+
await stdio.flush();
|
|
1141
|
+
return exitCode;
|
|
1142
|
+
};
|
|
1143
|
+
})();
|