@volter/tabnode 0.2.14-volter.88

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 (429) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +78 -0
  3. package/THIRD-PARTY-NOTICES.md +12 -0
  4. package/dist/__sw__.js +526 -0
  5. package/dist/assets/runtime-worker-4MKaHFVb.js +75221 -0
  6. package/dist/assets/runtime-worker-4MKaHFVb.js.map +1 -0
  7. package/dist/code-transforms.d.ts +21 -0
  8. package/dist/code-transforms.d.ts.map +1 -0
  9. package/dist/config/cdn.d.ts +12 -0
  10. package/dist/config/cdn.d.ts.map +1 -0
  11. package/dist/create-runtime.d.ts +22 -0
  12. package/dist/create-runtime.d.ts.map +1 -0
  13. package/dist/host-globals.d.ts +62 -0
  14. package/dist/host-globals.d.ts.map +1 -0
  15. package/dist/index.cjs +36021 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/index.d.ts +127 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.mjs +36020 -0
  20. package/dist/index.mjs.map +1 -0
  21. package/dist/node-internals.d.ts +68 -0
  22. package/dist/node-internals.d.ts.map +1 -0
  23. package/dist/node-lib/binding/blob.d.ts +12 -0
  24. package/dist/node-lib/binding/blob.d.ts.map +1 -0
  25. package/dist/node-lib/binding/buffer.d.ts +144 -0
  26. package/dist/node-lib/binding/buffer.d.ts.map +1 -0
  27. package/dist/node-lib/binding/cares_wrap.d.ts +14 -0
  28. package/dist/node-lib/binding/cares_wrap.d.ts.map +1 -0
  29. package/dist/node-lib/binding/fds.d.ts +30 -0
  30. package/dist/node-lib/binding/fds.d.ts.map +1 -0
  31. package/dist/node-lib/binding/fs.d.ts +157 -0
  32. package/dist/node-lib/binding/fs.d.ts.map +1 -0
  33. package/dist/node-lib/binding/handles.d.ts +81 -0
  34. package/dist/node-lib/binding/handles.d.ts.map +1 -0
  35. package/dist/node-lib/binding/http_parser.d.ts +122 -0
  36. package/dist/node-lib/binding/http_parser.d.ts.map +1 -0
  37. package/dist/node-lib/binding/index.d.ts +3 -0
  38. package/dist/node-lib/binding/index.d.ts.map +1 -0
  39. package/dist/node-lib/binding/llhttp-wasm.d.ts +22 -0
  40. package/dist/node-lib/binding/llhttp-wasm.d.ts.map +1 -0
  41. package/dist/node-lib/binding/misc.d.ts +123 -0
  42. package/dist/node-lib/binding/misc.d.ts.map +1 -0
  43. package/dist/node-lib/binding/pipe_wrap.d.ts +84 -0
  44. package/dist/node-lib/binding/pipe_wrap.d.ts.map +1 -0
  45. package/dist/node-lib/binding/process_wrap.d.ts +173 -0
  46. package/dist/node-lib/binding/process_wrap.d.ts.map +1 -0
  47. package/dist/node-lib/binding/spawn_sync.d.ts +30 -0
  48. package/dist/node-lib/binding/spawn_sync.d.ts.map +1 -0
  49. package/dist/node-lib/binding/stream_wrap.d.ts +191 -0
  50. package/dist/node-lib/binding/stream_wrap.d.ts.map +1 -0
  51. package/dist/node-lib/binding/stubs.d.ts +23 -0
  52. package/dist/node-lib/binding/stubs.d.ts.map +1 -0
  53. package/dist/node-lib/binding/tcp_wrap.d.ts +98 -0
  54. package/dist/node-lib/binding/tcp_wrap.d.ts.map +1 -0
  55. package/dist/node-lib/binding/tty_wrap.d.ts +36 -0
  56. package/dist/node-lib/binding/tty_wrap.d.ts.map +1 -0
  57. package/dist/node-lib/binding/util.d.ts +126 -0
  58. package/dist/node-lib/binding/util.d.ts.map +1 -0
  59. package/dist/node-lib/binding/uv.d.ts +32 -0
  60. package/dist/node-lib/binding/uv.d.ts.map +1 -0
  61. package/dist/node-lib/binding/zlib-pako.d.ts +22 -0
  62. package/dist/node-lib/binding/zlib-pako.d.ts.map +1 -0
  63. package/dist/node-lib/binding/zlib.d.ts +38 -0
  64. package/dist/node-lib/binding/zlib.d.ts.map +1 -0
  65. package/dist/node-lib/buffer-module.d.ts +51 -0
  66. package/dist/node-lib/buffer-module.d.ts.map +1 -0
  67. package/dist/node-lib/child-process-module.d.ts +26 -0
  68. package/dist/node-lib/child-process-module.d.ts.map +1 -0
  69. package/dist/node-lib/events-module.d.ts +58 -0
  70. package/dist/node-lib/events-module.d.ts.map +1 -0
  71. package/dist/node-lib/fs-module.d.ts +5 -0
  72. package/dist/node-lib/fs-module.d.ts.map +1 -0
  73. package/dist/node-lib/http-bridge.d.ts +43 -0
  74. package/dist/node-lib/http-bridge.d.ts.map +1 -0
  75. package/dist/node-lib/http-module.d.ts +35 -0
  76. package/dist/node-lib/http-module.d.ts.map +1 -0
  77. package/dist/node-lib/internals/addresses.d.ts +40 -0
  78. package/dist/node-lib/internals/addresses.d.ts.map +1 -0
  79. package/dist/node-lib/internals/buffer-and-streams.d.ts +96 -0
  80. package/dist/node-lib/internals/buffer-and-streams.d.ts.map +1 -0
  81. package/dist/node-lib/internals/child-process.d.ts +27 -0
  82. package/dist/node-lib/internals/child-process.d.ts.map +1 -0
  83. package/dist/node-lib/internals/events-util.d.ts +83 -0
  84. package/dist/node-lib/internals/events-util.d.ts.map +1 -0
  85. package/dist/node-lib/internals/index.d.ts +2 -0
  86. package/dist/node-lib/internals/index.d.ts.map +1 -0
  87. package/dist/node-lib/internals/modules.d.ts +67 -0
  88. package/dist/node-lib/internals/modules.d.ts.map +1 -0
  89. package/dist/node-lib/internals/readline-access.d.ts +2 -0
  90. package/dist/node-lib/internals/readline-access.d.ts.map +1 -0
  91. package/dist/node-lib/internals/runtime.d.ts +150 -0
  92. package/dist/node-lib/internals/runtime.d.ts.map +1 -0
  93. package/dist/node-lib/internals/util.d.ts +33 -0
  94. package/dist/node-lib/internals/util.d.ts.map +1 -0
  95. package/dist/node-lib/lazy.d.ts +31 -0
  96. package/dist/node-lib/lazy.d.ts.map +1 -0
  97. package/dist/node-lib/load.d.ts +27 -0
  98. package/dist/node-lib/load.d.ts.map +1 -0
  99. package/dist/node-lib/module-hooks.d.ts +89 -0
  100. package/dist/node-lib/module-hooks.d.ts.map +1 -0
  101. package/dist/node-lib/net-module.d.ts +181 -0
  102. package/dist/node-lib/net-module.d.ts.map +1 -0
  103. package/dist/node-lib/node-versions.d.ts +27 -0
  104. package/dist/node-lib/node-versions.d.ts.map +1 -0
  105. package/dist/node-lib/public-modules.d.ts +2 -0
  106. package/dist/node-lib/public-modules.d.ts.map +1 -0
  107. package/dist/node-lib/require-hook.d.ts +15 -0
  108. package/dist/node-lib/require-hook.d.ts.map +1 -0
  109. package/dist/node-lib/small-modules.d.ts +16 -0
  110. package/dist/node-lib/small-modules.d.ts.map +1 -0
  111. package/dist/node-lib/sources.d.ts +4 -0
  112. package/dist/node-lib/sources.d.ts.map +1 -0
  113. package/dist/node-lib/stream-module.d.ts +77 -0
  114. package/dist/node-lib/stream-module.d.ts.map +1 -0
  115. package/dist/node-lib/timers.d.ts +19 -0
  116. package/dist/node-lib/timers.d.ts.map +1 -0
  117. package/dist/node-lib/util-module.d.ts +76 -0
  118. package/dist/node-lib/util-module.d.ts.map +1 -0
  119. package/dist/node-resolution.d.ts +50 -0
  120. package/dist/node-resolution.d.ts.map +1 -0
  121. package/dist/node-resolver.d.ts +7 -0
  122. package/dist/node-resolver.d.ts.map +1 -0
  123. package/dist/npm/index.d.ts +73 -0
  124. package/dist/npm/index.d.ts.map +1 -0
  125. package/dist/npm/registry.d.ts +111 -0
  126. package/dist/npm/registry.d.ts.map +1 -0
  127. package/dist/npm/resolver.d.ts +79 -0
  128. package/dist/npm/resolver.d.ts.map +1 -0
  129. package/dist/npm/tarball.d.ts +28 -0
  130. package/dist/npm/tarball.d.ts.map +1 -0
  131. package/dist/process-tokens.d.ts +77 -0
  132. package/dist/process-tokens.d.ts.map +1 -0
  133. package/dist/punycode-source.d.ts +3 -0
  134. package/dist/punycode-source.d.ts.map +1 -0
  135. package/dist/runtime-interface.d.ts +74 -0
  136. package/dist/runtime-interface.d.ts.map +1 -0
  137. package/dist/runtime.d.ts +144 -0
  138. package/dist/runtime.d.ts.map +1 -0
  139. package/dist/server-bridge.d.ts +147 -0
  140. package/dist/server-bridge.d.ts.map +1 -0
  141. package/dist/shims/async_hooks.d.ts +50 -0
  142. package/dist/shims/async_hooks.d.ts.map +1 -0
  143. package/dist/shims/child_process.d.ts +104 -0
  144. package/dist/shims/child_process.d.ts.map +1 -0
  145. package/dist/shims/cluster.d.ts +52 -0
  146. package/dist/shims/cluster.d.ts.map +1 -0
  147. package/dist/shims/command-line.d.ts +43 -0
  148. package/dist/shims/command-line.d.ts.map +1 -0
  149. package/dist/shims/constants.d.ts +222 -0
  150. package/dist/shims/constants.d.ts.map +1 -0
  151. package/dist/shims/crypto-constants.d.ts +12 -0
  152. package/dist/shims/crypto-constants.d.ts.map +1 -0
  153. package/dist/shims/crypto.d.ts +144 -0
  154. package/dist/shims/crypto.d.ts.map +1 -0
  155. package/dist/shims/dgram.d.ts +34 -0
  156. package/dist/shims/dgram.d.ts.map +1 -0
  157. package/dist/shims/dns.d.ts +91 -0
  158. package/dist/shims/dns.d.ts.map +1 -0
  159. package/dist/shims/domain.d.ts +25 -0
  160. package/dist/shims/domain.d.ts.map +1 -0
  161. package/dist/shims/esbuild.d.ts +205 -0
  162. package/dist/shims/esbuild.d.ts.map +1 -0
  163. package/dist/shims/fs.d.ts +25 -0
  164. package/dist/shims/fs.d.ts.map +1 -0
  165. package/dist/shims/http2.d.ts +81 -0
  166. package/dist/shims/http2.d.ts.map +1 -0
  167. package/dist/shims/inspector.d.ts +25 -0
  168. package/dist/shims/inspector.d.ts.map +1 -0
  169. package/dist/shims/module.d.ts +22 -0
  170. package/dist/shims/module.d.ts.map +1 -0
  171. package/dist/shims/os.d.ts +159 -0
  172. package/dist/shims/os.d.ts.map +1 -0
  173. package/dist/shims/path.d.ts +52 -0
  174. package/dist/shims/path.d.ts.map +1 -0
  175. package/dist/shims/perf_hooks.d.ts +50 -0
  176. package/dist/shims/perf_hooks.d.ts.map +1 -0
  177. package/dist/shims/process.d.ts +226 -0
  178. package/dist/shims/process.d.ts.map +1 -0
  179. package/dist/shims/rollup.d.ts +71 -0
  180. package/dist/shims/rollup.d.ts.map +1 -0
  181. package/dist/shims/string_decoder.d.ts +41 -0
  182. package/dist/shims/string_decoder.d.ts.map +1 -0
  183. package/dist/shims/sync-child.d.ts +64 -0
  184. package/dist/shims/sync-child.d.ts.map +1 -0
  185. package/dist/shims/tls.d.ts +53 -0
  186. package/dist/shims/tls.d.ts.map +1 -0
  187. package/dist/shims/url.d.ts +84 -0
  188. package/dist/shims/url.d.ts.map +1 -0
  189. package/dist/shims/v8.d.ts +73 -0
  190. package/dist/shims/v8.d.ts.map +1 -0
  191. package/dist/shims/vfs-adapter.d.ts +126 -0
  192. package/dist/shims/vfs-adapter.d.ts.map +1 -0
  193. package/dist/shims/vm.d.ts +52 -0
  194. package/dist/shims/vm.d.ts.map +1 -0
  195. package/dist/shims/wasi.d.ts +78 -0
  196. package/dist/shims/wasi.d.ts.map +1 -0
  197. package/dist/shims/worker_threads.d.ts +66 -0
  198. package/dist/shims/worker_threads.d.ts.map +1 -0
  199. package/dist/shims/zlib-constants.d.ts +66 -0
  200. package/dist/shims/zlib-constants.d.ts.map +1 -0
  201. package/dist/shims/zlib.d.ts +102 -0
  202. package/dist/shims/zlib.d.ts.map +1 -0
  203. package/dist/transform.d.ts +24 -0
  204. package/dist/transform.d.ts.map +1 -0
  205. package/dist/types/package-json.d.ts +18 -0
  206. package/dist/types/package-json.d.ts.map +1 -0
  207. package/dist/utils/binary-encoding.d.ts +13 -0
  208. package/dist/utils/binary-encoding.d.ts.map +1 -0
  209. package/dist/utils/glob.d.ts +19 -0
  210. package/dist/utils/glob.d.ts.map +1 -0
  211. package/dist/utils/hash.d.ts +6 -0
  212. package/dist/utils/hash.d.ts.map +1 -0
  213. package/dist/virtual-fs.d.ts +259 -0
  214. package/dist/virtual-fs.d.ts.map +1 -0
  215. package/dist/vite-plugin.cjs +50 -0
  216. package/dist/vite-plugin.cjs.map +1 -0
  217. package/dist/vite-plugin.d.ts +36 -0
  218. package/dist/vite-plugin.d.ts.map +1 -0
  219. package/dist/vite-plugin.mjs +31 -0
  220. package/dist/vite-plugin.mjs.map +1 -0
  221. package/dist/worker/runtime-worker.d.ts +8 -0
  222. package/dist/worker/runtime-worker.d.ts.map +1 -0
  223. package/dist/worker-runtime.d.ts +50 -0
  224. package/dist/worker-runtime.d.ts.map +1 -0
  225. package/package.json +88 -0
  226. package/src/code-transforms.ts +560 -0
  227. package/src/config/cdn.ts +13 -0
  228. package/src/create-runtime.ts +89 -0
  229. package/src/host-globals.ts +121 -0
  230. package/src/index.ts +235 -0
  231. package/src/node-internals.ts +283 -0
  232. package/src/node-lib/LICENSE +47 -0
  233. package/src/node-lib/_http_agent.js +547 -0
  234. package/src/node-lib/_http_client.js +996 -0
  235. package/src/node-lib/_http_common.js +269 -0
  236. package/src/node-lib/_http_incoming.js +453 -0
  237. package/src/node-lib/_http_outgoing.js +1262 -0
  238. package/src/node-lib/_http_server.js +1230 -0
  239. package/src/node-lib/assert/strict.js +3 -0
  240. package/src/node-lib/assert.js +844 -0
  241. package/src/node-lib/binding/blob.ts +35 -0
  242. package/src/node-lib/binding/buffer.ts +465 -0
  243. package/src/node-lib/binding/cares_wrap.ts +57 -0
  244. package/src/node-lib/binding/fds.ts +80 -0
  245. package/src/node-lib/binding/fs.ts +857 -0
  246. package/src/node-lib/binding/handles.ts +187 -0
  247. package/src/node-lib/binding/http_parser.ts +536 -0
  248. package/src/node-lib/binding/index.ts +77 -0
  249. package/src/node-lib/binding/llhttp-wasm.ts +670 -0
  250. package/src/node-lib/binding/misc.ts +252 -0
  251. package/src/node-lib/binding/pipe_wrap.ts +166 -0
  252. package/src/node-lib/binding/process_wrap.ts +371 -0
  253. package/src/node-lib/binding/spawn_sync.ts +141 -0
  254. package/src/node-lib/binding/stream_wrap.ts +413 -0
  255. package/src/node-lib/binding/stubs.ts +19 -0
  256. package/src/node-lib/binding/tcp_wrap.ts +254 -0
  257. package/src/node-lib/binding/tty_wrap.ts +56 -0
  258. package/src/node-lib/binding/util.ts +274 -0
  259. package/src/node-lib/binding/uv.ts +102 -0
  260. package/src/node-lib/binding/zlib-pako.ts +50 -0
  261. package/src/node-lib/binding/zlib.ts +259 -0
  262. package/src/node-lib/buffer-module.ts +70 -0
  263. package/src/node-lib/buffer.js +1373 -0
  264. package/src/node-lib/child-process-module.ts +58 -0
  265. package/src/node-lib/child_process.js +1046 -0
  266. package/src/node-lib/constants.js +41 -0
  267. package/src/node-lib/diagnostics_channel.js +438 -0
  268. package/src/node-lib/events-module.ts +80 -0
  269. package/src/node-lib/events.js +1223 -0
  270. package/src/node-lib/fs-module.ts +43 -0
  271. package/src/node-lib/fs.js +3377 -0
  272. package/src/node-lib/http-bridge.ts +299 -0
  273. package/src/node-lib/http-module.ts +53 -0
  274. package/src/node-lib/http.js +198 -0
  275. package/src/node-lib/https.js +429 -0
  276. package/src/node-lib/internal/assert/assertion_error.js +417 -0
  277. package/src/node-lib/internal/assert/calltracker.js +153 -0
  278. package/src/node-lib/internal/assert/myers_diff.js +177 -0
  279. package/src/node-lib/internal/assert/utils.js +278 -0
  280. package/src/node-lib/internal/buffer.js +1120 -0
  281. package/src/node-lib/internal/child_process/serialization.js +169 -0
  282. package/src/node-lib/internal/child_process.js +1135 -0
  283. package/src/node-lib/internal/constants.js +56 -0
  284. package/src/node-lib/internal/deps/minimatch/index.js +1628 -0
  285. package/src/node-lib/internal/errors.js +1912 -0
  286. package/src/node-lib/internal/events/abort_listener.js +54 -0
  287. package/src/node-lib/internal/events/symbols.js +11 -0
  288. package/src/node-lib/internal/fixed_queue.js +119 -0
  289. package/src/node-lib/internal/freelist.js +30 -0
  290. package/src/node-lib/internal/fs/cp/cp-sync.js +242 -0
  291. package/src/node-lib/internal/fs/cp/cp.js +382 -0
  292. package/src/node-lib/internal/fs/dir.js +369 -0
  293. package/src/node-lib/internal/fs/glob.js +763 -0
  294. package/src/node-lib/internal/fs/promises.js +1312 -0
  295. package/src/node-lib/internal/fs/read/context.js +129 -0
  296. package/src/node-lib/internal/fs/recursive_watch.js +275 -0
  297. package/src/node-lib/internal/fs/rimraf.js +311 -0
  298. package/src/node-lib/internal/fs/streams.js +571 -0
  299. package/src/node-lib/internal/fs/sync_write_stream.js +49 -0
  300. package/src/node-lib/internal/fs/utils.js +987 -0
  301. package/src/node-lib/internal/fs/watchers.js +418 -0
  302. package/src/node-lib/internal/http.js +62 -0
  303. package/src/node-lib/internal/mime.js +389 -0
  304. package/src/node-lib/internal/modules/customization_hooks.js +406 -0
  305. package/src/node-lib/internal/net.js +95 -0
  306. package/src/node-lib/internal/querystring.js +119 -0
  307. package/src/node-lib/internal/readline/callbacks.js +132 -0
  308. package/src/node-lib/internal/readline/emitKeypressEvents.js +99 -0
  309. package/src/node-lib/internal/readline/interface.js +1418 -0
  310. package/src/node-lib/internal/readline/promises.js +144 -0
  311. package/src/node-lib/internal/readline/utils.js +405 -0
  312. package/src/node-lib/internal/socket_list.js +108 -0
  313. package/src/node-lib/internal/stream_base_commons.js +280 -0
  314. package/src/node-lib/internal/streams/add-abort-signal.js +60 -0
  315. package/src/node-lib/internal/streams/compose.js +257 -0
  316. package/src/node-lib/internal/streams/destroy.js +361 -0
  317. package/src/node-lib/internal/streams/duplex.js +203 -0
  318. package/src/node-lib/internal/streams/duplexify.js +379 -0
  319. package/src/node-lib/internal/streams/duplexpair.js +62 -0
  320. package/src/node-lib/internal/streams/end-of-stream.js +331 -0
  321. package/src/node-lib/internal/streams/from.js +208 -0
  322. package/src/node-lib/internal/streams/lazy_transform.js +57 -0
  323. package/src/node-lib/internal/streams/legacy.js +125 -0
  324. package/src/node-lib/internal/streams/operators.js +436 -0
  325. package/src/node-lib/internal/streams/passthrough.js +47 -0
  326. package/src/node-lib/internal/streams/pipeline.js +465 -0
  327. package/src/node-lib/internal/streams/readable.js +1762 -0
  328. package/src/node-lib/internal/streams/state.js +51 -0
  329. package/src/node-lib/internal/streams/transform.js +204 -0
  330. package/src/node-lib/internal/streams/utils.js +363 -0
  331. package/src/node-lib/internal/streams/writable.js +1163 -0
  332. package/src/node-lib/internal/tty.js +260 -0
  333. package/src/node-lib/internal/util/colors.js +40 -0
  334. package/src/node-lib/internal/util/comparisons.js +1028 -0
  335. package/src/node-lib/internal/util/debuglog.js +524 -0
  336. package/src/node-lib/internal/util/inspect.js +2535 -0
  337. package/src/node-lib/internal/util/parse_args/parse_args.js +412 -0
  338. package/src/node-lib/internal/util/parse_args/utils.js +197 -0
  339. package/src/node-lib/internal/util.js +1003 -0
  340. package/src/node-lib/internal/validators.js +654 -0
  341. package/src/node-lib/internals/addresses.ts +159 -0
  342. package/src/node-lib/internals/buffer-and-streams.ts +224 -0
  343. package/src/node-lib/internals/child-process.ts +64 -0
  344. package/src/node-lib/internals/events-util.ts +105 -0
  345. package/src/node-lib/internals/index.ts +66 -0
  346. package/src/node-lib/internals/modules.ts +117 -0
  347. package/src/node-lib/internals/readline-access.ts +16 -0
  348. package/src/node-lib/internals/runtime.ts +277 -0
  349. package/src/node-lib/internals/util.ts +98 -0
  350. package/src/node-lib/lazy.ts +158 -0
  351. package/src/node-lib/load.ts +390 -0
  352. package/src/node-lib/module-hooks.ts +281 -0
  353. package/src/node-lib/net-module.ts +248 -0
  354. package/src/node-lib/net.js +2540 -0
  355. package/src/node-lib/node-versions.ts +34 -0
  356. package/src/node-lib/os.js +356 -0
  357. package/src/node-lib/path.js +1694 -0
  358. package/src/node-lib/primordials.js +743 -0
  359. package/src/node-lib/public-modules.ts +109 -0
  360. package/src/node-lib/punycode.js +455 -0
  361. package/src/node-lib/querystring.js +484 -0
  362. package/src/node-lib/readline/promises.js +73 -0
  363. package/src/node-lib/readline.js +523 -0
  364. package/src/node-lib/require-hook.ts +27 -0
  365. package/src/node-lib/small-modules.ts +35 -0
  366. package/src/node-lib/sources.ts +200 -0
  367. package/src/node-lib/stream/promises.js +44 -0
  368. package/src/node-lib/stream-module.ts +101 -0
  369. package/src/node-lib/stream.js +152 -0
  370. package/src/node-lib/timers.ts +33 -0
  371. package/src/node-lib/tty.js +168 -0
  372. package/src/node-lib/util-module.ts +104 -0
  373. package/src/node-lib/util.js +689 -0
  374. package/src/node-lib/wasi.js +179 -0
  375. package/src/node-lib/zlib.js +1036 -0
  376. package/src/node-resolution.ts +241 -0
  377. package/src/node-resolver.ts +33 -0
  378. package/src/npm/index.ts +425 -0
  379. package/src/npm/registry.ts +235 -0
  380. package/src/npm/resolver.ts +589 -0
  381. package/src/npm/tarball.ts +246 -0
  382. package/src/process-tokens.ts +156 -0
  383. package/src/punycode-source.ts +6 -0
  384. package/src/runtime-interface.ts +85 -0
  385. package/src/runtime.ts +3073 -0
  386. package/src/server-bridge.ts +971 -0
  387. package/src/shims/async_hooks.ts +181 -0
  388. package/src/shims/child_process.ts +1591 -0
  389. package/src/shims/cluster.ts +79 -0
  390. package/src/shims/command-line.ts +79 -0
  391. package/src/shims/constants.ts +68 -0
  392. package/src/shims/crypto-constants.ts +11 -0
  393. package/src/shims/crypto.ts +1061 -0
  394. package/src/shims/dgram.ts +47 -0
  395. package/src/shims/dns.ts +185 -0
  396. package/src/shims/domain.ts +58 -0
  397. package/src/shims/esbuild.ts +1638 -0
  398. package/src/shims/fs.ts +82 -0
  399. package/src/shims/http2.ts +96 -0
  400. package/src/shims/inspector.ts +30 -0
  401. package/src/shims/module.ts +86 -0
  402. package/src/shims/os.ts +195 -0
  403. package/src/shims/path.ts +246 -0
  404. package/src/shims/perf_hooks.ts +92 -0
  405. package/src/shims/process.ts +804 -0
  406. package/src/shims/rollup.ts +149 -0
  407. package/src/shims/string_decoder.ts +396 -0
  408. package/src/shims/sync-child.ts +469 -0
  409. package/src/shims/tls.ts +94 -0
  410. package/src/shims/url.ts +217 -0
  411. package/src/shims/v8.ts +113 -0
  412. package/src/shims/vfs-adapter.ts +408 -0
  413. package/src/shims/vm.ts +132 -0
  414. package/src/shims/wasi.ts +1440 -0
  415. package/src/shims/worker_threads.ts +114 -0
  416. package/src/shims/zlib-constants.ts +65 -0
  417. package/src/shims/zlib.ts +228 -0
  418. package/src/transform.ts +324 -0
  419. package/src/types/external.d.ts +55 -0
  420. package/src/types/package-json.ts +17 -0
  421. package/src/types/pako-zlib.d.ts +30 -0
  422. package/src/types/sha.js.d.ts +14 -0
  423. package/src/utils/binary-encoding.ts +43 -0
  424. package/src/utils/glob.ts +54 -0
  425. package/src/utils/hash.ts +12 -0
  426. package/src/virtual-fs.ts +1048 -0
  427. package/src/vite-plugin.ts +76 -0
  428. package/src/worker/runtime-worker.ts +128 -0
  429. package/src/worker-runtime.ts +145 -0
