@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,5 +1,4 @@
1
1
  import type { EcoBuildPlugin } from '../build/contracts/build-types.js';
2
- import { type BrowserRuntimeManifest } from '../build/browser/browser-runtime-manifest.js';
3
2
  import type { AppRuntime } from '../config/assembly/app-runtime.js';
4
3
  import type { EcoPagesAppConfig } from '../config/internal-types.js';
5
4
  import type { EcoPageFile, EcoPagesElement } from '../types/contracts.js';
@@ -8,8 +7,9 @@ import { AssetProcessingService } from '../assets/asset-processing-service/asset
8
7
  import type { AssetDefinition, ProcessedAsset } from '../assets/asset-processing-service/assets.types.js';
9
8
  import type { StaticExportContext, StaticExportRelease } from '../static-site-generator/static-export-context.js';
10
9
  import { type ServerDomInstaller } from './server-dom.js';
10
+ import type { SsrScriptPreload } from '../route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js';
11
11
  export type { ServerDomInstaller, ServerDomSurfaceKind } from './server-dom.js';
12
- export type { EcoBuildLoader, EcoBuildOnLoadArgs, EcoBuildOnLoadResult, EcoBuildImportKind, EcoBuildOnResolveArgs, EcoBuildOnResolveResult, EcoBuildPlugin, EcoBuildPluginBuilder, } from '../build/contracts/build-types.js';
12
+ export type { EcoBuildFilter, EcoBuildLoader, EcoBuildOnLoadArgs, EcoBuildOnLoadResult, EcoBuildOnResolveArgs, EcoBuildOnResolveResult, EcoBuildPlugin, EcoBuildPluginBuilder, EcoBuildResolvedId, } from '../build/contracts/build-types.js';
13
13
  export type { PageBrowserGraphContribution, PageBrowserGraphContributionContext } from '../types/contracts.js';
14
14
  export type { StaticExportContext, StaticExportRelease } from '../static-site-generator/static-export-context.js';
15
15
  export type { HtmlDocumentContribution, HtmlDocumentContributionContext, } from '../route-renderer/orchestration/integration-renderer.js';
@@ -20,8 +20,8 @@ export type { HtmlDocumentContribution, HtmlDocumentContributionContext, } from
20
20
  * renderer still owns its framework-specific render payload type internally.
21
21
  *
22
22
  * @remarks
23
- * The plugin contract currently constructs the Build-layer asset service and runtime manifest; #556
24
- * tracks moving those implementations behind the plugin contracts layer.
23
+ * The plugin contract currently constructs the Build-layer asset service; #556 tracks moving that
24
+ * implementation behind the plugin contracts layer.
25
25
  */
26
26
  export type AnyIntegrationPlugin = IntegrationPlugin<unknown>;
