@ecopages/core 0.6.0 → 0.7.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 (354) hide show
  1. package/README.md +8 -143
  2. package/package.json +16 -3
  3. package/src/adapters/node/dev-session.js +2 -1
  4. package/src/adapters/node/node-client-bridge.d.ts +5 -7
  5. package/src/adapters/node/node-client-bridge.js +4 -14
  6. package/src/adapters/node/server-adapter.d.ts +4 -2
  7. package/src/adapters/node/server-adapter.js +13 -12
  8. package/src/adapters/shared/hmr/client-bridge.d.ts +25 -0
  9. package/src/adapters/shared/hmr/client-bridge.js +35 -0
  10. package/src/adapters/shared/hmr/dev-transform-entrypoint-registry.js +1 -1
  11. package/src/adapters/shared/hmr/hmr-manager.d.ts +9 -2
  12. package/src/adapters/shared/hmr/hmr-manager.js +36 -6
  13. package/src/adapters/shared/http/dist-file-handler.js +3 -7
  14. package/src/adapters/shared/http/response-headers.d.ts +29 -0
  15. package/src/adapters/shared/http/response-headers.js +89 -0
  16. package/src/adapters/shared/runtime/copy-runtime-public-dir.js +1 -1
  17. package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +3 -2
  18. package/src/adapters/shared/runtime/runtime-server-lifecycle.js +4 -3
  19. package/src/adapters/shared/runtime/server-request-pipeline.js +4 -4
  20. package/src/adapters/shared/runtime/server-static-builder.d.ts +19 -8
  21. package/src/adapters/shared/runtime/server-static-builder.js +23 -4
  22. package/src/adapters/shared/ws/node-http-websocket-upgrades.d.ts +1 -1
  23. package/src/adapters/shared/ws/node-http-websocket-upgrades.js +23 -16
  24. package/src/assets/app-browser-client-build.d.ts +5 -12
  25. package/src/assets/app-browser-client-build.js +121 -336
  26. package/src/assets/asset-processing-service/app-browser-client-bundle.d.ts +4 -0
  27. package/src/assets/asset-processing-service/app-browser-client-bundle.js +6 -0
  28. package/src/assets/asset-processing-service/asset-dependency-keys.d.ts +28 -8
  29. package/src/assets/asset-processing-service/asset-dependency-keys.js +104 -29
  30. package/src/assets/asset-processing-service/asset-processing.service.d.ts +60 -2
  31. package/src/assets/asset-processing-service/asset-processing.service.js +189 -58
  32. package/src/assets/asset-processing-service/bundleable-script.d.ts +3 -0
  33. package/src/assets/asset-processing-service/bundleable-script.js +4 -0
  34. package/src/assets/asset-processing-service/grouped-content-bundles.d.ts +2 -2
  35. package/src/assets/asset-processing-service/grouped-content-bundles.js +5 -10
  36. package/src/assets/asset-processing-service/index.d.ts +0 -3
  37. package/src/assets/asset-processing-service/index.js +0 -3
  38. package/src/assets/asset-processing-service/last-good-output.d.ts +21 -0
  39. package/src/assets/asset-processing-service/last-good-output.js +32 -0
  40. package/src/assets/asset-processing-service/page-package.js +1 -4
  41. package/src/assets/asset-processing-service/processed-asset-ledger.d.ts +63 -0
  42. package/src/assets/asset-processing-service/processed-asset-ledger.js +101 -0
  43. package/src/assets/asset-processing-service/processors/base/base-processor.js +1 -1
  44. package/src/assets/asset-processing-service/processors/base/base-script-processor.js +1 -1
  45. package/src/assets/asset-processing-service/processors/script/content-script.processor.d.ts +24 -0
  46. package/src/assets/asset-processing-service/processors/script/content-script.processor.js +59 -4
  47. package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +8 -4
  48. package/src/assets/asset-processing-service/processors/script/file-script.processor.js +18 -6
  49. package/src/assets/asset-processing-service/processors/script/node-module-script.processor.js +2 -3
  50. package/src/assets/asset-processing-service/processors/stylesheet/app-stylesheet-imports.d.ts +34 -0
  51. package/src/assets/asset-processing-service/processors/stylesheet/app-stylesheet-imports.js +115 -0
  52. package/src/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +2 -2
  53. package/src/assets/asset-processing-service/processors/stylesheet/css-module-types.d.ts +39 -0
  54. package/src/assets/asset-processing-service/processors/stylesheet/css-module-types.js +150 -0
  55. package/src/assets/asset-processing-service/processors/stylesheet/css-scanner.d.ts +84 -0
  56. package/src/assets/asset-processing-service/processors/stylesheet/css-scanner.js +379 -0
  57. package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts +16 -0
  58. package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +50 -24
  59. package/src/assets/asset-processing-service/processors/stylesheet/import-order.d.ts +33 -0
  60. package/src/assets/asset-processing-service/processors/stylesheet/import-order.js +67 -0
  61. package/src/assets/asset-processing-service/processors/stylesheet/package-stylesheet.d.ts +44 -0
  62. package/src/assets/asset-processing-service/processors/stylesheet/package-stylesheet.js +149 -0
  63. package/src/assets/asset-processing-service/processors/stylesheet/processed-stylesheet-cache.d.ts +31 -0
  64. package/src/assets/asset-processing-service/processors/stylesheet/processed-stylesheet-cache.js +59 -0
  65. package/src/assets/asset-processing-service/processors/stylesheet/source-relative-stylesheet.d.ts +20 -0
  66. package/src/assets/asset-processing-service/processors/stylesheet/source-relative-stylesheet.js +51 -0
  67. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-failure.d.ts +2 -0
  68. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-failure.js +5 -0
  69. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-module.d.ts +37 -0
  70. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-module.js +48 -0
  71. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-processor-pipeline.d.ts +25 -1
  72. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-processor-pipeline.js +56 -15
  73. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-warnings.d.ts +9 -0
  74. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-warnings.js +21 -0
  75. package/src/assets/browser-asset-output.js +1 -1
  76. package/src/assets/hashed-browser-asset.js +1 -1
  77. package/src/assets/{browser-runtime-asset-page-cache.d.ts → page-script-page-cache.d.ts} +3 -3
  78. package/src/assets/{browser-runtime-asset-page-cache.js → page-script-page-cache.js} +3 -3
  79. package/src/build/app-build-manifest-runtime.d.ts +23 -11
  80. package/src/build/app-build-manifest-runtime.js +52 -13
  81. package/src/build/browser/jsx-ownership-plugins.d.ts +4 -1
  82. package/src/build/browser/jsx-ownership-plugins.js +6 -0
  83. package/src/build/build-adapter.d.ts +1 -1
  84. package/src/build/build-adapter.js +1 -1
  85. package/src/build/build-graph.d.ts +4 -2
  86. package/src/build/build-graph.js +12 -46
  87. package/src/build/cache/build-input-dependency-index.d.ts +0 -19
  88. package/src/build/cache/build-input-dependency-index.js +1 -34
  89. package/src/build/cache/pages-unified-graph-build.js +7 -43
  90. package/src/build/cache/server-module-entries.d.ts +1 -1
  91. package/src/build/cache/server-module-entries.js +9 -9
  92. package/src/build/contracts/build-contracts.d.ts +59 -12
  93. package/src/build/contracts/build-manifest.d.ts +3 -6
  94. package/src/build/contracts/build-manifest.js +2 -12
  95. package/src/build/contracts/content-virtual-modules.js +1 -3
  96. package/src/build/copy-server-files.js +1 -1
  97. package/src/build/preserve-import-meta-transform.d.ts +3 -1
  98. package/src/build/preserve-import-meta-transform.js +7 -4
  99. package/src/build/production-asset-ledger.d.ts +36 -0
  100. package/src/build/production-asset-ledger.js +104 -0
  101. package/src/build/production-dist-complete.js +12 -13
  102. package/src/build/production-route-list.js +1 -1
  103. package/src/build/rolldown/app-package-declarations.js +1 -1
  104. package/src/build/rolldown/entry-module-closures.d.ts +5 -1
  105. package/src/build/rolldown/entry-module-closures.js +21 -8
  106. package/src/build/rolldown/rolldown-adapter-helpers.d.ts +19 -8
  107. package/src/build/rolldown/rolldown-adapter-helpers.js +82 -45
  108. package/src/build/rolldown/rolldown-build-adapter.js +10 -13
  109. package/src/build/rolldown/rolldown-module-id.d.ts +18 -0
  110. package/src/build/rolldown/rolldown-module-id.js +29 -0
  111. package/src/build/rolldown/rolldown-plugin-bridge.d.ts +24 -60
  112. package/src/build/rolldown/rolldown-plugin-bridge.js +201 -373
  113. package/src/build/rolldown/stylesheet-module-plugin.d.ts +34 -0
  114. package/src/build/rolldown/stylesheet-module-plugin.js +160 -0
  115. package/src/build/rolldown/worker-entries-plugin.d.ts +13 -0
  116. package/src/build/rolldown/worker-entries-plugin.js +57 -0
  117. package/src/build/runtime/build-environment-options.js +13 -3
  118. package/src/build/runtime/build-request-identity.js +1 -1
  119. package/src/build/runtime/build-request-policy.d.ts +7 -12
  120. package/src/build/runtime/build-request-policy.js +63 -17
  121. package/src/build/server/imported-view-plugin.d.ts +1 -0
  122. package/src/build/server/imported-view-plugin.js +6 -4
  123. package/src/build/server/page-module-import.service.d.ts +1 -2
  124. package/src/build/server/page-module-import.service.js +4 -6
  125. package/src/build/server/resolve-static-view.js +3 -2
  126. package/src/build/server/route-module-build-cache-registry.js +1 -1
  127. package/src/build/server/route-module-build-cache.store.js +1 -1
  128. package/src/build/server/route-module-build-manifest.js +1 -1
  129. package/src/build/server/route-module-dependency-hasher.d.ts +1 -1
  130. package/src/build/server/route-module-dependency-hasher.js +2 -2
  131. package/src/build/server/server-modules-manifest.d.ts +3 -5
  132. package/src/build/server/server-modules-manifest.js +6 -21
  133. package/src/build/server/view-module.d.ts +12 -0
  134. package/src/build/server/view-module.js +23 -0
  135. package/src/build/server/view-reference.d.ts +16 -5
  136. package/src/build/server/view-reference.js +25 -14
  137. package/src/build/server-bundle-deploy-manifest.d.ts +1 -1
  138. package/src/build/server-bundle-deploy-manifest.js +2 -2
  139. package/src/build/server-bundle-publication.d.ts +7 -1
  140. package/src/build/server-bundle-publication.js +11 -4
  141. package/src/build/server-module.js +1 -1
  142. package/src/build/worker-urls.d.ts +60 -0
  143. package/src/build/worker-urls.js +197 -0
  144. package/src/build.d.ts +7 -5
  145. package/src/build.js +7 -5
  146. package/src/cache/module-parse-cache.js +2 -2
  147. package/src/client/navigation-attributes.d.ts +8 -0
  148. package/src/client/navigation-attributes.js +8 -0
  149. package/src/client/navigation-scripts/global-scripts.d.ts +14 -0
  150. package/src/client/navigation-scripts/global-scripts.js +65 -0
  151. package/src/client/navigation-scripts/index.d.ts +1 -0
  152. package/src/client/navigation-scripts/index.js +1 -0
  153. package/src/client.d.ts +2 -2
  154. package/src/client.js +2 -2
  155. package/src/config/assembly/app-runtime.d.ts +45 -5
  156. package/src/config/assembly/app-runtime.js +11 -2
  157. package/src/config/assembly/finalize-config.js +13 -5
  158. package/src/config/config-module-files.js +10 -6
  159. package/src/config/index.d.ts +2 -1
  160. package/src/config/internal-types.d.ts +3 -0
  161. package/src/config/load-eco-config.js +8 -5
  162. package/src/config/resolve-eco-config-path.js +3 -3
  163. package/src/config/server-config-bundle.js +1 -1
  164. package/src/config/user-config-types.d.ts +54 -1
  165. package/src/config/write-types.js +4 -1
  166. package/src/css-imports.d.ts +12 -0
  167. package/src/declarations.d.ts +2 -0
  168. package/src/dev/development-restart-watch-paths.js +1 -1
  169. package/src/dev/development-restart.js +1 -1
  170. package/src/dev/invalidation/development-invalidation.service.d.ts +6 -1
  171. package/src/dev/invalidation/development-invalidation.service.js +18 -2
  172. package/src/dev/stylesheets/development-stylesheet.service.d.ts +149 -0
  173. package/src/dev/stylesheets/development-stylesheet.service.js +350 -0
  174. package/src/dev/transform-server/dev-transform-bundler.d.ts +12 -3
  175. package/src/dev/transform-server/dev-transform-bundler.js +32 -21
  176. package/src/dev/transform-server/dev-transform-externalize-plugin.d.ts +3 -5
  177. package/src/dev/transform-server/dev-transform-externalize-plugin.js +8 -9
  178. package/src/dev/transform-server/dev-transform-import-rewriter.d.ts +15 -2
  179. package/src/dev/transform-server/dev-transform-import-rewriter.js +204 -35
  180. package/src/dev/transform-server/dev-transform-install-stamp.d.ts +17 -0
  181. package/src/dev/transform-server/dev-transform-install-stamp.js +79 -0
  182. package/src/dev/transform-server/dev-transform-server.d.ts +38 -2
  183. package/src/dev/transform-server/dev-transform-server.js +96 -33
  184. package/src/dev/transform-server/dev-transform-url.d.ts +4 -2
  185. package/src/dev/transform-server/dev-transform-url.js +13 -12
  186. package/src/dev/transform-server/dev-transform-vendor-registry.d.ts +178 -21
  187. package/src/dev/transform-server/dev-transform-vendor-registry.js +675 -99
  188. package/src/dev/transform-server/index.d.ts +1 -1
  189. package/src/dev-toolbar/dev-toolbar-package.js +4 -4
  190. package/src/eco/component-render-output.d.ts +6 -1
  191. package/src/eco/component-render-output.js +32 -7
  192. package/src/eco/discovered-dependencies.d.ts +30 -11
  193. package/src/eco/discovered-dependencies.js +25 -13
  194. package/src/eco/discovered-dependency-paths.d.ts +36 -0
  195. package/src/eco/discovered-dependency-paths.js +58 -0
  196. package/src/eco/eco.browser.js +8 -12
  197. package/src/eco/eco.js +0 -30
  198. package/src/eco/mdx-page-metadata.d.ts +14 -0
  199. package/src/eco/mdx-page-metadata.js +15 -0
  200. package/src/eco/page-layout-normalization.d.ts +6 -2
  201. package/src/eco/page-layout-normalization.js +9 -6
  202. package/src/env.js +17 -0
  203. package/src/hmr/client/hmr-runtime.js +14 -13
  204. package/src/hmr/dev-client-runtime.d.ts +5 -2
  205. package/src/hmr/dev-client-runtime.js +14 -4
  206. package/src/hmr/hmr-entrypoint-output.js +1 -1
  207. package/src/hmr/hmr-strategy.d.ts +2 -2
  208. package/src/hmr/hmr-strategy.js +2 -2
  209. package/src/hmr/strategies/js-hmr-strategy.d.ts +4 -1
  210. package/src/hmr/strategies/js-hmr-strategy.js +7 -6
  211. package/src/hmr/strategies/template-source-hmr-strategy.d.ts +25 -0
  212. package/src/hmr/strategies/template-source-hmr-strategy.js +36 -0
  213. package/src/html-pages/html-page-module-scripts.d.ts +2 -1
  214. package/src/html-pages/html-page-module-scripts.js +37 -14
  215. package/src/html-pages/html-page-module.js +1 -1
  216. package/src/html-pages/html-page-renderer.js +7 -6
  217. package/src/html-pages/html-page-template.d.ts +0 -5
  218. package/src/html-pages/html-page-template.js +3 -15
  219. package/src/html-pages/html-pages.plugin.js +2 -2
  220. package/src/integration.d.ts +8 -6
  221. package/src/integration.js +5 -3
  222. package/src/page-cache/html-page-cache-dependency-index.js +1 -1
  223. package/src/page-cache/page-cache-service.js +1 -1
  224. package/src/plugins/alias-resolver-plugin.d.ts +7 -0
  225. package/src/plugins/alias-resolver-plugin.js +16 -6
  226. package/src/plugins/component-import-discovery.d.ts +178 -7
  227. package/src/plugins/component-import-discovery.js +696 -112
  228. package/src/plugins/eco-component-meta-plugin.d.ts +47 -6
  229. package/src/plugins/eco-component-meta-plugin.js +227 -59
  230. package/src/plugins/foreign-jsx-override-plugin.d.ts +14 -1
  231. package/src/plugins/foreign-jsx-override-plugin.js +18 -8
  232. package/src/plugins/integration-plugin.d.ts +47 -11
  233. package/src/plugins/integration-plugin.js +57 -8
  234. package/src/plugins/processor.d.ts +72 -7
  235. package/src/plugins/processor.js +44 -9
  236. package/src/plugins/stylesheet-kinds.d.ts +57 -0
  237. package/src/plugins/stylesheet-kinds.js +114 -0
  238. package/src/plugins/tsconfig-import-resolver.d.ts +49 -3
  239. package/src/plugins/tsconfig-import-resolver.js +120 -6
  240. package/src/processor-contract.d.ts +66 -0
  241. package/src/processor-contract.js +389 -0
  242. package/src/processor.d.ts +6 -1
  243. package/src/processor.js +6 -1
  244. package/src/route-renderer/error-pages/default-error-pages.d.ts +1 -0
  245. package/src/route-renderer/error-pages/default-error-pages.js +27 -7
  246. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +8 -0
  247. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +12 -0
  248. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +77 -24
  249. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +97 -32
  250. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +1 -1
  251. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +9 -0
  252. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +16 -2
  253. package/src/route-renderer/orchestration/document-shell/layout-children-not-rendered-error.d.ts +35 -0
  254. package/src/route-renderer/orchestration/document-shell/layout-children-not-rendered-error.js +53 -0
  255. package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +4 -8
  256. package/src/route-renderer/orchestration/foreign-child/render-session.js +2 -5
  257. package/src/route-renderer/orchestration/integration-renderer.d.ts +171 -64
  258. package/src/route-renderer/orchestration/integration-renderer.js +293 -332
  259. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +8 -5
  260. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +27 -25
  261. package/src/route-renderer/orchestration/ownership-graph/component-graph.d.ts +0 -6
  262. package/src/route-renderer/orchestration/page-browser-graph/global-injector-assets.service.js +3 -3
  263. package/src/route-renderer/orchestration/page-browser-graph/grouped-graph-build-plan.d.ts +12 -25
  264. package/src/route-renderer/orchestration/page-browser-graph/grouped-graph-build-plan.js +1 -14
  265. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +0 -16
  266. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +1 -87
  267. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +8 -16
  268. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +25 -271
  269. package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.d.ts +0 -24
  270. package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.js +0 -67
  271. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.d.ts +28 -15
  272. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +63 -41
  273. package/src/route-renderer/page-loading/component-dependency-collection.d.ts +4 -1
  274. package/src/route-renderer/page-loading/component-dependency-collection.js +51 -15
  275. package/src/route-renderer/page-loading/dependency-resolver.d.ts +10 -0
  276. package/src/route-renderer/page-loading/dependency-resolver.js +27 -6
  277. package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +4 -2
  278. package/src/route-renderer/page-loading/file-scoped-dependency-components.js +22 -17
  279. package/src/route-renderer/page-loading/lazy-entry-collection.d.ts +5 -0
  280. package/src/route-renderer/page-loading/lazy-entry-collection.js +6 -4
  281. package/src/route-renderer/page-loading/page-dependency-bundling.d.ts +5 -2
  282. package/src/route-renderer/page-loading/page-dependency-bundling.js +15 -31
  283. package/src/route-renderer/page-loading/page-module-loader.d.ts +13 -2
  284. package/src/route-renderer/page-loading/page-module-loader.js +23 -5
  285. package/src/route-renderer/route-renderer.d.ts +1 -1
  286. package/src/router/client/navigation-commit.d.ts +2 -0
  287. package/src/router/client/navigation-commit.js +20 -3
  288. package/src/router/client/navigation-coordinator.d.ts +18 -0
  289. package/src/router/client/navigation-coordinator.js +14 -0
  290. package/src/router/client/navigation-head-order.fixture.css +3 -0
  291. package/src/router/client/navigation-head.d.ts +2 -1
  292. package/src/router/client/navigation-head.fixture.css +3 -0
  293. package/src/router/client/navigation-head.js +222 -39
  294. package/src/router/client/navigation-lifecycle.d.ts +8 -1
  295. package/src/router/client/navigation-lifecycle.js +6 -3
  296. package/src/router/client/navigation-pipeline.d.ts +1 -0
  297. package/src/router/client/navigation-pipeline.js +1 -0
  298. package/src/router/server/route-registry.d.ts +3 -2
  299. package/src/router/server/route-registry.js +6 -5
  300. package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +30 -18
  301. package/src/static-site-generator/production-page-browser-graph-prebuild.js +82 -143
  302. package/src/static-site-generator/static-site-generator.d.ts +37 -4
  303. package/src/static-site-generator/static-site-generator.js +99 -51
  304. package/src/types/asset-types.d.ts +19 -1
  305. package/src/types/build-types.d.ts +53 -35
  306. package/src/types/component-identity.d.ts +8 -0
  307. package/src/types/contracts.d.ts +69 -21
  308. package/src/types/dev-transform-types.d.ts +33 -6
  309. package/src/types/eco-api-types.d.ts +13 -18
  310. package/src/types/integration-types.d.ts +1 -1
  311. package/src/types/public-types.d.ts +1 -1
  312. package/src/utils/additional-watch-paths.js +3 -5
  313. package/src/utils/entry-command-flags.d.ts +23 -0
  314. package/src/utils/entry-command-flags.js +24 -0
  315. package/src/utils/package-path.d.ts +42 -0
  316. package/src/utils/package-path.js +114 -0
  317. package/src/utils/parse-cli-args.d.ts +18 -1
  318. package/src/utils/parse-cli-args.js +54 -37
  319. package/src/utils/path-containment.js +3 -10
  320. package/src/utils/resolve-work-dir.js +2 -2
  321. package/src/utils/root-relative-path.js +2 -2
  322. package/src/utils/server-bundle-context.d.ts +5 -0
  323. package/src/utils/server-bundle-context.js +7 -1
  324. package/src/utils/server-utils.module.js +1 -1
  325. package/src/watchers/project-watcher-ignore.js +3 -3
  326. package/src/watchers/project-watcher.d.ts +14 -2
  327. package/src/watchers/project-watcher.js +37 -6
  328. package/src/watchers/workspace-package-watch-roots.js +2 -2
  329. package/src/assets/app-browser-client-manifest.d.ts +0 -66
  330. package/src/assets/app-browser-client-manifest.js +0 -260
  331. package/src/assets/asset-processing-service/asset-package-role.d.ts +0 -2
  332. package/src/assets/asset-processing-service/asset-package-role.js +0 -3
  333. package/src/assets/asset-processing-service/browser-runtime-asset.factory.d.ts +0 -58
  334. package/src/assets/asset-processing-service/browser-runtime-asset.factory.js +0 -61
  335. package/src/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +0 -79
  336. package/src/assets/asset-processing-service/browser-runtime-entry-resolution.js +0 -200
  337. package/src/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +0 -24
  338. package/src/assets/asset-processing-service/browser-runtime-entry.factory.js +0 -67
  339. package/src/build/browser/browser-runtime-manifest.d.ts +0 -35
  340. package/src/build/browser/browser-runtime-manifest.js +0 -65
  341. package/src/build/browser/browser-runtime-plugin-helpers.d.ts +0 -14
  342. package/src/build/browser/browser-runtime-plugin-helpers.js +0 -21
  343. package/src/build/browser/browser-runtime-plugin.d.ts +0 -54
  344. package/src/build/browser/browser-runtime-plugin.js +0 -76
  345. package/src/build/rolldown/server-side-css-shim-plugin.d.ts +0 -28
  346. package/src/build/rolldown/server-side-css-shim-plugin.js +0 -59
  347. package/src/dev/transform-server/dev-transform-module-kind.d.ts +0 -13
  348. package/src/dev/transform-server/dev-transform-module-kind.js +0 -17
  349. package/src/dev/transform-server/dev-transform-runtime-specifiers.d.ts +0 -5
  350. package/src/dev/transform-server/dev-transform-runtime-specifiers.js +0 -16
  351. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +0 -15
  352. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +0 -65
  353. package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.d.ts +0 -21
  354. package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.js +0 -31
