@seanhogg/builderforce-webcontainers-core 2026.10.8 → 2026.10.10

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.
Files changed (296) hide show
  1. package/dist/build.d.ts +6 -0
  2. package/dist/build.d.ts.map +1 -1
  3. package/dist/build.js +9 -1
  4. package/dist/build.js.map +1 -1
  5. package/dist/buildHost.d.ts +3 -0
  6. package/dist/buildHost.d.ts.map +1 -1
  7. package/dist/buildHost.js +25 -12
  8. package/dist/buildHost.js.map +1 -1
  9. package/dist/compileComponent.d.ts.map +1 -1
  10. package/dist/compileComponent.js +4 -1
  11. package/dist/compileComponent.js.map +1 -1
  12. package/dist/compileScript.d.ts +12 -4
  13. package/dist/compileScript.d.ts.map +1 -1
  14. package/dist/compileScript.js +26 -13
  15. package/dist/compileScript.js.map +1 -1
  16. package/dist/components.d.ts +5 -0
  17. package/dist/components.d.ts.map +1 -1
  18. package/dist/components.js.map +1 -1
  19. package/dist/detectProject.d.ts +2 -0
  20. package/dist/detectProject.d.ts.map +1 -1
  21. package/dist/detectProject.js +13 -7
  22. package/dist/detectProject.js.map +1 -1
  23. package/dist/devServer.d.ts +38 -4
  24. package/dist/devServer.d.ts.map +1 -1
  25. package/dist/devServer.js +140 -24
  26. package/dist/devServer.js.map +1 -1
  27. package/dist/devStyles.d.ts +27 -0
  28. package/dist/devStyles.d.ts.map +1 -0
  29. package/dist/devStyles.js +52 -0
  30. package/dist/devStyles.js.map +1 -0
  31. package/dist/hot/client.d.ts +33 -0
  32. package/dist/hot/client.d.ts.map +1 -0
  33. package/dist/hot/client.js +46 -0
  34. package/dist/hot/client.js.map +1 -0
  35. package/dist/hot/moduleGraph.d.ts +39 -0
  36. package/dist/hot/moduleGraph.d.ts.map +1 -0
  37. package/dist/hot/moduleGraph.js +69 -0
  38. package/dist/hot/moduleGraph.js.map +1 -0
  39. package/dist/hot/planUpdate.d.ts +33 -0
  40. package/dist/hot/planUpdate.d.ts.map +1 -0
  41. package/dist/hot/planUpdate.js +43 -0
  42. package/dist/hot/planUpdate.js.map +1 -0
  43. package/dist/hot/reactRefresh.d.ts +45 -0
  44. package/dist/hot/reactRefresh.d.ts.map +1 -0
  45. package/dist/hot/reactRefresh.js +86 -0
  46. package/dist/hot/reactRefresh.js.map +1 -0
  47. package/dist/html.d.ts +2 -8
  48. package/dist/html.d.ts.map +1 -1
  49. package/dist/html.js +11 -17
  50. package/dist/html.js.map +1 -1
  51. package/dist/index.d.ts +19 -1
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +11 -1
  54. package/dist/index.js.map +1 -1
  55. package/dist/installer/tree.d.ts.map +1 -1
  56. package/dist/installer/tree.js +30 -5
  57. package/dist/installer/tree.js.map +1 -1
  58. package/dist/installer/wasmBuilds.d.ts +34 -0
  59. package/dist/installer/wasmBuilds.d.ts.map +1 -0
  60. package/dist/installer/wasmBuilds.js +41 -0
  61. package/dist/installer/wasmBuilds.js.map +1 -0
  62. package/dist/node/builtins.d.ts +6 -1
  63. package/dist/node/builtins.d.ts.map +1 -1
  64. package/dist/node/builtins.js +17 -10
  65. package/dist/node/builtins.js.map +1 -1
  66. package/dist/node/childProcess.d.ts +3 -3
  67. package/dist/node/childProcess.d.ts.map +1 -1
  68. package/dist/node/childProcess.js +68 -16
  69. package/dist/node/childProcess.js.map +1 -1
  70. package/dist/node/crypto.d.ts.map +1 -1
  71. package/dist/node/crypto.js +5 -4
  72. package/dist/node/crypto.js.map +1 -1
  73. package/dist/node/esm.d.ts +7 -0
  74. package/dist/node/esm.d.ts.map +1 -1
  75. package/dist/node/esm.js +28 -2
  76. package/dist/node/esm.js.map +1 -1
  77. package/dist/node/fs/index.d.ts +3 -0
  78. package/dist/node/fs/index.d.ts.map +1 -1
  79. package/dist/node/fs/index.js +22 -106
  80. package/dist/node/fs/index.js.map +1 -1
  81. package/dist/node/fs/stdinFd.d.ts +10 -0
  82. package/dist/node/fs/stdinFd.d.ts.map +1 -0
  83. package/dist/node/fs/stdinFd.js +40 -0
  84. package/dist/node/fs/stdinFd.js.map +1 -0
  85. package/dist/node/fs/streams.d.ts +24 -0
  86. package/dist/node/fs/streams.d.ts.map +1 -0
  87. package/dist/node/fs/streams.js +144 -0
  88. package/dist/node/fs/streams.js.map +1 -0
  89. package/dist/node/fs/sync.d.ts +2 -0
  90. package/dist/node/fs/sync.d.ts.map +1 -1
  91. package/dist/node/fs/sync.js +17 -0
  92. package/dist/node/fs/sync.js.map +1 -1
  93. package/dist/node/globalObject.d.ts +25 -0
  94. package/dist/node/globalObject.d.ts.map +1 -0
  95. package/dist/node/globalObject.js +83 -0
  96. package/dist/node/globalObject.js.map +1 -0
  97. package/dist/node/http/index.d.ts.map +1 -1
  98. package/dist/node/http/index.js +4 -3
  99. package/dist/node/http/index.js.map +1 -1
  100. package/dist/node/http/server.d.ts.map +1 -1
  101. package/dist/node/http/server.js +8 -5
  102. package/dist/node/http/server.js.map +1 -1
  103. package/dist/node/http/serverResponse.d.ts +3 -0
  104. package/dist/node/http/serverResponse.d.ts.map +1 -1
  105. package/dist/node/http/serverResponse.js +7 -0
  106. package/dist/node/http/serverResponse.js.map +1 -1
  107. package/dist/node/ipc.d.ts +26 -0
  108. package/dist/node/ipc.d.ts.map +1 -0
  109. package/dist/node/ipc.js +76 -0
  110. package/dist/node/ipc.js.map +1 -0
  111. package/dist/node/loader.d.ts +2 -0
  112. package/dist/node/loader.d.ts.map +1 -1
  113. package/dist/node/loader.js +79 -14
  114. package/dist/node/loader.js.map +1 -1
  115. package/dist/node/misc.d.ts.map +1 -1
  116. package/dist/node/misc.js +20 -6
  117. package/dist/node/misc.js.map +1 -1
  118. package/dist/node/process.d.ts +2 -5
  119. package/dist/node/process.d.ts.map +1 -1
  120. package/dist/node/process.js +16 -11
  121. package/dist/node/process.js.map +1 -1
  122. package/dist/node/processExit.d.ts +13 -0
  123. package/dist/node/processExit.d.ts.map +1 -0
  124. package/dist/node/processExit.js +25 -0
  125. package/dist/node/processExit.js.map +1 -0
  126. package/dist/node/program.d.ts.map +1 -1
  127. package/dist/node/program.js +6 -5
  128. package/dist/node/program.js.map +1 -1
  129. package/dist/node/runtime.d.ts +6 -1
  130. package/dist/node/runtime.d.ts.map +1 -1
  131. package/dist/node/runtime.js +23 -15
  132. package/dist/node/runtime.js.map +1 -1
  133. package/dist/node/stream/readable.d.ts +2 -1
  134. package/dist/node/stream/readable.d.ts.map +1 -1
  135. package/dist/node/stream/readable.js +2 -1
  136. package/dist/node/stream/readable.js.map +1 -1
  137. package/dist/node/urlqs.d.ts +1 -1
  138. package/dist/node/urlqs.d.ts.map +1 -1
  139. package/dist/node/urlqs.js +11 -2
  140. package/dist/node/urlqs.js.map +1 -1
  141. package/dist/node/wasi/abi.d.ts +82 -0
  142. package/dist/node/wasi/abi.d.ts.map +1 -0
  143. package/dist/node/wasi/abi.js +144 -0
  144. package/dist/node/wasi/abi.js.map +1 -0
  145. package/dist/node/wasi/files.d.ts +67 -0
  146. package/dist/node/wasi/files.d.ts.map +1 -0
  147. package/dist/node/wasi/files.js +319 -0
  148. package/dist/node/wasi/files.js.map +1 -0
  149. package/dist/node/wasi/index.d.ts +17 -0
  150. package/dist/node/wasi/index.d.ts.map +1 -0
  151. package/dist/node/wasi/index.js +129 -0
  152. package/dist/node/wasi/index.js.map +1 -0
  153. package/dist/node/workerThreads.d.ts +31 -0
  154. package/dist/node/workerThreads.d.ts.map +1 -0
  155. package/dist/node/workerThreads.js +165 -0
  156. package/dist/node/workerThreads.js.map +1 -0
  157. package/dist/node/zlib.d.ts.map +1 -1
  158. package/dist/node/zlib.js +23 -2
  159. package/dist/node/zlib.js.map +1 -1
  160. package/dist/shell/context.d.ts.map +1 -1
  161. package/dist/shell/context.js +2 -2
  162. package/dist/shell/context.js.map +1 -1
  163. package/dist/shell/devHandoff.d.ts +10 -4
  164. package/dist/shell/devHandoff.d.ts.map +1 -1
  165. package/dist/shell/devHandoff.js +7 -5
  166. package/dist/shell/devHandoff.js.map +1 -1
  167. package/dist/shell/exec.d.ts.map +1 -1
  168. package/dist/shell/exec.js +6 -5
  169. package/dist/shell/exec.js.map +1 -1
  170. package/dist/shell/npm.js +2 -2
  171. package/dist/shell/npm.js.map +1 -1
  172. package/dist/shell/program.js +5 -5
  173. package/dist/shell/program.js.map +1 -1
  174. package/dist/styleModules.d.ts +2 -5
  175. package/dist/styleModules.d.ts.map +1 -1
  176. package/dist/styleModules.js +23 -14
  177. package/dist/styleModules.js.map +1 -1
  178. package/dist/styles/compile.d.ts +18 -0
  179. package/dist/styles/compile.d.ts.map +1 -0
  180. package/dist/styles/compile.js +34 -0
  181. package/dist/styles/compile.js.map +1 -0
  182. package/dist/styles/compilers.d.ts +75 -0
  183. package/dist/styles/compilers.d.ts.map +1 -0
  184. package/dist/styles/compilers.js +77 -0
  185. package/dist/styles/compilers.js.map +1 -0
  186. package/dist/styles/cssModules.d.ts +40 -0
  187. package/dist/styles/cssModules.d.ts.map +1 -0
  188. package/dist/styles/cssModules.js +239 -0
  189. package/dist/styles/cssModules.js.map +1 -0
  190. package/dist/styles/imports.d.ts +37 -0
  191. package/dist/styles/imports.d.ts.map +1 -0
  192. package/dist/styles/imports.js +88 -0
  193. package/dist/styles/imports.js.map +1 -0
  194. package/dist/styles/languages.d.ts +13 -0
  195. package/dist/styles/languages.d.ts.map +1 -0
  196. package/dist/styles/languages.js +20 -0
  197. package/dist/styles/languages.js.map +1 -0
  198. package/dist/styles/packageStyles.d.ts +19 -0
  199. package/dist/styles/packageStyles.d.ts.map +1 -0
  200. package/dist/styles/packageStyles.js +32 -0
  201. package/dist/styles/packageStyles.js.map +1 -0
  202. package/dist/svelteCompiler.d.ts.map +1 -1
  203. package/dist/svelteCompiler.js +19 -2
  204. package/dist/svelteCompiler.js.map +1 -1
  205. package/dist/system/commands.d.ts +2 -0
  206. package/dist/system/commands.d.ts.map +1 -1
  207. package/dist/system/commands.js +18 -0
  208. package/dist/system/commands.js.map +1 -1
  209. package/dist/system/index.d.ts +3 -1
  210. package/dist/system/index.d.ts.map +1 -1
  211. package/dist/system/index.js +1 -0
  212. package/dist/system/index.js.map +1 -1
  213. package/dist/system/ipc.d.ts +33 -0
  214. package/dist/system/ipc.d.ts.map +1 -0
  215. package/dist/system/ipc.js +65 -0
  216. package/dist/system/ipc.js.map +1 -0
  217. package/dist/system/kernel.d.ts.map +1 -1
  218. package/dist/system/kernel.js +6 -3
  219. package/dist/system/kernel.js.map +1 -1
  220. package/dist/system/process.d.ts +3 -0
  221. package/dist/system/process.d.ts.map +1 -1
  222. package/dist/system/process.js +50 -26
  223. package/dist/system/process.js.map +1 -1
  224. package/dist/system/terminal.d.ts +10 -4
  225. package/dist/system/terminal.d.ts.map +1 -1
  226. package/dist/system/terminal.js +21 -13
  227. package/dist/system/terminal.js.map +1 -1
  228. package/dist/system/types.d.ts +29 -7
  229. package/dist/system/types.d.ts.map +1 -1
  230. package/dist/vueCompiler.d.ts.map +1 -1
  231. package/dist/vueCompiler.js +11 -8
  232. package/dist/vueCompiler.js.map +1 -1
  233. package/package.json +4 -1
  234. package/src/build.ts +13 -1
  235. package/src/buildHost.ts +23 -10
  236. package/src/compileComponent.ts +4 -1
  237. package/src/compileScript.ts +30 -11
  238. package/src/components.ts +5 -0
  239. package/src/detectProject.ts +13 -6
  240. package/src/devServer.ts +148 -23
  241. package/src/devStyles.ts +70 -0
  242. package/src/hot/client.ts +70 -0
  243. package/src/hot/moduleGraph.ts +90 -0
  244. package/src/hot/planUpdate.ts +66 -0
  245. package/src/hot/reactRefresh.ts +93 -0
  246. package/src/html.ts +13 -19
  247. package/src/index.ts +19 -1
  248. package/src/installer/tree.ts +32 -5
  249. package/src/installer/wasmBuilds.ts +60 -0
  250. package/src/node/builtins.ts +23 -12
  251. package/src/node/childProcess.ts +73 -20
  252. package/src/node/crypto.ts +5 -4
  253. package/src/node/esm.ts +26 -2
  254. package/src/node/fs/index.ts +26 -103
  255. package/src/node/fs/stdinFd.ts +44 -0
  256. package/src/node/fs/streams.ts +177 -0
  257. package/src/node/fs/sync.ts +15 -0
  258. package/src/node/globalObject.ts +82 -0
  259. package/src/node/http/index.ts +4 -3
  260. package/src/node/http/server.ts +8 -5
  261. package/src/node/http/serverResponse.ts +7 -0
  262. package/src/node/ipc.ts +91 -0
  263. package/src/node/loader.ts +78 -14
  264. package/src/node/misc.ts +19 -6
  265. package/src/node/process.ts +15 -8
  266. package/src/node/processExit.ts +21 -0
  267. package/src/node/program.ts +12 -9
  268. package/src/node/runtime.ts +27 -15
  269. package/src/node/stream/readable.ts +2 -1
  270. package/src/node/urlqs.ts +10 -2
  271. package/src/node/wasi/abi.ts +151 -0
  272. package/src/node/wasi/files.ts +350 -0
  273. package/src/node/wasi/index.ts +149 -0
  274. package/src/node/workerThreads.ts +198 -0
  275. package/src/node/zlib.ts +24 -2
  276. package/src/shell/context.ts +2 -2
  277. package/src/shell/devHandoff.ts +16 -9
  278. package/src/shell/exec.ts +6 -5
  279. package/src/shell/npm.ts +2 -2
  280. package/src/shell/program.ts +5 -5
  281. package/src/styleModules.ts +30 -14
  282. package/src/styles/compile.ts +43 -0
  283. package/src/styles/compilers.ts +143 -0
  284. package/src/styles/cssModules.ts +254 -0
  285. package/src/styles/imports.ts +125 -0
  286. package/src/styles/languages.ts +29 -0
  287. package/src/styles/packageStyles.ts +35 -0
  288. package/src/svelteCompiler.ts +20 -3
  289. package/src/system/commands.ts +17 -0
  290. package/src/system/index.ts +4 -0
  291. package/src/system/ipc.ts +89 -0
  292. package/src/system/kernel.ts +6 -3
  293. package/src/system/process.ts +57 -30
  294. package/src/system/terminal.ts +34 -12
  295. package/src/system/types.ts +31 -7
  296. package/src/vueCompiler.ts +11 -8
