@seanhogg/builderforce-webcontainers 2026.10.8 → 2026.10.9
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 +3 -3
- package/dist/cdnModules.d.ts +16 -0
- package/dist/cdnModules.d.ts.map +1 -0
- package/dist/cdnModules.js +25 -0
- package/dist/cdnModules.js.map +1 -0
- package/dist/componentCompilers.d.ts +5 -5
- package/dist/componentCompilers.d.ts.map +1 -1
- package/dist/componentCompilers.js +5 -23
- package/dist/componentCompilers.js.map +1 -1
- package/dist/host.d.ts +11 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +10 -15
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/node/childRelay.d.ts +22 -0
- package/dist/node/childRelay.d.ts.map +1 -0
- package/dist/node/childRelay.js +54 -0
- package/dist/node/childRelay.js.map +1 -0
- package/dist/node/processHost.d.ts.map +1 -1
- package/dist/node/processHost.js +18 -32
- package/dist/node/processHost.js.map +1 -1
- package/dist/node/protocol.d.ts +30 -7
- package/dist/node/protocol.d.ts.map +1 -1
- package/dist/node/protocol.js.map +1 -1
- package/dist/node/worker.js +135 -132
- package/dist/node/workerProcess.d.ts.map +1 -1
- package/dist/node/workerProcess.js +31 -4
- package/dist/node/workerProcess.js.map +1 -1
- package/dist/previewUpdates.d.ts +10 -0
- package/dist/previewUpdates.d.ts.map +1 -0
- package/dist/previewUpdates.js +27 -0
- package/dist/previewUpdates.js.map +1 -0
- package/dist/process-worker.js +135 -132
- package/dist/protocol.d.ts +2 -2
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +2 -2
- package/dist/protocol.js.map +1 -1
- package/dist/relay.html +1 -1
- package/dist/styleCompilers.d.ts +19 -0
- package/dist/styleCompilers.d.ts.map +1 -0
- package/dist/styleCompilers.js +22 -0
- package/dist/styleCompilers.js.map +1 -0
- package/dist/sw.js +1 -1
- package/dist/transport.d.ts +3 -2
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +4 -4
- package/dist/transport.js.map +1 -1
- package/dist/worker.d.ts +6 -2
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +5 -5
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
- package/src/cdnModules.ts +34 -0
- package/src/componentCompilers.ts +8 -32
- package/src/host.ts +21 -18
- package/src/index.ts +3 -0
- package/src/node/childRelay.ts +63 -0
- package/src/node/processHost.ts +23 -31
- package/src/node/protocol.ts +24 -8
- package/src/node/workerProcess.ts +36 -7
- package/src/previewUpdates.ts +28 -0
- package/src/protocol.ts +2 -2
- package/src/relay.ts +6 -5
- package/src/styleCompilers.ts +45 -0
- package/src/transport.ts +7 -6
- package/src/worker.ts +5 -5
package/dist/protocol.d.ts
CHANGED
|
@@ -24,8 +24,8 @@ export declare const RELAY_READY = "bfwc:relay-ready";
|
|
|
24
24
|
export declare const RELAY_ATTACH = "bfwc:relay-attach";
|
|
25
25
|
/** relay → host: the worker asked for `id` again. */
|
|
26
26
|
export declare const RELAY_REATTACH = "bfwc:relay-reattach";
|
|
27
|
-
/** host → relay:
|
|
28
|
-
export declare const
|
|
27
|
+
/** host → relay: tell every frame showing the preview at `base` what changed (`update`; absent = reload). */
|
|
28
|
+
export declare const RELAY_UPDATE = "bfwc:relay-reload";
|
|
29
29
|
/** host → relay, with a MessagePort: start a process worker on the preview origin, bridged over the port. */
|
|
30
30
|
export declare const RELAY_SPAWN = "bfwc:relay-spawn";
|
|
31
31
|
export interface AttachMessage {
|
package/dist/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,eAAe,WAAW,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAqB,CAA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cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAGpE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAG9D;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAGhE"}
|
package/dist/protocol.js
CHANGED
|
@@ -24,8 +24,8 @@ export const RELAY_READY = 'bfwc:relay-ready';
|
|
|
24
24
|
export const RELAY_ATTACH = 'bfwc:relay-attach';
|
|
25
25
|
/** relay → host: the worker asked for `id` again. */
|
|
26
26
|
export const RELAY_REATTACH = 'bfwc:relay-reattach';
|
|
27
|
-
/** host → relay:
|
|
28
|
-
export const
|
|
27
|
+
/** host → relay: tell every frame showing the preview at `base` what changed (`update`; absent = reload). */
|
|
28
|
+
export const RELAY_UPDATE = 'bfwc:relay-reload';
|
|
29
29
|
/** host → relay, with a MessagePort: start a process worker on the preview origin, bridged over the port. */
|
|
30
30
|
export const RELAY_SPAWN = 'bfwc:relay-spawn';
|
|
31
31
|
/** The path segment that routes a preview request to a virtual server: `/__port/3000/…`. */
|
package/dist/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC;AAExC;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAE7C,4FAA4F;AAC5F,MAAM,CAAC,MAAM,MAAM,GAAG,aAAa,CAAC;AACpC,mFAAmF;AACnF,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC;AAExC;;;;GAIG;AACH,sDAAsD;AACtD,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC;AAC9C,oEAAoE;AACpE,MAAM,CAAC,MAAM,YAAY,GAAG,mBAAmB,CAAC;AAChD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,GAAG,CAAC;AACxF,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,SAAiB,EAAE,EAAU;IACvD,OAAO,GAAG,aAAa,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,MAAM,CAAC,GAAG,KAA2B,CAAC;IACtC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;AAClG,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,MAAM,CAAC,GAAG,KAA4B,CAAC;IACvC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,MAAM,CAAC,GAAG,KAAyB,CAAC;IACpC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC;AACjH,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,MAAM,CAAC,GAAG,KAA0B,CAAC;IACrC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC;AACnE,CAAC"}
|
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
|
|
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 u(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 m="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 E(e,t){if(typeof BroadcastChannel>"u")return;let r=new BroadcastChannel(a(e));r.postMessage(t),r.close()}var n=window.parent;async function y(){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"?E(o.base,o.update??{type:"reload"}):o?.type===d&&r.ports[0]&&u(r.ports[0],new Worker(new URL(`./${m}`,location.href),{name:"bfwc-process"}))}),n.postMessage({type:s},"*")}y().catch(e=>{n.postMessage({type:s,error:e instanceof Error?e.message:String(e)},"*")});})();
|
|
2
2
|
</script></body></html>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type StyleCompilers } from '@seanhogg/builderforce-webcontainers-core';
|
|
2
|
+
import { type ImportModule } from './cdnModules.js';
|
|
3
|
+
/**
|
|
4
|
+
* Sass and Less, fetched from a CDN the first time a project has a `.scss`,
|
|
5
|
+
* `.sass` or `.less` file (or a `<style lang>` block), pinned to the project's own
|
|
6
|
+
* range. Both official packages ship pure-JS builds that run in a page.
|
|
7
|
+
*/
|
|
8
|
+
export interface CdnStyleCompilerOptions {
|
|
9
|
+
/** The ES module URL of `sass` for a range. */
|
|
10
|
+
sassUrl?: (range: string) => string;
|
|
11
|
+
/** The ES module URL of `less` for a range. */
|
|
12
|
+
lessUrl?: (range: string) => string;
|
|
13
|
+
/** Loads a module by URL. Default: native `import()`. */
|
|
14
|
+
importModule?: ImportModule;
|
|
15
|
+
}
|
|
16
|
+
export declare const defaultSassUrl: (range: string) => string;
|
|
17
|
+
export declare const defaultLessUrl: (range: string) => string;
|
|
18
|
+
export declare function createCdnStyleCompilers(options?: CdnStyleCompilerOptions): StyleCompilers;
|
|
19
|
+
//# sourceMappingURL=styleCompilers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styleCompilers.d.ts","sourceRoot":"","sources":["../src/styleCompilers.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,cAAc,EACpB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAyC,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE3F;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,+CAA+C;IAC/C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,+CAA+C;IAC/C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,yDAAyD;IACzD,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,WAAmC,CAAC;AAChF,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,WAAmC,CAAC;AAQhF,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,uBAA4B,GAAG,cAAc,CAW7F"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createLessCompiler, createSassCompiler, } from '@seanhogg/builderforce-webcontainers-core';
|
|
2
|
+
import { memoizedLoader, nativeImport, rangeOf } from './cdnModules.js';
|
|
3
|
+
export const defaultSassUrl = (range) => `https://esm.sh/sass@${range}`;
|
|
4
|
+
export const defaultLessUrl = (range) => `https://esm.sh/less@${range}`;
|
|
5
|
+
/** A CommonJS build arrives as the default export; an ES build as the namespace. */
|
|
6
|
+
const moduleApi = (module, probe) => {
|
|
7
|
+
const namespace = module;
|
|
8
|
+
return (probe in namespace ? namespace : namespace.default);
|
|
9
|
+
};
|
|
10
|
+
export function createCdnStyleCompilers(options = {}) {
|
|
11
|
+
const load = memoizedLoader(options.importModule ?? nativeImport);
|
|
12
|
+
return (language, dependencies) => {
|
|
13
|
+
if (language === 'less') {
|
|
14
|
+
const url = (options.lessUrl ?? defaultLessUrl)(rangeOf(dependencies, 'less', '4'));
|
|
15
|
+
return load(url, (module) => createLessCompiler(moduleApi(module, 'render')));
|
|
16
|
+
}
|
|
17
|
+
const range = rangeOf(dependencies, 'sass', rangeOf(dependencies, 'sass-embedded', '1'));
|
|
18
|
+
const url = (options.sassUrl ?? defaultSassUrl)(range);
|
|
19
|
+
return load(url, (module) => createSassCompiler(moduleApi(module, 'compileStringAsync')));
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=styleCompilers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styleCompilers.js","sourceRoot":"","sources":["../src/styleCompilers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GAKnB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,OAAO,EAAqB,MAAM,iBAAiB,CAAC;AAgB3F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,uBAAuB,K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/dist/sw.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{var b="__bfwc",W=/^[A-Za-z0-9_-]+$/,x="bfwc:attach",A="bfwc:reattach";var D="__port";function g(n){return n.startsWith(`/${D}/`)}function
|
|
1
|
+
"use strict";(()=>{var b="__bfwc",W=/^[A-Za-z0-9_-]+$/,x="bfwc:attach",A="bfwc:reattach";var D="__port";function g(n){return n.startsWith(`/${D}/`)}function P(n){let r=n.endsWith("/")?n:n+"/";return r.endsWith(`/${b}/`)?r:`${r}${b}/`}function E(n){let r=n;return!!r&&(r.type==="response"||r.type==="chunk"||r.type==="end")&&typeof r.reqId=="number"}var k={"content-type":"text/plain; charset=utf-8","cache-control":"no-store"};function T(n){let r=P(n.scopePath),c=n.timeoutMs??3e4,h=n.reattachWaitMs??3e3,u=new Map,a=new Map,p=new Map,l=new Map,w=0;function R(t,s){u.set(t,s),s.onmessage=i=>{let e=i.data;if(!E(e))return;if(e.type==="response"){p.get(e.reqId)?.(e),p.delete(e.reqId);return}let o=l.get(e.reqId);if(o)try{if(e.type==="chunk")return o.enqueue(new Uint8Array(e.data));l.delete(e.reqId),e.error?o.error(new Error(e.error)):o.close()}catch{l.delete(e.reqId)}};for(let i of a.get(t)??[])i(s);a.delete(t)}function v(t){if(!t.pathname.startsWith(r))return null;let s=t.pathname.slice(r.length),i=s.indexOf("/"),e=i<0?s:s.slice(0,i);return!e||!W.test(e)?null:{id:e,path:i<0?"/":s.slice(i),search:t.search}}async function L(t){let s=u.get(t);if(s)return s;let i=new Promise(e=>{let o=a.get(t)??[];o.push(e),a.set(t,o),setTimeout(()=>e(void 0),h)});return await n.requestReattach(t),i}let y=new Map;function C(t,s){if(!t||!g(s.path))return;let i=/^\/__port\/\d+/.exec(s.path)[0];y.set(t,{id:s.id,prefix:i}),y.size>200&&y.delete(y.keys().next().value)}function I(t,s,i){let e=v(t);if(e||!s||t.origin!==i)return e;let o=y.get(s);return o?{id:o.id,path:o.prefix+t.pathname,search:t.search}:null}async function M(t,s){let i=await L(t.id);if(!i)return{status:503,headers:k,body:"This preview is not running in any open tab."};let e=++w;return new Promise(o=>{let _=setTimeout(()=>{p.delete(e),u.get(t.id)===i&&u.delete(t.id),o({status:504,headers:k,body:"The preview did not answer in time."})},c);p.set(e,f=>{if(clearTimeout(_),!f.streaming)return o({status:f.status,headers:f.headers,body:f.body});let S=new ReadableStream({start:U=>void l.set(e,U),cancel:()=>{l.delete(e)&&i.postMessage({type:"cancel",reqId:e})}});o({status:f.status,headers:f.headers,body:S})}),i.postMessage({type:"request",reqId:e,path:t.path,search:t.search,...s})})}return{attach:R,match:v,matchForClient:I,rememberClient:C,respond:M,detach:t=>u.delete(t)}}var d=globalThis,m=T({scopePath:new URL(d.registration.scope).pathname,async requestReattach(n){let r=await d.clients.matchAll({type:"window",includeUncontrolled:!0});for(let c of r)c.postMessage({type:A,id:n})}});d.addEventListener("install",()=>{d.skipWaiting()});d.addEventListener("activate",n=>{n.waitUntil(d.clients.claim())});d.addEventListener("message",n=>{let r=n.data,c=n.ports[0];r?.type===x&&typeof r.id=="string"&&c&&m.attach(r.id,c)});var q=new Set([101,204,205,304]);d.addEventListener("fetch",n=>{let{request:r}=n,c=m.matchForClient(new URL(r.url),n.clientId,new URL(d.registration.scope).origin);if(!c)return;let h=g(c.path);r.method!=="GET"&&!h||(h&&m.rememberClient(n.resultingClientId,c),n.respondWith((async()=>{let u;if(h){let p={};r.headers.forEach((w,R)=>p[R]=w);let l=r.method==="GET"||r.method==="HEAD"?null:await r.arrayBuffer();u={method:r.method,headers:p,body:l}}let a=await m.respond(c,u);return q.has(a.status)&&a.body instanceof ReadableStream&&a.body.cancel(),new Response(q.has(a.status)?null:a.body,{status:a.status,headers:a.headers})})()))});})();
|
package/dist/transport.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PreviewUpdate } from '@seanhogg/builderforce-webcontainers-core';
|
|
1
2
|
import type { WorkerLike } from './node/processHost.js';
|
|
2
3
|
export interface PreviewTransport {
|
|
3
4
|
/** The origin previews are served from. */
|
|
@@ -8,8 +9,8 @@ export interface PreviewTransport {
|
|
|
8
9
|
attach(id: string, port: MessagePort): void;
|
|
9
10
|
/** The worker restarted and wants `id` again. */
|
|
10
11
|
onReattach(listener: (id: string) => void): () => void;
|
|
11
|
-
/**
|
|
12
|
-
|
|
12
|
+
/** Tell every frame showing the preview at `base` what changed: a hot update, or reload. */
|
|
13
|
+
send(base: string, update: PreviewUpdate): void;
|
|
13
14
|
/**
|
|
14
15
|
* Start a process worker on the preview origin. Only the relay has one to
|
|
15
16
|
* offer; same-origin mode runs processes on the host's origin, which is the
|
package/dist/transport.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAIxD,MAAM,WAAW,gBAAgB;IAC/B,2CAA2C;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,8CAA8C;IAC9C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,yDAAyD;IACzD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5C,iDAAiD;IACjD,UAAU,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACvD,
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAIxD,MAAM,WAAW,gBAAgB;IAC/B,2CAA2C;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,8CAA8C;IAC9C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,yDAAyD;IACzD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5C,iDAAiD;IACjD,UAAU,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACvD,4FAA4F;IAC5F,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IAChD;;;;OAIG;IACH,YAAY,CAAC,IAAI,UAAU,CAAC;IAC5B,OAAO,IAAI,IAAI,CAAC;CACjB;AAKD,wBAAsB,mBAAmB,CAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA6BnH;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA6DhF"}
|
package/dist/transport.js
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
* then never read the host's cookies, storage or DOM, which is what an editor
|
|
11
11
|
* running AI-written code or arbitrary npm packages needs.
|
|
12
12
|
*/
|
|
13
|
-
import { ATTACH, REATTACH, RELAY_ATTACH, RELAY_READY, RELAY_REATTACH,
|
|
13
|
+
import { ATTACH, REATTACH, RELAY_ATTACH, RELAY_READY, RELAY_REATTACH, RELAY_SPAWN, RELAY_UPDATE, } from './protocol.js';
|
|
14
14
|
import { workerOverPort } from './relayWorker.js';
|
|
15
|
-
import {
|
|
15
|
+
import { broadcastUpdate, waitForActive } from './worker.js';
|
|
16
16
|
/** How long the relay has to register its worker before boot gives up. */
|
|
17
17
|
const RELAY_TIMEOUT_MS = 15_000;
|
|
18
18
|
export async function sameOriginTransport(serviceWorkerUrl, scopeOption) {
|
|
@@ -38,7 +38,7 @@ export async function sameOriginTransport(serviceWorkerUrl, scopeOption) {
|
|
|
38
38
|
listeners.add(listener);
|
|
39
39
|
return () => listeners.delete(listener);
|
|
40
40
|
},
|
|
41
|
-
|
|
41
|
+
send: broadcastUpdate,
|
|
42
42
|
dispose() {
|
|
43
43
|
container.removeEventListener('message', onWorkerMessage);
|
|
44
44
|
listeners.clear();
|
|
@@ -96,7 +96,7 @@ export async function relayTransport(relayUrl) {
|
|
|
96
96
|
listeners.add(listener);
|
|
97
97
|
return () => listeners.delete(listener);
|
|
98
98
|
},
|
|
99
|
-
|
|
99
|
+
send: (base, update) => post({ type: RELAY_UPDATE, base, update }),
|
|
100
100
|
createWorker() {
|
|
101
101
|
const channel = new MessageChannel();
|
|
102
102
|
post({ type: RELAY_SPAWN }, [channel.port2]);
|
package/dist/transport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAsB7D,0EAA0E;AAC1E,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,gBAAwB,EAAE,WAAoB;IACtF,MAAM,SAAS,GAAG,SAAS,CAAC,aAAa,CAAC;IAC1C,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,6FAA6F,CAAC,CAAC;IAE/H,M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AE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;QAC9D,UAAU,CAAC,QAAQ;YACjB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1C,CAAC;QACD,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAClE,YAAY;YACV,MAAM,OAAO,GAAG,IAAI,cAAc,EAAE,CAAC;YACrC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;YAC7C,OAAO,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC;QACD,OAAO;YACL,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;YACtD,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,KAAK,CAAC,MAAM,EAAE,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/worker.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small helpers shared by the page-side transports and the relay page.
|
|
3
|
+
*/
|
|
4
|
+
import { type PreviewUpdate } from '@seanhogg/builderforce-webcontainers-core';
|
|
1
5
|
/** Resolve once the registration has an active worker. */
|
|
2
6
|
export declare function waitForActive(registration: ServiceWorkerRegistration): Promise<ServiceWorker>;
|
|
3
|
-
/**
|
|
4
|
-
export declare function
|
|
7
|
+
/** Tell every frame (on this origin) showing the preview served at `base` what changed. */
|
|
8
|
+
export declare function broadcastUpdate(base: string, update: PreviewUpdate): void;
|
|
5
9
|
//# sourceMappingURL=worker.d.ts.map
|
package/dist/worker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAElG,0DAA0D;AAC1D,wBAAgB,aAAa,CAAC,YAAY,EAAE,yBAAyB,GAAG,OAAO,CAAC,aAAa,CAAC,CAU7F;AAED,2FAA2F;AAC3F,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAKzE"}
|
package/dist/worker.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Small helpers shared by the page-side transports and the relay page.
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { updateChannelName } from '@seanhogg/builderforce-webcontainers-core';
|
|
5
5
|
/** Resolve once the registration has an active worker. */
|
|
6
6
|
export function waitForActive(registration) {
|
|
7
7
|
if (registration.active)
|
|
@@ -18,12 +18,12 @@ export function waitForActive(registration) {
|
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
22
|
-
export function
|
|
21
|
+
/** Tell every frame (on this origin) showing the preview served at `base` what changed. */
|
|
22
|
+
export function broadcastUpdate(base, update) {
|
|
23
23
|
if (typeof BroadcastChannel === 'undefined')
|
|
24
24
|
return;
|
|
25
|
-
const channel = new BroadcastChannel(
|
|
26
|
-
channel.postMessage(
|
|
25
|
+
const channel = new BroadcastChannel(updateChannelName(base));
|
|
26
|
+
channel.postMessage(update);
|
|
27
27
|
channel.close();
|
|
28
28
|
}
|
|
29
29
|
//# sourceMappingURL=worker.js.map
|
package/dist/worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAsB,MAAM,2CAA2C,CAAC;AAElG,0DAA0D;AAC1D,MAAM,UAAU,aAAa,CAAC,YAAuC;IACnE,IAAI,YAAY,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IACrE,MAAM,UAAU,GAAG,YAAY,CAAC,UAAU,IAAI,YAAY,CAAC,OAAO,CAAC;IACnE,IAAI,CAAC,UAAU;QAAE,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC,CAAC;IACjG,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,UAAU,CAAC,gBAAgB,CAAC,aAAa,EAAE,GAAG,EAAE;YAC9C,IAAI,UAAU,CAAC,KAAK,KAAK,WAAW,IAAI,YAAY,CAAC,MAAM;gBAAE,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;YAC1F,IAAI,UAAU,CAAC,KAAK,KAAK,WAAW;gBAAE,MAAM,CAAC,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC,CAAC;QAC3G,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,MAAqB;IACjE,IAAI,OAAO,gBAAgB,KAAK,WAAW;QAAE,OAAO;IACpD,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9D,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5B,OAAO,CAAC,KAAK,EAAE,CAAC;AAClB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seanhogg/builderforce-webcontainers",
|
|
3
|
-
"version": "2026.10.
|
|
3
|
+
"version": "2026.10.9",
|
|
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.9"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@vue/compiler-sfc": "^3.5.0",
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isRegistryRange } from '@seanhogg/builderforce-webcontainers-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Loading a compiler (Vue, Svelte, Sass, Less) from a CDN the first time a
|
|
5
|
+
* project needs it — nothing is downloaded for a project that doesn't — pinned
|
|
6
|
+
* to the project's own range, so compiler and runtime agree.
|
|
7
|
+
*/
|
|
8
|
+
export type ImportModule = (url: string) => Promise<unknown>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `import()` of a runtime URL. The magic comments stop the host app's bundler
|
|
12
|
+
* (webpack, Vite) from trying to resolve the CDN URL at build time.
|
|
13
|
+
*/
|
|
14
|
+
export const nativeImport: ImportModule = (url) => import(/* webpackIgnore: true */ /* @vite-ignore */ url);
|
|
15
|
+
|
|
16
|
+
/** The project's range for `name` when the CDN can fetch it, else `fallback`. */
|
|
17
|
+
export function rangeOf(dependencies: Readonly<Record<string, string>>, name: string, fallback: string): string {
|
|
18
|
+
const range = dependencies[name];
|
|
19
|
+
return range && isRegistryRange(range) ? range : fallback;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** One load per URL; a failed download is forgotten so the next request retries. */
|
|
23
|
+
export function memoizedLoader<T>(load: ImportModule): (url: string, make: (module: unknown) => T) => Promise<T> {
|
|
24
|
+
const cache = new Map<string, Promise<T>>();
|
|
25
|
+
return (url, make) => {
|
|
26
|
+
let hit = cache.get(url);
|
|
27
|
+
if (!hit) {
|
|
28
|
+
hit = load(url).then(make);
|
|
29
|
+
hit.catch(() => cache.delete(url));
|
|
30
|
+
cache.set(url, hit);
|
|
31
|
+
}
|
|
32
|
+
return hit;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createSvelteCompiler,
|
|
3
3
|
createVueCompiler,
|
|
4
|
-
isRegistryRange,
|
|
5
4
|
type ComponentCompiler,
|
|
6
5
|
type ComponentCompilers,
|
|
7
6
|
type SvelteCompilerLike,
|
|
8
7
|
type VueCompilerSfcLike,
|
|
9
8
|
} from '@seanhogg/builderforce-webcontainers-core';
|
|
9
|
+
import { memoizedLoader, nativeImport, rangeOf, type ImportModule } from './cdnModules.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The Vue and Svelte compilers, fetched from a CDN the first time a project
|
|
13
|
-
* needs one
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* the runtime is served by esm.sh from the same range, so the compiler is too.)
|
|
13
|
+
* needs one, pinned to the project's own framework range. (Svelte's compiled
|
|
14
|
+
* output calls internal runtime functions that change between minors; the
|
|
15
|
+
* runtime is served by esm.sh from the same range, so the compiler is too.)
|
|
17
16
|
*/
|
|
18
17
|
export interface CdnComponentCompilerOptions {
|
|
19
18
|
/** The ES module URL of `@vue/compiler-sfc`'s browser build for a `vue` range. */
|
|
@@ -21,7 +20,7 @@ export interface CdnComponentCompilerOptions {
|
|
|
21
20
|
/** The ES module URL of `svelte/compiler` for a `svelte` range. */
|
|
22
21
|
svelteCompilerUrl?: (range: string) => string;
|
|
23
22
|
/** Loads a module by URL. Default: native `import()`. */
|
|
24
|
-
importModule?:
|
|
23
|
+
importModule?: ImportModule;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
/** Self-contained ESM build the official Vue SFC playground loads. */
|
|
@@ -30,37 +29,14 @@ export const defaultVueCompilerUrl = (range: string) =>
|
|
|
30
29
|
|
|
31
30
|
export const defaultSvelteCompilerUrl = (range: string) => `https://esm.sh/svelte@${range}/compiler`;
|
|
32
31
|
|
|
33
|
-
/**
|
|
34
|
-
* `import()` of a runtime URL. The magic comments stop the host app's bundler
|
|
35
|
-
* (webpack, Vite) from trying to resolve the CDN URL at build time.
|
|
36
|
-
*/
|
|
37
|
-
const nativeImport = (url: string): Promise<unknown> => import(/* webpackIgnore: true */ /* @vite-ignore */ url);
|
|
38
|
-
|
|
39
|
-
function rangeOf(dependencies: Readonly<Record<string, string>>, name: string, fallback: string): string {
|
|
40
|
-
const range = dependencies[name];
|
|
41
|
-
return range && isRegistryRange(range) ? range : fallback;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
32
|
export function createCdnComponentCompilers(options: CdnComponentCompilerOptions = {}): ComponentCompilers {
|
|
45
|
-
const load = options.importModule ?? nativeImport;
|
|
46
|
-
const cache = new Map<string, Promise<ComponentCompiler>>();
|
|
47
|
-
|
|
48
|
-
const memo = (url: string, make: (module: unknown) => ComponentCompiler): Promise<ComponentCompiler> => {
|
|
49
|
-
let hit = cache.get(url);
|
|
50
|
-
if (!hit) {
|
|
51
|
-
hit = load(url).then(make);
|
|
52
|
-
hit.catch(() => cache.delete(url)); // a failed download may be retried
|
|
53
|
-
cache.set(url, hit);
|
|
54
|
-
}
|
|
55
|
-
return hit;
|
|
56
|
-
};
|
|
57
|
-
|
|
33
|
+
const load = memoizedLoader<ComponentCompiler>(options.importModule ?? nativeImport);
|
|
58
34
|
return (extension, dependencies) => {
|
|
59
35
|
if (extension === '.vue') {
|
|
60
36
|
const url = (options.vueCompilerUrl ?? defaultVueCompilerUrl)(rangeOf(dependencies, 'vue', '3'));
|
|
61
|
-
return
|
|
37
|
+
return load(url, (module) => createVueCompiler(module as VueCompilerSfcLike));
|
|
62
38
|
}
|
|
63
39
|
const url = (options.svelteCompilerUrl ?? defaultSvelteCompilerUrl)(rangeOf(dependencies, 'svelte', '5'));
|
|
64
|
-
return
|
|
40
|
+
return load(url, (module) => createSvelteCompiler(module as SvelteCompilerLike));
|
|
65
41
|
};
|
|
66
42
|
}
|
package/src/host.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
type ProjectProfile,
|
|
16
16
|
type RuntimeProcess,
|
|
17
17
|
type ServerAddress,
|
|
18
|
+
type StyleCompilers,
|
|
18
19
|
type Transformer,
|
|
19
20
|
type ZipExportOptions,
|
|
20
21
|
} from '@seanhogg/builderforce-webcontainers-core';
|
|
@@ -25,6 +26,8 @@ import { listenToPreviewBridge } from './previewBridge.js';
|
|
|
25
26
|
import { relayTransport, sameOriginTransport } from './transport.js';
|
|
26
27
|
import { createEsbuildWasmBundler, createEsbuildWasmTransformer } from './esbuildWasm.js';
|
|
27
28
|
import { createCdnComponentCompilers } from './componentCompilers.js';
|
|
29
|
+
import { createCdnStyleCompilers } from './styleCompilers.js';
|
|
30
|
+
import { watchForPreviewUpdates } from './previewUpdates.js';
|
|
28
31
|
|
|
29
32
|
/** Serve previews on THIS page's origin. Only for code the page's own user trusts. */
|
|
30
33
|
export interface SameOriginOptions {
|
|
@@ -56,23 +59,28 @@ export interface CommonRuntimeOptions {
|
|
|
56
59
|
cdn?: PackageCdnFactory;
|
|
57
60
|
/** `.vue` / `.svelte` compilers. Default: the official ones, fetched from a CDN on first use. */
|
|
58
61
|
components?: ComponentCompilers;
|
|
62
|
+
/** Sass / Less compilers. Default: the official pure-JS builds, fetched from a CDN on first use. */
|
|
63
|
+
styles?: StyleCompilers;
|
|
59
64
|
/** Bundler for `build()`. Default: esbuild-wasm (the same instance as the compiler). */
|
|
60
65
|
bundler?: Bundler;
|
|
61
66
|
/** Stable id (e.g. the project id; `[A-Za-z0-9_-]`) — keeps the preview URL stable across reloads. */
|
|
62
67
|
id?: string;
|
|
63
68
|
/** The "Built with Builderforce.ai" badge in the preview. Default true — please keep it. */
|
|
64
69
|
attribution?: boolean;
|
|
65
|
-
/**
|
|
70
|
+
/** Update open previews when files change. Default true. */
|
|
66
71
|
liveReload?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Apply edits in place where possible: stylesheets swap and React components
|
|
74
|
+
* re-render keeping their state (Fast Refresh); anything else reloads. `false`
|
|
75
|
+
* reloads on every edit. Default true.
|
|
76
|
+
*/
|
|
77
|
+
hot?: boolean;
|
|
67
78
|
/** Your scripts (JavaScript source), run in every preview page before the app — analytics, test hooks, a mock `fetch`. */
|
|
68
79
|
previewScripts?: string[];
|
|
69
80
|
/** The Node runtime behind `run` (process workers, npm registry). */
|
|
70
81
|
node?: NodeRuntimeOptions;
|
|
71
82
|
}
|
|
72
83
|
|
|
73
|
-
/** Edits arrive in bursts (a save, an agent writing several files): reload once per burst. */
|
|
74
|
-
const RELOAD_DEBOUNCE_MS = 120;
|
|
75
|
-
|
|
76
84
|
export interface RuntimeBuildOptions {
|
|
77
85
|
/** Where the site will be served from. Default `./` (works from any directory). */
|
|
78
86
|
base?: string;
|
|
@@ -86,7 +94,7 @@ export interface PreviewRuntime {
|
|
|
86
94
|
readonly url: string;
|
|
87
95
|
readonly fs: VirtualFileSystem;
|
|
88
96
|
readonly server: DevServer;
|
|
89
|
-
/** Write files into the runtime (nested or flat; see `FileTree`), under `at` (default `/`). Open previews
|
|
97
|
+
/** Write files into the runtime (nested or flat; see `FileTree`), under `at` (default `/`). Open previews update. */
|
|
90
98
|
writeTree(files: FileTree, at?: string): void;
|
|
91
99
|
/** The project as a zip — "Download project" with `exclude: ['node_modules']`, or a full snapshot to restore later. */
|
|
92
100
|
exportZip(options?: ZipExportOptions): Uint8Array;
|
|
@@ -161,12 +169,13 @@ export async function startPreviewRuntime(options: PreviewRuntimeOptions): Promi
|
|
|
161
169
|
const base = previewBase(transport.scope, id);
|
|
162
170
|
const fs = new VirtualFileSystem();
|
|
163
171
|
const components = options.components ?? createCdnComponentCompilers();
|
|
172
|
+
const styles = options.styles ?? createCdnStyleCompilers();
|
|
164
173
|
/** Run in every preview page: dev-server documents and pages virtual servers serve alike. */
|
|
165
174
|
let previewScripts: string[] = [...(options.previewScripts ?? [])];
|
|
166
175
|
let server: DevServer;
|
|
167
176
|
try {
|
|
168
177
|
const transformer = options.transformer ?? (await createEsbuildWasmTransformer());
|
|
169
|
-
server = new DevServer({ fs, transformer, base, cdn: options.cdn, components, attribution: options.attribution, previewScripts });
|
|
178
|
+
server = new DevServer({ fs, transformer, base, cdn: options.cdn, components, styles, attribution: options.attribution, previewScripts, hot: options.hot });
|
|
170
179
|
} catch (error) {
|
|
171
180
|
transport.dispose();
|
|
172
181
|
throw error;
|
|
@@ -201,14 +210,9 @@ export async function startPreviewRuntime(options: PreviewRuntimeOptions): Promi
|
|
|
201
210
|
if (wanted === id) attach();
|
|
202
211
|
});
|
|
203
212
|
|
|
204
|
-
//
|
|
205
|
-
|
|
206
|
-
const stopWatching = options.liveReload === false
|
|
207
|
-
? undefined
|
|
208
|
-
: fs.watch(() => {
|
|
209
|
-
clearTimeout(reloadTimer);
|
|
210
|
-
reloadTimer = setTimeout(() => transport.reload(base), RELOAD_DEBOUNCE_MS);
|
|
211
|
-
});
|
|
213
|
+
// Every frame showing this preview hears what each burst of edits changed.
|
|
214
|
+
const reload = () => transport.send(base, { type: 'reload' });
|
|
215
|
+
const stopWatching = options.liveReload === false ? undefined : watchForPreviewUpdates(fs, server, (update) => transport.send(base, update));
|
|
212
216
|
|
|
213
217
|
const previewMessages = listenToPreview(window, transport.origin, base);
|
|
214
218
|
// WebSockets and document.cookie for virtual servers, which a service worker cannot carry.
|
|
@@ -222,18 +226,18 @@ export async function startPreviewRuntime(options: PreviewRuntimeOptions): Promi
|
|
|
222
226
|
writeTree: (files, at) => fs.writeTree(files, at),
|
|
223
227
|
exportZip: (zipOptions) => exportZip(fs, zipOptions),
|
|
224
228
|
importZip: (zip, at) => importZip(fs, zip, at),
|
|
225
|
-
reload
|
|
229
|
+
reload,
|
|
226
230
|
profile: () => server.profile(),
|
|
227
231
|
async build(buildOptions = {}) {
|
|
228
232
|
const bundler = options.bundler ?? (await createEsbuildWasmBundler());
|
|
229
|
-
return buildProject({ files: fs, bundler, cdn: options.cdn, components, base: buildOptions.base, minify: buildOptions.minify });
|
|
233
|
+
return buildProject({ files: fs, bundler, cdn: options.cdn, components, styles, base: buildOptions.base, minify: buildOptions.minify });
|
|
230
234
|
},
|
|
231
235
|
onError: (listener) => previewMessages.onError(listener),
|
|
232
236
|
onPreviewConsole: (listener) => previewMessages.onConsole(listener),
|
|
233
237
|
setPreviewScripts(scripts) {
|
|
234
238
|
previewScripts = [...scripts];
|
|
235
239
|
server.setPreviewScripts(previewScripts);
|
|
236
|
-
|
|
240
|
+
reload();
|
|
237
241
|
},
|
|
238
242
|
run: (command: string, args?: string[] | ProcessOptions, runOptions?: ProcessOptions) => processes.run(command, args as string[], runOptions),
|
|
239
243
|
onServerListening: (listener) => processes.servers.onListening(listener),
|
|
@@ -245,7 +249,6 @@ export async function startPreviewRuntime(options: PreviewRuntimeOptions): Promi
|
|
|
245
249
|
responder?.dispose();
|
|
246
250
|
processes.dispose();
|
|
247
251
|
previewMessages.dispose();
|
|
248
|
-
clearTimeout(reloadTimer);
|
|
249
252
|
stopWatching?.();
|
|
250
253
|
stopReattach();
|
|
251
254
|
transport.dispose();
|
package/src/index.ts
CHANGED
|
@@ -18,6 +18,9 @@ export { createEsbuildWasmTransformer, createEsbuildWasmBundler, loadEsbuildWasm
|
|
|
18
18
|
export type { EsbuildWasmOptions } from './esbuildWasm.js';
|
|
19
19
|
export { createCdnComponentCompilers, defaultVueCompilerUrl, defaultSvelteCompilerUrl } from './componentCompilers.js';
|
|
20
20
|
export type { CdnComponentCompilerOptions } from './componentCompilers.js';
|
|
21
|
+
export { createCdnStyleCompilers, defaultSassUrl, defaultLessUrl } from './styleCompilers.js';
|
|
22
|
+
export type { CdnStyleCompilerOptions } from './styleCompilers.js';
|
|
23
|
+
export { watchForPreviewUpdates } from './previewUpdates.js';
|
|
21
24
|
export { createCacheStoragePackageCache } from './packageCache.js';
|
|
22
25
|
export { ProcessHost, createWorkerProcess, servePortRequest, createPortResponder, openPortResponse, injectBridge } from './node/index.js';
|
|
23
26
|
export type { NodeRuntimeOptions, ProcessHostOptions, ProcessInfo, WorkerLike, PortResponder, PortResponderOptions, OpenedPortResponse } from './node/index.js';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page side of the children ONE process Worker spawns (a shell running
|
|
3
|
+
* `node`, `child_process.fork`, a `worker_threads` Worker): each is started as a
|
|
4
|
+
* process of its own, and its output, exit and message channel are relayed back
|
|
5
|
+
* to the spawning Worker, keyed by the Worker's own child id.
|
|
6
|
+
*/
|
|
7
|
+
import type { ChildHandle, ProcessOptions } from '@seanhogg/builderforce-webcontainers-core';
|
|
8
|
+
import type { HostToWorker, WorkerToHost } from './protocol.js';
|
|
9
|
+
|
|
10
|
+
type ChildMessage = Extract<WorkerToHost, { type: 'spawn' | 'child-stdin' | 'child-kill' | 'child-resize' | 'child-ipc' | 'child-ipc-disconnect' }>;
|
|
11
|
+
|
|
12
|
+
const CHILD_MESSAGES = new Set<string>(['spawn', 'child-stdin', 'child-kill', 'child-resize', 'child-ipc', 'child-ipc-disconnect']);
|
|
13
|
+
|
|
14
|
+
export function isChildMessage(message: WorkerToHost): message is ChildMessage {
|
|
15
|
+
return CHILD_MESSAGES.has(message.type);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class ChildRelay {
|
|
19
|
+
private readonly children = new Map<number, ChildHandle>();
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
private readonly spawn: (command: string, args: string[], options: ProcessOptions) => ChildHandle,
|
|
23
|
+
private readonly post: (message: HostToWorker) => void,
|
|
24
|
+
) {}
|
|
25
|
+
|
|
26
|
+
receive(message: ChildMessage): void {
|
|
27
|
+
if (message.type === 'spawn') return this.start(message);
|
|
28
|
+
const child = this.children.get(message.childId);
|
|
29
|
+
switch (message.type) {
|
|
30
|
+
case 'child-stdin':
|
|
31
|
+
if (message.data === null) child?.closeStdin();
|
|
32
|
+
else child?.write(message.data);
|
|
33
|
+
return;
|
|
34
|
+
case 'child-kill':
|
|
35
|
+
return child?.kill(message.signal);
|
|
36
|
+
case 'child-resize':
|
|
37
|
+
return child?.resize?.(message.cols, message.rows);
|
|
38
|
+
case 'child-ipc':
|
|
39
|
+
return child?.ipc?.send(message.data);
|
|
40
|
+
case 'child-ipc-disconnect':
|
|
41
|
+
return child?.ipc?.disconnect();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private start(message: Extract<ChildMessage, { type: 'spawn' }>): void {
|
|
46
|
+
const { childId } = message;
|
|
47
|
+
let child: ChildHandle;
|
|
48
|
+
try {
|
|
49
|
+
child = this.spawn(message.command, message.args, { cwd: message.cwd, env: message.env, terminal: message.terminal, ipc: message.ipc, thread: message.thread });
|
|
50
|
+
} catch (error) {
|
|
51
|
+
return this.post({ type: 'child-error', childId, code: (error as { code?: string }).code ?? 'EFAIL', message: (error as Error).message });
|
|
52
|
+
}
|
|
53
|
+
this.children.set(childId, child);
|
|
54
|
+
child.onStdout((data) => this.post({ type: 'child-out', childId, stream: 'stdout', data }));
|
|
55
|
+
child.onStderr((data) => this.post({ type: 'child-out', childId, stream: 'stderr', data }));
|
|
56
|
+
child.ipc?.onMessage((data) => this.post({ type: 'child-ipc', childId, data }));
|
|
57
|
+
child.ipc?.onDisconnect(() => this.post({ type: 'child-ipc-disconnect', childId }));
|
|
58
|
+
void child.exit.then((code) => {
|
|
59
|
+
this.children.delete(childId);
|
|
60
|
+
this.post({ type: 'child-exit', childId, code });
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|