@seanhogg/builderforce-webcontainers 2026.10.10 → 2026.10.12
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/assets.js +2 -2
- package/dist/host.d.ts +11 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +8 -3
- package/dist/host.js.map +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/processHost.d.ts +2 -0
- package/dist/node/processHost.d.ts.map +1 -1
- package/dist/node/processHost.js +3 -2
- package/dist/node/processHost.js.map +1 -1
- package/dist/node/worker.js +120 -120
- package/dist/process-worker.js +120 -120
- package/dist/relay.html +1 -1
- package/package.json +2 -2
- package/src/host.ts +21 -2
- package/src/node/index.ts +2 -1
- package/src/node/processHost.ts +5 -2
package/dist/relay.html
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<!doctype html><html><head><meta charset="utf-8"><title>Preview relay</title></head><body><script>"use strict";(()=>{var i="bfwc:attach",p="bfwc:reattach",s="bfwc:relay-ready",c="bfwc:relay-attach",l="bfwc:relay-reattach",f="bfwc:relay-reload",d="bfwc:relay-spawn";function
|
|
1
|
+
<!doctype html><html><head><meta charset="utf-8"><title>Preview relay</title></head><body><script>"use strict";(()=>{var i="bfwc:attach",p="bfwc:reattach",s="bfwc:relay-ready",c="bfwc:relay-attach",l="bfwc:relay-reattach",f="bfwc:relay-reload",d="bfwc:relay-spawn";function m(e,t){t.onmessage=r=>e.postMessage({kind:"message",data:r.data}),t.onerror=r=>e.postMessage({kind:"error",message:r.message||"The process worker failed."}),e.onmessage=r=>{let o=r.data;o?.kind==="message"?t.postMessage(o.data):o?.kind==="terminate"&&(t.terminate(),e.close())}}var u="process-worker.js";function a(e){return`bfwc:reload:${e}`}function g(e){if(e.active)return Promise.resolve(e.active);let t=e.installing??e.waiting;return t?new Promise((r,o)=>{t.addEventListener("statechange",()=>{t.state==="activated"&&e.active&&r(e.active),t.state==="redundant"&&o(new Error("The preview service worker failed to install."))})}):Promise.reject(new Error("The preview service worker did not install."))}function y(e,t){if(typeof BroadcastChannel>"u")return;let r=new BroadcastChannel(a(e));r.postMessage(t),r.close()}var n=window.parent;async function E(){let e=navigator.serviceWorker;if(!e)throw new Error("Service workers are unavailable on the preview origin.");let t=await e.register(new URL("./sw.js",location.href).href,{scope:"./"});await g(t),e.addEventListener("message",r=>{r.data?.type===p&&typeof r.data.id=="string"&&n.postMessage({type:l,id:r.data.id},"*")}),addEventListener("message",r=>{if(r.source!==n)return;let o=r.data;o?.type===c&&typeof o.id=="string"&&r.ports[0]?t.active?.postMessage({type:i,id:o.id},[r.ports[0]]):o?.type===f&&typeof o.base=="string"?y(o.base,o.update??{type:"reload"}):o?.type===d&&r.ports[0]&&m(r.ports[0],new Worker(new URL(`./${u}`,location.href),{name:"bfwc-process"}))}),n.postMessage({type:s},"*")}E().catch(e=>{n.postMessage({type:s,error:e instanceof Error?e.message:String(e)},"*")});})();
|
|
2
2
|
</script></body></html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seanhogg/builderforce-webcontainers",
|
|
3
|
-
"version": "2026.10.
|
|
3
|
+
"version": "2026.10.12",
|
|
4
4
|
"description": "BuilderForce WebContainers — browser runtime. Boots an in-browser dev server for a project held in memory and serves it to an iframe through a service worker. Open source, no COOP/COEP, no session caps.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"esbuild-wasm": "^0.24.0",
|
|
68
|
-
"@seanhogg/builderforce-webcontainers-core": "^2026.10.
|
|
68
|
+
"@seanhogg/builderforce-webcontainers-core": "^2026.10.12"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@vue/compiler-sfc": "^3.5.0",
|
package/src/host.ts
CHANGED
|
@@ -3,8 +3,10 @@ import {
|
|
|
3
3
|
PortCookieJars,
|
|
4
4
|
VirtualFileSystem,
|
|
5
5
|
buildProject,
|
|
6
|
+
rootedFileSystem,
|
|
6
7
|
exportZip,
|
|
7
8
|
importZip,
|
|
9
|
+
normalizePath,
|
|
8
10
|
type BuildResult,
|
|
9
11
|
type Bundler,
|
|
10
12
|
type ComponentCompilers,
|
|
@@ -63,6 +65,14 @@ export interface CommonRuntimeOptions {
|
|
|
63
65
|
styles?: StyleCompilers;
|
|
64
66
|
/** Bundler for `build()`. Default: esbuild-wasm (the same instance as the compiler). */
|
|
65
67
|
bundler?: Bundler;
|
|
68
|
+
/**
|
|
69
|
+
* The project's directory, as Node programs see it: where `run` starts and
|
|
70
|
+
* `process.cwd()` points. Everything this runtime hands you (`fs`,
|
|
71
|
+
* `writeTree`, zips, the dev server, `build`) addresses the project as `/`.
|
|
72
|
+
* Default `/home/project`; `/` puts the project at the file-system root,
|
|
73
|
+
* which file watchers (chokidar under Vite, so SvelteKit) mishandle.
|
|
74
|
+
*/
|
|
75
|
+
root?: string;
|
|
66
76
|
/** Stable id (e.g. the project id; `[A-Za-z0-9_-]`) — keeps the preview URL stable across reloads. */
|
|
67
77
|
id?: string;
|
|
68
78
|
/** The "Built with Builderforce.ai" badge in the preview. Default true — please keep it. */
|
|
@@ -92,7 +102,10 @@ export interface PreviewRuntime {
|
|
|
92
102
|
readonly id: string;
|
|
93
103
|
/** Absolute URL to load in the preview iframe. */
|
|
94
104
|
readonly url: string;
|
|
105
|
+
/** The project, rooted at `/` (see `root`). */
|
|
95
106
|
readonly fs: VirtualFileSystem;
|
|
107
|
+
/** The project's directory as Node programs see it (`/home/project` by default). */
|
|
108
|
+
readonly root: string;
|
|
96
109
|
readonly server: DevServer;
|
|
97
110
|
/** Write files into the runtime (nested or flat; see `FileTree`), under `at` (default `/`). Open previews update. */
|
|
98
111
|
writeTree(files: FileTree, at?: string): void;
|
|
@@ -138,6 +151,8 @@ export interface PreviewRuntime {
|
|
|
138
151
|
dispose(): void;
|
|
139
152
|
}
|
|
140
153
|
|
|
154
|
+
const DEFAULT_ROOT = '/home/project';
|
|
155
|
+
|
|
141
156
|
function randomId(): string {
|
|
142
157
|
return globalThis.crypto?.randomUUID?.().replace(/-/g, '').slice(0, 16) ?? Math.random().toString(36).slice(2, 18);
|
|
143
158
|
}
|
|
@@ -167,7 +182,10 @@ export async function startPreviewRuntime(options: PreviewRuntimeOptions): Promi
|
|
|
167
182
|
: await sameOriginTransport((options as SameOriginOptions).serviceWorkerUrl, options.scope);
|
|
168
183
|
|
|
169
184
|
const base = previewBase(transport.scope, id);
|
|
170
|
-
const
|
|
185
|
+
const root = normalizePath(options.root ?? DEFAULT_ROOT);
|
|
186
|
+
// Processes see the whole tree; everything else sees the project as `/`.
|
|
187
|
+
const files = new VirtualFileSystem();
|
|
188
|
+
const fs = rootedFileSystem(files, root);
|
|
171
189
|
const components = options.components ?? createCdnComponentCompilers();
|
|
172
190
|
const styles = options.styles ?? createCdnStyleCompilers();
|
|
173
191
|
/** Run in every preview page: dev-server documents and pages virtual servers serve alike. */
|
|
@@ -184,7 +202,7 @@ export async function startPreviewRuntime(options: PreviewRuntimeOptions): Promi
|
|
|
184
202
|
const previewUrl = new URL(base, transport.origin).href;
|
|
185
203
|
// In relay mode processes run on the preview origin (the relay starts them), never the host's.
|
|
186
204
|
const node = { ...options.node, createWorker: options.node?.createWorker ?? transport.createWorker?.bind(transport) };
|
|
187
|
-
const processes = createProcessHost({ fs, base, origin: transport.origin, previewUrl, options: node });
|
|
205
|
+
const processes = createProcessHost({ fs: files, cwd: root, base, origin: transport.origin, previewUrl, options: node });
|
|
188
206
|
|
|
189
207
|
const cookies = new PortCookieJars();
|
|
190
208
|
let responder: ReturnType<typeof createPortResponder> | undefined;
|
|
@@ -222,6 +240,7 @@ export async function startPreviewRuntime(options: PreviewRuntimeOptions): Promi
|
|
|
222
240
|
id,
|
|
223
241
|
url: previewUrl,
|
|
224
242
|
fs,
|
|
243
|
+
root,
|
|
225
244
|
server,
|
|
226
245
|
writeTree: (files, at) => fs.writeTree(files, at),
|
|
227
246
|
exportZip: (zipOptions) => exportZip(fs, zipOptions),
|
package/src/node/index.ts
CHANGED
|
@@ -31,13 +31,14 @@ export interface NodeRuntimeOptions {
|
|
|
31
31
|
killGraceMs?: number;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export function createProcessHost(args: { fs: VirtualFileSystem; base: string; origin: string; previewUrl: string; options?: NodeRuntimeOptions }): ProcessHost {
|
|
34
|
+
export function createProcessHost(args: { fs: VirtualFileSystem; cwd?: string; base: string; origin: string; previewUrl: string; options?: NodeRuntimeOptions }): ProcessHost {
|
|
35
35
|
const { options = {} } = args;
|
|
36
36
|
const createWorker =
|
|
37
37
|
options.createWorker ??
|
|
38
38
|
(() => new Worker(options.workerUrl ?? new URL('./worker.js', import.meta.url), { name: 'bfwc-process' }) as unknown as WorkerLike);
|
|
39
39
|
return new ProcessHost({
|
|
40
40
|
fs: args.fs,
|
|
41
|
+
cwd: args.cwd,
|
|
41
42
|
createWorker,
|
|
42
43
|
previewOrigin: args.origin,
|
|
43
44
|
previewBase: args.base,
|
package/src/node/processHost.ts
CHANGED
|
@@ -45,6 +45,8 @@ export interface WorkerLike {
|
|
|
45
45
|
|
|
46
46
|
export interface ProcessHostOptions {
|
|
47
47
|
fs: VirtualFileSystem;
|
|
48
|
+
/** Where a process starts when `run` names no `cwd`. Default `/`. */
|
|
49
|
+
cwd?: string;
|
|
48
50
|
createWorker(): WorkerLike;
|
|
49
51
|
/** Origin and base path previews are served under (`/__bfwc/<id>/`). */
|
|
50
52
|
previewOrigin: string;
|
|
@@ -132,12 +134,13 @@ export class ProcessHost {
|
|
|
132
134
|
|
|
133
135
|
spawnChild(command: string, args: string[] = [], options: ProcessOptions = {}): ChildHandle {
|
|
134
136
|
const pid = allocatePid();
|
|
137
|
+
const cwd = options.cwd ?? this.options.cwd ?? '/';
|
|
135
138
|
const worker = this.options.createWorker();
|
|
136
139
|
let resolveExit!: (code: number) => void;
|
|
137
140
|
const exit = new Promise<number>((resolve) => (resolveExit = resolve));
|
|
138
141
|
const proc: Proc = {
|
|
139
142
|
pid,
|
|
140
|
-
info: { pid, command, args: [...args], cwd
|
|
143
|
+
info: { pid, command, args: [...args], cwd, startedAt: Date.now() },
|
|
141
144
|
worker,
|
|
142
145
|
stdout: new Set(),
|
|
143
146
|
stderr: new Set(),
|
|
@@ -171,7 +174,7 @@ export class ProcessHost {
|
|
|
171
174
|
pid,
|
|
172
175
|
command,
|
|
173
176
|
args,
|
|
174
|
-
cwd
|
|
177
|
+
cwd,
|
|
175
178
|
env: { ...DEFAULT_ENV, ...this.options.env, ...options.env },
|
|
176
179
|
terminal: options.terminal,
|
|
177
180
|
ipc: options.ipc,
|