@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
@@ -68,6 +68,7 @@ export interface AppliedDevFileChanges {
68
68
  */
69
69
  export declare class DevelopmentInvalidationService {
70
70
  private readonly appConfig;
71
+ private stylesheetKinds?;
71
72
  constructor(appConfig: EcoPagesAppConfig);
72
73
  /**
73
74
  * Marks the app-owned server-module graph stale and advances the development generation.
@@ -100,7 +101,9 @@ export declare class DevelopmentInvalidationService {
100
101
  * file it imports) would otherwise leave the cached import serving the old content, because cached
101
102
  * imports no longer re-hash their dependencies. A source file also used by a browser entrypoint
102
103
  * reloads the browser so server-rendered markup is refreshed when the same module is used by an
103
- * island. Other categories keep their own reload and processing behavior.
104
+ * island. A processor-owned stylesheet a browser module imports also goes to HMR, which hot-updates that module
105
+ * with the new CSS, while the Processor still refreshes the links that deliver it. Other categories keep their own
106
+ * reload and processing behavior.
104
107
  */
105
108
  planFileChange(filePath: string, context?: DevelopmentInvalidationPlanningContext): DevelopmentInvalidationPlan;
106
109
  private classifyFileChange;
@@ -130,6 +133,8 @@ export declare class DevelopmentInvalidationService {
130
133
  isIncludeSourceFile(filePath: string): boolean;
131
134
  /** Returns whether a file is an explicit server-rendered view module. */
132
135
  isExplicitServerViewFile(filePath: string): boolean;
136
+ /** Returns whether a file under the source directory has an integration template extension. */
137
+ isTemplateSourceFile(filePath: string): boolean;
133
138
  /**
134
139
  * Returns whether the file is a route source file.
135
140
  */
@@ -1,10 +1,12 @@
1
- import path from 'node:path';
1
+ import { getStylesheetKinds } from '../../plugins/stylesheet-kinds.js';
2
+ import { path } from '@ecopages/file-system/path';
2
3
  import { isDevEnvFilePath } from '../development-restart-watch-paths.js';
3
4
  import { matchesAdditionalWatchPath, resolveAdditionalWatchPath } from '../../utils/additional-watch-paths.js';
4
5
  import { isPathInside } from '../../utils/path-containment.js';
5
6
  import { clearAppDevelopmentRouteModuleBuildCaches } from '../../build/server/route-module-build-cache-registry.js';
6
7
  import { clearAppPageCache, invalidateAppPageCacheBySourcePaths } from '../../page-cache/page-cache-service.js';
7
8
  import { requireAppRuntime } from '../../utils/app-runtime.js';
9
+ import { forgetDiscoveryOwner } from '../../plugins/component-import-discovery.js';
8
10
  const sourceFileExtension = /\.(?:[cm]?ts|[jt]sx?|mdx)$/u;
9
11
  const INVALIDATION_PLAN_BY_CATEGORY = {
10
12
  'runtime-restart': {
@@ -77,6 +79,7 @@ const INVALIDATION_PLAN_BY_CATEGORY = {
77
79
  */
78
80
  export class DevelopmentInvalidationService {
79
81
  appConfig;
82
+ stylesheetKinds;
80
83
  constructor(appConfig) {
81
84
  this.appConfig = appConfig;
82
85
  }
@@ -112,6 +115,7 @@ export class DevelopmentInvalidationService {
112
115
  }
113
116
  for (const filePath of changes.deleted) {
114
117
  byPath.set(path.resolve(filePath), 'deleted');
118
+ forgetDiscoveryOwner(this.appConfig.rootDir, filePath);
115
119
  }
116
120
  const files = [];
117
121
  for (const [filePath, kind] of byPath) {
@@ -193,7 +197,9 @@ export class DevelopmentInvalidationService {
193
197
  * file it imports) would otherwise leave the cached import serving the old content, because cached
194
198
  * imports no longer re-hash their dependencies. A source file also used by a browser entrypoint
195
199
  * reloads the browser so server-rendered markup is refreshed when the same module is used by an
196
- * island. Other categories keep their own reload and processing behavior.
200
+ * island. A processor-owned stylesheet a browser module imports also goes to HMR, which hot-updates that module
201
+ * with the new CSS, while the Processor still refreshes the links that deliver it. Other categories keep their own
202
+ * reload and processing behavior.
197
203
  */
198
204
  planFileChange(filePath, context = {}) {
199
205
  const category = this.classifyFileChange(filePath, context);
@@ -201,9 +207,13 @@ export class DevelopmentInvalidationService {
201
207
  const inputIndex = requireAppRuntime(this.appConfig).buildInputIndex;
202
208
  const readByServerRouteModule = inputIndex.resolveKeys('server-route-module', filePath).length > 0;
203
209
  const readByBrowserEntrypoint = inputIndex.resolveKeys('entrypoint', filePath).length > 0;
210
+ const stylesheetReadByBrowserModule = category === 'processor-owned-asset' &&
211
+ readByBrowserEntrypoint &&
212
+ (this.stylesheetKinds ??= getStylesheetKinds(this.appConfig)).isStylesheet(filePath);
204
213
  return {
205
214
  category,
206
215
  ...plan,
216
+ delegateToHmr: plan.delegateToHmr || stylesheetReadByBrowserModule,
207
217
  invalidateServerModules: plan.invalidateServerModules || readByServerRouteModule,
208
218
  reloadBrowser: plan.reloadBrowser || (category === 'source' && readByServerRouteModule && readByBrowserEntrypoint),
209
219
  };
@@ -286,6 +296,12 @@ export class DevelopmentInvalidationService {
286
296
  const viewsDir = path.join(this.appConfig.absolutePaths.srcDir, 'views');
287
297
  return isPathInside(resolvedPath, viewsDir) && this.isSourceFile(resolvedPath);
288
298
  }
299
+ /** Returns whether a file under the source directory has an integration template extension. */
300
+ isTemplateSourceFile(filePath) {
301
+ const resolvedPath = path.resolve(filePath);
302
+ return (isPathInside(resolvedPath, this.appConfig.absolutePaths.srcDir) &&
303
+ this.appConfig.templatesExt.some((extension) => resolvedPath.endsWith(extension)));
304
+ }
289
305
  /**
290
306
  * Returns whether the file is a route source file.
291
307
  */
@@ -0,0 +1,149 @@
1
+ import type { EcoPagesAppConfig, IClientBridge } from '../../config/internal-types.js';
2
+ /** One watcher batch, by kind. Paths are absolute. */
3
+ export interface StylesheetChanges {
4
+ created: readonly string[];
5
+ changed: readonly string[];
6
+ deleted: readonly string[];
7
+ }
8
+ /**
9
+ * Keeps the app's stylesheets processed while `ecopages dev` runs.
10
+ *
11
+ * @remarks
12
+ * Core owns this lifecycle for whichever stylesheet Processor the app registers; the Processor only transforms. The
13
+ * service:
14
+ * - prewarms every stylesheet the Processor owns in `srcDir`, or every plain `.css` one when the app has none, so the first edit has an output to compare with;
15
+ * - keeps each stylesheet's last good output, and the reverse map from each file a transform read to the stylesheets
16
+ * that read it, taken from the transform's own `dependencies`;
17
+ * - runs watcher batches one at a time, in order;
18
+ * - writes each output at its source-relative href (only for a stylesheet in `srcDir`) and sends `css-update` only
19
+ * when the bytes changed;
20
+ * - tells apart an edit to a CSS Module that keeps its class map, which only the delivered CSS follows, from one that
21
+ * changes the map, which the modules that import it must re-import (see {@link keepsClassMap}).
22
+ *
23
+ * Only the Project Watcher and the dev transform server create it, so it never runs in production, which writes no
24
+ * stylesheet outside the build.
25
+ *
26
+ * A stylesheet that fails keeps its last good output and sends `bridge.error`, except a partial processed on its own,
27
+ * which may only compile inside the stylesheets that import it and so fails silently. The first success after a failure
28
+ * always sends `css-update`, even with the same bytes, since the browser clears the error overlay only on a message
29
+ * that is not an error. A stylesheet in the public directory is copied as written, so the service leaves it alone.
30
+ */
31
+ export declare class DevelopmentStylesheetService {
32
+ private readonly appConfig;
33
+ private readonly outputs;
34
+ /** The error message of each stylesheet whose latest transform failed. */
35
+ private readonly failed;
36
+ /** Partials whose transform on their own failed, retried when a stylesheet is created. */
37
+ private readonly failedPartials;
38
+ /** The CSS Modules the latest batch rebuilt, by whether their class map is the one the browser holds. */
39
+ private readonly classMapKept;
40
+ private readonly dependencies;
41
+ private readonly dependents;
42
+ private queue;
43
+ constructor(appConfig: EcoPagesAppConfig);
44
+ /**
45
+ * The registered Processor that transforms stylesheets, if any, with the app's stylesheet kinds.
46
+ *
47
+ * @remarks
48
+ * Looked up at the start of each task rather than once, since the service can exist before every Processor is
49
+ * registered on the config. A Processor without `transformStylesheet` takes no part in stylesheets, so it is never
50
+ * the one, whatever its capabilities. An app with none still has plain CSS, whose `@import` partials core inlines,
51
+ * so the service keeps those stylesheets built too.
52
+ */
53
+ private resolveScope;
54
+ /**
55
+ * Processes every stylesheet the Processor owns in `srcDir`, logging and skipping one that fails.
56
+ *
57
+ * @remarks
58
+ * A partial is processed alone too, since a Page may also link it. One that fails alone but that another
59
+ * stylesheet imports is not reported: it may only compile inside that stylesheet, which reports its own errors.
60
+ */
61
+ prewarm(): Promise<void>;
62
+ /**
63
+ * Rebuilds the stylesheets one watcher batch affects and returns those whose output changed, or that recovered.
64
+ *
65
+ * @remarks
66
+ * A changed file rebuilds every stylesheet whose transform read it, except one that another of those stylesheets
67
+ * reads in turn: a transform reports nested imports too, so that outer stylesheet is rebuilt already. Two
68
+ * stylesheets that import each other are both rebuilt. A changed stylesheet is rebuilt itself too; a partial, one
69
+ * another stylesheet reads, is rebuilt on its own for a Page that links it, and a failure there is silent. A created
70
+ * stylesheet also retries every stylesheet that failed, partials on their own included, since one may have failed
71
+ * on the missing import the new file satisfies, and a failed transform reports no dependencies. The changed files
72
+ * that are not stylesheets go to the Processor's `invalidateStylesheets` hook, which names the stylesheets they make
73
+ * stale. The processed stylesheet cache is emptied first, and again after the hook, so every path of this edit
74
+ * transforms with the current inputs.
75
+ */
76
+ applyChanges(changes: StylesheetChanges, bridge: IClientBridge): Promise<string[]>;
77
+ /** The stylesheets a batch's stylesheet changes affect, before the invalidation hook adds its own. */
78
+ private collectAffected;
79
+ /**
80
+ * A digest of the last good output of `file`, or `undefined` when the service has none.
81
+ *
82
+ * @remarks
83
+ * The dev transform server versions a stylesheet import with it, so the URL changes when an `@import` partial or
84
+ * the Processor's content changes the CSS, not only when the stylesheet's own bytes do.
85
+ */
86
+ version(file: string): string | undefined;
87
+ /**
88
+ * The error messages of the stylesheets whose latest transform failed and that no save has fixed yet.
89
+ *
90
+ * @remarks
91
+ * The HMR manager sends them after the updates of a batch, which the client would otherwise clear the overlay
92
+ * with, and to a browser that connects while they stand.
93
+ */
94
+ failureMessages(): string[];
95
+ /**
96
+ * The module a binding import of `file` receives from its last good output, with the files that output read.
97
+ *
98
+ * @remarks
99
+ * A stylesheet that never compiled has no output: its module is empty, an empty string or an empty class map,
100
+ * so the importer still loads and the failure shows in the overlay.
101
+ */
102
+ lastGoodModule(file: string): {
103
+ code: string;
104
+ dependencies: string[];
105
+ };
106
+ /**
107
+ * Whether the latest batch rebuilt the CSS Module `file` and left its class map as it was.
108
+ *
109
+ * @remarks
110
+ * The browser then needs only the new CSS, which `css-update` carries; the modules that import the class map keep
111
+ * working, so the watcher does not hot-update them. A CSS Module this batch did not rebuild, or deleted, or one
112
+ * whose class map changed, answers `false`, as does any other stylesheet.
113
+ */
114
+ keepsClassMap(file: string): boolean;
115
+ /**
116
+ * The stylesheets the Processor's invalidation hook names for the files of a batch that are not stylesheets.
117
+ *
118
+ * @remarks
119
+ * A hook that throws is logged and shown, and invalidates nothing, so the rest of the batch still updates.
120
+ */
121
+ private invalidatedByContent;
122
+ /** The stylesheets the service processed, or failed to, that no other stylesheet read. */
123
+ private entries;
124
+ private owns;
125
+ /** Processes `file`, reports a failure, and returns whether its output changed or recovered. */
126
+ private rebuild;
127
+ /**
128
+ * Processes a stylesheet another stylesheet imports on its own, for a Page that links it, and returns whether its
129
+ * output changed.
130
+ *
131
+ * @remarks
132
+ * A failure is not reported: the partial may only compile inside the stylesheets that import it, which report
133
+ * their own errors, so its last good output, if any, stays.
134
+ */
135
+ private rebuildPartial;
136
+ /**
137
+ * Transforms `file` and records its output and dependencies.
138
+ *
139
+ * @returns Whether the output changed, which writes it and, with a `bridge`, sends `css-update`; or the error
140
+ * message when the transform failed.
141
+ */
142
+ private transform;
143
+ private recordDependencies;
144
+ /** Drops a deleted stylesheet's output, its CSS Module declaration and the files it read; the stylesheets that read it stay mapped to it. */
145
+ private forget;
146
+ private enqueue;
147
+ }
148
+ /** Returns the one lazily created development stylesheet service of a finalized app. */
149
+ export declare function getDevelopmentStylesheetService(appConfig: EcoPagesAppConfig): DevelopmentStylesheetService;
@@ -0,0 +1,350 @@
1
+ import { fileSystem } from '@ecopages/file-system';
2
+ import { path } from '@ecopages/file-system/path';
3
+ import { applyStylesheetProcessors, } from '../../assets/asset-processing-service/processors/stylesheet/stylesheet-processor-pipeline.js';
4
+ import { removeCssModuleDeclaration, warnMissingCssModuleRootDirs, writeCssModuleDeclaration, } from '../../assets/asset-processing-service/processors/stylesheet/css-module-types.js';
5
+ import { toClassMapModule, toStylesheetModule, } from '../../assets/asset-processing-service/processors/stylesheet/stylesheet-module.js';
6
+ import { emptyStylesheetModule } from '../../assets/asset-processing-service/processors/stylesheet/stylesheet-failure.js';
7
+ import { writeSourceRelativeStylesheet } from '../../assets/asset-processing-service/processors/stylesheet/source-relative-stylesheet.js';
8
+ import { appLogger } from '../../global/app-logger.js';
9
+ import { findStylesheetProcessor, getStylesheetKinds, PLAIN_CSS_KINDS, } from '../../plugins/stylesheet-kinds.js';
10
+ import { requireAppRuntime } from '../../utils/app-runtime.js';
11
+ import { contentHash } from '../../utils/content-hash.js';
12
+ import { isPathInside } from '../../utils/path-containment.js';
13
+ /**
14
+ * Keeps the app's stylesheets processed while `ecopages dev` runs.
15
+ *
16
+ * @remarks
17
+ * Core owns this lifecycle for whichever stylesheet Processor the app registers; the Processor only transforms. The
18
+ * service:
19
+ * - prewarms every stylesheet the Processor owns in `srcDir`, or every plain `.css` one when the app has none, so the first edit has an output to compare with;
20
+ * - keeps each stylesheet's last good output, and the reverse map from each file a transform read to the stylesheets
21
+ * that read it, taken from the transform's own `dependencies`;
22
+ * - runs watcher batches one at a time, in order;
23
+ * - writes each output at its source-relative href (only for a stylesheet in `srcDir`) and sends `css-update` only
24
+ * when the bytes changed;
25
+ * - tells apart an edit to a CSS Module that keeps its class map, which only the delivered CSS follows, from one that
26
+ * changes the map, which the modules that import it must re-import (see {@link keepsClassMap}).
27
+ *
28
+ * Only the Project Watcher and the dev transform server create it, so it never runs in production, which writes no
29
+ * stylesheet outside the build.
30
+ *
31
+ * A stylesheet that fails keeps its last good output and sends `bridge.error`, except a partial processed on its own,
32
+ * which may only compile inside the stylesheets that import it and so fails silently. The first success after a failure
33
+ * always sends `css-update`, even with the same bytes, since the browser clears the error overlay only on a message
34
+ * that is not an error. A stylesheet in the public directory is copied as written, so the service leaves it alone.
35
+ */
36
+ export class DevelopmentStylesheetService {
37
+ appConfig;
38
+ outputs = new Map();
39
+ /** The error message of each stylesheet whose latest transform failed. */
40
+ failed = new Map();
41
+ /** Partials whose transform on their own failed, retried when a stylesheet is created. */
42
+ failedPartials = new Set();
43
+ /** The CSS Modules the latest batch rebuilt, by whether their class map is the one the browser holds. */
44
+ classMapKept = new Map();
45
+ dependencies = new Map();
46
+ dependents = new Map();
47
+ queue = Promise.resolve();
48
+ constructor(appConfig) {
49
+ this.appConfig = appConfig;
50
+ }
51
+ /**
52
+ * The registered Processor that transforms stylesheets, if any, with the app's stylesheet kinds.
53
+ *
54
+ * @remarks
55
+ * Looked up at the start of each task rather than once, since the service can exist before every Processor is
56
+ * registered on the config. A Processor without `transformStylesheet` takes no part in stylesheets, so it is never
57
+ * the one, whatever its capabilities. An app with none still has plain CSS, whose `@import` partials core inlines,
58
+ * so the service keeps those stylesheets built too.
59
+ */
60
+ resolveScope() {
61
+ const processor = findStylesheetProcessor([...this.appConfig.processors.values()].filter((candidate) => typeof candidate.transformStylesheet === 'function'));
62
+ return { processor, kinds: processor ? getStylesheetKinds(this.appConfig) : PLAIN_CSS_KINDS };
63
+ }
64
+ /**
65
+ * Processes every stylesheet the Processor owns in `srcDir`, logging and skipping one that fails.
66
+ *
67
+ * @remarks
68
+ * A partial is processed alone too, since a Page may also link it. One that fails alone but that another
69
+ * stylesheet imports is not reported: it may only compile inside that stylesheet, which reports its own errors.
70
+ */
71
+ prewarm() {
72
+ return this.enqueue(async () => {
73
+ const scope = this.resolveScope();
74
+ const srcDir = this.appConfig.absolutePaths.srcDir;
75
+ const patterns = scope.kinds.extensions.map((extension) => `**/*${extension}`);
76
+ const failures = new Map();
77
+ for (const relativePath of await fileSystem.glob(patterns, { cwd: srcDir })) {
78
+ const file = path.join(srcDir, relativePath);
79
+ if (!this.owns(scope, file))
80
+ continue;
81
+ const result = await this.transform(file);
82
+ if (typeof result === 'string')
83
+ failures.set(file, result);
84
+ }
85
+ for (const [file, message] of failures) {
86
+ if (this.dependents.has(file)) {
87
+ this.failedPartials.add(file);
88
+ continue;
89
+ }
90
+ this.failed.set(file, message);
91
+ appLogger.error(`Failed to process stylesheet ${file}: ${message}`);
92
+ }
93
+ warnMissingCssModuleRootDirs(this.appConfig);
94
+ });
95
+ }
96
+ /**
97
+ * Rebuilds the stylesheets one watcher batch affects and returns those whose output changed, or that recovered.
98
+ *
99
+ * @remarks
100
+ * A changed file rebuilds every stylesheet whose transform read it, except one that another of those stylesheets
101
+ * reads in turn: a transform reports nested imports too, so that outer stylesheet is rebuilt already. Two
102
+ * stylesheets that import each other are both rebuilt. A changed stylesheet is rebuilt itself too; a partial, one
103
+ * another stylesheet reads, is rebuilt on its own for a Page that links it, and a failure there is silent. A created
104
+ * stylesheet also retries every stylesheet that failed, partials on their own included, since one may have failed
105
+ * on the missing import the new file satisfies, and a failed transform reports no dependencies. The changed files
106
+ * that are not stylesheets go to the Processor's `invalidateStylesheets` hook, which names the stylesheets they make
107
+ * stale. The processed stylesheet cache is emptied first, and again after the hook, so every path of this edit
108
+ * transforms with the current inputs.
109
+ */
110
+ applyChanges(changes, bridge) {
111
+ return this.enqueue(async () => {
112
+ const scope = this.resolveScope();
113
+ const resolve = (files) => files.map((file) => path.resolve(file));
114
+ const created = resolve(changes.created);
115
+ const changed = resolve(changes.changed);
116
+ const deleted = resolve(changes.deleted);
117
+ for (const file of deleted)
118
+ this.forget(file);
119
+ this.classMapKept.clear();
120
+ const cache = requireAppRuntime(this.appConfig).processedStylesheets;
121
+ cache.evict();
122
+ const affected = this.collectAffected(scope, created, changed, deleted);
123
+ for (const file of await this.invalidatedByContent(scope, [...created, ...changed, ...deleted], bridge)) {
124
+ affected.add(file);
125
+ }
126
+ cache.evict();
127
+ const retried = created.some((file) => this.owns(scope, file)) ? [...this.failedPartials] : [];
128
+ const partials = [...new Set([...created, ...changed, ...retried])].filter((file) => this.owns(scope, file) && this.dependents.has(file) && !affected.has(file));
129
+ const restyled = [];
130
+ for (const file of affected) {
131
+ if (await this.rebuild(file, bridge))
132
+ restyled.push(file);
133
+ }
134
+ for (const file of partials) {
135
+ if (await this.rebuildPartial(file, bridge))
136
+ restyled.push(file);
137
+ }
138
+ return restyled;
139
+ });
140
+ }
141
+ /** The stylesheets a batch's stylesheet changes affect, before the invalidation hook adds its own. */
142
+ collectAffected(scope, created, changed, deleted) {
143
+ const affected = new Set();
144
+ for (const file of [...created, ...changed, ...deleted]) {
145
+ const readers = this.dependents.get(file) ?? new Set();
146
+ for (const reader of readers) {
147
+ const coveredByAnotherReader = [...(this.dependents.get(reader) ?? [])].some((outer) => readers.has(outer));
148
+ if (!coveredByAnotherReader)
149
+ affected.add(reader);
150
+ }
151
+ }
152
+ for (const file of [...created, ...changed]) {
153
+ if (this.owns(scope, file) && !this.dependents.has(file))
154
+ affected.add(file);
155
+ }
156
+ if (created.some((file) => this.owns(scope, file))) {
157
+ for (const file of this.failed.keys()) {
158
+ if (!this.dependents.has(file))
159
+ affected.add(file);
160
+ }
161
+ }
162
+ return affected;
163
+ }
164
+ /**
165
+ * A digest of the last good output of `file`, or `undefined` when the service has none.
166
+ *
167
+ * @remarks
168
+ * The dev transform server versions a stylesheet import with it, so the URL changes when an `@import` partial or
169
+ * the Processor's content changes the CSS, not only when the stylesheet's own bytes do.
170
+ */
171
+ version(file) {
172
+ return this.outputs.get(path.resolve(file))?.digest;
173
+ }
174
+ /**
175
+ * The error messages of the stylesheets whose latest transform failed and that no save has fixed yet.
176
+ *
177
+ * @remarks
178
+ * The HMR manager sends them after the updates of a batch, which the client would otherwise clear the overlay
179
+ * with, and to a browser that connects while they stand.
180
+ */
181
+ failureMessages() {
182
+ return [...this.failed.values()];
183
+ }
184
+ /**
185
+ * The module a binding import of `file` receives from its last good output, with the files that output read.
186
+ *
187
+ * @remarks
188
+ * A stylesheet that never compiled has no output: its module is empty, an empty string or an empty class map,
189
+ * so the importer still loads and the failure shows in the overlay.
190
+ */
191
+ lastGoodModule(file) {
192
+ const resolved = path.resolve(file);
193
+ const output = this.outputs.get(resolved);
194
+ const code = output
195
+ ? output.classMap === undefined
196
+ ? toStylesheetModule(output.css)
197
+ : toClassMapModule(JSON.parse(output.classMap))
198
+ : emptyStylesheetModule(getStylesheetKinds(this.appConfig).isCssModule(resolved));
199
+ return { code, dependencies: [...(this.dependencies.get(resolved) ?? [])] };
200
+ }
201
+ /**
202
+ * Whether the latest batch rebuilt the CSS Module `file` and left its class map as it was.
203
+ *
204
+ * @remarks
205
+ * The browser then needs only the new CSS, which `css-update` carries; the modules that import the class map keep
206
+ * working, so the watcher does not hot-update them. A CSS Module this batch did not rebuild, or deleted, or one
207
+ * whose class map changed, answers `false`, as does any other stylesheet.
208
+ */
209
+ keepsClassMap(file) {
210
+ return this.classMapKept.get(path.resolve(file)) ?? false;
211
+ }
212
+ /**
213
+ * The stylesheets the Processor's invalidation hook names for the files of a batch that are not stylesheets.
214
+ *
215
+ * @remarks
216
+ * A hook that throws is logged and shown, and invalidates nothing, so the rest of the batch still updates.
217
+ */
218
+ async invalidatedByContent({ processor, kinds }, files, bridge) {
219
+ const content = files.filter((file) => !kinds.isStylesheet(file));
220
+ if (content.length === 0 || !processor?.invalidateStylesheets)
221
+ return [];
222
+ let invalidated;
223
+ try {
224
+ invalidated = await processor.invalidateStylesheets(content);
225
+ }
226
+ catch (error) {
227
+ const message = error instanceof Error ? error.message : String(error);
228
+ appLogger.error(`Processor ${processor.name} failed to invalidate stylesheets: ${message}`);
229
+ bridge.error(message);
230
+ return [];
231
+ }
232
+ if (invalidated === 'all')
233
+ return this.entries();
234
+ return invalidated.map((file) => path.resolve(file)).filter((file) => this.owns({ processor, kinds }, file));
235
+ }
236
+ /** The stylesheets the service processed, or failed to, that no other stylesheet read. */
237
+ entries() {
238
+ return [...new Set([...this.outputs.keys(), ...this.failed.keys()])].filter((file) => !this.dependents.has(file));
239
+ }
240
+ owns({ processor, kinds }, file) {
241
+ return ((processor?.canProcessAsset('stylesheet', file) ?? true) &&
242
+ kinds.isStylesheet(file) &&
243
+ (kinds.scopesCssModules || !kinds.isCssModule(file)) &&
244
+ !isPathInside(file, this.appConfig.absolutePaths.publicDir));
245
+ }
246
+ /** Processes `file`, reports a failure, and returns whether its output changed or recovered. */
247
+ async rebuild(file, bridge) {
248
+ const recovered = this.failed.has(file);
249
+ const result = await this.transform(file, bridge);
250
+ if (typeof result === 'string') {
251
+ this.failed.set(file, result);
252
+ appLogger.error(`Failed to process stylesheet ${file}: ${result}`);
253
+ bridge.error(result);
254
+ return false;
255
+ }
256
+ if (recovered) {
257
+ this.failed.delete(file);
258
+ if (!result)
259
+ bridge.cssUpdate(file);
260
+ return true;
261
+ }
262
+ return result === true;
263
+ }
264
+ /**
265
+ * Processes a stylesheet another stylesheet imports on its own, for a Page that links it, and returns whether its
266
+ * output changed.
267
+ *
268
+ * @remarks
269
+ * A failure is not reported: the partial may only compile inside the stylesheets that import it, which report
270
+ * their own errors, so its last good output, if any, stays.
271
+ */
272
+ async rebuildPartial(file, bridge) {
273
+ const result = await this.transform(file, bridge);
274
+ if (typeof result === 'string') {
275
+ this.failedPartials.add(file);
276
+ appLogger.debug(`Stylesheet ${file} does not compile on its own: ${result}`);
277
+ return false;
278
+ }
279
+ this.failedPartials.delete(file);
280
+ this.failed.delete(file);
281
+ return result;
282
+ }
283
+ /**
284
+ * Transforms `file` and records its output and dependencies.
285
+ *
286
+ * @returns Whether the output changed, which writes it and, with a `bridge`, sends `css-update`; or the error
287
+ * message when the transform failed.
288
+ */
289
+ async transform(file, bridge) {
290
+ if (!fileSystem.exists(file))
291
+ return false;
292
+ let processed;
293
+ try {
294
+ processed = await applyStylesheetProcessors(this.appConfig, await fileSystem.readFile(file), file);
295
+ }
296
+ catch (error) {
297
+ return error instanceof Error ? error.message : String(error);
298
+ }
299
+ const { css, dependencies, exports } = processed;
300
+ const classMap = exports ? JSON.stringify(exports) : undefined;
301
+ this.recordDependencies(file, dependencies);
302
+ if (exports)
303
+ writeCssModuleDeclaration(this.appConfig, file, exports);
304
+ const previous = this.outputs.get(file);
305
+ if (classMap !== undefined)
306
+ this.classMapKept.set(file, previous !== undefined && previous.classMap === classMap);
307
+ if (previous?.css === css && previous.classMap === classMap)
308
+ return false;
309
+ const { srcDir, distDir } = this.appConfig.absolutePaths;
310
+ writeSourceRelativeStylesheet({ srcDir, distDir }, file, css);
311
+ this.outputs.set(file, { css, classMap, digest: contentHash(classMap ?? css) });
312
+ bridge?.cssUpdate(file);
313
+ return true;
314
+ }
315
+ recordDependencies(file, dependencies) {
316
+ for (const dependency of this.dependencies.get(file) ?? []) {
317
+ const dependents = this.dependents.get(dependency);
318
+ dependents?.delete(file);
319
+ if (dependents?.size === 0)
320
+ this.dependents.delete(dependency);
321
+ }
322
+ this.dependencies.set(file, new Set(dependencies));
323
+ for (const dependency of dependencies) {
324
+ const dependents = this.dependents.get(dependency) ?? new Set();
325
+ dependents.add(file);
326
+ this.dependents.set(dependency, dependents);
327
+ }
328
+ }
329
+ /** Drops a deleted stylesheet's output, its CSS Module declaration and the files it read; the stylesheets that read it stay mapped to it. */
330
+ forget(file) {
331
+ if (getStylesheetKinds(this.appConfig).isCssModule(file))
332
+ removeCssModuleDeclaration(this.appConfig, file);
333
+ this.outputs.delete(file);
334
+ this.failed.delete(file);
335
+ this.failedPartials.delete(file);
336
+ this.recordDependencies(file, []);
337
+ this.dependencies.delete(file);
338
+ }
339
+ enqueue(task) {
340
+ const run = this.queue.then(task, task);
341
+ this.queue = run.catch(() => undefined);
342
+ return run;
343
+ }
344
+ }
345
+ /** Returns the one lazily created development stylesheet service of a finalized app. */
346
+ export function getDevelopmentStylesheetService(appConfig) {
347
+ const runtime = requireAppRuntime(appConfig);
348
+ runtime.developmentStylesheets ??= new DevelopmentStylesheetService(appConfig);
349
+ return runtime.developmentStylesheets;
350
+ }
@@ -4,7 +4,6 @@ import type { DevTransformBundleContributor, DevTransformBundleResult } from './
4
4
  export type DevTransformBundlerOptions = {
5
5
  appConfig: EcoPagesAppConfig;
6
6
  contributors?: readonly DevTransformBundleContributor[];
7
- getRuntimeSpecifierMap: () => ReadonlyMap<string, string>;
8
7
  vendorRegistry: DevTransformVendorRegistry;
9
8
  extraModuleRoots?: readonly string[];
10
9
  };
@@ -14,7 +13,6 @@ export type DevTransformBundlerOptions = {
14
13
  export declare class DevTransformBundler {
15
14
  private readonly appConfig;
16
15
  private readonly browserBundleService;
17
- private readonly getRuntimeSpecifierMap;
18
16
  private readonly vendorRegistry;
19
17
  private readonly contributors;
20
18
  private readonly extraModuleRoots;
@@ -22,5 +20,16 @@ export declare class DevTransformBundler {
22
20
  addContributor(contributor: DevTransformBundleContributor): void;
23
21
  private selectContributor;
24
22
  private resolveTempOutdir;
25
- transpileModule(sourcePath: string): Promise<DevTransformBundleResult>;
23
+ /**
24
+ * Rewrites the imports of browser ESM `code` whose source is `sourcePath`; see {@link rewriteModuleImports}.
25
+ *
26
+ * @remarks
27
+ * A stylesheet import is versioned by the output the development stylesheet service last produced for it, so an
28
+ * edit to one of its `@import` partials gives the importer a new URL.
29
+ */
30
+ rewriteImports(code: string, sourcePath: string): Promise<{
31
+ code: string;
32
+ dependencies: string[];
33
+ }>;
34
+ transpileModule(sourcePath: string, variant?: string): Promise<DevTransformBundleResult>;
26
35
  }