@@ -1,12 +1,15 @@
1
- import path from 'node:path';
2
- import { fileURLToPath } from 'node:url';
1
+ import { path } from '@ecopages/file-system/path';
3
2
  import { resolveBuildEntryPath } from '../build-graph.js';
3
+ import { fromRolldownModuleId } from './rolldown-module-id.js';
4
4
  /**
5
5
  * @remarks
6
6
  * Source dependencies come from the module graph before emission can inline or
7
7
  * remove modules. External ids are retained as leaves for local file hashing.
8
+ * The files a plugin declared with `addWatchFile` for a module join the closure
9
+ * of every entry that holds that module. An entry whose module Rolldown detected
10
+ * as CommonJS is also listed in `commonJsEntrypoints`.
8
11
  */
9
- export function createEntryModuleClosuresPlugin(graph, root) {
12
+ export function createEntryModuleClosuresPlugin(graph, root, watchFiles) {
10
13
  return {
11
14
  name: 'ecopages-entry-module-closures',
12
15
  generateBundle() {
@@ -15,14 +18,20 @@ export function createEntryModuleClosuresPlugin(graph, root) {
15
18
  const normalizedIds = new Map([...ids].map((id) => [
16
19
  id,
17
20
  id.startsWith('file:')
18
- ? fileURLToPath(id)
21
+ ? path.fromFileUrl(id)
19
22
  : id.startsWith('\0') || !infoById.get(id) || !path.isAbsolute(id)
20
- ? id
23
+ ? fromRolldownModuleId(id)
21
24
  : resolveBuildEntryPath(id, root),
22
25
  ]));
23
26
  for (const id of ids) {
24
- if (!infoById.get(id)?.isEntry)
27
+ const entryInfo = infoById.get(id);
28
+ if (!entryInfo?.isEntry)
25
29
  continue;
30
+ const entryPath = resolveBuildEntryPath(id, root);
31
+ const commonJsEntrypoints = (graph.commonJsEntrypoints ??= []);
32
+ if (entryInfo.inputFormat === 'cjs' && !commonJsEntrypoints.includes(entryPath)) {
33
+ commonJsEntrypoints.push(entryPath);
34
+ }
26
35
  const closure = new Set([id]);
27
36
  for (const moduleId of closure) {
28
37
  const info = infoById.get(moduleId);
@@ -31,8 +40,12 @@ export function createEntryModuleClosuresPlugin(graph, root) {
31
40
  for (const imported of [...info.importedIds, ...info.dynamicallyImportedIds])
32
41
  closure.add(imported);
33
42
  }
34
- graph.entrypoints[resolveBuildEntryPath(id, root)] = [...closure].map((moduleId) => normalizedIds.get(moduleId) ??
35
- (moduleId.startsWith('file:') ? fileURLToPath(moduleId) : moduleId));
43
+ const modules = [...closure].map((moduleId) => normalizedIds.get(moduleId) ??
44
+ (moduleId.startsWith('file:') ? path.fromFileUrl(moduleId) : fromRolldownModuleId(moduleId)));
45
+ const declared = [...closure].flatMap((moduleId) => [
46
+ ...(watchFiles.get(fromRolldownModuleId(moduleId)) ?? []),
47
+ ]);
48
+ graph.entrypoints[entryPath] = [...new Set([...modules, ...declared])];
36
49
  }
37
50
  },
38
51
  };
@@ -9,9 +9,20 @@
9
9
  *
10
10
  * @module
11
11
  */
12
+ import { type PathApi } from '@ecopages/file-system/path';
12
13
  import type { InputOptions, OutputOptions, RolldownOutput, RolldownPlugin } from 'rolldown';
13
- import type { BuildInputRecorder } from './rolldown-plugin-bridge.js';
14
+ import { type WatchFilesByModule } from './rolldown-plugin-bridge.js';
14
15
  import type { BuildDependencyGraph, BuildOptions, BuildLog, BuildSuccess } from '../build-adapter.js';
16
+ /**
17
+ * Returns the import specifier that a server output file in `outdir` uses to load an installed package file.
18
+ *
19
+ * @remarks
20
+ * The specifier is a `./` or `../` path relative to `outdir`. On Windows a package installed on another drive
21
+ * than `outdir` (a temp folder on `C:` and a checkout on `D:`) has no relative path, so it is a `file:` URL,
22
+ * which Node's ESM loader accepts where a bare `D:/` path is rejected. `pathApi` exists so tests can run the
23
+ * Windows rules on any platform.
24
+ */
25
+ export declare function toInstalledPackageExternalId(resolvedPath: string, outdir: string, pathApi?: PathApi): string;
15
26
  /**
16
27
  * Keeps installed compiled packages external as paths relative to the output
17
28
  * directory.
@@ -46,8 +57,8 @@ import type { BuildDependencyGraph, BuildOptions, BuildLog, BuildSuccess } from
46
57
  * Packages the app declares stay bare specifiers through the `external`
47
58
  * option, which Rolldown checks before this hook. Packages in
48
59
  * `CORE_RUNTIME_BUNDLED_PACKAGES`, workspace and source packages, anything
49
- * that does not resolve and anything on another drive than `outdir` are
50
- * bundled.
60
+ * that does not resolve are bundled. On Windows a package on another drive than
61
+ * `outdir` stays external as a `file:` URL.
51
62
  */
52
63
  export declare function createInstalledPackageExternalPlugin(contextRoot: string, outdir: string, reportDir?: string): RolldownPlugin;
53
64
  /**
@@ -77,8 +88,8 @@ export declare function toBuildLog(entry: unknown): BuildLog;
77
88
  * Converts a build failure into logs, one per underlying error of a Rolldown `BundleError`.
78
89
  *
79
90
  * @remarks
80
- * Only an unattributed `BundleError` is expanded. An `AggregateError` or an error an `EcoBuildPlugin`
81
- * threw is one failure and becomes one log.
91
+ * Only a `BundleError` is expanded. An `AggregateError` an `EcoBuildPlugin` setup threw is one failure
92
+ * and becomes one log.
82
93
  */
83
94
  export declare function toBuildLogs(error: unknown): BuildLog[];
84
95
  /** Translated Rolldown options for one {@link BuildOptions} request. */
@@ -89,9 +100,9 @@ export interface ResolvedRolldownOptions {
89
100
  /**
90
101
  * Translates a {@link BuildOptions} into Rolldown's `InputOptions` and
91
102
  * `OutputOptions`. Always sets `experimental.nativeMagicString: true`
92
- * and always consolidates eco plugins via the bridge, which runs every
93
- * plugin `setup`.
103
+ * and always maps eco plugins via the bridge, which runs every plugin
104
+ * `setup`. `watchFiles` receives the files those plugins declare.
94
105
  */
95
- export declare function resolveRolldownOptions(options: BuildOptions, contextRoot: string, outdir: string, appRootRequireCache: Map<string, NodeJS.Require>, recordBuildInput: BuildInputRecorder): Promise<ResolvedRolldownOptions>;
106
+ export declare function resolveRolldownOptions(options: BuildOptions, contextRoot: string, outdir: string, appRootRequireCache: Map<string, NodeJS.Require>, watchFiles: WatchFilesByModule): Promise<ResolvedRolldownOptions>;
96
107
  /** Maps a Rolldown `output` to the output fields of a {@link BuildSuccess}. */
97
108
  export declare function buildResultFromRolldownOutput(output: RolldownOutput, outdir: string, contextRoot: string, dependencyGraph: BuildDependencyGraph, entrypoints: BuildOptions['entrypoints'], naming?: BuildOptions['naming'], includeContent?: boolean): Pick<BuildSuccess, 'success' | 'outputs' | 'dependencyGraph' | 'outputGraph' | 'entryOutputs'>;
@@ -11,9 +11,8 @@
11
11
  */
12
12
  import { createHash } from 'node:crypto';
13
13
  import { builtinModules, createRequire } from 'node:module';
14
- import path from 'node:path';
14
+ import { path } from '@ecopages/file-system/path';
15
15
  import { fileSystem } from '@ecopages/file-system';
16
- import { fileURLToPath } from 'node:url';
17
16
  import { stripVTControlCharacters } from 'node:util';
18
17
  import { recordBuildEntryOutput, resolveBuildEntryPath } from '../build-graph.js';
19
18
  import { id as idFilter, include } from 'rolldown/filter';
@@ -23,12 +22,14 @@ import { isEcopagesEnvEnabled } from '../../env.js';
23
22
  import { isBarePackageImportSpecifier } from '../../plugins/tsconfig-import-resolver.js';
24
23
  import { toPackageRootSpecifier } from '../../plugins/package-specifier.js';
25
24
  import { isServerOnlyModuleSpecifier } from '../contracts/server-only-specifier.js';
26
- import { createServerSideCssShimPlugin } from './server-side-css-shim-plugin.js';
25
+ import { createWorkerEntriesPlugin } from './worker-entries-plugin.js';
26
+ import { createStylesheetModulePlugin } from './stylesheet-module-plugin.js';
27
27
  import { appLogger } from '../../global/app-logger.js';
28
28
  import { realpathOfDirectory } from '../preserve-import-meta-transform.js';
29
- import { createRolldownPluginBridge, getEcoBuildPluginName } from './rolldown-plugin-bridge.js';
29
+ import { fromRolldownModuleId } from './rolldown-module-id.js';
30
+ import { createRolldownPluginBridge } from './rolldown-plugin-bridge.js';
30
31
  import { isDeclaredAppPackageImport, isWorkspacePackageImport } from './app-package-declarations.js';
31
- const coreSourceFile = fileURLToPath(import.meta.url);
32
+ const coreSourceFile = path.fromFileUrl(import.meta.url);
32
33
  const nodeBuiltinSpecifiers = new Set(builtinModules);
33
34
  const MAX_FLATTENED_PRESERVED_MODULE_NAME_BYTES = 120;
34
35
  const PRESERVED_MODULE_NAME_HASH_LENGTH = 16;
@@ -46,7 +47,7 @@ function getCorePackageNames() {
46
47
  if (corePackageNames) {
47
48
  return corePackageNames;
48
49
  }
49
- const packageJsonPath = fileURLToPath(new URL('../../../package.json', import.meta.url));
50
+ const packageJsonPath = path.fromFileUrl(new URL('../../../package.json', import.meta.url));
50
51
  corePackageNames = new Set();
51
52
  try {
52
53
  const packageJson = JSON.parse(fileSystem.readFileSync(packageJsonPath));
@@ -107,7 +108,7 @@ function isAppPackageExternal(id, contextRoot, appRootRequireCache) {
107
108
  function createExternalMatcher(options, appRootRequireCache) {
108
109
  const explicitExternals = new Set(options.external ?? []);
109
110
  const externalPackages = options.externalPackages === true;
110
- const contextRoot = options.root ? path.resolve(options.root) : process.cwd();
111
+ const contextRoot = options.root ? path.resolve(options.root) : path.cwd();
111
112
  return (id) => {
112
113
  if (explicitExternals.has(id)) {
113
114
  return true;
@@ -157,7 +158,23 @@ function isUndeclaredPackageImport(id, contextRoot) {
157
158
  * loader, so PnP installs are not supported for relocated server output.
158
159
  */
159
160
  function isInstalledCompiledModule(filePath) {
160
- return /\.[cm]?js$/u.test(filePath) && /[\\/]node_modules[\\/]/u.test(filePath) && !/\.zip[\\/]/u.test(filePath);
161
+ return /\.[cm]?js$/u.test(filePath) && filePath.includes('/node_modules/') && !filePath.includes('.zip/');
162
+ }
163
+ /**
164
+ * Returns the import specifier that a server output file in `outdir` uses to load an installed package file.
165
+ *
166
+ * @remarks
167
+ * The specifier is a `./` or `../` path relative to `outdir`. On Windows a package installed on another drive
168
+ * than `outdir` (a temp folder on `C:` and a checkout on `D:`) has no relative path, so it is a `file:` URL,
169
+ * which Node's ESM loader accepts where a bare `D:/` path is rejected. `pathApi` exists so tests can run the
170
+ * Windows rules on any platform.
171
+ */
172
+ export function toInstalledPackageExternalId(resolvedPath, outdir, pathApi = path) {
173
+ const relativePath = pathApi.relative(outdir, resolvedPath);
174
+ if (pathApi.isAbsolute(relativePath)) {
175
+ return pathApi.toFileUrl(resolvedPath).href;
176
+ }
177
+ return relativePath.startsWith('../') ? relativePath : `./${relativePath}`;
161
178
  }
162
179
  /**
163
180
  * Keeps installed compiled packages external as paths relative to the output
@@ -193,8 +210,8 @@ function isInstalledCompiledModule(filePath) {
193
210
  * Packages the app declares stay bare specifiers through the `external`
194
211
  * option, which Rolldown checks before this hook. Packages in
195
212
  * `CORE_RUNTIME_BUNDLED_PACKAGES`, workspace and source packages, anything
196
- * that does not resolve and anything on another drive than `outdir` are
197
- * bundled.
213
+ * that does not resolve are bundled. On Windows a package on another drive than
214
+ * `outdir` stays external as a `file:` URL.
198
215
  */
199
216
  export function createInstalledPackageExternalPlugin(contextRoot, outdir, reportDir) {
200
217
  const coreNames = getCorePackageNames();
@@ -214,19 +231,19 @@ export function createInstalledPackageExternalPlugin(contextRoot, outdir, report
214
231
  const resolveOptions = { kind: extraOptions.kind, skipSelf: true };
215
232
  const resolved = (importer ? await this.resolve(id, importer, resolveOptions) : null) ??
216
233
  (coreNames.has(packageName) ? await this.resolve(id, coreSourceFile, resolveOptions) : null);
217
- if (!resolved || resolved.external || !isInstalledCompiledModule(resolved.id)) {
234
+ const resolvedPath = resolved && !resolved.external ? fromRolldownModuleId(resolved.id) : undefined;
235
+ if (!resolvedPath || !isInstalledCompiledModule(resolvedPath)) {
218
236
  return null;
219
237
  }
220
238
  realOutdir ??= realpathOfDirectory(outdir);
221
- const relativePath = path.relative(realOutdir, resolved.id).split(path.sep).join('/');
222
- if (path.isAbsolute(relativePath)) {
223
- return null;
224
- }
225
239
  realContextRoot ??= realpathOfDirectory(contextRoot);
226
- if (reportDir && !isPathInside(resolved.id, realContextRoot)) {
240
+ if (reportDir && !isPathInside(resolvedPath, realContextRoot)) {
227
241
  outsideRootPackages.add(packageName);
228
242
  }
229
- const externalId = relativePath.startsWith('../') ? relativePath : `./${relativePath}`;
243
+ const externalId = toInstalledPackageExternalId(resolvedPath, realOutdir);
244
+ if (externalId.startsWith('file:')) {
245
+ return { id: externalId, external: true };
246
+ }
230
247
  externalIds.add(externalId);
231
248
  return { id: externalId, external: true };
232
249
  },
@@ -245,7 +262,7 @@ export function createInstalledPackageExternalPlugin(contextRoot, outdir, report
245
262
  }
246
263
  if (reportDir) {
247
264
  const outputLabel = entryFileNames
248
- .map((fileName) => path.relative(contextRoot, path.join(reportDir, fileName)).split(path.sep).join('/'))
265
+ .map((fileName) => path.relative(contextRoot, path.join(reportDir, fileName)))
249
266
  .join(', ');
250
267
  warnPackagesOutsideAppRoot(outputLabel, outsideRootPackages);
251
268
  }
@@ -271,8 +288,8 @@ const nodeBuiltinFilter = new RegExp(`^(?:node:.*|${[...nodeBuiltinSpecifiers].m
271
288
  */
272
289
  export function createBrowserServerOnlyGuardPlugin() {
273
290
  const rejectServerOnly = (id, importer) => {
274
- const from = importer ? ` (imported from ${importer})` : '';
275
- throw new Error(`[browser-build] server-only module "${id}" cannot be bundled for the browser${from}. Check the browser graph boundary for the importer.`);
291
+ const from = importer ? ` (imported from ${fromRolldownModuleId(importer)})` : '';
292
+ throw new Error(`[browser-build] server-only module "${fromRolldownModuleId(id)}" cannot be bundled for the browser${from}. Check the browser graph boundary for the importer.`);
276
293
  };
277
294
  return {
278
295
  name: 'ecopages-browser-server-only-guard',
@@ -282,7 +299,7 @@ export function createBrowserServerOnlyGuardPlugin() {
282
299
  if (!isNodeBuiltinSpecifier(id)) {
283
300
  return null;
284
301
  }
285
- const from = importer ? ` (imported from ${importer})` : '';
302
+ const from = importer ? ` (imported from ${fromRolldownModuleId(importer)})` : '';
286
303
  throw new Error(`[browser-build] Node builtin "${id}" cannot be bundled for the browser${from}. Check package "browser" exports and the client-graph boundary for the importer.`);
287
304
  },
288
305
  },
@@ -380,29 +397,29 @@ export function toBuildLog(entry) {
380
397
  Object.assign(log, { [key]: source[key] });
381
398
  }
382
399
  }
400
+ if (typeof log.id === 'string') {
401
+ log.id = fromRolldownModuleId(log.id);
402
+ }
403
+ if (typeof log.loc?.file === 'string') {
404
+ log.loc = { ...log.loc, file: fromRolldownModuleId(log.loc.file) };
405
+ }
383
406
  if (typeof source.frame === 'string') {
384
407
  log.frame = stripVTControlCharacters(source.frame);
385
408
  }
386
409
  if (typeof source.stack === 'string') {
387
410
  log.stack = source.stack;
388
411
  }
389
- const ecoBuildPluginName = getEcoBuildPluginName(entry);
390
- if (ecoBuildPluginName) {
391
- log.plugin = ecoBuildPluginName;
392
- }
393
412
  return log;
394
413
  }
395
414
  /**
396
415
  * Converts a build failure into logs, one per underlying error of a Rolldown `BundleError`.
397
416
  *
398
417
  * @remarks
399
- * Only an unattributed `BundleError` is expanded. An `AggregateError` or an error an `EcoBuildPlugin`
400
- * threw is one failure and becomes one log.
418
+ * Only a `BundleError` is expanded. An `AggregateError` an `EcoBuildPlugin` setup threw is one failure
419
+ * and becomes one log.
401
420
  */
402
421
  export function toBuildLogs(error) {
403
- const errors = error instanceof Error && !(error instanceof AggregateError) && !getEcoBuildPluginName(error)
404
- ? error.errors
405
- : undefined;
422
+ const errors = error instanceof Error && !(error instanceof AggregateError) ? error.errors : undefined;
406
423
  return (Array.isArray(errors) && errors.length > 0 ? errors : [error]).map(toBuildLog);
407
424
  }
408
425
  function buildRolldownTransformOptions(options) {
@@ -418,11 +435,11 @@ function buildRolldownTransformOptions(options) {
418
435
  }
419
436
  return Object.keys(transformOptions).length > 0 ? transformOptions : undefined;
420
437
  }
421
- async function buildRolldownInputPlugins(options, contextRoot, outdir, rolldownPlatform, recordBuildInput) {
438
+ async function buildRolldownInputPlugins(options, contextRoot, outdir, rolldownPlatform, watchFiles) {
422
439
  const entrypoints = Array.isArray(options.entrypoints)
423
440
  ? Object.fromEntries(options.entrypoints.map((entry, index) => [String(index), entry]))
424
441
  : options.entrypoints;
425
- const appPlugins = await createRolldownPluginBridge((options.plugins ?? []).filter((plugin) => plugin.environments?.includes(options.environment) ?? true), contextRoot, recordBuildInput, entrypoints);
442
+ const appPlugins = await createRolldownPluginBridge((options.plugins ?? []).filter((plugin) => plugin.environments?.includes(options.environment) ?? true), contextRoot, { entrypoints, watchFiles });
426
443
  return [
427
444
  ...(options.externalPackages === true
428
445
  ? [
@@ -430,11 +447,12 @@ async function buildRolldownInputPlugins(options, contextRoot, outdir, rolldownP
430
447
  ]
431
448
  : []),
432
449
  ...(rolldownPlatform === 'browser' ? [createBrowserServerOnlyGuardPlugin()] : []),
433
- ...(options.environment === 'server' ? [createServerSideCssShimPlugin()] : []),
450
+ createStylesheetModulePlugin({ environment: options.environment, root: contextRoot }, options.stylesheets, watchFiles),
434
451
  ...appPlugins,
452
+ ...(options.environment === 'browser' && options.workerEntries !== false ? [createWorkerEntriesPlugin()] : []),
435
453
  ];
436
454
  }
437
- async function buildRolldownInputOptions(options, contextRoot, outdir, external, rolldownPlatform, recordBuildInput) {
455
+ async function buildRolldownInputOptions(options, contextRoot, outdir, external, rolldownPlatform, watchFiles) {
438
456
  return {
439
457
  input: options.entrypoints,
440
458
  cwd: contextRoot,
@@ -453,7 +471,7 @@ async function buildRolldownInputOptions(options, contextRoot, outdir, external,
453
471
  experimental: {
454
472
  nativeMagicString: true,
455
473
  },
456
- plugins: await buildRolldownInputPlugins(options, contextRoot, outdir, rolldownPlatform, recordBuildInput),
474
+ plugins: await buildRolldownInputPlugins(options, contextRoot, outdir, rolldownPlatform, watchFiles),
457
475
  };
458
476
  }
459
477
  function resolveRolldownEntryFileNames(options) {
@@ -486,7 +504,12 @@ function truncateUtf8(value, maximumBytes) {
486
504
  return prefix;
487
505
  }
488
506
  function flattenPreservedModuleName(sourceName) {
489
- const flattened = sourceName.replaceAll(/[\\/]/g, '-');
507
+ const flattened = path
508
+ .fromNative(sourceName)
509
+ .split('/')
510
+ .filter((segment) => segment !== '' && segment !== '.' && segment !== '..')
511
+ .join('-')
512
+ .replaceAll(':', '');
490
513
  if (Buffer.byteLength(flattened) <= MAX_FLATTENED_PRESERVED_MODULE_NAME_BYTES)
491
514
  return flattened;
492
515
  const digest = createHash('sha256').update(sourceName).digest('hex').slice(0, PRESERVED_MODULE_NAME_HASH_LENGTH);
@@ -505,6 +528,17 @@ function flattenPreservedModuleName(sourceName) {
505
528
  function flattenPreservedModuleFileNames(pattern) {
506
529
  return (chunk) => pattern.replaceAll('[name]', () => flattenPreservedModuleName(chunk.name));
507
530
  }
531
+ /**
532
+ * Sanitizes the name Rolldown gives a preserved module before it fills `[name]`.
533
+ *
534
+ * @remarks
535
+ * A module on another drive than `preserveModulesRoot` has no path relative to it, and Rolldown names it with a
536
+ * `../` prefix that it rejects as a `[name]` substitution before `entryFileNames` can rewrite it. The prefix is
537
+ * dropped here, along with the characters Rolldown's default sanitizer removes.
538
+ */
539
+ function sanitizePreservedModuleName(name) {
540
+ return name.replace(/^(?:\.\.?\/)+/u, '').replaceAll(/[\0?*:]/gu, '_');
541
+ }
508
542
  function buildRolldownOutputOptions(options, outdir) {
509
543
  const entryFileNames = resolveRolldownEntryFileNames(options);
510
544
  return {
@@ -517,7 +551,10 @@ function buildRolldownOutputOptions(options, outdir) {
517
551
  ...(options.preserveModules
518
552
  ? {
519
553
  preserveModules: true,
520
- ...(options.preserveModulesRoot ? { preserveModulesRoot: options.preserveModulesRoot } : {}),
554
+ sanitizeFileName: sanitizePreservedModuleName,
555
+ ...(options.preserveModulesRoot
556
+ ? { preserveModulesRoot: path.toNative(options.preserveModulesRoot) }
557
+ : {}),
521
558
  }
522
559
  : {}),
523
560
  sourcemap: mapRolldownSourcemap(options.sourcemap),
@@ -527,14 +564,14 @@ function buildRolldownOutputOptions(options, outdir) {
527
564
  /**
528
565
  * Translates a {@link BuildOptions} into Rolldown's `InputOptions` and
529
566
  * `OutputOptions`. Always sets `experimental.nativeMagicString: true`
530
- * and always consolidates eco plugins via the bridge, which runs every
531
- * plugin `setup`.
567
+ * and always maps eco plugins via the bridge, which runs every plugin
568
+ * `setup`. `watchFiles` receives the files those plugins declare.
532
569
  */
533
- export async function resolveRolldownOptions(options, contextRoot, outdir, appRootRequireCache, recordBuildInput) {
570
+ export async function resolveRolldownOptions(options, contextRoot, outdir, appRootRequireCache, watchFiles) {
534
571
  const rolldownPlatform = options.environment === 'browser' ? 'browser' : 'node';
535
572
  const external = createExternalMatcher(options, appRootRequireCache);
536
573
  return {
537
- inputOptions: await buildRolldownInputOptions(options, contextRoot, outdir, external, rolldownPlatform, recordBuildInput),
574
+ inputOptions: await buildRolldownInputOptions(options, contextRoot, outdir, external, rolldownPlatform, watchFiles),
538
575
  outputOptions: buildRolldownOutputOptions(options, outdir),
539
576
  };
540
577
  }
@@ -550,10 +587,10 @@ export async function resolveRolldownOptions(options, contextRoot, outdir, appRo
550
587
  function isContentHashedOutput(entry, entryNamingHashed) {
551
588
  if (entry.type === 'chunk')
552
589
  return entry.isEntry ? entryNamingHashed : true;
553
- const fileName = path.posix.basename(entry.fileName);
590
+ const fileName = path.basename(entry.fileName);
554
591
  return entry.names.some((name) => {
555
- const extension = path.posix.extname(name);
556
- const stem = path.posix.basename(name, extension);
592
+ const extension = path.extname(name);
593
+ const stem = path.basename(name, extension);
557
594
  return (fileName.startsWith(`${stem}-`) &&
558
595
  fileName.endsWith(extension) &&
559
596
  /^[A-Za-z0-9_-]+$/u.test(fileName.slice(stem.length + 1, fileName.length - extension.length)));
@@ -569,7 +606,7 @@ function isHashedSourceMap(fileName, hashedFileNames) {
569
606
  function sourceModulePath(moduleId, root) {
570
607
  if (moduleId.startsWith('\0'))
571
608
  return [];
572
- const filePath = moduleId.startsWith('file:') ? fileURLToPath(moduleId) : moduleId;
609
+ const filePath = moduleId.startsWith('file:') ? path.fromFileUrl(moduleId) : moduleId;
573
610
  return path.isAbsolute(filePath) ? [resolveBuildEntryPath(filePath, root)] : [];
574
611
  }
575
612
  /** Maps a Rolldown `output` to the output fields of a {@link BuildSuccess}. */
@@ -9,12 +9,11 @@
9
9
  * Each `build()` creates a fresh `rolldown()` bundler.
10
10
  */
11
11
  import { createRequire } from 'node:module';
12
- import path from 'node:path';
12
+ import { path } from '@ecopages/file-system/path';
13
13
  import { rolldown } from 'rolldown';
14
14
  import { buildResultFromRolldownOutput, resolveRolldownOptions, toBuildLog, toBuildLogs, } from './rolldown-adapter-helpers.js';
15
15
  import { recordRolldownBuildInvocation } from './rolldown-build-invocation-metrics.js';
16
16
  import { createEntryModuleClosuresPlugin } from './entry-module-closures.js';
17
- import { createBuildInputRecorder, getBuildInputRecordingContext } from '../cache/build-input-dependency-index.js';
18
17
  const moduleRequire = createRequire(import.meta.url);
19
18
  export class RolldownBuildAdapter {
20
19
  /** Per-adapter require cache, keyed on resolved context root. */
@@ -31,15 +30,15 @@ export class RolldownBuildAdapter {
31
30
  throw new Error('Build requests require environment: "server" or "browser".');
32
31
  }
33
32
  recordRolldownBuildInvocation();
34
- const contextRoot = options.root ? path.resolve(options.root) : process.cwd();
33
+ const contextRoot = options.root ? path.resolve(options.root) : path.cwd();
35
34
  const outdir = path.resolve(options.outdir ?? 'dist/client/assets');
36
- const recordingContext = getBuildInputRecordingContext();
37
- const loadedInputs = new Set();
38
- const loadedInputsByModule = new Map();
39
- const recordBuildInput = createBuildInputRecorder(recordingContext, loadedInputs, loadedInputsByModule);
40
- const { inputOptions, outputOptions } = await resolveRolldownOptions(options, contextRoot, outdir, this.appRootRequireCache, recordBuildInput);
41
- const dependencyGraph = { entrypoints: {} };
42
- inputOptions.plugins = [inputOptions.plugins, createEntryModuleClosuresPlugin(dependencyGraph, contextRoot)];
35
+ const watchFiles = new Map();
36
+ const { inputOptions, outputOptions } = await resolveRolldownOptions(options, contextRoot, outdir, this.appRootRequireCache, watchFiles);
37
+ const dependencyGraph = { entrypoints: {}, commonJsEntrypoints: [] };
38
+ inputOptions.plugins = [
39
+ inputOptions.plugins,
40
+ createEntryModuleClosuresPlugin(dependencyGraph, contextRoot, watchFiles),
41
+ ];
43
42
  const warnings = [];
44
43
  const bundle = await rolldown({
45
44
  ...inputOptions,
@@ -56,8 +55,6 @@ export class RolldownBuildAdapter {
56
55
  : await bundle.write(outputOptions);
57
56
  return {
58
57
  ...buildResultFromRolldownOutput(output, outdir, contextRoot, dependencyGraph, options.entrypoints, options.naming, options.writeToDisk === false),
59
- loadedInputs: [...loadedInputs],
60
- loadedInputsByModule: Object.fromEntries([...loadedInputsByModule].map(([moduleId, paths]) => [moduleId, [...paths]])),
61
58
  warnings,
62
59
  };
63
60
  }
@@ -77,7 +74,7 @@ export class RolldownBuildAdapter {
77
74
  }
78
75
  }
79
76
  resolve(importPath, rootDir) {
80
- return moduleRequire.resolve(importPath, { paths: [rootDir] });
77
+ return path.fromNative(moduleRequire.resolve(importPath, { paths: [rootDir] }));
81
78
  }
82
79
  }
83
80
  export function createRolldownBuildAdapter() {
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Converts a module id Rolldown hands to a hook into an Ecopages path.
3
+ *
4
+ * @remarks
5
+ * Rolldown's resolver returns native paths, so on Windows a module id arrives with backslashes. Virtual ids
6
+ * (`\0...`) and bare specifiers pass through unchanged.
7
+ */
8
+ export declare function fromRolldownModuleId(id: string): string;
9
+ /**
10
+ * Converts a path a hook resolves into the module id form Rolldown's own resolver produces.
11
+ *
12
+ * @remarks
13
+ * Rolldown keys modules by id string. On Windows its resolver returns backslash paths, so a plugin that resolved
14
+ * the same file to a forward-slash id would make it a second module. A query or hash after the path is kept as
15
+ * written. Only a drive-letter path is converted: a root-relative id such as `/assets/vendors/react.js` is a URL
16
+ * an external import keeps, not a file.
17
+ */
18
+ export declare function toRolldownModuleId(id: string): string;
@@ -0,0 +1,29 @@
1
+ import { path } from '@ecopages/file-system/path';
2
+ const WINDOWS_DRIVE_PATH = /^[A-Za-z]:\//u;
3
+ /**
4
+ * Converts a module id Rolldown hands to a hook into an Ecopages path.
5
+ *
6
+ * @remarks
7
+ * Rolldown's resolver returns native paths, so on Windows a module id arrives with backslashes. Virtual ids
8
+ * (`\0...`) and bare specifiers pass through unchanged.
9
+ */
10
+ export function fromRolldownModuleId(id) {
11
+ return path.fromNative(id);
12
+ }
13
+ /**
14
+ * Converts a path a hook resolves into the module id form Rolldown's own resolver produces.
15
+ *
16
+ * @remarks
17
+ * Rolldown keys modules by id string. On Windows its resolver returns backslash paths, so a plugin that resolved
18
+ * the same file to a forward-slash id would make it a second module. A query or hash after the path is kept as
19
+ * written. Only a drive-letter path is converted: a root-relative id such as `/assets/vendors/react.js` is a URL
20
+ * an external import keeps, not a file.
21
+ */
22
+ export function toRolldownModuleId(id) {
23
+ if (!WINDOWS_DRIVE_PATH.test(id))
24
+ return id;
25
+ const suffixIndex = id.search(/[?#]/u);
26
+ return suffixIndex === -1
27
+ ? path.toNative(id)
28
+ : `${path.toNative(id.slice(0, suffixIndex))}${id.slice(suffixIndex)}`;
29
+ }
@@ -2,75 +2,39 @@
2
2
  * Bundler plugin bridge.
3
3
  *
4
4
  * @remarks
5
- * Translates an array of `EcoBuildPlugin` instances (the runtime-agnostic
6
- * plugin contract used by Ecopages processors and integrations) into
7
- * the bundler's native `Plugin` array. The bridge exposes the same
8
- * four hooks (`onResolve`, `onLoad`, `transform`, `module`) the
9
- * `EcoBuildPlugin` contract uses, but maps them to the bundler's
10
- * `resolveId`/`load`/`transform` hooks.
11
- *
12
- * The shared `EcoBuildPlugin` contract stays the boundary between
13
- * integrations and bundler backends.
14
- *
15
- * **Namespace handling.**
16
- *
17
- * The shared `EcoBuildPlugin` contract scopes `onResolve`/`onLoad`
18
- * handlers with a `namespace` string. The bundler encodes namespaces
19
- * into the module id (no separate field). The bridge prepends
20
- * `<namespace>:` to the resolved id when the result includes a
21
- * namespace. A namespaced `onLoad`/`onResolve` filter matches only ids
22
- * with that prefix, and is tested against the path after it. The bridge
23
- * strips the prefix before forwarding the id back
24
- * to the callback so plugin code keeps seeing the same `path` shape
25
- * it did on the historical contract.
5
+ * Translates `EcoBuildPlugin` instances (the runtime-agnostic plugin contract used by Ecopages
6
+ * processors and integrations) into Rolldown plugins. Every handler a plugin registers becomes its
7
+ * own Rolldown plugin, named after the `EcoBuildPlugin` and carrying the handler's filter as a native
8
+ * hook filter: `onResolve` maps to `resolveId`, `onLoad` to `load`, `transform` to `transform`,
9
+ * `onEnd` to `buildEnd`, and `module` to a `resolveId` and `load` pair for a `\0` virtual id.
26
10
  *
27
11
  * **Plugin ordering is semantically significant.**
28
12
  *
29
- * All `EcoBuildPlugin` instances are merged into one Rolldown plugin.
30
- * Its `resolveId` and `load` check the registrations in `plugins` array
31
- * order, and the first non-null result wins. `transform` runs every
32
- * matching registration in array order. The position of each plugin in
33
- * the array determines its priority:
34
- *
35
- * - **Index 0** has the highest priority.
36
- * - **Last index** has the lowest priority.
37
- *
38
- * When adding new integrations or processors, ensure security-critical
39
- * plugins (e.g. `ecopages-client-graph-boundary`) are placed **before**
40
- * general-purpose loaders in the array so they always get first refusal
41
- * on every source file.
13
+ * The Rolldown plugins keep the order of the `plugins` array, and of the handlers inside each
14
+ * plugin. Rolldown gives the first non-null `resolveId` and `load` result precedence, and runs every
15
+ * matching `transform` in order, chaining their source maps. Index 0 has the highest priority, so
16
+ * security-critical plugins (e.g. `ecopages-client-graph-boundary`) go **before** general-purpose
17
+ * loaders, to get first refusal on every source file.
42
18
  */
43
19
  import type { Plugin } from 'rolldown';
44
20
  import type { EcoBuildPlugin } from '../contracts/build-types.js';
45
- /** Returns the name of the `EcoBuildPlugin` that threw `error` inside the bridge, if any. */
46
- export declare function getEcoBuildPluginName(error: unknown): string | undefined;
47
- export type BuildInputRecorder = (moduleId: string, filePath: string) => void;
21
+ /** Files each module's plugins declared with `addWatchFile`, keyed by Rolldown module id. */
22
+ export type WatchFilesByModule = Map<string, Set<string>>;
48
23
  /**
49
- * Creates the single Rolldown `Plugin` that drives the supplied
50
- * `EcoBuildPlugin` instances.
51
- *
52
- * All eco plugins are merged into one Rolldown plugin. Its `resolveId`
53
- * and `load` hooks check the registrations in `plugins` array order, so
54
- * registrations from earlier eco plugins win over later ones. `transform`
55
- * runs every matching registration in that same order.
24
+ * Creates the Rolldown plugins that drive the supplied `EcoBuildPlugin` instances.
56
25
  *
57
26
  * @remarks
58
- * Every `setup` runs here, before the plugin object exists, because
59
- * Rolldown reads hook filters when the plugin is registered. Each hook
60
- * declares the union of its registrations as a hook filter, so Rolldown
61
- * calls into JavaScript only for ids that at least one registration may
62
- * match. A namespaced registration contributes only `^<namespace>:`; its
63
- * exact filter is tested in JavaScript against the path after the prefix.
64
- * Transform filters are tested with the query and hash stripped. Rolldown
65
- * tests filters against ids with `/` separators, so a filter written for
66
- * backslash separators does not match on Windows.
67
- *
68
- * Every build creates a new bridge, so registrations and the
69
- * virtual-module counter never carry over between builds.
27
+ * Every `setup` runs here, in order, before any Rolldown plugin exists, because Rolldown reads hook
28
+ * filters when a plugin is registered; a handler registered later throws. Every builder shares one
29
+ * `entrypoints` object, so a plugin can key state on it for one build. Transform filters are tested
30
+ * with the query and hash stripped and never see a `\0` virtual id. Rolldown tests filters against
31
+ * ids with `/` separators, so a filter written for backslash separators does not match on Windows.
70
32
  *
71
33
  * @param plugins - `EcoBuildPlugin` instances registered for this build.
72
- * @param contextRoot - Project root used to resolve relative load paths.
73
- * @param recordBuildInput - Records filesystem paths this load read so watch
74
- * and invalidation include them.
34
+ * @param contextRoot - Project root used to resolve a relative path an `onResolve` callback returns.
35
+ * @param options.watchFiles - Receives each file a callback declares with `addWatchFile`, under the module it ran for.
75
36
  */
76
- export declare function createRolldownPluginBridge(plugins: EcoBuildPlugin[], contextRoot: string, recordBuildInput?: BuildInputRecorder, entrypoints?: Readonly<Record<string, string>>): Promise<Plugin[]>;
37
+ export declare function createRolldownPluginBridge(plugins: EcoBuildPlugin[], contextRoot: string, options?: {
38
+ entrypoints?: Readonly<Record<string, string>>;
39
+ watchFiles?: WatchFilesByModule;
40
+ }): Promise<Plugin[]>;