@flanksource/page-runtime 0.0.0 → 0.1.0

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 (786) hide show
  1. package/README.md +495 -0
  2. package/dist/build/README.md +96 -0
  3. package/{spikes/lib → dist/build}/cjs-export-names.mjs +4 -2
  4. package/dist/build/dependencies.mjs +279 -0
  5. package/dist/build/dependencies.mjs.map +1 -0
  6. package/dist/build/dependency-cache-Zg-FGasE.mjs +2130 -0
  7. package/dist/build/dependency-cache-Zg-FGasE.mjs.map +1 -0
  8. package/dist/build/index.mjs +42 -0
  9. package/dist/build/index.mjs.map +1 -0
  10. package/{builder-package.json → dist/build/package.json} +1 -1
  11. package/dist/build/types/activity-schema.d.ts +62 -0
  12. package/dist/build/types/build/barrels.d.ts +70 -0
  13. package/dist/build/types/build/base.d.ts +2 -0
  14. package/dist/build/types/build/browser-runtime-exports.d.ts +19 -0
  15. package/dist/build/types/build/check-fragment.d.ts +5 -0
  16. package/dist/build/types/build/commonjs-exports.d.ts +5 -0
  17. package/dist/build/types/build/convert-commonjs.d.ts +12 -0
  18. package/dist/build/types/build/dependencies.d.ts +6 -0
  19. package/dist/build/types/build/dependency-barrel-index.d.ts +5 -0
  20. package/dist/build/types/build/dependency-barrels.d.ts +7 -0
  21. package/dist/build/types/build/dependency-cache.d.ts +7 -0
  22. package/dist/build/types/build/dependency-optional.d.ts +4 -0
  23. package/dist/build/types/build/dependency-plugin.d.ts +8 -0
  24. package/dist/build/types/build/dependency-runtime.d.ts +20 -0
  25. package/dist/build/types/build/dependency-workers.d.ts +8 -0
  26. package/dist/build/types/build/errors.d.ts +9 -0
  27. package/dist/build/types/build/fragment.d.ts +13 -0
  28. package/dist/build/types/build/index.d.ts +7 -0
  29. package/dist/build/types/build/library-runtime.d.ts +21 -0
  30. package/dist/build/types/build/module-utils.d.ts +3 -0
  31. package/dist/build/types/build/recipe-dependencies.d.ts +2 -0
  32. package/dist/build/types/build/runtime-entries.d.ts +4 -0
  33. package/dist/build/types/build/runtime-layer.d.ts +17 -0
  34. package/dist/build/types/build/trace.d.ts +140 -0
  35. package/dist/build/types/design-schema.d.ts +98 -0
  36. package/dist/build/types/host/agent-source.d.ts +2 -0
  37. package/dist/build/types/host/agent-validation.d.ts +3 -0
  38. package/dist/build/types/host/design-validation.d.ts +2 -0
  39. package/dist/build/types/host/message-values.d.ts +8 -0
  40. package/dist/build/types/host/review/validation.d.ts +5 -0
  41. package/dist/build/types/host/validation.d.ts +6 -0
  42. package/dist/build/types/link/page-sources.d.ts +31 -0
  43. package/dist/build/types/link/types.d.ts +62 -0
  44. package/dist/build/types/link/validation.d.ts +9 -0
  45. package/dist/build/types/markers.d.ts +10 -0
  46. package/dist/build/types/review-schema.d.ts +60 -0
  47. package/dist/build/types/schema.d.ts +319 -0
  48. package/dist/build/types/sw/barrels.d.ts +9 -0
  49. package/dist/build/types/sw/compiler-plugins.d.ts +6 -0
  50. package/dist/build/types/sw/composition.d.ts +8 -0
  51. package/dist/build/types/sw/module-transform.d.ts +68 -0
  52. package/dist/build/types/sw/profile.d.ts +7 -0
  53. package/dist/build/types/sw/source-provider.d.ts +7 -0
  54. package/dist/build/types/sw/versions.d.ts +10 -0
  55. package/dist/node/catalog.mjs +1 -0
  56. package/dist/node/chunks/publication-RchcQvxD.mjs +229 -0
  57. package/dist/node/chunks/publication-RchcQvxD.mjs.map +1 -0
  58. package/dist/node/chunks/schema-CaRTfg2x.mjs +12 -0
  59. package/dist/node/chunks/schema-CaRTfg2x.mjs.map +1 -0
  60. package/dist/node/dev.mjs +410 -0
  61. package/dist/node/dev.mjs.map +1 -0
  62. package/dist/node/publication/cli.mjs +13 -0
  63. package/dist/node/publication/cli.mjs.map +1 -0
  64. package/dist/node/publication.mjs +1 -0
  65. package/dist/node/schema.mjs +1 -0
  66. package/dist/node/styles.mjs +49 -0
  67. package/dist/node/styles.mjs.map +1 -0
  68. package/dist/static/boot.js +40938 -0
  69. package/dist/static/boot.js.map +1 -0
  70. package/dist/static/bootstrap.html +1 -0
  71. package/dist/static/devtools-hook.js +118 -0
  72. package/dist/static/document-bundle.js +1 -0
  73. package/dist/static/document.js +2621 -0
  74. package/dist/static/editing.js +37 -0
  75. package/dist/static/export-compiler.js +81521 -0
  76. package/dist/static/export-compiler.js.map +1 -0
  77. package/dist/static/page-agent.js +17193 -0
  78. package/dist/static/page-agent.js.map +1 -0
  79. package/dist/static/sw.js +86112 -0
  80. package/dist/static/sw.js.map +1 -0
  81. package/package.json +46 -13
  82. package/scripts/build-node.ts +26 -0
  83. package/scripts/build-static.ts +15 -4
  84. package/scripts/build.ts +1 -0
  85. package/scripts/react-externals.ts +18 -0
  86. package/scripts/release-version.ts +2 -1
  87. package/src/activity-schema.ts +3 -2
  88. package/src/build/README.md +3 -1
  89. package/src/build/browser-runtime-exports.ts +52 -0
  90. package/src/build/dependencies.ts +3 -1
  91. package/src/build/dependency-barrel-index.ts +48 -0
  92. package/src/build/dependency-barrels.ts +26 -5
  93. package/src/build/dependency-cache.ts +1 -1
  94. package/src/build/dependency-optional.ts +15 -0
  95. package/src/build/dependency-plugin.ts +2 -2
  96. package/src/build/dependency-runtime.ts +48 -13
  97. package/src/build/dependency-workers.ts +41 -0
  98. package/src/build/library-runtime.ts +6 -3
  99. package/src/build/runtime-layer.ts +99 -0
  100. package/src/build/trace.ts +12 -10
  101. package/src/dev/README.md +30 -0
  102. package/src/dev/index.ts +4 -1
  103. package/src/dev/runtime-origin.ts +63 -0
  104. package/src/editing.ts +1 -1
  105. package/src/form/entry-source.ts +68 -0
  106. package/src/form/form-page.ts +63 -0
  107. package/src/form/index.ts +2 -0
  108. package/src/form/source-update.ts +17 -0
  109. package/src/frame/activity.ts +4 -2
  110. package/src/frame/agent/README.md +1 -1
  111. package/src/frame/agent/agent.browser.ts +1 -1
  112. package/src/frame/agent/frame-layout.ts +54 -0
  113. package/src/frame/agent/index.ts +11 -8
  114. package/src/frame/agent/overlay.ts +19 -6
  115. package/src/frame/agent/owner.ts +6 -3
  116. package/src/frame/agent/review.ts +3 -2
  117. package/src/frame/agent.ts +1 -0
  118. package/src/frame/boot-styles.ts +3 -3
  119. package/src/frame/boot.ts +98 -34
  120. package/src/frame/bridge.ts +4 -4
  121. package/src/frame/document-assets.ts +76 -0
  122. package/src/frame/document-entry.ts +68 -0
  123. package/src/frame/document-modules.ts +113 -0
  124. package/src/frame/document-mount.ts +32 -0
  125. package/src/frame/export-page.ts +6 -4
  126. package/src/frame/export.ts +5 -6
  127. package/src/frame/index.ts +2 -1
  128. package/src/frame/mount-page.ts +36 -0
  129. package/src/frame/render-job.ts +101 -0
  130. package/src/frame/runtime.browser.ts +20 -1
  131. package/src/frame/tailwind/load.ts +16 -7
  132. package/src/frame/tailwind/recipe.ts +4 -9
  133. package/src/frame/tailwind/runtime.ts +4 -4
  134. package/src/frame/tailwind/stylesheets.ts +12 -7
  135. package/src/frame/tailwind/testing/client.ts +8 -7
  136. package/src/frame/tailwind/testing/server.ts +1 -1
  137. package/src/frame/testing/boot-layout.ts +3 -0
  138. package/src/frame/testing/host.ts +18 -0
  139. package/src/frame/testing/server.ts +18 -3
  140. package/src/host/BuildLog.tsx +2 -1
  141. package/src/host/DEBUG_CONSOLE.md +13 -0
  142. package/src/host/PageForm.tsx +63 -0
  143. package/src/host/PageFrame.tsx +14 -6
  144. package/src/host/RuntimeActivity.tsx +3 -1
  145. package/src/host/RuntimeDebugPanel.tsx +18 -0
  146. package/src/host/activity-state.ts +1 -1
  147. package/src/host/bridge.ts +2 -1
  148. package/src/host/debug-runtime.tsx +17 -0
  149. package/src/host/design-validation.ts +1 -1
  150. package/src/host/index.ts +1 -0
  151. package/src/host/link/transport.ts +2 -1
  152. package/src/host/review/index.ts +6 -5
  153. package/src/host/runtime-diagnostics.ts +41 -0
  154. package/src/host/validation.ts +40 -3
  155. package/src/link/testing/server.ts +10 -7
  156. package/src/link/testing/worker.ts +1 -1
  157. package/src/schema.ts +32 -6
  158. package/src/styles.ts +40 -0
  159. package/src/sw/compile.ts +1 -1
  160. package/src/sw/compiler.ts +14 -7
  161. package/src/sw/converted.browser.ts +1 -1
  162. package/src/sw/errors.ts +15 -2
  163. package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/browser-server.ts +5 -5
  164. package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/fixtures.ts +2 -2
  165. package/src/sw/link-compiler.ts +12 -4
  166. package/src/sw/link-route.ts +1 -1
  167. package/src/sw/markers.ts +1 -1
  168. package/src/sw/module-transform.ts +14 -2
  169. package/src/sw/profile.ts +3 -1
  170. package/src/sw/resolver.ts +8 -4
  171. package/src/sw/router.ts +52 -12
  172. package/src/sw/runtime-exports.ts +39 -0
  173. package/src/sw/source-provider.ts +20 -0
  174. package/src/sw/versions.ts +11 -4
  175. package/src/sw/worker.ts +5 -1
  176. package/.vitest/gavel-reporter-3e3dfb64eda19344.mjs +0 -59
  177. package/.vitest/vitest-report-root-1793958008919344000.json +0 -1
  178. package/.vitest/vitest-report-root-1793958052786561000.json +0 -1
  179. package/.vitest/vitest-report-root-1793958143511414000.json +0 -1
  180. package/.vitest/vitest-report-root-1793958185908019000.json +0 -1
  181. package/.vitest/vitest-report-root-1793958252687550000.json +0 -1
  182. package/.vitest/vitest-report-root-1793958260385388000.json +0 -1
  183. package/.vitest/vitest-report-root-1793958312358683000.json +0 -1
  184. package/.vitest/vitest-report-root-1793958386118791000.json +0 -1
  185. package/.vitest/vitest-report-root-1793958388712140000.json +0 -1
  186. package/.vitest/vitest-report-root-1793958429135603000.json +0 -1
  187. package/.vitest/vitest-report-root-1793958433387809000.json +0 -1
  188. package/.vitest/vitest-report-root-1793958517322792000.json +0 -1
  189. package/.vitest/vitest-report-root-1793958542332252000.json +0 -1
  190. package/.vitest/vitest-report-root-1793958617698698000.json +0 -1
  191. package/.vitest/vitest-report-root-1793958676587753000.json +0 -1
  192. package/.vitest/vitest-report-root-1793958707827469000.json +0 -1
  193. package/.vitest/vitest-report-root-1793958729745028000.json +0 -1
  194. package/.vitest/vitest-report-root-1793958736696408000.json +0 -1
  195. package/.vitest/vitest-report-root-1793958740449993000.json +0 -1
  196. package/.vitest/vitest-report-root-1793958841510921000.json +0 -1
  197. package/.vitest/vitest-report-root-1793958847664582000.json +0 -1
  198. package/.vitest/vitest-report-root-1793958900327643000.json +0 -1
  199. package/.vitest/vitest-report-root-1793958950822823000.json +0 -1
  200. package/.vitest/vitest-report-root-1793959013655262000.json +0 -1
  201. package/.vitest/vitest-report-root-1793959017905881000.json +0 -1
  202. package/.vitest/vitest-report-root-1793959093169044000.json +0 -1
  203. package/.vitest/vitest-report-root-1793959093978087000.json +0 -1
  204. package/.vitest/vitest-report-root-1793959101111925000.json +0 -1
  205. package/.vitest/vitest-report-root-1793959145317906000.json +0 -1
  206. package/.vitest/vitest-report-root-1793959190760607000.json +0 -1
  207. package/.vitest/vitest-report-root-1793959249695805000.json +0 -1
  208. package/.vitest/vitest-report-root-1793959323191511000.json +0 -1
  209. package/.vitest/vitest-report-root-1793959453311564000.json +0 -1
  210. package/.vitest/vitest-report-root-1793959495806182000.json +0 -1
  211. package/.vitest/vitest-report-root-1793959499945435000.json +0 -1
  212. package/.vitest/vitest-report-root-1793959546773807000.json +0 -1
  213. package/.vitest/vitest-report-root-1793959583335593000.json +0 -1
  214. package/.vitest/vitest-report-root-1793959621479504000.json +0 -1
  215. package/.vitest/vitest-report-root-1793959651002360000.json +0 -1
  216. package/.vitest/vitest-report-root-1793959655646061000.json +0 -1
  217. package/.vitest/vitest-report-root-1793959741176826000.json +0 -1
  218. package/.vitest/vitest-report-root-1793959744743733000.json +0 -1
  219. package/.vitest/vitest-report-root-1793959833244182000.json +0 -1
  220. package/.vitest/vitest-report-root-1793959882131751000.json +0 -1
  221. package/.vitest/vitest-report-root-1793959887033254000.json +0 -1
  222. package/.vitest/vitest-report-root-1793960000631977000.json +0 -1
  223. package/.vitest/vitest-report-root-1793960011938504000.json +0 -1
  224. package/.vitest/vitest-report-root-1793961370018852000.json +0 -1
  225. package/.vitest/vitest-report-root-1793961745370827000.json +0 -1
  226. package/.vitest/vitest-report-root-1793961764143180000.json +0 -1
  227. package/.vitest/vitest-report-root-1793961835963066000.json +0 -1
  228. package/.vitest/vitest-report-root-1793961890729922000.json +0 -1
  229. package/.vitest/vitest-report-root-1793961968680074000.json +0 -1
  230. package/.vitest/vitest-report-root-1793962066862337000.json +0 -1
  231. package/.vitest/vitest-report-root-1793962087917497000.json +0 -1
  232. package/.vitest/vitest-report-root-1793962157254386000.json +0 -1
  233. package/.vitest/vitest-report-root-1793962171214865000.json +0 -1
  234. package/.vitest/vitest-report-root-1793962183290533000.json +0 -1
  235. package/.vitest/vitest-report-root-1793962184809932000.json +0 -1
  236. package/.vitest/vitest-report-root-1793962197715204000.json +0 -1
  237. package/.vitest/vitest-report-root-1793962244650717000.json +0 -1
  238. package/.vitest/vitest-report-root-1793962259802273000.json +0 -1
  239. package/.vitest/vitest-report-root-1793962278799745000.json +0 -1
  240. package/.vitest/vitest-report-root-1793962304412974000.json +0 -1
  241. package/.vitest/vitest-report-root-1793962328411454000.json +0 -1
  242. package/.vitest/vitest-report-root-1793962355747869000.json +0 -1
  243. package/.vitest/vitest-report-root-1793962381401572000.json +0 -1
  244. package/.vitest/vitest-report-root-1793962393326735000.json +0 -1
  245. package/.vitest/vitest-report-root-1793962393329206000.json +0 -1
  246. package/.vitest/vitest-report-root-1793962437796768000.json +0 -1
  247. package/.vitest/vitest-report-root-1793962444190384000.json +0 -1
  248. package/.vitest/vitest-report-root-1793962445347541000.json +0 -1
  249. package/.vitest/vitest-report-root-1793962473691143000.json +0 -1
  250. package/.vitest/vitest-report-root-1793962474291457000.json +0 -1
  251. package/.vitest/vitest-report-root-1793962499680468000.json +0 -1
  252. package/.vitest/vitest-report-root-1793962504410483000.json +0 -1
  253. package/.vitest/vitest-report-root-1793962516850524000.json +0 -1
  254. package/.vitest/vitest-report-root-1793962536736273000.json +0 -1
  255. package/.vitest/vitest-report-root-1793962551181783000.json +0 -1
  256. package/.vitest/vitest-report-root-1793962553575620000.json +0 -1
  257. package/.vitest/vitest-report-root-1793962555169730000.json +0 -1
  258. package/.vitest/vitest-report-root-1793962572639765000.json +0 -1
  259. package/.vitest/vitest-report-root-1793962597102952000.json +0 -1
  260. package/.vitest/vitest-report-root-1793962637156669000.json +0 -1
  261. package/.vitest/vitest-report-root-1793962653530027000.json +0 -1
  262. package/.vitest/vitest-report-root-1793962665824334000.json +0 -1
  263. package/.vitest/vitest-report-root-1793962682161714000.json +0 -1
  264. package/.vitest/vitest-report-root-1793962719526168000.json +0 -1
  265. package/.vitest/vitest-report-root-1793962723853934000.json +0 -1
  266. package/.vitest/vitest-report-root-1793962741927728000.json +0 -1
  267. package/.vitest/vitest-report-root-1793962794308371000.json +0 -1
  268. package/.vitest/vitest-report-root-1793962796334481000.json +0 -1
  269. package/.vitest/vitest-report-root-1793962798075169000.json +0 -1
  270. package/.vitest/vitest-report-root-1793962836466676000.json +0 -1
  271. package/.vitest/vitest-report-root-1793962846507317000.json +0 -1
  272. package/.vitest/vitest-report-root-1793962876266701000.json +0 -1
  273. package/.vitest/vitest-report-root-1793962922031308000.json +0 -1
  274. package/.vitest/vitest-report-root-1793962932957166000.json +0 -1
  275. package/.vitest/vitest-report-root-1793962946930725000.json +0 -1
  276. package/.vitest/vitest-report-root-1793963027896350000.json +0 -1
  277. package/.vitest/vitest-report-root-1793963036618707000.json +0 -1
  278. package/.vitest/vitest-report-root-1793963067365318000.json +0 -1
  279. package/.vitest/vitest-report-root-1793963077597641000.json +0 -1
  280. package/.vitest/vitest-report-root-1793963126365651000.json +0 -1
  281. package/.vitest/vitest-report-root-1793963208744553000.json +0 -1
  282. package/.vitest/vitest-report-root-1793963232806450000.json +0 -1
  283. package/.vitest/vitest-report-root-1793963325077422000.json +0 -1
  284. package/.vitest/vitest-report-root-1793963392172877000.json +0 -1
  285. package/.vitest/vitest-report-root-1793963398218324000.json +0 -1
  286. package/.vitest/vitest-report-root-1793963410749092000.json +0 -1
  287. package/.vitest/vitest-report-root-1793963437279580000.json +0 -1
  288. package/.vitest/vitest-report-root-1793963450096193000.json +0 -1
  289. package/.vitest/vitest-report-root-1793963478908641000.json +0 -1
  290. package/.vitest/vitest-report-root-1793963507838465000.json +0 -1
  291. package/.vitest/vitest-report-root-1793963528668174000.json +0 -1
  292. package/.vitest/vitest-report-root-1793963601860390000.json +0 -1
  293. package/.vitest/vitest-report-root-1793963611633446000.json +0 -1
  294. package/.vitest/vitest-report-root-1793963624713406000.json +0 -1
  295. package/.vitest/vitest-report-root-1793963680656685000.json +0 -1
  296. package/.vitest/vitest-report-root-1793963705231851000.json +0 -1
  297. package/.vitest/vitest-report-root-1793963708929500000.json +0 -1
  298. package/.vitest/vitest-report-root-1793963710267844000.json +0 -1
  299. package/.vitest/vitest-report-root-1793963713999248000.json +0 -1
  300. package/.vitest/vitest-report-root-1793963786513455000.json +0 -1
  301. package/.vitest/vitest-report-root-1793963792518765000.json +0 -1
  302. package/.vitest/vitest-report-root-1793963804089549000.json +0 -1
  303. package/.vitest/vitest-report-root-1793963840412921000.json +0 -1
  304. package/.vitest/vitest-report-root-1793963880361176000.json +0 -1
  305. package/.vitest/vitest-report-root-1793963935121106000.json +0 -1
  306. package/.vitest/vitest-report-root-1793963937290698000.json +0 -1
  307. package/.vitest/vitest-report-root-1793963977050773000.json +0 -1
  308. package/.vitest/vitest-report-root-1793963981229158000.json +0 -1
  309. package/.vitest/vitest-report-root-1793963989422080000.json +0 -1
  310. package/.vitest/vitest-report-root-1793964025924629000.json +0 -1
  311. package/.vitest/vitest-report-root-1793964027983705000.json +0 -1
  312. package/.vitest/vitest-report-root-1793964059969386000.json +0 -1
  313. package/.vitest/vitest-report-root-1793964071524069000.json +0 -1
  314. package/.vitest/vitest-report-root-1793964076285860000.json +0 -1
  315. package/.vitest/vitest-report-root-1793964077988100000.json +0 -1
  316. package/.vitest/vitest-report-root-1793964093289042000.json +0 -1
  317. package/.vitest/vitest-report-root-1793964102899356000.json +0 -1
  318. package/.vitest/vitest-report-root-1793964128089691000.json +0 -1
  319. package/.vitest/vitest-report-root-1793964129495156000.json +0 -1
  320. package/.vitest/vitest-report-root-1793964182849665000.json +0 -1
  321. package/.vitest/vitest-report-root-1793964223959893000.json +0 -1
  322. package/.vitest/vitest-report-root-1793964253351716000.json +0 -1
  323. package/.vitest/vitest-report-root-1793964290220122000.json +0 -1
  324. package/.vitest/vitest-report-root-1793964318037006000.json +0 -1
  325. package/.vitest/vitest-report-root-1793964334676691000.json +0 -1
  326. package/.vitest/vitest-report-root-1793964378520677000.json +0 -1
  327. package/.vitest/vitest-report-root-1793964383748994000.json +0 -1
  328. package/.vitest/vitest-report-root-1793964394042303000.json +0 -1
  329. package/.vitest/vitest-report-root-1793964466521881000.json +0 -1
  330. package/.vitest/vitest-report-root-1793964470478175000.json +0 -1
  331. package/.vitest/vitest-report-root-1793964484499019000.json +0 -1
  332. package/.vitest/vitest-report-root-1793964527645213000.json +0 -1
  333. package/.vitest/vitest-report-root-1793964608875865000.json +0 -1
  334. package/.vitest/vitest-report-root-1793964623608336000.json +0 -1
  335. package/.vitest/vitest-report-root-1793964629870846000.json +0 -1
  336. package/.vitest/vitest-report-root-1793964674515564000.json +0 -1
  337. package/.vitest/vitest-report-root-1793964706923651000.json +0 -1
  338. package/.vitest/vitest-report-root-1793964712832942000.json +0 -1
  339. package/.vitest/vitest-report-root-1793964714824633000.json +0 -1
  340. package/.vitest/vitest-report-root-1793964755433952000.json +0 -1
  341. package/.vitest/vitest-report-root-1793964783157670000.json +0 -1
  342. package/.vitest/vitest-report-root-1793964818963246000.json +0 -1
  343. package/.vitest/vitest-report-root-1793964843818548000.json +0 -1
  344. package/.vitest/vitest-report-root-1793964929824204000.json +0 -1
  345. package/.vitest/vitest-report-root-1793964973060713000.json +0 -1
  346. package/.vitest/vitest-report-root-1793964983122482000.json +0 -1
  347. package/.vitest/vitest-report-root-1793965107264567000.json +0 -1
  348. package/.vitest/vitest-report-root-1793965258759177000.json +0 -1
  349. package/.vitest/vitest-report-root-1793965277212091000.json +0 -1
  350. package/.vitest/vitest-report-root-1793965420648188000.json +0 -1
  351. package/.vitest/vitest-report-root-1793965611688414000.json +0 -1
  352. package/.vitest/vitest-report-root-1793965753407694000.json +0 -1
  353. package/.vitest/vitest-report-root-1793965766104309000.json +0 -1
  354. package/.vitest/vitest-report-root-1793965766823098000.json +0 -1
  355. package/.vitest/vitest-report-root-1793965806066109000.json +0 -1
  356. package/.vitest/vitest-report-root-1793965824697182000.json +0 -1
  357. package/.vitest/vitest-report-root-1793965904374564000.json +0 -1
  358. package/.vitest/vitest-report-root-1793965920838340000.json +0 -1
  359. package/.vitest/vitest-report-root-1793965932520617000.json +0 -1
  360. package/.vitest/vitest-report-root-1793965971574656000.json +0 -1
  361. package/.vitest/vitest-report-root-1793966049815024000.json +0 -1
  362. package/.vitest/vitest-report-root-1793966057888034000.json +0 -1
  363. package/.vitest/vitest-report-root-1793966066838868000.json +0 -1
  364. package/.vitest/vitest-report-root-1793966160347764000.json +0 -1
  365. package/.vitest/vitest-report-root-1793966196305985000.json +0 -1
  366. package/.vitest/vitest-report-root-1793966221538043000.json +0 -1
  367. package/.vitest/vitest-report-root-1793966251519918000.json +0 -1
  368. package/.vitest/vitest-report-root-1793966447000588000.json +0 -1
  369. package/.vitest/vitest-report-root-1793966463178249000.json +0 -1
  370. package/.vitest/vitest-report-root-1793966486995648000.json +0 -1
  371. package/.vitest/vitest-report-root-1793966726756953000.json +0 -1
  372. package/.vitest/vitest-report-root-1793966763656807000.json +0 -1
  373. package/.vitest/vitest-report-root-1793966979409799000.json +0 -1
  374. package/.vitest/vitest-report-root-1793967385250149000.json +0 -1
  375. package/.vitest/vitest-report-root-1793967617080163000.json +0 -1
  376. package/.vitest/vitest-report-root-1793967649428508000.json +0 -1
  377. package/.vitest/vitest-report-root-1793967773689520000.json +0 -1
  378. package/.vitest/vitest-report-root-1793968743743508000.json +0 -1
  379. package/.vitest/vitest-report-root-1793968846470407000.json +0 -1
  380. package/.vitest/vitest-report-root-1793968880878391000.json +0 -1
  381. package/.vitest/vitest-report-root-1793969027713529000.json +0 -1
  382. package/.vitest/vitest-report-root-1793969041841266000.json +0 -1
  383. package/.vitest/vitest-report-root-1793969142007468000.json +0 -1
  384. package/.vitest/vitest-report-root-1793969164867379000.json +0 -1
  385. package/.vitest/vitest-report-root-1793969193145858000.json +0 -1
  386. package/.vitest/vitest-report-root-1793969246818533000.json +0 -1
  387. package/.vitest/vitest-report-root-1793969270845486000.json +0 -1
  388. package/.vitest/vitest-report-root-1793969272514219000.json +0 -1
  389. package/.vitest/vitest-report-root-1793969302476105000.json +0 -1
  390. package/.vitest/vitest-report-root-1793969401697799000.json +0 -1
  391. package/.vitest/vitest-report-root-1793969433222630000.json +0 -1
  392. package/.vitest/vitest-report-root-1793969453350714000.json +0 -1
  393. package/.vitest/vitest-report-root-1793969567187400000.json +0 -1
  394. package/.vitest/vitest-report-root-1793969602230024000.json +0 -1
  395. package/.vitest/vitest-report-root-1793969633261063000.json +0 -1
  396. package/.vitest/vitest-report-root-1793969673876404000.json +0 -1
  397. package/.vitest/vitest-report-root-1793969702287010000.json +0 -1
  398. package/.vitest/vitest-report-root-1793969745828386000.json +0 -1
  399. package/.vitest/vitest-report-root-1793969893687205000.json +0 -1
  400. package/.vitest/vitest-report-root-1793969949642120000.json +0 -1
  401. package/.vitest/vitest-report-root-1793969981399076000.json +0 -1
  402. package/.vitest/vitest-report-root-1793970027152713000.json +0 -1
  403. package/.vitest/vitest-report-root-1793970030585158000.json +0 -1
  404. package/.vitest/vitest-report-root-1793970160195767000.json +0 -1
  405. package/.vitest/vitest-report-root-1793970215752422000.json +0 -1
  406. package/.vitest/vitest-report-root-1793970217114968000.json +0 -1
  407. package/.vitest/vitest-report-root-1793970329879319000.json +0 -1
  408. package/.vitest/vitest-report-root-1793970590586994000.json +0 -1
  409. package/.vitest/vitest-report-root-1793970625359990000.json +0 -1
  410. package/.vitest/vitest-report-root-1793970672590269000.json +0 -1
  411. package/.vitest/vitest-report-root-1793970796789022000.json +0 -1
  412. package/.vitest/vitest-report-root-1793970825710990000.json +0 -1
  413. package/.vitest/vitest-report-root-1793970884000509000.json +0 -1
  414. package/.vitest/vitest-report-root-1793970900444617000.json +0 -1
  415. package/.vitest/vitest-report-root-1793972186024681000.json +0 -1
  416. package/.vitest/vitest-report-root-1793972227757396000.json +0 -1
  417. package/.vitest/vitest-report-root-1793972736341600000.json +0 -1
  418. package/.vitest/vitest-report-root-1793972769249562000.json +0 -1
  419. package/.vitest/vitest-report-root-1793972859435283000.json +0 -1
  420. package/.vitest/vitest-report-root-1793972915169294000.json +0 -1
  421. package/.vitest/vitest-report-root-1793973081515450000.json +0 -1
  422. package/.vitest/vitest-report-root-1793973111336773000.json +0 -1
  423. package/.vitest/vitest-report-root-1793973253986969000.json +0 -1
  424. package/.vitest/vitest-report-root-1793973561283775000.json +0 -1
  425. package/.vitest/vitest-report-root-1793973593320977000.json +0 -1
  426. package/.vitest/vitest-report-root-1793973648302867000.json +0 -1
  427. package/.vitest/vitest-report-root-1793973819657242000.json +0 -1
  428. package/.vitest/vitest-report-root-1793973952727311000.json +0 -1
  429. package/.vitest/vitest-report-root-1793974334455876000.json +0 -1
  430. package/.vitest/vitest-report-root-1793974437074196000.json +0 -1
  431. package/.vitest/vitest-report-root-1793974437553146000.json +0 -1
  432. package/.vitest/vitest-report-root-1793974461818626000.json +0 -1
  433. package/.vitest/vitest-report-root-1793974515255198000.json +0 -1
  434. package/.vitest/vitest-report-root-1793974516267191000.json +0 -1
  435. package/.vitest/vitest-report-root-1793974621202824000.json +0 -1
  436. package/.vitest/vitest-report-root-1793974718450330000.json +0 -1
  437. package/.vitest/vitest-report-root-1793974834942373000.json +0 -1
  438. package/.vitest/vitest-report-root-1793974921367314000.json +0 -1
  439. package/.vitest/vitest-report-root-1793975019367156000.json +0 -1
  440. package/.vitest/vitest-report-root-1793975048166096000.json +0 -1
  441. package/.vitest/vitest-report-root-1793975133024339000.json +0 -1
  442. package/.vitest/vitest-report-root-1793975159711704000.json +0 -1
  443. package/.vitest/vitest-report-root-1793975517481736000.json +0 -1
  444. package/.vitest/vitest-report-root-1793975680008825000.json +0 -1
  445. package/.vitest/vitest-report-root-1793976067648494000.json +0 -1
  446. package/.vitest/vitest-report-root-1793976314122479000.json +0 -1
  447. package/.vitest/vitest-report-root-1793976513022402000.json +0 -1
  448. package/.vitest/vitest-report-root-1793976540410805000.json +0 -1
  449. package/.vitest/vitest-report-root-1793976555103273000.json +0 -1
  450. package/.vitest/vitest-report-root-1793976702974407000.json +0 -1
  451. package/.vitest/vitest-report-root-1793976721093108000.json +0 -1
  452. package/.vitest/vitest-report-root-1793976955473681000.json +0 -1
  453. package/.vitest/vitest-report-root-1793977049628483000.json +0 -1
  454. package/.vitest/vitest-report-root-1793977098467804000.json +0 -1
  455. package/.vitest/vitest-report-root-1793977132144900000.json +0 -1
  456. package/.vitest/vitest-report-root-1793977279648191000.json +0 -1
  457. package/.vitest/vitest-report-root-1793977365312127000.json +0 -1
  458. package/.vitest/vitest-report-root-1793978227796817000.json +0 -1
  459. package/.vitest/vitest-report-root-1793978255189735000.json +0 -1
  460. package/.vitest/vitest-report-root-1793978306509070000.json +0 -1
  461. package/.vitest/vitest-report-root-1793978418301216000.json +0 -1
  462. package/.vitest/vitest-report-root-1793978445072573000.json +0 -1
  463. package/.vitest/vitest-report-root-1793978546605517000.json +0 -1
  464. package/.vitest/vitest-report-root-1793978576060950000.json +0 -1
  465. package/.vitest/vitest-report-root-1793978590261408000.json +0 -1
  466. package/.vitest/vitest-report-root-1793978674733179000.json +0 -1
  467. package/.vitest/vitest-report-root-1793978718588785000.json +0 -1
  468. package/.vitest/vitest-report-root-1793978725363453000.json +0 -1
  469. package/.vitest/vitest-report-root-1793978729967285000.json +0 -1
  470. package/.vitest/vitest-report-root-1793978755641607000.json +0 -1
  471. package/.vitest/vitest-report-root-1793978782769802000.json +0 -1
  472. package/.vitest/vitest-report-root-1793978784870947000.json +0 -1
  473. package/.vitest/vitest-report-root-1793978806927335000.json +0 -1
  474. package/.vitest/vitest-report-root-1793978822508324000.json +0 -1
  475. package/.vitest/vitest-report-root-1793978836339794000.json +0 -1
  476. package/.vitest/vitest-report-root-1793978837947352000.json +0 -1
  477. package/.vitest/vitest-report-root-1793978891548295000.json +0 -1
  478. package/.vitest/vitest-report-root-1793978946172947000.json +0 -1
  479. package/.vitest/vitest-report-root-1793978947109807000.json +0 -1
  480. package/.vitest/vitest-report-root-1793979034208662000.json +0 -1
  481. package/.vitest/vitest-report-root-1793979070583608000.json +0 -1
  482. package/.vitest/vitest-report-root-1793979081187144000.json +0 -1
  483. package/.vitest/vitest-report-root-1793979085428673000.json +0 -1
  484. package/.vitest/vitest-report-root-1793979155097858000.json +0 -1
  485. package/.vitest/vitest-report-root-1793979233508873000.json +0 -1
  486. package/.vitest/vitest-report-root-1793979268653273000.json +0 -1
  487. package/.vitest/vitest-report-root-1793979341978843000.json +0 -1
  488. package/.vitest/vitest-report-root-1793979345344877000.json +0 -1
  489. package/.vitest/vitest-report-root-1793979389390374000.json +0 -1
  490. package/.vitest/vitest-report-root-1793979400063493000.json +0 -1
  491. package/.vitest/vitest-report-root-1793979432448725000.json +0 -1
  492. package/.vitest/vitest-report-root-1793979459139430000.json +0 -1
  493. package/.vitest/vitest-report-root-1793979480341961000.json +0 -1
  494. package/.vitest/vitest-report-root-1793979510130869000.json +0 -1
  495. package/.vitest/vitest-report-root-1793979524763924000.json +0 -1
  496. package/.vitest/vitest-report-root-1793979571563010000.json +0 -1
  497. package/.vitest/vitest-report-root-1793979627916920000.json +0 -1
  498. package/.vitest/vitest-report-root-1793979726395379000.json +0 -1
  499. package/.vitest/vitest-report-root-1793979752029533000.json +0 -1
  500. package/.vitest/vitest-report-root-1793979753365744000.json +0 -1
  501. package/.vitest/vitest-report-root-1793979759386206000.json +0 -1
  502. package/.vitest/vitest-report-root-1793979787819109000.json +0 -1
  503. package/.vitest/vitest-report-root-1793979827615051000.json +0 -1
  504. package/.vitest/vitest-report-root-1793979927737393000.json +0 -1
  505. package/.vitest/vitest-report-root-1793979929836169000.json +0 -1
  506. package/.vitest/vitest-report-root-1793979955780781000.json +0 -1
  507. package/.vitest/vitest-report-root-1793980200569636000.json +0 -1
  508. package/.vitest/vitest-report-root-1793980206045213000.json +0 -1
  509. package/.vitest/vitest-report-root-1793980285772027000.json +0 -1
  510. package/.vitest/vitest-report-root-1793980459229828000.json +0 -1
  511. package/.vitest/vitest-report-root-1793980460545874000.json +0 -1
  512. package/.vitest/vitest-report-root-1793980554484341000.json +0 -1
  513. package/.vitest/vitest-report-root-1793980674494388000.json +0 -1
  514. package/.vitest/vitest-report-root-1793980683752195000.json +0 -1
  515. package/.vitest/vitest-report-root-1793980947108651000.json +0 -1
  516. package/.vitest/vitest-report-root-1793981129616629000.json +0 -1
  517. package/.vitest/vitest-report-root-1793981196611441000.json +0 -1
  518. package/.vitest/vitest-report-root-1793981226583545000.json +0 -1
  519. package/.vitest/vitest-report-root-1793981294259721000.json +0 -1
  520. package/.vitest/vitest-report-root-1793981353393048000.json +0 -1
  521. package/.vitest/vitest-report-root-1793981424585368000.json +0 -1
  522. package/.vitest/vitest-report-root-1793981513266687000.json +0 -1
  523. package/.vitest/vitest-report-root-1793981526418218000.json +0 -1
  524. package/.vitest/vitest-report-root-1793981540069877000.json +0 -1
  525. package/.vitest/vitest-report-root-1793981761193625000.json +0 -1
  526. package/.vitest/vitest-report-root-1793981868520992000.json +0 -1
  527. package/.vitest/vitest-report-root-1793982048467772000.json +0 -1
  528. package/.vitest/vitest-report-root-1793982119518020000.json +0 -1
  529. package/.vitest/vitest-report-root-1793982243473651000.json +0 -1
  530. package/.vitest/vitest-report-root-1793982406880629000.json +0 -1
  531. package/.vitest/vitest-report-root-1793982433563632000.json +0 -1
  532. package/.vitest/vitest-report-root-1793982496753204000.json +0 -1
  533. package/.vitest/vitest-report-root-1793982500153311000.json +0 -1
  534. package/.vitest/vitest-report-root-1793982542086095000.json +0 -1
  535. package/.vitest/vitest-report-root-1793982659482988000.json +0 -1
  536. package/.vitest/vitest-report-root-1793983799132716000.json +0 -1
  537. package/.vitest/vitest-report-root-1793983822721833000.json +0 -1
  538. package/.vitest/vitest-report-root-1793984998618484000.json +0 -1
  539. package/.vitest/vitest-report-root-1793985050475750000.json +0 -1
  540. package/.vitest/vitest-report-root-1793985095516077000.json +0 -1
  541. package/.vitest/vitest-report-root-1793985130729074000.json +0 -1
  542. package/.vitest/vitest-report-root-1793985177150997000.json +0 -1
  543. package/.vitest/vitest-report-root-1793985267658626000.json +0 -1
  544. package/.vitest/vitest-report-root-1793985412705211000.json +0 -1
  545. package/.vitest/vitest-report-root-1793985433752853000.json +0 -1
  546. package/.vitest/vitest-report-root-1794087938302852000.json +0 -1
  547. package/.vitest/vitest-report-root-1794087978339022000.json +0 -1
  548. package/.vitest/vitest-report-root-1794088095283811000.json +0 -1
  549. package/.vitest/vitest-report-root-1794088129997065000.json +0 -1
  550. package/.vitest/vitest-report-root-1794088147336556000.json +0 -1
  551. package/.vitest/vitest-report-root-1794088173414593000.json +0 -1
  552. package/.vitest/vitest-report-root-1794088221289657000.json +0 -1
  553. package/.vitest/vitest-report-root-1794088250766611000.json +0 -1
  554. package/.vitest/vitest-report-root-1794088365553234000.json +0 -1
  555. package/.vitest/vitest-report-root-1794088395202655000.json +0 -1
  556. package/.vitest/vitest-report-root-1794090028732187000.json +0 -1
  557. package/.vitest/vitest-report-root-1794090054787283000.json +0 -1
  558. package/.vitest/vitest-report-root-1794090153955794000.json +0 -1
  559. package/.vitest/vitest-report-root-1794090161850160000.json +0 -1
  560. package/.vitest/vitest-report-root-1794091755693314000.json +0 -1
  561. package/.vitest/vitest-report-root-1794091765029349000.json +0 -1
  562. package/.vitest/vitest-report-root-1794091975649927000.json +0 -1
  563. package/.vitest/vitest-report-root-1794091994027950000.json +0 -1
  564. package/.vitest/vitest-report-root-1794092005178771000.json +0 -1
  565. package/.vitest/vitest-report-root-1794113295302382000.json +0 -1
  566. package/.vitest/vitest-report-root-1794114156337032000.json +0 -1
  567. package/.vitest/vitest-report-root-1794114198454137000.json +0 -1
  568. package/.vitest/vitest-report-root-1794114254064413000.json +0 -1
  569. package/.vitest/vitest-report-root-1794114280107510000.json +0 -1
  570. package/.vitest/vitest-report-root-1794114495199837000.json +0 -1
  571. package/.vitest/vitest-report-root-1794114646604233000.json +0 -1
  572. package/.vitest/vitest-report-root-1794114666311689000.json +0 -1
  573. package/.vitest/vitest-report-root-1794114974303438000.json +0 -1
  574. package/.vitest/vitest-report-root-1794115037361450000.json +0 -1
  575. package/.vitest/vitest-report-root-1794115097838937000.json +0 -1
  576. package/.vitest/vitest-report-root-1794115604669388000.json +0 -1
  577. package/.vitest/vitest-report-root-1794115633814500000.json +0 -1
  578. package/.vitest/vitest-report-root-1794115648756242000.json +0 -1
  579. package/.vitest/vitest-report-root-1794115873440741000.json +0 -1
  580. package/.vitest/vitest-report-root-1794115952930230000.json +0 -1
  581. package/.vitest/vitest-report-root-1794115963344701000.json +0 -1
  582. package/.vitest/vitest-report-root-1794116196067450000.json +0 -1
  583. package/.vitest/vitest-report-root-1794116254301280000.json +0 -1
  584. package/.vitest/vitest-report-root-1794116259342966000.json +0 -1
  585. package/.vitest/vitest-report-root-1794118178787879000.json +0 -1
  586. package/.vitest/vitest-report-root-1794137087891409000.json +0 -1
  587. package/.vitest/vitest-report-root-1794137100301214000.json +0 -1
  588. package/.vitest/vitest-report-root-1794137107377813000.json +0 -1
  589. package/.vitest/vitest-report-root-1794137171230704000.json +0 -1
  590. package/.vitest/vitest-report-root-1794137317761465000.json +0 -1
  591. package/.vitest/vitest-report-root-1794137320282368000.json +0 -1
  592. package/PACKAGE_PUBLICATIONS.md +0 -26
  593. package/scripts/local-workspaces.test.ts +0 -31
  594. package/scripts/release-version-cli.test.ts +0 -40
  595. package/scripts/release-version.test.ts +0 -29
  596. package/spikes/README.md +0 -70
  597. package/spikes/barrel-rewriting/README.md +0 -97
  598. package/spikes/barrel-rewriting/measure.ts +0 -134
  599. package/spikes/barrel-rewriting/readme.ts +0 -174
  600. package/spikes/barrel-rewriting/results.json +0 -3440
  601. package/spikes/barrel-rewriting/run.ts +0 -330
  602. package/spikes/barrel-rewriting/setup.ts +0 -90
  603. package/spikes/barrel-rewriting/sw.ts +0 -148
  604. package/spikes/barrel-rewriting/tenant.ts +0 -91
  605. package/spikes/barrel-rewriting/worker-config.ts +0 -33
  606. package/spikes/closure-fragments/README.md +0 -157
  607. package/spikes/closure-fragments/results.json +0 -959
  608. package/spikes/closure-fragments/run.ts +0 -298
  609. package/spikes/compiler/README.md +0 -177
  610. package/spikes/compiler/compile.test.ts +0 -78
  611. package/spikes/compiler/compile.ts +0 -82
  612. package/spikes/compiler/facet-redact.d.ts +0 -5
  613. package/spikes/compiler/markers.ts +0 -88
  614. package/spikes/compiler/pages.ts +0 -43
  615. package/spikes/compiler/readme.ts +0 -116
  616. package/spikes/compiler/reference.ts +0 -81
  617. package/spikes/compiler/render.ts +0 -113
  618. package/spikes/compiler/results.json +0 -3310
  619. package/spikes/compiler/run.ts +0 -250
  620. package/spikes/compiler/sucrase-parser.d.ts +0 -8
  621. package/spikes/compiler/sw.ts +0 -62
  622. package/spikes/diagram-readiness/README.md +0 -134
  623. package/spikes/diagram-readiness/analysis.test.ts +0 -52
  624. package/spikes/diagram-readiness/analysis.ts +0 -35
  625. package/spikes/diagram-readiness/browser.ts +0 -209
  626. package/spikes/diagram-readiness/readme.ts +0 -65
  627. package/spikes/diagram-readiness/results.json +0 -30289
  628. package/spikes/diagram-readiness/run.ts +0 -103
  629. package/spikes/diagram-readiness/server.ts +0 -53
  630. package/spikes/esm-sh/README.md +0 -27
  631. package/spikes/frame-commenting/README.md +0 -183
  632. package/spikes/frame-commenting/agent.ts +0 -110
  633. package/spikes/frame-commenting/hook.ts +0 -1
  634. package/spikes/frame-commenting/host.ts +0 -66
  635. package/spikes/frame-commenting/measure.ts +0 -180
  636. package/spikes/frame-commenting/model.test.ts +0 -27
  637. package/spikes/frame-commenting/model.ts +0 -40
  638. package/spikes/frame-commenting/readme.ts +0 -61
  639. package/spikes/frame-commenting/results.json +0 -5320
  640. package/spikes/frame-commenting/run.ts +0 -73
  641. package/spikes/frame-commenting/setup.ts +0 -125
  642. package/spikes/lib/barrels.test.ts +0 -107
  643. package/spikes/lib/barrels.ts +0 -309
  644. package/spikes/lib/content-types.ts +0 -28
  645. package/spikes/lib/convert-commonjs.ts +0 -168
  646. package/spikes/lib/fragment.ts +0 -108
  647. package/spikes/lib/library-set.ts +0 -194
  648. package/spikes/lib/module-transform.test.ts +0 -133
  649. package/spikes/lib/module-transform.ts +0 -351
  650. package/spikes/lib/origin.ts +0 -140
  651. package/spikes/lib/pages.ts +0 -290
  652. package/spikes/lib/report.ts +0 -23
  653. package/spikes/lib/runtime-server.ts +0 -282
  654. package/spikes/lib/static-server.ts +0 -82
  655. package/spikes/lib/trace.ts +0 -384
  656. package/spikes/local-folder-link/README.md +0 -85
  657. package/spikes/local-folder-link/checkout.ts +0 -132
  658. package/spikes/local-folder-link/documents.ts +0 -36
  659. package/spikes/local-folder-link/readme.ts +0 -42
  660. package/spikes/local-folder-link/results.json +0 -12815
  661. package/spikes/local-folder-link/rewrite.test.ts +0 -27
  662. package/spikes/local-folder-link/rewrite.ts +0 -38
  663. package/spikes/local-folder-link/run.ts +0 -123
  664. package/spikes/local-folder-link/server.ts +0 -100
  665. package/spikes/local-folder-link/sw.ts +0 -97
  666. package/spikes/origin-isolation/README.md +0 -426
  667. package/spikes/origin-isolation/browsers.ts +0 -43
  668. package/spikes/origin-isolation/helper.ts +0 -6
  669. package/spikes/origin-isolation/host.ts +0 -25
  670. package/spikes/origin-isolation/measure.ts +0 -118
  671. package/spikes/origin-isolation/model.test.ts +0 -45
  672. package/spikes/origin-isolation/model.ts +0 -49
  673. package/spikes/origin-isolation/proxy.ts +0 -35
  674. package/spikes/origin-isolation/readme.ts +0 -83
  675. package/spikes/origin-isolation/results.json +0 -3242
  676. package/spikes/origin-isolation/run.ts +0 -35
  677. package/spikes/origin-isolation/server.ts +0 -108
  678. package/spikes/origin-isolation/sw.ts +0 -28
  679. package/spikes/origin-isolation/tenant.ts +0 -165
  680. package/spikes/react-runtime-set/README.md +0 -48
  681. package/spikes/react-runtime-set/convert.ts +0 -118
  682. package/spikes/react-runtime-set/export-names.mjs +0 -8
  683. package/spikes/react-runtime-set/page/page.js +0 -46
  684. package/spikes/react-runtime-set/results.json +0 -84
  685. package/spikes/react-runtime-set/run.ts +0 -255
  686. package/spikes/run.ts +0 -15
  687. package/spikes/sw-tenant-frame/README.md +0 -95
  688. package/spikes/sw-tenant-frame/results.json +0 -1348
  689. package/spikes/sw-tenant-frame/run.ts +0 -373
  690. package/spikes/sw-tenant-frame/site/frame.html +0 -113
  691. package/spikes/sw-tenant-frame/site/host.html +0 -25
  692. package/spikes/sw-tenant-frame/site/sw.js +0 -10
  693. package/spikes/tailwind-parity/README.md +0 -78
  694. package/spikes/tailwind-parity/compare.test.ts +0 -70
  695. package/spikes/tailwind-parity/compare.ts +0 -91
  696. package/spikes/tailwind-parity/facet-font-scale.d.ts +0 -6
  697. package/spikes/tailwind-parity/facet-styles.ts +0 -77
  698. package/spikes/tailwind-parity/results.json +0 -885
  699. package/spikes/tailwind-parity/run.ts +0 -385
  700. package/spikes/tailwind-parity/runtime-tailwind.ts +0 -82
  701. package/src/activity.test.ts +0 -57
  702. package/src/build/barrels.test.ts +0 -107
  703. package/src/build/dependency-runtime.test.ts +0 -121
  704. package/src/build/library-runtime.test.ts +0 -343
  705. package/src/dev/cli.test.ts +0 -12
  706. package/src/dev/packages.test.ts +0 -175
  707. package/src/editing.test.tsx +0 -31
  708. package/src/frame/activity.test.ts +0 -27
  709. package/src/frame/agent/overlay.test.ts +0 -42
  710. package/src/frame/agent/owner.test.ts +0 -78
  711. package/src/frame/agent/vocabulary.test.ts +0 -36
  712. package/src/frame/boot-bundle.test.ts +0 -20
  713. package/src/frame/boot-styles.test.ts +0 -102
  714. package/src/frame/boot.test.ts +0 -108
  715. package/src/frame/export-compiler.test.ts +0 -23
  716. package/src/frame/export.test.ts +0 -17
  717. package/src/frame/tailwind/cache.test.ts +0 -53
  718. package/src/frame/tailwind/load.test.ts +0 -74
  719. package/src/frame/tailwind/runtime-cache.test.ts +0 -97
  720. package/src/frame/tailwind/store.test.ts +0 -104
  721. package/src/frame/tailwind/tailwind.test.ts +0 -119
  722. package/src/host/BuildLog.test.tsx +0 -40
  723. package/src/host/PageFrame.test.tsx +0 -39
  724. package/src/host/activity-state.test.ts +0 -37
  725. package/src/host/agent-source.test.ts +0 -9
  726. package/src/host/agent-validation.test.ts +0 -40
  727. package/src/host/bridge-request.test.ts +0 -87
  728. package/src/host/bridge.test.ts +0 -34
  729. package/src/host/build-log.test.ts +0 -47
  730. package/src/host/clear-cache.test.ts +0 -75
  731. package/src/host/design-validation.test.ts +0 -38
  732. package/src/host/link/transport.test.ts +0 -10
  733. package/src/host/origin.test.ts +0 -10
  734. package/src/host/review/remote.test.ts +0 -21
  735. package/src/host/review/source.test.ts +0 -19
  736. package/src/host/review/validation.test.ts +0 -34
  737. package/src/host/runtime-integration.test.ts +0 -29
  738. package/src/host/source-path.test.ts +0 -14
  739. package/src/host/vocabulary-validation.test.ts +0 -60
  740. package/src/link/build.test.ts +0 -25
  741. package/src/link/commonjs.test.ts +0 -34
  742. package/src/link/overrides.test.ts +0 -103
  743. package/src/link/page-sources.test.ts +0 -52
  744. package/src/publication/publication.test.ts +0 -89
  745. package/src/storage/db.test.ts +0 -52
  746. package/src/sw/activity-router.test.ts +0 -53
  747. package/src/sw/candidates.test.ts +0 -9
  748. package/src/sw/compile.test.ts +0 -152
  749. package/src/sw/compiler.test.ts +0 -51
  750. package/src/sw/composition.test.ts +0 -51
  751. package/src/sw/converted-resolver.test.ts +0 -129
  752. package/src/sw/converted-router.test.ts +0 -91
  753. package/src/sw/converted.test.ts +0 -31
  754. package/src/sw/errors.test.ts +0 -8
  755. package/src/sw/link-activity.test.ts +0 -126
  756. package/src/sw/link-cache.test.ts +0 -15
  757. package/src/sw/link-markdown.test.ts +0 -52
  758. package/src/sw/link-route.test.ts +0 -150
  759. package/src/sw/link-source.test.ts +0 -31
  760. package/src/sw/markers.test.ts +0 -33
  761. package/src/sw/module-transform.test.ts +0 -131
  762. package/src/sw/package-generation.test.ts +0 -33
  763. package/src/sw/page-clients.test.ts +0 -37
  764. package/src/sw/profile.test.ts +0 -21
  765. package/src/sw/resolver.test.ts +0 -183
  766. package/src/sw/router-cache.test.ts +0 -78
  767. package/src/sw/runtime-module.test.ts +0 -61
  768. package/src/sw/source-hash.test.ts +0 -7
  769. package/src/sw/storage.test.ts +0 -108
  770. package/tsconfig.json +0 -10
  771. package/vitest.browser.config.ts +0 -4
  772. package/vitest.config.ts +0 -9
  773. /package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/browser-client.ts +0 -0
  774. /package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/fixtures/copy-to-clipboard-entry.headers +0 -0
  775. /package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/fixtures/copy-to-clipboard-entry.mjs.txt +0 -0
  776. /package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/fixtures/copy-to-clipboard-module.headers +0 -0
  777. /package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/fixtures/copy-to-clipboard-module.mjs.txt +0 -0
  778. /package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/fixtures/react-copy-to-clipboard-entry.headers +0 -0
  779. /package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/fixtures/react-copy-to-clipboard-entry.mjs.txt +0 -0
  780. /package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/fixtures/react-copy-to-clipboard-module.headers +0 -0
  781. /package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/fixtures/react-copy-to-clipboard-module.mjs.txt +0 -0
  782. /package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/fixtures/toggle-selection-entry.headers +0 -0
  783. /package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/fixtures/toggle-selection-entry.mjs.txt +0 -0
  784. /package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/fixtures/toggle-selection-module.headers +0 -0
  785. /package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/fixtures/toggle-selection-module.mjs.txt +0 -0
  786. /package/{spikes/esm-sh → src/sw/esm-sh-fixtures}/redact.ts +0 -0
