@nimbus-sh/worker 0.9.0 → 0.10.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-wasm-bundle.generated.d.ts +24 -24
- package/dist/esbuild-wasm-bundle.generated.d.ts.map +1 -1
- package/dist/esbuild-wasm-bundle.generated.js +24 -24
- package/dist/facets/cirrus-real.js +3 -3
- package/dist/facets/compose.js +9 -2
- package/dist/facets/esbuild-bundle-pool.d.ts +1 -1
- package/dist/facets/esbuild-bundle-pool.js +3 -3
- package/dist/facets/esbuild-transform.d.ts +6 -2
- package/dist/facets/esbuild-transform.d.ts.map +1 -1
- package/dist/facets/esbuild-transform.js +8 -4
- package/dist/facets/manager.d.ts +28 -0
- package/dist/facets/manager.d.ts.map +1 -1
- package/dist/facets/manager.js +89 -37
- package/dist/facets/real-vite-hmr.d.ts +2 -0
- package/dist/facets/real-vite-hmr.d.ts.map +1 -1
- package/dist/facets/real-vite-hmr.js +3 -2
- package/dist/git/commands.d.ts +17 -1
- package/dist/git/commands.d.ts.map +1 -1
- package/dist/git/commands.js +73 -9
- package/dist/git/network-facet.d.ts +2 -0
- package/dist/git/network-facet.d.ts.map +1 -1
- package/dist/git/network-facet.js +10 -5
- package/dist/hosted/commands.d.ts.map +1 -1
- package/dist/hosted/commands.js +2 -2
- package/dist/hosted/runtime.d.ts +3 -2
- package/dist/hosted/runtime.d.ts.map +1 -1
- package/dist/hosted/runtime.js +1 -0
- package/dist/hosted/services.d.ts +8 -0
- package/dist/hosted/services.d.ts.map +1 -1
- package/dist/hosted/services.js +3 -0
- package/dist/loaders/generated-workers.d.ts +2 -2
- package/dist/loaders/generated-workers.d.ts.map +1 -1
- package/dist/loaders/generated-workers.js +4 -4
- package/dist/loaders/pre-bundle-preamble.d.ts +6 -3
- package/dist/loaders/pre-bundle-preamble.d.ts.map +1 -1
- package/dist/loaders/pre-bundle-preamble.js +13 -8
- package/dist/node-shims-artifact.generated.js +3 -3
- package/dist/npm/cache.d.ts +6 -1
- package/dist/npm/cache.d.ts.map +1 -1
- package/dist/npm/cache.js +8 -6
- package/dist/npm/install-batch-facet.d.ts +2 -0
- package/dist/npm/install-batch-facet.d.ts.map +1 -1
- package/dist/npm/install-batch-facet.js +29 -15
- package/dist/npm/installer.d.ts +8 -4
- package/dist/npm/installer.d.ts.map +1 -1
- package/dist/npm/installer.js +173 -113
- package/dist/npm/npx-install.d.ts +3 -1
- package/dist/npm/npx-install.d.ts.map +1 -1
- package/dist/npm/npx-install.js +4 -1
- package/dist/npm/placement.d.ts +16 -0
- package/dist/npm/placement.d.ts.map +1 -0
- package/dist/npm/placement.js +33 -0
- package/dist/npm/r2-cache.d.ts +10 -6
- package/dist/npm/r2-cache.d.ts.map +1 -1
- package/dist/npm/r2-cache.js +32 -16
- package/dist/npm/resolve-one-facet.d.ts +3 -0
- package/dist/npm/resolve-one-facet.d.ts.map +1 -1
- package/dist/npm/resolve-one-facet.js +1 -0
- package/dist/npm/resolver.d.ts +11 -6
- package/dist/npm/resolver.d.ts.map +1 -1
- package/dist/npm/resolver.js +12 -3
- package/dist/runtime/cpython-resident.d.ts.map +1 -1
- package/dist/runtime/cpython-resident.js +2 -10
- package/dist/runtime/esbuild-wasm-bytes.d.ts +25 -18
- package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -1
- package/dist/runtime/esbuild-wasm-bytes.js +55 -30
- package/dist/runtime/facet-loader-host.d.ts.map +1 -1
- package/dist/runtime/facet-loader-host.js +0 -7
- package/dist/runtime/node-shims.d.ts.map +1 -1
- package/dist/runtime/node-shims.js +839 -180
- package/dist/runtime/python-repl.d.ts.map +1 -1
- package/dist/runtime/python-repl.js +2 -33
- package/dist/runtime/ruby-resident.d.ts.map +1 -1
- package/dist/runtime/ruby-resident.js +5 -16
- package/dist/runtime/wasi/preamble.d.ts +0 -22
- package/dist/runtime/wasi/preamble.d.ts.map +1 -1
- package/dist/runtime/wasi/preamble.js +98 -1401
- package/dist/session/hibernation.d.ts +45 -2
- package/dist/session/hibernation.d.ts.map +1 -1
- package/dist/session/hibernation.js +78 -1
- package/dist/session/nimbus-session.d.ts +10 -2
- package/dist/session/nimbus-session.d.ts.map +1 -1
- package/dist/session/nimbus-session.js +13 -1
- package/dist/session/npm-install-port.d.ts.map +1 -1
- package/dist/session/npm-install-port.js +1 -0
- package/dist/session/routes.d.ts.map +1 -1
- package/dist/session/routes.js +4 -2
- package/dist/session/rpc.d.ts +5 -2
- package/dist/session/rpc.d.ts.map +1 -1
- package/dist/session/rpc.js +10 -2
- package/dist/session/supervisor-rpc.d.ts +17 -9
- package/dist/session/supervisor-rpc.d.ts.map +1 -1
- package/dist/session/supervisor-rpc.js +15 -22
- package/dist/workspace-host.d.ts +1 -1
- package/dist/workspace-host.d.ts.map +1 -1
- package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -1
- package/dist/wrangler/nimbus-wrangler.js +3 -0
- package/package.json +30 -4
- package/public/_assets/esbuild-0.24.2.js +2380 -0
- package/public/_assets/runtime/{node-shims-acaa037e6d26ec0d.js → node-shims-7b4dd7a76d95d21e.js} +838 -179
- package/scripts/bundle-esbuild-wasm.mjs +55 -39
- package/scripts/bundle-facet-workers.mjs +45 -7
|
@@ -10,8 +10,10 @@
|
|
|
10
10
|
* than the supervisor's. The facet needs two pieces of esbuild-wasm
|
|
11
11
|
* at module-load time:
|
|
12
12
|
*
|
|
13
|
-
* 1. The JS adapter (`esbuild-wasm/esm/browser.js
|
|
14
|
-
*
|
|
13
|
+
* 1. The JS adapter (`esbuild-wasm/esm/browser.js`, ~117 KiB), rewritten
|
|
14
|
+
* into a function body. The supervisor already imports the same
|
|
15
|
+
* build as a module for its own transforms, so the adapter is staged
|
|
16
|
+
* beside the wasm rather than embedded a second time as a string.
|
|
15
17
|
*
|
|
16
18
|
* 2. The wasm binary (`esbuild.wasm`) — 12 MiB. Lives in the
|
|
17
19
|
* static-assets layer (Workers ASSETS binding) at
|
|
@@ -48,11 +50,15 @@
|
|
|
48
50
|
* Output:
|
|
49
51
|
* src/esbuild-wasm-bundle.generated.ts
|
|
50
52
|
* export const ESBUILD_WASM_VERSION: string;
|
|
53
|
+
* export const ESBUILD_WASM_ASSET_PATH: string; // /_assets/esbuild-<version>.wasm
|
|
54
|
+
* export const ESBUILD_JS_ASSET_PATH: string; // /_assets/esbuild-<version>.js
|
|
51
55
|
* export const ESBUILD_WASM_SHA256: string; // staged wasm digest
|
|
52
|
-
* export const
|
|
56
|
+
* export const ESBUILD_JS_SHA256: string; // staged adapter digest
|
|
53
57
|
*
|
|
54
58
|
* public/_assets/esbuild-<version>.wasm
|
|
55
59
|
* The raw wasm, picked up by the wrangler ASSETS binding.
|
|
60
|
+
* public/_assets/esbuild-<version>.js
|
|
61
|
+
* The adapter as a function body, same binding.
|
|
56
62
|
*
|
|
57
63
|
* Run via:
|
|
58
64
|
* node scripts/bundle-esbuild-wasm.mjs
|
|
@@ -144,8 +150,8 @@ async function main() {
|
|
|
144
150
|
// The ASSETS binding picks up everything under `assets.directory`
|
|
145
151
|
// (./public per wrangler.jsonc). We version-name the file so a
|
|
146
152
|
// future esbuild-wasm bump produces a different asset filename and
|
|
147
|
-
// forces a fresh fetch (no stale-cache risk;
|
|
148
|
-
//
|
|
153
|
+
// forces a fresh fetch (no stale-cache risk; the generated module names
|
|
154
|
+
// the path and src/runtime/esbuild-wasm-bytes.ts reads it).
|
|
149
155
|
await fs.mkdir(OUT_ASSETS_DIR, { recursive: true });
|
|
150
156
|
const assetName = `esbuild-${version}.wasm`;
|
|
151
157
|
const assetOut = path.join(OUT_ASSETS_DIR, assetName);
|
|
@@ -155,53 +161,48 @@ async function main() {
|
|
|
155
161
|
console.log(
|
|
156
162
|
`[bundle-esbuild-wasm] copied esbuild.wasm → ${path.relative(ROOT, assetOut)} (${(wasmBytes.length / (1024 * 1024)).toFixed(1)} MiB)`,
|
|
157
163
|
);
|
|
164
|
+
// The JS adapter is staged the same way. Facets splice it into their
|
|
165
|
+
// source as a string; the supervisor imports esbuild-wasm as a module
|
|
166
|
+
// for its own transforms, so carrying the adapter inline as well
|
|
167
|
+
// shipped it twice in the Worker bundle.
|
|
168
|
+
const jsAssetName = `esbuild-${version}.js`;
|
|
169
|
+
const jsAssetOut = path.join(OUT_ASSETS_DIR, jsAssetName);
|
|
170
|
+
const jsBytes = Buffer.from(jsFn, 'utf8');
|
|
171
|
+
await fs.writeFile(jsAssetOut, jsBytes);
|
|
172
|
+
const jsSha256 = createHash('sha256').update(jsBytes).digest('hex');
|
|
173
|
+
console.log(
|
|
174
|
+
`[bundle-esbuild-wasm] wrote JS adapter → ${path.relative(ROOT, jsAssetOut)} (${(jsBytes.length / 1024).toFixed(1)} KiB)`,
|
|
175
|
+
);
|
|
158
176
|
|
|
159
177
|
// ── 3. Clean up any stale-versioned wasm assets in public/_assets/ ──
|
|
160
178
|
// Keeps the deploy lean: a developer who bumped the esbuild-wasm
|
|
161
179
|
// version locally won't accidentally ship two copies.
|
|
162
180
|
for (const entry of await fs.readdir(OUT_ASSETS_DIR)) {
|
|
163
|
-
if (entry.startsWith('esbuild-') && entry.endsWith('.wasm')
|
|
181
|
+
if (entry.startsWith('esbuild-') && (entry.endsWith('.wasm') || entry.endsWith('.js'))
|
|
182
|
+
&& entry !== assetName && entry !== jsAssetName) {
|
|
164
183
|
const stale = path.join(OUT_ASSETS_DIR, entry);
|
|
165
184
|
await fs.unlink(stale);
|
|
166
185
|
console.log(`[bundle-esbuild-wasm] removed stale asset: ${entry}`);
|
|
167
186
|
}
|
|
168
187
|
}
|
|
169
188
|
|
|
170
|
-
// ── 4. Emit the
|
|
171
|
-
//
|
|
172
|
-
// sat in supervisor module scope for the isolate's lifetime
|
|
173
|
-
// moved
|
|
189
|
+
// ── 4. Emit the generated TS module: versions and digests only ──────
|
|
190
|
+
// Neither artifact is inline. The base64 wasm string was 16 MiB and
|
|
191
|
+
// sat in supervisor module scope for the isolate's lifetime (A'.5
|
|
192
|
+
// moved it to env.ASSETS); the JS adapter followed so the bundle
|
|
193
|
+
// carries esbuild-wasm once, as the module the supervisor imports.
|
|
174
194
|
const header = `/**
|
|
175
195
|
* esbuild-wasm-bundle.generated.ts — AUTO-GENERATED by scripts/bundle-esbuild-wasm.mjs
|
|
176
196
|
* DO NOT EDIT.
|
|
177
197
|
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* public/_assets/esbuild-${version}.wasm and is fetched on demand by
|
|
182
|
-
* src/esbuild-wasm-bytes.ts.
|
|
198
|
+
* Digests of the staged esbuild-wasm ${version} artifacts. Both live in
|
|
199
|
+
* the static-assets layer, public/_assets/esbuild-${version}.{wasm,js},
|
|
200
|
+
* and are fetched on demand and verified by src/runtime/esbuild-wasm-bytes.ts.
|
|
183
201
|
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
export const ESBUILD_WASM_VERSION: string = ${JSON.stringify(version)};
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* SHA-256 of the staged public/_assets/esbuild-${version}.wasm bytes.
|
|
193
|
-
* src/runtime/esbuild-wasm-bytes.ts verifies every fetch against it — the L2
|
|
194
|
-
* (caches.default) tier included — before the bytes reach workerd's loader.
|
|
195
|
-
*/
|
|
196
|
-
export const ESBUILD_WASM_SHA256: string = ${JSON.stringify(wasmSha256)};
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Function body that, when wrapped in \`new Function(...)()\`, returns
|
|
200
|
-
* the esbuild-wasm namespace (build, transform, initialize, ...).
|
|
201
|
-
*
|
|
202
|
-
* Source: node_modules/esbuild-wasm/esm/browser.js with the trailing
|
|
203
|
-
* \`export { ... }\` rewritten to \`return { ... };\`. Why the browser
|
|
204
|
-
* build:
|
|
202
|
+
* The JS adapter is node_modules/esbuild-wasm/esm/browser.js with the
|
|
203
|
+
* trailing \`export { ... }\` rewritten to \`return { ... };\`, so that
|
|
204
|
+
* \`new Function(body)()\` yields the esbuild namespace inside a facet.
|
|
205
|
+
* Why the browser build:
|
|
205
206
|
* - Pure ESM with no \`createRequire\`, no \`require("fs")\`, and
|
|
206
207
|
* no \`process.binding\` — safe to evaluate inside a workerd
|
|
207
208
|
* dynamic-worker isolate.
|
|
@@ -219,13 +220,28 @@ export const ESBUILD_WASM_SHA256: string = ${JSON.stringify(wasmSha256)};
|
|
|
219
220
|
* patterns (createRequire / dynamic node-builtin require / process.binding)
|
|
220
221
|
* and bails loud if a future release reintroduces them.
|
|
221
222
|
*/
|
|
222
|
-
export const
|
|
223
|
+
export const ESBUILD_WASM_VERSION: string = ${JSON.stringify(version)};
|
|
224
|
+
/**
|
|
225
|
+
* Where the artifacts live inside env.ASSETS. Version-named, so a bump
|
|
226
|
+
* lands under a new name and never serves a stale cache entry. Naming them
|
|
227
|
+
* here is what puts them under scripts/dist-integrity.mjs's staged-asset
|
|
228
|
+
* check, which discovers asset paths by value in generated modules.
|
|
229
|
+
*/
|
|
230
|
+
export const ESBUILD_WASM_ASSET_PATH: string = ${JSON.stringify('/_assets/' + assetName)};
|
|
231
|
+
export const ESBUILD_JS_ASSET_PATH: string = ${JSON.stringify('/_assets/' + jsAssetName)};
|
|
232
|
+
/**
|
|
233
|
+
* SHA-256 of the staged public/_assets/esbuild-${version}.wasm bytes.
|
|
234
|
+
* src/runtime/esbuild-wasm-bytes.ts verifies every fetch against it — the L2
|
|
235
|
+
* (caches.default) tier included — before the bytes reach workerd's loader.
|
|
236
|
+
*/
|
|
237
|
+
export const ESBUILD_WASM_SHA256: string = ${JSON.stringify(wasmSha256)};
|
|
238
|
+
/** SHA-256 of the staged public/_assets/esbuild-${version}.js adapter, checked the same way. */
|
|
239
|
+
export const ESBUILD_JS_SHA256: string = ${JSON.stringify(jsSha256)};
|
|
223
240
|
`;
|
|
224
|
-
|
|
225
241
|
await fs.writeFile(OUT_TS, header, 'utf8');
|
|
226
242
|
const stat = await fs.stat(OUT_TS);
|
|
227
243
|
console.log(
|
|
228
|
-
`[bundle-esbuild-wasm] wrote ${path.relative(ROOT, OUT_TS)} (${(stat.size / 1024).toFixed(1)} KiB —
|
|
244
|
+
`[bundle-esbuild-wasm] wrote ${path.relative(ROOT, OUT_TS)} (${(stat.size / 1024).toFixed(1)} KiB — digests only)`,
|
|
229
245
|
);
|
|
230
246
|
}
|
|
231
247
|
|
|
@@ -47,12 +47,53 @@ import { build } from 'esbuild';
|
|
|
47
47
|
import { writeFileSync, mkdirSync } from 'node:fs';
|
|
48
48
|
import { dirname, join } from 'node:path';
|
|
49
49
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
50
|
+
// core's own parser dependency, reached through the workspace hoist; the
|
|
51
|
+
// script runs under plain node at postinstall, so nothing here is TypeScript.
|
|
52
|
+
import { parse } from 'acorn';
|
|
50
53
|
|
|
51
54
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
52
55
|
const root = join(__dirname, '..');
|
|
53
56
|
const coreRoot = join(root, '..', 'core');
|
|
54
57
|
const platformRoot = join(root, '..', 'platform');
|
|
55
58
|
|
|
59
|
+
/**
|
|
60
|
+
* The bundle without its comments. esbuild keeps every comment that sits
|
|
61
|
+
* inside an expression or object literal, plus its own `// path` module
|
|
62
|
+
* markers, and nothing reads any of them: the strings are evaluated, never
|
|
63
|
+
* shown, mapped or `toString()`ed. The comment ranges come from a real
|
|
64
|
+
* parse of the output, so a `//` inside a string, template or regex is
|
|
65
|
+
* untouched; only comments go, and a line that held nothing but a comment
|
|
66
|
+
* goes with it. Every other character, identifier and line stays put.
|
|
67
|
+
*/
|
|
68
|
+
function withoutComments(text) {
|
|
69
|
+
const comments = [];
|
|
70
|
+
parse(text, { ecmaVersion: 'latest', sourceType: 'module', allowAwaitOutsideFunction: true, onComment: comments });
|
|
71
|
+
let out = '';
|
|
72
|
+
let cursor = 0;
|
|
73
|
+
for (const { start, end } of comments) {
|
|
74
|
+
if (start < cursor) continue;
|
|
75
|
+
const lineStart = text.lastIndexOf('\n', start - 1) + 1;
|
|
76
|
+
const lineEndAt = text.indexOf('\n', end);
|
|
77
|
+
const lineEnd = lineEndAt < 0 ? text.length : lineEndAt;
|
|
78
|
+
const leading = text.slice(lineStart, start);
|
|
79
|
+
const trailing = text.slice(end, lineEnd);
|
|
80
|
+
if (leading.trim() === '' && trailing.trim() === '') {
|
|
81
|
+
// The comment is the whole line (or lines): drop them, newline included.
|
|
82
|
+
out += text.slice(cursor, lineStart);
|
|
83
|
+
cursor = lineEndAt < 0 ? text.length : lineEnd + 1;
|
|
84
|
+
} else if (trailing.trim() === '') {
|
|
85
|
+
// Trailing comment: drop it and the blank that led to it.
|
|
86
|
+
out += text.slice(cursor, start).replace(/[ \t]+$/, '');
|
|
87
|
+
cursor = end;
|
|
88
|
+
} else {
|
|
89
|
+
// Mid-line block comment: one space keeps the tokens on either side apart.
|
|
90
|
+
out += `${text.slice(cursor, start)} `;
|
|
91
|
+
cursor = end;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return out + text.slice(cursor);
|
|
95
|
+
}
|
|
96
|
+
|
|
56
97
|
/**
|
|
57
98
|
* Bundle one TS source into a self-contained ESM string suitable for
|
|
58
99
|
* inlining as a facet preamble. Strips the leading `export` on
|
|
@@ -76,7 +117,7 @@ async function bundleAsPreamble(entryPath, label) {
|
|
|
76
117
|
if (!result.outputFiles || result.outputFiles.length === 0) {
|
|
77
118
|
throw new Error(`[bundle-facet-workers/${label}] esbuild produced no output`);
|
|
78
119
|
}
|
|
79
|
-
let stripped = result.outputFiles[0].text;
|
|
120
|
+
let stripped = withoutComments(result.outputFiles[0].text);
|
|
80
121
|
stripped = stripped.replace(/^export\s+(async\s+function|function|const|class)\b/gm, '$1');
|
|
81
122
|
stripped = stripped.replace(/\n?export\s*\{[^}]*\}\s*;\s*$/g, '');
|
|
82
123
|
return stripped;
|
|
@@ -112,7 +153,7 @@ async function bundleVirtualSocketKernel() {
|
|
|
112
153
|
if (!result.outputFiles || result.outputFiles.length === 0) {
|
|
113
154
|
throw new Error('[bundle-facet-workers/virtual-socket-kernel] esbuild produced no output');
|
|
114
155
|
}
|
|
115
|
-
return result.outputFiles[0].text;
|
|
156
|
+
return withoutComments(result.outputFiles[0].text);
|
|
116
157
|
}
|
|
117
158
|
|
|
118
159
|
/**
|
|
@@ -126,10 +167,7 @@ const WASI_REQUIRED_TOP_LEVEL = [
|
|
|
126
167
|
'__wasiMakeImports',
|
|
127
168
|
'__wasiRunStart',
|
|
128
169
|
'__wasiRunStartAsync',
|
|
129
|
-
'__wasiReadFilesB64',
|
|
130
170
|
'__wasiAdoptSupervisor',
|
|
131
|
-
'__wasiDrainPersist',
|
|
132
|
-
'__wasiRevalidateFS',
|
|
133
171
|
'fdTable',
|
|
134
172
|
];
|
|
135
173
|
|
|
@@ -168,7 +206,7 @@ async function bundleWasiInstance() {
|
|
|
168
206
|
if (!result.outputFiles || result.outputFiles.length === 0) {
|
|
169
207
|
throw new Error('[bundle-facet-workers/wasi-instance] esbuild produced no output');
|
|
170
208
|
}
|
|
171
|
-
let src = result.outputFiles[0].text;
|
|
209
|
+
let src = withoutComments(result.outputFiles[0].text);
|
|
172
210
|
// The body is spliced into another module; a re-export block there is a
|
|
173
211
|
// syntax error, and callers append their own `export { … }`.
|
|
174
212
|
src = src.replace(/^export\s+(async\s+function|function|const|let|var|class)\b/gm, '$1');
|
|
@@ -233,7 +271,7 @@ async function bundleBashRunner() {
|
|
|
233
271
|
if (!result.outputFiles || result.outputFiles.length === 0) {
|
|
234
272
|
throw new Error('[bundle-facet-workers/bash-runner] esbuild produced no output');
|
|
235
273
|
}
|
|
236
|
-
const src = result.outputFiles[0].text;
|
|
274
|
+
const src = withoutComments(result.outputFiles[0].text);
|
|
237
275
|
for (const name of ['__bashBoot', '__bashFeed']) {
|
|
238
276
|
if (!new RegExp(`^\\s*globalThis\\.${name}\\s*=`, 'm').test(src)) {
|
|
239
277
|
throw new Error(
|