@nimbus-sh/worker 0.12.0 → 0.13.1
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 +7 -5
- 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
package/public/_assets/runtime/{esbuild-cli-b7aecffd4c6a36fe.js → oxc-facet-fd86fefcdf16bf9c.js}
RENAMED
|
@@ -1,633 +1,174 @@
|
|
|
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
1
|
"use strict";
|
|
567
2
|
(() => {
|
|
568
|
-
function
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
return
|
|
3
|
+
function bindExports(instance) {
|
|
4
|
+
const exports = instance.exports;
|
|
5
|
+
const memory = exports.memory;
|
|
6
|
+
if (!(memory instanceof WebAssembly.Memory)) throw new Error("oxc transform: the wasm exports no memory");
|
|
7
|
+
const call = (name) => {
|
|
8
|
+
const fn = exports[name];
|
|
9
|
+
if (typeof fn !== "function") throw new Error(`oxc transform: the wasm does not export ${name}`);
|
|
10
|
+
return (...args) => Number(fn(...args));
|
|
11
|
+
};
|
|
12
|
+
const release = call("nimbus_oxc_release");
|
|
13
|
+
return {
|
|
14
|
+
memory,
|
|
15
|
+
nimbus_oxc_alloc: call("nimbus_oxc_alloc"),
|
|
16
|
+
nimbus_oxc_realloc: call("nimbus_oxc_realloc"),
|
|
17
|
+
nimbus_oxc_transform: call("nimbus_oxc_transform"),
|
|
18
|
+
nimbus_oxc_release: () => {
|
|
19
|
+
release();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
579
22
|
}
|
|
580
|
-
function
|
|
23
|
+
function createOxcTransform(module, { retireAboveBytes = 64 * 1024 * 1024 } = {}) {
|
|
24
|
+
const encoder = new TextEncoder();
|
|
25
|
+
const decoder = new TextDecoder();
|
|
26
|
+
let instance = null;
|
|
27
|
+
let lastArena = { used: 0, reserved: 0 };
|
|
28
|
+
const KNOWN = {
|
|
29
|
+
loader: true,
|
|
30
|
+
format: true,
|
|
31
|
+
target: true,
|
|
32
|
+
sourcemap: true,
|
|
33
|
+
sourcefile: true,
|
|
34
|
+
minify: true,
|
|
35
|
+
jsx: true,
|
|
36
|
+
jsxFactory: true,
|
|
37
|
+
jsxFragment: true,
|
|
38
|
+
tsconfigRaw: true,
|
|
39
|
+
define: true,
|
|
40
|
+
supported: true
|
|
41
|
+
};
|
|
42
|
+
function wire(options) {
|
|
43
|
+
for (const key of Object.keys(options)) {
|
|
44
|
+
if (KNOWN[key] !== true && Reflect.get(options, key) !== void 0) throw new Error(`oxc transform: option "${key}" is not supported`);
|
|
45
|
+
}
|
|
46
|
+
const loader = options.loader ?? "js";
|
|
47
|
+
if (loader !== "js" && loader !== "jsx" && loader !== "ts" && loader !== "tsx") {
|
|
48
|
+
throw new Error(`oxc transform: loader "${loader}" is not supported`);
|
|
49
|
+
}
|
|
50
|
+
const format = options.format === void 0 ? "preserve" : options.format;
|
|
51
|
+
if (format !== "preserve" && format !== "esm" && format !== "cjs") throw new Error(`oxc transform: format "${format}" is not supported`);
|
|
52
|
+
if (options.target !== void 0 && options.target !== "esnext") {
|
|
53
|
+
throw new Error(`oxc transform: target "${options.target}" is not supported; only esnext`);
|
|
54
|
+
}
|
|
55
|
+
if (options.minify) throw new Error("oxc transform: minify is not supported");
|
|
56
|
+
if (options.tsconfigRaw !== void 0 && options.tsconfigRaw !== "" && JSON.stringify(options.tsconfigRaw) !== "{}") {
|
|
57
|
+
throw new Error("oxc transform: tsconfigRaw is not supported");
|
|
58
|
+
}
|
|
59
|
+
const sourcemap = options.sourcemap === void 0 || options.sourcemap === false ? "none" : options.sourcemap === true || options.sourcemap === "external" ? "external" : options.sourcemap === "inline" ? "inline" : null;
|
|
60
|
+
if (sourcemap === null) throw new Error(`oxc transform: sourcemap "${String(options.sourcemap)}" is not supported`);
|
|
61
|
+
const jsx = options.jsx ?? "transform";
|
|
62
|
+
if (jsx !== "transform" && jsx !== "automatic" && jsx !== "preserve") throw new Error(`oxc transform: jsx "${jsx}" is not supported`);
|
|
63
|
+
if (jsx === "preserve" && format === "cjs" && (loader === "jsx" || loader === "tsx")) {
|
|
64
|
+
throw new Error('oxc transform: jsx "preserve" is not supported with format "cjs"');
|
|
65
|
+
}
|
|
66
|
+
const fields = ["loader", loader, "format", format, "jsx", jsx, "sourcemap", sourcemap];
|
|
67
|
+
if (options.jsxFactory) fields.push("jsxFactory", options.jsxFactory);
|
|
68
|
+
if (options.jsxFragment) fields.push("jsxFragment", options.jsxFragment);
|
|
69
|
+
if (options.sourcefile) fields.push("sourcefile", options.sourcefile);
|
|
70
|
+
for (const [name, value] of Object.entries(options.define ?? {})) fields.push("define", name, value);
|
|
71
|
+
for (const [feature, supported] of Object.entries(options.supported ?? {})) {
|
|
72
|
+
if (feature === "dynamic-import") fields.push("dynamicImport", supported ? "1" : "0");
|
|
73
|
+
else if (feature === "import-meta") fields.push("importMeta", supported ? "1" : "0");
|
|
74
|
+
else if (!supported) throw new Error(`oxc transform: supported["${feature}"] = false is not supported`);
|
|
75
|
+
}
|
|
76
|
+
for (const field of fields) {
|
|
77
|
+
if (field.includes("\0")) throw new Error("oxc transform: an option contains a NUL character");
|
|
78
|
+
}
|
|
79
|
+
return fields.join("\0");
|
|
80
|
+
}
|
|
81
|
+
function messages(bytes) {
|
|
82
|
+
const errors = [];
|
|
83
|
+
const warnings = [];
|
|
84
|
+
const fields = [];
|
|
85
|
+
for (let at2 = 0; at2 < bytes.length; ) {
|
|
86
|
+
let length = 0;
|
|
87
|
+
for (; bytes[at2] !== 58; at2++) {
|
|
88
|
+
const digit = bytes[at2] - 48;
|
|
89
|
+
if (!(digit >= 0 && digit <= 9) || at2 >= bytes.length) throw new Error("oxc transform: malformed diagnostics");
|
|
90
|
+
length = length * 10 + digit;
|
|
91
|
+
}
|
|
92
|
+
at2++;
|
|
93
|
+
if (at2 + length > bytes.length) throw new Error("oxc transform: malformed diagnostics");
|
|
94
|
+
fields.push(decoder.decode(bytes.subarray(at2, at2 + length)));
|
|
95
|
+
at2 += length;
|
|
96
|
+
}
|
|
97
|
+
if (fields.length % 7 !== 0) throw new Error("oxc transform: malformed diagnostics");
|
|
98
|
+
for (let i = 0; i + 7 <= fields.length; i += 7) {
|
|
99
|
+
const [kind, line, column, length, file, lineText, message] = fields.slice(i, i + 7);
|
|
100
|
+
const lineNumber = Number(line);
|
|
101
|
+
const location = lineNumber > 0 ? { file, namespace: file === "<stdin>" ? "" : "file", line: lineNumber, column: Number(column), length: Number(length), lineText, suggestion: "" } : null;
|
|
102
|
+
(kind === "E" ? errors : warnings).push({ id: "", pluginName: "", text: message, location, notes: [], detail: void 0 });
|
|
103
|
+
}
|
|
104
|
+
return { errors, warnings };
|
|
105
|
+
}
|
|
106
|
+
function failure(errors, warnings) {
|
|
107
|
+
const lines = errors.map((e) => e.location ? `${e.location.file}:${e.location.line}:${e.location.column}: ERROR: ${e.text}` : `error: ${e.text}`);
|
|
108
|
+
const count = errors.length === 1 ? "1 error" : `${errors.length} errors`;
|
|
109
|
+
return Object.assign(new Error(`Transform failed with ${count}:
|
|
110
|
+
${lines.join("\n")}`), { errors, warnings });
|
|
111
|
+
}
|
|
112
|
+
function run(code, optionsWire) {
|
|
113
|
+
const exports = instance ??= bindExports(new WebAssembly.Instance(module, {}));
|
|
114
|
+
const options = encoder.encode(optionsWire);
|
|
115
|
+
let capacity = code.length + options.length;
|
|
116
|
+
let ptr = exports.nimbus_oxc_alloc(capacity);
|
|
117
|
+
let read = 0;
|
|
118
|
+
let written = 0;
|
|
119
|
+
for (; ; ) {
|
|
120
|
+
const into = new Uint8Array(exports.memory.buffer, ptr + written, capacity - options.length - written);
|
|
121
|
+
const step = encoder.encodeInto(read === 0 ? code : code.slice(read), into);
|
|
122
|
+
read += step.read;
|
|
123
|
+
written += step.written;
|
|
124
|
+
if (read >= code.length) break;
|
|
125
|
+
const grown = written + (code.length - read) * 3 + options.length;
|
|
126
|
+
ptr = exports.nimbus_oxc_realloc(ptr, capacity, grown);
|
|
127
|
+
capacity = grown;
|
|
128
|
+
}
|
|
129
|
+
new Uint8Array(exports.memory.buffer, ptr + written, options.length).set(options);
|
|
130
|
+
const at2 = exports.nimbus_oxc_transform(ptr, capacity, written, options.length);
|
|
131
|
+
try {
|
|
132
|
+
const [status, codePtr, codeLength, mapPtr, mapLength, diagnosticsPtr, diagnosticsLength, arenaUsed, arenaReserved] = new Uint32Array(exports.memory.buffer, at2, 9);
|
|
133
|
+
lastArena = { used: arenaUsed, reserved: arenaReserved };
|
|
134
|
+
const memory = exports.memory.buffer;
|
|
135
|
+
const { errors, warnings } = messages(new Uint8Array(memory, diagnosticsPtr, diagnosticsLength));
|
|
136
|
+
if (status !== 0) {
|
|
137
|
+
if (status === 2) throw Object.assign(new Error(`oxc transform: ${errors[0]?.text ?? "the options were refused"}`), { errors, warnings });
|
|
138
|
+
throw failure(errors, warnings);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
code: decoder.decode(new Uint8Array(memory, codePtr, codeLength)),
|
|
142
|
+
map: decoder.decode(new Uint8Array(memory, mapPtr, mapLength)),
|
|
143
|
+
warnings
|
|
144
|
+
};
|
|
145
|
+
} finally {
|
|
146
|
+
exports.nimbus_oxc_release();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
581
149
|
return {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
rename: (...args) => hop(supervisor.rename(...args)),
|
|
602
|
-
readlink: (...args) => hop(supervisor.readlink(...args)),
|
|
603
|
-
symlink: (...args) => hop(supervisor.symlink(...args)),
|
|
604
|
-
fsync: (...args) => hop(supervisor.fsSync(...args)),
|
|
605
|
-
revision: (...args) => hop(supervisor.fsRevision(...args)),
|
|
606
|
-
acquire: (...args) => hop(supervisor.fsAcquire(...args)),
|
|
607
|
-
list: (...args) => hop(supervisor.fsList(...args)),
|
|
608
|
-
realpath: (...args) => hop(supervisor.fsRealpath(...args)),
|
|
609
|
-
remove: (...args) => hop(supervisor.fsRemove(...args)),
|
|
610
|
-
copyFile: (...args) => hop(supervisor.fsCopyFile(...args)),
|
|
611
|
-
copyTree: (...args) => hop(supervisor.fsCopyTree(...args)),
|
|
612
|
-
fstat: (...args) => hop(supervisor.fsFstat(...args)),
|
|
613
|
-
dup: (...args) => hop(supervisor.fsDup(...args)),
|
|
614
|
-
seek: (...args) => hop(supervisor.fsSeek(...args)),
|
|
615
|
-
setStatus: (...args) => hop(supervisor.fsSetStatus(...args)),
|
|
616
|
-
readdirHandle: (...args) => hop(supervisor.fsReaddirHandle(...args)),
|
|
617
|
-
ftruncate: (...args) => hop(supervisor.fsFtruncate(...args)),
|
|
618
|
-
fchmod: (...args) => hop(supervisor.fsFchmod(...args)),
|
|
619
|
-
fchown: (...args) => hop(supervisor.fsFchown(...args)),
|
|
620
|
-
futimes: (...args) => hop(supervisor.fsFutimes(...args)),
|
|
621
|
-
appendOnce: (...args) => hop(supervisor.fsAppend(...args)),
|
|
622
|
-
acknowledgeAppend: (...args) => hop(supervisor.fsAppendAck(...args)),
|
|
623
|
-
writeBatch: (...args) => hop(supervisor.writeBatch(...args)),
|
|
624
|
-
writeStream: (...args) => Promise.resolve(supervisor.writeBatchStream(...args)),
|
|
625
|
-
writeFileFrom: async (path) => {
|
|
626
|
-
const name = typeof path === "string" ? path : path.path;
|
|
627
|
-
throw Object.assign(new Error(`ENOTSUP: a streamed whole-file write is a host operation, write '${name}' as a W7 stream`), { code: "ENOTSUP" });
|
|
150
|
+
async transform(code, options = {}) {
|
|
151
|
+
const optionsWire = wire(options);
|
|
152
|
+
try {
|
|
153
|
+
return run(code, optionsWire);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (error instanceof Error && Reflect.get(error, "errors") !== void 0) throw error;
|
|
156
|
+
instance = null;
|
|
157
|
+
const reason = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
158
|
+
if (error instanceof RangeError && /^Maximum call stack size exceeded\.?$/.test(error.message)) {
|
|
159
|
+
throw Object.assign(new Error(`Transform failed with 1 error:
|
|
160
|
+
error: the Oxc transform ran out of stack (${reason})`), {
|
|
161
|
+
stackExhausted: true
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
throw new Error(`Transform failed with 1 error:
|
|
165
|
+
error: the Oxc transform crashed (${reason})`);
|
|
166
|
+
} finally {
|
|
167
|
+
if (instance && instance.memory.buffer.byteLength > retireAboveBytes) instance = null;
|
|
168
|
+
}
|
|
628
169
|
},
|
|
629
|
-
|
|
630
|
-
|
|
170
|
+
memoryBytes: () => instance ? instance.memory.buffer.byteLength : 0,
|
|
171
|
+
lastArena: () => lastArena
|
|
631
172
|
};
|
|
632
173
|
}
|
|
633
174
|
|
|
@@ -8838,32 +8379,34 @@ return globalThis.Go;
|
|
|
8838
8379
|
function isLexerError(error) {
|
|
8839
8380
|
return error instanceof Error && typeof Reflect.get(error, "idx") === "number";
|
|
8840
8381
|
}
|
|
8841
|
-
function rewriteDynamicImports(code, parentUrl, moduleMetadata = false) {
|
|
8382
|
+
function rewriteDynamicImports(code, parentUrl, moduleMetadata = false, routeImports = true) {
|
|
8842
8383
|
const metadata = moduleMetadata && /\bimport\s*(?:\.|\/[/*])/.test(code);
|
|
8843
|
-
|
|
8384
|
+
const imports = routeImports && mayHaveDynamicImport(code);
|
|
8385
|
+
if (!imports && !metadata) return code;
|
|
8844
8386
|
let lexed;
|
|
8845
8387
|
try {
|
|
8846
|
-
lexed = rewriteFromLexer(code, parentUrl, metadata);
|
|
8388
|
+
lexed = rewriteFromLexer(code, parentUrl, metadata, imports);
|
|
8847
8389
|
} catch (error) {
|
|
8848
8390
|
if (!(isLexerError(error) || error instanceof SyntaxError || error instanceof RangeError)) throw error;
|
|
8849
8391
|
lexed = null;
|
|
8850
8392
|
}
|
|
8851
|
-
return lexed ?? rewriteWithGrammar(code, parentUrl, metadata);
|
|
8393
|
+
return lexed ?? rewriteWithGrammar(code, parentUrl, metadata, imports);
|
|
8852
8394
|
}
|
|
8853
|
-
function rewriteFromLexer(code, parentUrl, metadata) {
|
|
8395
|
+
function rewriteFromLexer(code, parentUrl, metadata, imports) {
|
|
8854
8396
|
const hashbang = code.startsWith("#!") ? lineEnd(code, 0) : 0;
|
|
8855
8397
|
const source = hashbang ? " ".repeat(hashbang) + code.slice(hashbang) : code;
|
|
8856
|
-
const
|
|
8398
|
+
const lexed = lexImports(source);
|
|
8857
8399
|
const lines = new Lines(source);
|
|
8858
|
-
const passed = passedOver(source,
|
|
8400
|
+
const passed = passedOver(source, lexed, [...ambiguousSlashes(source, lines), ...htmlComments(source, lines)]);
|
|
8859
8401
|
if (passed === null) return null;
|
|
8860
8402
|
const calls = [];
|
|
8861
8403
|
const metas = [];
|
|
8862
|
-
for (const entry of
|
|
8404
|
+
for (const entry of lexed) {
|
|
8863
8405
|
if (entry.t === DYNAMIC_IMPORT) calls.push({ ss: entry.ss, se: entry.se, d: entry.d, lexed: true });
|
|
8864
8406
|
else if (metadata && entry.t === IMPORT_META) metas.push({ start: entry.s, end: entry.e });
|
|
8865
8407
|
}
|
|
8866
|
-
|
|
8408
|
+
if (!imports) calls.length = 0;
|
|
8409
|
+
for (const at2 of imports ? passed : []) {
|
|
8867
8410
|
const open = skipTrivia(source, at2 + "import".length).at;
|
|
8868
8411
|
const end = source[open] === "(" ? parenthesisEnd(source, open) : null;
|
|
8869
8412
|
if (end === null) return null;
|
|
@@ -9074,7 +8617,7 @@ return globalThis.Go;
|
|
|
9074
8617
|
return node;
|
|
9075
8618
|
}
|
|
9076
8619
|
};
|
|
9077
|
-
function rewriteWithGrammar(code, parentUrl, metadata) {
|
|
8620
|
+
function rewriteWithGrammar(code, parentUrl, metadata, imports) {
|
|
9078
8621
|
const collected = {
|
|
9079
8622
|
call: DYNAMIC_IMPORT_HELPER + "(" + JSON.stringify(parentUrl) + ", ",
|
|
9080
8623
|
edits: [],
|
|
@@ -9098,6 +8641,7 @@ return globalThis.Go;
|
|
|
9098
8641
|
} catch {
|
|
9099
8642
|
continue;
|
|
9100
8643
|
}
|
|
8644
|
+
if (!imports) collected.edits.length = 0;
|
|
9101
8645
|
if (!collected.edits.length && !collected.metas.length) return code;
|
|
9102
8646
|
let insertion = program.body[0]?.start ?? code.length;
|
|
9103
8647
|
for (const statement of program.body) {
|
|
@@ -9138,14 +8682,15 @@ const ${binding} = arguments[2];
|
|
|
9138
8682
|
const key = (name) => `[${JSON.stringify(name)}]`;
|
|
9139
8683
|
const nameOf = (node) => node.type === "Identifier" ? String(node.name) : String(node.value);
|
|
9140
8684
|
const sourceOf = (node) => JSON.stringify(String(node.value));
|
|
9141
|
-
|
|
9142
|
-
const
|
|
9143
|
-
|
|
9144
|
-
|
|
9145
|
-
return "module.exports.__esModule = true; ";
|
|
9146
|
-
};
|
|
8685
|
+
const exportsRef = temp();
|
|
8686
|
+
const exportGetter = temp();
|
|
8687
|
+
const defineProperty = temp();
|
|
8688
|
+
const live = (exported, value) => `${exportGetter}(${JSON.stringify(exported)}, () => ${value});`;
|
|
9147
8689
|
const requires = [];
|
|
8690
|
+
const imported = [];
|
|
8691
|
+
const getters = [];
|
|
9148
8692
|
const edits = [];
|
|
8693
|
+
let exportsAnything = false;
|
|
9149
8694
|
if (esm.startsWith("#!")) edits.push({ start: 0, end: 2, text: "//" });
|
|
9150
8695
|
for (const node of program.body) {
|
|
9151
8696
|
switch (node.type) {
|
|
@@ -9156,59 +8701,54 @@ const ${binding} = arguments[2];
|
|
|
9156
8701
|
break;
|
|
9157
8702
|
}
|
|
9158
8703
|
const mod = temp();
|
|
9159
|
-
|
|
8704
|
+
requires.push(`const ${mod} = require(${sourceOf(node.source)});`);
|
|
9160
8705
|
for (const specifier of node.specifiers) {
|
|
9161
8706
|
const local = specifier.local.name;
|
|
9162
|
-
if (specifier.type === "ImportNamespaceSpecifier")
|
|
8707
|
+
if (specifier.type === "ImportNamespaceSpecifier") imported.push(`const ${local} = ${mod};`);
|
|
9163
8708
|
else if (specifier.type === "ImportDefaultSpecifier") {
|
|
9164
|
-
|
|
9165
|
-
} else
|
|
8709
|
+
imported.push(`const ${local} = ${mod} && ${mod}.__esModule ? ${mod}.default : ${mod};`);
|
|
8710
|
+
} else imported.push(`const ${local} = ${mod}${key(nameOf(specifier.imported))};`);
|
|
9166
8711
|
}
|
|
9167
|
-
requires.push(bindings.join(" "));
|
|
9168
8712
|
break;
|
|
9169
8713
|
}
|
|
9170
8714
|
case "ExportNamedDeclaration": {
|
|
8715
|
+
exportsAnything = true;
|
|
9171
8716
|
if (node.declaration) {
|
|
9172
8717
|
edits.push({ start: node.start, end: node.declaration.start, text: "" });
|
|
9173
|
-
const
|
|
9174
|
-
edits.push({
|
|
9175
|
-
start: node.end,
|
|
9176
|
-
end: node.end,
|
|
9177
|
-
text: "\n" + esModule() + names.map((name) => `module.exports${key(name)} = ${name};`).join(" ")
|
|
9178
|
-
});
|
|
8718
|
+
for (const name of declaredNames(node.declaration)) getters.push([name, name]);
|
|
9179
8719
|
} else if (node.source) {
|
|
9180
8720
|
const mod = temp();
|
|
9181
|
-
|
|
9182
|
-
|
|
9183
|
-
|
|
9184
|
-
end: node.end,
|
|
9185
|
-
text: `${esModule()}{ const ${mod} = require(${sourceOf(node.source)}); ${assigns.join(" ")} }`
|
|
9186
|
-
});
|
|
8721
|
+
edits.push({ start: node.start, end: node.end, text: "" });
|
|
8722
|
+
requires.push(`const ${mod} = require(${sourceOf(node.source)});`);
|
|
8723
|
+
for (const s of node.specifiers) getters.push([nameOf(s.exported), `${mod}${key(nameOf(s.local))}`]);
|
|
9187
8724
|
} else {
|
|
9188
|
-
|
|
9189
|
-
|
|
8725
|
+
edits.push({ start: node.start, end: node.end, text: "" });
|
|
8726
|
+
for (const s of node.specifiers) getters.push([nameOf(s.exported), nameOf(s.local)]);
|
|
9190
8727
|
}
|
|
9191
8728
|
break;
|
|
9192
8729
|
}
|
|
9193
8730
|
case "ExportDefaultDeclaration": {
|
|
8731
|
+
exportsAnything = true;
|
|
9194
8732
|
const declaration = node.declaration;
|
|
9195
8733
|
if ((declaration.type === "FunctionDeclaration" || declaration.type === "ClassDeclaration") && declaration.id) {
|
|
9196
8734
|
edits.push({ start: node.start, end: declaration.start, text: "" });
|
|
9197
|
-
|
|
9198
|
-
${esModule()}module.exports.default = ${declaration.id.name};` });
|
|
8735
|
+
getters.push(["default", declaration.id.name]);
|
|
9199
8736
|
} else {
|
|
9200
8737
|
edits.push({
|
|
9201
8738
|
start: node.start,
|
|
9202
8739
|
end: node.end,
|
|
9203
|
-
text: `${
|
|
8740
|
+
text: `${exportsRef}.default = (${esm.slice(declaration.start, declaration.end)});`
|
|
9204
8741
|
});
|
|
9205
8742
|
}
|
|
9206
8743
|
break;
|
|
9207
8744
|
}
|
|
9208
8745
|
case "ExportAllDeclaration": {
|
|
8746
|
+
exportsAnything = true;
|
|
9209
8747
|
const mod = temp();
|
|
9210
|
-
|
|
9211
|
-
|
|
8748
|
+
edits.push({ start: node.start, end: node.end, text: "" });
|
|
8749
|
+
requires.push(`const ${mod} = require(${sourceOf(node.source)});`);
|
|
8750
|
+
if (node.exported) getters.push([nameOf(node.exported), mod]);
|
|
8751
|
+
else requires.push(`for (const k in ${mod}) if (k !== "default" && k !== "__esModule") ${exportGetter}(k, () => ${mod}[k]);`);
|
|
9212
8752
|
break;
|
|
9213
8753
|
}
|
|
9214
8754
|
default:
|
|
@@ -9222,8 +8762,13 @@ ${esModule()}module.exports.default = ${declaration.id.name};` });
|
|
|
9222
8762
|
at2 = end;
|
|
9223
8763
|
}
|
|
9224
8764
|
parts.push(esm.slice(at2));
|
|
9225
|
-
|
|
9226
|
-
|
|
8765
|
+
const header = exportsAnything ? [
|
|
8766
|
+
`const ${exportsRef} = module.exports; ${exportsRef}.__esModule = true; const ${defineProperty} = Object.defineProperty;`,
|
|
8767
|
+
`const ${exportGetter} = (name, get) => ${defineProperty}(${exportsRef}, name, { enumerable: true, configurable: true, get });`
|
|
8768
|
+
] : [];
|
|
8769
|
+
const installed = getters.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([exported, value]) => live(exported, value));
|
|
8770
|
+
return `${[...header, ...requires].join("\n")}
|
|
8771
|
+
return (async () => { ${[...imported, ...installed].join(" ")}
|
|
9227
8772
|
${parts.join("")}
|
|
9228
8773
|
})();
|
|
9229
8774
|
`;
|
|
@@ -9257,384 +8802,9 @@ ${parts.join("")}
|
|
|
9257
8802
|
return names;
|
|
9258
8803
|
}
|
|
9259
8804
|
|
|
9260
|
-
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
|
|
9264
|
-
|
|
9265
|
-
var O_APPEND = 1024;
|
|
9266
|
-
var O_DIRECTORY = 65536;
|
|
9267
|
-
var CONSTANTS = { O_RDONLY: 0, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND, O_DIRECTORY };
|
|
9268
|
-
var GO_ERRNO_CODES = {
|
|
9269
|
-
EPERM: true,
|
|
9270
|
-
ENOENT: true,
|
|
9271
|
-
EINTR: true,
|
|
9272
|
-
EIO: true,
|
|
9273
|
-
EBADF: true,
|
|
9274
|
-
EAGAIN: true,
|
|
9275
|
-
ENOMEM: true,
|
|
9276
|
-
EACCES: true,
|
|
9277
|
-
EBUSY: true,
|
|
9278
|
-
EEXIST: true,
|
|
9279
|
-
EXDEV: true,
|
|
9280
|
-
ENOTDIR: true,
|
|
9281
|
-
EISDIR: true,
|
|
9282
|
-
EINVAL: true,
|
|
9283
|
-
EMFILE: true,
|
|
9284
|
-
ENOTTY: true,
|
|
9285
|
-
EFBIG: true,
|
|
9286
|
-
ENOSPC: true,
|
|
9287
|
-
ESPIPE: true,
|
|
9288
|
-
EROFS: true,
|
|
9289
|
-
EMLINK: true,
|
|
9290
|
-
EPIPE: true,
|
|
9291
|
-
ENAMETOOLONG: true,
|
|
9292
|
-
ENOTEMPTY: true,
|
|
9293
|
-
ENOSYS: true
|
|
9294
|
-
};
|
|
9295
|
-
var WRITE_SLICE_BYTES = 1 << 20;
|
|
9296
|
-
var S_IFREG = 32768;
|
|
9297
|
-
var S_IFDIR = 16384;
|
|
9298
|
-
var S_IFLNK = 40960;
|
|
9299
|
-
var S_IFIFO = 4096;
|
|
9300
|
-
function errno(code, detail) {
|
|
9301
|
-
return Object.assign(new Error(`${code}: ${detail}`), { code });
|
|
9302
|
-
}
|
|
9303
|
-
function goError(error) {
|
|
9304
|
-
const code = typeof error === "object" && error !== null ? Reflect.get(error, "code") : void 0;
|
|
9305
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
9306
|
-
return Object.assign(new Error(message), {
|
|
9307
|
-
code: typeof code === "string" && GO_ERRNO_CODES[code] ? code : "EIO"
|
|
9308
|
-
});
|
|
9309
|
-
}
|
|
9310
|
-
function resolvePath(cwd, path) {
|
|
9311
|
-
const parts = [];
|
|
9312
|
-
for (const part of (path.startsWith("/") ? path : `${cwd}/${path}`).split("/")) {
|
|
9313
|
-
if (part === "" || part === ".") continue;
|
|
9314
|
-
if (part === "..") parts.pop();
|
|
9315
|
-
else parts.push(part);
|
|
9316
|
-
}
|
|
9317
|
-
return `/${parts.join("/")}`;
|
|
9318
|
-
}
|
|
9319
|
-
function goStats(stat, size = stat.size) {
|
|
9320
|
-
const type = stat.type === "directory" ? S_IFDIR : stat.type === "symlink" ? S_IFLNK : S_IFREG;
|
|
9321
|
-
return {
|
|
9322
|
-
dev: stat.dev,
|
|
9323
|
-
ino: stat.ino,
|
|
9324
|
-
mode: type | stat.mode & 4095,
|
|
9325
|
-
nlink: stat.nlink,
|
|
9326
|
-
uid: stat.uid,
|
|
9327
|
-
gid: stat.gid,
|
|
9328
|
-
rdev: 0,
|
|
9329
|
-
size,
|
|
9330
|
-
blksize: 4096,
|
|
9331
|
-
blocks: Math.ceil(size / 512),
|
|
9332
|
-
atimeMs: stat.atime,
|
|
9333
|
-
mtimeMs: stat.mtime,
|
|
9334
|
-
ctimeMs: stat.ctime,
|
|
9335
|
-
isDirectory: () => stat.type === "directory"
|
|
9336
|
-
};
|
|
9337
|
-
}
|
|
9338
|
-
var Stdio = class {
|
|
9339
|
-
constructor(stdin, output) {
|
|
9340
|
-
this.stdin = stdin;
|
|
9341
|
-
this.output = output;
|
|
9342
|
-
}
|
|
9343
|
-
stdin;
|
|
9344
|
-
output;
|
|
9345
|
-
stdinOffset = 0;
|
|
9346
|
-
held = [];
|
|
9347
|
-
hold(fd, bytes2) {
|
|
9348
|
-
this.held.push({ fd, bytes: bytes2 });
|
|
9349
|
-
}
|
|
9350
|
-
async write(fd, bytes2) {
|
|
9351
|
-
await this.flush();
|
|
9352
|
-
for (let done = 0; done < bytes2.length; done += WRITE_SLICE_BYTES) {
|
|
9353
|
-
await this.output(fd, bytes2.slice(done, done + WRITE_SLICE_BYTES));
|
|
9354
|
-
}
|
|
9355
|
-
}
|
|
9356
|
-
async flush() {
|
|
9357
|
-
for (let next = this.held.shift(); next; next = this.held.shift()) {
|
|
9358
|
-
await this.output(next.fd, next.bytes);
|
|
9359
|
-
}
|
|
9360
|
-
}
|
|
9361
|
-
read(buffer, offset2, length) {
|
|
9362
|
-
const input = this.stdin ?? new Uint8Array(0);
|
|
9363
|
-
const chunk = input.subarray(this.stdinOffset, this.stdinOffset + length);
|
|
9364
|
-
buffer.set(chunk, offset2);
|
|
9365
|
-
this.stdinOffset += chunk.length;
|
|
9366
|
-
return chunk.length;
|
|
9367
|
-
}
|
|
9368
|
-
};
|
|
9369
|
-
var isOutput = (fd) => fd === 1 || fd === 2;
|
|
9370
|
-
function goFilesystem(vfs, stdio, state, live, crash) {
|
|
9371
|
-
const files = new Map();
|
|
9372
|
-
let nextFd = 3;
|
|
9373
|
-
const at2 = (path) => resolvePath(state.cwd, path);
|
|
9374
|
-
const add = (file2) => {
|
|
9375
|
-
const fd = nextFd++;
|
|
9376
|
-
files.set(fd, file2);
|
|
9377
|
-
return fd;
|
|
9378
|
-
};
|
|
9379
|
-
const file = (fd) => {
|
|
9380
|
-
const open = files.get(fd);
|
|
9381
|
-
if (!open) throw errno("EBADF", `fd ${fd}`);
|
|
9382
|
-
return open;
|
|
9383
|
-
};
|
|
9384
|
-
const settle = (work, callback) => {
|
|
9385
|
-
Promise.resolve().then(work).then(
|
|
9386
|
-
(value) => {
|
|
9387
|
-
if (live()) deliver(callback, null, value);
|
|
9388
|
-
},
|
|
9389
|
-
(error) => {
|
|
9390
|
-
if (live()) deliver(callback, goError(error), void 0);
|
|
9391
|
-
}
|
|
9392
|
-
);
|
|
9393
|
-
};
|
|
9394
|
-
const deliver = (callback, error, value) => {
|
|
9395
|
-
try {
|
|
9396
|
-
callback(error, value);
|
|
9397
|
-
} catch (trap) {
|
|
9398
|
-
crash(trap);
|
|
9399
|
-
}
|
|
9400
|
-
};
|
|
9401
|
-
const stat = async (path, followSymlinks) => {
|
|
9402
|
-
const found = await vfs.stat(path, { followSymlinks });
|
|
9403
|
-
if (!found) throw errno("ENOENT", path);
|
|
9404
|
-
return goStats(found);
|
|
9405
|
-
};
|
|
9406
|
-
const fs = {
|
|
9407
|
-
constants: CONSTANTS,
|
|
9408
|
-
writeSync(fd, buffer) {
|
|
9409
|
-
if (isOutput(fd)) stdio.hold(fd, buffer.slice());
|
|
9410
|
-
return buffer.length;
|
|
9411
|
-
},
|
|
9412
|
-
write(fd, buffer, offset2, length, position, callback) {
|
|
9413
|
-
settle(async () => {
|
|
9414
|
-
const data2 = buffer.subarray(offset2, offset2 + length);
|
|
9415
|
-
if (isOutput(fd)) {
|
|
9416
|
-
await stdio.write(fd, data2);
|
|
9417
|
-
return length;
|
|
9418
|
-
}
|
|
9419
|
-
const open = file(fd);
|
|
9420
|
-
if (open.kind !== "handle") throw errno("EBADF", `fd ${fd} is not open for writing`);
|
|
9421
|
-
for (let done = 0; done < length; ) {
|
|
9422
|
-
const slice = data2.slice(done, Math.min(length, done + WRITE_SLICE_BYTES));
|
|
9423
|
-
const written = await vfs.write(open.handle, position === null ? null : position + done, slice);
|
|
9424
|
-
if (written <= 0) throw errno("EIO", `short write to ${open.path}`);
|
|
9425
|
-
done += written;
|
|
9426
|
-
}
|
|
9427
|
-
return length;
|
|
9428
|
-
}, callback);
|
|
9429
|
-
},
|
|
9430
|
-
read(fd, buffer, offset2, length, position, callback) {
|
|
9431
|
-
settle(async () => {
|
|
9432
|
-
if (fd === 0) return stdio.read(buffer, offset2, length);
|
|
9433
|
-
const open = file(fd);
|
|
9434
|
-
if (open.kind === "directory") throw errno("EISDIR", open.path);
|
|
9435
|
-
if (open.kind === "bytes") {
|
|
9436
|
-
const start = position ?? open.position;
|
|
9437
|
-
const chunk = open.bytes.subarray(start, start + length);
|
|
9438
|
-
buffer.set(chunk, offset2);
|
|
9439
|
-
if (position === null) open.position += chunk.length;
|
|
9440
|
-
return chunk.length;
|
|
9441
|
-
}
|
|
9442
|
-
const bytes2 = await vfs.read(open.handle, position, length);
|
|
9443
|
-
buffer.set(bytes2, offset2);
|
|
9444
|
-
return bytes2.length;
|
|
9445
|
-
}, callback);
|
|
9446
|
-
},
|
|
9447
|
-
open(path, flags, mode, callback) {
|
|
9448
|
-
settle(async () => {
|
|
9449
|
-
const target = at2(path);
|
|
9450
|
-
const access = flags & 3;
|
|
9451
|
-
if (access === 0 && (flags & (O_CREAT | O_TRUNC | O_APPEND)) === 0) {
|
|
9452
|
-
const found = await vfs.stat(target);
|
|
9453
|
-
if (!found) throw errno("ENOENT", target);
|
|
9454
|
-
if (found.type === "directory") return add({ kind: "directory", path: target, stat: goStats(found) });
|
|
9455
|
-
if (flags & O_DIRECTORY) throw errno("ENOTDIR", target);
|
|
9456
|
-
const bytes2 = await vfs.readFile(target);
|
|
9457
|
-
if (!bytes2) throw errno("ENOENT", target);
|
|
9458
|
-
return add({ kind: "bytes", path: target, bytes: bytes2, stat: goStats(found, bytes2.length), position: 0 });
|
|
9459
|
-
}
|
|
9460
|
-
const openFlags = {
|
|
9461
|
-
read: access === O_RDWR,
|
|
9462
|
-
write: true,
|
|
9463
|
-
create: (flags & O_CREAT) !== 0,
|
|
9464
|
-
exclusive: (flags & O_EXCL) !== 0,
|
|
9465
|
-
truncate: (flags & O_TRUNC) !== 0,
|
|
9466
|
-
append: (flags & O_APPEND) !== 0,
|
|
9467
|
-
mode
|
|
9468
|
-
};
|
|
9469
|
-
const handle = await vfs.open(target, openFlags);
|
|
9470
|
-
return add({ kind: "handle", path: target, handle: handle.id });
|
|
9471
|
-
}, callback);
|
|
9472
|
-
},
|
|
9473
|
-
close(fd, callback) {
|
|
9474
|
-
settle(async () => {
|
|
9475
|
-
const open = file(fd);
|
|
9476
|
-
files.delete(fd);
|
|
9477
|
-
if (open.kind === "handle") await vfs.close(open.handle);
|
|
9478
|
-
}, callback);
|
|
9479
|
-
},
|
|
9480
|
-
fstat(fd, callback) {
|
|
9481
|
-
settle(async () => {
|
|
9482
|
-
if (fd <= 2) {
|
|
9483
|
-
return {
|
|
9484
|
-
dev: 0,
|
|
9485
|
-
ino: fd,
|
|
9486
|
-
mode: S_IFIFO | 384,
|
|
9487
|
-
nlink: 1,
|
|
9488
|
-
uid: 0,
|
|
9489
|
-
gid: 0,
|
|
9490
|
-
rdev: 0,
|
|
9491
|
-
size: 0,
|
|
9492
|
-
blksize: 4096,
|
|
9493
|
-
blocks: 0,
|
|
9494
|
-
atimeMs: 0,
|
|
9495
|
-
mtimeMs: 0,
|
|
9496
|
-
ctimeMs: 0,
|
|
9497
|
-
isDirectory: () => false
|
|
9498
|
-
};
|
|
9499
|
-
}
|
|
9500
|
-
const open = file(fd);
|
|
9501
|
-
return open.kind === "handle" ? goStats(await vfs.fstat(open.handle)) : open.stat;
|
|
9502
|
-
}, callback);
|
|
9503
|
-
},
|
|
9504
|
-
stat(path, callback) {
|
|
9505
|
-
settle(() => stat(at2(path), true), callback);
|
|
9506
|
-
},
|
|
9507
|
-
lstat(path, callback) {
|
|
9508
|
-
settle(() => stat(at2(path), false), callback);
|
|
9509
|
-
},
|
|
9510
|
-
readdir(path, callback) {
|
|
9511
|
-
settle(async () => (await vfs.readdir(at2(path))).map((entry) => entry.name), callback);
|
|
9512
|
-
},
|
|
9513
|
-
mkdir(path, perm, callback) {
|
|
9514
|
-
settle(() => vfs.mkdir(at2(path), { mode: perm }), callback);
|
|
9515
|
-
},
|
|
9516
|
-
rmdir(path, callback) {
|
|
9517
|
-
settle(() => vfs.rmdir(at2(path)), callback);
|
|
9518
|
-
},
|
|
9519
|
-
unlink(path, callback) {
|
|
9520
|
-
settle(() => vfs.unlink(at2(path)), callback);
|
|
9521
|
-
},
|
|
9522
|
-
rename(from, to, callback) {
|
|
9523
|
-
settle(() => vfs.rename(at2(from), at2(to)), callback);
|
|
9524
|
-
},
|
|
9525
|
-
readlink(path, callback) {
|
|
9526
|
-
settle(async () => {
|
|
9527
|
-
const target = await vfs.readlink(at2(path));
|
|
9528
|
-
if (target === null) throw errno("EINVAL", `${path} is not a symbolic link`);
|
|
9529
|
-
return target;
|
|
9530
|
-
}, callback);
|
|
9531
|
-
},
|
|
9532
|
-
symlink(target, path, callback) {
|
|
9533
|
-
settle(() => vfs.symlink(target, at2(path)), callback);
|
|
9534
|
-
},
|
|
9535
|
-
link(_existing, path, callback) {
|
|
9536
|
-
settle(() => {
|
|
9537
|
-
throw errno("ENOSYS", `hard links are not supported: ${path}`);
|
|
9538
|
-
}, callback);
|
|
9539
|
-
},
|
|
9540
|
-
chmod(path, mode, callback) {
|
|
9541
|
-
settle(() => vfs.chmod(at2(path), mode), callback);
|
|
9542
|
-
},
|
|
9543
|
-
fchmod(fd, mode, callback) {
|
|
9544
|
-
settle(() => {
|
|
9545
|
-
const open = file(fd);
|
|
9546
|
-
return open.kind === "handle" ? vfs.fchmod(open.handle, mode) : vfs.chmod(open.path, mode);
|
|
9547
|
-
}, callback);
|
|
9548
|
-
},
|
|
9549
|
-
chown(path, uid, gid, callback) {
|
|
9550
|
-
settle(() => vfs.chown(at2(path), uid, gid), callback);
|
|
9551
|
-
},
|
|
9552
|
-
lchown(path, uid, gid, callback) {
|
|
9553
|
-
settle(() => vfs.chown(at2(path), uid, gid, { followSymlinks: false }), callback);
|
|
9554
|
-
},
|
|
9555
|
-
fchown(fd, uid, gid, callback) {
|
|
9556
|
-
settle(() => {
|
|
9557
|
-
const open = file(fd);
|
|
9558
|
-
return open.kind === "handle" ? vfs.fchown(open.handle, uid, gid) : vfs.chown(open.path, uid, gid);
|
|
9559
|
-
}, callback);
|
|
9560
|
-
},
|
|
9561
|
-
utimes(path, atime, mtime, callback) {
|
|
9562
|
-
settle(() => vfs.utimes(at2(path), atime * 1e3, mtime * 1e3), callback);
|
|
9563
|
-
},
|
|
9564
|
-
truncate(path, length, callback) {
|
|
9565
|
-
settle(() => vfs.truncate(at2(path), length), callback);
|
|
9566
|
-
},
|
|
9567
|
-
ftruncate(fd, length, callback) {
|
|
9568
|
-
settle(() => {
|
|
9569
|
-
const open = file(fd);
|
|
9570
|
-
if (open.kind !== "handle") throw errno("EBADF", `fd ${fd} is not open for writing`);
|
|
9571
|
-
return vfs.ftruncate(open.handle, length);
|
|
9572
|
-
}, callback);
|
|
9573
|
-
},
|
|
9574
|
-
fsync(fd, callback) {
|
|
9575
|
-
settle(() => {
|
|
9576
|
-
const open = file(fd);
|
|
9577
|
-
return open.kind === "handle" ? vfs.fsync(open.handle) : void 0;
|
|
9578
|
-
}, callback);
|
|
9579
|
-
}
|
|
9580
|
-
};
|
|
9581
|
-
return { fs, files };
|
|
9582
|
-
}
|
|
9583
|
-
globalThis.__esbuildCliRun = async function __esbuildCliRun(args, supervisor, output, module) {
|
|
9584
|
-
const stdio = new Stdio(args.stdin, output);
|
|
9585
|
-
const vfs = supervisorFilesystem(supervisor);
|
|
9586
|
-
const state = { cwd: args.cwd, umask: args.umask };
|
|
9587
|
-
let go = null;
|
|
9588
|
-
let crash = () => {
|
|
9589
|
-
};
|
|
9590
|
-
const crashed = new Promise((_, reject) => {
|
|
9591
|
-
crash = reject;
|
|
9592
|
-
});
|
|
9593
|
-
const { fs, files } = goFilesystem(vfs, stdio, state, () => go !== null && !go.exited, (error) => crash(error));
|
|
9594
|
-
const process = {
|
|
9595
|
-
pid: 1,
|
|
9596
|
-
ppid: 0,
|
|
9597
|
-
getuid: () => args.uid,
|
|
9598
|
-
geteuid: () => args.uid,
|
|
9599
|
-
getgid: () => args.gid,
|
|
9600
|
-
getegid: () => args.gid,
|
|
9601
|
-
getgroups: () => args.groups,
|
|
9602
|
-
umask(mask) {
|
|
9603
|
-
const prior = state.umask;
|
|
9604
|
-
if (typeof mask === "number") state.umask = mask;
|
|
9605
|
-
return prior;
|
|
9606
|
-
},
|
|
9607
|
-
cwd: () => state.cwd,
|
|
9608
|
-
chdir(path) {
|
|
9609
|
-
state.cwd = resolvePath(state.cwd, path);
|
|
9610
|
-
}
|
|
9611
|
-
};
|
|
9612
|
-
const Go = __esbuildGoRuntime({ Object, Array, Uint8Array, TextEncoder, TextDecoder, crypto, performance, fs, process }, fs);
|
|
9613
|
-
const program = new Go();
|
|
9614
|
-
go = program;
|
|
9615
|
-
program.argv = ["esbuild", ...args.argv];
|
|
9616
|
-
program.env = args.env;
|
|
9617
|
-
let exitCode = 0;
|
|
9618
|
-
program.exit = (code) => {
|
|
9619
|
-
exitCode = code;
|
|
9620
|
-
};
|
|
9621
|
-
try {
|
|
9622
|
-
const instance = await WebAssembly.instantiate(module, program.importObject);
|
|
9623
|
-
await Promise.race([program.run(instance), crashed]);
|
|
9624
|
-
} catch (error) {
|
|
9625
|
-
stdio.hold(2, new TextEncoder().encode(`esbuild: ${error instanceof Error ? error.message : String(error)}
|
|
9626
|
-
`));
|
|
9627
|
-
exitCode = exitCode || 1;
|
|
9628
|
-
} finally {
|
|
9629
|
-
for (const timer of program._scheduledTimeouts.values()) clearTimeout(timer);
|
|
9630
|
-
for (const open of files.values()) {
|
|
9631
|
-
if (open.kind === "handle") await Promise.resolve(vfs.close(open.handle)).catch(() => void 0);
|
|
9632
|
-
}
|
|
9633
|
-
files.clear();
|
|
9634
|
-
}
|
|
9635
|
-
await stdio.flush();
|
|
9636
|
-
return exitCode;
|
|
9637
|
-
};
|
|
9638
|
-
globalThis.__nimbusRewriteDynamicImports = rewriteDynamicImports;
|
|
9639
|
-
globalThis.__nimbusLowerAsyncModule = lowerAsyncModule;
|
|
8805
|
+
Object.assign(globalThis, {
|
|
8806
|
+
__nimbusCreateOxcTransform: createOxcTransform,
|
|
8807
|
+
__nimbusRewriteDynamicImports: rewriteDynamicImports,
|
|
8808
|
+
__nimbusLowerAsyncModule: lowerAsyncModule
|
|
8809
|
+
});
|
|
9640
8810
|
})();
|