@seanhogg/builderforce-webcontainers-core 2026.10.9 → 2026.10.11
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/installer/tree.d.ts.map +1 -1
- package/dist/installer/tree.js +12 -5
- package/dist/installer/tree.js.map +1 -1
- package/dist/installer/wasmBuilds.d.ts +13 -6
- package/dist/installer/wasmBuilds.d.ts.map +1 -1
- package/dist/installer/wasmBuilds.js +17 -8
- package/dist/installer/wasmBuilds.js.map +1 -1
- package/dist/node/builtins.d.ts.map +1 -1
- package/dist/node/builtins.js +2 -0
- package/dist/node/builtins.js.map +1 -1
- package/dist/node/misc.d.ts.map +1 -1
- package/dist/node/misc.js +0 -1
- package/dist/node/misc.js.map +1 -1
- package/dist/node/wasi/abi.d.ts +82 -0
- package/dist/node/wasi/abi.d.ts.map +1 -0
- package/dist/node/wasi/abi.js +144 -0
- package/dist/node/wasi/abi.js.map +1 -0
- package/dist/node/wasi/files.d.ts +67 -0
- package/dist/node/wasi/files.d.ts.map +1 -0
- package/dist/node/wasi/files.js +319 -0
- package/dist/node/wasi/files.js.map +1 -0
- package/dist/node/wasi/index.d.ts +17 -0
- package/dist/node/wasi/index.d.ts.map +1 -0
- package/dist/node/wasi/index.js +129 -0
- package/dist/node/wasi/index.js.map +1 -0
- package/dist/rootedFs.d.ts +19 -0
- package/dist/rootedFs.d.ts.map +1 -0
- package/dist/rootedFs.js +97 -0
- package/dist/rootedFs.js.map +1 -0
- package/dist/shell/devHandoff.d.ts.map +1 -1
- package/dist/shell/devHandoff.js +3 -1
- package/dist/shell/devHandoff.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/installer/tree.ts +13 -4
- package/src/installer/wasmBuilds.ts +24 -9
- package/src/node/builtins.ts +2 -0
- package/src/node/misc.ts +0 -1
- package/src/node/wasi/abi.ts +151 -0
- package/src/node/wasi/files.ts +350 -0
- package/src/node/wasi/index.ts +149 -0
- package/src/rootedFs.ts +108 -0
- package/src/shell/devHandoff.ts +3 -1
package/dist/rootedFs.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A directory of a {@link VirtualFileSystem}, seen as a whole file system:
|
|
3
|
+
* `/src/App.tsx` in the view is `<root>/src/App.tsx` in the base. Reads, writes
|
|
4
|
+
* and watch events pass straight through (the base stays the one store), and
|
|
5
|
+
* nothing outside `root` is visible.
|
|
6
|
+
*
|
|
7
|
+
* This is how a project lives below the file-system root (`/home/project`)
|
|
8
|
+
* while the dev server, builds, zips and the host's own file access keep
|
|
9
|
+
* addressing it as `/`. Node programs see the base, so `process.cwd()` is a real
|
|
10
|
+
* directory: tools that watch their project (chokidar under Vite) misbehave when
|
|
11
|
+
* it is `/` itself.
|
|
12
|
+
*
|
|
13
|
+
* A subclass so it is accepted wherever a `VirtualFileSystem` is; every public
|
|
14
|
+
* method is mapped (rootedFs.test.ts fails on one that is not).
|
|
15
|
+
*/
|
|
16
|
+
import { VirtualFileSystem } from './vfs.js';
|
|
17
|
+
import { normalizePath } from './paths.js';
|
|
18
|
+
class RootedFileSystem extends VirtualFileSystem {
|
|
19
|
+
base;
|
|
20
|
+
root;
|
|
21
|
+
prefix;
|
|
22
|
+
constructor(base, root) {
|
|
23
|
+
super();
|
|
24
|
+
this.base = base;
|
|
25
|
+
this.root = root;
|
|
26
|
+
this.prefix = root + '/';
|
|
27
|
+
}
|
|
28
|
+
/** View path → base path. */
|
|
29
|
+
real(path) {
|
|
30
|
+
const key = normalizePath(path);
|
|
31
|
+
return key === '/' ? this.root : this.root + key;
|
|
32
|
+
}
|
|
33
|
+
/** Base path under `root` → view path. */
|
|
34
|
+
local(path) {
|
|
35
|
+
return path === this.root ? '/' : path.slice(this.root.length);
|
|
36
|
+
}
|
|
37
|
+
writeFile(path, contents) {
|
|
38
|
+
if (normalizePath(path) === '/')
|
|
39
|
+
throw new Error(`EISDIR: illegal operation on a directory, open '/'`);
|
|
40
|
+
this.base.writeFile(this.real(path), contents);
|
|
41
|
+
}
|
|
42
|
+
readFile(path) {
|
|
43
|
+
return this.base.readFile(this.real(path));
|
|
44
|
+
}
|
|
45
|
+
isFile(path) {
|
|
46
|
+
return this.base.isFile(this.real(path));
|
|
47
|
+
}
|
|
48
|
+
isDirectory(path) {
|
|
49
|
+
return normalizePath(path) === '/' || this.base.isDirectory(this.real(path));
|
|
50
|
+
}
|
|
51
|
+
mkdir(path) {
|
|
52
|
+
if (normalizePath(path) !== '/')
|
|
53
|
+
this.base.mkdir(this.real(path));
|
|
54
|
+
}
|
|
55
|
+
readdir(path) {
|
|
56
|
+
return this.base.readdir(this.real(path));
|
|
57
|
+
}
|
|
58
|
+
entries(path) {
|
|
59
|
+
return this.base.entries(this.real(path));
|
|
60
|
+
}
|
|
61
|
+
rename(from, to) {
|
|
62
|
+
this.base.rename(this.real(from), this.real(to));
|
|
63
|
+
}
|
|
64
|
+
list() {
|
|
65
|
+
return this.base.list().filter((path) => path.startsWith(this.prefix)).map((path) => this.local(path));
|
|
66
|
+
}
|
|
67
|
+
explicitDirectories() {
|
|
68
|
+
return this.base.explicitDirectories().filter((dir) => dir.startsWith(this.prefix)).map((dir) => this.local(dir));
|
|
69
|
+
}
|
|
70
|
+
rm(path) {
|
|
71
|
+
this.base.rm(this.real(path));
|
|
72
|
+
}
|
|
73
|
+
version(path) {
|
|
74
|
+
return this.base.version(this.real(path));
|
|
75
|
+
}
|
|
76
|
+
mtime(path) {
|
|
77
|
+
return this.base.mtime(this.real(path));
|
|
78
|
+
}
|
|
79
|
+
toFlat() {
|
|
80
|
+
const out = {};
|
|
81
|
+
for (const path of this.list())
|
|
82
|
+
out[path.slice(1)] = this.readFile(path);
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
watch(listener, options = {}) {
|
|
86
|
+
return this.base.watch((change) => {
|
|
87
|
+
if (change.path !== this.root)
|
|
88
|
+
listener({ ...change, path: this.local(change.path) });
|
|
89
|
+
}, { under: this.real(options.under ?? '/') });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** `fs` seen from `root` (`/` is `fs` itself). */
|
|
93
|
+
export function rootedFileSystem(fs, root) {
|
|
94
|
+
const key = normalizePath(root);
|
|
95
|
+
return key === '/' ? fs : new RootedFileSystem(fs, key);
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=rootedFs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rootedFs.js","sourceRoot":"","sources":["../src/rootedFs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,iBAAiB,EAAwE,MAAM,UAAU,CAAC;AACnH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,gBAAiB,SAAQ,iBAAiB;IAGjB;IAA0C;IAFtD,MAAM,CAAS;IAEhC,YAA6B,IAAuB,EAAmB,IAAY;QACjF,KAAK,EAAE,CAAC;QADmB,SAAI,GAAJ,IAAI,CAAmB;QAAmB,SAAI,GAAJ,IAAI,CAAQ;QAEjF,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC;IAC3B,CAAC;IAED,6BAA6B;IACrB,IAAI,CAAC,IAAY;QACvB,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;QAChC,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IACnD,CAAC;IAED,0CAA0C;IAClC,KAAK,CAAC,IAAY;QACxB,OAAO,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjE,CA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C,QAAQ,CAAC,IAAI,CAAE,CAAC;QAC1E,OAAO,GAAG,CAAC;IACb,CAAC;IAEQ,KAAK,CAAC,QAAoC,EAAE,UAA8B,EAAE;QACnF,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;YAChC,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI;gBAAE,QAAQ,CAAC,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACxF,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC;IACjD,CAAC;CACF;AAED,kDAAkD;AAClD,MAAM,UAAU,gBAAgB,CAAC,EAAqB,EAAE,IAAY;IAClE,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devHandoff.d.ts","sourceRoot":"","sources":["../../src/shell/devHandoff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"devHandoff.d.ts","sourceRoot":"","sources":["../../src/shell/devHandoff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAInD,UAAU,OAAO;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,6DAA6D;AAC7D,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,GAAG,SAAS,CAMlE;AAED,kGAAkG;AAClG,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,GAAG,SAAS,CAIzF;AASD,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAahH"}
|
package/dist/shell/devHandoff.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ownServerReason } from '../detectProject.js';
|
|
2
|
+
import { rootedFileSystem } from '../rootedFs.js';
|
|
2
3
|
/** Does this command line start a dev server we hand off? */
|
|
3
4
|
export function matchDevServer(argv) {
|
|
4
5
|
const [command, ...rest] = argv;
|
|
@@ -12,7 +13,8 @@ export function matchDevServer(argv) {
|
|
|
12
13
|
/** The handoff for this command line, when the attached preview can serve the project instead. */
|
|
13
14
|
export function devServerHandoff(ctx, argv) {
|
|
14
15
|
const handoff = matchDevServer(argv);
|
|
15
|
-
|
|
16
|
+
// The project is the working directory (`npm run` starts scripts in the package's own).
|
|
17
|
+
return handoff && ctx.system.previewUrl && !ownServerReason(rootedFileSystem(ctx.fs, ctx.cwd)) ? handoff : undefined;
|
|
16
18
|
}
|
|
17
19
|
function portOf(argv, fallback, env) {
|
|
18
20
|
const at = argv.findIndex((a) => a === '--port' || a.startsWith('--port='));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devHandoff.js","sourceRoot":"","sources":["../../src/shell/devHandoff.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"devHandoff.js","sourceRoot":"","sources":["../../src/shell/devHandoff.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,g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AC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seanhogg/builderforce-webcontainers-core",
|
|
3
|
-
"version": "2026.10.
|
|
3
|
+
"version": "2026.10.11",
|
|
4
4
|
"description": "BuilderForce WebContainers — core. A runtime-agnostic in-browser dev server: virtual file system, module resolution, import rewriting to a package CDN, CSS/JSON/asset modules and project detection. No COOP/COEP required.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { VirtualFileSystem } from './vfs.js';
|
|
2
2
|
export type { FileContent, FileTree, FlatFiles, FsChange } from './vfs.js';
|
|
3
3
|
export type { DirectoryEntry } from './vfs.js';
|
|
4
|
+
export { rootedFileSystem } from './rootedFs.js';
|
|
4
5
|
export { exportZip, importZip } from './archive.js';
|
|
5
6
|
export type { ZipExportOptions } from './archive.js';
|
|
6
7
|
export { normalizePath, dirname, basename, join, extname } from './paths.js';
|
package/src/installer/tree.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import type { PackageManifest } from './registry.js';
|
|
14
14
|
import { parseDependency, type PackageJson, type ParsedSpec } from './spec.js';
|
|
15
15
|
import { satisfies, validRange } from './semver.js';
|
|
16
|
-
import {
|
|
16
|
+
import { napiWasmSiblings, wasmBuildOf } from './wasmBuilds.js';
|
|
17
17
|
|
|
18
18
|
export type EdgeType = 'prod' | 'dev' | 'optional' | 'peer';
|
|
19
19
|
|
|
@@ -34,6 +34,8 @@ interface Dependency {
|
|
|
34
34
|
type: EdgeType;
|
|
35
35
|
/** Added by this installer (a napi-rs wasm binding), not declared: missing is silent. */
|
|
36
36
|
implied?: boolean;
|
|
37
|
+
/** Installed only when this preferred package did not resolve (the threaded wasm binding stands in for the single-threaded one). */
|
|
38
|
+
fallbackFor?: string;
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
interface Edge extends Dependency {
|
|
@@ -99,8 +101,10 @@ function dependenciesOf(m: PackageJson | PackageManifest, isRoot: boolean, produ
|
|
|
99
101
|
if (isRoot && !production) add((m as PackageJson).devDependencies, 'dev');
|
|
100
102
|
add(m.dependencies, 'prod');
|
|
101
103
|
add(m.optionalDependencies, 'optional');
|
|
102
|
-
const sibling
|
|
103
|
-
|
|
104
|
+
for (const sibling of napiWasmSiblings(m.optionalDependencies)) {
|
|
105
|
+
const listed = out.get(sibling.name);
|
|
106
|
+
out.set(sibling.name, listed ? { ...listed, fallbackFor: sibling.fallbackFor } : { name: sibling.name, range: sibling.range, type: 'optional', implied: true, fallbackFor: sibling.fallbackFor });
|
|
107
|
+
}
|
|
104
108
|
if (!isRoot) {
|
|
105
109
|
const meta = (m as PackageManifest).peerDependenciesMeta ?? {};
|
|
106
110
|
for (const [name, range] of Object.entries(m.peerDependencies ?? {})) {
|
|
@@ -108,7 +112,8 @@ function dependenciesOf(m: PackageJson | PackageManifest, isRoot: boolean, produ
|
|
|
108
112
|
}
|
|
109
113
|
}
|
|
110
114
|
const bundled = bundledNames(m as PackageManifest);
|
|
111
|
-
|
|
115
|
+
// A fallback resolves after the flavor it stands in for, so it can see whether that one landed.
|
|
116
|
+
return [...out.values()].filter((d) => !bundled.has(d.name)).sort((a, b) => Number(!!a.fallbackFor) - Number(!!b.fallbackFor) || (a.name < b.name ? -1 : 1));
|
|
112
117
|
}
|
|
113
118
|
|
|
114
119
|
/** A native-binary package's wasm twin when one fits the range (`wasmBuilds.ts`), else the package itself. */
|
|
@@ -183,6 +188,10 @@ export async function resolveTree(options: ResolveTreeOptions): Promise<Map<stri
|
|
|
183
188
|
for (const dep of deps) {
|
|
184
189
|
const spec = specs.get(dep.name);
|
|
185
190
|
if (!spec) continue;
|
|
191
|
+
if (dep.fallbackFor) {
|
|
192
|
+
const preferred = lookup(location, dep.fallbackFor);
|
|
193
|
+
if (preferred && matches(nodes.get(preferred)!.manifest.version, specs.get(dep.fallbackFor)?.range ?? spec.range)) continue;
|
|
194
|
+
}
|
|
186
195
|
const from = dep.type === 'peer' ? parentLocation(location) : location;
|
|
187
196
|
const existing = lookup(from, dep.name);
|
|
188
197
|
const edge = { ...dep, range: spec.range, owner: location, from };
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* requires `esbuild` gets `esbuild-wasm` at the same version, with the same
|
|
6
6
|
* JavaScript API. Vite, Nuxt, SvelteKit, tsx and tsup all reach for these.
|
|
7
7
|
* Data, not branches: another tool with an official wasm twin is one more row.
|
|
8
|
-
* - A napi-rs
|
|
8
|
+
* - A napi-rs WebAssembly binding (`napiWasmSiblings`), added beside the
|
|
9
9
|
* per-platform ones the package lists.
|
|
10
10
|
*/
|
|
11
11
|
import type { ParsedSpec } from './spec.js';
|
|
@@ -18,19 +18,34 @@ const WASM_BUILDS: Readonly<Record<string, string>> = {
|
|
|
18
18
|
/** A napi-rs per-platform binding name: `@oxc-parser/binding-linux-x64-gnu`, `lightningcss-darwin-arm64`. */
|
|
19
19
|
const NAPI_PLATFORM = /-(?:darwin|linux|win32|android|freebsd|openharmony|sunos|aix)-[a-z0-9_-]+$/;
|
|
20
20
|
|
|
21
|
+
/** WebAssembly binding flavors, preferred first: `wasip1` is single-threaded (no shared memory, so no cross-origin isolation); `wasi` needs threads. */
|
|
22
|
+
const NAPI_WASM_FLAVORS = ['-wasm32-wasip1', '-wasm32-wasi'] as const;
|
|
23
|
+
|
|
24
|
+
export interface NapiWasmSibling {
|
|
25
|
+
name: string;
|
|
26
|
+
range: string;
|
|
27
|
+
/** Install only when this preferred flavor did not resolve. */
|
|
28
|
+
fallbackFor?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
21
31
|
/**
|
|
22
32
|
* napi-rs packages list a binding per platform as optional dependencies, none of
|
|
23
|
-
* which fits here; most also publish
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
33
|
+
* which fits here; most also publish WebAssembly siblings they look for next but do
|
|
34
|
+
* not list (oxc-parser, rolldown, @tailwindcss/oxide). This names them, at the
|
|
35
|
+
* bindings' range, as optional dependencies: the single-threaded `-wasm32-wasip1`
|
|
36
|
+
* first, the threaded `-wasm32-wasi` only if that one is not published (a registry
|
|
37
|
+
* miss is skipped like any optional one). Nothing when the package lists the single-threaded one itself; one that lists only the threaded one gets the single-threaded one added, and its own entry becomes the fallback.
|
|
27
38
|
*/
|
|
28
|
-
export function
|
|
39
|
+
export function napiWasmSiblings(optional: Readonly<Record<string, string>> | undefined): NapiWasmSibling[] {
|
|
29
40
|
const bindings = Object.entries(optional ?? {}).filter(([name]) => NAPI_PLATFORM.test(name));
|
|
30
|
-
if (bindings.length < 2) return
|
|
41
|
+
if (bindings.length < 2) return [];
|
|
31
42
|
const [first, range] = bindings[0]!;
|
|
32
|
-
const
|
|
33
|
-
|
|
43
|
+
const base = first.replace(NAPI_PLATFORM, '');
|
|
44
|
+
if (bindings.some(([name]) => name.replace(NAPI_PLATFORM, '') !== base)) return [];
|
|
45
|
+
const [preferred, fallback] = NAPI_WASM_FLAVORS.map((flavor) => base + flavor) as [string, string];
|
|
46
|
+
if (optional![preferred]) return [];
|
|
47
|
+
// Listing only the threaded flavor still gets the single-threaded one added; the listed entry becomes its fallback.
|
|
48
|
+
return [{ name: preferred, range }, { name: fallback, range, fallbackFor: preferred }];
|
|
34
49
|
}
|
|
35
50
|
|
|
36
51
|
/**
|
package/src/node/builtins.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { createStdinRead } from './fs/stdinFd.js';
|
|
|
18
18
|
import { constants as fsConstants } from './fs/stats.js';
|
|
19
19
|
import { createCryptoModule } from './crypto.js';
|
|
20
20
|
import { createQuerystringModule, createUrlModule } from './urlqs.js';
|
|
21
|
+
import { createWasiModule } from './wasi/index.js';
|
|
21
22
|
import { createAssertModule } from './assert.js';
|
|
22
23
|
import { createZlibModule } from './zlib.js';
|
|
23
24
|
import { createHttpModule, createNetModule, createFetch } from './http/index.js';
|
|
@@ -107,6 +108,7 @@ export function createBuiltins(deps: BuiltinDeps) {
|
|
|
107
108
|
util: () => createUtilModule(env, (message) => proc.stderr.write(message + '\n')),
|
|
108
109
|
'util/types': () => utilTypes,
|
|
109
110
|
vm: () => createVmModule(),
|
|
111
|
+
wasi: (get) => createWasiModule({ fs: get('fs'), stdout: (bytes) => void proc.stdout.write(bytes), stderr: (bytes) => void proc.stderr.write(bytes), exit: (code) => proc.exit(code) }),
|
|
110
112
|
zlib: () => createZlibModule(),
|
|
111
113
|
};
|
|
112
114
|
for (const [name, mod] of Object.entries(stubs)) factories[name] ??= () => mod;
|
package/src/node/misc.ts
CHANGED
|
@@ -257,7 +257,6 @@ export function createStubModules(): Record<string, Record<string, unknown>> {
|
|
|
257
257
|
trace_events: { createTracing: () => ({ enable() {}, disable() {} }), getEnabledCategories: () => '' },
|
|
258
258
|
sqlite: { DatabaseSync: unavailable('sqlite.DatabaseSync') },
|
|
259
259
|
test: { test: unavailable('node:test'), describe: unavailable('node:test'), it: unavailable('node:test') },
|
|
260
|
-
wasi: { WASI: unavailable('wasi.WASI') },
|
|
261
260
|
repl: { start: unavailable('repl.start') },
|
|
262
261
|
domain: { create: () => Object.assign(new EventEmitterBase(), { run: (fn: () => unknown) => fn(), add() {}, remove() {}, bind: <F>(fn: F) => fn, intercept: <F>(fn: F) => fn, enter() {}, exit() {}, dispose() {} }) },
|
|
263
262
|
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASI preview1's numbers and memory layout: errno values, file types, flags, and a
|
|
3
|
+
* view over the module's memory that re-reads `memory.buffer` on every call (the
|
|
4
|
+
* buffer is replaced whenever the module grows its memory).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const ERRNO = {
|
|
8
|
+
SUCCESS: 0,
|
|
9
|
+
ACCES: 2,
|
|
10
|
+
BADF: 8,
|
|
11
|
+
EXIST: 20,
|
|
12
|
+
FAULT: 21,
|
|
13
|
+
INVAL: 28,
|
|
14
|
+
IO: 29,
|
|
15
|
+
ISDIR: 31,
|
|
16
|
+
LOOP: 32,
|
|
17
|
+
NAMETOOLONG: 37,
|
|
18
|
+
NOENT: 44,
|
|
19
|
+
NOSPC: 51,
|
|
20
|
+
NOSYS: 52,
|
|
21
|
+
NOTDIR: 54,
|
|
22
|
+
NOTEMPTY: 55,
|
|
23
|
+
NOTSUP: 58,
|
|
24
|
+
PERM: 63,
|
|
25
|
+
SPIPE: 70,
|
|
26
|
+
NOTCAPABLE: 76,
|
|
27
|
+
} as const;
|
|
28
|
+
|
|
29
|
+
export const FILETYPE = { UNKNOWN: 0, CHARACTER_DEVICE: 2, DIRECTORY: 3, REGULAR_FILE: 4 } as const;
|
|
30
|
+
export const OFLAGS = { CREAT: 1, DIRECTORY: 2, EXCL: 4, TRUNC: 8 } as const;
|
|
31
|
+
export const FDFLAGS = { APPEND: 1 } as const;
|
|
32
|
+
export const WHENCE = { SET: 0, CUR: 1, END: 2 } as const;
|
|
33
|
+
export const CLOCK = { REALTIME: 0, MONOTONIC: 1, PROCESS_CPUTIME: 2, THREAD_CPUTIME: 3 } as const;
|
|
34
|
+
|
|
35
|
+
/** Every right: this runtime does not narrow capabilities per descriptor. */
|
|
36
|
+
export const ALL_RIGHTS = 0x1fffffffn;
|
|
37
|
+
|
|
38
|
+
/** A guest pointer or length outside the module's memory: answered as FAULT. */
|
|
39
|
+
export class Fault extends Error {}
|
|
40
|
+
|
|
41
|
+
/** Run guest-memory access, turning its RangeError into a `Fault` (an fs RangeError is not one). */
|
|
42
|
+
export function guest<T>(fn: () => T): T {
|
|
43
|
+
try {
|
|
44
|
+
return fn();
|
|
45
|
+
} catch (error) {
|
|
46
|
+
throw error instanceof RangeError ? new Fault(error.message) : error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Run a syscall body, answering a thrown error as its errno. */
|
|
51
|
+
export function attempt(fn: () => number | void): number {
|
|
52
|
+
try {
|
|
53
|
+
return fn() ?? ERRNO.SUCCESS;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
return errnoOf(error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** A number as the u64 WASI wants; NaN and infinities are 0. */
|
|
60
|
+
export const u64 = (n: number): bigint => (Number.isFinite(n) ? BigInt(Math.max(0, Math.round(n))) : 0n);
|
|
61
|
+
|
|
62
|
+
/** A Node error code (`ENOENT`) as a WASI errno. */
|
|
63
|
+
export function errnoOf(error: unknown): number {
|
|
64
|
+
if (error instanceof Fault) return ERRNO.FAULT;
|
|
65
|
+
if (error instanceof RangeError) return ERRNO.INVAL; // from fs work: a size or offset it cannot honor
|
|
66
|
+
const code = (error as { code?: string } | null)?.code;
|
|
67
|
+
switch (code) {
|
|
68
|
+
case 'ENOENT':
|
|
69
|
+
return ERRNO.NOENT;
|
|
70
|
+
case 'EEXIST':
|
|
71
|
+
return ERRNO.EXIST;
|
|
72
|
+
case 'EISDIR':
|
|
73
|
+
return ERRNO.ISDIR;
|
|
74
|
+
case 'ENOTDIR':
|
|
75
|
+
return ERRNO.NOTDIR;
|
|
76
|
+
case 'ENOTEMPTY':
|
|
77
|
+
return ERRNO.NOTEMPTY;
|
|
78
|
+
case 'EBADF':
|
|
79
|
+
return ERRNO.BADF;
|
|
80
|
+
case 'EINVAL':
|
|
81
|
+
return ERRNO.INVAL;
|
|
82
|
+
case 'EACCES':
|
|
83
|
+
return ERRNO.ACCES;
|
|
84
|
+
case 'EPERM':
|
|
85
|
+
return ERRNO.PERM;
|
|
86
|
+
case 'ENOSPC':
|
|
87
|
+
return ERRNO.NOSPC;
|
|
88
|
+
case 'ENAMETOOLONG':
|
|
89
|
+
return ERRNO.NAMETOOLONG;
|
|
90
|
+
case 'ELOOP':
|
|
91
|
+
return ERRNO.LOOP;
|
|
92
|
+
default:
|
|
93
|
+
return ERRNO.IO;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Little-endian access to the module's memory, current as of each call. */
|
|
98
|
+
export class Memory {
|
|
99
|
+
constructor(private readonly memory: () => WebAssembly.Memory) {}
|
|
100
|
+
|
|
101
|
+
get view(): DataView {
|
|
102
|
+
return new DataView(this.memory().buffer);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
bytes(at: number, length: number): Uint8Array {
|
|
106
|
+
return guest(() => new Uint8Array(this.memory().buffer, at, length));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
u32(at: number, value: number): void {
|
|
110
|
+
guest(() => this.view.setUint32(at, value, true));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
u64(at: number, value: bigint): void {
|
|
114
|
+
guest(() => this.view.setBigUint64(at, value, true));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
text(at: number, length: number): string {
|
|
118
|
+
// a copy: TextDecoder rejects a view over a SharedArrayBuffer
|
|
119
|
+
return new TextDecoder().decode(this.bytes(at, length).slice());
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The buffers an `iovec` array points at (`fd_write`, `fd_read`). */
|
|
123
|
+
iovecs(at: number, count: number): Uint8Array[] {
|
|
124
|
+
return guest(() => {
|
|
125
|
+
const view = this.view;
|
|
126
|
+
const out: Uint8Array[] = [];
|
|
127
|
+
for (let i = 0; i < count; i++) out.push(this.bytes(view.getUint32(at + i * 8, true), view.getUint32(at + i * 8 + 4, true)));
|
|
128
|
+
return out;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Write strings as WASI lays out argv/environ: a pointer table, then NUL-terminated bytes. */
|
|
133
|
+
strings(values: readonly string[], pointers: number, buffer: number): void {
|
|
134
|
+
guest(() => {
|
|
135
|
+
const view = this.view;
|
|
136
|
+
let at = buffer;
|
|
137
|
+
values.forEach((value, i) => {
|
|
138
|
+
const encoded = new TextEncoder().encode(value + '\0');
|
|
139
|
+
view.setUint32(pointers + i * 4, at, true);
|
|
140
|
+
this.bytes(at, encoded.length).set(encoded);
|
|
141
|
+
at += encoded.length;
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The sizes `args_sizes_get` / `environ_sizes_get` report. */
|
|
147
|
+
sizes(values: readonly string[], countAt: number, bytesAt: number): void {
|
|
148
|
+
this.u32(countAt, values.length);
|
|
149
|
+
this.u32(bytesAt, values.reduce((total, value) => total + new TextEncoder().encode(value).length + 1, 0));
|
|
150
|
+
}
|
|
151
|
+
}
|