@@ -0,0 +1,2130 @@
1
+ import { isBuiltin } from "node:module";
2
+ import { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
3
+ import { mkdir, open, readFile, rename, rm, writeFile } from "node:fs/promises";
4
+ import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
5
+ import { createHash, randomUUID } from "node:crypto";
6
+ import { ResolverFactory } from "rolldown/experimental";
7
+ import { parseSync } from "rolldown/utils";
8
+ import { execFileSync } from "node:child_process";
9
+ import { fileURLToPath, pathToFileURL } from "node:url";
10
+ import { rolldown } from "rolldown";
11
+ import { init, parse } from "es-module-lexer";
12
+ import { Worker } from "node:worker_threads";
13
+ // src/build/fragment.ts
14
+ function sorted(record) {
15
+ return Object.fromEntries(Object.entries(record).sort(([a], [b]) => a.localeCompare(b)));
16
+ }
17
+ function fragmentOf(tracer, aliases = {}) {
18
+ return {
19
+ fragment: 1,
20
+ name: tracer.spec.name,
21
+ imports: sorted(tracer.imports),
22
+ scopes: sorted(Object.fromEntries(Object.entries(tracer.scopes).map(([key, table]) => [key, sorted(table)]))),
23
+ remaps: sorted(tracer.remaps),
24
+ aliases,
25
+ inherits: [...tracer.inherited.keys()].sort(),
26
+ integrity: sorted(Object.fromEntries([...tracer.files.values()].map((file) => [file.url, file.integrity]))),
27
+ ...tracer.spec.compiler ? { compiler: tracer.spec.compiler } : {}
28
+ };
29
+ }
30
+ function lookup(table, specifier) {
31
+ const exact = table[specifier];
32
+ if (exact) return exact;
33
+ let best = null;
34
+ for (const key of Object.keys(table)) if (key.endsWith("/") && specifier.startsWith(key) && (!best || key.length > best.length)) best = key;
35
+ return best ? `${table[best]}${specifier.slice(best.length)}` : null;
36
+ }
37
+ /** Resolves a bare specifier the way a browser applies an import map: most specific scope first, then the top level. */
38
+ function resolveSpecifier(map, specifier, referrer) {
39
+ const scopes = Object.keys(map.scopes).filter((scope) => referrer.startsWith(scope)).sort((a, b) => b.length - a.length);
40
+ for (const scope of scopes) {
41
+ const table = map.scopes[scope];
42
+ const resolved = table ? lookup(table, specifier) : null;
43
+ if (resolved) return resolved;
44
+ }
45
+ return lookup(map.imports, specifier);
46
+ }
47
+ /**
48
+ * Composes fragments into one page import map. Fragments are applied in order; a later fragment
49
+ * remapping a specifier or a scope entry is an error, and so is an inherited specifier nobody maps.
50
+ */
51
+ function composeImportMap(fragments, base) {
52
+ const failures = [];
53
+ const url = (value) => `${base}${value}`;
54
+ const map = {
55
+ imports: {},
56
+ scopes: {}
57
+ };
58
+ for (const fragment of fragments) {
59
+ const owned = [];
60
+ for (const [specifier, target] of Object.entries(fragment.imports)) {
61
+ const existing = map.imports[specifier];
62
+ if (existing && existing !== url(target)) failures.push({
63
+ name: fragment.name,
64
+ detail: `remaps ${specifier}: ${existing} → ${url(target)}`
65
+ });
66
+ else map.imports[specifier] = url(target);
67
+ owned.push(specifier);
68
+ }
69
+ for (const [from, to] of Object.entries(fragment.remaps)) {
70
+ const existing = map.imports[url(from)];
71
+ if (existing && existing !== url(to)) failures.push({
72
+ name: fragment.name,
73
+ detail: `remaps ${from} twice: ${existing} and ${url(to)}`
74
+ });
75
+ else map.imports[url(from)] = url(to);
76
+ }
77
+ for (const [alias, prefix] of Object.entries(fragment.aliases)) for (const specifier of owned) {
78
+ if (specifier !== prefix && !specifier.startsWith(`${prefix}/`)) continue;
79
+ const target = map.imports[specifier];
80
+ if (target) map.imports[`${alias}${specifier.slice(prefix.length)}`] = target;
81
+ }
82
+ for (const [scope, table] of Object.entries(fragment.scopes)) {
83
+ const merged = map.scopes[url(scope)] ??= {};
84
+ for (const [specifier, target] of Object.entries(table)) {
85
+ const existing = merged[specifier];
86
+ if (existing && existing !== url(target)) failures.push({
87
+ name: fragment.name,
88
+ detail: `scope ${scope} maps ${specifier} to both ${existing} and ${url(target)}`
89
+ });
90
+ else merged[specifier] = url(target);
91
+ }
92
+ }
93
+ }
94
+ for (const fragment of fragments) for (const specifier of fragment.inherits) if (!lookup(map.imports, specifier)) failures.push({
95
+ name: fragment.name,
96
+ detail: `imports ${specifier}, which no fragment maps at the top level`
97
+ });
98
+ return {
99
+ map,
100
+ failures
101
+ };
102
+ }
103
+ // src/build/module-utils.ts
104
+ function specifierKind$1(specifier) {
105
+ if (/^(\.{1,2}\/|\/)/.test(specifier)) return "relative";
106
+ if (isBuiltin(specifier) || specifier.startsWith("node:")) return "builtin";
107
+ if (/^[a-z][a-z0-9+.-]*:/i.test(specifier)) return "url";
108
+ return "bare";
109
+ }
110
+ const NPM_PREFIX$1 = "/npm/";
111
+ const CANONICAL_CANDIDATES$1 = [
112
+ "",
113
+ ".mjs",
114
+ ".js",
115
+ ".cjs",
116
+ ".json",
117
+ "/index.mjs",
118
+ "/index.js",
119
+ "/index.cjs"
120
+ ];
121
+ // src/build/trace.ts
122
+ const IMPORT_CONDITIONS = [
123
+ "browser",
124
+ "import",
125
+ "module",
126
+ "default"
127
+ ];
128
+ const REQUIRE_CONDITIONS = [
129
+ "browser",
130
+ "require",
131
+ "default"
132
+ ];
133
+ const EMPTY_MODULE = "export default {};\n";
134
+ const JS_EXTENSIONS$1 = /* @__PURE__ */ new Set([
135
+ ".js",
136
+ ".mjs",
137
+ ".cjs"
138
+ ]);
139
+ const NEW_URL = /new URL\(\s*(['"])(\.{1,2}\/[^'"]+)\1\s*,\s*import\.meta\.url\s*\)/g;
140
+ const CSS_IMPORT = /@import\s+(?:url\(\s*)?(?:(['"])(.*?)\1|([^'")\s;]+))/g;
141
+ const CSS_URL = /url\(\s*(['"]?)([^'")]+)\1\s*\)/g;
142
+ function createResolver(conditionNames) {
143
+ return new ResolverFactory({
144
+ conditionNames,
145
+ mainFields: [
146
+ "browser",
147
+ "module",
148
+ "main"
149
+ ],
150
+ aliasFields: [["browser"]],
151
+ extensions: [
152
+ ".mjs",
153
+ ".js",
154
+ ".cjs",
155
+ ".json"
156
+ ],
157
+ symlinks: true
158
+ });
159
+ }
160
+ function resolveBrowser(options) {
161
+ const pkg = packageOf(join(options.fromDir, "package.json"));
162
+ const manifest = JSON.parse(readFileSync(join(pkg.dir, "package.json"), "utf8"));
163
+ const mapping = typeof manifest.browser === "object" ? manifest.browser[options.specifier] : void 0;
164
+ if (mapping === false) return { empty: true };
165
+ if (typeof mapping === "string" && specifierKind$1(mapping) === "builtin") return { builtin: {
166
+ resolved: mapping,
167
+ isRuntimeModule: mapping.startsWith("node:")
168
+ } };
169
+ const result = options.resolver.sync(options.fromDir, options.specifier);
170
+ if (result.error?.startsWith("Path is ignored ")) return { empty: true };
171
+ if (!result.path && isBuiltin(options.specifier)) return { builtin: {
172
+ resolved: options.specifier,
173
+ isRuntimeModule: options.specifier.startsWith("node:")
174
+ } };
175
+ return result;
176
+ }
177
+ function integrityOf(bytes) {
178
+ return `sha384-${createHash("sha384").update(bytes).digest("base64")}`;
179
+ }
180
+ function packageName(specifier) {
181
+ const parts = specifier.split("/");
182
+ return (specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0]) ?? specifier;
183
+ }
184
+ /** The string value of a dynamic import's argument, or null when it is computed. */
185
+ function stringLiteral(expression) {
186
+ const text = expression.trim();
187
+ const quoted = /^(['"])([^'"\\]*)\1$/.exec(text);
188
+ if (quoted) return quoted[2] ?? null;
189
+ const template = /^`([^`$\\]*)`$/.exec(text);
190
+ return template ? template[1] ?? null : null;
191
+ }
192
+ const formats = /* @__PURE__ */ new Map();
193
+ /** Parses a JavaScript file once and classifies it by its syntax, which is what a browser cares about. */
194
+ function moduleFormat(path) {
195
+ const code = readFileSync(path, "utf8");
196
+ const known = formats.get(path);
197
+ if (known?.code === code) return known;
198
+ const parsed = parseSync(path, code, {
199
+ lang: "js",
200
+ sourceType: "unambiguous"
201
+ });
202
+ const commonJsSyntax = /\brequire\s*\(|\bmodule\.exports\b|\bexports\.[\w$]+\s*=|\bexports\[/.test(code);
203
+ if (parsed.errors.length > 0) throw new Error(`${path}: ${parsed.errors.map((error) => error.message).join("; ")}`);
204
+ const result = {
205
+ format: !parsed.module.hasModuleSyntax && commonJsSyntax ? "commonjs" : "esm",
206
+ code,
207
+ module: parsed.module
208
+ };
209
+ formats.set(path, result);
210
+ return result;
211
+ }
212
+ const manifests = /* @__PURE__ */ new Map();
213
+ function manifestAt(dir) {
214
+ if (manifests.has(dir)) return manifests.get(dir) ?? null;
215
+ const file = join(dir, "package.json");
216
+ const manifest = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : {};
217
+ const id = manifest.name && manifest.version ? {
218
+ name: manifest.name,
219
+ version: manifest.version,
220
+ dir
221
+ } : null;
222
+ manifests.set(dir, id);
223
+ return id;
224
+ }
225
+ /**
226
+ * The package that contains `path`: the nearest directory with a named, versioned package.json. Nested
227
+ * manifests without a version (subpath shims) and dependencies a library bundled into its own dist (no
228
+ * manifest at all) belong to the enclosing package.
229
+ */
230
+ function packageOf(path) {
231
+ for (let dir = dirname(path); dir !== dirname(dir); dir = dirname(dir)) {
232
+ const manifest = manifestAt(dir);
233
+ if (manifest) return manifest;
234
+ }
235
+ throw new Error(`${path} is not inside a package`);
236
+ }
237
+ function urlOf(pkg, path) {
238
+ return `${pkg.name}@${pkg.version}/${relative(pkg.dir, path).split(sep).join("/")}`;
239
+ }
240
+ /** Picks an `exports` target for the browser, honouring the package's own condition order. */
241
+ function exportTarget(value) {
242
+ if (typeof value === "string") return value;
243
+ if (Array.isArray(value)) {
244
+ for (const item of value) {
245
+ const target = exportTarget(item);
246
+ if (target) return target;
247
+ }
248
+ return null;
249
+ }
250
+ if (value && typeof value === "object") for (const [condition, nested] of Object.entries(value)) {
251
+ if (!IMPORT_CONDITIONS.includes(condition)) continue;
252
+ const target = exportTarget(nested);
253
+ if (target) return target;
254
+ }
255
+ return null;
256
+ }
257
+ function filesUnder(dir) {
258
+ if (!existsSync(dir)) return [];
259
+ return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
260
+ const path = join(dir, entry.name);
261
+ if (entry.isFile()) return [path];
262
+ return entry.isDirectory() && entry.name !== "node_modules" ? filesUnder(path) : [];
263
+ });
264
+ }
265
+ /** Every entry point a package's `exports` declares for the browser, with `*` patterns expanded. */
266
+ function exportEntries(dir) {
267
+ const manifest = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
268
+ if (manifest.exports === void 0) throw new Error(`${manifest.name} has no exports map`);
269
+ const exportsField = manifest.exports && typeof manifest.exports === "object" && !Array.isArray(manifest.exports) && Object.keys(manifest.exports).some((key) => key.startsWith(".")) ? manifest.exports : { ".": manifest.exports };
270
+ const entries = [];
271
+ for (const [key, value] of Object.entries(exportsField)) {
272
+ const target = exportTarget(value);
273
+ if (!target) continue;
274
+ const specifier = key === "." ? manifest.name : `${manifest.name}${key.slice(1)}`;
275
+ if (!key.includes("*")) {
276
+ entries.push({
277
+ specifier,
278
+ path: join(dir, target)
279
+ });
280
+ continue;
281
+ }
282
+ const [targetPrefix = "", targetSuffix = ""] = target.split("*");
283
+ if (!target.includes("*")) continue;
284
+ const base = join(dir, targetPrefix);
285
+ const search = targetPrefix.endsWith("/") ? base : dirname(base);
286
+ for (const path of filesUnder(search)) {
287
+ if (!path.startsWith(base) || !path.endsWith(targetSuffix) || path.endsWith(".d.ts")) continue;
288
+ const captured = path.slice(base.length, path.length - targetSuffix.length).split(sep).join("/");
289
+ entries.push({
290
+ specifier: specifier.replaceAll("*", () => captured),
291
+ path
292
+ });
293
+ }
294
+ }
295
+ return entries;
296
+ }
297
+ function resolveEntry(resolver, fromDir, specifier) {
298
+ const result = resolver.sync(fromDir, specifier);
299
+ if (!result.path) throw new Error(`cannot resolve ${specifier} from ${fromDir}: ${result.error}`);
300
+ return {
301
+ specifier,
302
+ path: result.path
303
+ };
304
+ }
305
+ /**
306
+ * Traces a fragment's dependency closure: every file a browser loads from the fragment's entries, the bare
307
+ * imports each package needs mapped, and the CommonJS-only entries that must be converted.
308
+ */
309
+ var ClosureTracer = class {
310
+ spec;
311
+ imports = {};
312
+ scopes = {};
313
+ /** URL remaps: CommonJS files that ESM code imports by a relative path, redirected to their converted file. */
314
+ remaps = {};
315
+ /** Relative imports without a file name, by package: the runtime rewrites them to canonical URLs. */
316
+ canonicalRewrites = /* @__PURE__ */ new Map();
317
+ inherited = /* @__PURE__ */ new Map();
318
+ files = /* @__PURE__ */ new Map();
319
+ packages = /* @__PURE__ */ new Map();
320
+ commonJs = /* @__PURE__ */ new Map();
321
+ failures = [];
322
+ untraced = [];
323
+ /** Resources on other origins that traced files load, which the frame's CSP and egress allowlist must permit. */
324
+ external = [];
325
+ resolver = createResolver(IMPORT_CONDITIONS);
326
+ targets = /* @__PURE__ */ new Map();
327
+ queue = [];
328
+ constructor(spec) {
329
+ this.spec = spec;
330
+ }
331
+ trace() {
332
+ for (const entry of this.spec.entries) {
333
+ const url = this.target(entry.path, entry.specifier, "bare");
334
+ if (url) this.mapTopLevel(entry.specifier, url);
335
+ }
336
+ for (const path of this.spec.files ?? []) this.target(path, this.spec.name, "relative");
337
+ this.drain();
338
+ return this;
339
+ }
340
+ traceDependencies(options) {
341
+ const pkg = packageOf(options.path);
342
+ const file = this.files.get(urlOf(pkg, options.path));
343
+ if (!file) throw new Error(`${options.path}: page-styles must be an ESM module`);
344
+ for (const specifier of options.dependencies) this.follow(specifier, file, pkg);
345
+ this.drain();
346
+ }
347
+ emptyModule() {
348
+ if (!this.spec.runtimeBase) throw new Error(`${this.spec.name}: browser:false requires a library runtime set`);
349
+ const url = `${this.spec.runtimeBase}empty.js`;
350
+ this.files.set(url, {
351
+ url,
352
+ path: join(this.spec.resolveFrom, "dist/runtime/empty.js"),
353
+ kind: "esm",
354
+ integrity: integrityOf(EMPTY_MODULE),
355
+ bareImports: []
356
+ });
357
+ return url;
358
+ }
359
+ /** Traces files queued after `trace`, such as ESM packages that converted CommonJS code imports. */
360
+ drain() {
361
+ for (let next = this.queue.shift(); next; next = this.queue.shift()) this.visit(next);
362
+ }
363
+ fail(name, detail) {
364
+ if (!this.failures.some((failure) => failure.name === name && failure.detail === detail)) this.failures.push({
365
+ name,
366
+ detail
367
+ });
368
+ }
369
+ inherit(specifier, importer) {
370
+ const importers = this.inherited.get(specifier) ?? /* @__PURE__ */ new Set();
371
+ importers.add(importer);
372
+ this.inherited.set(specifier, importers);
373
+ }
374
+ mapTopLevel(specifier, url) {
375
+ const existing = this.imports[specifier];
376
+ if (existing && existing !== url) this.fail(specifier, `top-level conflict: ${existing} and ${url}`);
377
+ else this.imports[specifier] = url;
378
+ }
379
+ mapInScope(scope, specifier, url) {
380
+ const table = this.scopes[scope] ??= {};
381
+ const existing = table[specifier];
382
+ if (existing && existing !== url) this.fail(packageName(specifier), `scope ${scope} maps ${specifier} to both ${existing} and ${url}`);
383
+ else table[specifier] = url;
384
+ }
385
+ /** Maps a base-set specifier at the top level, resolved from the fragment root so every importer shares one copy. */
386
+ provideTopLevel(specifier) {
387
+ const known = this.imports[specifier];
388
+ if (known) return known;
389
+ const resolved = this.resolver.sync(this.spec.resolveFrom, specifier);
390
+ if (!resolved.path) {
391
+ this.fail(packageName(specifier), `cannot resolve base-set specifier ${specifier}: ${resolved.error}`);
392
+ return null;
393
+ }
394
+ const url = this.target(resolved.path, specifier, "bare");
395
+ if (url) this.mapTopLevel(specifier, url);
396
+ return url;
397
+ }
398
+ /**
399
+ * Registers a file and returns the URL an import of it maps to: the file itself, or, for a CommonJS-only
400
+ * package entry, its converted file in the runtime set.
401
+ */
402
+ target(path, specifier, via) {
403
+ if (this.targets.has(path)) return this.targets.get(path) ?? null;
404
+ const pkg = packageOf(path);
405
+ this.packages.set(`${pkg.name}@${pkg.version}`, pkg.dir);
406
+ const extension = extname(path);
407
+ let url = urlOf(pkg, path);
408
+ if (JS_EXTENSIONS$1.has(extension)) {
409
+ const parsed = moduleFormat(path);
410
+ if (parsed.format === "esm") this.addFile({
411
+ url,
412
+ path,
413
+ kind: "esm",
414
+ integrity: integrityOf(parsed.code),
415
+ bareImports: []
416
+ }, parsed, pkg);
417
+ else if (via === "bare") url = this.commonJsEntry(path, specifier, pkg);
418
+ else {
419
+ const converted = this.commonJsEntry(path, `${pkg.name}/${relative(pkg.dir, path).split(sep).join("/")}`, pkg);
420
+ if (converted) this.remaps[url] = converted;
421
+ }
422
+ } else if (extension === ".css") this.addCss(path, url, pkg);
423
+ else {
424
+ const kind = extension === ".json" ? "json" : "asset";
425
+ this.addFile({
426
+ url,
427
+ path,
428
+ kind,
429
+ integrity: integrityOf(readFileSync(path)),
430
+ bareImports: []
431
+ }, null, pkg);
432
+ }
433
+ this.targets.set(path, url);
434
+ return url;
435
+ }
436
+ commonJsEntry(path, specifier, pkg) {
437
+ if (!this.spec.runtimeBase) {
438
+ this.fail(pkg.name, `${pkg.name}@${pkg.version} is CommonJS-only; additional packages must ship ESM`);
439
+ return null;
440
+ }
441
+ const subpath = specifier === pkg.name ? "index" : specifier.slice(pkg.name.length + 1).replace(/\.(c|m)?js$/, "");
442
+ const name = `${pkg.name}@${pkg.version}/${subpath}`;
443
+ const url = `${this.spec.runtimeBase}${name}.js`;
444
+ this.commonJs.set(name, {
445
+ specifier,
446
+ path,
447
+ pkg,
448
+ name,
449
+ url
450
+ });
451
+ return url;
452
+ }
453
+ addFile(file, parsed, pkg) {
454
+ this.files.set(file.url, file);
455
+ if (parsed && file.kind === "esm") this.queue.push({
456
+ file,
457
+ code: parsed.code,
458
+ module: parsed.module,
459
+ pkg
460
+ });
461
+ }
462
+ addCss(path, url, pkg) {
463
+ const code = readFileSync(path, "utf8");
464
+ this.files.set(url, {
465
+ url,
466
+ path,
467
+ kind: "css",
468
+ integrity: integrityOf(code),
469
+ bareImports: []
470
+ });
471
+ const imports = new Set([...code.matchAll(CSS_IMPORT)].map((match) => match[2] ?? match[3] ?? ""));
472
+ for (const reference of imports) if (/^https?:/.test(reference)) this.external.push({
473
+ url,
474
+ reference
475
+ });
476
+ else this.target(join(dirname(path), reference), reference, "relative");
477
+ for (const match of code.matchAll(CSS_URL)) {
478
+ const value = match[2] ?? "";
479
+ if (imports.has(value) || !value || /^(data:|#|\/)/.test(value)) continue;
480
+ if (/^https?:/.test(value)) {
481
+ this.external.push({
482
+ url,
483
+ reference: value
484
+ });
485
+ continue;
486
+ }
487
+ const asset = join(dirname(path), value.split(/[?#]/)[0] ?? value);
488
+ if (existsSync(asset)) this.target(asset, value, "relative");
489
+ else this.fail(pkg.name, `${url} references missing asset ${value}`);
490
+ }
491
+ }
492
+ visit({ file, code, module, pkg }) {
493
+ const specifiers = /* @__PURE__ */ new Set();
494
+ for (const item of module.staticImports) specifiers.add(item.moduleRequest.value);
495
+ for (const item of module.staticExports) for (const entry of item.entries) if (entry.moduleRequest) specifiers.add(entry.moduleRequest.value);
496
+ for (const item of module.dynamicImports) {
497
+ const expression = code.slice(item.moduleRequest.start, item.moduleRequest.end);
498
+ const literal = stringLiteral(expression);
499
+ if (literal === null) this.untraced.push({
500
+ url: file.url,
501
+ expression: expression.replace(/\s+/g, " ").slice(0, 120)
502
+ });
503
+ else specifiers.add(literal);
504
+ }
505
+ for (const match of code.matchAll(NEW_URL)) if (match[2]) specifiers.add(match[2]);
506
+ for (const specifier of specifiers) this.follow(specifier, file, pkg);
507
+ }
508
+ follow(specifier, file, pkg) {
509
+ const kind = specifierKind$1(specifier);
510
+ if (kind === "url") return;
511
+ const resolved = resolveBrowser({
512
+ resolver: this.resolver,
513
+ fromDir: dirname(file.path),
514
+ specifier
515
+ });
516
+ if (resolved.empty) {
517
+ const url = this.emptyModule();
518
+ if (kind === "relative") this.remaps[urlOf(pkg, join(dirname(file.path), specifier))] = url;
519
+ else {
520
+ file.bareImports.push(specifier);
521
+ this.mapInScope(`${pkg.name}@${pkg.version}/`, specifier, url);
522
+ }
523
+ return;
524
+ }
525
+ if (resolved.builtin || kind === "builtin" && !resolved.path) {
526
+ this.fail(pkg.name, `${file.url} imports Node built-in ${resolved.builtin?.resolved ?? specifier}`);
527
+ return;
528
+ }
529
+ if (kind === "relative") {
530
+ if (!resolved.path) {
531
+ this.fail(pkg.name, `${file.url} imports missing ${specifier}`);
532
+ return;
533
+ }
534
+ const written = specifier.split(/[?#]/)[0] ?? specifier;
535
+ if (!resolved.path.endsWith(written.replace(/^(\.{1,2}\/)+/, "").split("/").join(sep))) this.canonicalRewrites.set(pkg.name, (this.canonicalRewrites.get(pkg.name) ?? 0) + 1);
536
+ const url = this.target(resolved.path, specifier, "relative");
537
+ const writtenPath = join(dirname(file.path), written);
538
+ if (url && writtenPath !== resolved.path) this.remaps[urlOf(pkg, writtenPath)] = this.remaps[url] ?? url;
539
+ return;
540
+ }
541
+ file.bareImports.push(specifier);
542
+ const name = packageName(specifier);
543
+ if (this.spec.inherits.includes(name)) {
544
+ this.inherit(specifier, file.url);
545
+ return;
546
+ }
547
+ if (this.spec.topLevel.includes(name)) {
548
+ this.provideTopLevel(specifier);
549
+ return;
550
+ }
551
+ if (!resolved.path) {
552
+ this.fail(name, `${file.url} cannot resolve ${specifier} (${resolved.error})`);
553
+ return;
554
+ }
555
+ const url = this.target(resolved.path, specifier, "bare");
556
+ if (url) this.mapInScope(`${pkg.name}@${pkg.version}/`, specifier, url);
557
+ }
558
+ };
559
+ // src/build/barrels.ts
560
+ function importedName(entry) {
561
+ const kind = entry.importName.kind;
562
+ return kind === "NamespaceObject" ? "*" : kind === "Default" ? "default" : entry.importName.name ?? "";
563
+ }
564
+ /**
565
+ * oxc folds `import X from "m"; export { X as Y }` into an export entry placed at the import statement, and names
566
+ * X's local binding as the imported name. The import entry the export points into gives the name `m` exports.
567
+ */
568
+ function forwardedName(entry, declaration) {
569
+ if (entry.importName.kind === "All") return "*";
570
+ if (!declaration) return entry.importName.name ?? "";
571
+ const start = entry.importName.start;
572
+ const binding = declaration.entries.find((candidate) => candidate.localName.start === start || candidate.importName.start === start);
573
+ if (!binding) throw new Error(`export ${entry.exportName.name} folded from the import at ${declaration.start} names no binding of that import`);
574
+ return importedName(binding);
575
+ }
576
+ function shapeOf(module) {
577
+ const imports = /* @__PURE__ */ new Map();
578
+ const declarations = /* @__PURE__ */ new Map();
579
+ const sideEffectImports = [];
580
+ for (const item of module.staticImports) {
581
+ declarations.set(item.start, item);
582
+ if (item.entries.length === 0) sideEffectImports.push(item.moduleRequest.value);
583
+ for (const entry of item.entries) if (!entry.isType) imports.set(entry.localName.value, {
584
+ from: item.moduleRequest.value,
585
+ name: importedName(entry)
586
+ });
587
+ }
588
+ const exports = /* @__PURE__ */ new Map();
589
+ const stars = [];
590
+ for (const item of module.staticExports) {
591
+ const declaration = declarations.get(item.start);
592
+ for (const entry of item.entries) {
593
+ if (entry.isType) continue;
594
+ const request = entry.moduleRequest?.value;
595
+ if (entry.importName.kind === "AllButDefault") {
596
+ if (request) stars.push(request);
597
+ continue;
598
+ }
599
+ const exported = entry.exportName.kind === "Default" ? "default" : entry.exportName.name;
600
+ if (!exported) continue;
601
+ const local = entry.localName.kind === "Name" ? entry.localName.name ?? "default" : "default";
602
+ exports.set(exported, request ? {
603
+ from: request,
604
+ name: forwardedName(entry, declaration)
605
+ } : { name: local });
606
+ }
607
+ }
608
+ return {
609
+ imports,
610
+ exports,
611
+ stars,
612
+ sideEffectImports
613
+ };
614
+ }
615
+ function forwards(shape) {
616
+ return shape.stars.length > 0 || [...shape.exports.values()].some((entry) => entry.from !== void 0);
617
+ }
618
+ /**
619
+ * Follows every forwarding module's exports to the module that defines each name, the way a bundler honouring
620
+ * `sideEffects` skips re-export modules. A hop goes through a module only when that module may be skipped. A name the
621
+ * index cannot place exactly (a namespace, an ambiguous or unresolvable `export *`) stops at the module where the
622
+ * browser's own resolution would continue, which is always safe to import from.
623
+ */
624
+ function buildBarrelIndex(input) {
625
+ const kept = /* @__PURE__ */ new Map();
626
+ const blocked = /* @__PURE__ */ new Set();
627
+ const skippable = (url) => {
628
+ const shape = input.shape(url);
629
+ if (!shape) return false;
630
+ if (!input.sideEffectFree(url)) {
631
+ if (forwards(shape)) blocked.add(url);
632
+ return false;
633
+ }
634
+ if (shape.sideEffectImports.length > 0) {
635
+ kept.set(url, `imports ${shape.sideEffectImports.join(", ")} for its side effects`);
636
+ return false;
637
+ }
638
+ return true;
639
+ };
640
+ const memo = /* @__PURE__ */ new Map();
641
+ const active = /* @__PURE__ */ new Set();
642
+ const locate = (url, name) => {
643
+ const key = `${url}#${name}`;
644
+ if (memo.has(key)) return memo.get(key) ?? null;
645
+ if (active.has(key)) return null;
646
+ active.add(key);
647
+ const location = find(url, name);
648
+ active.delete(key);
649
+ memo.set(key, location);
650
+ return location;
651
+ };
652
+ const find = (url, name) => {
653
+ const shape = input.shape(url);
654
+ if (!shape) return null;
655
+ const here = {
656
+ url,
657
+ name
658
+ };
659
+ const forward = shape.exports.get(name);
660
+ if (forward) {
661
+ if (forward.from === void 0 || forward.name === "*" || !skippable(url)) return here;
662
+ const target = input.resolve(url, forward.from);
663
+ return target && locate(target, forward.name) || here;
664
+ }
665
+ if (name === "default" || shape.stars.length === 0) return null;
666
+ const found = /* @__PURE__ */ new Map();
667
+ let unresolved = false;
668
+ for (const star of shape.stars) {
669
+ const target = input.resolve(url, star);
670
+ if (!target || !input.shape(target)) {
671
+ unresolved = true;
672
+ continue;
673
+ }
674
+ const location = locate(target, name);
675
+ if (location) found.set(`${location.url}#${location.name}`, location);
676
+ }
677
+ if (unresolved || found.size > 1) return here;
678
+ const [only] = found.values();
679
+ if (!only) return null;
680
+ return skippable(url) ? only : here;
681
+ };
682
+ const namesMemo = /* @__PURE__ */ new Map();
683
+ const stack = /* @__PURE__ */ new Set();
684
+ const exportNames = (url) => {
685
+ const known = namesMemo.get(url);
686
+ if (known) return known;
687
+ const shape = input.shape(url);
688
+ const names = new Set(shape?.exports.keys() ?? []);
689
+ if (!shape || stack.has(url)) return names;
690
+ stack.add(url);
691
+ for (const star of shape.stars) {
692
+ const target = input.resolve(url, star);
693
+ for (const name of target ? exportNames(target) : []) if (name !== "default") names.add(name);
694
+ }
695
+ stack.delete(url);
696
+ namesMemo.set(url, names);
697
+ return names;
698
+ };
699
+ const index = {
700
+ modules: [],
701
+ barrels: {}
702
+ };
703
+ const positions = /* @__PURE__ */ new Map();
704
+ let names = 0;
705
+ for (const url of input.urls) {
706
+ const shape = input.shape(url);
707
+ if (!shape || !forwards(shape) || !skippable(url)) continue;
708
+ const entries = {};
709
+ for (const name of exportNames(url)) {
710
+ const location = locate(url, name);
711
+ if (!location || location.url === url) continue;
712
+ let position = positions.get(location.url);
713
+ if (position === void 0) {
714
+ position = index.modules.push(location.url) - 1;
715
+ positions.set(location.url, position);
716
+ }
717
+ entries[name] = location.name === name ? position : [position, location.name];
718
+ names += 1;
719
+ }
720
+ if (Object.keys(entries).length > 0) index.barrels[url] = entries;
721
+ }
722
+ return {
723
+ index,
724
+ kept: [...kept].map(([url, reason]) => ({
725
+ url,
726
+ reason
727
+ })),
728
+ blocked: [...blocked],
729
+ names
730
+ };
731
+ }
732
+ /** Converts a `sideEffects` glob to a RegExp over package-relative paths, with webpack's matching rules. */
733
+ function sideEffectsPattern$1(pattern, id) {
734
+ const glob = pattern.replace(/^\.\//, "");
735
+ const full = glob.includes("/") ? glob : `**/${glob}`;
736
+ let source = "";
737
+ let braces = 0;
738
+ for (let i = 0; i < full.length; i += 1) {
739
+ const char = full[i] ?? "";
740
+ if (char === "*" && full[i + 1] === "*") {
741
+ const slash = full[i + 2] === "/";
742
+ source += slash ? "(?:.*/)?" : ".*";
743
+ i += slash ? 2 : 1;
744
+ } else if (char === "*") source += "[^/]*";
745
+ else if (char === "?") source += "[^/]";
746
+ else if (char === "{") {
747
+ braces += 1;
748
+ source += "(?:";
749
+ } else if (char === "}" && braces > 0) {
750
+ braces -= 1;
751
+ source += ")";
752
+ } else if (char === "," && braces > 0) source += "|";
753
+ else if (char === "[" || char === "]") throw new Error(`${id}: sideEffects pattern ${pattern} uses a character class, which the index does not support`);
754
+ else source += char.replace(/[.+^$()|\\]/g, "\\$&");
755
+ }
756
+ return new RegExp(`^${source}$`);
757
+ }
758
+ /** Whether a package's `sideEffects` declaration lets a bundler skip the file at a package-relative path. */
759
+ function sideEffectsRule$1(declaration, id) {
760
+ if (declaration === false) return () => true;
761
+ if (declaration === void 0 || declaration === true) return () => false;
762
+ if (Array.isArray(declaration) && declaration.every((item) => typeof item === "string")) {
763
+ const patterns = declaration.map((item) => sideEffectsPattern$1(item, id));
764
+ return (path) => !patterns.some((pattern) => pattern.test(path));
765
+ }
766
+ throw new Error(`${id} declares sideEffects as ${JSON.stringify(declaration)}, which is neither a boolean nor a list of globs`);
767
+ }
768
+ /** Builds the barrel index the libraries would publish, over every ESM file of a library set. */
769
+ function libraryBarrelIndex(options) {
770
+ const started = performance.now();
771
+ const shapes = /* @__PURE__ */ new Map();
772
+ const shape = (url) => {
773
+ if (shapes.has(url)) return shapes.get(url) ?? null;
774
+ const file = options.files.get(url);
775
+ const converted = url.includes("/dist/runtime/");
776
+ const value = file && file.kind === "esm" && !converted ? shapeOf(moduleFormat(file.path).module) : null;
777
+ shapes.set(url, value);
778
+ return value;
779
+ };
780
+ const known = (url) => options.files.has(url) || options.remapped.has(url);
781
+ const resolve = (url, specifier) => {
782
+ const kind = specifierKind$1(specifier);
783
+ if (kind === "relative") {
784
+ const path = new URL(specifier, `https://runtime.invalid${NPM_PREFIX$1}${url}`).pathname;
785
+ if (!path.startsWith("/npm/")) return null;
786
+ const resolved = path.slice(5);
787
+ return CANONICAL_CANDIDATES$1.map((suffix) => `${resolved}${suffix}`).find(known) ?? null;
788
+ }
789
+ if (kind !== "bare") return null;
790
+ const target = resolveSpecifier(options.map, specifier, `${NPM_PREFIX$1}${url}`);
791
+ return target?.startsWith("/npm/") ? target.slice(5) : null;
792
+ };
793
+ const rules = /* @__PURE__ */ new Map();
794
+ const owner = (url) => {
795
+ const file = options.files.get(url);
796
+ if (!file) throw new Error(`${url} is not in the library set`);
797
+ return packageOf(file.path);
798
+ };
799
+ const sideEffectFree = (url) => {
800
+ const pkg = owner(url);
801
+ let rule = rules.get(pkg.dir);
802
+ if (!rule) {
803
+ rule = sideEffectsRule$1(JSON.parse(readFileSync(join(pkg.dir, "package.json"), "utf8")).sideEffects, `${pkg.name}@${pkg.version}`);
804
+ rules.set(pkg.dir, rule);
805
+ }
806
+ return rule(url.slice(`${pkg.name}@${pkg.version}/`.length));
807
+ };
808
+ const built = buildBarrelIndex({
809
+ urls: [...options.files.keys()].filter((url) => shape(url) !== null),
810
+ shape,
811
+ resolve,
812
+ sideEffectFree
813
+ });
814
+ const undeclared = {};
815
+ for (const url of built.blocked) {
816
+ const pkg = owner(url);
817
+ const id = `${pkg.name}@${pkg.version}`;
818
+ undeclared[id] = (undeclared[id] ?? 0) + 1;
819
+ }
820
+ return {
821
+ ...built,
822
+ undeclared,
823
+ ms: Math.round(performance.now() - started),
824
+ bytes: Buffer.byteLength(JSON.stringify(built.index))
825
+ };
826
+ }
827
+ // src/build/errors.ts
828
+ var NodeBuiltinError = class extends Error {
829
+ name = "NodeBuiltinError";
830
+ };
831
+ var CommonJsConversionError = class extends Error {
832
+ name = "CommonJsConversionError";
833
+ };
834
+ var BaseSetRemapError = class extends Error {
835
+ name = "BaseSetRemapError";
836
+ };
837
+ // src/build/convert-commonjs.ts
838
+ const ENTRY = "\0runtime-entry:";
839
+ const REQUIRE_EXTERNAL = "\0runtime-require:";
840
+ const EMPTY = "\0runtime-empty";
841
+ const IDENTIFIER$1 = /^[A-Za-z_$][\w$]*$/;
842
+ const JS_EXTENSIONS = /* @__PURE__ */ new Set([
843
+ ".js",
844
+ ".mjs",
845
+ ".cjs"
846
+ ]);
847
+ const LEFTOVER_REQUIRE = /(?<![\w$.])__require\s*\(/;
848
+ const here = dirname(fileURLToPath(import.meta.url));
849
+ function exportNames(entries) {
850
+ const output = execFileSync(process.execPath, [join(here, "cjs-export-names.mjs")], {
851
+ input: JSON.stringify(entries.map((entry) => entry.path)),
852
+ env: {
853
+ ...process.env,
854
+ NODE_ENV: "development"
855
+ },
856
+ encoding: "utf8",
857
+ stdio: [
858
+ "pipe",
859
+ "pipe",
860
+ "ignore"
861
+ ],
862
+ maxBuffer: 67108864,
863
+ timeout: 3e4
864
+ });
865
+ const result = JSON.parse(output);
866
+ for (const entry of entries) {
867
+ const item = result[entry.path];
868
+ if (!item?.names || item.error) throw new CommonJsConversionError(`${entry.pkg.name}: listing ${entry.specifier} exports threw: ${item?.error ?? "no export list returned"}`);
869
+ }
870
+ return result;
871
+ }
872
+ /** The ESM face of one CommonJS entry: its `module.exports` as the default export plus an explicit named-export list. */
873
+ function entrySource(entry, names) {
874
+ const exported = names.filter((name) => name !== "default" && name !== "__esModule");
875
+ const lines = [`import * as ns from ${JSON.stringify(entry.path)};`];
876
+ lines.push("export default ns.default;");
877
+ exported.forEach((name, index) => lines.push(`const __e${index} = ns[${JSON.stringify(name)}];`));
878
+ if (exported.length > 0) {
879
+ const specifiers = exported.map((name, index) => `__e${index} as ${IDENTIFIER$1.test(name) ? name : JSON.stringify(name)}`);
880
+ lines.push(`export { ${specifiers.join(", ")} };`);
881
+ }
882
+ return `${lines.join("\n")}\n`;
883
+ }
884
+ /**
885
+ * Resolves cross-package `require`s through a CommonJS adapter that imports the shared ESM copy,
886
+ * preserving module.exports identity instead of converting an ESM namespace back to CommonJS.
887
+ */
888
+ function runtimeSetPlugin(tracer, names) {
889
+ const { runtimeBase, inherits, topLevel } = tracer.spec;
890
+ if (!runtimeBase) throw new Error(`${tracer.spec.name} has no runtime set to convert CommonJS into`);
891
+ const requireResolver = createResolver(REQUIRE_CONDITIONS);
892
+ const external = (options) => options.kind === "require-call" ? `${REQUIRE_EXTERNAL}${JSON.stringify(options)}` : {
893
+ id: options.source,
894
+ external: true
895
+ };
896
+ return {
897
+ name: "page-runtime-set",
898
+ resolveId(source, importer, { kind }) {
899
+ if (source === EMPTY || source.startsWith(ENTRY) || source.startsWith(REQUIRE_EXTERNAL)) return source;
900
+ if (!importer || importer.startsWith(ENTRY)) return null;
901
+ if (importer.startsWith(REQUIRE_EXTERNAL)) return {
902
+ id: source,
903
+ external: true
904
+ };
905
+ const from = packageOf(importer);
906
+ const resolved = resolveBrowser({
907
+ resolver: kind === "require-call" ? requireResolver : tracer.resolver,
908
+ fromDir: dirname(importer),
909
+ specifier: source
910
+ });
911
+ if (resolved.empty) return EMPTY;
912
+ if (resolved.builtin || specifierKind$1(source) === "builtin" && !resolved.path) {
913
+ tracer.fail(from.name, `CommonJS code in ${from.name}@${from.version} requires Node built-in ${resolved.builtin?.resolved ?? source}`);
914
+ return {
915
+ id: source,
916
+ external: true
917
+ };
918
+ }
919
+ if (specifierKind$1(source) === "relative") return null;
920
+ const name = packageName(source);
921
+ if (inherits.includes(name)) {
922
+ tracer.inherit(source, runtimeBase);
923
+ return external({
924
+ source,
925
+ kind,
926
+ ...resolved.path ? { path: resolved.path } : {}
927
+ });
928
+ }
929
+ if (topLevel.includes(name)) {
930
+ if (!tracer.provideTopLevel(source)) throw new Error(`cannot resolve base-set entry ${source}`);
931
+ return external({
932
+ source,
933
+ kind,
934
+ ...resolved.path ? { path: resolved.path } : {}
935
+ });
936
+ }
937
+ if (!resolved.path) {
938
+ tracer.fail(name, `CommonJS code in ${from.name}@${from.version} requires ${source}, which does not resolve (${resolved.error})`);
939
+ return {
940
+ id: source,
941
+ external: true
942
+ };
943
+ }
944
+ if (!JS_EXTENSIONS.has(extname(resolved.path))) return resolved.path;
945
+ const url = tracer.target(resolved.path, source, "bare");
946
+ const owner = `${from.name}@${from.version}`;
947
+ if (url) tracer.mapInScope(`${runtimeBase}${owner}/`, source, url);
948
+ return external({
949
+ source,
950
+ kind,
951
+ path: resolved.path,
952
+ owner
953
+ });
954
+ },
955
+ load(id) {
956
+ if (id === EMPTY) return "module.exports = {};";
957
+ if (id.startsWith(ENTRY)) {
958
+ const entry = tracer.commonJs.get(id.slice(15));
959
+ if (!entry) throw new Error(`unknown runtime-set entry ${id}`);
960
+ const exported = names[entry.path]?.names;
961
+ if (!exported) throw new CommonJsConversionError(`${entry.specifier}: missing explicit export list`);
962
+ return entrySource(entry, exported);
963
+ }
964
+ if (id.startsWith(REQUIRE_EXTERNAL)) {
965
+ const { source, path } = JSON.parse(id.slice(17));
966
+ return `import * as ns from ${JSON.stringify(source)};\nmodule.exports = ${path && moduleFormat(path).format === "commonjs" ? "ns.default" : "ns"};\n`;
967
+ }
968
+ return null;
969
+ }
970
+ };
971
+ }
972
+ function chunkFileName(chunk) {
973
+ const owners = /* @__PURE__ */ new Set();
974
+ for (const id of chunk.moduleIds) if (id.startsWith(REQUIRE_EXTERNAL)) {
975
+ const { owner } = JSON.parse(id.slice(17));
976
+ if (owner) owners.add(owner);
977
+ } else if (isAbsolute(id) && JS_EXTENSIONS.has(extname(id))) {
978
+ const pkg = packageOf(id);
979
+ owners.add(`${pkg.name}@${pkg.version}`);
980
+ }
981
+ if (owners.size > 1) throw new CommonJsConversionError(`shared chunk ${chunk.name} combines dependency scopes ${[...owners].join(", ")}`);
982
+ const [owner] = owners;
983
+ return `${owner ? `${owner}/` : ""}_chunks/[name]-[hash].js`;
984
+ }
985
+ async function build(tracer, names, outDir) {
986
+ const entries = [...tracer.commonJs.values()];
987
+ const bundle = await rolldown({
988
+ input: Object.fromEntries(entries.map((entry) => [entry.name, `${ENTRY}${entry.name}`])),
989
+ plugins: [runtimeSetPlugin(tracer, names)],
990
+ platform: "browser",
991
+ transform: { define: { "process.env.NODE_ENV": JSON.stringify("development") } },
992
+ logLevel: "silent"
993
+ });
994
+ const options = {
995
+ format: "esm",
996
+ entryFileNames: "[name].js",
997
+ chunkFileNames: chunkFileName
998
+ };
999
+ try {
1000
+ return (outDir ? await bundle.write({
1001
+ ...options,
1002
+ dir: outDir
1003
+ }) : await bundle.generate(options)).output;
1004
+ } finally {
1005
+ await bundle.close();
1006
+ }
1007
+ }
1008
+ function register(tracer, outDir, output) {
1009
+ const fileNames = new Set(output.map((item) => item.fileName));
1010
+ let bytes = 0;
1011
+ for (const item of output) {
1012
+ if (item.type !== "chunk") throw new Error(`converting CommonJS emitted an asset: ${item.fileName}`);
1013
+ const url = `${tracer.spec.runtimeBase}${item.fileName}`;
1014
+ const leftover = item.code.split("\n").find((line) => LEFTOVER_REQUIRE.test(line));
1015
+ if (leftover) {
1016
+ const owners = [...new Set(item.moduleIds.filter((id) => !id.startsWith("\0")).map((id) => packageOf(id).name))];
1017
+ tracer.fail(owners.join(", "), `${url} still calls require through rolldown's shim: ${leftover.trim().slice(0, 160)}`);
1018
+ }
1019
+ const bareImports = [...item.imports, ...item.dynamicImports].filter((id) => !fileNames.has(id));
1020
+ tracer.files.set(url, {
1021
+ url,
1022
+ path: join(outDir, item.fileName),
1023
+ kind: "esm",
1024
+ integrity: integrityOf(item.code),
1025
+ bareImports
1026
+ });
1027
+ bytes += Buffer.byteLength(item.code);
1028
+ }
1029
+ return bytes;
1030
+ }
1031
+ /**
1032
+ * Converts every CommonJS-only entry the tracer found into the development runtime set. Converting
1033
+ * can reach ESM packages, whose imports can reach more CommonJS entries, so discovery repeats until it is stable.
1034
+ */
1035
+ async function convertCommonJs(tracer, outDir) {
1036
+ if (tracer.commonJs.size === 0) return [];
1037
+ for (let known = -1; known !== tracer.commonJs.size;) {
1038
+ known = tracer.commonJs.size;
1039
+ await build(tracer, exportNames([...tracer.commonJs.values()]), null);
1040
+ tracer.drain();
1041
+ }
1042
+ const started = performance.now();
1043
+ const entries = [...tracer.commonJs.values()];
1044
+ const output = await build(tracer, exportNames(entries), outDir);
1045
+ const bytes = register(tracer, outDir, output);
1046
+ return [{
1047
+ entries: entries.length,
1048
+ chunks: output.length,
1049
+ bytes,
1050
+ ms: Math.round(performance.now() - started)
1051
+ }];
1052
+ }
1053
+ // src/build/recipe-dependencies.ts
1054
+ async function traceRecipeDependencies(tracer) {
1055
+ const entry = tracer.spec.entries.find(({ specifier }) => specifier === `${tracer.spec.name}/page-styles`);
1056
+ if (!entry) return;
1057
+ const loaded = await import(pathToFileURL(entry.path).href);
1058
+ const recipe = loaded.pageStyles ?? loaded.default;
1059
+ if (!recipe || !Array.isArray(recipe.runtimeDependencies) || recipe.runtimeDependencies.some((value) => typeof value !== "string" || !value || /^[a-z][a-z0-9+.-]*:/i.test(value))) throw new Error(`${entry.specifier}: runtimeDependencies must declare package specifiers or relative files`);
1060
+ tracer.traceDependencies({
1061
+ path: entry.path,
1062
+ dependencies: recipe.runtimeDependencies
1063
+ });
1064
+ }
1065
+ // src/sw/versions.ts
1066
+ function version(text) {
1067
+ const match = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([\w.-]+))?(?:\+[\w.-]+)?$/.exec(text);
1068
+ if (!match) throw new Error(`invalid semantic version ${text}`);
1069
+ return {
1070
+ parts: [
1071
+ Number(match[1]),
1072
+ Number(match[2]),
1073
+ Number(match[3])
1074
+ ],
1075
+ pre: match[4]?.split(".") ?? []
1076
+ };
1077
+ }
1078
+ function compare(a, b) {
1079
+ for (let i = 0; i < 3; i++) if (a.parts[i] !== b.parts[i]) return a.parts[i] - b.parts[i];
1080
+ if (!a.pre.length || !b.pre.length) return Number(!a.pre.length) - Number(!b.pre.length);
1081
+ for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
1082
+ const x = a.pre[i];
1083
+ const y = b.pre[i];
1084
+ if (x === y) continue;
1085
+ if (x === void 0 || y === void 0) return x === void 0 ? -1 : 1;
1086
+ if (/^\d+$/.test(x) && /^\d+$/.test(y)) return Number(x) - Number(y);
1087
+ if (/^\d+$/.test(x) !== /^\d+$/.test(y)) return /^\d+$/.test(x) ? -1 : 1;
1088
+ return x < y ? -1 : 1;
1089
+ }
1090
+ return 0;
1091
+ }
1092
+ function partial(text) {
1093
+ const match = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(-[\w.-]+)?(?:\+[\w.-]+)?$/.exec(text);
1094
+ if (!match) throw new Error(`invalid semantic range ${text}`);
1095
+ const parts = match.slice(1, 4);
1096
+ let count = parts.findIndex((p) => p === void 0 || /[xX*]/.test(p));
1097
+ if (count === -1) count = 3;
1098
+ if (parts.slice(count).some((p) => p !== void 0 && !/[xX*]/.test(p))) throw new Error(`invalid semantic range ${text}`);
1099
+ return {
1100
+ v: version(`${parts.map((p, i) => i < count ? p : "0").join(".")}${match[4] ?? ""}`),
1101
+ count
1102
+ };
1103
+ }
1104
+ function upper(v, index) {
1105
+ return {
1106
+ parts: v.parts.map((n, i) => i < index ? n : i === index ? n + 1 : 0),
1107
+ pre: ["0"]
1108
+ };
1109
+ }
1110
+ function comparator(actual, token) {
1111
+ const match = /^(\^|~|>=|<=|>|<|=)?(.+)$/.exec(token);
1112
+ if (!match?.[2]) throw new Error(`invalid semantic range ${token}`);
1113
+ const op = match[1] ?? "=";
1114
+ const { v, count } = partial(match[2]);
1115
+ if (!count) return op !== ">" && op !== "<";
1116
+ const c = compare(actual, v);
1117
+ if (op === "^") {
1118
+ const first = v.parts.findIndex((n, i) => n > 0 || i === count - 1);
1119
+ return c >= 0 && compare(actual, upper(v, first)) < 0;
1120
+ }
1121
+ if (op === "~") return c >= 0 && compare(actual, upper(v, Math.min(count - 1, 1))) < 0;
1122
+ if (op === "=") return count === 3 ? c === 0 : c >= 0 && compare(actual, upper(v, count - 1)) < 0;
1123
+ if (op === ">=") return c >= 0;
1124
+ if (op === "<") return c < 0;
1125
+ if (op === ">") return count === 3 ? c > 0 : compare(actual, upper(v, count - 1)) >= 0;
1126
+ return count === 3 ? c <= 0 : compare(actual, upper(v, count - 1)) < 0;
1127
+ }
1128
+ function rangeTokens(branch) {
1129
+ const words = branch.trim().split(/\s+/);
1130
+ const expanded = [];
1131
+ for (let i = 0; i < words.length; i += 1) {
1132
+ const lo = words[i];
1133
+ const hi = words[i + 2];
1134
+ if (words[i + 1] === "-" && hi !== void 0) {
1135
+ const end = partial(hi);
1136
+ expanded.push(`>=${partial(lo).v.parts.join(".")}`, end.count === 3 ? `<=${hi}` : `<${upper(end.v, end.count - 1).parts.join(".")}-0`);
1137
+ i += 2;
1138
+ } else expanded.push(lo);
1139
+ }
1140
+ const normalized = expanded.join(" ").replace(/(\^|~|>=|<=|>|<|=)\s+/g, "$1");
1141
+ return normalized ? normalized.split(/\s+/) : ["*"];
1142
+ }
1143
+ function satisfiesVersion(text, range) {
1144
+ const actual = version(text);
1145
+ return range.split("||").some((branch) => {
1146
+ const tokens = rangeTokens(branch);
1147
+ if (actual.pre.length && !tokens.some((token) => {
1148
+ const target = partial(token.replace(/^(\^|~|>=|<=|>|<|=)/, "")).v;
1149
+ return target.pre.length && target.parts.every((n, i) => n === actual.parts[i]);
1150
+ })) return false;
1151
+ return tokens.every((token) => comparator(actual, token));
1152
+ });
1153
+ }
1154
+ // src/sw/profile.ts
1155
+ function record(value, path) {
1156
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${path}: expected an object`);
1157
+ return value;
1158
+ }
1159
+ function keys(value, allowed, path) {
1160
+ for (const key of Object.keys(value)) if (!allowed.includes(key)) throw new Error(`${path}.${key}: unknown key`);
1161
+ }
1162
+ // src/host/message-values.ts
1163
+ function validateJson(value, depth = 0) {
1164
+ if (depth > 50) throw new Error("data: maximum nesting exceeded");
1165
+ if (value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value)) return;
1166
+ if (Array.isArray(value)) {
1167
+ value.forEach((v) => validateJson(v, depth + 1));
1168
+ return;
1169
+ }
1170
+ for (const item of Object.values(record(value, "data"))) validateJson(item, depth + 1);
1171
+ }
1172
+ // src/sw/compiler-plugins.ts
1173
+ /** Validates a library's compiler plugin declaration; a library may only contribute modules it exports itself. */
1174
+ function validateCompilerPlugins(value, options) {
1175
+ const declared = record(value, options.path);
1176
+ keys(declared, ["remark"], options.path);
1177
+ if (!Array.isArray(declared.remark) || !declared.remark.length) throw new Error(`${options.path}.remark: expected a non-empty array of plugins`);
1178
+ for (const [index, entry] of declared.remark.entries()) {
1179
+ const path = `${options.path}.remark[${index}]`;
1180
+ const plugin = record(entry, path);
1181
+ keys(plugin, ["module", "options"], path);
1182
+ if (typeof plugin.module !== "string" || !plugin.module.startsWith(`${options.library}/`)) throw new Error(`${path}.module: expected a ${options.library}/… module the library exports, got ${String(plugin.module)}`);
1183
+ if (plugin.options !== void 0) validateJson(plugin.options);
1184
+ }
1185
+ return declared;
1186
+ }
1187
+ // src/build/base.ts
1188
+ const BASE_PACKAGES = [
1189
+ "react",
1190
+ "react-dom",
1191
+ "scheduler",
1192
+ "@tanstack/react-query",
1193
+ "jotai"
1194
+ ];
1195
+ const BASE_ENTRIES = [
1196
+ "react",
1197
+ "react/jsx-runtime",
1198
+ "react/jsx-dev-runtime",
1199
+ "react-dom",
1200
+ "react-dom/client",
1201
+ "react-dom/server",
1202
+ "scheduler",
1203
+ "@tanstack/react-query",
1204
+ "jotai"
1205
+ ];
1206
+ // src/build/library-runtime.ts
1207
+ function librarySpec(options) {
1208
+ const dir = realpathSync(options.libraryDir);
1209
+ const manifest = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
1210
+ if (!manifest.name || !manifest.version) throw new Error(`${dir}/package.json must declare name and version`);
1211
+ const exported = exportEntries(dir);
1212
+ const compiler = manifest.pageRuntime?.compiler === void 0 ? void 0 : validateCompilerPlugins(manifest.pageRuntime.compiler, {
1213
+ library: manifest.name,
1214
+ path: `${manifest.name} package.json pageRuntime.compiler`
1215
+ });
1216
+ const entries = exported.filter(({ path, specifier }) => !options.exclude?.includes(specifier) && path.startsWith(`${join(dir, "dist")}${sep}`) && !path.startsWith(`${join(dir, "dist/runtime")}${sep}`));
1217
+ if (!entries.length) throw new Error(`${manifest.name}: no browser exports in dist; build the library first`);
1218
+ for (const plugin of compiler?.remark ?? []) {
1219
+ const entry = exported.find(({ specifier }) => specifier === plugin.module);
1220
+ if (!entry) throw new Error(`${manifest.name}: compiler plugin ${plugin.module} is not in package.json exports`);
1221
+ if (!entries.some(({ specifier }) => specifier === entry.specifier)) entries.push(entry);
1222
+ }
1223
+ const exportedDirs = [...new Set(entries.filter(({ path }) => /\.m?js$/.test(path)).map(({ path }) => dirname(path)))];
1224
+ const excluded = exported.filter(({ specifier }) => options.exclude?.includes(specifier));
1225
+ const excludedDirs = excluded.map(({ path }) => dirname(path)).filter((dir) => !entries.some((entry) => entry.path.startsWith(`${dir}${sep}`)));
1226
+ const files = readdirSync(join(dir, "dist"), {
1227
+ recursive: true,
1228
+ encoding: "utf8"
1229
+ }).filter((path) => !path.startsWith(`runtime${sep}`) && /\.(m?js)$/.test(path)).map((path) => join(dir, "dist", path)).filter((path) => !excluded.some((entry) => entry.path === path) && !excludedDirs.some((dir) => path.startsWith(`${dir}${sep}`))).filter((path) => exportedDirs.some((exported) => path.startsWith(`${exported}${sep}`)));
1230
+ const providesBase = !options.base && manifest.name === "@flanksource/clicky-ui";
1231
+ if (providesBase) {
1232
+ const resolver = createResolver(IMPORT_CONDITIONS);
1233
+ for (const specifier of BASE_ENTRIES) {
1234
+ const from = specifier === "scheduler" ? realpathSync(join(dir, "node_modules/react-dom")) : dir;
1235
+ entries.push(resolveEntry(resolver, from, specifier));
1236
+ }
1237
+ }
1238
+ return {
1239
+ name: manifest.name,
1240
+ resolveFrom: dir,
1241
+ runtimeBase: `${manifest.name}@${manifest.version}/dist/runtime/`,
1242
+ entries,
1243
+ files,
1244
+ topLevel: providesBase ? BASE_PACKAGES : [],
1245
+ inherits: options.base ? [...new Set(Object.keys(options.base.imports).map(packageName))] : [],
1246
+ ...compiler ? { compiler } : {}
1247
+ };
1248
+ }
1249
+ function assertTrace(tracer) {
1250
+ if (!tracer.failures.length) return;
1251
+ const message = tracer.failures.map(({ name, detail }) => `${name}: ${detail}`).join("\n");
1252
+ if (/Node built-in|requires node:/.test(message)) throw new NodeBuiltinError(message);
1253
+ if (/still calls require/.test(message)) throw new CommonJsConversionError(message);
1254
+ throw new Error(message);
1255
+ }
1256
+ function assertBase(options, fragment) {
1257
+ if (!options.base) return;
1258
+ const inherited = new Set(Object.keys(options.base.imports).map(packageName));
1259
+ for (const table of [
1260
+ fragment.imports,
1261
+ ...Object.values(fragment.scopes),
1262
+ fragment.aliases
1263
+ ]) for (const specifier of Object.keys(table)) if (inherited.has(packageName(specifier))) throw new BaseSetRemapError(`${fragment.name} remaps base-set specifier ${specifier} from ${options.base.name}`);
1264
+ for (const url of Object.keys(fragment.remaps)) if ([...inherited].some((name) => url.startsWith(`${name}@`))) throw new BaseSetRemapError(`${fragment.name} remaps base-set URL ${url} from ${options.base.name}`);
1265
+ for (const specifier of fragment.inherits) if (!options.base.imports[specifier]) throw new BaseSetRemapError(`${fragment.name} inherits ${specifier}, which ${options.base.name} does not provide`);
1266
+ }
1267
+ async function buildLibraryRuntime(options) {
1268
+ const tracer = new ClosureTracer(librarySpec(options)).trace();
1269
+ await traceRecipeDependencies(tracer);
1270
+ assertTrace(tracer);
1271
+ assertBase(options, fragmentOf(tracer, options.aliases));
1272
+ await rm(options.outDir, {
1273
+ recursive: true,
1274
+ force: true
1275
+ });
1276
+ await mkdir(options.outDir, { recursive: true });
1277
+ try {
1278
+ await convertCommonJs(tracer, resolve(options.outDir));
1279
+ } catch (cause) {
1280
+ assertTrace(tracer);
1281
+ if (cause instanceof CommonJsConversionError) throw cause;
1282
+ throw new CommonJsConversionError(`${tracer.spec.name}: converting ${[...tracer.commonJs.values()].map((entry) => entry.specifier).join(", ")}: ${String(cause)}`, { cause });
1283
+ }
1284
+ assertTrace(tracer);
1285
+ const fragment = fragmentOf(tracer, options.aliases);
1286
+ if (fragment.integrity[`${tracer.spec.runtimeBase}empty.js`]) await writeFile(join(options.outDir, "empty.js"), EMPTY_MODULE);
1287
+ assertBase(options, fragment);
1288
+ const composed = composeImportMap(options.base ? [options.base, fragment] : [fragment], "/npm/");
1289
+ if (composed.failures.length) throw new BaseSetRemapError(composed.failures.map((failure) => failure.detail).join("\n"));
1290
+ const barrels = libraryBarrelIndex({
1291
+ files: tracer.files,
1292
+ remapped: new Set(Object.keys(fragment.remaps)),
1293
+ map: composed.map
1294
+ }).index;
1295
+ await writeFile(join(options.outDir, "importmap.json"), `${JSON.stringify(fragment, null, 2)}\n`);
1296
+ await writeFile(join(options.outDir, "barrels.json"), `${JSON.stringify(barrels, null, 2)}\n`);
1297
+ return {
1298
+ fragment,
1299
+ barrels
1300
+ };
1301
+ }
1302
+ // src/sw/barrels.ts
1303
+ function sideEffectsPattern(pattern, id) {
1304
+ const glob = pattern.replace(/^\.\//, "");
1305
+ const full = glob.includes("/") ? glob : `**/${glob}`;
1306
+ let source = "";
1307
+ let braces = 0;
1308
+ for (let i = 0; i < full.length; i += 1) {
1309
+ const char = full[i] ?? "";
1310
+ if (char === "*" && full[i + 1] === "*") {
1311
+ const slash = full[i + 2] === "/";
1312
+ source += slash ? "(?:.*/)?" : ".*";
1313
+ i += slash ? 2 : 1;
1314
+ } else if (char === "*") source += "[^/]*";
1315
+ else if (char === "?") source += "[^/]";
1316
+ else if (char === "{") {
1317
+ braces += 1;
1318
+ source += "(?:";
1319
+ } else if (char === "}" && braces > 0) {
1320
+ braces -= 1;
1321
+ source += ")";
1322
+ } else if (char === "," && braces > 0) source += "|";
1323
+ else if (char === "[" || char === "]") throw new Error(`${id}: sideEffects pattern ${pattern} uses a character class, which the index does not support`);
1324
+ else source += char.replace(/[.+^$()|\\]/g, "\\$&");
1325
+ }
1326
+ return new RegExp(`^${source}$`);
1327
+ }
1328
+ /** Whether a package's `sideEffects` declaration lets a bundler skip the file at a package-relative path. */
1329
+ function sideEffectsRule(declaration, id) {
1330
+ if (declaration === false) return () => true;
1331
+ if (declaration === void 0 || declaration === true) return () => false;
1332
+ if (Array.isArray(declaration) && declaration.every((item) => typeof item === "string")) {
1333
+ const patterns = declaration.map((item) => sideEffectsPattern(item, id));
1334
+ return (path) => !patterns.some((pattern) => pattern.test(path));
1335
+ }
1336
+ throw new Error(`${id} declares sideEffects as ${JSON.stringify(declaration)}, which is neither a boolean nor a list of globs`);
1337
+ }
1338
+ function guardedBarrels(options) {
1339
+ const root = `${options.name}@${options.version}/`;
1340
+ const free = sideEffectsRule(options.sideEffects, root);
1341
+ return {
1342
+ modules: options.index.modules,
1343
+ barrels: Object.fromEntries(Object.entries(options.index.barrels).filter(([url]) => !url.startsWith(root) || free(url.slice(root.length))))
1344
+ };
1345
+ }
1346
+ // src/sw/composition.ts
1347
+ function mergeBarrels(indices) {
1348
+ const result = {
1349
+ modules: [],
1350
+ barrels: {}
1351
+ };
1352
+ const positions = /* @__PURE__ */ new Map();
1353
+ const position = (module) => {
1354
+ const existing = positions.get(module);
1355
+ if (existing !== void 0) return existing;
1356
+ positions.set(module, result.modules.push(module) - 1);
1357
+ return result.modules.length - 1;
1358
+ };
1359
+ const describe = (entries, modules) => JSON.stringify(Object.entries(entries).sort(([a], [b]) => a.localeCompare(b)).map(([name, at]) => [name, typeof at === "number" ? modules[at] : [modules[at[0]], at[1]]]));
1360
+ for (const index of indices) for (const [path, entries] of Object.entries(index.barrels)) {
1361
+ const remapped = Object.fromEntries(Object.entries(entries).map(([name, at]) => {
1362
+ const module = index.modules[typeof at === "number" ? at : at[0]];
1363
+ if (module === void 0) throw new Error(`barrel ${path}: ${name} points outside its module list`);
1364
+ return [name, typeof at === "number" ? position(module) : [position(module), at[1]]];
1365
+ }));
1366
+ const existing = result.barrels[path];
1367
+ if (existing && describe(existing, result.modules) !== describe(remapped, result.modules)) throw new Error(`barrel ${path} is indexed differently by two libraries`);
1368
+ result.barrels[path] = remapped;
1369
+ }
1370
+ return result;
1371
+ }
1372
+ // src/sw/module-transform.ts
1373
+ function specifierKind(specifier) {
1374
+ if (/^(\.{1,2}\/|\/)/.test(specifier)) return "relative";
1375
+ if (specifier.startsWith("node:")) return "builtin";
1376
+ if (/^[a-z][a-z0-9+.-]*:/i.test(specifier)) return "url";
1377
+ return "bare";
1378
+ }
1379
+ const NPM_PREFIX = "/npm/";
1380
+ /** Suffixes tried for a relative import that names no file, in the build tool's resolution order. */
1381
+ const CANONICAL_CANDIDATES = [
1382
+ "",
1383
+ ".mjs",
1384
+ ".js",
1385
+ ".cjs",
1386
+ ".json",
1387
+ "/index.mjs",
1388
+ "/index.js",
1389
+ "/index.cjs"
1390
+ ];
1391
+ const IDENTIFIER = String.raw`[\p{ID_Start}$_][\p{ID_Continue}$‌‍]*`;
1392
+ const MODULE_NAME = String.raw`(?:${IDENTIFIER}|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')`;
1393
+ const DEFAULT_BINDING = new RegExp(String.raw`^(${IDENTIFIER})\s*(?:,\s*|$)`, "u");
1394
+ const NAMESPACE_BINDING = new RegExp(String.raw`^\*\s*as\s+(${IDENTIFIER})$`, "u");
1395
+ const NAMED_BINDING = new RegExp(String.raw`^(${MODULE_NAME})(?:\s+as\s+(${MODULE_NAME}))?$`, "u");
1396
+ const PLAIN_NAME = new RegExp(String.raw`^${IDENTIFIER}$`, "u");
1397
+ function unquote(name) {
1398
+ if (name.startsWith("\"")) return JSON.parse(name);
1399
+ if (name.startsWith("'")) {
1400
+ let json = "\"";
1401
+ for (let i = 1; i < name.length - 1; i += 1) {
1402
+ const char = name[i];
1403
+ if (char === "\\") {
1404
+ const escaped = name[++i];
1405
+ json += escaped === "'" ? "'" : `\\${escaped}`;
1406
+ } else json += char === "\"" ? "\\\"" : char;
1407
+ }
1408
+ return JSON.parse(`${json}"`);
1409
+ }
1410
+ return name;
1411
+ }
1412
+ function nameText(name) {
1413
+ return PLAIN_NAME.test(name) ? name : JSON.stringify(name);
1414
+ }
1415
+ function bindingText({ imported, local }) {
1416
+ return imported === local ? nameText(local) : `${nameText(imported)} as ${nameText(local)}`;
1417
+ }
1418
+ /**
1419
+ * Parses the bindings between `import` (or `export`) and `from`. Returns null for anything it does not fully
1420
+ * understand, comments included, so the caller leaves that statement as written.
1421
+ */
1422
+ function parseClause(text) {
1423
+ if (/\/[/*]/.test(text)) return null;
1424
+ let rest = text.trim();
1425
+ const clause = {
1426
+ bindings: [],
1427
+ namespace: null
1428
+ };
1429
+ const defaultBinding = DEFAULT_BINDING.exec(rest);
1430
+ if (defaultBinding?.[1]) {
1431
+ clause.bindings.push({
1432
+ imported: "default",
1433
+ local: defaultBinding[1]
1434
+ });
1435
+ rest = rest.slice(defaultBinding[0].length);
1436
+ if (rest === "") return clause;
1437
+ }
1438
+ const namespace = NAMESPACE_BINDING.exec(rest);
1439
+ if (namespace?.[1]) return {
1440
+ ...clause,
1441
+ namespace: namespace[1]
1442
+ };
1443
+ const named = /^\{([^}]*)\}$/.exec(rest);
1444
+ if (!named) return null;
1445
+ for (const part of (named[1] ?? "").split(",")) {
1446
+ const item = part.trim();
1447
+ if (item === "") continue;
1448
+ const match = NAMED_BINDING.exec(item);
1449
+ if (!match?.[1]) return null;
1450
+ clause.bindings.push({
1451
+ imported: unquote(match[1]),
1452
+ local: unquote(match[2] ?? match[1])
1453
+ });
1454
+ }
1455
+ return clause;
1456
+ }
1457
+ function emptyTransformStats() {
1458
+ return {
1459
+ canonical: 0,
1460
+ statements: 0,
1461
+ rewritten: 0,
1462
+ kept: 0,
1463
+ whole: 0,
1464
+ unparsed: 0
1465
+ };
1466
+ }
1467
+ function targetOf(specifier, options) {
1468
+ const kind = specifierKind(specifier);
1469
+ if (kind === "bare") return {
1470
+ url: options.resolveBare(specifier, options.url),
1471
+ canonical: null
1472
+ };
1473
+ if (kind !== "relative") return {
1474
+ url: null,
1475
+ canonical: null
1476
+ };
1477
+ const path = new URL(specifier, `https://runtime.invalid${options.url}`).pathname;
1478
+ if (!path.startsWith("/npm/") || !options.url.startsWith("/npm/")) return {
1479
+ url: path,
1480
+ canonical: null
1481
+ };
1482
+ const resolved = path.slice(5);
1483
+ const found = CANONICAL_CANDIDATES.map((suffix) => `${resolved}${suffix}`).find(options.known);
1484
+ if (!found) return {
1485
+ url: path,
1486
+ canonical: null
1487
+ };
1488
+ return {
1489
+ url: `${NPM_PREFIX}${found}`,
1490
+ canonical: found === resolved ? null : `${NPM_PREFIX}${found}`
1491
+ };
1492
+ }
1493
+ function specifierEdit(code, item, specifier) {
1494
+ const quoted = /^['"`]/.test(code.slice(item.start, item.end));
1495
+ return {
1496
+ start: item.start,
1497
+ end: item.end,
1498
+ text: quoted ? JSON.stringify(specifier) : specifier
1499
+ };
1500
+ }
1501
+ function rewriteStatement(code, item, entries, modules, specifier, stats) {
1502
+ if (item.attributes !== null || item.phase !== null || item.typeOnly) return null;
1503
+ const head = code.slice(item.importStart, item.start - 1);
1504
+ if (/^import\s*$/.test(head)) return null;
1505
+ const statement = /^(import|export)\s*([\s\S]*?)\s*from\s*$/.exec(head);
1506
+ const clause = statement ? parseClause(statement[2] ?? "") : null;
1507
+ if (!statement || !clause) {
1508
+ stats.unparsed += 1;
1509
+ return null;
1510
+ }
1511
+ const keyword = statement[1] ?? "import";
1512
+ if (keyword === "export" && clause.namespace) {
1513
+ stats.whole += 1;
1514
+ return null;
1515
+ }
1516
+ const groups = /* @__PURE__ */ new Map();
1517
+ const kept = [];
1518
+ for (const binding of clause.bindings) {
1519
+ const entry = entries[binding.imported];
1520
+ if (entry === void 0) {
1521
+ kept.push(bindingText(binding));
1522
+ continue;
1523
+ }
1524
+ const [position, name] = typeof entry === "number" ? [entry, binding.imported] : entry;
1525
+ const module = modules[position];
1526
+ if (module === void 0) throw new Error(`barrel index entry for ${binding.imported} points at missing module ${position}`);
1527
+ groups.set(module, [...groups.get(module) ?? [], bindingText({
1528
+ imported: name,
1529
+ local: binding.local
1530
+ })]);
1531
+ }
1532
+ stats.kept += kept.length;
1533
+ if (clause.namespace) stats.whole += 1;
1534
+ if (groups.size === 0) return null;
1535
+ const from = JSON.stringify(specifier);
1536
+ const statements = [
1537
+ ...clause.namespace ? [`import * as ${clause.namespace} from ${from}`] : [],
1538
+ ...kept.length > 0 ? [`${keyword} { ${kept.join(", ")} } from ${from}`] : [],
1539
+ ...[...groups].map(([module, names]) => `${keyword} { ${names.join(", ")} } from ${JSON.stringify(`${NPM_PREFIX}${module}`)}`)
1540
+ ];
1541
+ stats.statements += 1;
1542
+ stats.rewritten += clause.bindings.length - kept.length;
1543
+ return `${statements.join("; ")};`;
1544
+ }
1545
+ /**
1546
+ * Rewrites a served module's imports: relative imports in package files that name no file become canonical URLs,
1547
+ * and named imports from an indexed barrel move to the modules that define them. Everything else stays as written.
1548
+ */
1549
+ function transformModule(code, options) {
1550
+ const stats = emptyTransformStats();
1551
+ const [imports] = parse(code);
1552
+ const edits = [];
1553
+ for (const item of imports) {
1554
+ if (item.type === "import-meta" || item.specifier === void 0 || item.type === "dynamic" && item.glob) continue;
1555
+ const target = targetOf(item.specifier, options);
1556
+ const barrel = target.url?.startsWith("/npm/") ? options.barrels?.barrels[target.url.slice(5)] : void 0;
1557
+ if (barrel && options.barrels && item.type === "static") {
1558
+ const statement = rewriteStatement(code, item, barrel, options.barrels.modules, target.canonical ?? item.specifier, stats);
1559
+ if (statement !== null) {
1560
+ edits.push({
1561
+ start: item.importStart,
1562
+ end: item.importEnd,
1563
+ text: statement
1564
+ });
1565
+ continue;
1566
+ }
1567
+ } else if (barrel && item.type === "reexport-star") stats.whole += 1;
1568
+ if (target.canonical) {
1569
+ edits.push(specifierEdit(code, item, target.canonical));
1570
+ stats.canonical += 1;
1571
+ }
1572
+ }
1573
+ edits.sort((a, b) => b.start - a.start);
1574
+ let rewritten = code;
1575
+ let limit = code.length;
1576
+ for (const edit of edits) {
1577
+ if (edit.end > limit) throw new Error(`${options.url}: overlapping import edits at ${edit.start}`);
1578
+ rewritten = `${rewritten.slice(0, edit.start)}${edit.text}${rewritten.slice(edit.end)}`;
1579
+ limit = edit.start;
1580
+ }
1581
+ return {
1582
+ code: rewritten,
1583
+ stats
1584
+ };
1585
+ }
1586
+ // src/build/dependency-barrel-index.ts
1587
+ function dependencyBarrelIndex(options) {
1588
+ const paths = /* @__PURE__ */ new Map();
1589
+ const rules = /* @__PURE__ */ new Map();
1590
+ const canonical = (path) => {
1591
+ const url = options.canonical(path).slice(5);
1592
+ paths.set(url, path);
1593
+ return url;
1594
+ };
1595
+ const pathOf = (url) => {
1596
+ const path = paths.get(url);
1597
+ if (!path) throw new Error(`Unknown dependency barrel module ${url}`);
1598
+ return path;
1599
+ };
1600
+ return buildBarrelIndex({
1601
+ urls: [canonical(options.path)],
1602
+ shape(url) {
1603
+ const path = pathOf(url);
1604
+ if (!/\.m?js$/.test(path)) return null;
1605
+ const module = moduleFormat(path);
1606
+ return module.format === "esm" ? shapeOf(module.module) : null;
1607
+ },
1608
+ resolve(url, source) {
1609
+ const path = options.resolve(dirname(pathOf(url)), source);
1610
+ return path ? canonical(path) : null;
1611
+ },
1612
+ sideEffectFree(url) {
1613
+ const path = pathOf(url);
1614
+ const pkg = packageOf(path);
1615
+ let rule = rules.get(pkg.dir);
1616
+ if (!rule) {
1617
+ rule = sideEffectsRule(JSON.parse(readFileSync(join(pkg.dir, "package.json"), "utf8")).sideEffects, pkg.name);
1618
+ rules.set(pkg.dir, rule);
1619
+ }
1620
+ return rule(relative(pkg.dir, path).replaceAll("\\", "/"));
1621
+ }
1622
+ }).index;
1623
+ }
1624
+ // src/build/dependency-barrels.ts
1625
+ function dependencyBarrels({ target, root, barrelSource, external }) {
1626
+ const resolver = new ResolverFactory({
1627
+ conditionNames: [
1628
+ target,
1629
+ "import",
1630
+ "default"
1631
+ ],
1632
+ mainFields: target === "browser" ? [
1633
+ "browser",
1634
+ "module",
1635
+ "main"
1636
+ ] : ["module", "main"],
1637
+ extensions: [
1638
+ ".mjs",
1639
+ ".js",
1640
+ ".cjs",
1641
+ ".json"
1642
+ ],
1643
+ symlinks: true
1644
+ });
1645
+ const loaded = /* @__PURE__ */ new Set();
1646
+ const indexed = /* @__PURE__ */ new Set();
1647
+ const directories = /* @__PURE__ */ new Map();
1648
+ const installedIdentities = /* @__PURE__ */ new Map();
1649
+ let index = {
1650
+ modules: [],
1651
+ barrels: {}
1652
+ };
1653
+ const canonical = (path) => {
1654
+ const pkg = packageOf(path);
1655
+ if (barrelSource === "installed" && !installedIdentities.has(pkg.dir)) installedIdentities.set(pkg.dir, installedIdentities.size);
1656
+ const instance = installedIdentities.get(pkg.dir);
1657
+ const key = `${pkg.name}@${pkg.version}${instance === void 0 ? "" : `+installed.${instance}`}`;
1658
+ directories.set(key, pkg.dir);
1659
+ if (!loaded.has(pkg.dir)) {
1660
+ loaded.add(pkg.dir);
1661
+ const file = join(pkg.dir, "dist/runtime/barrels.json");
1662
+ if (barrelSource === "published" && existsSync(file)) {
1663
+ const manifest = JSON.parse(readFileSync(join(pkg.dir, "package.json"), "utf8"));
1664
+ const published = guardedBarrels({
1665
+ index: JSON.parse(readFileSync(file, "utf8")),
1666
+ name: pkg.name,
1667
+ version: pkg.version,
1668
+ ...manifest.sideEffects === void 0 ? {} : { sideEffects: manifest.sideEffects }
1669
+ });
1670
+ const own = `${pkg.name}@${pkg.version}/`;
1671
+ const inside = (at) => published.modules[typeof at === "number" ? at : at[0]]?.startsWith(own) === true;
1672
+ index = mergeBarrels([index, {
1673
+ modules: published.modules,
1674
+ barrels: Object.fromEntries(Object.entries(published.barrels).filter(([url, entries]) => url.startsWith(own) && Object.values(entries).every(inside)))
1675
+ }]);
1676
+ }
1677
+ }
1678
+ return `/npm/${key}/${relative(pkg.dir, path).split(sep).join("/")}`;
1679
+ };
1680
+ const localPath = (url) => {
1681
+ const match = /^\/npm\/((?:@[^/]+\/)?[^/]+)\/(.+)$/.exec(url);
1682
+ const root = match && directories.get(match[1]);
1683
+ if (!match || !root) throw new Error(`Unknown compiled runtime module ${url}`);
1684
+ return join(root, match[2]);
1685
+ };
1686
+ return {
1687
+ name: "dependency-runtime-barrels",
1688
+ async buildStart() {
1689
+ await init;
1690
+ },
1691
+ resolveId(source) {
1692
+ return source.startsWith("/npm/") ? localPath(source) : null;
1693
+ },
1694
+ transform(code, id) {
1695
+ const entry = id.startsWith("\0entry:");
1696
+ if (!entry && (id.startsWith("\0") || !/\.m?js$/.test(id))) return null;
1697
+ const parsed = parseSync(id, code, {
1698
+ lang: "js",
1699
+ sourceType: "unambiguous"
1700
+ });
1701
+ if (!parsed.module.hasModuleSyntax) return null;
1702
+ const from = entry ? root : dirname(id);
1703
+ const url = entry ? "/runtime-entry.js" : canonical(id);
1704
+ for (const item of parsed.module.staticImports) {
1705
+ if (external.has(item.moduleRequest.value)) continue;
1706
+ const path = resolver.sync(from, item.moduleRequest.value).path;
1707
+ if (path) {
1708
+ canonical(path);
1709
+ if (!indexed.has(path)) {
1710
+ indexed.add(path);
1711
+ const pkg = packageOf(path);
1712
+ if (barrelSource === "installed" || !existsSync(join(pkg.dir, "dist/runtime/barrels.json"))) index = mergeBarrels([index, dependencyBarrelIndex({
1713
+ path,
1714
+ canonical,
1715
+ resolve: (from, source) => resolver.sync(from, source).path
1716
+ })]);
1717
+ }
1718
+ }
1719
+ }
1720
+ return transformModule(code, {
1721
+ url,
1722
+ barrels: index,
1723
+ known: () => false,
1724
+ resolveBare(source) {
1725
+ if (external.has(source)) return null;
1726
+ const path = resolver.sync(from, source).path;
1727
+ return path ? canonical(path) : null;
1728
+ }
1729
+ }).code;
1730
+ }
1731
+ };
1732
+ }
1733
+ // src/build/commonjs-exports.ts
1734
+ async function commonJsExportNames(paths) {
1735
+ if (!paths.length) return {};
1736
+ return new Promise((resolve, reject) => {
1737
+ const worker = new Worker(new URL("./cjs-export-names.mjs", import.meta.url), {
1738
+ workerData: paths,
1739
+ env: {
1740
+ ...process.env,
1741
+ NODE_ENV: "development"
1742
+ },
1743
+ stdout: true,
1744
+ stderr: true
1745
+ });
1746
+ worker.stdout.resume();
1747
+ worker.stderr.resume();
1748
+ const timeout = setTimeout(() => {
1749
+ reject(/* @__PURE__ */ new Error("Timed out enumerating CommonJS runtime exports"));
1750
+ worker.terminate();
1751
+ }, 3e4);
1752
+ let result;
1753
+ worker.once("message", (message) => {
1754
+ result = message;
1755
+ });
1756
+ worker.once("error", reject);
1757
+ worker.once("exit", (code) => {
1758
+ clearTimeout(timeout);
1759
+ if (code !== 0 || !result) {
1760
+ reject(/* @__PURE__ */ new Error(`CommonJS export worker exited with code ${code} before returning exports`));
1761
+ return;
1762
+ }
1763
+ for (const path of paths) if (!result[path]?.names || result[path]?.error) {
1764
+ reject(/* @__PURE__ */ new Error(`Cannot enumerate CommonJS exports of ${path}: ${result[path]?.error}`));
1765
+ return;
1766
+ }
1767
+ resolve(result);
1768
+ });
1769
+ });
1770
+ }
1771
+ // src/build/dependency-optional.ts
1772
+ function optionalDependency(options) {
1773
+ if (specifierKind$1(options.source) !== "bare" || options.importer.startsWith("\0")) return false;
1774
+ const pkg = packageOf(options.importer);
1775
+ const manifest = JSON.parse(readFileSync(join(pkg.dir, "package.json"), "utf8"));
1776
+ const name = packageName(options.source);
1777
+ return Object.hasOwn(manifest.optionalDependencies ?? {}, name) || manifest.peerDependenciesMeta?.[name]?.optional === true;
1778
+ }
1779
+ // src/build/dependency-workers.ts
1780
+ const workerURL = /(new\s+(?:Worker|SharedWorker)\s*\(\s*)new URL\(\s*(['"])([^'":?#]+)\2\s*,\s*import\.meta\.url\s*\)/g;
1781
+ async function bundleWorkerURLs(options) {
1782
+ const matches = [...options.code.matchAll(workerURL)].filter((match) => !match[3].startsWith("/"));
1783
+ const replacements = await Promise.all(matches.map(async (match) => {
1784
+ const path = resolve(dirname(options.id), match[3]);
1785
+ let pending = options.workers.get(path);
1786
+ if (!pending) {
1787
+ pending = compileWorker(path, options.trackInput).then((source) => options.context.emitFile({
1788
+ type: "asset",
1789
+ name: basename(path),
1790
+ source
1791
+ }));
1792
+ options.workers.set(path, pending);
1793
+ }
1794
+ return match[1] + `new URL(import.meta.ROLLUP_FILE_URL_${await pending})`;
1795
+ }));
1796
+ let code = options.code;
1797
+ for (let index = matches.length - 1; index >= 0; index--) {
1798
+ const match = matches[index];
1799
+ code = code.slice(0, match.index) + replacements[index] + code.slice(match.index + match[0].length);
1800
+ }
1801
+ return code;
1802
+ }
1803
+ async function compileWorker(path, trackInput) {
1804
+ const worker = await rolldown({
1805
+ input: path,
1806
+ platform: "browser",
1807
+ plugins: [{
1808
+ name: "worker-inputs",
1809
+ transform(code, id) {
1810
+ if (!id.startsWith("\0")) trackInput(id, code);
1811
+ }
1812
+ }],
1813
+ onLog(level, log, handler) {
1814
+ if (log.code === "UNRESOLVED_IMPORT") throw new Error(log.message);
1815
+ handler(level, log);
1816
+ }
1817
+ });
1818
+ try {
1819
+ const { output } = await worker.generate({
1820
+ format: "esm",
1821
+ codeSplitting: false,
1822
+ minify: true
1823
+ });
1824
+ const chunk = output[0];
1825
+ if (output.length !== 1 || chunk?.type !== "chunk" || chunk.imports.length || chunk.dynamicImports.length) throw new Error(`Worker ${path} must compile to one browser script`);
1826
+ return chunk.code;
1827
+ } finally {
1828
+ await worker.close();
1829
+ }
1830
+ }
1831
+ // src/build/dependency-runtime.ts
1832
+ function buildInstalledDependencyRuntime(options) {
1833
+ return buildDependencyRuntime(options, "installed");
1834
+ }
1835
+ async function buildDependencyRuntime(options, barrelSource = "published") {
1836
+ if (!options.entries.length) throw new Error("A dependency runtime requires at least one entry");
1837
+ const root = resolve(options.root);
1838
+ const entries = [...new Set(options.entries)].sort();
1839
+ const inputs = {};
1840
+ const trackInput = (path, code) => {
1841
+ inputs[path] = createHash("sha256").update(code).digest("hex");
1842
+ };
1843
+ const styles = /* @__PURE__ */ new Set();
1844
+ const assets = /* @__PURE__ */ new Set();
1845
+ const workers = /* @__PURE__ */ new Map();
1846
+ const resolved = /* @__PURE__ */ new Map();
1847
+ const peersByPackage = /* @__PURE__ */ new Map();
1848
+ let commonJs = {};
1849
+ const browserResolver = createResolver(IMPORT_CONDITIONS);
1850
+ const plugin = {
1851
+ name: "dependency-runtime",
1852
+ async buildStart() {
1853
+ for (const entry of entries) {
1854
+ if (options.resolvedEntries?.[entry]) {
1855
+ resolved.set(entry, options.resolvedEntries[entry]);
1856
+ continue;
1857
+ }
1858
+ const result = await this.resolve(entry, join(root, "package.json"), { skipSelf: true });
1859
+ if (!result || result.external) throw new Error(`Cannot resolve runtime entry ${entry} from ${root}`);
1860
+ resolved.set(entry, result.id);
1861
+ }
1862
+ commonJs = await commonJsExportNames([...new Set(resolved.values())].filter((path) => moduleFormat(path).format === "commonjs"));
1863
+ },
1864
+ async resolveId(source, importer, extra) {
1865
+ if (source.startsWith("\0external-require:")) return source;
1866
+ if (options.external?.[source]) {
1867
+ const version = options.externalVersions?.[packageName(source)];
1868
+ const from = version && importer && !importer.startsWith("\0") ? importer : void 0;
1869
+ const original = version || extra.kind === "require-call" ? await this.resolve(source, from ?? join(root, "package.json"), {
1870
+ ...extra,
1871
+ skipSelf: true
1872
+ }) : void 0;
1873
+ let sharedPeer = false;
1874
+ if (version && from) {
1875
+ const pkg = packageOf(from);
1876
+ if (!peersByPackage.has(pkg.dir)) peersByPackage.set(pkg.dir, JSON.parse(readFileSync(join(pkg.dir, "package.json"), "utf8")).peerDependencies ?? {});
1877
+ const range = peersByPackage.get(pkg.dir)?.[packageName(source)];
1878
+ if (range) {
1879
+ if (!satisfiesVersion(version, range)) throw new Error(`${pkg.name} requires ${packageName(source)}@${range}; the runtime provides ${version}`);
1880
+ sharedPeer = true;
1881
+ }
1882
+ }
1883
+ if (!version || sharedPeer || !original || original.external || packageOf(original.id).version === version) {
1884
+ if (extra.kind !== "require-call") return {
1885
+ id: source,
1886
+ external: true
1887
+ };
1888
+ const commonJs = !original || original.external ? moduleFormat(options.external[source]).module.staticExports.some((item) => item.entries.some((entry) => entry.exportName.kind === "Default")) : moduleFormat(original.id).format === "commonjs";
1889
+ return `\0external-require:${JSON.stringify({
1890
+ source,
1891
+ commonJs
1892
+ })}`;
1893
+ }
1894
+ }
1895
+ if (isBuiltin(source)) {
1896
+ if (options.target === "browser") {
1897
+ const mapped = importer && resolveBrowser({
1898
+ resolver: browserResolver,
1899
+ fromDir: dirname(importer),
1900
+ specifier: source
1901
+ });
1902
+ if (mapped && mapped.empty) return "\0browser-empty";
1903
+ if (mapped && mapped.path) return mapped.path;
1904
+ throw new Error(`Browser runtime cannot import ${source} from ${importer}`);
1905
+ }
1906
+ return {
1907
+ id: source,
1908
+ external: true
1909
+ };
1910
+ }
1911
+ if (source.startsWith("\0entry:")) return source;
1912
+ if (extra.kind === "dynamic-import" && importer && optionalDependency({
1913
+ source,
1914
+ importer
1915
+ })) return await this.resolve(source, importer, {
1916
+ ...extra,
1917
+ skipSelf: true
1918
+ }) ?? {
1919
+ id: source,
1920
+ external: true
1921
+ };
1922
+ if (importer?.startsWith("\0entry:")) return this.resolve(source, join(root, "package.json"), {
1923
+ ...extra,
1924
+ skipSelf: true
1925
+ });
1926
+ if (/^(react|react-dom|scheduler)(\/|$)/.test(source)) return this.resolve(source, join(root, "package.json"), {
1927
+ ...extra,
1928
+ skipSelf: true
1929
+ });
1930
+ return null;
1931
+ },
1932
+ load(id) {
1933
+ if (id === "\0browser-empty") return "export default {};";
1934
+ if (id.startsWith("\0external-require:")) {
1935
+ const { source, commonJs } = JSON.parse(id.slice(18));
1936
+ return `import * as ns from ${JSON.stringify(source)}; module.exports = ${commonJs ? "ns.default" : "ns"};`;
1937
+ }
1938
+ if (id.endsWith(".css")) {
1939
+ const tracer = new ClosureTracer({
1940
+ name: "dependency-styles",
1941
+ resolveFrom: root,
1942
+ entries: [],
1943
+ topLevel: [],
1944
+ inherits: []
1945
+ });
1946
+ tracer.target(id, id, "relative");
1947
+ if (tracer.failures.length) throw new Error(tracer.failures.map((item) => item.detail).join("\n"));
1948
+ for (const file of tracer.files.values()) {
1949
+ const fileName = `assets/${file.url}`;
1950
+ const source = readFileSync(file.path);
1951
+ inputs[file.path] = createHash("sha256").update(source).digest("hex");
1952
+ if (file.path === id) styles.add(fileName);
1953
+ if (!assets.has(fileName)) this.emitFile({
1954
+ type: "asset",
1955
+ fileName,
1956
+ source
1957
+ });
1958
+ assets.add(fileName);
1959
+ }
1960
+ return {
1961
+ code: "export {};",
1962
+ moduleType: "js"
1963
+ };
1964
+ }
1965
+ if (!id.startsWith("\0entry:")) return null;
1966
+ const specifier = id.slice(7, -4);
1967
+ const path = resolved.get(specifier);
1968
+ if (!path) throw new Error(`Missing resolved runtime entry ${id}`);
1969
+ const names = commonJs[path]?.names;
1970
+ const requested = options.exports?.[specifier];
1971
+ if (!names) {
1972
+ const source = JSON.stringify(options.resolvedEntries?.[specifier] ?? specifier);
1973
+ if (requested) return `import { ${requested.map((name, index) => `${JSON.stringify(name)} as e${index}`).join(", ")} } from ${source}; export { ${requested.map((name, index) => `e${index} as ${JSON.stringify(name)}`).join(", ")} };`;
1974
+ return `export * from ${source}; ${moduleFormat(path).module.staticExports.some((item) => item.entries.some((entry) => entry.exportName.kind === "Default" || entry.exportName.name === "default")) ? `export { default } from ${source};` : ""}`;
1975
+ }
1976
+ const exported = names.filter((name) => name !== "default" && name !== "__esModule");
1977
+ return [
1978
+ `import value from ${JSON.stringify(path)};`,
1979
+ "export default value;",
1980
+ ...exported.map((name, index) => `const e${index} = value[${JSON.stringify(name)}]; export { e${index} as ${JSON.stringify(name)} };`)
1981
+ ].join("\n");
1982
+ },
1983
+ async transform(code, id) {
1984
+ if (!id.startsWith("\0") && !id.endsWith(".css")) trackInput(id, code);
1985
+ if (id.startsWith("\0")) return null;
1986
+ if (options.target === "browser" && code.includes("import.meta.url")) code = await bundleWorkerURLs({
1987
+ code,
1988
+ id,
1989
+ context: this,
1990
+ workers,
1991
+ trackInput
1992
+ });
1993
+ return code.replace(/new URL\(\s*(['"])(\.{1,2}\/[^'"]+)\1\s*,\s*import\.meta\.url\s*\)/g, (_match, _quote, reference) => {
1994
+ const path = resolve(dirname(id), reference);
1995
+ const source = readFileSync(path);
1996
+ inputs[path] = createHash("sha256").update(source).digest("hex");
1997
+ return `new URL(import.meta.ROLLUP_FILE_URL_${this.emitFile({
1998
+ type: "asset",
1999
+ name: basename(path),
2000
+ source
2001
+ })})`;
2002
+ });
2003
+ }
2004
+ };
2005
+ await rm(options.outDir, {
2006
+ recursive: true,
2007
+ force: true
2008
+ });
2009
+ await mkdir(options.outDir, { recursive: true });
2010
+ const bundle = await rolldown({
2011
+ input: Object.fromEntries(entries.map((specifier, index) => [`entry-${index}`, `\0entry:${specifier}.mjs`])),
2012
+ plugins: [plugin, dependencyBarrels({
2013
+ target: options.target,
2014
+ root,
2015
+ barrelSource,
2016
+ external: new Set(Object.keys(options.external ?? {}))
2017
+ })],
2018
+ platform: options.target,
2019
+ resolve: {
2020
+ conditionNames: [
2021
+ options.target,
2022
+ "import",
2023
+ "default"
2024
+ ],
2025
+ mainFields: options.target === "browser" ? [
2026
+ "browser",
2027
+ "module",
2028
+ "main"
2029
+ ] : ["module", "main"],
2030
+ aliasFields: options.target === "browser" ? [["browser"]] : []
2031
+ },
2032
+ transform: { define: { "process.env.NODE_ENV": JSON.stringify("development") } },
2033
+ onLog(level, log, handler) {
2034
+ if (log.code === "UNRESOLVED_IMPORT") throw new Error(log.message);
2035
+ if (log.code === "MODULE_LEVEL_DIRECTIVE") return;
2036
+ handler(level, log);
2037
+ }
2038
+ });
2039
+ try {
2040
+ const paths = Object.fromEntries(Object.entries(options.external ?? {}).map(([specifier, path]) => {
2041
+ const value = relative(options.outDir, path).split(sep).join("/");
2042
+ return [specifier, value.startsWith(".") ? value : `./${value}`];
2043
+ }));
2044
+ const { output } = await bundle.write({
2045
+ dir: options.outDir,
2046
+ format: "esm",
2047
+ entryFileNames: "[name].mjs",
2048
+ chunkFileNames: "[name]-[hash].mjs",
2049
+ paths,
2050
+ ...options.target === "node" ? { banner: "import { createRequire as __runtimeRequire } from \"node:module\"; const require = __runtimeRequire(import.meta.url);" } : {}
2051
+ });
2052
+ if (options.target === "browser") {
2053
+ for (const item of output) if (item.type === "chunk" && /(?<![\w$.])__require\s*\(/.test(item.code)) throw new Error(`Browser dependency runtime ${item.fileName} still contains a dynamic require`);
2054
+ }
2055
+ const imports = Object.fromEntries(entries.map((specifier, index) => [specifier, `entry-${index}.mjs`]));
2056
+ const integrity = Object.fromEntries(output.map((item) => [item.fileName, createHash("sha256").update(readFileSync(join(options.outDir, item.fileName))).digest("hex")]));
2057
+ const runtime = {
2058
+ schema: 1,
2059
+ target: options.target,
2060
+ imports,
2061
+ integrity,
2062
+ inputs,
2063
+ styles: [...styles]
2064
+ };
2065
+ await writeFile(join(options.outDir, "runtime.json"), JSON.stringify(runtime, null, 2));
2066
+ return runtime;
2067
+ } finally {
2068
+ await bundle.close();
2069
+ }
2070
+ }
2071
+ // src/build/dependency-cache.ts
2072
+ async function ensureDependencyRuntime(options) {
2073
+ const identity = createHash("sha256").update(JSON.stringify({
2074
+ root: resolve(options.root),
2075
+ target: options.target,
2076
+ entries: [...new Set(options.entries)].sort(),
2077
+ exports: options.exports,
2078
+ external: options.external,
2079
+ externalVersions: options.externalVersions,
2080
+ resolvedEntries: options.resolvedEntries,
2081
+ lock: readFileSync(join(options.root, "pnpm-lock.yaml"), "utf8"),
2082
+ compiler: readFileSync(new URL(import.meta.url)),
2083
+ abi: process.versions.modules
2084
+ })).digest("hex");
2085
+ await mkdir(options.cacheDir, { recursive: true });
2086
+ const pointer = join(options.cacheDir, `${identity}.json`);
2087
+ const lock = `${pointer}.lock`;
2088
+ const deadline = Date.now() + 3e5;
2089
+ let handle;
2090
+ while (!handle) try {
2091
+ handle = await open(lock, "wx");
2092
+ } catch (error) {
2093
+ if (error.code !== "EEXIST") throw error;
2094
+ if (Date.now() > deadline) throw new Error(`Timed out waiting for compiled runtime ${lock}`);
2095
+ await new Promise((done) => setTimeout(done, 25));
2096
+ }
2097
+ try {
2098
+ if (existsSync(pointer)) {
2099
+ const cached = JSON.parse(await readFile(pointer, "utf8"));
2100
+ if (Object.entries(cached.inputs).every(([path, hash]) => existsSync(path) && createHash("sha256").update(readFileSync(path)).digest("hex") === hash)) return cached;
2101
+ }
2102
+ const root = join(options.cacheDir, `${identity}-${randomUUID()}`);
2103
+ const staging = `${root}.pending`;
2104
+ try {
2105
+ const runtime = await buildDependencyRuntime({
2106
+ ...options,
2107
+ outDir: staging
2108
+ });
2109
+ await rename(staging, root);
2110
+ const result = {
2111
+ ...runtime,
2112
+ root
2113
+ };
2114
+ await writeFile(`${pointer}.pending`, JSON.stringify(result));
2115
+ await rename(`${pointer}.pending`, pointer);
2116
+ return result;
2117
+ } finally {
2118
+ await rm(staging, {
2119
+ recursive: true,
2120
+ force: true
2121
+ });
2122
+ }
2123
+ } finally {
2124
+ await handle.close();
2125
+ await rm(lock);
2126
+ }
2127
+ }
2128
+ export { specifierKind$1 as C, resolveSpecifier as E, packageOf as S, fragmentOf as T, createResolver as _, buildLibraryRuntime as a, moduleFormat as b, BASE_PACKAGES as c, BaseSetRemapError as d, CommonJsConversionError as f, IMPORT_CONDITIONS as g, EMPTY_MODULE as h, assertTrace as i, traceRecipeDependencies as l, ClosureTracer as m, buildDependencyRuntime as n, librarySpec as o, NodeBuiltinError as p, buildInstalledDependencyRuntime as r, BASE_ENTRIES as s, ensureDependencyRuntime as t, convertCommonJs as u, exportEntries as v, composeImportMap as w, packageName as x, integrityOf as y };
2129
+
2130
+ //# sourceMappingURL=dependency-cache-Zg-FGasE.mjs.map