@nimbus-sh/worker 0.8.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.d.ts +3 -0
- package/dist/facets/compose.d.ts.map +1 -1
- package/dist/facets/compose.js +10 -3
- 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 +54 -15
- package/dist/facets/manager.d.ts.map +1 -1
- package/dist/facets/manager.js +227 -144
- 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 +28 -39
- package/dist/hosted/runtime.d.ts +24 -2
- package/dist/hosted/runtime.d.ts.map +1 -1
- package/dist/hosted/runtime.js +70 -13
- package/dist/hosted/services.d.ts +14 -2
- package/dist/hosted/services.d.ts.map +1 -1
- package/dist/hosted/services.js +15 -2
- 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/bash-repl.d.ts +5 -3
- package/dist/runtime/bash-repl.d.ts.map +1 -1
- package/dist/runtime/bash-repl.js +8 -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 -9
- package/dist/runtime/node-shims.d.ts.map +1 -1
- package/dist/runtime/node-shims.js +853 -181
- package/dist/runtime/python-repl.d.ts +4 -3
- package/dist/runtime/python-repl.d.ts.map +1 -1
- package/dist/runtime/python-repl.js +10 -39
- package/dist/runtime/ruby-repl.d.ts +3 -2
- package/dist/runtime/ruby-repl.d.ts.map +1 -1
- package/dist/runtime/ruby-repl.js +7 -6
- package/dist/runtime/ruby-resident.d.ts.map +1 -1
- package/dist/runtime/ruby-resident.js +5 -16
- package/dist/runtime/runtime-catalog.js +1 -1
- 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 +160 -1445
- package/dist/runtime-catalog.generated.js +1 -1
- 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/init.d.ts.map +1 -1
- package/dist/session/init.js +1 -0
- package/dist/session/nimbus-session.d.ts +16 -23
- package/dist/session/nimbus-session.d.ts.map +1 -1
- package/dist/session/nimbus-session.js +25 -36
- package/dist/session/npm-install-port.d.ts.map +1 -1
- package/dist/session/npm-install-port.js +1 -0
- package/dist/session/port-capability.d.ts.map +1 -1
- package/dist/session/port-capability.js +11 -1
- package/dist/session/programmatic.js +2 -2
- package/dist/session/routes.d.ts.map +1 -1
- package/dist/session/routes.js +4 -2
- package/dist/session/rpc.d.ts +7 -44
- package/dist/session/rpc.d.ts.map +1 -1
- package/dist/session/rpc.js +17 -67
- package/dist/session/supervisor-op.d.ts +8 -3
- package/dist/session/supervisor-op.d.ts.map +1 -1
- package/dist/session/supervisor-op.js +10 -45
- package/dist/session/supervisor-rpc.d.ts +47 -22
- package/dist/session/supervisor-rpc.d.ts.map +1 -1
- package/dist/session/supervisor-rpc.js +64 -26
- package/dist/vfs/facet-resident-store.d.ts.map +1 -1
- package/dist/vfs/facet-resident-store.js +4 -2
- package/dist/workspace-host.d.ts +2 -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-8f8c64edd2a1f0f5.js → node-shims-7b4dd7a76d95d21e.js} +852 -180
- package/scripts/bundle-esbuild-wasm.mjs +55 -39
- package/scripts/bundle-facet-workers.mjs +45 -7
- package/scripts/bundle-runtime.mjs +35 -8
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* esbuild-wasm-bytes.ts — supervisor-side fetcher for the esbuild-wasm
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* esbuild-wasm-bytes.ts — supervisor-side fetcher for the two esbuild-wasm
|
|
3
|
+
* artifacts a transform facet is built from: the wasm binary and the JS
|
|
4
|
+
* adapter that drives it. Both live in the static-assets layer
|
|
5
|
+
* (env.ASSETS); this module hands them to the caller when needed.
|
|
5
6
|
*
|
|
6
7
|
* Cache strategy
|
|
7
8
|
* ──────────────
|
|
8
9
|
* - NO module-scope cache (would pin 16 MiB in supervisor heap; the
|
|
9
10
|
* reason this module exists, see Phase 2 A'.5 below).
|
|
10
11
|
* - L2 colo cache via `caches.default` (cache-and-scrub W-D): the bytes
|
|
11
|
-
* are version-pinned by URL (`/_assets/esbuild-<ESBUILD_VERSION
|
|
12
|
+
* are version-pinned by URL (`/_assets/esbuild-<ESBUILD_VERSION>.*`),
|
|
12
13
|
* so an `immutable` cache entry is correct. The Cache API holds its
|
|
13
14
|
* OWN reference outside the supervisor heap, so this does not
|
|
14
15
|
* re-introduce the residency that A'.5 removed.
|
|
@@ -28,6 +29,11 @@
|
|
|
28
29
|
* are stored OUTSIDE the supervisor heap (workerd manages them), so
|
|
29
30
|
* adding L2 wrap doesn't undo this.
|
|
30
31
|
*
|
|
32
|
+
* The JS adapter followed the wasm for the same reason at a smaller
|
|
33
|
+
* scale: the supervisor already imports esbuild-wasm's browser build as a
|
|
34
|
+
* module for its own transforms, so carrying the same 117 KiB again as a
|
|
35
|
+
* string literal for facets doubled it in the Worker bundle.
|
|
36
|
+
*
|
|
31
37
|
* Each call to `fetchEsbuildWasmBytes(env)` now does:
|
|
32
38
|
* - one `caches.default.match()` — sub-millisecond on hit
|
|
33
39
|
* - on miss: one env.ASSETS.fetch() + one cache write-back
|
|
@@ -39,31 +45,39 @@
|
|
|
39
45
|
* Cache lookup failure (any throw) → fall through to ASSETS.
|
|
40
46
|
* ASSETS fetch returning non-200 → throw (deploy bug, surface loudly).
|
|
41
47
|
* Digest mismatch on either tier → throw (the bytes are compiled as a wasm
|
|
42
|
-
* module, so they are verified against
|
|
48
|
+
* module or evaluated as facet code, so they are verified against the
|
|
49
|
+
* digest the generator recorded before returning).
|
|
43
50
|
*/
|
|
44
|
-
import {
|
|
45
|
-
import { ESBUILD_WASM_SHA256 } from '../esbuild-wasm-bundle.generated.js';
|
|
51
|
+
import { ESBUILD_JS_ASSET_PATH, ESBUILD_JS_SHA256, ESBUILD_WASM_ASSET_PATH, ESBUILD_WASM_SHA256, } from '../esbuild-wasm-bundle.generated.js';
|
|
46
52
|
import { disposeRpcResource } from '@nimbus-sh/platform/rpc-dispose.js';
|
|
47
53
|
import { sha256Hex } from '@nimbus-sh/core/_shared/crypto.js';
|
|
48
54
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* scripts/bundle-esbuild-wasm.mjs at predeploy time.
|
|
54
|
-
*/
|
|
55
|
-
export const ESBUILD_WASM_ASSET_PATH = `/_assets/esbuild-${ESBUILD_VERSION}.wasm`;
|
|
56
|
-
/**
|
|
57
|
-
* Synthetic L2 cache key for the esbuild-wasm asset. Versioned via
|
|
58
|
-
* ESBUILD_WASM_ASSET_PATH so each esbuild upgrade lands a fresh entry
|
|
59
|
-
* and old entries naturally evict on TTL.
|
|
55
|
+
* Synthetic L2 cache keys for the esbuild-wasm assets, staged at
|
|
56
|
+
* public/_assets/esbuild-<version>.{wasm,js} by scripts/bundle-esbuild-wasm.mjs
|
|
57
|
+
* at predeploy time. Versioned via the asset paths so each esbuild upgrade
|
|
58
|
+
* lands fresh entries and old ones naturally evict on TTL.
|
|
60
59
|
*
|
|
61
60
|
* Exported so the test endpoint at /api/_test/cache/wasm/reset can
|
|
62
|
-
* purge the
|
|
61
|
+
* purge the entries between probe runs (otherwise wrangler dev's
|
|
63
62
|
* persistent caches.default.state preserves the L2 hit across sessions
|
|
64
63
|
* and the cold path is unobservable).
|
|
65
64
|
*/
|
|
66
|
-
export const ESBUILD_WASM_L2_KEY = `https://nimbus-cache.invalid
|
|
65
|
+
export const ESBUILD_WASM_L2_KEY = `https://nimbus-cache.invalid${ESBUILD_WASM_ASSET_PATH}`;
|
|
66
|
+
export const ESBUILD_JS_L2_KEY = `https://nimbus-cache.invalid${ESBUILD_JS_ASSET_PATH}`;
|
|
67
|
+
const ESBUILD_WASM_ASSET = {
|
|
68
|
+
label: 'esbuild-wasm',
|
|
69
|
+
path: ESBUILD_WASM_ASSET_PATH,
|
|
70
|
+
l2Key: ESBUILD_WASM_L2_KEY,
|
|
71
|
+
sha256: ESBUILD_WASM_SHA256,
|
|
72
|
+
contentType: 'application/wasm',
|
|
73
|
+
};
|
|
74
|
+
const ESBUILD_JS_ASSET = {
|
|
75
|
+
label: 'esbuild-wasm JS adapter',
|
|
76
|
+
path: ESBUILD_JS_ASSET_PATH,
|
|
77
|
+
l2Key: ESBUILD_JS_L2_KEY,
|
|
78
|
+
sha256: ESBUILD_JS_SHA256,
|
|
79
|
+
contentType: 'text/javascript; charset=utf-8',
|
|
80
|
+
};
|
|
67
81
|
/**
|
|
68
82
|
* Fetch the esbuild-wasm bytes from the static-assets layer.
|
|
69
83
|
*
|
|
@@ -77,13 +91,24 @@ export const ESBUILD_WASM_L2_KEY = `https://nimbus-cache.invalid/_assets/esbuild
|
|
|
77
91
|
* to env.ASSETS and write-back. Cache failures are silent — ASSETS is
|
|
78
92
|
* always the correct source of truth.
|
|
79
93
|
*/
|
|
80
|
-
export
|
|
94
|
+
export function fetchEsbuildWasmBytes(env) {
|
|
95
|
+
return fetchVerifiedAsset(env, ESBUILD_WASM_ASSET);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Fetch the esbuild-wasm JS adapter: the function body that, wrapped in
|
|
99
|
+
* `new Function(...)()`, returns the esbuild namespace. Facet sources
|
|
100
|
+
* splice it in verbatim, so it is verified like the wasm it drives.
|
|
101
|
+
*/
|
|
102
|
+
export async function fetchEsbuildJsFnBody(env) {
|
|
103
|
+
return new TextDecoder().decode(await fetchVerifiedAsset(env, ESBUILD_JS_ASSET));
|
|
104
|
+
}
|
|
105
|
+
async function fetchVerifiedAsset(env, asset) {
|
|
81
106
|
const caches = globalThis.caches;
|
|
82
107
|
// ── L2 fast path ────────────────────────────────────────────────
|
|
83
108
|
let ab = null;
|
|
84
109
|
try {
|
|
85
110
|
if (caches?.default) {
|
|
86
|
-
const hit = await caches.default.match(new Request(
|
|
111
|
+
const hit = await caches.default.match(new Request(asset.l2Key));
|
|
87
112
|
if (hit && hit.ok)
|
|
88
113
|
ab = await hit.arrayBuffer();
|
|
89
114
|
}
|
|
@@ -95,12 +120,12 @@ export async function fetchEsbuildWasmBytes(env) {
|
|
|
95
120
|
// Construct a synthetic request — env.ASSETS routes by pathname only;
|
|
96
121
|
// the host is ignored. Using `.invalid` per RFC-2606 makes it
|
|
97
122
|
// unambiguous that this URL is internal-binding-only.
|
|
98
|
-
const url = `https://nimbus-internal.invalid${
|
|
123
|
+
const url = `https://nimbus-internal.invalid${asset.path}`;
|
|
99
124
|
const res = await env.ASSETS.fetch(new Request(url));
|
|
100
125
|
try {
|
|
101
126
|
if (!res.ok) {
|
|
102
|
-
throw new Error(
|
|
103
|
-
`for ${
|
|
127
|
+
throw new Error(`${asset.label} asset fetch failed: ${res.status} ${res.statusText} ` +
|
|
128
|
+
`for ${asset.path} — deploy is missing the asset`);
|
|
104
129
|
}
|
|
105
130
|
// Read the bytes once (Response body is a one-shot stream). The
|
|
106
131
|
// caller needs the ArrayBuffer to hand to workerd's LOADER; we
|
|
@@ -112,9 +137,9 @@ export async function fetchEsbuildWasmBytes(env) {
|
|
|
112
137
|
}
|
|
113
138
|
}
|
|
114
139
|
const digest = await sha256Hex(ab);
|
|
115
|
-
if (digest !==
|
|
116
|
-
throw new Error(
|
|
117
|
-
`${digest} (${fromCache ? 'L2 cache' : 'ASSETS'}) for ${
|
|
140
|
+
if (digest !== asset.sha256) {
|
|
141
|
+
throw new Error(`${asset.label} integrity check failed: expected ${asset.sha256}, got ` +
|
|
142
|
+
`${digest} (${fromCache ? 'L2 cache' : 'ASSETS'}) for ${asset.path} — ` +
|
|
118
143
|
'the staged asset is corrupt or out of sync; rerun ' +
|
|
119
144
|
'scripts/bundle-esbuild-wasm.mjs and redeploy');
|
|
120
145
|
}
|
|
@@ -134,14 +159,14 @@ export async function fetchEsbuildWasmBytes(env) {
|
|
|
134
159
|
// detach the buffer (only ReadableStream consumption would).
|
|
135
160
|
const writeBack = new Response(new Uint8Array(ab), {
|
|
136
161
|
headers: {
|
|
137
|
-
'Content-Type':
|
|
162
|
+
'Content-Type': asset.contentType,
|
|
138
163
|
'Cache-Control': 'public, max-age=31536000, immutable',
|
|
139
164
|
},
|
|
140
165
|
});
|
|
141
166
|
// Awaited so subsequent reads strictly hit L2 (no
|
|
142
167
|
// double-fetch race). The wasm payload is 12 MiB; workerd
|
|
143
168
|
// structured-clones it into the cache, ~1-5 ms locally.
|
|
144
|
-
await caches.default.put(new Request(
|
|
169
|
+
await caches.default.put(new Request(asset.l2Key), writeBack);
|
|
145
170
|
}
|
|
146
171
|
}
|
|
147
172
|
catch { /* silent */ }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facet-loader-host.d.ts","sourceRoot":"","sources":["../../src/runtime/facet-loader-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"facet-loader-host.d.ts","sourceRoot":"","sources":["../../src/runtime/facet-loader-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAS,SAAS,EAAa,MAAM,uCAAuC,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,kBAAkB,GAAG,SAAS,CAiBhF;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,YAAY,GACrB;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,kBAAkB,CAAA;CAAE,CAM3C;AAED,uEAAuE;AACvE,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAGrE"}
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import { manifestVfs } from '@nimbus-sh/core/runtime/vfs-manifest.js';
|
|
2
1
|
import { IsolatePool } from '@nimbus-sh/fabric/isolate-pool.js';
|
|
3
2
|
export function loaderFacetHost(env, ctx) {
|
|
4
3
|
return {
|
|
5
4
|
// workerd suspends a guest through JSPI, which is what lets a syscall reach
|
|
6
5
|
// back to the session mid-instruction.
|
|
7
6
|
parking: 'jspi',
|
|
8
|
-
/**
|
|
9
|
-
* A manifest, not a copy: sizes and modes, with the facet demand-loading
|
|
10
|
-
* whatever the program opens through its supervisor. It has to be — the
|
|
11
|
-
* whole seed crosses one RPC, and a session filesystem does not fit in one.
|
|
12
|
-
*/
|
|
13
|
-
seedFilesystem(vfs, root, options) {
|
|
14
|
-
return manifestVfs(vfs, root, options);
|
|
15
|
-
},
|
|
16
7
|
open(spec) {
|
|
17
8
|
return new IsolatePool(env, ctx, {
|
|
18
9
|
tag: spec.tag,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-shims.d.ts","sourceRoot":"","sources":["../../src/runtime/node-shims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;
|
|
1
|
+
{"version":3,"file":"node-shims.d.ts","sourceRoot":"","sources":["../../src/runtime/node-shims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAiDH,wBAAgB,iBAAiB,IAAI,MAAM,CAmrQ1C"}
|