@seanhogg/builderforce-webcontainers-core 2026.10.2 → 2026.10.4

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 (426) hide show
  1. package/dist/build.d.ts +42 -0
  2. package/dist/build.d.ts.map +1 -0
  3. package/dist/build.js +65 -0
  4. package/dist/build.js.map +1 -0
  5. package/dist/buildHost.d.ts +31 -0
  6. package/dist/buildHost.d.ts.map +1 -0
  7. package/dist/buildHost.js +125 -0
  8. package/dist/buildHost.js.map +1 -0
  9. package/dist/buildHtml.d.ts +28 -0
  10. package/dist/buildHtml.d.ts.map +1 -0
  11. package/dist/buildHtml.js +74 -0
  12. package/dist/buildHtml.js.map +1 -0
  13. package/dist/bundler.d.ts +129 -0
  14. package/dist/bundler.d.ts.map +1 -0
  15. package/dist/bundler.js +79 -0
  16. package/dist/bundler.js.map +1 -0
  17. package/dist/check/acquire.d.ts +46 -0
  18. package/dist/check/acquire.d.ts.map +1 -0
  19. package/dist/check/acquire.js +179 -0
  20. package/dist/check/acquire.js.map +1 -0
  21. package/dist/check/compilerHost.d.ts +22 -0
  22. package/dist/check/compilerHost.d.ts.map +1 -0
  23. package/dist/check/compilerHost.js +128 -0
  24. package/dist/check/compilerHost.js.map +1 -0
  25. package/dist/check/diagnostics.d.ts +23 -0
  26. package/dist/check/diagnostics.d.ts.map +1 -0
  27. package/dist/check/diagnostics.js +28 -0
  28. package/dist/check/diagnostics.js.map +1 -0
  29. package/dist/check/index.d.ts +19 -0
  30. package/dist/check/index.d.ts.map +1 -0
  31. package/dist/check/index.js +13 -0
  32. package/dist/check/index.js.map +1 -0
  33. package/dist/check/projects.d.ts +26 -0
  34. package/dist/check/projects.d.ts.map +1 -0
  35. package/dist/check/projects.js +124 -0
  36. package/dist/check/projects.js.map +1 -0
  37. package/dist/check/shims.d.ts +29 -0
  38. package/dist/check/shims.d.ts.map +1 -0
  39. package/dist/check/shims.js +76 -0
  40. package/dist/check/shims.js.map +1 -0
  41. package/dist/check/typeStore.d.ts +57 -0
  42. package/dist/check/typeStore.d.ts.map +1 -0
  43. package/dist/check/typeStore.js +89 -0
  44. package/dist/check/typeStore.js.map +1 -0
  45. package/dist/check/typecheck.d.ts +29 -0
  46. package/dist/check/typecheck.d.ts.map +1 -0
  47. package/dist/check/typecheck.js +91 -0
  48. package/dist/check/typecheck.js.map +1 -0
  49. package/dist/compileComponent.d.ts +8 -0
  50. package/dist/compileComponent.d.ts.map +1 -0
  51. package/dist/compileComponent.js +22 -0
  52. package/dist/compileComponent.js.map +1 -0
  53. package/dist/compileScript.d.ts +19 -4
  54. package/dist/compileScript.d.ts.map +1 -1
  55. package/dist/compileScript.js +37 -12
  56. package/dist/compileScript.js.map +1 -1
  57. package/dist/components.d.ts +41 -0
  58. package/dist/components.d.ts.map +1 -0
  59. package/dist/components.js +14 -0
  60. package/dist/components.js.map +1 -0
  61. package/dist/detectProject.d.ts +3 -0
  62. package/dist/detectProject.d.ts.map +1 -1
  63. package/dist/detectProject.js +16 -6
  64. package/dist/detectProject.js.map +1 -1
  65. package/dist/devServer.d.ts +5 -2
  66. package/dist/devServer.d.ts.map +1 -1
  67. package/dist/devServer.js +12 -8
  68. package/dist/devServer.js.map +1 -1
  69. package/dist/hash.d.ts +2 -0
  70. package/dist/hash.d.ts.map +1 -0
  71. package/dist/hash.js +22 -0
  72. package/dist/hash.js.map +1 -0
  73. package/dist/index.d.ts +24 -6
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +14 -3
  76. package/dist/index.js.map +1 -1
  77. package/dist/installer/bins.d.ts +24 -0
  78. package/dist/installer/bins.d.ts.map +1 -0
  79. package/dist/installer/bins.js +56 -0
  80. package/dist/installer/bins.js.map +1 -0
  81. package/dist/installer/index.d.ts +14 -0
  82. package/dist/installer/index.d.ts.map +1 -0
  83. package/dist/installer/index.js +9 -0
  84. package/dist/installer/index.js.map +1 -0
  85. package/dist/installer/install.d.ts +46 -0
  86. package/dist/installer/install.d.ts.map +1 -0
  87. package/dist/installer/install.js +245 -0
  88. package/dist/installer/install.js.map +1 -0
  89. package/dist/installer/lockfile.d.ts +49 -0
  90. package/dist/installer/lockfile.d.ts.map +1 -0
  91. package/dist/installer/lockfile.js +110 -0
  92. package/dist/installer/lockfile.js.map +1 -0
  93. package/dist/installer/registry.d.ts +84 -0
  94. package/dist/installer/registry.d.ts.map +1 -0
  95. package/dist/installer/registry.js +130 -0
  96. package/dist/installer/registry.js.map +1 -0
  97. package/dist/installer/semver.d.ts +38 -0
  98. package/dist/installer/semver.d.ts.map +1 -0
  99. package/dist/installer/semver.js +187 -0
  100. package/dist/installer/semver.js.map +1 -0
  101. package/dist/installer/spec.d.ts +30 -0
  102. package/dist/installer/spec.d.ts.map +1 -0
  103. package/dist/installer/spec.js +30 -0
  104. package/dist/installer/spec.js.map +1 -0
  105. package/dist/installer/tar.d.ts +17 -0
  106. package/dist/installer/tar.d.ts.map +1 -0
  107. package/dist/installer/tar.js +150 -0
  108. package/dist/installer/tar.js.map +1 -0
  109. package/dist/installer/tree.d.ts +48 -0
  110. package/dist/installer/tree.d.ts.map +1 -0
  111. package/dist/installer/tree.js +179 -0
  112. package/dist/installer/tree.js.map +1 -0
  113. package/dist/node/assert.d.ts +15 -0
  114. package/dist/node/assert.d.ts.map +1 -0
  115. package/dist/node/assert.js +137 -0
  116. package/dist/node/assert.js.map +1 -0
  117. package/dist/node/buffer.d.ts +84 -0
  118. package/dist/node/buffer.d.ts.map +1 -0
  119. package/dist/node/buffer.js +304 -0
  120. package/dist/node/buffer.js.map +1 -0
  121. package/dist/node/builtins.d.ts +25 -0
  122. package/dist/node/builtins.d.ts.map +1 -0
  123. package/dist/node/builtins.js +101 -0
  124. package/dist/node/builtins.js.map +1 -0
  125. package/dist/node/callable.d.ts +13 -0
  126. package/dist/node/callable.d.ts.map +1 -0
  127. package/dist/node/callable.js +26 -0
  128. package/dist/node/callable.js.map +1 -0
  129. package/dist/node/childProcess.d.ts +13 -0
  130. package/dist/node/childProcess.d.ts.map +1 -0
  131. package/dist/node/childProcess.js +143 -0
  132. package/dist/node/childProcess.js.map +1 -0
  133. package/dist/node/crypto.d.ts +3 -0
  134. package/dist/node/crypto.d.ts.map +1 -0
  135. package/dist/node/crypto.js +180 -0
  136. package/dist/node/crypto.js.map +1 -0
  137. package/dist/node/esm.d.ts +9 -0
  138. package/dist/node/esm.d.ts.map +1 -0
  139. package/dist/node/esm.js +202 -0
  140. package/dist/node/esm.js.map +1 -0
  141. package/dist/node/events.d.ts +40 -0
  142. package/dist/node/events.d.ts.map +1 -0
  143. package/dist/node/events.js +160 -0
  144. package/dist/node/events.js.map +1 -0
  145. package/dist/node/fs/index.d.ts +7 -0
  146. package/dist/node/fs/index.d.ts.map +1 -0
  147. package/dist/node/fs/index.js +270 -0
  148. package/dist/node/fs/index.js.map +1 -0
  149. package/dist/node/fs/stats.d.ts +93 -0
  150. package/dist/node/fs/stats.d.ts.map +1 -0
  151. package/dist/node/fs/stats.js +104 -0
  152. package/dist/node/fs/stats.js.map +1 -0
  153. package/dist/node/fs/sync.d.ts +98 -0
  154. package/dist/node/fs/sync.d.ts.map +1 -0
  155. package/dist/node/fs/sync.js +348 -0
  156. package/dist/node/fs/sync.js.map +1 -0
  157. package/dist/node/hashes.d.ts +15 -0
  158. package/dist/node/hashes.d.ts.map +1 -0
  159. package/dist/node/hashes.js +195 -0
  160. package/dist/node/hashes.js.map +1 -0
  161. package/dist/node/http/client.d.ts +35 -0
  162. package/dist/node/http/client.d.ts.map +1 -0
  163. package/dist/node/http/client.js +161 -0
  164. package/dist/node/http/client.js.map +1 -0
  165. package/dist/node/http/index.d.ts +5 -0
  166. package/dist/node/http/index.d.ts.map +1 -0
  167. package/dist/node/http/index.js +125 -0
  168. package/dist/node/http/index.js.map +1 -0
  169. package/dist/node/http/server.d.ts +135 -0
  170. package/dist/node/http/server.d.ts.map +1 -0
  171. package/dist/node/http/server.js +308 -0
  172. package/dist/node/http/server.js.map +1 -0
  173. package/dist/node/http/status.d.ts +3 -0
  174. package/dist/node/http/status.d.ts.map +1 -0
  175. package/dist/node/http/status.js +13 -0
  176. package/dist/node/http/status.js.map +1 -0
  177. package/dist/node/inspect.d.ts +22 -0
  178. package/dist/node/inspect.d.ts.map +1 -0
  179. package/dist/node/inspect.js +172 -0
  180. package/dist/node/inspect.js.map +1 -0
  181. package/dist/node/loader.d.ts +91 -0
  182. package/dist/node/loader.d.ts.map +1 -0
  183. package/dist/node/loader.js +265 -0
  184. package/dist/node/loader.js.map +1 -0
  185. package/dist/node/loop.d.ts +71 -0
  186. package/dist/node/loop.d.ts.map +1 -0
  187. package/dist/node/loop.js +189 -0
  188. package/dist/node/loop.js.map +1 -0
  189. package/dist/node/misc.d.ts +10 -0
  190. package/dist/node/misc.d.ts.map +1 -0
  191. package/dist/node/misc.js +256 -0
  192. package/dist/node/misc.js.map +1 -0
  193. package/dist/node/path.d.ts +14 -0
  194. package/dist/node/path.d.ts.map +1 -0
  195. package/dist/node/path.js +128 -0
  196. package/dist/node/path.js.map +1 -0
  197. package/dist/node/process.d.ts +31 -0
  198. package/dist/node/process.d.ts.map +1 -0
  199. package/dist/node/process.js +309 -0
  200. package/dist/node/process.js.map +1 -0
  201. package/dist/node/program.d.ts +19 -0
  202. package/dist/node/program.d.ts.map +1 -0
  203. package/dist/node/program.js +165 -0
  204. package/dist/node/program.js.map +1 -0
  205. package/dist/node/readline.d.ts +2 -0
  206. package/dist/node/readline.d.ts.map +1 -0
  207. package/dist/node/readline.js +155 -0
  208. package/dist/node/readline.js.map +1 -0
  209. package/dist/node/resolve.d.ts +45 -0
  210. package/dist/node/resolve.d.ts.map +1 -0
  211. package/dist/node/resolve.js +206 -0
  212. package/dist/node/resolve.js.map +1 -0
  213. package/dist/node/runtime.d.ts +40 -0
  214. package/dist/node/runtime.d.ts.map +1 -0
  215. package/dist/node/runtime.js +149 -0
  216. package/dist/node/runtime.js.map +1 -0
  217. package/dist/node/stream/index.d.ts +52 -0
  218. package/dist/node/stream/index.d.ts.map +1 -0
  219. package/dist/node/stream/index.js +184 -0
  220. package/dist/node/stream/index.js.map +1 -0
  221. package/dist/node/stream/readable.d.ts +83 -0
  222. package/dist/node/stream/readable.d.ts.map +1 -0
  223. package/dist/node/stream/readable.js +325 -0
  224. package/dist/node/stream/readable.js.map +1 -0
  225. package/dist/node/stream/writable.d.ts +80 -0
  226. package/dist/node/stream/writable.d.ts.map +1 -0
  227. package/dist/node/stream/writable.js +224 -0
  228. package/dist/node/stream/writable.js.map +1 -0
  229. package/dist/node/urlqs.d.ts +22 -0
  230. package/dist/node/urlqs.d.ts.map +1 -0
  231. package/dist/node/urlqs.js +165 -0
  232. package/dist/node/urlqs.js.map +1 -0
  233. package/dist/node/util.d.ts +37 -0
  234. package/dist/node/util.d.ts.map +1 -0
  235. package/dist/node/util.js +160 -0
  236. package/dist/node/util.js.map +1 -0
  237. package/dist/node/zlib.d.ts +2 -0
  238. package/dist/node/zlib.d.ts.map +1 -0
  239. package/dist/node/zlib.js +133 -0
  240. package/dist/node/zlib.js.map +1 -0
  241. package/dist/packageCdn.d.ts +40 -0
  242. package/dist/packageCdn.d.ts.map +1 -1
  243. package/dist/packageCdn.js +54 -7
  244. package/dist/packageCdn.js.map +1 -1
  245. package/dist/projectConfig.d.ts +6 -2
  246. package/dist/projectConfig.d.ts.map +1 -1
  247. package/dist/projectConfig.js +32 -8
  248. package/dist/projectConfig.js.map +1 -1
  249. package/dist/shell/builtins.d.ts +23 -0
  250. package/dist/shell/builtins.d.ts.map +1 -0
  251. package/dist/shell/builtins.js +131 -0
  252. package/dist/shell/builtins.js.map +1 -0
  253. package/dist/shell/context.d.ts +41 -0
  254. package/dist/shell/context.d.ts.map +1 -0
  255. package/dist/shell/context.js +65 -0
  256. package/dist/shell/context.js.map +1 -0
  257. package/dist/shell/devHandoff.d.ts +18 -0
  258. package/dist/shell/devHandoff.d.ts.map +1 -0
  259. package/dist/shell/devHandoff.js +36 -0
  260. package/dist/shell/devHandoff.js.map +1 -0
  261. package/dist/shell/exec.d.ts +67 -0
  262. package/dist/shell/exec.d.ts.map +1 -0
  263. package/dist/shell/exec.js +247 -0
  264. package/dist/shell/exec.js.map +1 -0
  265. package/dist/shell/expand.d.ts +28 -0
  266. package/dist/shell/expand.d.ts.map +1 -0
  267. package/dist/shell/expand.js +149 -0
  268. package/dist/shell/expand.js.map +1 -0
  269. package/dist/shell/fileCommands.d.ts +10 -0
  270. package/dist/shell/fileCommands.d.ts.map +1 -0
  271. package/dist/shell/fileCommands.js +208 -0
  272. package/dist/shell/fileCommands.js.map +1 -0
  273. package/dist/shell/lineEditor.d.ts +43 -0
  274. package/dist/shell/lineEditor.d.ts.map +1 -0
  275. package/dist/shell/lineEditor.js +234 -0
  276. package/dist/shell/lineEditor.js.map +1 -0
  277. package/dist/shell/npm.d.ts +6 -0
  278. package/dist/shell/npm.d.ts.map +1 -0
  279. package/dist/shell/npm.js +234 -0
  280. package/dist/shell/npm.js.map +1 -0
  281. package/dist/shell/parse.d.ts +73 -0
  282. package/dist/shell/parse.d.ts.map +1 -0
  283. package/dist/shell/parse.js +300 -0
  284. package/dist/shell/parse.js.map +1 -0
  285. package/dist/shell/program.d.ts +12 -0
  286. package/dist/shell/program.d.ts.map +1 -0
  287. package/dist/shell/program.js +219 -0
  288. package/dist/shell/program.js.map +1 -0
  289. package/dist/shell/textCommands.d.ts +15 -0
  290. package/dist/shell/textCommands.d.ts.map +1 -0
  291. package/dist/shell/textCommands.js +185 -0
  292. package/dist/shell/textCommands.js.map +1 -0
  293. package/dist/styleModules.d.ts +6 -0
  294. package/dist/styleModules.d.ts.map +1 -1
  295. package/dist/styleModules.js +14 -4
  296. package/dist/styleModules.js.map +1 -1
  297. package/dist/svelteCompiler.d.ts +28 -0
  298. package/dist/svelteCompiler.d.ts.map +1 -0
  299. package/dist/svelteCompiler.js +13 -0
  300. package/dist/svelteCompiler.js.map +1 -0
  301. package/dist/system/commands.d.ts +26 -0
  302. package/dist/system/commands.d.ts.map +1 -0
  303. package/dist/system/commands.js +53 -0
  304. package/dist/system/commands.js.map +1 -0
  305. package/dist/system/index.d.ts +23 -0
  306. package/dist/system/index.d.ts.map +1 -0
  307. package/dist/system/index.js +16 -0
  308. package/dist/system/index.js.map +1 -0
  309. package/dist/system/kernel.d.ts +54 -0
  310. package/dist/system/kernel.d.ts.map +1 -0
  311. package/dist/system/kernel.js +81 -0
  312. package/dist/system/kernel.js.map +1 -0
  313. package/dist/system/ports.d.ts +32 -0
  314. package/dist/system/ports.d.ts.map +1 -0
  315. package/dist/system/ports.js +57 -0
  316. package/dist/system/ports.js.map +1 -0
  317. package/dist/system/process.d.ts +32 -0
  318. package/dist/system/process.d.ts.map +1 -0
  319. package/dist/system/process.js +130 -0
  320. package/dist/system/process.js.map +1 -0
  321. package/dist/system/programs.d.ts +10 -0
  322. package/dist/system/programs.d.ts.map +1 -0
  323. package/dist/system/programs.js +22 -0
  324. package/dist/system/programs.js.map +1 -0
  325. package/dist/system/terminal.d.ts +45 -0
  326. package/dist/system/terminal.d.ts.map +1 -0
  327. package/dist/system/terminal.js +127 -0
  328. package/dist/system/terminal.js.map +1 -0
  329. package/dist/system/types.d.ts +100 -0
  330. package/dist/system/types.d.ts.map +1 -0
  331. package/dist/system/types.js +2 -0
  332. package/dist/system/types.js.map +1 -0
  333. package/dist/vfs.d.ts +28 -4
  334. package/dist/vfs.d.ts.map +1 -1
  335. package/dist/vfs.js +95 -32
  336. package/dist/vfs.js.map +1 -1
  337. package/dist/vueCompiler.d.ts +75 -0
  338. package/dist/vueCompiler.d.ts.map +1 -0
  339. package/dist/vueCompiler.js +67 -0
  340. package/dist/vueCompiler.js.map +1 -0
  341. package/package.json +18 -2
  342. package/src/build.ts +105 -0
  343. package/src/buildHost.ts +154 -0
  344. package/src/buildHtml.ts +101 -0
  345. package/src/bundler.ts +190 -0
  346. package/src/check/acquire.ts +212 -0
  347. package/src/check/compilerHost.ts +138 -0
  348. package/src/check/diagnostics.ts +48 -0
  349. package/src/check/index.ts +28 -0
  350. package/src/check/projects.ts +149 -0
  351. package/src/check/shims.ts +88 -0
  352. package/src/check/typeStore.ts +103 -0
  353. package/src/check/typecheck.ts +134 -0
  354. package/src/compileComponent.ts +21 -0
  355. package/src/compileScript.ts +42 -13
  356. package/src/components.ts +59 -0
  357. package/src/detectProject.ts +18 -6
  358. package/src/devServer.ts +16 -11
  359. package/src/hash.ts +22 -0
  360. package/src/index.ts +35 -6
  361. package/src/installer/bins.ts +64 -0
  362. package/src/installer/index.ts +13 -0
  363. package/src/installer/install.ts +275 -0
  364. package/src/installer/lockfile.ts +146 -0
  365. package/src/installer/registry.ts +175 -0
  366. package/src/installer/semver.ts +190 -0
  367. package/src/installer/spec.ts +53 -0
  368. package/src/installer/tar.ts +155 -0
  369. package/src/installer/tree.ts +236 -0
  370. package/src/node/assert.ts +127 -0
  371. package/src/node/buffer.ts +304 -0
  372. package/src/node/builtins.ts +123 -0
  373. package/src/node/callable.ts +25 -0
  374. package/src/node/childProcess.ts +164 -0
  375. package/src/node/crypto.ts +187 -0
  376. package/src/node/esm.ts +196 -0
  377. package/src/node/events.ts +176 -0
  378. package/src/node/fs/index.ts +277 -0
  379. package/src/node/fs/stats.ts +110 -0
  380. package/src/node/fs/sync.ts +335 -0
  381. package/src/node/hashes.ts +171 -0
  382. package/src/node/http/client.ts +173 -0
  383. package/src/node/http/index.ts +122 -0
  384. package/src/node/http/server.ts +308 -0
  385. package/src/node/http/status.ts +13 -0
  386. package/src/node/inspect.ts +166 -0
  387. package/src/node/loader.ts +293 -0
  388. package/src/node/loop.ts +193 -0
  389. package/src/node/misc.ts +250 -0
  390. package/src/node/path.ts +135 -0
  391. package/src/node/process.ts +324 -0
  392. package/src/node/program.ts +170 -0
  393. package/src/node/readline.ts +157 -0
  394. package/src/node/resolve.ts +216 -0
  395. package/src/node/runtime.ts +184 -0
  396. package/src/node/stream/index.ts +196 -0
  397. package/src/node/stream/readable.ts +345 -0
  398. package/src/node/stream/writable.ts +244 -0
  399. package/src/node/urlqs.ts +162 -0
  400. package/src/node/util.ts +145 -0
  401. package/src/node/zlib.ts +145 -0
  402. package/src/packageCdn.ts +91 -7
  403. package/src/projectConfig.ts +34 -7
  404. package/src/shell/builtins.ts +141 -0
  405. package/src/shell/context.ts +89 -0
  406. package/src/shell/devHandoff.ts +49 -0
  407. package/src/shell/exec.ts +268 -0
  408. package/src/shell/expand.ts +145 -0
  409. package/src/shell/fileCommands.ts +206 -0
  410. package/src/shell/lineEditor.ts +233 -0
  411. package/src/shell/npm.ts +229 -0
  412. package/src/shell/parse.ts +295 -0
  413. package/src/shell/program.ts +223 -0
  414. package/src/shell/textCommands.ts +177 -0
  415. package/src/styleModules.ts +15 -4
  416. package/src/svelteCompiler.ts +31 -0
  417. package/src/system/commands.ts +72 -0
  418. package/src/system/index.ts +22 -0
  419. package/src/system/kernel.ts +106 -0
  420. package/src/system/ports.ts +73 -0
  421. package/src/system/process.ts +158 -0
  422. package/src/system/programs.ts +31 -0
  423. package/src/system/terminal.ts +135 -0
  424. package/src/system/types.ts +103 -0
  425. package/src/vfs.ts +92 -28
  426. package/src/vueCompiler.ts +121 -0