@@ -0,0 +1,425 @@
1
+ /**
2
+ * npm Package Manager
3
+ * Orchestrates package installation into the virtual file system
4
+ */
5
+
6
+ import { VirtualFS } from '../virtual-fs';
7
+ import { Registry, RegistryOptions } from './registry';
8
+ import {
9
+ resolveDependencies,
10
+ resolveFromPackageJson,
11
+ ResolvedPackage,
12
+ ResolvedTree,
13
+ ResolveOptions,
14
+ } from './resolver';
15
+ import { downloadAndExtract, extractTarball, __browserRuntimeInstallPool } from './tarball';
16
+ import * as path from '../shims/path';
17
+ import { initTransformer, transformPackage, isTransformerReady } from '../transform';
18
+
19
+ /**
20
+ * Whether the install rewrites the ES modules it unpacks into CommonJS.
21
+ *
22
+ * Off, whatever `transform` asked for: the pass was the largest share of the
23
+ * install's time, fourteen thousand files for a 700-package tree, and nothing
24
+ * needs it. The runtime's module loader transforms an ES module the first
25
+ * time it is required, with the result cached, and the browser-side module
26
+ * server bundles a package from its files with esbuild, which takes ES
27
+ * modules as they are. The install leaves the files as published.
28
+ *
29
+ * A live binding rather than a literal, so the transformer the loader itself
30
+ * uses stays part of the build instead of being folded away with the
31
+ * branches below.
32
+ */
33
+ let installTransformEnabled = false;
34
+
35
+ /** Turn the install's rewrite pass back on. Nothing in the engine does. */
36
+ export function setInstallTransformEnabled(enabled: boolean): void {
37
+ installTransformEnabled = enabled;
38
+ }
39
+
40
+ /**
41
+ * Normalize a package.json bin field into a consistent Record<string, string>.
42
+ * Handles both string form ("bin": "cli.js") and object form ("bin": {"cmd": "cli.js"}).
43
+ */
44
+ function normalizeBin(pkgName: string, bin?: Record<string, string> | string): Record<string, string> {
45
+ if (!bin) return {};
46
+ if (typeof bin === 'string') {
47
+ // String form uses the package name (without scope) as the command name
48
+ const cmdName = pkgName.includes('/') ? pkgName.split('/').pop()! : pkgName;
49
+ return { [cmdName]: bin };
50
+ }
51
+ return bin;
52
+ }
53
+
54
+ export interface InstallOptions {
55
+ registry?: string;
56
+ save?: boolean;
57
+ saveDev?: boolean;
58
+ includeDev?: boolean;
59
+ includeOptional?: boolean;
60
+ onProgress?: (message: string) => void;
61
+ /** Transform ESM packages to CJS after install (default: true) */
62
+ transform?: boolean;
63
+ }
64
+
65
+ export interface InstallResult {
66
+ installed: Map<string, ResolvedPackage>;
67
+ added: string[];
68
+ }
69
+
70
+ /**
71
+ * npm Package Manager for VirtualFS
72
+ */
73
+ export class PackageManager {
74
+ private vfs: VirtualFS;
75
+ private registry: Registry;
76
+ private cwd: string;
77
+
78
+ constructor(vfs: VirtualFS, options: { cwd?: string } & RegistryOptions = {}) {
79
+ this.vfs = vfs;
80
+ this.registry = new Registry(options);
81
+ this.cwd = options.cwd || '/';
82
+ }
83
+
84
+ /**
85
+ * Install a package and its dependencies
86
+ */
87
+ async install(
88
+ packageSpec: string,
89
+ options: InstallOptions = {}
90
+ ): Promise<InstallResult> {
91
+ const { onProgress } = options;
92
+
93
+ // Parse package spec (name@version)
94
+ const { name, version } = parsePackageSpec(packageSpec);
95
+
96
+ onProgress?.(`Resolving ${name}@${version || 'latest'}...`);
97
+
98
+ // Resolve dependencies
99
+ const resolved = await resolveDependencies(name, version || 'latest', {
100
+ registry: this.registry,
101
+ includeDev: options.includeDev,
102
+ includeOptional: options.includeOptional,
103
+ onProgress,
104
+ });
105
+
106
+ // Install all resolved packages
107
+ const added = await this.installResolved(resolved, options);
108
+
109
+ // Update package.json if save option is set
110
+ if (options.save || options.saveDev) {
111
+ const pkgToAdd = resolved.get(name);
112
+ if (pkgToAdd) {
113
+ await this.updatePackageJson(
114
+ name,
115
+ `^${pkgToAdd.version}`,
116
+ options.saveDev || false
117
+ );
118
+ }
119
+ }
120
+
121
+ onProgress?.(`Installed ${resolved.size} packages`);
122
+
123
+ return { installed: resolved, added };
124
+ }
125
+
126
+ /**
127
+ * Install all dependencies from package.json
128
+ */
129
+ async installFromPackageJson(options: InstallOptions = {}): Promise<InstallResult> {
130
+ const { onProgress } = options;
131
+
132
+ const pkgJsonPath = path.join(this.cwd, 'package.json');
133
+
134
+ if (!this.vfs.existsSync(pkgJsonPath)) {
135
+ throw new Error('No package.json found');
136
+ }
137
+
138
+ // A workspace install runs member by member, and the page hands the
139
+ // engine the manifest each member is to be installed from: a pnpm or npm
140
+ // workspace rewrites a member's dependencies (a `workspace:*` link is not
141
+ // a registry range) and the file on disk is not what should be resolved.
142
+ // Where the page recorded no manifest for this directory, the file is.
143
+ const pkgJson = (this.vfs as unknown as Record<symbol, Map<string, unknown> | undefined>)[Symbol.for('@volter/browser-node/workspace-install-manifests')]?.get(this.cwd)
144
+ ?? JSON.parse(this.vfs.readFileSync(pkgJsonPath, 'utf8'));
145
+
146
+ onProgress?.('Resolving dependencies...');
147
+
148
+ // Resolve all dependencies
149
+ const resolved = await resolveFromPackageJson(pkgJson, {
150
+ registry: this.registry,
151
+ includeDev: options.includeDev,
152
+ includeOptional: options.includeOptional,
153
+ onProgress,
154
+ });
155
+
156
+ // Install all resolved packages
157
+ const added = await this.installResolved(resolved, options);
158
+
159
+ onProgress?.(`Installed ${resolved.size} packages`);
160
+
161
+ return { installed: resolved, added };
162
+ }
163
+
164
+ /**
165
+ * Install resolved packages to node_modules
166
+ */
167
+ private async installResolved(
168
+ resolved: ResolvedTree,
169
+ options: InstallOptions
170
+ ): Promise<string[]> {
171
+ const { onProgress } = options;
172
+ const added: string[] = [];
173
+
174
+ // Ensure node_modules exists
175
+ const nodeModulesPath = path.join(this.cwd, 'node_modules');
176
+ this.vfs.mkdirSync(nodeModulesPath, { recursive: true });
177
+
178
+ // Filter packages that need to be installed
179
+ const toInstall: Array<{ name: string; pkg: ResolvedPackage; pkgPath: string }> = [];
180
+
181
+ for (const [name, pkg] of resolved) {
182
+ const pkgPath = path.join(nodeModulesPath, name);
183
+
184
+ // Skip if already installed with same version
185
+ const existingPkgJson = path.join(pkgPath, 'package.json');
186
+ if (this.vfs.existsSync(existingPkgJson)) {
187
+ try {
188
+ const existing = JSON.parse(
189
+ this.vfs.readFileSync(existingPkgJson, 'utf8')
190
+ );
191
+ if (existing.version === pkg.version) {
192
+ onProgress?.(`Skipping ${name}@${pkg.version} (already installed)`);
193
+ continue;
194
+ }
195
+ } catch {
196
+ // Continue with installation if package.json is invalid
197
+ }
198
+ }
199
+
200
+ toInstall.push({ name, pkg, pkgPath });
201
+ }
202
+
203
+ // The versions a dependent gets under its own node_modules, from the
204
+ // resolver's nested walk: React Router's build found semver 6 where
205
+ // normalize-package-data wanted 7 while the tree stayed flat.
206
+ for (const [nestedKey, pkg] of resolved.__nested instanceof Map ? resolved.__nested : []) {
207
+ toInstall.push({ name: pkg.name, pkg, pkgPath: path.join(nodeModulesPath, nestedKey) });
208
+ }
209
+
210
+ // The install rewrote every ES module it unpacked into CommonJS with
211
+ // esbuild, fourteen thousand files for a 700-package tree, and that pass
212
+ // was the largest share of the install's time. Nothing needs it: the
213
+ // runtime's module loader transforms an ES module the first time it is
214
+ // required, with the result cached, and the browser-side module server
215
+ // bundles a package from its files with esbuild, which takes ES modules
216
+ // as they are. The install leaves the files as published.
217
+ const shouldTransform = installTransformEnabled;
218
+ if (shouldTransform && !isTransformerReady()) {
219
+ onProgress?.('Initializing ESM transformer...');
220
+ await initTransformer();
221
+ }
222
+
223
+ // Six packages at a time, each batch waiting for its slowest, left the
224
+ // network idle behind one large tarball. A pool keeps every lane busy:
225
+ // as many downloads in flight as the page allows connections, and the
226
+ // extraction they feed serialized under the store's lock.
227
+ const CONCURRENCY = 16;
228
+ onProgress?.(`Installing ${toInstall.length} packages...`);
229
+
230
+ await __browserRuntimeInstallPool(toInstall, CONCURRENCY, async ({ name, pkg, pkgPath }) => {
231
+ onProgress?.(` Downloading ${name}@${pkg.version}...`);
232
+
233
+ // With a shared package store, a package the origin has seen is
234
+ // linked instead of downloaded: the hook the worker installs is
235
+ // asked first, and only a declined package is fetched.
236
+ const __installHook = (globalThis as Record<symbol, ((name: string, pkg: ResolvedPackage, pkgPath: string, vfs: VirtualFS) => Promise<boolean>) | undefined>)[Symbol.for("@volter/browser-runtime/package-install")];
237
+ if (!(__installHook && await __installHook(name, pkg, pkgPath, this.vfs))) {
238
+ await downloadAndExtract(pkg.tarballUrl, this.vfs, pkgPath, {
239
+ stripComponents: 1, // Strip "package/" prefix
240
+ });
241
+ }
242
+
243
+ // Transform ESM to CJS
244
+ if (shouldTransform) {
245
+ try {
246
+ const count = await transformPackage(this.vfs, pkgPath, onProgress);
247
+ if (count > 0) {
248
+ onProgress?.(` Transformed ${count} files in ${name}`);
249
+ }
250
+ } catch (transformError) {
251
+ onProgress?.(` Warning: Transform failed for ${name}: ${transformError}`);
252
+ }
253
+ }
254
+
255
+ // Create bin stubs in /node_modules/.bin/
256
+ try {
257
+ const pkgJsonPath = path.join(pkgPath, 'package.json');
258
+ if (this.vfs.existsSync(pkgJsonPath)) {
259
+ const pkgJson = JSON.parse(this.vfs.readFileSync(pkgJsonPath, 'utf8'));
260
+ const binEntries = normalizeBin(name, pkgJson.bin);
261
+ // A nested package's stubs belong to the node_modules it sits in.
262
+ const binDir = path.join(pkgPath.slice(0, pkgPath.lastIndexOf("/node_modules/") + "/node_modules".length), ".bin");
263
+ for (const [cmdName, entryPath] of Object.entries(binEntries)) {
264
+ this.vfs.mkdirSync(binDir, { recursive: true });
265
+ const targetPath = path.join(pkgPath, entryPath);
266
+ this.vfs.writeFileSync(
267
+ path.join(binDir, cmdName),
268
+ `node "${targetPath}" "$@"\n`
269
+ );
270
+ }
271
+ }
272
+ } catch {
273
+ // Non-critical — skip if bin stub creation fails
274
+ }
275
+
276
+ added.push(name);
277
+ });
278
+
279
+ // Create .package-lock.json for tracking
280
+ await this.writeLockfile(resolved);
281
+
282
+ return added;
283
+ }
284
+
285
+ /**
286
+ * Write lockfile with resolved versions
287
+ */
288
+ private async writeLockfile(
289
+ resolved: Map<string, ResolvedPackage>
290
+ ): Promise<void> {
291
+ const lockfile: Record<string, { version: string; resolved: string }> = {};
292
+
293
+ for (const [name, pkg] of resolved) {
294
+ lockfile[name] = {
295
+ version: pkg.version,
296
+ resolved: pkg.tarballUrl,
297
+ };
298
+ }
299
+
300
+ const lockfilePath = path.join(this.cwd, 'node_modules', '.package-lock.json');
301
+ this.vfs.writeFileSync(lockfilePath, JSON.stringify(lockfile, null, 2));
302
+ }
303
+
304
+ /**
305
+ * Update package.json with new dependency
306
+ */
307
+ private async updatePackageJson(
308
+ packageName: string,
309
+ version: string,
310
+ isDev: boolean
311
+ ): Promise<void> {
312
+ const pkgJsonPath = path.join(this.cwd, 'package.json');
313
+
314
+ let pkgJson: Record<string, unknown> = {};
315
+
316
+ if (this.vfs.existsSync(pkgJsonPath)) {
317
+ pkgJson = JSON.parse(this.vfs.readFileSync(pkgJsonPath, 'utf8'));
318
+ }
319
+
320
+ const field = isDev ? 'devDependencies' : 'dependencies';
321
+
322
+ if (!pkgJson[field]) {
323
+ pkgJson[field] = {};
324
+ }
325
+
326
+ (pkgJson[field] as Record<string, string>)[packageName] = version;
327
+
328
+ this.vfs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
329
+ }
330
+
331
+ /**
332
+ * List installed packages
333
+ */
334
+ list(): Record<string, string> {
335
+ const nodeModulesPath = path.join(this.cwd, 'node_modules');
336
+
337
+ if (!this.vfs.existsSync(nodeModulesPath)) {
338
+ return {};
339
+ }
340
+
341
+ const packages: Record<string, string> = {};
342
+ const entries = this.vfs.readdirSync(nodeModulesPath);
343
+
344
+ for (const entry of entries) {
345
+ // Skip hidden files and non-package entries
346
+ if (entry.startsWith('.')) continue;
347
+
348
+ // Handle scoped packages (@org/pkg)
349
+ if (entry.startsWith('@')) {
350
+ const scopePath = path.join(nodeModulesPath, entry);
351
+ const scopedPkgs = this.vfs.readdirSync(scopePath);
352
+
353
+ for (const scopedPkg of scopedPkgs) {
354
+ const pkgJsonPath = path.join(scopePath, scopedPkg, 'package.json');
355
+ if (this.vfs.existsSync(pkgJsonPath)) {
356
+ const pkgJson = JSON.parse(this.vfs.readFileSync(pkgJsonPath, 'utf8'));
357
+ packages[`${entry}/${scopedPkg}`] = pkgJson.version;
358
+ }
359
+ }
360
+ } else {
361
+ const pkgJsonPath = path.join(nodeModulesPath, entry, 'package.json');
362
+ if (this.vfs.existsSync(pkgJsonPath)) {
363
+ const pkgJson = JSON.parse(this.vfs.readFileSync(pkgJsonPath, 'utf8'));
364
+ packages[entry] = pkgJson.version;
365
+ }
366
+ }
367
+ }
368
+
369
+ return packages;
370
+ }
371
+ }
372
+
373
+ /**
374
+ * Parse a package specifier into name and version
375
+ * Examples: "express", "express@4.18.2", "@types/node@18"
376
+ */
377
+ function parsePackageSpec(spec: string): { name: string; version?: string } {
378
+ // Handle scoped packages
379
+ if (spec.startsWith('@')) {
380
+ const slashIndex = spec.indexOf('/');
381
+ if (slashIndex === -1) {
382
+ throw new Error(`Invalid package spec: ${spec}`);
383
+ }
384
+
385
+ const afterSlash = spec.slice(slashIndex + 1);
386
+ const atIndex = afterSlash.indexOf('@');
387
+
388
+ if (atIndex === -1) {
389
+ return { name: spec };
390
+ }
391
+
392
+ return {
393
+ name: spec.slice(0, slashIndex + 1 + atIndex),
394
+ version: afterSlash.slice(atIndex + 1),
395
+ };
396
+ }
397
+
398
+ // Regular packages
399
+ const atIndex = spec.indexOf('@');
400
+ if (atIndex === -1) {
401
+ return { name: spec };
402
+ }
403
+
404
+ return {
405
+ name: spec.slice(0, atIndex),
406
+ version: spec.slice(atIndex + 1),
407
+ };
408
+ }
409
+
410
+ // Convenience function for quick installs
411
+ export async function install(
412
+ packageSpec: string,
413
+ vfs: VirtualFS,
414
+ options?: InstallOptions
415
+ ): Promise<InstallResult> {
416
+ const pm = new PackageManager(vfs);
417
+ return pm.install(packageSpec, options);
418
+ }
419
+
420
+ // Re-export types and modules
421
+ export { Registry } from './registry';
422
+ export type { RegistryOptions, PackageVersion, PackageManifest } from './registry';
423
+ export type { ResolvedPackage, ResolveOptions } from './resolver';
424
+ export type { ExtractOptions } from './tarball';
425
+ export { parsePackageSpec };
@@ -0,0 +1,235 @@
1
+ /**
2
+ * npm Registry Client
3
+ * Fetches package metadata from npm registry
4
+ */
5
+
6
+ export interface PackageVersion {
7
+ name: string;
8
+ version: string;
9
+ dependencies?: Record<string, string>;
10
+ devDependencies?: Record<string, string>;
11
+ peerDependencies?: Record<string, string>;
12
+ peerDependenciesMeta?: Record<string, { optional?: boolean }>;
13
+ optionalDependencies?: Record<string, string>;
14
+ dist: {
15
+ tarball: string;
16
+ shasum: string;
17
+ integrity?: string;
18
+ };
19
+ main?: string;
20
+ module?: string;
21
+ exports?: Record<string, unknown>;
22
+ bin?: Record<string, string> | string;
23
+ }
24
+
25
+ export interface PackageManifest {
26
+ name: string;
27
+ 'dist-tags': {
28
+ latest: string;
29
+ [tag: string]: string;
30
+ };
31
+ versions: Record<string, PackageVersion>;
32
+ time?: Record<string, string>;
33
+ }
34
+
35
+ export interface RegistryOptions {
36
+ registry?: string;
37
+ /** An `@scope`, or a whole unscoped name, to the registry that answers for it. */
38
+ registryScopes?: Record<string, string>;
39
+ cache?: Map<string, PackageManifest>;
40
+ }
41
+
42
+ declare global {
43
+ /**
44
+ * The version a lockfile recorded for a name, as the page read it: enough
45
+ * to stand in for the registry's document without fetching the packument.
46
+ */
47
+ // eslint-disable-next-line no-var
48
+ var __browserRuntimeLockfileManifests: Map<string, LockfileVersionDoc> | undefined;
49
+ /**
50
+ * An `@scope`, or a whole unscoped name, to the registry that answers for
51
+ * it. The engine builds its package manager itself, with no options of
52
+ * ours, so a page's scopes arrive the way the lockfile's records do.
53
+ */
54
+ // eslint-disable-next-line no-var
55
+ var __browserRuntimeRegistryScopes: Record<string, string> | undefined;
56
+ }
57
+
58
+ /** One version's record in a lockfile, as the page hands it over. */
59
+ export interface LockfileVersionDoc {
60
+ version: string;
61
+ dependencies?: Record<string, string>;
62
+ peerDependencies?: Record<string, string>;
63
+ peerDependenciesMeta?: Record<string, { optional?: boolean }>;
64
+ optionalDependencies?: Record<string, string>;
65
+ }
66
+
67
+ const DEFAULT_REGISTRY = 'https://registry.npmjs.org';
68
+
69
+ export class Registry {
70
+ // Read by the resolver when it forms a tarball URL for a nested version.
71
+ registryUrl: string;
72
+ registryScopes?: Record<string, string>;
73
+ private cache: Map<string, PackageManifest>;
74
+
75
+ constructor(options: RegistryOptions = {}) {
76
+ this.registryUrl = options.registry || DEFAULT_REGISTRY;
77
+ this.registryScopes = options.registryScopes;
78
+ this.cache = options.cache || new Map();
79
+ }
80
+
81
+ /**
82
+ * Which registry answers for a name: the one its scope is served from,
83
+ * or the one its whole name is, and otherwise the default.
84
+ *
85
+ * A project may carry packages of its own that no public registry has: a
86
+ * private SDK, a twin, a package built in the same workspace but never
87
+ * published. Asking one registry for every name meant npm answered 404 for
88
+ * the scope and the install failed with nothing the project could do short
89
+ * of publishing.
90
+ */
91
+ registryFor(packageName: string): string {
92
+ const scopes = this.registryScopes ?? globalThis.__browserRuntimeRegistryScopes;
93
+ if (scopes && typeof packageName === "string") {
94
+ const scope = packageName.startsWith("@") && packageName.includes("/") ? packageName.slice(0, packageName.indexOf("/")) : packageName;
95
+ const url = scopes[scope] ?? scopes[packageName];
96
+ if (typeof url === "string" && url !== "") return url.endsWith("/") ? url.slice(0, -1) : url;
97
+ }
98
+ return this.registryUrl;
99
+ }
100
+
101
+ /**
102
+ * Fetch package manifest (all versions metadata)
103
+ */
104
+ async getPackageManifest(packageName: string): Promise<PackageManifest> {
105
+ // Check cache first
106
+ if (this.cache.has(packageName)) {
107
+ return this.cache.get(packageName)!;
108
+ }
109
+
110
+ // With a lockfile in hand the resolver already knows every version, so the
111
+ // whole packument, every version a package ever published, is the wrong
112
+ // request: it is the largest download of an install and the slowest part
113
+ // of a cold one. A pinned name asks for that one version instead, and the
114
+ // answer is shaped like a one-version packument so the rest of the
115
+ // resolver is unchanged.
116
+ const __docs = globalThis.__browserRuntimeLockfileManifests;
117
+ const __doc = __docs instanceof Map ? __docs.get(packageName) : void 0;
118
+ if (__doc) {
119
+ // The lockfile's record of the version stands in for the registry's
120
+ // document: the tarball is where a registry keeps one, and what the
121
+ // version depends on is what the lockfile wrote down.
122
+ const __tarball = `${this.registryFor(packageName)}/${encodePackageName(packageName)}/-/${packageName.slice(packageName.lastIndexOf("/") + 1)}-${__doc.version}.tgz`;
123
+ const __manifest = { "dist-tags": { latest: __doc.version }, versions: { [__doc.version]: { name: packageName, version: __doc.version, dist: { tarball: __tarball }, dependencies: __doc.dependencies, ...(__doc.peerDependencies ? { peerDependencies: __doc.peerDependencies, peerDependenciesMeta: __doc.peerDependenciesMeta || {} } : {}), ...(__doc.optionalDependencies ? { optionalDependencies: __doc.optionalDependencies } : {}) } } } as unknown as PackageManifest;
124
+ this.cache.set(packageName, __manifest);
125
+ return __manifest;
126
+ }
127
+ const __pins = globalThis.__browserRuntimeLockfilePins;
128
+ const __pin = __pins instanceof Map ? __pins.get(packageName) : void 0;
129
+ if (typeof __pin === "string") {
130
+ const pinnedUrl = `${this.registryFor(packageName)}/${encodePackageName(packageName)}/${__pin}`;
131
+ const pinnedResponse = await fetch(pinnedUrl, { headers: { Accept: "application/json" } });
132
+ if (pinnedResponse.ok) {
133
+ const versionData = await pinnedResponse.json() as PackageVersion;
134
+ if (versionData && versionData.dist && versionData.dist.tarball) {
135
+ const pinnedManifest = { "dist-tags": { latest: __pin }, versions: { [__pin]: versionData } } as unknown as PackageManifest;
136
+ this.cache.set(packageName, pinnedManifest);
137
+ return pinnedManifest;
138
+ }
139
+ }
140
+ }
141
+
142
+ const url = `${this.registryFor(packageName)}/${encodePackageName(packageName)}`;
143
+
144
+ const response = await fetch(url, {
145
+ headers: {
146
+ Accept: 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8',
147
+ },
148
+ });
149
+
150
+ if (!response.ok) {
151
+ if (response.status === 404) {
152
+ throw new Error(`Package not found: ${packageName}`);
153
+ }
154
+ throw new Error(`Failed to fetch package ${packageName}: ${response.status}`);
155
+ }
156
+
157
+ const manifest = (await response.json()) as PackageManifest;
158
+
159
+ // Cache the result
160
+ this.cache.set(packageName, manifest);
161
+
162
+ return manifest;
163
+ }
164
+
165
+ /**
166
+ * Get specific version metadata
167
+ */
168
+ async getPackageVersion(
169
+ packageName: string,
170
+ version: string
171
+ ): Promise<PackageVersion> {
172
+ const manifest = await this.getPackageManifest(packageName);
173
+
174
+ // Handle dist-tags (like "latest", "next", etc.)
175
+ if (manifest['dist-tags'][version]) {
176
+ version = manifest['dist-tags'][version];
177
+ }
178
+
179
+ const versionData = manifest.versions[version];
180
+ if (!versionData) {
181
+ throw new Error(`Version ${version} not found for package ${packageName}`);
182
+ }
183
+
184
+ return versionData;
185
+ }
186
+
187
+ /**
188
+ * Get latest version number
189
+ */
190
+ async getLatestVersion(packageName: string): Promise<string> {
191
+ const manifest = await this.getPackageManifest(packageName);
192
+ return manifest['dist-tags'].latest;
193
+ }
194
+
195
+ /**
196
+ * Get all available versions
197
+ */
198
+ async getVersions(packageName: string): Promise<string[]> {
199
+ const manifest = await this.getPackageManifest(packageName);
200
+ return Object.keys(manifest.versions);
201
+ }
202
+
203
+ /**
204
+ * Download tarball as ArrayBuffer
205
+ */
206
+ async downloadTarball(tarballUrl: string): Promise<ArrayBuffer> {
207
+ const response = await fetch(tarballUrl);
208
+
209
+ if (!response.ok) {
210
+ throw new Error(`Failed to download tarball: ${response.status}`);
211
+ }
212
+
213
+ return response.arrayBuffer();
214
+ }
215
+
216
+ /**
217
+ * Clear the cache
218
+ */
219
+ clearCache(): void {
220
+ this.cache.clear();
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Encode scoped package names for URL
226
+ * @scoped/package -> @scoped%2fpackage
227
+ */
228
+ export function encodePackageName(name: string): string {
229
+ return name.replace('/', '%2f');
230
+ }
231
+
232
+ // Default registry instance
233
+ export const registry = new Registry();
234
+
235
+ export default Registry;