@@ -0,0 +1,254 @@
1
+ import { contentHash } from '../hash.js';
2
+
3
+ /**
4
+ * CSS Modules for the dev server: every class and keyframes name a `.module.*`
5
+ * stylesheet defines is renamed to one unique to that file, so two components'
6
+ * `.title` never collide in the preview, exactly as they don't in a build (where
7
+ * esbuild's `local-css` loader does the same job).
8
+ *
9
+ * Supported: `:global(.x)` / `:local(.x)` and the bare `:global` / `:local`
10
+ * modes, `composes: a b`, `composes: a from './other.module.css'`,
11
+ * `composes: a from global`, local `@keyframes` and the `animation` /
12
+ * `animation-name` declarations that use them, nested rules and at-rules.
13
+ * Names are a pure function of (file, name), so an edit never renames a class
14
+ * an open page already holds.
15
+ */
16
+ export type ComposedClass = { kind: 'local'; name: string } | { kind: 'global'; name: string } | { kind: 'import'; from: string; name: string };
17
+
18
+ export interface ScopedCssModule {
19
+ css: string;
20
+ /** Exported name (class or keyframes) → its name in `css`. */
21
+ locals: Record<string, string>;
22
+ /** The classes `composes:` adds to an exported class, in order. */
23
+ composes: Record<string, ComposedClass[]>;
24
+ }
25
+
26
+ type FrameKind = 'rules' | 'decls' | 'keyframes' | 'atdecls';
27
+ interface Frame {
28
+ kind: FrameKind;
29
+ /** The local classes a style rule's selector names — what its `composes:` applies to. */
30
+ classes: string[];
31
+ }
32
+
33
+ /** At-rules whose block holds rules (or, nested in a style rule, declarations). */
34
+ const GROUP_AT_RULES = new Set(['media', 'supports', 'layer', 'container', 'document', '-moz-document', 'scope', 'starting-style']);
35
+ const IDENT = /^-?(?:[_a-zA-Z -￿]|\\.)(?:[\w -￿-]|\\.)*/;
36
+
37
+ /** Index just past the string starting at `at`. */
38
+ function stringEnd(text: string, at: number): number {
39
+ const quote = text[at];
40
+ let i = at + 1;
41
+ while (i < text.length && text[i] !== quote) i += text[i] === '\\' ? 2 : 1;
42
+ return Math.min(i + 1, text.length);
43
+ }
44
+
45
+ /** Index just past the `)` matching the `(` at `at`, skipping strings and nested parens. */
46
+ function parenEnd(text: string, at: number): number {
47
+ let depth = 0;
48
+ for (let i = at; i < text.length; i++) {
49
+ const ch = text[i];
50
+ if (ch === '"' || ch === "'") i = stringEnd(text, i) - 1;
51
+ else if (ch === '(') depth++;
52
+ else if (ch === ')' && --depth === 0) return i + 1;
53
+ }
54
+ return text.length;
55
+ }
56
+
57
+ const unescape = (name: string) => name.replace(/\\(.)/g, '$1');
58
+
59
+ export function scopeCssModule(source: string, path: string): ScopedCssModule {
60
+ const hash = contentHash(path, 5);
61
+ const locals: Record<string, string> = {};
62
+ const composes: Record<string, ComposedClass[]> = {};
63
+ const local = (name: string): string => (locals[name] ??= `_${name.replace(/[^\w-]/g, '_')}_${hash}`);
64
+
65
+ const keyframes = new Set<string>();
66
+ for (const match of source.matchAll(/@(?:-[a-z]+-)?keyframes\s+(-?[_a-zA-Z][\w-]*)/g)) keyframes.add(match[1]!);
67
+
68
+ function scopeSelector(selector: string, classes: string[]): string {
69
+ let out = '';
70
+ let global = false;
71
+ for (let i = 0; i < selector.length; ) {
72
+ const ch = selector[i]!;
73
+ if (ch === '"' || ch === "'") {
74
+ const end = stringEnd(selector, i);
75
+ out += selector.slice(i, end);
76
+ i = end;
77
+ } else if (ch === '[') {
78
+ const end = selector.indexOf(']', i);
79
+ const stop = end < 0 ? selector.length : end + 1;
80
+ out += selector.slice(i, stop);
81
+ i = stop;
82
+ } else if (ch === ',') {
83
+ global = false;
84
+ out += ch;
85
+ i++;
86
+ } else if (selector.startsWith(':global(', i) || selector.startsWith(':local(', i)) {
87
+ const isGlobal = selector.startsWith(':global(', i);
88
+ const open = i + (isGlobal ? 7 : 6);
89
+ const close = parenEnd(selector, open);
90
+ const inner = selector.slice(open + 1, close - 1);
91
+ out += isGlobal ? inner : scopeSelector(inner, classes);
92
+ i = close;
93
+ } else if (/^:(global|local)(?![\w-])/.test(selector.slice(i))) {
94
+ global = selector.startsWith(':global', i);
95
+ i += global ? 7 : 6;
96
+ if (selector[i] === ' ' && /(^|[\s>+~(,])$/.test(out)) i++; // `:global .x` → `.x`, not ` .x`
97
+ } else if (ch === '.' && IDENT.test(selector.slice(i + 1))) {
98
+ const raw = IDENT.exec(selector.slice(i + 1))![0];
99
+ const name = unescape(raw);
100
+ if (global) out += `.${raw}`;
101
+ else {
102
+ out += `.${local(name)}`;
103
+ classes.push(name);
104
+ }
105
+ i += 1 + raw.length;
106
+ } else {
107
+ out += ch;
108
+ i++;
109
+ }
110
+ }
111
+ return out;
112
+ }
113
+
114
+ function scopeKeyframesPrelude(prelude: string): string {
115
+ return prelude.replace(/(keyframes\s+)(?::global\(\s*([\w-]+)\s*\)|:local\(\s*([\w-]+)\s*\)|(-?[_a-zA-Z][\w-]*))/, (_m, lead: string, globalName?: string, localName?: string, plain?: string) =>
116
+ lead + (globalName ?? local((localName ?? plain)!)),
117
+ );
118
+ }
119
+
120
+ function composeDeclaration(value: string, classes: string[]): void {
121
+ const match = /^(.*?)(?:\s+from\s+(global|"[^"]*"|'[^']*'))?\s*$/s.exec(value.trim());
122
+ if (!match) return;
123
+ const names = match[1]!.split(/\s+/).filter(Boolean);
124
+ const from = match[2];
125
+ const parts = names.map((name): ComposedClass => {
126
+ if (from === 'global') return { kind: 'global', name };
127
+ if (from) return { kind: 'import', from: from.slice(1, -1), name };
128
+ local(name); // a composed local class is exported even if no selector names it
129
+ return { kind: 'local', name };
130
+ });
131
+ for (const owner of classes) (composes[owner] ??= []).push(...parts);
132
+ }
133
+
134
+ const stack: Frame[] = [{ kind: 'rules', classes: [] }];
135
+ const top = () => stack[stack.length - 1]!;
136
+ let out = '';
137
+
138
+ function statement(text: string): void {
139
+ const frame = top();
140
+ if (frame.kind === 'decls') {
141
+ const composed = /^\s*composes\s*:\s*([^;]*);?\s*$/is.exec(text);
142
+ if (composed) return composeDeclaration(composed[1]!, frame.classes);
143
+ const animation = /^(\s*(?:-[a-z]+-)?animation(?:-name)?\s*:)([^;]*)(;?\s*)$/is.exec(text);
144
+ if (animation) {
145
+ const value = animation[2]!.replace(/(^|[\s,])(-?[_a-zA-Z][\w-]*)(?=$|[\s,])/g, (m, lead: string, name: string) => (keyframes.has(name) ? lead + local(name) : m));
146
+ out += animation[1] + value + animation[3];
147
+ return;
148
+ }
149
+ }
150
+ out += text;
151
+ }
152
+
153
+ function open(prelude: string): void {
154
+ const parent = top();
155
+ const trimmed = prelude.trim();
156
+ if (trimmed.startsWith('@')) {
157
+ const name = (/^@([\w-]+)/.exec(trimmed)?.[1] ?? '').toLowerCase();
158
+ if (name.endsWith('keyframes')) {
159
+ out += `${scopeKeyframesPrelude(prelude)}{`;
160
+ stack.push({ kind: 'keyframes', classes: [] });
161
+ } else {
162
+ out += `${prelude}{`;
163
+ stack.push({ kind: GROUP_AT_RULES.has(name) ? (parent.kind === 'decls' ? 'decls' : 'rules') : 'atdecls', classes: parent.classes });
164
+ }
165
+ } else if (parent.kind === 'keyframes' || parent.kind === 'atdecls') {
166
+ out += `${prelude}{`;
167
+ stack.push({ kind: 'atdecls', classes: [] });
168
+ } else {
169
+ const classes: string[] = [];
170
+ out += `${scopeSelector(prelude, classes)}{`;
171
+ stack.push({ kind: 'decls', classes });
172
+ }
173
+ }
174
+
175
+ let buffer = '';
176
+ for (let i = 0; i < source.length; ) {
177
+ const ch = source[i]!;
178
+ if (ch === '/' && source[i + 1] === '*') {
179
+ const end = source.indexOf('*/', i + 2);
180
+ i = end < 0 ? source.length : end + 2; // comments are dropped from the dev stylesheet
181
+ } else if (ch === '"' || ch === "'") {
182
+ const end = stringEnd(source, i);
183
+ buffer += source.slice(i, end);
184
+ i = end;
185
+ } else if (ch === '(') {
186
+ // `url(data:…;…)` and `:not(.a, .b)` hold characters that would otherwise end a statement.
187
+ const end = parenEnd(source, i);
188
+ buffer += source.slice(i, end);
189
+ i = end;
190
+ } else if (ch === '{') {
191
+ open(buffer);
192
+ buffer = '';
193
+ i++;
194
+ } else if (ch === ';') {
195
+ statement(`${buffer};`);
196
+ buffer = '';
197
+ i++;
198
+ } else if (ch === '}') {
199
+ if (buffer.trim()) statement(buffer);
200
+ buffer = '';
201
+ out += '}';
202
+ if (stack.length > 1) stack.pop();
203
+ i++;
204
+ } else {
205
+ buffer += ch;
206
+ i++;
207
+ }
208
+ }
209
+ out += buffer;
210
+ return { css: out, locals, composes };
211
+ }
212
+
213
+ const RESERVED = new Set(
214
+ 'break case catch class const continue debugger default delete do else enum export extends false finally for function if import in instanceof new null return super switch this throw true try typeof var void while with yield let static implements interface package private protected public await arguments eval'.split(' '),
215
+ );
216
+
217
+ /**
218
+ * The JS module a dev-server CSS Module becomes: it injects its scoped CSS via
219
+ * `injectCss` (a statement given the CSS literal), and exports the class map as
220
+ * the default plus each valid identifier as a named export — Vite's shape.
221
+ * `importUrl` maps a `composes … from` path to the URL its module is served at.
222
+ */
223
+ export function cssModuleToModule(scoped: ScopedCssModule, path: string, injectCss: (cssExpression: string) => string, importUrl: (from: string) => string | undefined): string {
224
+ const imports = new Map<string, string>();
225
+ const importName = (from: string) => {
226
+ let name = imports.get(from);
227
+ if (!name) imports.set(from, (name = `__composed${imports.size}`));
228
+ return name;
229
+ };
230
+
231
+ const valueOf = (key: string, seen: Set<string>): string[] => {
232
+ if (seen.has(key)) return [];
233
+ seen.add(key);
234
+ const parts = [JSON.stringify(scoped.locals[key] ?? key)];
235
+ for (const part of scoped.composes[key] ?? []) {
236
+ if (part.kind === 'local') parts.push(...valueOf(part.name, seen));
237
+ else if (part.kind === 'global') parts.push(JSON.stringify(part.name));
238
+ else parts.push(`${importName(part.from)}[${JSON.stringify(part.name)}]`);
239
+ }
240
+ return parts;
241
+ };
242
+
243
+ const entries = Object.keys(scoped.locals).map((key) => ` ${JSON.stringify(key)}: ${valueOf(key, new Set()).join(' + " " + ')},`);
244
+ const header: string[] = [];
245
+ for (const [from, name] of imports) {
246
+ const url = importUrl(from);
247
+ if (!url) throw new Error(`${path}: cannot find "${from}" (composes … from)`);
248
+ header.push(`import ${name} from ${JSON.stringify(url)};`);
249
+ }
250
+ const named = Object.keys(scoped.locals)
251
+ .filter((key) => /^[A-Za-z_$][\w$]*$/.test(key) && !RESERVED.has(key))
252
+ .map((key) => `export const ${key} = __classes[${JSON.stringify(key)}];`);
253
+ return [...header, injectCss(JSON.stringify(scoped.css)), `const __classes = {\n${entries.join('\n')}\n};`, 'export default __classes;', ...named].join('\n');
254
+ }
@@ -0,0 +1,125 @@
1
+ import type { VirtualFileSystem } from '../vfs.js';
2
+ import { dirname, join, normalizePath } from '../paths.js';
3
+ import { isRegistryRange } from '../packageCdn.js';
4
+ import { splitPackageSpecifier } from '../resolve.js';
5
+ import { styleLanguageOf, type StyleLanguage } from './languages.js';
6
+
7
+ /**
8
+ * Where a preprocessor's `@use` / `@import` finds its files: the project's own
9
+ * files first, then an installed `node_modules`, then the package on a CDN — so
10
+ * `@use 'bootstrap/scss/functions'` works whether or not `npm install` has run.
11
+ *
12
+ * Ids are VFS paths (`/src/_vars.scss`) for project and installed files and
13
+ * absolute URLs for CDN files, so a CDN file's own relative imports resolve
14
+ * against its URL.
15
+ */
16
+ export interface StyleSource {
17
+ id: string;
18
+ contents: string;
19
+ language: StyleLanguage;
20
+ }
21
+
22
+ export interface StyleImportHost {
23
+ /**
24
+ * The id of the file `specifier` names from the stylesheet `from` (an id, or
25
+ * undefined for the entry), trying each path `candidates` derives — partials,
26
+ * extensions, index files, which differ per language.
27
+ */
28
+ resolve(specifier: string, from: string | undefined, candidates: (path: string) => string[]): Promise<string | undefined>;
29
+ load(id: string): Promise<StyleSource>;
30
+ }
31
+
32
+ export interface StyleImportHostOptions {
33
+ fs: VirtualFileSystem;
34
+ /** The project's dependency ranges, which pin CDN package files. */
35
+ dependencies: Readonly<Record<string, string>>;
36
+ /** Fetches a CDN file's text, or undefined when it does not exist. Default: `fetch`. */
37
+ fetchText?: (url: string) => Promise<string | undefined>;
38
+ /** A package file's URL. Default: jsDelivr, which serves package files as published. */
39
+ packageFileUrl?: (name: string, range: string, subpath: string) => string;
40
+ }
41
+
42
+ export const jsDelivrFileUrl = (name: string, range: string, subpath: string): string => `https://cdn.jsdelivr.net/npm/${name}@${range}${subpath}`;
43
+
44
+ const defaultFetchText = async (url: string): Promise<string | undefined> => {
45
+ const res = await fetch(url);
46
+ return res.ok ? res.text() : undefined;
47
+ };
48
+
49
+ const isUrl = (id: string) => /^https?:\/\//i.test(id);
50
+
51
+ export function createStyleImportHost(options: StyleImportHostOptions): StyleImportHost {
52
+ const { fs, dependencies } = options;
53
+ const fetchText = options.fetchText ?? defaultFetchText;
54
+ const packageFileUrl = options.packageFileUrl ?? jsDelivrFileUrl;
55
+ /** A CDN probe answers the same way for the host's lifetime, found or not. */
56
+ const remote = new Map<string, Promise<string | undefined>>();
57
+
58
+ const fetchCached = (url: string) => {
59
+ let pending = remote.get(url);
60
+ if (!pending) {
61
+ pending = fetchText(url).catch(() => undefined);
62
+ remote.set(url, pending);
63
+ }
64
+ return pending;
65
+ };
66
+
67
+ async function exists(id: string): Promise<boolean> {
68
+ return isUrl(id) ? (await fetchCached(id)) !== undefined : fs.isFile(id);
69
+ }
70
+
71
+ async function firstExisting(paths: string[]): Promise<string | undefined> {
72
+ for (const path of paths) if (await exists(path)) return path;
73
+ return undefined;
74
+ }
75
+
76
+ /** A package's own stylesheet entry (`"sass"` / `"style"` in its package.json), for `@use 'pkg'`. */
77
+ async function packageEntry(root: string): Promise<string | undefined> {
78
+ const manifest = isUrl(root) ? await fetchCached(`${root}/package.json`) : fs.readText(join(root, 'package.json'));
79
+ if (!manifest) return undefined;
80
+ try {
81
+ const json = JSON.parse(manifest) as { sass?: unknown; style?: unknown };
82
+ const entry = typeof json.sass === 'string' ? json.sass : typeof json.style === 'string' ? json.style : undefined;
83
+ return entry ? (isUrl(root) ? new URL(entry, `${root}/`).href : join(root, entry)) : undefined;
84
+ } catch {
85
+ return undefined;
86
+ }
87
+ }
88
+
89
+ async function fromPackage(specifier: string, candidates: (path: string) => string[]): Promise<string | undefined> {
90
+ const { name, subpath } = splitPackageSpecifier(specifier);
91
+ const range = dependencies[name];
92
+ const roots = [`/node_modules/${name}`, packageFileUrl(name, range && isRegistryRange(range) ? range : 'latest', '')];
93
+ for (const root of roots) {
94
+ if (!subpath) {
95
+ const entry = await packageEntry(root);
96
+ if (entry && (await exists(entry))) return entry;
97
+ continue;
98
+ }
99
+ const hit = await firstExisting(candidates(`${root}${subpath}`));
100
+ if (hit) return hit;
101
+ }
102
+ return undefined;
103
+ }
104
+
105
+ return {
106
+ async resolve(specifier, from, candidates) {
107
+ const spec = specifier.startsWith('~') ? specifier.slice(1) : specifier;
108
+ if (isUrl(spec)) return firstExisting(candidates(spec));
109
+ const relative = spec.startsWith('./') || spec.startsWith('../') || spec.startsWith('/');
110
+ // Preprocessors look beside the importing file first, even for `@use 'vars'`.
111
+ if (!specifier.startsWith('~')) {
112
+ const near = !from ? normalizePath(spec) : isUrl(from) ? new URL(spec, from).href : spec.startsWith('/') ? normalizePath(spec) : join(dirname(from), spec);
113
+ const hit = await firstExisting(candidates(near));
114
+ if (hit || relative) return hit;
115
+ }
116
+ return fromPackage(spec, candidates);
117
+ },
118
+
119
+ async load(id) {
120
+ const contents = isUrl(id) ? await fetchCached(id) : fs.readText(id);
121
+ if (contents === undefined) throw new Error(`Cannot read stylesheet ${id}`);
122
+ return { id, contents, language: styleLanguageOf(id.replace(/[?#].*$/, '')) ?? 'css' };
123
+ },
124
+ };
125
+ }
@@ -0,0 +1,29 @@
1
+ import { extname } from '../paths.js';
2
+
3
+ /**
4
+ * Which files are stylesheets, in which language — the one place that says so,
5
+ * for the dev server, the build and component `<style lang>` blocks alike.
6
+ */
7
+ export type StyleLanguage = 'css' | 'scss' | 'sass' | 'less';
8
+
9
+ const BY_EXTENSION: Record<string, StyleLanguage> = { '.css': 'css', '.scss': 'scss', '.sass': 'sass', '.less': 'less' };
10
+
11
+ /** The language of a stylesheet path, or undefined when it is not one. */
12
+ export function styleLanguageOf(path: string): StyleLanguage | undefined {
13
+ return BY_EXTENSION[extname(path).toLowerCase()];
14
+ }
15
+
16
+ export function isStylesheet(path: string): boolean {
17
+ return styleLanguageOf(path) !== undefined;
18
+ }
19
+
20
+ /** `card.module.css`, `card.module.scss`: class names are scoped to the file. */
21
+ export function isCssModule(path: string): boolean {
22
+ return /\.module\.(css|scss|sass|less)$/i.test(path);
23
+ }
24
+
25
+ /** A `<style lang="…">` value as a language; `postcss` and absent mean plain CSS. */
26
+ export function styleLanguageOfLang(lang: string | undefined): StyleLanguage | undefined {
27
+ if (!lang || lang === 'css' || lang === 'postcss') return 'css';
28
+ return lang === 'scss' || lang === 'sass' || lang === 'less' ? lang : undefined;
29
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A stylesheet imported from a package by JS — `import 'bootstrap/dist/css/bootstrap.css'`.
3
+ * It cannot stay a JS import of a CSS URL, so both the dev server and the build
4
+ * route it through one virtual directory: the dev server answers there with a
5
+ * module that links (or, for Sass/Less, injects) the stylesheet; the build turns
6
+ * it into a CSS `@import` (or the compiled CSS) in the entry's bundle.
7
+ */
8
+ export const PACKAGE_STYLE_DIR = 'bfwc-package-css';
9
+
10
+ const PREFIX = `/${PACKAGE_STYLE_DIR}/`;
11
+
12
+ /** The virtual path a package stylesheet specifier is served and bundled under. */
13
+ export function packageStylePath(specifier: string): string {
14
+ return PREFIX + specifier;
15
+ }
16
+
17
+ /** The package specifier behind a virtual path, or undefined when `path` is not one. */
18
+ export function packageStyleSpecifier(path: string): string | undefined {
19
+ return path.startsWith(PREFIX) ? path.slice(PREFIX.length) : undefined;
20
+ }
21
+
22
+ /**
23
+ * A module that adds `<link rel="stylesheet" href>` once (keyed by `key`). A link,
24
+ * not fetched text in a <style>, so the stylesheet's own relative `url()`s
25
+ * (fonts, icons) resolve against the CDN, where those files are.
26
+ */
27
+ export function linkStylesheetModule(key: string, href: string): string {
28
+ const id = JSON.stringify(key);
29
+ return [
30
+ `if (!document.querySelector('link[data-bfwc=' + JSON.stringify(${id}) + ']')) {`,
31
+ ` const link = document.createElement('link'); link.rel = 'stylesheet'; link.href = ${JSON.stringify(href)}; link.setAttribute('data-bfwc', ${id}); document.head.appendChild(link);`,
32
+ `}`,
33
+ `export default ${JSON.stringify(href)};`,
34
+ ].join('\n');
35
+ }
@@ -1,4 +1,4 @@
1
- import type { ComponentCompiler } from './components.js';
1
+ import type { ComponentCompiler, ComponentRequest } from './components.js';
2
2
 
3
3
  /**
4
4
  * Svelte components through `svelte/compiler`. CSS is always compiled as
@@ -17,14 +17,31 @@ export interface SvelteCompilerLike {
17
17
  ): { js: { code: string }; css?: { code: string } | null };
18
18
  }
19
19
 
20
+ const STYLE_BLOCK = /<style(\s[^>]*?)?\slang\s*=\s*["']?([\w-]+)["']?([^>]*)>([\s\S]*?)<\/style>/gi;
21
+
22
+ /** `<style lang="scss">` blocks compiled to plain `<style>` before Svelte sees them, as svelte-preprocess would. */
23
+ async function preprocessStyles(source: string, path: string, preprocessStyle: ComponentRequest['preprocessStyle']): Promise<string> {
24
+ const blocks = [...source.matchAll(STYLE_BLOCK)].filter((match) => match[2] !== 'css');
25
+ if (!blocks.length) return source;
26
+ if (!preprocessStyle) throw new Error(`${path}: <style lang="${blocks[0]![2]}"> needs a CSS preprocessor, and none is configured.`);
27
+ let out = '';
28
+ let cursor = 0;
29
+ for (const block of blocks) {
30
+ const css = await preprocessStyle(block[2]!, block[4]!);
31
+ out += `${source.slice(cursor, block.index)}<style${block[1] ?? ''}${block[3]}>${css}</style>`;
32
+ cursor = block.index! + block[0].length;
33
+ }
34
+ return out + source.slice(cursor);
35
+ }
36
+
20
37
  export function createSvelteCompiler(svelte: SvelteCompilerLike): ComponentCompiler {
21
38
  const major = Number.parseInt(svelte.VERSION, 10);
22
39
  // Svelte 5 renamed the browser target from 'dom' to 'client'.
23
40
  // Typed as Svelte 5's value; Svelte 4 receives its own spelling at runtime.
24
41
  const generate = (major >= 5 ? 'client' : 'dom') as 'client';
25
42
  return {
26
- compile(source, { path, dev }) {
27
- const result = svelte.compile(source, { filename: path, generate, css: 'external', dev });
43
+ async compile(source, { path, dev, preprocessStyle }) {
44
+ const result = svelte.compile(await preprocessStyles(source, path, preprocessStyle), { filename: path, generate, css: 'external', dev });
28
45
  return { code: result.js.code, loader: 'js', css: result.css?.code ?? '' };
29
46
  },
30
47
  };
@@ -16,6 +16,21 @@ export interface ResolvedCommand {
16
16
  args: string[];
17
17
  }
18
18
 
19
+ /** Where registered programs live (`which node` → `/usr/local/bin/node`); the default `PATH`. */
20
+ export const SYSTEM_BIN_DIRS = ['/usr/local/bin', '/usr/bin', '/bin'] as const;
21
+
22
+ /**
23
+ * `/usr/local/bin/node` → `node`: an absolute path into a system bin directory
24
+ * names the registered program, unless a real file sits there. Tools spawn
25
+ * `process.execPath` this way (Next.js's telemetry flush, worker pools).
26
+ */
27
+ function systemProgramName(fs: VirtualFileSystem, command: string): string | undefined {
28
+ if (!command.startsWith('/')) return undefined;
29
+ const path = normalizePath(command);
30
+ if (!(SYSTEM_BIN_DIRS as readonly string[]).includes(dirname(path)) || fs.isFile(path)) return undefined;
31
+ return path.slice(dirname(path).length + 1);
32
+ }
33
+
19
34
  /** Every `node_modules/.bin` from `cwd` up to the root, nearest first. */
20
35
  export function binDirectories(cwd: string): string[] {
21
36
  const out: string[] = [];
@@ -60,6 +75,8 @@ export function resolveCommand(
60
75
  if (!command.includes('/') && Object.prototype.hasOwnProperty.call(programs, command)) {
61
76
  return { name: command, program: programs[command]!, args };
62
77
  }
78
+ const system = systemProgramName(fs, command);
79
+ if (system && Object.prototype.hasOwnProperty.call(programs, system)) return { name: system, program: programs[system]!, args };
63
80
  const file = findExecutable(fs, command, cwd, env);
64
81
  if (!file) return undefined;
65
82
  const { name, args: lead } = interpreterFor(fs, file);
@@ -15,7 +15,11 @@ export type {
15
15
  HttpHandler,
16
16
  ByteChannel,
17
17
  UpgradeHandler,
18
+ ThreadInfo,
19
+ StdioChunk,
18
20
  } from './types.js';
21
+ export { createIpcEndpoint, createIpcPair } from './ipc.js';
22
+ export type { IpcEndpoint } from './ipc.js';
19
23
  export { PortRegistry, parsePortPath } from './ports.js';
20
24
  export { pushStream, bytesStream, textResponse, readBody, bufferResponse, headOf, drainBody, createChannelPair } from './httpStream.js';
21
25
  export type { PushStream } from './httpStream.js';
@@ -0,0 +1,89 @@
1
+ /**
2
+ * A message channel between a process and the parent that started it — what
3
+ * `child_process.fork()` opens (`child.send` ↔ `process.send`) and what a
4
+ * `worker_threads` Worker talks over (`worker.postMessage` ↔ `parentPort`).
5
+ *
6
+ * One endpoint shape for every hop: in-process (the core kernel), and relayed
7
+ * through the page between process Workers (the browser runtime). Messages are
8
+ * structured-cloned, as Node's `serialization: 'advanced'` does, and delivered
9
+ * asynchronously. Messages that arrive before the receiver subscribes wait for
10
+ * it — a child attaching its `process.on('message')` while its module loads
11
+ * still gets what the parent sent right after `fork()`.
12
+ */
13
+ export interface IpcEndpoint {
14
+ send(message: unknown): void;
15
+ onMessage(listener: (message: unknown) => void): () => void;
16
+ /** Close the channel; both ends hear `onDisconnect`. */
17
+ disconnect(): void;
18
+ onDisconnect(listener: () => void): () => void;
19
+ readonly connected: boolean;
20
+ }
21
+
22
+ /**
23
+ * An endpoint whose sends go out through `post` and whose incoming traffic the
24
+ * owner feeds in: `receive(message)` for a message, `closed()` when the far end
25
+ * went away. `onClose` runs once when THIS end disconnects (to tell the far end).
26
+ */
27
+ export function createIpcEndpoint(post: (message: unknown) => void, onClose: () => void = () => undefined) {
28
+ const listeners = new Set<(message: unknown) => void>();
29
+ const disconnectListeners = new Set<() => void>();
30
+ let backlog: unknown[] = [];
31
+ let connected = true;
32
+
33
+ const close = (notifyFarEnd: boolean) => {
34
+ if (!connected) return;
35
+ connected = false;
36
+ backlog = [];
37
+ if (notifyFarEnd) onClose();
38
+ queueMicrotask(() => disconnectListeners.forEach((listener) => listener()));
39
+ };
40
+
41
+ const endpoint: IpcEndpoint = {
42
+ send(message) {
43
+ if (!connected) throw Object.assign(new Error('Channel closed'), { code: 'ERR_IPC_CHANNEL_CLOSED' });
44
+ post(structuredClone(message));
45
+ },
46
+ onMessage(listener) {
47
+ listeners.add(listener);
48
+ if (backlog.length) {
49
+ const waiting = backlog;
50
+ backlog = [];
51
+ queueMicrotask(() => waiting.forEach((message) => listener(message)));
52
+ }
53
+ return () => listeners.delete(listener);
54
+ },
55
+ disconnect: () => close(true),
56
+ onDisconnect(listener) {
57
+ disconnectListeners.add(listener);
58
+ return () => disconnectListeners.delete(listener);
59
+ },
60
+ get connected() {
61
+ return connected;
62
+ },
63
+ };
64
+
65
+ return {
66
+ endpoint,
67
+ receive(message: unknown) {
68
+ if (!connected) return;
69
+ if (!listeners.size) backlog.push(message);
70
+ else queueMicrotask(() => listeners.forEach((listener) => listener(message)));
71
+ },
72
+ closed: () => close(false),
73
+ };
74
+ }
75
+
76
+ /** Two endpoints wired to each other, in one realm: the parent's and the child's. */
77
+ export function createIpcPair(): [IpcEndpoint, IpcEndpoint] {
78
+ // eslint-disable-next-line prefer-const -- each side's `post` reaches the other, created after it
79
+ let child: ReturnType<typeof createIpcEndpoint>;
80
+ const parent = createIpcEndpoint(
81
+ (message) => child.receive(message),
82
+ () => child.closed(),
83
+ );
84
+ child = createIpcEndpoint(
85
+ (message) => parent.receive(message),
86
+ () => parent.closed(),
87
+ );
88
+ return [parent.endpoint, child.endpoint];
89
+ }
@@ -10,8 +10,9 @@ import type { PackageCache } from '../installer/registry.js';
10
10
  import type { ByteChannel, ChildHandle, HttpRequestData, HttpResponseData, HttpStreamResponse, Program, ProcessOptions, System } from './types.js';
11
11
  import { PortRegistry } from './ports.js';
12
12
  import { ServerEvents } from './serverEvents.js';
13
- import { commandNotFound, resolveCommand } from './commands.js';
13
+ import { commandNotFound, resolveCommand, SYSTEM_BIN_DIRS } from './commands.js';
14
14
  import { runArguments, runProgram, toRuntimeProcess, type RuntimeProcess } from './process.js';
15
+ import { createIpcPair } from './ipc.js';
15
16
 
16
17
  export interface KernelOptions {
17
18
  fs?: VirtualFileSystem;
@@ -28,7 +29,7 @@ export interface KernelOptions {
28
29
  }
29
30
 
30
31
  export const DEFAULT_ENV: Record<string, string> = {
31
- PATH: '/usr/local/bin:/usr/bin:/bin',
32
+ PATH: SYSTEM_BIN_DIRS.join(':'),
32
33
  HOME: '/home/user',
33
34
  USER: 'user',
34
35
  SHELL: '/bin/bfsh',
@@ -79,7 +80,9 @@ export class Kernel {
79
80
  const env = { ...this.env, ...options.env };
80
81
  const resolved = resolveCommand(this.fs, this.options.programs, command, args, cwd, env);
81
82
  if (!resolved) throw commandNotFound(command);
82
- return runProgram({ program: resolved.program, args: resolved.args, system: this.system, cwd, env, terminal: options.terminal });
83
+ const [parentEnd, childEnd] = options.ipc ? createIpcPair() : [];
84
+ const child = runProgram({ program: resolved.program, args: resolved.args, system: this.system, cwd, env, terminal: options.terminal, thread: options.thread, channel: childEnd });
85
+ return parentEnd ? { ...child, ipc: parentEnd } : child;
83
86
  }
84
87
 
85
88
  /** Send an HTTP request to a virtual server (what the preview service worker does in the browser); resolves with the whole response. */