@@ -0,0 +1,164 @@
1
+ /**
2
+ * `child_process` over the system's `spawn`: every "process" is another program
3
+ * of this runtime (node, npm, the shell and its commands). There are no native
4
+ * executables, so spawning one fails with ENOENT exactly as a missing binary
5
+ * would. Synchronous variants cannot block a browser thread on another one, so
6
+ * they throw a clear error instead of hanging.
7
+ */
8
+ import { EventEmitterBase } from './events.js';
9
+ import { Readable } from './stream/readable.js';
10
+ import { Writable } from './stream/writable.js';
11
+ import type { EventLoop } from './loop.js';
12
+ import type { ChildHandle, System } from '../system/types.js';
13
+
14
+ interface SpawnOptions {
15
+ cwd?: string;
16
+ env?: Record<string, string | undefined>;
17
+ shell?: boolean | string;
18
+ stdio?: unknown;
19
+ signal?: AbortSignal;
20
+ encoding?: string;
21
+ maxBuffer?: number;
22
+ }
23
+
24
+ export interface ChildProcessDeps {
25
+ system: System;
26
+ loop: EventLoop;
27
+ cwd(): string;
28
+ env(): Record<string, string | undefined>;
29
+ /** Parent's stdio for `stdio: 'inherit'`. */
30
+ stdout(chunk: string): void;
31
+ stderr(chunk: string): void;
32
+ }
33
+
34
+ const quote = (arg: string) => (/^[\w@%+=:,./-]+$/.test(arg) ? arg : `'${arg.replace(/'/g, `'\\''`)}'`);
35
+
36
+ class ChildProcess extends EventEmitterBase {
37
+ pid?: number;
38
+ exitCode: number | null = null;
39
+ signalCode: string | null = null;
40
+ killed = false;
41
+ connected = false;
42
+ spawnfile: string;
43
+ spawnargs: string[];
44
+ stdin: Writable;
45
+ stdout: Readable;
46
+ stderr: Readable;
47
+ stdio: [Writable, Readable, Readable];
48
+ private handle?: ChildHandle;
49
+
50
+ constructor(deps: ChildProcessDeps, command: string, args: string[], options: SpawnOptions) {
51
+ super();
52
+ this.spawnfile = command;
53
+ this.spawnargs = [command, ...args];
54
+ this.stdout = new Readable({ read() {} });
55
+ this.stderr = new Readable({ read() {} });
56
+ this.stdin = new Writable({
57
+ write: (chunk: Uint8Array | string, _enc: string, cb: () => void) => {
58
+ this.handle?.write(typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk));
59
+ cb();
60
+ },
61
+ final: (cb: () => void) => {
62
+ this.handle?.closeStdin();
63
+ cb();
64
+ },
65
+ });
66
+ this.stdio = [this.stdin, this.stdout, this.stderr];
67
+ const inherit = options.stdio === 'inherit' || (Array.isArray(options.stdio) && options.stdio[1] === 'inherit');
68
+
69
+ const env: Record<string, string> = {};
70
+ for (const [k, v] of Object.entries(options.env ?? deps.env())) if (v !== undefined) env[k] = String(v);
71
+ const [file, argv] = options.shell ? ['jsh', ['-c', [command, ...args].join(' ')]] : [command, args];
72
+ const release = deps.loop.hold();
73
+ try {
74
+ this.handle = deps.system.spawn(file, argv, { cwd: options.cwd ?? deps.cwd(), env });
75
+ } catch (error) {
76
+ release();
77
+ const code = (error as { code?: string }).code ?? 'ENOENT';
78
+ const failure = Object.assign(new Error(`spawn ${command} ${code}`), { code, errno: -2, syscall: `spawn ${command}`, path: command, spawnargs: args });
79
+ queueMicrotask(() => {
80
+ this.emit('error', failure);
81
+ this.emit('close', -2, null);
82
+ });
83
+ return;
84
+ }
85
+ this.pid = this.handle.pid;
86
+ this.handle.onStdout((chunk) => (inherit ? deps.stdout(chunk) : this.stdout.push(chunk)));
87
+ this.handle.onStderr((chunk) => (inherit ? deps.stderr(chunk) : this.stderr.push(chunk)));
88
+ options.signal?.addEventListener('abort', () => this.kill());
89
+ queueMicrotask(() => this.emit('spawn'));
90
+ void this.handle.exit.then((code) => {
91
+ this.exitCode = this.killed ? null : code;
92
+ this.stdout.push(null);
93
+ this.stderr.push(null);
94
+ deps.loop._run(() => {
95
+ this.emit('exit', this.exitCode, this.signalCode);
96
+ this.emit('close', this.exitCode, this.signalCode);
97
+ });
98
+ release();
99
+ });
100
+ }
101
+
102
+ kill(signal = 'SIGTERM'): boolean {
103
+ if (!this.handle || this.exitCode !== null) return false;
104
+ this.killed = true;
105
+ this.signalCode = signal;
106
+ this.handle.kill(signal);
107
+ return true;
108
+ }
109
+
110
+ send(): boolean {
111
+ throw Object.assign(new Error('IPC channels are not supported in the browser runtime'), { code: 'ERR_FEATURE_UNAVAILABLE_ON_PLATFORM' });
112
+ }
113
+ disconnect(): void {}
114
+ ref(): void {}
115
+ unref(): void {}
116
+ }
117
+
118
+ type ExecCallback = (error: (Error & { code?: number | string }) | null, stdout: string, stderr: string) => void;
119
+
120
+ function collect(child: ChildProcess, command: string, callback?: ExecCallback): ChildProcess {
121
+ let stdout = '';
122
+ let stderr = '';
123
+ child.stdout.on('data', (c: unknown) => (stdout += String(c)));
124
+ child.stderr.on('data', (c: unknown) => (stderr += String(c)));
125
+ child.on('error', (error: Error) => callback?.(error, stdout, stderr));
126
+ child.on('close', (code: number | null, signal: string | null) => {
127
+ if (code === -2) return; // already reported through 'error'
128
+ const error = code === 0 ? null : Object.assign(new Error(`Command failed: ${command}\n${stderr}`), { code: code ?? undefined, killed: child.killed, signal, cmd: command });
129
+ callback?.(error as (Error & { code?: number }) | null, stdout, stderr);
130
+ });
131
+ return child;
132
+ }
133
+
134
+ const noSync = (name: string) => () => {
135
+ throw Object.assign(new Error(`child_process.${name} is not supported in the browser runtime (a synchronous child would block the thread it needs). Use the async form.`), { code: 'ERR_FEATURE_UNAVAILABLE_ON_PLATFORM' });
136
+ };
137
+
138
+ export function createChildProcessModule(deps: ChildProcessDeps): Record<string, unknown> {
139
+ const spawn = (command: string, args?: string[] | SpawnOptions, options?: SpawnOptions) => {
140
+ if (!Array.isArray(args)) [options, args] = [args, []];
141
+ return new ChildProcess(deps, command, args.map(String), options ?? {});
142
+ };
143
+ return {
144
+ spawn,
145
+ exec(command: string, options?: SpawnOptions | ExecCallback, callback?: ExecCallback) {
146
+ if (typeof options === 'function') [callback, options] = [options, {}];
147
+ return collect(new ChildProcess(deps, command, [], { ...options, shell: true }), command, callback);
148
+ },
149
+ execFile(file: string, args?: string[] | SpawnOptions | ExecCallback, options?: SpawnOptions | ExecCallback, callback?: ExecCallback) {
150
+ if (typeof args === 'function') [callback, args, options] = [args, [], {}];
151
+ else if (!Array.isArray(args)) [callback, options, args] = [options as ExecCallback, args, []];
152
+ if (typeof options === 'function') [callback, options] = [options, {}];
153
+ return collect(new ChildProcess(deps, file, args, options ?? {}), [file, ...args].map(quote).join(' '), callback);
154
+ },
155
+ fork(modulePath: string, args?: string[] | SpawnOptions, options?: SpawnOptions) {
156
+ if (!Array.isArray(args)) [options, args] = [args, []];
157
+ return new ChildProcess(deps, 'node', [modulePath, ...args], options ?? {});
158
+ },
159
+ execSync: noSync('execSync'),
160
+ execFileSync: noSync('execFileSync'),
161
+ spawnSync: noSync('spawnSync'),
162
+ ChildProcess,
163
+ };
164
+ }
@@ -0,0 +1,187 @@
1
+ /**
2
+ * The `crypto` module: hashes and HMAC (sync, via hashes.ts), random bytes and
3
+ * UUIDs (WebCrypto's getRandomValues), pbkdf2, `timingSafeEqual`, and
4
+ * `webcrypto`/`subtle` passed through. Ciphers, signing and key generation are
5
+ * not shimmed — they throw a clear error rather than misbehave.
6
+ */
7
+ import { Buffer } from './buffer.js';
8
+ import { hashAlgorithm, HASHES } from './hashes.js';
9
+ import { Transform } from './stream/index.js';
10
+
11
+ type Input = string | ArrayBufferView;
12
+
13
+ const toBytes = (data: Input, encoding?: string): Uint8Array =>
14
+ typeof data === 'string' ? Buffer.from(data, encoding) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
15
+
16
+ const output = (bytes: Uint8Array, encoding?: string) => (encoding && encoding !== 'buffer' ? Buffer.from(bytes).toString(encoding as 'hex') : Buffer.from(bytes));
17
+
18
+ class Hash extends Transform {
19
+ private chunks: Uint8Array[] = [];
20
+ private done = false;
21
+
22
+ constructor(private readonly algorithm: string) {
23
+ super();
24
+ hashAlgorithm(algorithm);
25
+ }
26
+
27
+ update(data: Input, encoding?: string): this {
28
+ if (this.done) throw Object.assign(new Error('Digest already called'), { code: 'ERR_CRYPTO_HASH_FINALIZED' });
29
+ this.chunks.push(toBytes(data, encoding).slice());
30
+ return this;
31
+ }
32
+
33
+ digest(encoding?: string): string | Buffer {
34
+ this.done = true;
35
+ return output(hashAlgorithm(this.algorithm).digest(Buffer.concat(this.chunks)), encoding);
36
+ }
37
+
38
+ copy(): Hash {
39
+ const copy = new Hash(this.algorithm);
40
+ copy.chunks = [...this.chunks];
41
+ return copy;
42
+ }
43
+
44
+ override _transform(chunk: Uint8Array, _encoding: string, callback: () => void): void {
45
+ this.update(chunk);
46
+ callback();
47
+ }
48
+
49
+ override _flush(callback: (error?: Error | null, data?: unknown) => void): void {
50
+ callback(null, this.digest());
51
+ }
52
+ }
53
+
54
+ export function hmac(algorithm: string, key: Uint8Array, data: Uint8Array): Uint8Array {
55
+ const { digest, blockSize } = hashAlgorithm(algorithm);
56
+ let k = key.length > blockSize ? digest(key) : key;
57
+ const padded = new Uint8Array(blockSize);
58
+ padded.set(k);
59
+ k = padded;
60
+ const inner = new Uint8Array(blockSize + data.length);
61
+ const outer = new Uint8Array(blockSize);
62
+ for (let i = 0; i < blockSize; i++) {
63
+ inner[i] = k[i]! ^ 0x36;
64
+ outer[i] = k[i]! ^ 0x5c;
65
+ }
66
+ inner.set(data, blockSize);
67
+ const innerHash = digest(inner);
68
+ const final = new Uint8Array(blockSize + innerHash.length);
69
+ final.set(outer);
70
+ final.set(innerHash, blockSize);
71
+ return digest(final);
72
+ }
73
+
74
+ class Hmac extends Hash {
75
+ private readonly hmacKey: Uint8Array;
76
+ private readonly parts: Uint8Array[] = [];
77
+
78
+ constructor(private readonly hmacAlgorithm: string, key: Input) {
79
+ super(hmacAlgorithm);
80
+ this.hmacKey = toBytes(key).slice();
81
+ }
82
+
83
+ override update(data: Input, encoding?: string): this {
84
+ this.parts.push(toBytes(data, encoding).slice());
85
+ return this;
86
+ }
87
+
88
+ override digest(encoding?: string): string | Buffer {
89
+ return output(hmac(this.hmacAlgorithm, this.hmacKey, Buffer.concat(this.parts)), encoding);
90
+ }
91
+ }
92
+
93
+ function pbkdf2Sync(password: Input, salt: Input, iterations: number, keylen: number, digest = 'sha1'): Buffer {
94
+ const pw = toBytes(password);
95
+ const s = toBytes(salt);
96
+ const out = new Uint8Array(keylen);
97
+ for (let block = 1, at = 0; at < keylen; block++) {
98
+ const input = new Uint8Array(s.length + 4);
99
+ input.set(s);
100
+ new DataView(input.buffer).setUint32(s.length, block);
101
+ let u = hmac(digest, pw, input);
102
+ const t = u.slice();
103
+ for (let i = 1; i < iterations; i++) {
104
+ u = hmac(digest, pw, u);
105
+ for (let j = 0; j < t.length; j++) t[j] = t[j]! ^ u[j]!;
106
+ }
107
+ out.set(t.subarray(0, keylen - at), at);
108
+ at += t.length;
109
+ }
110
+ return Buffer.from(out);
111
+ }
112
+
113
+ function randomFill<T extends ArrayBufferView>(view: T): T {
114
+ const bytes = new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
115
+ for (let i = 0; i < bytes.length; i += 65536) globalThis.crypto.getRandomValues(bytes.subarray(i, i + 65536));
116
+ return view;
117
+ }
118
+
119
+ const unsupported = (name: string) => () => {
120
+ throw Object.assign(new Error(`crypto.${name} is not available in the browser runtime`), { code: 'ERR_FEATURE_UNAVAILABLE_ON_PLATFORM' });
121
+ };
122
+
123
+ export function createCryptoModule(): Record<string, unknown> {
124
+ const randomBytes = (size: number, callback?: (error: Error | null, buf: Buffer) => void) => {
125
+ const buf = randomFill(Buffer.alloc(size));
126
+ if (callback) queueMicrotask(() => callback(null, buf));
127
+ return buf;
128
+ };
129
+ return {
130
+ createHash: (algorithm: string) => new Hash(algorithm),
131
+ createHmac: (algorithm: string, key: Input) => new Hmac(algorithm, key),
132
+ hash: (algorithm: string, data: Input, encoding = 'hex') => output(hashAlgorithm(algorithm).digest(toBytes(data)), encoding),
133
+ getHashes: () => Object.keys(HASHES),
134
+ getCiphers: () => [],
135
+ getCurves: () => [],
136
+ randomBytes,
137
+ pseudoRandomBytes: randomBytes,
138
+ randomFillSync: (view: ArrayBufferView, offset = 0, size?: number) => {
139
+ randomFill(new Uint8Array(view.buffer, view.byteOffset + offset, size ?? view.byteLength - offset));
140
+ return view;
141
+ },
142
+ randomFill: (view: ArrayBufferView, ...rest: unknown[]) => {
143
+ const callback = rest.pop() as (e: Error | null, v: ArrayBufferView) => void;
144
+ randomFill(view);
145
+ queueMicrotask(() => callback(null, view));
146
+ },
147
+ randomUUID: () => globalThis.crypto.randomUUID(),
148
+ randomInt(min: number, max?: number | ((e: Error | null, n: number) => void), callback?: (e: Error | null, n: number) => void) {
149
+ if (typeof max !== 'number') [callback, max, min] = [max as typeof callback, min, 0];
150
+ const value = min + Math.floor((globalThis.crypto.getRandomValues(new Uint32Array(1))[0]! / 2 ** 32) * (max - min));
151
+ if (callback) queueMicrotask(() => callback!(null, value));
152
+ return value;
153
+ },
154
+ getRandomValues: <T extends ArrayBufferView>(view: T) => randomFill(view),
155
+ timingSafeEqual(a: ArrayBufferView, b: ArrayBufferView) {
156
+ if (a.byteLength !== b.byteLength) throw new RangeError('Input buffers must have the same byte length');
157
+ const x = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
158
+ const y = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
159
+ let diff = 0;
160
+ for (let i = 0; i < x.length; i++) diff |= x[i]! ^ y[i]!;
161
+ return diff === 0;
162
+ },
163
+ pbkdf2Sync,
164
+ pbkdf2(password: Input, salt: Input, iterations: number, keylen: number, digest: string, callback: (e: Error | null, key?: Buffer) => void) {
165
+ queueMicrotask(() => {
166
+ try {
167
+ callback(null, pbkdf2Sync(password, salt, iterations, keylen, digest));
168
+ } catch (error) {
169
+ callback(error as Error);
170
+ }
171
+ });
172
+ },
173
+ webcrypto: globalThis.crypto,
174
+ subtle: globalThis.crypto?.subtle,
175
+ constants: {},
176
+ createCipheriv: unsupported('createCipheriv'),
177
+ createDecipheriv: unsupported('createDecipheriv'),
178
+ createSign: unsupported('createSign'),
179
+ createVerify: unsupported('createVerify'),
180
+ generateKeyPairSync: unsupported('generateKeyPairSync'),
181
+ generateKeyPair: unsupported('generateKeyPair'),
182
+ createPrivateKey: unsupported('createPrivateKey'),
183
+ createPublicKey: unsupported('createPublicKey'),
184
+ scryptSync: unsupported('scryptSync'),
185
+ scrypt: unsupported('scrypt'),
186
+ };
187
+ }
@@ -0,0 +1,196 @@
1
+ /**
2
+ * ES modules → the CommonJS wrapper, so `require` and `import` share one
3
+ * synchronous loader (`require()` must be sync, and esbuild-wasm has no sync
4
+ * transform in the browser). es-module-lexer finds every import/export; this
5
+ * file rewrites just those spans:
6
+ *
7
+ * import d, { a as b } from 'x' → const __bfwc_m0 = __bfwc_import("x"); const d = …default; const { a: b } = …
8
+ * export const x = 1 → const x = 1 (+ a live getter `x` on exports)
9
+ * export default expr → const __bfwc_default = expr
10
+ * export { a as b } / export * from 'y' / import('z') / import.meta
11
+ *
12
+ * Exports are LIVE (getters over the local bindings). Imported bindings are
13
+ * snapshots taken when the import statement runs: a cycle that reads a binding
14
+ * before the other module finished initialising sees `undefined` rather than
15
+ * the later value. Function declarations are hoisted and exported before any
16
+ * import runs, which covers the common cyclic case.
17
+ */
18
+ import { init, parse } from 'es-module-lexer';
19
+
20
+ /** Resolve before the first transform (the lexer is WebAssembly). */
21
+ export const esmReady: Promise<void> = init;
22
+
23
+ export const ESM_MARK = Symbol.for('bfwc.esm');
24
+
25
+ interface Edit {
26
+ start: number;
27
+ end: number;
28
+ text: string;
29
+ }
30
+
31
+ const IDENT = /^[\p{L}_$][\p{L}\p{N}_$]*$/u;
32
+
33
+ /** Cheap pre-check before lexing a CommonJS-looking file. */
34
+ export function mayBeEsm(source: string): boolean {
35
+ return /(?:^|[\s;})])(?:import\s*[\w{*'"]|export\s+|export\s*[{*])/.test(source);
36
+ }
37
+
38
+ /** Does the lexer see module syntax? (Node's "detect module" for ambiguous .js) */
39
+ export function hasModuleSyntax(source: string): boolean {
40
+ try {
41
+ const [imports, exports] = parse(source);
42
+ return exports.length > 0 || imports.some((i) => i.t === 1 || i.t === 3);
43
+ } catch {
44
+ return false;
45
+ }
46
+ }
47
+
48
+ /** `a, b as c, default as d` → [[imported, local]]. */
49
+ function parseList(list: string): Array<[string, string]> {
50
+ return list
51
+ .split(',')
52
+ .map((part) => part.trim())
53
+ .filter(Boolean)
54
+ .map((part) => {
55
+ const m = /^(?:type\s+)?("[^"]*"|'[^']*'|[^\s]+)(?:\s+as\s+("[^"]*"|'[^']*'|[^\s]+))?$/.exec(part);
56
+ if (!m) throw new SyntaxError(`Cannot parse import/export list entry "${part}"`);
57
+ const unquote = (s: string) => (/^["']/.test(s) ? s.slice(1, -1) : s);
58
+ return [unquote(m[1]!), unquote(m[2] ?? m[1]!)] as [string, string];
59
+ });
60
+ }
61
+
62
+ const access = (ns: string, key: string) => (IDENT.test(key) ? `${ns}.${key}` : `${ns}[${JSON.stringify(key)}]`);
63
+
64
+ /** After `const`/`let`/`var`, the further declarator names `export const a = 1, b = 2` declares. */
65
+ function extraDeclarators(source: string, from: number): string[] {
66
+ const names: string[] = [];
67
+ let depth = 0;
68
+ for (let i = from; i < source.length; i++) {
69
+ const ch = source[i]!;
70
+ if (ch === '"' || ch === "'" || ch === '`') {
71
+ const quote = ch;
72
+ for (i++; i < source.length && source[i] !== quote; i++) if (source[i] === '\\') i++;
73
+ continue;
74
+ }
75
+ if (ch === '(' || ch === '[' || ch === '{') depth++;
76
+ else if (ch === ')' || ch === ']' || ch === '}') depth--;
77
+ else if (depth === 0 && ch === ';') break;
78
+ else if (depth === 0 && ch === '\n') {
79
+ const before = source.slice(from, i).trimEnd();
80
+ const after = source.slice(i + 1).trimStart();
81
+ if (!/[,=+\-*/%&|^?:(]$/.test(before) && !/^[,.=+\-*/%&|^?:)]/.test(after)) break;
82
+ } else if (depth === 0 && ch === ',') {
83
+ const m = /^\s*([\p{L}_$][\p{L}\p{N}_$]*)/u.exec(source.slice(i + 1));
84
+ if (m) names.push(m[1]!);
85
+ }
86
+ if (depth < 0) break;
87
+ }
88
+ return names;
89
+ }
90
+
91
+ const isIdentChar = (ch: string | undefined) => !!ch && /[\p{L}\p{N}_$]/u.test(ch);
92
+
93
+ /** The `export` keyword governing the export name at `pos` (not a substring of an identifier). */
94
+ function exportKeywordBefore(source: string, pos: number): number {
95
+ for (let at = source.lastIndexOf('export', pos - 1); at >= 0; at = source.lastIndexOf('export', at - 1)) {
96
+ if (!isIdentChar(source[at - 1]) && !isIdentChar(source[at + 6])) return at;
97
+ }
98
+ return -1;
99
+ }
100
+
101
+ export function esmToCjs(source: string): string {
102
+ const [imports, exports] = parse(source);
103
+ const edits: Edit[] = [];
104
+ const getters = new Map<string, string>();
105
+ const removedKeywords = new Set<number>();
106
+ const reexportStarts = new Set<number>();
107
+ let counter = 0;
108
+ const call = (spec: string) => `__bfwc_import(${JSON.stringify(spec)})`;
109
+
110
+ for (const imp of imports) {
111
+ if (imp.t === 2) {
112
+ edits.push({ start: imp.ss, end: imp.d, text: '__bfwc_dynamic' });
113
+ continue;
114
+ }
115
+ if (imp.t === 3) {
116
+ edits.push({ start: imp.s, end: imp.e, text: '__bfwc_meta' });
117
+ continue;
118
+ }
119
+ if (imp.t !== 1 || imp.n === undefined) continue;
120
+ const statement = source.slice(imp.ss, imp.se);
121
+ const ns = `__bfwc_m${counter++}`;
122
+ const load = `const ${ns} = ${call(imp.n)};`;
123
+
124
+ if (statement.startsWith('export')) {
125
+ reexportStarts.add(imp.ss);
126
+ const nsMatch = /^export\s*\*\s*as\s+("[^"]*"|'[^']*'|[^\s]+)/.exec(statement);
127
+ if (nsMatch) getters.set(nsMatch[1]!.replace(/^["']|["']$/g, ''), ns);
128
+ else if (/^export\s*\*/.test(statement)) edits.push({ start: imp.ss, end: imp.se, text: `${load} __bfwc_star(exports, ${ns});` });
129
+ else for (const [imported, exported] of parseList(/\{([^}]*)\}/.exec(statement)?.[1] ?? '')) getters.set(exported, access(ns, imported));
130
+ if (!edits.some((e) => e.start === imp.ss)) edits.push({ start: imp.ss, end: imp.se, text: load });
131
+ continue;
132
+ }
133
+
134
+ const clause = /^import\s*([\s\S]*?)\s*from\s*["']/.exec(statement)?.[1];
135
+ if (clause === undefined) {
136
+ edits.push({ start: imp.ss, end: imp.se, text: `${call(imp.n)};` });
137
+ continue;
138
+ }
139
+ const parts: string[] = [load];
140
+ const braces = /\{([\s\S]*)\}/.exec(clause);
141
+ const outside = clause.replace(/\{[\s\S]*\}/, '').split(',').map((s) => s.trim()).filter(Boolean);
142
+ for (const item of outside) {
143
+ const star = /^\*\s*as\s+(\S+)$/.exec(item);
144
+ if (star) parts.push(`const ${star[1]} = ${ns};`);
145
+ else parts.push(`const ${item} = __bfwc_get(${ns}, "default");`);
146
+ }
147
+ if (braces) {
148
+ for (const [imported, local] of parseList(braces[1]!)) parts.push(`const ${local} = __bfwc_get(${ns}, ${JSON.stringify(imported)});`);
149
+ }
150
+ edits.push({ start: imp.ss, end: imp.se, text: parts.join(' ') });
151
+ }
152
+
153
+ const listStatements = new Map<number, number>();
154
+ for (const exp of exports) {
155
+ const kw = exportKeywordBefore(source, exp.s);
156
+ if (kw < 0 || reexportStarts.has(kw)) continue;
157
+ const between = source.slice(kw + 6, exp.s);
158
+ if (/^\s*\{/.test(between)) {
159
+ // `export { a, b as c }`: drop the statement, keep the bindings as getters.
160
+ if (!listStatements.has(kw)) {
161
+ const close = source.indexOf('}', kw);
162
+ let end = close + 1;
163
+ const semi = /^\s*;/.exec(source.slice(end));
164
+ if (semi) end += semi[0].length;
165
+ listStatements.set(kw, end);
166
+ edits.push({ start: kw, end, text: '' });
167
+ }
168
+ getters.set(exp.n, exp.ln ?? exp.n);
169
+ continue;
170
+ }
171
+ if (exp.n === 'default' && source.startsWith('default', exp.s) && !between.trim()) {
172
+ if (exp.ln && exp.ls >= 0) {
173
+ edits.push({ start: kw, end: exp.e, text: '' }); // `export default function name` → `function name`
174
+ getters.set('default', exp.ln);
175
+ } else {
176
+ edits.push({ start: kw, end: exp.e, text: 'const __bfwc_default =' });
177
+ getters.set('default', '__bfwc_default');
178
+ }
179
+ continue;
180
+ }
181
+ if (!removedKeywords.has(kw)) {
182
+ removedKeywords.add(kw);
183
+ edits.push({ start: kw, end: kw + 6, text: '' });
184
+ const decl = /^\s*(const|let|var)\b/.exec(between);
185
+ if (decl) for (const name of extraDeclarators(source, exp.e)) getters.set(name, name);
186
+ }
187
+ getters.set(exp.n, exp.ln ?? exp.n);
188
+ }
189
+
190
+ edits.sort((a, b) => b.start - a.start);
191
+ let code = source;
192
+ for (const edit of edits) code = code.slice(0, edit.start) + edit.text + code.slice(edit.end);
193
+ const getterList = [...getters].map(([name, expr]) => `${JSON.stringify(name)}: () => ${expr}`).join(', ');
194
+ // One line, so stack-trace line numbers stay aligned with the source.
195
+ return `"use strict";__bfwc_esm(exports, { ${getterList} });${code}`;
196
+ }