@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,127 @@
1
+ /**
2
+ * `assert` (and `assert/strict`): the assertion functions test runners and
3
+ * defensive library code call, throwing `AssertionError` with Node's fields.
4
+ */
5
+ import { inspect } from './inspect.js';
6
+ import { isDeepStrictEqual } from './util.js';
7
+
8
+ export class AssertionError extends Error {
9
+ code = 'ERR_ASSERTION';
10
+ actual: unknown;
11
+ expected: unknown;
12
+ operator: string;
13
+ generatedMessage: boolean;
14
+
15
+ constructor(options: { message?: string | Error; actual?: unknown; expected?: unknown; operator?: string }) {
16
+ const generated = options.message === undefined;
17
+ super(generated ? `${inspect(options.actual)} ${options.operator ?? '=='} ${inspect(options.expected)}` : String(options.message));
18
+ this.name = 'AssertionError';
19
+ this.actual = options.actual;
20
+ this.expected = options.expected;
21
+ this.operator = options.operator ?? '==';
22
+ this.generatedMessage = generated;
23
+ }
24
+ }
25
+
26
+ function looseDeepEqual(a: unknown, b: unknown): boolean {
27
+ // eslint-disable-next-line eqeqeq
28
+ if (a == b) return true;
29
+ if (typeof a !== 'object' || typeof b !== 'object' || !a || !b) return false;
30
+ const ka = Object.keys(a);
31
+ const kb = Object.keys(b);
32
+ return ka.length === kb.length && ka.every((k) => looseDeepEqual((a as any)[k], (b as any)[k]));
33
+ }
34
+
35
+ function fail(message: string | Error | undefined, actual: unknown, expected: unknown, operator: string): never {
36
+ if (message instanceof Error) throw message;
37
+ throw new AssertionError({ message, actual, expected, operator });
38
+ }
39
+
40
+ function matchesExpectation(error: unknown, expected: unknown): boolean {
41
+ if (expected === undefined) return true;
42
+ if (typeof expected === 'function') {
43
+ if (expected.prototype !== undefined && error instanceof (expected as new () => unknown)) return true;
44
+ if (Error.isPrototypeOf(expected)) return false;
45
+ return (expected as (e: unknown) => boolean)(error) === true;
46
+ }
47
+ if (expected instanceof RegExp) return expected.test(String(error instanceof Error ? error.message : error)) || expected.test(String(error));
48
+ if (typeof expected === 'object' && expected) {
49
+ return Object.entries(expected).every(([k, v]) => (v instanceof RegExp ? v.test(String((error as any)?.[k])) : isDeepStrictEqual((error as any)?.[k], v)));
50
+ }
51
+ return false;
52
+ }
53
+
54
+ export function createAssertModule(strict = false): Record<string, unknown> {
55
+ const ok = (value: unknown, message?: string | Error) => {
56
+ if (!value) fail(message ?? 'The expression evaluated to a falsy value', value, true, '==');
57
+ };
58
+ const equal = strict
59
+ ? (a: unknown, b: unknown, m?: string | Error) => !Object.is(a, b) && fail(m, a, b, 'strictEqual')
60
+ // eslint-disable-next-line eqeqeq
61
+ : (a: unknown, b: unknown, m?: string | Error) => a != b && !(Number.isNaN(a) && Number.isNaN(b)) && fail(m, a, b, '==');
62
+ const deepEqual = strict
63
+ ? (a: unknown, b: unknown, m?: string | Error) => !isDeepStrictEqual(a, b) && fail(m, a, b, 'deepStrictEqual')
64
+ : (a: unknown, b: unknown, m?: string | Error) => !looseDeepEqual(a, b) && fail(m, a, b, 'deepEqual');
65
+
66
+ const throws = (fn: () => unknown, expected?: unknown, message?: string | Error) => {
67
+ if (typeof expected === 'string') [message, expected] = [expected, undefined];
68
+ try {
69
+ fn();
70
+ } catch (error) {
71
+ if (!matchesExpectation(error, expected)) throw error;
72
+ return;
73
+ }
74
+ fail(message ?? 'Missing expected exception.', undefined, expected, 'throws');
75
+ };
76
+ const rejects = async (promiseOrFn: Promise<unknown> | (() => Promise<unknown>), expected?: unknown, message?: string | Error) => {
77
+ if (typeof expected === 'string') [message, expected] = [expected, undefined];
78
+ try {
79
+ await (typeof promiseOrFn === 'function' ? promiseOrFn() : promiseOrFn);
80
+ } catch (error) {
81
+ if (!matchesExpectation(error, expected)) throw error;
82
+ return;
83
+ }
84
+ fail(message ?? 'Missing expected rejection.', undefined, expected, 'rejects');
85
+ };
86
+
87
+ const assert = ((value: unknown, message?: string | Error) => ok(value, message)) as ((value: unknown, message?: string | Error) => void) & Record<string, unknown>;
88
+ Object.assign(assert, {
89
+ ok,
90
+ equal,
91
+ notEqual: strict
92
+ ? (a: unknown, b: unknown, m?: string | Error) => Object.is(a, b) && fail(m, a, b, 'notStrictEqual')
93
+ // eslint-disable-next-line eqeqeq
94
+ : (a: unknown, b: unknown, m?: string | Error) => a == b && fail(m, a, b, '!='),
95
+ strictEqual: (a: unknown, b: unknown, m?: string | Error) => !Object.is(a, b) && fail(m, a, b, 'strictEqual'),
96
+ notStrictEqual: (a: unknown, b: unknown, m?: string | Error) => Object.is(a, b) && fail(m, a, b, 'notStrictEqual'),
97
+ deepEqual,
98
+ notDeepEqual: (a: unknown, b: unknown, m?: string | Error) => (strict ? isDeepStrictEqual(a, b) : looseDeepEqual(a, b)) && fail(m, a, b, 'notDeepEqual'),
99
+ deepStrictEqual: (a: unknown, b: unknown, m?: string | Error) => !isDeepStrictEqual(a, b) && fail(m, a, b, 'deepStrictEqual'),
100
+ notDeepStrictEqual: (a: unknown, b: unknown, m?: string | Error) => isDeepStrictEqual(a, b) && fail(m, a, b, 'notDeepStrictEqual'),
101
+ throws,
102
+ doesNotThrow: (fn: () => unknown, message?: string | Error) => {
103
+ try {
104
+ fn();
105
+ } catch (error) {
106
+ fail(message ?? `Got unwanted exception: ${(error as Error)?.message ?? error}`, error, undefined, 'doesNotThrow');
107
+ }
108
+ },
109
+ rejects,
110
+ doesNotReject: async (p: Promise<unknown> | (() => Promise<unknown>), message?: string | Error) => {
111
+ try {
112
+ await (typeof p === 'function' ? p() : p);
113
+ } catch (error) {
114
+ fail(message ?? 'Got unwanted rejection.', error, undefined, 'doesNotReject');
115
+ }
116
+ },
117
+ match: (s: string, re: RegExp, m?: string | Error) => !re.test(s) && fail(m ?? `The input did not match the regular expression ${re}. Input: ${inspect(s)}`, s, re, 'match'),
118
+ doesNotMatch: (s: string, re: RegExp, m?: string | Error) => re.test(s) && fail(m, s, re, 'doesNotMatch'),
119
+ ifError: (value: unknown) => {
120
+ if (value !== null && value !== undefined) throw value;
121
+ },
122
+ fail: (message?: string | Error) => fail(message ?? 'Failed', undefined, undefined, 'fail'),
123
+ AssertionError,
124
+ });
125
+ assert.strict = strict ? assert : createAssertModule(true);
126
+ return assert;
127
+ }
@@ -0,0 +1,304 @@
1
+ /**
2
+ * Node's Buffer as a Uint8Array subclass — the common surface: encodings
3
+ * (utf8, hex, base64/base64url, latin1/binary, ascii, utf16le), `from`/`alloc`/
4
+ * `concat`, view-sharing `slice`, search, and the fixed-width integer and float
5
+ * readers/writers parsers rely on. Written here rather than pulling in the
6
+ * CommonJS `buffer` package so the core stays native ESM.
7
+ */
8
+
9
+ export type BufferEncoding = 'utf8' | 'utf-8' | 'hex' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'ascii' | 'ucs2' | 'ucs-2' | 'utf16le' | 'utf-16le';
10
+
11
+ const utf8Encoder = new TextEncoder();
12
+ const utf8Decoder = new TextDecoder();
13
+
14
+ function normalizeEncoding(encoding: unknown): string {
15
+ const e = String(encoding ?? 'utf8').toLowerCase();
16
+ switch (e) {
17
+ case 'utf8': case 'utf-8': return 'utf8';
18
+ case 'hex': return 'hex';
19
+ case 'base64': return 'base64';
20
+ case 'base64url': return 'base64url';
21
+ case 'latin1': case 'binary': return 'latin1';
22
+ case 'ascii': return 'ascii';
23
+ case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return 'utf16le';
24
+ default: throw new TypeError(`Unknown encoding: ${String(encoding)}`);
25
+ }
26
+ }
27
+
28
+ function base64ToBytes(input: string): Uint8Array {
29
+ const clean = input.replace(/[^A-Za-z0-9+/\-_]/g, '').replace(/-/g, '+').replace(/_/g, '/');
30
+ const padded = clean + '='.repeat((4 - (clean.length % 4)) % 4);
31
+ const binary = atob(clean.length % 4 === 1 ? padded.slice(0, -3) : padded);
32
+ const out = new Uint8Array(binary.length);
33
+ for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
34
+ return out;
35
+ }
36
+
37
+ function bytesToBinaryString(bytes: Uint8Array): string {
38
+ let out = '';
39
+ for (let i = 0; i < bytes.length; i += 0x8000) out += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
40
+ return out;
41
+ }
42
+
43
+ export function encode(text: string, encoding?: unknown): Uint8Array {
44
+ switch (normalizeEncoding(encoding)) {
45
+ case 'utf8': return utf8Encoder.encode(text);
46
+ case 'hex': {
47
+ const length = Math.floor(text.length / 2);
48
+ const out = new Uint8Array(length);
49
+ for (let i = 0; i < length; i++) {
50
+ const byte = parseInt(text.substr(i * 2, 2), 16);
51
+ if (Number.isNaN(byte)) return out.subarray(0, i);
52
+ out[i] = byte;
53
+ }
54
+ return out;
55
+ }
56
+ case 'base64': case 'base64url': return base64ToBytes(text);
57
+ case 'utf16le': {
58
+ const out = new Uint8Array(text.length * 2);
59
+ for (let i = 0; i < text.length; i++) {
60
+ const code = text.charCodeAt(i);
61
+ out[i * 2] = code & 0xff;
62
+ out[i * 2 + 1] = code >> 8;
63
+ }
64
+ return out;
65
+ }
66
+ default: { // latin1, ascii
67
+ const out = new Uint8Array(text.length);
68
+ for (let i = 0; i < text.length; i++) out[i] = text.charCodeAt(i) & 0xff;
69
+ return out;
70
+ }
71
+ }
72
+ }
73
+
74
+ export function decode(bytes: Uint8Array, encoding?: unknown): string {
75
+ switch (normalizeEncoding(encoding)) {
76
+ case 'utf8': return utf8Decoder.decode(bytes);
77
+ case 'hex': return Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
78
+ case 'base64': return btoa(bytesToBinaryString(bytes));
79
+ case 'base64url': return btoa(bytesToBinaryString(bytes)).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
80
+ case 'ascii': return bytesToBinaryString(bytes.map((b) => b & 0x7f));
81
+ case 'utf16le': {
82
+ let out = '';
83
+ for (let i = 0; i + 1 < bytes.length; i += 2) out += String.fromCharCode(bytes[i]! | (bytes[i + 1]! << 8));
84
+ return out;
85
+ }
86
+ default: return bytesToBinaryString(bytes);
87
+ }
88
+ }
89
+
90
+ type BufferSource = string | ArrayBuffer | ArrayLike<number> | Uint8Array | { type: 'Buffer'; data: number[] };
91
+
92
+ // Typed loosely: Node's `Buffer.from` overloads are not assignable to Uint8Array.from's.
93
+ const Uint8ArrayBase = Uint8Array as unknown as new (...args: any[]) => Uint8Array<ArrayBuffer>;
94
+
95
+ export class Buffer extends Uint8ArrayBase {
96
+ static poolSize = 8192;
97
+
98
+ constructor(arg: number | BufferSource, encodingOrOffset?: unknown, length?: number) {
99
+ if (typeof arg === 'string') super(encode(arg, encodingOrOffset));
100
+ else if (arg instanceof ArrayBuffer || (typeof SharedArrayBuffer !== 'undefined' && arg instanceof SharedArrayBuffer)) super(arg as ArrayBuffer, encodingOrOffset as number | undefined, length);
101
+ else super(arg as ArrayLike<number>);
102
+ }
103
+
104
+ static from(value: BufferSource, encodingOrOffset?: unknown, length?: number): Buffer {
105
+ if (typeof value === 'string') return new Buffer(encode(value, encodingOrOffset));
106
+ if (value instanceof ArrayBuffer) return new Buffer(value, encodingOrOffset, length);
107
+ if (ArrayBuffer.isView(value)) return new Buffer(new Uint8Array(value.buffer, value.byteOffset, value.byteLength)); // a copy
108
+ if (value && (value as { type?: string }).type === 'Buffer' && Array.isArray((value as { data?: unknown }).data)) return new Buffer((value as { data: number[] }).data);
109
+ if (value && typeof value === 'object' && typeof (value as { length?: unknown }).length === 'number') return new Buffer(value as ArrayLike<number>);
110
+ throw new TypeError('The first argument must be of type string, Buffer, ArrayBuffer, Array, or Array-like Object.');
111
+ }
112
+
113
+ static alloc(size: number, fill?: string | number | Uint8Array, encoding?: BufferEncoding): Buffer {
114
+ const buf = new Buffer(size);
115
+ if (fill !== undefined && fill !== 0) buf.fill(fill, 0, size, encoding);
116
+ return buf;
117
+ }
118
+
119
+ static allocUnsafe(size: number): Buffer {
120
+ return new Buffer(size);
121
+ }
122
+
123
+ static allocUnsafeSlow(size: number): Buffer {
124
+ return new Buffer(size);
125
+ }
126
+
127
+ static isBuffer(value: unknown): value is Buffer {
128
+ return value instanceof Buffer;
129
+ }
130
+
131
+ static isEncoding(encoding: unknown): boolean {
132
+ try {
133
+ normalizeEncoding(encoding);
134
+ return typeof encoding === 'string';
135
+ } catch {
136
+ return false;
137
+ }
138
+ }
139
+
140
+ static byteLength(value: string | ArrayBuffer | ArrayBufferView, encoding?: BufferEncoding): number {
141
+ if (typeof value === 'string') return encode(value, encoding).length;
142
+ return value.byteLength;
143
+ }
144
+
145
+ static concat(list: readonly Uint8Array[], totalLength?: number): Buffer {
146
+ const total = totalLength ?? list.reduce((n, b) => n + b.length, 0);
147
+ const out = Buffer.alloc(total);
148
+ let at = 0;
149
+ for (const item of list) {
150
+ if (at >= total) break;
151
+ out.set(item.subarray(0, total - at), at);
152
+ at += item.length;
153
+ }
154
+ return out;
155
+ }
156
+
157
+ static compare(a: Uint8Array, b: Uint8Array): number {
158
+ const length = Math.min(a.length, b.length);
159
+ for (let i = 0; i < length; i++) if (a[i] !== b[i]) return a[i]! < b[i]! ? -1 : 1;
160
+ return Math.sign(a.length - b.length);
161
+ }
162
+
163
+ get parent(): ArrayBufferLike {
164
+ return this.buffer;
165
+ }
166
+
167
+ override toString(encoding?: BufferEncoding, start = 0, end = this.length): string {
168
+ return decode(this.subarray(Math.max(0, start), Math.min(this.length, end)), encoding);
169
+ }
170
+
171
+ toLocaleString(): string {
172
+ return this.toString();
173
+ }
174
+
175
+ toJSON(): { type: 'Buffer'; data: number[] } {
176
+ return { type: 'Buffer', data: Array.from(this) };
177
+ }
178
+
179
+ equals(other: Uint8Array): boolean {
180
+ return Buffer.compare(this, other) === 0;
181
+ }
182
+
183
+ compare(target: Uint8Array, targetStart = 0, targetEnd = target.length, sourceStart = 0, sourceEnd = this.length): number {
184
+ return Buffer.compare(this.subarray(sourceStart, sourceEnd), target.subarray(targetStart, targetEnd));
185
+ }
186
+
187
+ copy(target: Uint8Array, targetStart = 0, sourceStart = 0, sourceEnd = this.length): number {
188
+ const chunk = this.subarray(sourceStart, Math.min(sourceEnd, sourceStart + (target.length - targetStart)));
189
+ target.set(chunk, targetStart);
190
+ return chunk.length;
191
+ }
192
+
193
+ /** Node's slice is a VIEW, unlike TypedArray#slice. */
194
+ override slice(start?: number, end?: number): Buffer {
195
+ return this.subarray(start, end) as Buffer;
196
+ }
197
+
198
+ override subarray(start?: number, end?: number): Buffer {
199
+ const view = super.subarray(start, end);
200
+ return new Buffer(view.buffer as ArrayBuffer, view.byteOffset, view.length);
201
+ }
202
+
203
+ write(text: string, offset?: number | string, length?: number | string, encoding?: string): number {
204
+ if (typeof offset === 'string') [encoding, offset, length] = [offset, 0, undefined];
205
+ else if (typeof length === 'string') [encoding, length] = [length, undefined];
206
+ const at = offset ?? 0;
207
+ const bytes = encode(text, encoding).subarray(0, Math.min((length as number | undefined) ?? Infinity, this.length - at));
208
+ this.set(bytes, at);
209
+ return bytes.length;
210
+ }
211
+
212
+ override fill(value: string | number | Uint8Array, start: number | string = 0, end: number = this.length, encoding?: BufferEncoding): this {
213
+ if (typeof start === 'string') [encoding, start] = [start as BufferEncoding, 0];
214
+ if (typeof value === 'number') return super.fill(value & 255, start, end);
215
+ const pattern = typeof value === 'string' ? encode(value, encoding) : value;
216
+ if (!pattern.length) return super.fill(0, start, end);
217
+ for (let i = start, j = 0; i < end; i++, j = (j + 1) % pattern.length) this[i] = pattern[j]!;
218
+ return this;
219
+ }
220
+
221
+ override indexOf(value: string | number | Uint8Array, byteOffset = 0, encoding?: BufferEncoding): number {
222
+ if (typeof value === 'number') return super.indexOf(value & 255, byteOffset);
223
+ const needle = typeof value === 'string' ? encode(value, encoding) : value;
224
+ const from = byteOffset < 0 ? Math.max(0, this.length + byteOffset) : byteOffset;
225
+ if (!needle.length) return Math.min(from, this.length);
226
+ outer: for (let i = from; i <= this.length - needle.length; i++) {
227
+ for (let j = 0; j < needle.length; j++) if (this[i + j] !== needle[j]) continue outer;
228
+ return i;
229
+ }
230
+ return -1;
231
+ }
232
+
233
+ override lastIndexOf(value: string | number | Uint8Array, byteOffset = this.length, encoding?: BufferEncoding): number {
234
+ if (typeof value === 'number') return super.lastIndexOf(value & 255, byteOffset);
235
+ const needle = typeof value === 'string' ? encode(value, encoding) : value;
236
+ outer: for (let i = Math.min(byteOffset, this.length - needle.length); i >= 0; i--) {
237
+ for (let j = 0; j < needle.length; j++) if (this[i + j] !== needle[j]) continue outer;
238
+ return i;
239
+ }
240
+ return -1;
241
+ }
242
+
243
+ override includes(value: string | number | Uint8Array, byteOffset = 0, encoding?: BufferEncoding): boolean {
244
+ return this.indexOf(value, byteOffset, encoding) !== -1;
245
+ }
246
+
247
+ private view(): DataView {
248
+ return new DataView(this.buffer, this.byteOffset, this.byteLength);
249
+ }
250
+
251
+ readUInt8(o = 0) { return this.view().getUint8(o); }
252
+ readUInt16LE(o = 0) { return this.view().getUint16(o, true); }
253
+ readUInt16BE(o = 0) { return this.view().getUint16(o); }
254
+ readUInt32LE(o = 0) { return this.view().getUint32(o, true); }
255
+ readUInt32BE(o = 0) { return this.view().getUint32(o); }
256
+ readInt8(o = 0) { return this.view().getInt8(o); }
257
+ readInt16LE(o = 0) { return this.view().getInt16(o, true); }
258
+ readInt16BE(o = 0) { return this.view().getInt16(o); }
259
+ readInt32LE(o = 0) { return this.view().getInt32(o, true); }
260
+ readInt32BE(o = 0) { return this.view().getInt32(o); }
261
+ readFloatLE(o = 0) { return this.view().getFloat32(o, true); }
262
+ readFloatBE(o = 0) { return this.view().getFloat32(o); }
263
+ readDoubleLE(o = 0) { return this.view().getFloat64(o, true); }
264
+ readDoubleBE(o = 0) { return this.view().getFloat64(o); }
265
+ readBigUInt64LE(o = 0) { return this.view().getBigUint64(o, true); }
266
+ readBigUInt64BE(o = 0) { return this.view().getBigUint64(o); }
267
+ readBigInt64LE(o = 0) { return this.view().getBigInt64(o, true); }
268
+ readBigInt64BE(o = 0) { return this.view().getBigInt64(o); }
269
+ writeUInt8(v: number, o = 0) { this.view().setUint8(o, v); return o + 1; }
270
+ writeUInt16LE(v: number, o = 0) { this.view().setUint16(o, v, true); return o + 2; }
271
+ writeUInt16BE(v: number, o = 0) { this.view().setUint16(o, v); return o + 2; }
272
+ writeUInt32LE(v: number, o = 0) { this.view().setUint32(o, v, true); return o + 4; }
273
+ writeUInt32BE(v: number, o = 0) { this.view().setUint32(o, v); return o + 4; }
274
+ writeInt8(v: number, o = 0) { this.view().setInt8(o, v); return o + 1; }
275
+ writeInt16LE(v: number, o = 0) { this.view().setInt16(o, v, true); return o + 2; }
276
+ writeInt16BE(v: number, o = 0) { this.view().setInt16(o, v); return o + 2; }
277
+ writeInt32LE(v: number, o = 0) { this.view().setInt32(o, v, true); return o + 4; }
278
+ writeInt32BE(v: number, o = 0) { this.view().setInt32(o, v); return o + 4; }
279
+ writeFloatLE(v: number, o = 0) { this.view().setFloat32(o, v, true); return o + 4; }
280
+ writeFloatBE(v: number, o = 0) { this.view().setFloat32(o, v); return o + 4; }
281
+ writeDoubleLE(v: number, o = 0) { this.view().setFloat64(o, v, true); return o + 8; }
282
+ writeDoubleBE(v: number, o = 0) { this.view().setFloat64(o, v); return o + 8; }
283
+ writeBigUInt64LE(v: bigint, o = 0) { this.view().setBigUint64(o, v, true); return o + 8; }
284
+ writeBigUInt64BE(v: bigint, o = 0) { this.view().setBigUint64(o, v); return o + 8; }
285
+ }
286
+
287
+ // Lower-case aliases (readUint8 etc.) that Node also exposes.
288
+ for (const name of Object.getOwnPropertyNames(Buffer.prototype)) {
289
+ const alias = name.replace(/UInt/, 'Uint');
290
+ if (alias !== name) Object.defineProperty(Buffer.prototype, alias, Object.getOwnPropertyDescriptor(Buffer.prototype, name)!);
291
+ }
292
+
293
+ export function createBufferModule(): Record<string, unknown> {
294
+ return {
295
+ Buffer,
296
+ SlowBuffer: Buffer,
297
+ kMaxLength: 2 ** 31 - 1,
298
+ constants: { MAX_LENGTH: 2 ** 31 - 1, MAX_STRING_LENGTH: 2 ** 29 - 24 },
299
+ INSPECT_MAX_BYTES: 50,
300
+ Blob: globalThis.Blob,
301
+ atob: globalThis.atob,
302
+ btoa: globalThis.btoa,
303
+ };
304
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * The builtin module table for one runtime. Modules are built lazily on first
3
+ * `require` (most programs touch a handful) and are per-process, because `fs`,
4
+ * `path` and `process` close over that process's cwd, IO and event loop.
5
+ */
6
+ import type { VirtualFileSystem } from '../vfs.js';
7
+ import type { ProgramIO, System } from '../system/types.js';
8
+ import type { EventLoop } from './loop.js';
9
+ import type { NodeProcess } from './process.js';
10
+ import { createEventsModule } from './events.js';
11
+ import { createBufferModule } from './buffer.js';
12
+ import { createPathModule } from './path.js';
13
+ import { createUtilModule, types as utilTypes } from './util.js';
14
+ import { createStreamModule } from './stream/index.js';
15
+ import { createFsModule } from './fs/index.js';
16
+ import { constants as fsConstants } from './fs/stats.js';
17
+ import { createCryptoModule } from './crypto.js';
18
+ import { createQuerystringModule, createUrlModule } from './urlqs.js';
19
+ import { createAssertModule } from './assert.js';
20
+ import { createZlibModule } from './zlib.js';
21
+ import { createHttpModule, createNetModule, createFetch } from './http/index.js';
22
+ import { createChildProcessModule } from './childProcess.js';
23
+ import { createReadlineModule } from './readline.js';
24
+ import { createAsyncHooksModule, createDiagnosticsChannelModule, createOsModule, createStringDecoderModule, createStubModules, createTimersModule, createTtyModule, createVmModule } from './misc.js';
25
+
26
+
27
+ export interface BuiltinDeps {
28
+ fs: VirtualFileSystem;
29
+ process: NodeProcess;
30
+ loop: EventLoop;
31
+ system: System;
32
+ io: ProgramIO;
33
+ console: Console;
34
+ }
35
+
36
+ type Factory = (get: (name: string) => any) => unknown;
37
+
38
+ export function createBuiltins(deps: BuiltinDeps) {
39
+ const { process: proc, loop, system } = deps;
40
+ const env = () => proc.env as Record<string, string | undefined>;
41
+ const stubs = createStubModules();
42
+ const clientDeps = { system, loop };
43
+
44
+ const factories: Record<string, Factory> = {
45
+ assert: () => createAssertModule(false),
46
+ 'assert/strict': () => createAssertModule(true),
47
+ async_hooks: () => createAsyncHooksModule(),
48
+ buffer: () => createBufferModule(),
49
+ child_process: () =>
50
+ createChildProcessModule({
51
+ system,
52
+ loop,
53
+ cwd: () => proc.cwd(),
54
+ env,
55
+ stdout: (c) => proc.stdout.write(c),
56
+ stderr: (c) => proc.stderr.write(c),
57
+ }),
58
+ console: () => Object.assign(Object.create(deps.console), { Console: function Console() { return deps.console; } }),
59
+ constants: (get) => ({ ...fsConstants, ...(get('os').constants.signals as object) }),
60
+ crypto: () => createCryptoModule(),
61
+ diagnostics_channel: () => createDiagnosticsChannelModule(),
62
+ 'dns/promises': (get) => get('dns').promises,
63
+ events: () => createEventsModule(),
64
+ fs: () => createFsModule({ vfs: deps.fs, cwd: () => proc.cwd(), stdout: deps.io.stdout, stderr: deps.io.stderr, hold: () => loop.hold() }),
65
+ 'fs/promises': (get) => get('fs').promises,
66
+ http: () => createHttpModule(clientDeps, 'http:'),
67
+ https: () => createHttpModule(clientDeps, 'https:'),
68
+ net: () => createNetModule(clientDeps),
69
+ os: () => createOsModule(env),
70
+ path: () => createPathModule(() => proc.cwd()),
71
+ 'path/posix': (get) => get('path'),
72
+ 'path/win32': (get) => get('path'),
73
+ process: () => proc,
74
+ querystring: () => createQuerystringModule(),
75
+ readline: () => createReadlineModule(),
76
+ 'readline/promises': (get) => get('readline').promises,
77
+ stream: () => createStreamModule(),
78
+ 'stream/promises': (get) => get('stream').promises,
79
+ 'stream/web': () => ({ ReadableStream, WritableStream, TransformStream, TextEncoderStream, TextDecoderStream, ByteLengthQueuingStrategy, CountQueuingStrategy }),
80
+ 'stream/consumers': () => ({
81
+ text: async (stream: AsyncIterable<unknown>) => {
82
+ let out = '';
83
+ for await (const chunk of stream) out += typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk as Uint8Array);
84
+ return out;
85
+ },
86
+ json: async (stream: AsyncIterable<unknown>) => {
87
+ let out = '';
88
+ for await (const chunk of stream) out += typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk as Uint8Array);
89
+ return JSON.parse(out);
90
+ },
91
+ }),
92
+ string_decoder: () => createStringDecoderModule(),
93
+ sys: (get) => get('util'),
94
+ timers: () => createTimersModule(loop),
95
+ 'timers/promises': (get) => get('timers').promises,
96
+ tty: () => createTtyModule(!!deps.io.terminal),
97
+ url: (get) => createUrlModule(get('querystring')),
98
+ util: () => createUtilModule(env, (message) => proc.stderr.write(message + '\n')),
99
+ 'util/types': () => utilTypes,
100
+ vm: () => createVmModule(),
101
+ zlib: () => createZlibModule(),
102
+ };
103
+ for (const [name, mod] of Object.entries(stubs)) factories[name] ??= () => mod;
104
+
105
+ const cache = new Map<string, unknown>();
106
+ const get = (name: string): any => {
107
+ if (cache.has(name)) return cache.get(name);
108
+ const factory = factories[name];
109
+ if (!factory) throw Object.assign(new Error(`No such built-in module: ${name}`), { code: 'ERR_UNKNOWN_BUILTIN_MODULE' });
110
+ const mod = factory(get);
111
+ cache.set(name, mod);
112
+ return mod;
113
+ };
114
+
115
+ return {
116
+ names: [...Object.keys(factories), 'module'].sort(),
117
+ isBuiltin: (name: string) => name === 'module' || name in factories,
118
+ get,
119
+ fetch: createFetch(clientDeps),
120
+ };
121
+ }
122
+
123
+ export type Builtins = ReturnType<typeof createBuiltins>;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Pre-ES2015 packages subclass Node's constructors the old way:
3
+ *
4
+ * function MyStream(opts) { Readable.call(this, opts); }
5
+ * util.inherits(MyStream, Readable);
6
+ *
7
+ * Calling an ES class without `new` throws, so the shims we expose are plain
8
+ * functions wrapping the class: `new`/`extends` construct the class, a bare
9
+ * call runs its `init` on the caller's `this`. The prototype is shared, so
10
+ * `instanceof` holds either way.
11
+ */
12
+ export function callable<C extends abstract new (...args: any[]) => object>(Base: C, init: (self: any, ...args: any[]) => void): C {
13
+ const Wrapped = function (this: unknown, ...args: unknown[]) {
14
+ if (!new.target) {
15
+ init(this, ...args);
16
+ return this;
17
+ }
18
+ return Reflect.construct(Base, args, new.target);
19
+ } as unknown as C;
20
+ Object.defineProperty(Wrapped, 'name', { value: Base.name });
21
+ (Wrapped as unknown as { prototype: object }).prototype = Base.prototype;
22
+ Object.setPrototypeOf(Wrapped, Base); // statics
23
+ Object.defineProperty(Base.prototype, 'constructor', { value: Wrapped, writable: true, configurable: true, enumerable: false });
24
+ return Wrapped;
25
+ }