27
27
  export declare const INTEGRATION_PLUGIN_ERRORS: {
@@ -60,8 +60,6 @@ export interface IntegrationPluginConfig {
60
60
  * integration.
61
61
  */
62
62
  jsxImportSource?: string;
63
- /** Browser runtime rewrites declared as data for the app build manifest. */
64
- browserRuntimeManifest?: BrowserRuntimeManifest;
65
63
  }
66
64
  type RendererClass<C> = new (options: IntegrationRendererOptions & {
67
65
  resolvedIntegrationDependencies: ProcessedAsset[];
@@ -84,8 +82,7 @@ export type IntegrationRendererBase = IntegrationRendererOptions & {
84
82
  *
85
83
  * Core owns lifecycle ordering. Integrations declare contributions through the
86
84
  * hooks on this class, while config finalization and app startup decide when
87
- * those hooks run. `plugins` declares environment-selected build hooks and
88
- * `browserRuntimeManifest` declares client import rewrites. For page-browser and
85
+ * those hooks run. `plugins` declares environment-selected build hooks. For page-browser and
89
86
  * document shaping, integrations should prefer the contribution contracts
90
87
  * re-exported from this module:
91
88
  * `PageBrowserGraphContribution` / `PageBrowserGraphContributionContext` and
@@ -96,7 +93,6 @@ export declare abstract class IntegrationPlugin<C = EcoPagesElement> {
96
93
  readonly extensions: string[];
97
94
  abstract renderer: RendererClass<C>;
98
95
  readonly jsxImportSource?: string;
99
- readonly browserRuntimeManifest: BrowserRuntimeManifest;
100
96
  /**
101
97
  * Whether this Integration's Pages can receive Params from `[param]` and `[...param]`
102
98
  * filenames.
@@ -118,8 +114,17 @@ export declare abstract class IntegrationPlugin<C = EcoPagesElement> {
118
114
  * Omit this when the Integration does not install DOM globals.
119
115
  */
120
116
  readonly serverDom?: ServerDomInstaller;
117
+ /**
118
+ * Which `ssr: true` Component scripts this Integration's custom-element preloader evaluates.
119
+ *
120
+ * @remarks
121
+ * Core assigns each `ssr: true` script to exactly one preloader: the preloading Integration that owns the
122
+ * declaring Component, else the first `'own-and-foreign'` Integration in config order. Omit this when the
123
+ * Integration has no custom-element preloader: a preloader whose Integration omits it is assigned no script.
124
+ */
125
+ readonly ssrScriptPreload?: SsrScriptPreload;
121
126
  protected integrationDependencies: AssetDefinition[];
122
- protected resolvedIntegrationDependencies: ProcessedAsset[];
127
+ protected readonly resolvedIntegrationDependencies: ProcessedAsset[];
123
128
  protected appConfig?: EcoPagesAppConfig;
124
129
  protected runtime?: AppRuntime;
125
130
  protected assetProcessingService?: AssetProcessingService;
@@ -175,9 +180,30 @@ export declare abstract class IntegrationPlugin<C = EcoPagesElement> {
175
180
  filePath: string;
176
181
  }): EcoPageFile;
177
182
  /**
178
- * Returns processed global assets resolved during `setup()`.
183
+ * Returns this Integration's processed global assets.
184
+ *
185
+ * @remarks
186
+ * The list is one array for the plugin's lifetime. {@link refreshResolvedIntegrationDependencies} updates it in
187
+ * place, so a renderer that holds it, across a teardown and a later setup too, sees each new resolution. Each
188
+ * `setup()` empties it; it stays empty until the Integration's activation, or the browser build of a
189
+ * `'browser-build'` runtime, resolves it. A subclass updates it in place or calls
190
+ * {@link refreshResolvedIntegrationDependencies}; it never replaces it.
179
191
  */
180
192
  getResolvedIntegrationDependencies(): ProcessedAsset[];
193
+ /** Returns the global assets this Integration adds to every Page it takes part in, before processing. */
194
+ getIntegrationDependencies(): readonly AssetDefinition[];
195
+ /**
196
+ * Processes the global assets and replaces the resolved list in place.
197
+ *
198
+ * @remarks
199
+ * `setup()` does not call it. Core's activation calls it right after a successful `setup()` when the runtime's
200
+ * `globalScriptResolution` is `'activation'`: in dev and in `ecopages start` (whose ledger is restored before any
201
+ * activation). A production build and the Lit static-render worker run a `'browser-build'` runtime: the build
202
+ * calls it after the app-wide browser build (or when it plans no route), the worker after restoring the asset
203
+ * ledger. A global script then resolves to that build's output instead of being bundled on its own. Does nothing
204
+ * before `setup()`.
205
+ */
206
+ refreshResolvedIntegrationDependencies(): Promise<void>;
181
207
  /**
182
208
  * Creates the common renderer options from runtime setup state.
183
209
  *
@@ -198,6 +224,11 @@ export declare abstract class IntegrationPlugin<C = EcoPagesElement> {
198
224
  createRenderer(base: IntegrationRendererBase): IntegrationRenderer<C>;
199
225
  /**
200
226
  * Returns the renderer shared by this Integration's application runtime.
227
+ *
228
+ * @remarks
229
+ * Creating the renderer checks that {@link ssrScriptPreload} and the renderer's custom-element preloader agree.
230
+ * A renderer that builds a preloader without the declaration throws as it builds it. A declaration whose renderer
231
+ * builds none throws here, since core would assign the renderer scripts it never evaluates.
201
232
  */
202
233
  getRenderer(): IntegrationRenderer<C>;
203
234
  /** Shapes one dependency batch before core asset processing runs. */
@@ -214,6 +245,11 @@ export declare abstract class IntegrationPlugin<C = EcoPagesElement> {
214
245
  staticExport?(context: StaticExportContext): Promise<StaticExportRelease | void>;
215
246
  /**
216
247
  * Performs runtime integration setup, after config finalization has sealed the build manifest.
248
+ *
249
+ * @remarks
250
+ * Global scripts are not resolved yet: {@link getResolvedIntegrationDependencies} reads them only after
251
+ * {@link refreshResolvedIntegrationDependencies} runs. It empties the resolved list in place, so a setup after a
252
+ * teardown does not show the previous lifecycle's assets before the next resolution.
217
253
  */
218
254
  setup(context: IntegrationRuntimeContext): Promise<void>;
219
255
  /** Registers Integration-owned development behavior against the app runtime. */
@@ -1,4 +1,3 @@
1
- import { createBrowserRuntimeManifest, } from '../build/browser/browser-runtime-manifest.js';
2
1
  import { AssetProcessingService } from '../assets/asset-processing-service/asset-processing.service.js';
3
2
  import { deepMerge } from '../utils/deep-merge.js';
4
3
  import { installConfiguredServerDom } from './server-dom.js';
@@ -19,8 +18,7 @@ export function mergeIntegrationOptions(defaults, overrides) {
19
18
  *
20
19
  * Core owns lifecycle ordering. Integrations declare contributions through the
21
20
  * hooks on this class, while config finalization and app startup decide when
22
- * those hooks run. `plugins` declares environment-selected build hooks and
23
- * `browserRuntimeManifest` declares client import rewrites. For page-browser and
21
+ * those hooks run. `plugins` declares environment-selected build hooks. For page-browser and
24
22
  * document shaping, integrations should prefer the contribution contracts
25
23
  * re-exported from this module:
26
24
  * `PageBrowserGraphContribution` / `PageBrowserGraphContributionContext` and
@@ -30,7 +28,6 @@ export class IntegrationPlugin {
30
28
  name;
31
29
  extensions;
32
30
  jsxImportSource;
33
- browserRuntimeManifest;
34
31
  /**
35
32
  * Whether this Integration's Pages can receive Params from `[param]` and `[...param]`
36
33
  * filenames.
@@ -52,6 +49,15 @@ export class IntegrationPlugin {
52
49
  * Omit this when the Integration does not install DOM globals.
53
50
  */
54
51
  serverDom;
52
+ /**
53
+ * Which `ssr: true` Component scripts this Integration's custom-element preloader evaluates.
54
+ *
55
+ * @remarks
56
+ * Core assigns each `ssr: true` script to exactly one preloader: the preloading Integration that owns the
57
+ * declaring Component, else the first `'own-and-foreign'` Integration in config order. Omit this when the
58
+ * Integration has no custom-element preloader: a preloader whose Integration omits it is assigned no script.
59
+ */
60
+ ssrScriptPreload;
55
61
  integrationDependencies;
56
62
  resolvedIntegrationDependencies = [];
57
63
  appConfig;
@@ -84,14 +90,41 @@ export class IntegrationPlugin {
84
90
  this.extensions = config.extensions;
85
91
  this.integrationDependencies = config.integrationDependencies || [];
86
92
  this.jsxImportSource = config.jsxImportSource;
87
- this.browserRuntimeManifest = config.browserRuntimeManifest ?? createBrowserRuntimeManifest();
88
93
  }
89
94
  /**
90
- * Returns processed global assets resolved during `setup()`.
95
+ * Returns this Integration's processed global assets.
96
+ *
97
+ * @remarks
98
+ * The list is one array for the plugin's lifetime. {@link refreshResolvedIntegrationDependencies} updates it in
99
+ * place, so a renderer that holds it, across a teardown and a later setup too, sees each new resolution. Each
100
+ * `setup()` empties it; it stays empty until the Integration's activation, or the browser build of a
101
+ * `'browser-build'` runtime, resolves it. A subclass updates it in place or calls
102
+ * {@link refreshResolvedIntegrationDependencies}; it never replaces it.
91
103
  */
92
104
  getResolvedIntegrationDependencies() {
93
105
  return this.resolvedIntegrationDependencies;
94
106
  }
107
+ /** Returns the global assets this Integration adds to every Page it takes part in, before processing. */
108
+ getIntegrationDependencies() {
109
+ return this.integrationDependencies;
110
+ }
111
+ /**
112
+ * Processes the global assets and replaces the resolved list in place.
113
+ *
114
+ * @remarks
115
+ * `setup()` does not call it. Core's activation calls it right after a successful `setup()` when the runtime's
116
+ * `globalScriptResolution` is `'activation'`: in dev and in `ecopages start` (whose ledger is restored before any
117
+ * activation). A production build and the Lit static-render worker run a `'browser-build'` runtime: the build
118
+ * calls it after the app-wide browser build (or when it plans no route), the worker after restoring the asset
119
+ * ledger. A global script then resolves to that build's output instead of being bundled on its own. Does nothing
120
+ * before `setup()`.
121
+ */
122
+ async refreshResolvedIntegrationDependencies() {
123
+ if (!this.assetProcessingService)
124
+ return;
125
+ const resolved = await this.assetProcessingService.processDependencies(this.integrationDependencies, this);
126
+ this.resolvedIntegrationDependencies.splice(0, this.resolvedIntegrationDependencies.length, ...resolved);
127
+ }
95
128
  /**
96
129
  * Creates the common renderer options from runtime setup state.
97
130
  *
@@ -126,16 +159,33 @@ export class IntegrationPlugin {
126
159
  }
127
160
  /**
128
161
  * Returns the renderer shared by this Integration's application runtime.
162
+ *
163
+ * @remarks
164
+ * Creating the renderer checks that {@link ssrScriptPreload} and the renderer's custom-element preloader agree.
165
+ * A renderer that builds a preloader without the declaration throws as it builds it. A declaration whose renderer
166
+ * builds none throws here, since core would assign the renderer scripts it never evaluates.
129
167
  */
130
168
  getRenderer() {
131
- this.rendererInstance ??= this.createRenderer(this.createRendererBase());
169
+ if (!this.rendererInstance) {
170
+ const renderer = this.createRenderer(this.createRendererBase());
171
+ if (this.ssrScriptPreload && !renderer.buildsSsrScriptPreloader) {
172
+ throw new Error(`[ecopages] Integration "${this.name}" declares ssrScriptPreload but its renderer builds no custom-element preloader, so the scripts assigned to it would never be evaluated. Build one with createSsrScriptPreloader() or drop the declaration.`);
173
+ }
174
+ this.rendererInstance = renderer;
175
+ }
132
176
  this.rendererInstance.name ||= this.name;
133
177
  return this.rendererInstance;
134
178
  }
135
179
  /**
136
180
  * Performs runtime integration setup, after config finalization has sealed the build manifest.
181
+ *
182
+ * @remarks
183
+ * Global scripts are not resolved yet: {@link getResolvedIntegrationDependencies} reads them only after
184
+ * {@link refreshResolvedIntegrationDependencies} runs. It empties the resolved list in place, so a setup after a
185
+ * teardown does not show the previous lifecycle's assets before the next resolution.
137
186
  */
138
187
  async setup(context) {
188
+ this.resolvedIntegrationDependencies.splice(0);
139
189
  await installConfiguredServerDom(context.appConfig.integrations);
140
190
  this.appConfig = context.appConfig;
141
191
  this.runtime = context.runtime;
@@ -144,7 +194,6 @@ export class IntegrationPlugin {
144
194
  if (context.runtime.hmr) {
145
195
  this.assetProcessingService.setHmrManager(context.runtime.hmr);
146
196
  }
147
- this.resolvedIntegrationDependencies = await this.assetProcessingService.processDependencies(this.integrationDependencies, this);
148
197
  }
149
198
  /** Registers Integration-owned development behavior against the app runtime. */
150
199
  hmr(context) {
@@ -1,7 +1,7 @@
1
1
  import type { EcoBuildPlugin } from '../build/contracts/build-types.js';
2
2
  import type { EcoPagesAppConfig, IClientBridge } from '../config/internal-types.js';
3
3
  import { GENERATED_BASE_PATHS } from '../constants.js';
4
- export type { EcoBuildLoader, EcoBuildOnLoadArgs, EcoBuildOnLoadResult, EcoBuildImportKind, EcoBuildOnResolveArgs, EcoBuildOnResolveResult, EcoBuildPlugin, EcoBuildPluginBuilder, } from '../build/contracts/build-types.js';
4
+ export type { EcoBuildFilter, EcoBuildLoader, EcoBuildOnLoadArgs, EcoBuildOnLoadResult, EcoBuildOnResolveArgs, EcoBuildOnResolveResult, EcoBuildPlugin, EcoBuildPluginBuilder, EcoBuildResolvedId, } from '../build/contracts/build-types.js';
5
5
  export declare const PROCESSOR_ERRORS: {
6
6
  readonly CACHE_DIRECTORY_NOT_SET: "Cache directory not set in context";
7
7
  };
@@ -24,6 +24,17 @@ export declare function writeGeneratedTypesPackage(options: {
24
24
  packageName: string;
25
25
  writeFile: (filePath: string, content: string) => void;
26
26
  }): void;
27
+ /**
28
+ * Builds the ambient module declarations of the stylesheet extensions a Processor declares, for the Processor to write
29
+ * into its generated `@types` package from `setup()`.
30
+ *
31
+ * @remarks
32
+ * Core ships the declarations of `.css` and `.module.css` itself (`css-imports.d.ts`), so they are left out; the
33
+ * result is empty when no stylesheet capability declares another extension. For each extension `*.<ext>` declares
34
+ * the CSS string, and, when the capability sets `cssModules`, `*.module.<ext>` declares the class map. The module
35
+ * pattern comes first because TypeScript takes the first of two patterns that match a specifier alike.
36
+ */
37
+ export declare function serializeStylesheetModuleDeclarations(capabilities: readonly ProcessorAssetCapability[]): string;
27
38
  /**
28
39
  * One debounce window of file changes, passed to {@link ProcessorWatchConfig.onChanges}.
29
40
  *
@@ -75,6 +86,15 @@ export interface ProcessorAssetCapability {
75
86
  * including grouped values (e.g. `*.{ CSS, ScSs }`).
76
87
  */
77
88
  extensions?: ProcessorExtensionPattern[];
89
+ /**
90
+ * Whether a `stylesheet` capability scopes CSS Modules.
91
+ *
92
+ * @remarks
93
+ * A Processor that sets it returns `exports` from {@link Processor.transformStylesheet} for every CSS Module it is
94
+ * given: a stylesheet named `*.module.css`, or `*.module.<ext>` for a declared extension. Without it, core fails
95
+ * a build that imports a CSS Module and names the Processor to install.
96
+ */
97
+ cssModules?: boolean;
78
98
  }
79
99
  export interface ProcessorConfig<TOptions = unknown> {
80
100
  name: string;
@@ -90,6 +110,33 @@ export interface ProcessorContext {
90
110
  distDir: string;
91
111
  cache?: string;
92
112
  }
113
+ /** What {@link Processor.transformStylesheet} returns for one stylesheet. */
114
+ export interface StylesheetTransformResult {
115
+ css: string;
116
+ /**
117
+ * The class map of a CSS Module: each local class name mapped to its scoped name, followed by the names it
118
+ * composes, separated by spaces.
119
+ *
120
+ * @remarks
121
+ * Required for a CSS Module when the Processor declares `cssModules`, and ignored for any other stylesheet. The
122
+ * scoped names must derive from the path relative to the app's `rootDir`, never from the absolute path, so a build
123
+ * gives the same names in any folder. Core serves the map as the module the importer receives and `css` as the
124
+ * stylesheet the Page links, both from this one result.
125
+ */
126
+ exports?: Readonly<Record<string, string>>;
127
+ /**
128
+ * Absolute paths of the other files the transform read, such as the partials an `@import` inlined.
129
+ *
130
+ * @remarks
131
+ * Take them from the transform itself (PostCSS `dependency` messages, Lightning CSS `dependencies`), never from a
132
+ * scan of the source. Core keeps the ones that are stylesheets and rebuilds the stylesheet, and every module that
133
+ * imports it, when one of them changes; a change to any other input reaches the stylesheet through
134
+ * {@link Processor.invalidateStylesheets}.
135
+ */
136
+ dependencies?: readonly string[];
137
+ }
138
+ /** What {@link Processor.invalidateStylesheets} returns: the stylesheets to rebuild, or `'all'` for every entry. */
139
+ export type StylesheetInvalidation = 'all' | readonly string[];
93
140
  /**
94
141
  * Unconstrained processor type for heterogeneous processor collections.
95
142
  */
@@ -142,15 +189,33 @@ export declare abstract class Processor<TOptions = unknown> {
142
189
  * Transforms one stylesheet before core writes or inlines it.
143
190
  *
144
191
  * @remarks
145
- * Core calls it for every `.css`, `.scss`, `.sass` and `.less` asset, from file and content dependencies alike,
146
- * when the Processor declares a `stylesheet` capability matching the file. Processors run in registration order,
147
- * each receiving the previous result. A Processor without this method
148
- * takes no part in stylesheet processing.
192
+ * Core calls it for each stylesheet the Processor's `stylesheet` capability matches, from file and content
193
+ * dependencies alike: a `.css` file, or a file with an extension the capability declares. At most one Processor
194
+ * in an app may declare a `stylesheet` capability: config finalization fails when two do. A Processor without
195
+ * this method takes no part in stylesheet processing.
149
196
  *
150
- * @param css - Stylesheet source, or the previous Processor's output.
197
+ * @param css - Stylesheet source.
151
198
  * @param file - Absolute path of the stylesheet, or the `processingOrigin` of a content dependency.
152
199
  */
153
- transformStylesheet?(css: string, file: string): Promise<string>;
200
+ transformStylesheet?(css: string, file: string): Promise<StylesheetTransformResult>;
201
+ /**
202
+ * Names the stylesheets a change to other files makes stale, such as the stylesheets Tailwind generates from the
203
+ * class names it scans in templates.
204
+ *
205
+ * @remarks
206
+ * In development core calls it once per watcher batch that changed a file that is not a stylesheet, with those
207
+ * absolute paths, before it rebuilds. `'all'` rebuilds every stylesheet no other stylesheet imports. The Processor
208
+ * may reset state here that would hide the change, as the PostCSS Processor recreates its plugins. A stylesheet
209
+ * whose own `@import` partials changed needs no hook: core rebuilds it from the transform's `dependencies`.
210
+ *
211
+ * @param files - The changed paths that are not stylesheets.
212
+ */
213
+ invalidateStylesheets?(files: readonly string[]): StylesheetInvalidation | Promise<StylesheetInvalidation>;
214
+ /**
215
+ * @remarks
216
+ * The file name is a digest of `key`, so a key may hold any character, including `:` and `/`,
217
+ * which some platforms reject in a file name.
218
+ */
154
219
  protected getCachePath(key: string): string;
155
220
  protected readCache<T>(key: string): Promise<T | null>;
156
221
  protected writeCache<T>(key: string, data: T): Promise<void>;
@@ -1,8 +1,10 @@
1
- import path from 'node:path';
1
+ import { path } from '@ecopages/file-system/path';
2
2
  import { fileSystem } from '@ecopages/file-system';
3
3
  import { DEFAULT_ECOPAGES_WORK_DIR } from '../constants.js';
4
4
  import { GENERATED_BASE_PATHS } from '../constants.js';
5
+ import { contentHash } from '../utils/content-hash.js';
5
6
  import { deepMerge } from '../utils/deep-merge.js';
7
+ import { extensionsOfPattern } from './stylesheet-kinds.js';
6
8
  export const PROCESSOR_ERRORS = {
7
9
  CACHE_DIRECTORY_NOT_SET: 'Cache directory not set in context',
8
10
  };
@@ -35,6 +37,36 @@ export function writeGeneratedTypesPackage(options) {
35
37
  });
36
38
  options.writeFile(packageManifestPath, serializeGeneratedTypesPackage(options.packageName));
37
39
  }
40
+ /**
41
+ * Builds the ambient module declarations of the stylesheet extensions a Processor declares, for the Processor to write
42
+ * into its generated `@types` package from `setup()`.
43
+ *
44
+ * @remarks
45
+ * Core ships the declarations of `.css` and `.module.css` itself (`css-imports.d.ts`), so they are left out; the
46
+ * result is empty when no stylesheet capability declares another extension. For each extension `*.<ext>` declares
47
+ * the CSS string, and, when the capability sets `cssModules`, `*.module.<ext>` declares the class map. The module
48
+ * pattern comes first because TypeScript takes the first of two patterns that match a specifier alike.
49
+ */
50
+ export function serializeStylesheetModuleDeclarations(capabilities) {
51
+ const declarations = new Map();
52
+ for (const capability of capabilities) {
53
+ if (capability.kind !== 'stylesheet')
54
+ continue;
55
+ for (const extension of (capability.extensions ?? []).flatMap(extensionsOfPattern)) {
56
+ if (extension === '.css')
57
+ continue;
58
+ declarations.set(extension, declarations.get(extension) === true || capability.cssModules === true);
59
+ }
60
+ }
61
+ return [...declarations]
62
+ .map(([extension, cssModules]) => {
63
+ const classes = cssModules
64
+ ? `declare module '*.module${extension}' {\n\tconst classes: { readonly [key: string]: string };\n\texport default classes;\n}\n\n`
65
+ : '';
66
+ return `${classes}declare module '*${extension}' {\n\tconst styles: string;\n\texport default styles;\n}\n`;
67
+ })
68
+ .join('\n');
69
+ }
38
70
  /**
39
71
  * Base class for content and asset processors that contribute build plugins.
40
72
  *
@@ -108,13 +140,20 @@ export class Processor {
108
140
  restoreProductionRuntime() {
109
141
  return Promise.resolve();
110
142
  }
143
+ /**
144
+ * @remarks
145
+ * The file name is a digest of `key`, so a key may hold any character, including `:` and `/`,
146
+ * which some platforms reject in a file name.
147
+ */
111
148
  getCachePath(key) {
112
- return `${this.context?.cache}/${key}`;
149
+ if (!this.context?.cache) {
150
+ throw new Error(PROCESSOR_ERRORS.CACHE_DIRECTORY_NOT_SET);
151
+ }
152
+ return path.join(this.context.cache, `${contentHash(key)}.json`);
113
153
  }
114
154
  async readCache(key) {
115
- const cachePath = this.getCachePath(key);
116
155
  try {
117
- const data = await fileSystem.readFile(cachePath);
156
+ const data = await fileSystem.readFile(this.getCachePath(key));
118
157
  return JSON.parse(data);
119
158
  }
120
159
  catch {
@@ -122,11 +161,7 @@ export class Processor {
122
161
  }
123
162
  }
124
163
  async writeCache(key, data) {
125
- if (!this.context?.cache) {
126
- throw new Error(PROCESSOR_ERRORS.CACHE_DIRECTORY_NOT_SET);
127
- }
128
- const cachePath = this.getCachePath(key);
129
- fileSystem.write(cachePath, JSON.stringify(data, null, 2));
164
+ fileSystem.write(this.getCachePath(key), JSON.stringify(data, null, 2));
130
165
  }
131
166
  getWatchConfig() {
132
167
  return this.watchConfig;
@@ -0,0 +1,57 @@
1
+ import type { EcoPagesAppConfig } from '../config/internal-types.js';
2
+ import type { Processor, ProcessorExtensionPattern } from './processor.js';
3
+ /**
4
+ * Answers which files are stylesheets and which of those are CSS Modules.
5
+ *
6
+ * @remarks
7
+ * A stylesheet is a `.css` file, plus a file with an extension the registered stylesheet Processor declares.
8
+ * Core names no other extension, so an app without a stylesheet Processor handles plain CSS only.
9
+ */
10
+ export interface StylesheetKinds {
11
+ /** The lowercase, dotted stylesheet extensions, `.css` first. */
12
+ readonly extensions: readonly string[];
13
+ /** Whether `file`, a path or an import specifier, names a stylesheet. */
14
+ isStylesheet(file: string): boolean;
15
+ /**
16
+ * Whether `file` names a CSS Module: `.module.css`, or `.module.<ext>` for an extension declared by a capability
17
+ * that sets `cssModules`. Any other `.module.<ext>` is a plain stylesheet.
18
+ */
19
+ isCssModule(file: string): boolean;
20
+ /** Whether the stylesheet Processor declares that it scopes CSS Modules. */
21
+ readonly scopesCssModules: boolean;
22
+ }
23
+ /**
24
+ * Concrete dotted extensions a Processor extension pattern names.
25
+ *
26
+ * @remarks
27
+ * Handles `.css`, `css`, `*.css` and `*.{css,scss}`. The bare `*` wildcard and patterns that are not an
28
+ * extension name none, so a Processor cannot turn every file into a stylesheet.
29
+ */
30
+ export declare function extensionsOfPattern(pattern: ProcessorExtensionPattern): string[];
31
+ /**
32
+ * Finds the one Processor that declares a `stylesheet` capability.
33
+ *
34
+ * @throws When two Processors declare one, naming both.
35
+ */
36
+ export declare function findStylesheetProcessor(processors: Iterable<Processor>): Processor | undefined;
37
+ /**
38
+ * Builds the {@link StylesheetKinds} for the stylesheet Processor among `processors`, or for plain CSS alone.
39
+ *
40
+ * @throws When two Processors declare a `stylesheet` capability.
41
+ */
42
+ export declare function createStylesheetKinds(processors?: Iterable<Processor>): StylesheetKinds;
43
+ /** What to do about a CSS Module when no registered stylesheet Processor scopes them. */
44
+ export declare const CSS_MODULE_PROCESSOR_FIX = "No stylesheet Processor scopes CSS Modules. Install @ecopages/lightningcss-processor and register it in the Processors of eco.config.ts.";
45
+ /** The kinds of an app with no stylesheet Processor. */
46
+ export declare const PLAIN_CSS_KINDS: StylesheetKinds;
47
+ /** The {@link StylesheetKinds} of the Processors registered on `appConfig`. */
48
+ export declare function getStylesheetKinds(appConfig: Pick<EcoPagesAppConfig, 'processors'>): StylesheetKinds;
49
+ /**
50
+ * Whether a stylesheet reference may copy `file` into the build.
51
+ *
52
+ * @remarks
53
+ * Protection goes by what is copied, not where it lives: in a monorepo the app's packages, hoisted or in pnpm's
54
+ * store, sit outside its folder, and a package may name a sibling dependency's files. Only a font, image or media
55
+ * file is copied, never a dotfile, so a reference such as `url(../../.env)` cannot publish a secret or a source file.
56
+ */
57
+ export declare function isEmittableReferenceFile(file: string): boolean;
@@ -0,0 +1,114 @@
1
+ import { path } from '@ecopages/file-system/path';
2
+ const CSS_EXTENSION = '.css';
3
+ const CSS_MODULE_INFIX = '.module';
4
+ /**
5
+ * Concrete dotted extensions a Processor extension pattern names.
6
+ *
7
+ * @remarks
8
+ * Handles `.css`, `css`, `*.css` and `*.{css,scss}`. The bare `*` wildcard and patterns that are not an
9
+ * extension name none, so a Processor cannot turn every file into a stylesheet.
10
+ */
11
+ export function extensionsOfPattern(pattern) {
12
+ const normalized = pattern.trim().toLowerCase();
13
+ const grouped = /^\*\.\{(.+)\}$/.exec(normalized);
14
+ const items = grouped ? grouped[1].split(',') : [normalized.replace(/^\*/, '')];
15
+ return items
16
+ .map((item) => item.trim().replace(/^\./, ''))
17
+ .filter((item) => item !== '' && !/[*{},/]/.test(item))
18
+ .map((item) => `.${item}`);
19
+ }
20
+ /**
21
+ * Finds the one Processor that declares a `stylesheet` capability.
22
+ *
23
+ * @throws When two Processors declare one, naming both.
24
+ */
25
+ export function findStylesheetProcessor(processors) {
26
+ let found;
27
+ for (const processor of processors) {
28
+ if (!processor.canProcessAsset('stylesheet'))
29
+ continue;
30
+ if (found) {
31
+ throw new Error(`Only one Processor may declare a stylesheet capability, but "${found.name}" and "${processor.name}" both do.`);
32
+ }
33
+ found = processor;
34
+ }
35
+ return found;
36
+ }
37
+ /**
38
+ * Builds the {@link StylesheetKinds} for the stylesheet Processor among `processors`, or for plain CSS alone.
39
+ *
40
+ * @throws When two Processors declare a `stylesheet` capability.
41
+ */
42
+ export function createStylesheetKinds(processors = []) {
43
+ const capabilities = (findStylesheetProcessor(processors)?.getAssetCapabilities() ?? []).filter((capability) => capability.kind === 'stylesheet');
44
+ const declared = capabilities.flatMap((capability) => (capability.extensions ?? []).flatMap(extensionsOfPattern));
45
+ const extensions = [...new Set([CSS_EXTENSION, ...declared])];
46
+ const moduleExtensions = new Set([
47
+ CSS_EXTENSION,
48
+ ...capabilities
49
+ .filter((capability) => capability.cssModules === true)
50
+ .flatMap((capability) => (capability.extensions ?? []).flatMap(extensionsOfPattern)),
51
+ ]);
52
+ const moduleSuffixes = [...moduleExtensions].map((extension) => `${CSS_MODULE_INFIX}${extension}`);
53
+ const endsWithAny = (file, suffixes) => {
54
+ const lower = file.toLowerCase();
55
+ return suffixes.some((suffix) => lower.endsWith(suffix));
56
+ };
57
+ return {
58
+ extensions,
59
+ isStylesheet: (file) => endsWithAny(file, extensions),
60
+ isCssModule: (file) => endsWithAny(file, moduleSuffixes),
61
+ scopesCssModules: capabilities.some((capability) => capability.cssModules === true),
62
+ };
63
+ }
64
+ /** What to do about a CSS Module when no registered stylesheet Processor scopes them. */
65
+ export const CSS_MODULE_PROCESSOR_FIX = 'No stylesheet Processor scopes CSS Modules. Install @ecopages/lightningcss-processor and register it in the Processors of eco.config.ts.';
66
+ /** The kinds of an app with no stylesheet Processor. */
67
+ export const PLAIN_CSS_KINDS = createStylesheetKinds();
68
+ /** The {@link StylesheetKinds} of the Processors registered on `appConfig`. */
69
+ export function getStylesheetKinds(appConfig) {
70
+ return createStylesheetKinds(appConfig.processors?.values() ?? []);
71
+ }
72
+ /**
73
+ * Extensions of the files a stylesheet reference may copy into the build: fonts, images and media, the types CSS
74
+ * loads.
75
+ */
76
+ const EMITTABLE_REFERENCE_EXTENSIONS = new Set([
77
+ '.woff2',
78
+ '.woff',
79
+ '.ttf',
80
+ '.otf',
81
+ '.eot',
82
+ '.png',
83
+ '.jpg',
84
+ '.jpeg',
85
+ '.gif',
86
+ '.webp',
87
+ '.avif',
88
+ '.svg',
89
+ '.ico',
90
+ '.bmp',
91
+ '.apng',
92
+ '.jxl',
93
+ '.tif',
94
+ '.cur',
95
+ '.mp4',
96
+ '.webm',
97
+ '.mov',
98
+ '.ogg',
99
+ '.mp3',
100
+ '.m4a',
101
+ '.wav',
102
+ ]);
103
+ /**
104
+ * Whether a stylesheet reference may copy `file` into the build.
105
+ *
106
+ * @remarks
107
+ * Protection goes by what is copied, not where it lives: in a monorepo the app's packages, hoisted or in pnpm's
108
+ * store, sit outside its folder, and a package may name a sibling dependency's files. Only a font, image or media
109
+ * file is copied, never a dotfile, so a reference such as `url(../../.env)` cannot publish a secret or a source file.
110
+ */
111
+ export function isEmittableReferenceFile(file) {
112
+ const name = path.basename(file);
113
+ return !name.startsWith('.') && EMITTABLE_REFERENCE_EXTENSIONS.has(path.extname(name).toLowerCase());
114
+ }