@ecopages/core 0.6.1 → 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 (350) 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 +4 -1
  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-lifecycle.d.ts +8 -1
  291. package/src/router/client/navigation-lifecycle.js +6 -3
  292. package/src/router/client/navigation-pipeline.d.ts +1 -0
  293. package/src/router/client/navigation-pipeline.js +1 -0
  294. package/src/router/server/route-registry.d.ts +3 -2
  295. package/src/router/server/route-registry.js +6 -5
  296. package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +30 -18
  297. package/src/static-site-generator/production-page-browser-graph-prebuild.js +82 -143
  298. package/src/static-site-generator/static-site-generator.d.ts +37 -4
  299. package/src/static-site-generator/static-site-generator.js +99 -51
  300. package/src/types/asset-types.d.ts +19 -1
  301. package/src/types/build-types.d.ts +53 -35
  302. package/src/types/component-identity.d.ts +8 -0
  303. package/src/types/contracts.d.ts +69 -21
  304. package/src/types/dev-transform-types.d.ts +33 -6
  305. package/src/types/eco-api-types.d.ts +13 -18
  306. package/src/types/integration-types.d.ts +1 -1
  307. package/src/types/public-types.d.ts +1 -1
  308. package/src/utils/additional-watch-paths.js +3 -5
  309. package/src/utils/entry-command-flags.d.ts +23 -0
  310. package/src/utils/entry-command-flags.js +24 -0
  311. package/src/utils/package-path.d.ts +42 -0
  312. package/src/utils/package-path.js +114 -0
  313. package/src/utils/parse-cli-args.d.ts +18 -1
  314. package/src/utils/parse-cli-args.js +54 -37
  315. package/src/utils/path-containment.js +3 -10
  316. package/src/utils/resolve-work-dir.js +2 -2
  317. package/src/utils/root-relative-path.js +2 -2
  318. package/src/utils/server-bundle-context.d.ts +5 -0
  319. package/src/utils/server-bundle-context.js +7 -1
  320. package/src/utils/server-utils.module.js +1 -1
  321. package/src/watchers/project-watcher-ignore.js +3 -3
  322. package/src/watchers/project-watcher.d.ts +14 -2
  323. package/src/watchers/project-watcher.js +37 -6
  324. package/src/watchers/workspace-package-watch-roots.js +2 -2
  325. package/src/assets/app-browser-client-manifest.d.ts +0 -66
  326. package/src/assets/app-browser-client-manifest.js +0 -260
  327. package/src/assets/asset-processing-service/asset-package-role.d.ts +0 -2
  328. package/src/assets/asset-processing-service/asset-package-role.js +0 -3
  329. package/src/assets/asset-processing-service/browser-runtime-asset.factory.d.ts +0 -58
  330. package/src/assets/asset-processing-service/browser-runtime-asset.factory.js +0 -61
  331. package/src/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +0 -79
  332. package/src/assets/asset-processing-service/browser-runtime-entry-resolution.js +0 -200
  333. package/src/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +0 -24
  334. package/src/assets/asset-processing-service/browser-runtime-entry.factory.js +0 -67
  335. package/src/build/browser/browser-runtime-manifest.d.ts +0 -35
  336. package/src/build/browser/browser-runtime-manifest.js +0 -65
  337. package/src/build/browser/browser-runtime-plugin-helpers.d.ts +0 -14
  338. package/src/build/browser/browser-runtime-plugin-helpers.js +0 -21
  339. package/src/build/browser/browser-runtime-plugin.d.ts +0 -54
  340. package/src/build/browser/browser-runtime-plugin.js +0 -76
  341. package/src/build/rolldown/server-side-css-shim-plugin.d.ts +0 -28
  342. package/src/build/rolldown/server-side-css-shim-plugin.js +0 -59
  343. package/src/dev/transform-server/dev-transform-module-kind.d.ts +0 -13
  344. package/src/dev/transform-server/dev-transform-module-kind.js +0 -17
  345. package/src/dev/transform-server/dev-transform-runtime-specifiers.d.ts +0 -5
  346. package/src/dev/transform-server/dev-transform-runtime-specifiers.js +0 -16
  347. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +0 -15
  348. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +0 -65
  349. package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.d.ts +0 -21
  350. package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.js +0 -31
@@ -1,39 +1,65 @@
1
- import path from 'node:path';
1
+ import { path } from '@ecopages/file-system/path';
2
2
  import { fileSystem } from '@ecopages/file-system';
3
- import { assertBrowserOutputInsideDist, sourceRelativeBrowserAssetPath } from '../../../browser-asset-output.js';
4
3
  import { writeHashedBrowserAsset } from '../../../hashed-browser-asset.js';
5
4
  import { BaseProcessor } from '../base/base-processor.js';
6
5
  import { applyStylesheetProcessors } from './stylesheet-processor-pipeline.js';
6
+ import { getStylesheetKinds } from '../../../../plugins/stylesheet-kinds.js';
7
+ import { emitPackageStylesheetReferences, emitStylesheetReferences, preparePackageStylesheet, } from './package-stylesheet.js';
8
+ import { writeSourceRelativeStylesheet } from './source-relative-stylesheet.js';
9
+ /**
10
+ * Processes a stylesheet file through the app's Processors and writes it under `dist/client/assets`.
11
+ *
12
+ * @remarks
13
+ * A package stylesheet (`fromPackage`) skips Processors (see {@link preparePackageStylesheet}) and is always
14
+ * written under its content hash. A package CSS Module is the one exception: the Processor that scopes CSS Modules
15
+ * scopes it, and the files it references follow the package policy (see {@link emitPackageStylesheetReferences}). The files any stylesheet's relative `url()` references name are emitted to
16
+ * `dist/client/assets` under a content hash (see {@link emitStylesheetReferences}); a linked stylesheet names them
17
+ * relative to where it is written, and an inline one root-relative, since a `<style>` resolves against the Page. In
18
+ * development a stylesheet inside `srcDir` keeps its source-relative path (see {@link writeSourceRelativeStylesheet}).
19
+ * The stylesheets the Processor inlined join `bundledSourceFilepaths`, so an edit to an `@import` partial evicts the
20
+ * cached asset and the Pages that link it.
21
+ */
7
22
  export class FileStylesheetProcessor extends BaseProcessor {
8
23
  getStyleContent = (srcUrl) => {
9
24
  return fileSystem.readFileAsBuffer(srcUrl);
10
25
  };
11
26
  async process(dep) {
12
- const buffer = this.getStyleContent(dep.filepath);
13
- const rawContent = buffer.toString();
14
- const processedContent = await applyStylesheetProcessors(this.appConfig, rawContent, dep.filepath);
15
- let filepath;
16
- if (!dep.inline) {
17
- const relativePath = sourceRelativeBrowserAssetPath(this.appConfig.absolutePaths.srcDir, dep.filepath);
18
- const directory = this.getAssetsDir();
19
- if (this.isProduction || !relativePath) {
20
- filepath = writeHashedBrowserAsset({
21
- bytes: processedContent,
22
- directory,
23
- extension: '.css',
24
- });
25
- }
26
- else {
27
- filepath = path.join(directory, relativePath);
28
- assertBrowserOutputInsideDist(this.appConfig.absolutePaths.distDir, filepath);
29
- fileSystem.ensureDir(path.dirname(filepath));
30
- fileSystem.write(filepath, processedContent);
31
- }
27
+ const directory = this.getAssetsDir();
28
+ const distDir = this.appConfig.absolutePaths.distDir;
29
+ const output = {
30
+ assetsDir: directory,
31
+ toReference: (emitted) => dep.inline ? `/${path.relative(distDir, emitted)}` : path.relative(directory, emitted),
32
+ };
33
+ const isCssModule = getStylesheetKinds(this.appConfig).isCssModule(dep.filepath);
34
+ if (dep.fromPackage && !isCssModule) {
35
+ return this.toProcessedAsset(dep, preparePackageStylesheet(dep.filepath, output));
32
36
  }
37
+ const { css, dependencies } = await applyStylesheetProcessors(this.appConfig, this.getStyleContent(dep.filepath).toString(), dep.filepath);
38
+ const processed = dependencies.length > 0
39
+ ? { ...dep, bundledSourceFilepaths: [...(dep.bundledSourceFilepaths ?? []), ...dependencies] }
40
+ : dep;
41
+ const sourceRelativePath = dep.inline || this.isProduction || dep.fromPackage
42
+ ? undefined
43
+ : writeSourceRelativeStylesheet(this.appDirs(), dep.filepath, css);
44
+ if (sourceRelativePath)
45
+ return this.toProcessedAsset(processed, undefined, sourceRelativePath);
46
+ const emit = dep.fromPackage ? emitPackageStylesheetReferences : emitStylesheetReferences;
47
+ return this.toProcessedAsset(processed, emit(css, dep.filepath, output));
48
+ }
49
+ appDirs() {
50
+ const { distDir, srcDir } = this.appConfig.absolutePaths;
51
+ return { srcDir, distDir };
52
+ }
53
+ /** Writes `content` under its content hash unless the stylesheet is inline or already written at `filepath`. */
54
+ toProcessedAsset(dep, content, filepath) {
55
+ const output = filepath ??
56
+ (dep.inline || content === undefined
57
+ ? undefined
58
+ : writeHashedBrowserAsset({ bytes: content, directory: this.getAssetsDir(), extension: '.css' }));
33
59
  return {
34
- filepath,
60
+ filepath: output,
35
61
  sourceFilepath: dep.filepath,
36
- content: dep.inline ? processedContent : undefined,
62
+ content: dep.inline ? content : undefined,
37
63
  kind: 'stylesheet',
38
64
  position: dep.position,
39
65
  attributes: dep.attributes,
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Orders inlined `@import`s the way the cascade does: a stylesheet imported more than once keeps only its last
3
+ * instance, where Lightning CSS and `postcss-import`-style bundlers place it.
4
+ *
5
+ * @remarks
6
+ * Equal-specificity rules cascade by their last occurrence, so an earlier copy of a stylesheet that is imported again
7
+ * later changes nothing except the order of what lies between. The scan cannot know which import is last until it
8
+ * has read the rest, so each inlined `@import` is written as a placeholder, and {@link ImportOrder.resolve} fills in
9
+ * the last instance of each stylesheet and drops the others. A placeholder is a NUL-delimited number, which no CSS
10
+ * source holds.
11
+ */
12
+ export declare class ImportOrder {
13
+ private readonly occurrences;
14
+ private readonly hoistable;
15
+ /** Records an inlined `@import` and returns the placeholder that stands for it in the importing CSS. */
16
+ add(stylesheet: string, css: string, conditions?: string): string;
17
+ /**
18
+ * Records an `@import` that moves to the top of the output (root-relative, `data:` or remote) and returns the
19
+ * placeholder that marks its place, so only the statements of the instances that are kept are hoisted.
20
+ */
21
+ hoist(statement: string): string;
22
+ /** Whether any `@import` was recorded. */
23
+ get isEmpty(): boolean;
24
+ /**
25
+ * Replaces the placeholders in `css` with the last instance of each stylesheet, wrapped in its conditions.
26
+ *
27
+ * @returns The CSS and the hoisted `@import` statements of the kept instances, in output order.
28
+ */
29
+ resolve(css: string): {
30
+ css: string;
31
+ hoisted: string[];
32
+ };
33
+ }
@@ -0,0 +1,67 @@
1
+ import { wrapInConditions } from './css-scanner.js';
2
+ const PLACEHOLDER = /\u0000(h?)(\d+)\u0000/g;
3
+ /**
4
+ * Orders inlined `@import`s the way the cascade does: a stylesheet imported more than once keeps only its last
5
+ * instance, where Lightning CSS and `postcss-import`-style bundlers place it.
6
+ *
7
+ * @remarks
8
+ * Equal-specificity rules cascade by their last occurrence, so an earlier copy of a stylesheet that is imported again
9
+ * later changes nothing except the order of what lies between. The scan cannot know which import is last until it
10
+ * has read the rest, so each inlined `@import` is written as a placeholder, and {@link ImportOrder.resolve} fills in
11
+ * the last instance of each stylesheet and drops the others. A placeholder is a NUL-delimited number, which no CSS
12
+ * source holds.
13
+ */
14
+ export class ImportOrder {
15
+ occurrences = [];
16
+ hoistable = [];
17
+ /** Records an inlined `@import` and returns the placeholder that stands for it in the importing CSS. */
18
+ add(stylesheet, css, conditions) {
19
+ this.occurrences.push({ stylesheet, css, conditions });
20
+ return `\u0000${this.occurrences.length - 1}\u0000`;
21
+ }
22
+ /**
23
+ * Records an `@import` that moves to the top of the output (root-relative, `data:` or remote) and returns the
24
+ * placeholder that marks its place, so only the statements of the instances that are kept are hoisted.
25
+ */
26
+ hoist(statement) {
27
+ this.hoistable.push(statement);
28
+ return `\u0000h${this.hoistable.length - 1}\u0000`;
29
+ }
30
+ /** Whether any `@import` was recorded. */
31
+ get isEmpty() {
32
+ return this.occurrences.length === 0;
33
+ }
34
+ /**
35
+ * Replaces the placeholders in `css` with the last instance of each stylesheet, wrapped in its conditions.
36
+ *
37
+ * @returns The CSS and the hoisted `@import` statements of the kept instances, in output order.
38
+ */
39
+ resolve(css) {
40
+ const last = new Map();
41
+ const visit = (text) => {
42
+ for (const match of text.matchAll(PLACEHOLDER)) {
43
+ if (match[1])
44
+ continue;
45
+ const id = Number(match[2]);
46
+ const occurrence = this.occurrences[id];
47
+ last.set(occurrence.stylesheet, id);
48
+ visit(occurrence.css);
49
+ }
50
+ };
51
+ visit(css);
52
+ const hoisted = [];
53
+ const render = (text) => text.replace(PLACEHOLDER, (_, hoist, rawId) => {
54
+ const id = Number(rawId);
55
+ if (hoist) {
56
+ hoisted.push(this.hoistable[id]);
57
+ return '';
58
+ }
59
+ const occurrence = this.occurrences[id];
60
+ if (last.get(occurrence.stylesheet) !== id)
61
+ return '';
62
+ const inlined = render(occurrence.css);
63
+ return occurrence.conditions ? (wrapInConditions(inlined, occurrence.conditions) ?? inlined) : inlined;
64
+ });
65
+ return { css: render(css), hoisted };
66
+ }
67
+ }
@@ -0,0 +1,44 @@
1
+ /** Where emitted files go and how the output stylesheet names them. */
2
+ export type StylesheetReferenceOutput = {
3
+ assetsDir: string;
4
+ /** The reference the output stylesheet uses for a file emitted to `assetsDir`. */
5
+ toReference: (emitted: string) => string;
6
+ };
7
+ /**
8
+ * Returns the browser-ready content of a package stylesheet.
9
+ *
10
+ * @remarks
11
+ * Processors do not transform it: a package ships CSS that is already built, and an app's PostCSS or Tailwind
12
+ * setup is not written for it. A tokenizer that honours strings, comments and escapes finds each relative `url()`
13
+ * and `image-set()` string, emits the file it names to `assetsDir` under a content hash, and rewrites the
14
+ * reference to what `toReference` returns for it. A `?` or `#` suffix is kept; root-relative, `data:` and remote
15
+ * URLs are left as written. An `@import` of a relative or package stylesheet is inlined in its place, its
16
+ * references rewritten from its location, wrapped in `@layer`, `@supports` and `@media` blocks for its conditions,
17
+ * and a file imported more than once keeps only its last instance, as the cascade orders it. Root-relative, `data:` and remote `@import`s and the first `@charset` are hoisted
18
+ * to the top, where browsers apply them; a hoisted import keeps its own conditions but not those of an `@import`
19
+ * that inlined its file. A reference to a missing file fails the build. Only a font, image or media file is copied;
20
+ * a reference to any other file is left as written with a warning (see {@link isEmittableReferenceFile}).
21
+ */
22
+ export declare function preparePackageStylesheet(stylesheet: string, output: StylesheetReferenceOutput): string;
23
+ /**
24
+ * Emits the files the relative `url()` and `image-set()` references of a processed app stylesheet name, and
25
+ * rewrites each reference to what `toReference` returns for the emitted file.
26
+ *
27
+ * @remarks
28
+ * A reference resolves from the real directory of the source stylesheet, as a Processor leaves it: `postcss-import` in the
29
+ * `@ecopages/postcss-processor` presets rebases the references of the files it inlines onto the importing file.
30
+ * `@import` and `@charset` are left as written. A reference to a missing file is left as written with a warning:
31
+ * Tailwind can generate a `url()` from a class it found in content, and a plain `postcss-import` leaves a package's
32
+ * references as the package wrote them. Only a font, image or media file is copied (see
33
+ * {@link isEmittableReferenceFile}).
34
+ */
35
+ export declare function emitStylesheetReferences(css: string, stylesheet: string, output: StylesheetReferenceOutput): string;
36
+ /**
37
+ * Emits the files the relative `url()` and `image-set()` references of a processed package stylesheet name, and
38
+ * rewrites each reference to what `toReference` returns for the emitted file.
39
+ *
40
+ * @remarks
41
+ * For a package CSS Module a Processor scoped, whose references stay as the package wrote them. It applies the
42
+ * policy of {@link preparePackageStylesheet} to them: a reference to a missing file fails the build.
43
+ */
44
+ export declare function emitPackageStylesheetReferences(css: string, stylesheet: string, output: StylesheetReferenceOutput): string;
@@ -0,0 +1,149 @@
1
+ import { path } from '@ecopages/file-system/path';
2
+ import { fileSystem } from '@ecopages/file-system';
3
+ import { resolvePackageStylesheetPath } from '../../../../plugins/tsconfig-import-resolver.js';
4
+ import { isEmittableReferenceFile } from '../../../../plugins/stylesheet-kinds.js';
5
+ import { appLogger } from '../../../../global/app-logger.js';
6
+ import { ImportOrder } from './import-order.js';
7
+ import { warnStylesheetOnce } from './stylesheet-warnings.js';
8
+ import { writeHashedBrowserAsset } from '../../../hashed-browser-asset.js';
9
+ import { realDirectory } from './app-stylesheet-imports.js';
10
+ import { isExternalReference, scanCss, splitReference, wrapInConditions } from './css-scanner.js';
11
+ /**
12
+ * Emits the file a reference names, or returns `undefined` to leave the reference as written, with a warning, when
13
+ * the file is not a type a stylesheet may copy.
14
+ */
15
+ function emitReferencedFile(stylesheet, source, reference, file, suffix, output) {
16
+ if (!isEmittableReferenceFile(file)) {
17
+ warnStylesheetOnce(stylesheet, source, `${stylesheet}: url(${reference}) names ${file}, which is not a font, image or media file, so it is not copied and the reference is left as written.`, (message) => appLogger.warn(message));
18
+ return undefined;
19
+ }
20
+ const emitted = writeHashedBrowserAsset({
21
+ bytes: fileSystem.readFileAsBuffer(file),
22
+ directory: output.assetsDir,
23
+ extension: path.extname(file),
24
+ });
25
+ return `${output.toReference(emitted)}${suffix}`;
26
+ }
27
+ /** Emits the file a package stylesheet's reference names; a missing file fails the build. */
28
+ function emitPackageReference(stylesheet, reference, output) {
29
+ const { decoded, suffix } = splitReference(reference);
30
+ const file = path.resolve(path.dirname(stylesheet), decoded);
31
+ if (!fileSystem.exists(file)) {
32
+ throw new Error(`[ecopages] ${stylesheet}: url(${reference}) names ${file}, which does not exist.`);
33
+ }
34
+ return emitReferencedFile(stylesheet, '', reference, fileSystem.realpath(file), suffix, output);
35
+ }
36
+ /**
37
+ * Emits the file an app stylesheet's reference names, or returns `undefined` to leave the reference as written,
38
+ * with a warning, when the file is missing.
39
+ */
40
+ function emitAppReference(stylesheet, source, reference, output) {
41
+ const { decoded, suffix } = splitReference(reference);
42
+ const file = path.resolve(realDirectory(stylesheet), decoded);
43
+ if (!fileSystem.exists(file)) {
44
+ warnStylesheetOnce(stylesheet, source, `${stylesheet}: url(${reference}) names ${file}, which does not exist, so it is left as written. Reference a file in the public directory with a root-relative URL such as /images/hero.png, and @import a package stylesheet through the @ecopages/postcss-processor presets, which rebase its url() references.`, (message) => appLogger.warn(message));
45
+ return undefined;
46
+ }
47
+ return emitReferencedFile(stylesheet, source, reference, fileSystem.realpath(file), suffix, output);
48
+ }
49
+ /**
50
+ * @remarks
51
+ * An `@import` specifier is a URL, so `base.css` names a sibling like `./base.css`; a package resolves only when
52
+ * no such file exists. Only a `.css` file is inlined, never a dotfile, so an `@import` cannot publish another file;
53
+ * like a `url()`, it may name a sibling dependency's stylesheet.
54
+ */
55
+ function resolveImportedStylesheet(stylesheet, specifier) {
56
+ const sibling = path.resolve(path.dirname(stylesheet), specifier);
57
+ const resolved = specifier.startsWith('.') || fileSystem.exists(sibling)
58
+ ? sibling
59
+ : resolvePackageStylesheetPath(stylesheet, specifier);
60
+ if (!resolved || !fileSystem.exists(resolved)) {
61
+ throw new Error(`[ecopages] ${stylesheet}: cannot resolve @import ${JSON.stringify(specifier)}.`);
62
+ }
63
+ const real = fileSystem.realpath(resolved);
64
+ if (path.extname(real).toLowerCase() !== '.css' || path.basename(real).startsWith('.')) {
65
+ throw new Error(`[ecopages] ${stylesheet}: @import ${JSON.stringify(specifier)} names ${real}, which is not a stylesheet.`);
66
+ }
67
+ return real;
68
+ }
69
+ /**
70
+ * Replaces a package stylesheet's `@import`: a root-relative, `data:` or remote one is hoisted, a relative or package
71
+ * one is inlined, wrapped in its conditions.
72
+ */
73
+ function inlinePackageImport(statement, stylesheet, context) {
74
+ if (isExternalReference(statement.specifier)) {
75
+ return context.order.hoist(statement.statement);
76
+ }
77
+ const imported = resolveImportedStylesheet(stylesheet, statement.specifier);
78
+ if (context.ancestors.includes(imported))
79
+ return '';
80
+ if (statement.conditions && wrapInConditions('', statement.conditions) === undefined) {
81
+ throw new Error(`[ecopages] ${stylesheet}: cannot read the conditions of ${statement.statement}`);
82
+ }
83
+ const inlined = preparePackageStylesheetFile(imported, context, context.output);
84
+ return context.order.add(imported, inlined, statement.conditions);
85
+ }
86
+ /**
87
+ * Rewrites one package stylesheet: its relative `url()` and `image-set()` string references, its `@import`s and
88
+ * its `@charset`, leaving strings and comments as written.
89
+ */
90
+ function preparePackageStylesheetFile(stylesheet, context, output) {
91
+ context.ancestors.push(stylesheet);
92
+ const prepared = scanCss(fileSystem.readFileSync(stylesheet), {
93
+ reference: (reference) => emitPackageReference(stylesheet, reference, output),
94
+ import: (statement) => inlinePackageImport(statement, stylesheet, context),
95
+ charset: (statement) => {
96
+ context.charset ??= statement;
97
+ return '';
98
+ },
99
+ });
100
+ context.ancestors.pop();
101
+ return prepared;
102
+ }
103
+ /**
104
+ * Returns the browser-ready content of a package stylesheet.
105
+ *
106
+ * @remarks
107
+ * Processors do not transform it: a package ships CSS that is already built, and an app's PostCSS or Tailwind
108
+ * setup is not written for it. A tokenizer that honours strings, comments and escapes finds each relative `url()`
109
+ * and `image-set()` string, emits the file it names to `assetsDir` under a content hash, and rewrites the
110
+ * reference to what `toReference` returns for it. A `?` or `#` suffix is kept; root-relative, `data:` and remote
111
+ * URLs are left as written. An `@import` of a relative or package stylesheet is inlined in its place, its
112
+ * references rewritten from its location, wrapped in `@layer`, `@supports` and `@media` blocks for its conditions,
113
+ * and a file imported more than once keeps only its last instance, as the cascade orders it. Root-relative, `data:` and remote `@import`s and the first `@charset` are hoisted
114
+ * to the top, where browsers apply them; a hoisted import keeps its own conditions but not those of an `@import`
115
+ * that inlined its file. A reference to a missing file fails the build. Only a font, image or media file is copied;
116
+ * a reference to any other file is left as written with a warning (see {@link isEmittableReferenceFile}).
117
+ */
118
+ export function preparePackageStylesheet(stylesheet, output) {
119
+ const context = { output, ancestors: [], order: new ImportOrder() };
120
+ const { css: body, hoisted } = context.order.resolve(preparePackageStylesheetFile(fileSystem.realpath(stylesheet), context, output));
121
+ const head = [...(context.charset ? [context.charset] : []), ...hoisted];
122
+ return head.length > 0 ? `${head.join('\n')}\n${body}` : body;
123
+ }
124
+ /**
125
+ * Emits the files the relative `url()` and `image-set()` references of a processed app stylesheet name, and
126
+ * rewrites each reference to what `toReference` returns for the emitted file.
127
+ *
128
+ * @remarks
129
+ * A reference resolves from the real directory of the source stylesheet, as a Processor leaves it: `postcss-import` in the
130
+ * `@ecopages/postcss-processor` presets rebases the references of the files it inlines onto the importing file.
131
+ * `@import` and `@charset` are left as written. A reference to a missing file is left as written with a warning:
132
+ * Tailwind can generate a `url()` from a class it found in content, and a plain `postcss-import` leaves a package's
133
+ * references as the package wrote them. Only a font, image or media file is copied (see
134
+ * {@link isEmittableReferenceFile}).
135
+ */
136
+ export function emitStylesheetReferences(css, stylesheet, output) {
137
+ return scanCss(css, { reference: (reference) => emitAppReference(stylesheet, css, reference, output) });
138
+ }
139
+ /**
140
+ * Emits the files the relative `url()` and `image-set()` references of a processed package stylesheet name, and
141
+ * rewrites each reference to what `toReference` returns for the emitted file.
142
+ *
143
+ * @remarks
144
+ * For a package CSS Module a Processor scoped, whose references stay as the package wrote them. It applies the
145
+ * policy of {@link preparePackageStylesheet} to them: a reference to a missing file fails the build.
146
+ */
147
+ export function emitPackageStylesheetReferences(css, stylesheet, output) {
148
+ return scanCss(css, { reference: (reference) => emitPackageReference(stylesheet, reference, output) });
149
+ }
@@ -0,0 +1,31 @@
1
+ /** A processed stylesheet and the other stylesheets its transform read. */
2
+ export interface ProcessedStylesheet {
3
+ css: string;
4
+ /** Absolute paths, without duplicates or the stylesheet itself. */
5
+ dependencies: string[];
6
+ /** The class map of a CSS Module, from the same transform as `css`; absent for any other stylesheet. */
7
+ exports?: Readonly<Record<string, string>>;
8
+ }
9
+ /**
10
+ * The stylesheets one app's Processor produced, by source file, so every caller of one edit reads one output.
11
+ *
12
+ * @remarks
13
+ * The dev stylesheet service, the dev transform server, server builds, browser bundles and the asset pipeline each
14
+ * process the stylesheets they meet; within one edit they share one transform per stylesheet. The development
15
+ * stylesheet service empties the cache at the start of every watcher batch, so any changed input, including content
16
+ * Tailwind scans or a file only the Processor knows it read, is seen on the next transform. Outside development no
17
+ * source changes while the process runs. Between batches an entry is reused only while the source and the
18
+ * dependencies its transform reported hash the same, which covers an edit whose batch has not arrived yet.
19
+ *
20
+ * A transform that started before {@link evict} belongs to a superseded generation: its result is not stored, and its
21
+ * caller transforms again. Concurrent misses within a generation share one transform. A failure is not cached.
22
+ */
23
+ export declare class ProcessedStylesheetCache {
24
+ private readonly entries;
25
+ private readonly inFlight;
26
+ private generation;
27
+ get(file: string, source: string, transform: () => Promise<ProcessedStylesheet>): Promise<ProcessedStylesheet>;
28
+ /** Drops every entry and starts a new generation, so no transform already running fills the cache. */
29
+ evict(): void;
30
+ private dependenciesUnchanged;
31
+ }
@@ -0,0 +1,59 @@
1
+ import { fileSystem } from '@ecopages/file-system';
2
+ import { path } from '@ecopages/file-system/path';
3
+ import { contentHash } from '../../../../utils/content-hash.js';
4
+ const hashFile = (file) => (fileSystem.exists(file) ? fileSystem.hash(file) : undefined);
5
+ /**
6
+ * The stylesheets one app's Processor produced, by source file, so every caller of one edit reads one output.
7
+ *
8
+ * @remarks
9
+ * The dev stylesheet service, the dev transform server, server builds, browser bundles and the asset pipeline each
10
+ * process the stylesheets they meet; within one edit they share one transform per stylesheet. The development
11
+ * stylesheet service empties the cache at the start of every watcher batch, so any changed input, including content
12
+ * Tailwind scans or a file only the Processor knows it read, is seen on the next transform. Outside development no
13
+ * source changes while the process runs. Between batches an entry is reused only while the source and the
14
+ * dependencies its transform reported hash the same, which covers an edit whose batch has not arrived yet.
15
+ *
16
+ * A transform that started before {@link evict} belongs to a superseded generation: its result is not stored, and its
17
+ * caller transforms again. Concurrent misses within a generation share one transform. A failure is not cached.
18
+ */
19
+ export class ProcessedStylesheetCache {
20
+ entries = new Map();
21
+ inFlight = new Map();
22
+ generation = 0;
23
+ async get(file, source, transform) {
24
+ const key = path.resolve(file);
25
+ const sourceHash = contentHash(source);
26
+ const entry = this.entries.get(key);
27
+ if (entry?.sourceHash === sourceHash && this.dependenciesUnchanged(entry))
28
+ return entry.result;
29
+ const generation = this.generation;
30
+ const flightKey = `${generation}\0${key}\0${sourceHash}`;
31
+ let pending = this.inFlight.get(flightKey);
32
+ if (!pending) {
33
+ pending = transform().finally(() => this.inFlight.delete(flightKey));
34
+ this.inFlight.set(flightKey, pending);
35
+ }
36
+ const result = await pending;
37
+ if (generation !== this.generation)
38
+ return this.get(file, source, transform);
39
+ this.entries.set(key, {
40
+ sourceHash,
41
+ dependencyHashes: new Map(result.dependencies.map((dependency) => [dependency, hashFile(dependency)])),
42
+ result,
43
+ });
44
+ return result;
45
+ }
46
+ /** Drops every entry and starts a new generation, so no transform already running fills the cache. */
47
+ evict() {
48
+ this.generation += 1;
49
+ this.entries.clear();
50
+ this.inFlight.clear();
51
+ }
52
+ dependenciesUnchanged(entry) {
53
+ for (const [dependency, hash] of entry.dependencyHashes) {
54
+ if (hashFile(dependency) !== hash)
55
+ return false;
56
+ }
57
+ return true;
58
+ }
59
+ }
@@ -0,0 +1,20 @@
1
+ /** The app folders {@link writeSourceRelativeStylesheet} reads from and writes to; `distDir` is the public output. */
2
+ export type SourceRelativeStylesheetDirs = {
3
+ srcDir: string;
4
+ distDir: string;
5
+ };
6
+ /**
7
+ * The href a development Page links `sourceFile` at, which CSS HMR refreshes; `undefined` for a file outside `srcDir`,
8
+ * which is written under a content hash instead.
9
+ */
10
+ export declare function sourceRelativeStylesheetHref(dirs: SourceRelativeStylesheetDirs, sourceFile: string): string | undefined;
11
+ /**
12
+ * Writes a processed app stylesheet at its source-relative path under `<distDir>/assets`, with the files its
13
+ * relative `url()` references name emitted beside it, and returns that path; `undefined` for a file outside `srcDir`.
14
+ *
15
+ * @remarks
16
+ * Development keeps a stylesheet inside `srcDir` at a stable href so CSS HMR can refresh the `<link>`. Core writes it
17
+ * when a Page links it, and its development stylesheet service rewrites it after an edit; both go through here so the
18
+ * output names the same emitted files. An unchanged file is not rewritten.
19
+ */
20
+ export declare function writeSourceRelativeStylesheet(dirs: SourceRelativeStylesheetDirs, sourceFile: string, processedCss: string): string | undefined;
@@ -0,0 +1,51 @@
1
+ import { path } from '@ecopages/file-system/path';
2
+ import { fileSystem } from '@ecopages/file-system';
3
+ import { RESOLVED_ASSETS_DIR } from '../../../../constants.js';
4
+ import { assertBrowserOutputInsideDist, sourceRelativeBrowserAssetPath } from '../../../browser-asset-output.js';
5
+ import { emitStylesheetReferences } from './package-stylesheet.js';
6
+ /**
7
+ * Where {@link writeSourceRelativeStylesheet} writes `sourceFile`; `undefined` for a file outside `srcDir`.
8
+ *
9
+ * @remarks
10
+ * A stylesheet with another extension, such as `card.scss` a Processor declares, is written as `card.scss.css`, so the
11
+ * static server answers with a CSS MIME type and `card.css` beside it keeps its own file.
12
+ */
13
+ function sourceRelativeStylesheetOutput(dirs, sourceFile) {
14
+ const relativePath = sourceRelativeBrowserAssetPath(dirs.srcDir, sourceFile);
15
+ if (!relativePath)
16
+ return undefined;
17
+ return path.join(dirs.distDir, RESOLVED_ASSETS_DIR, path.extname(relativePath) === '.css' ? relativePath : `${relativePath}.css`);
18
+ }
19
+ /**
20
+ * The href a development Page links `sourceFile` at, which CSS HMR refreshes; `undefined` for a file outside `srcDir`,
21
+ * which is written under a content hash instead.
22
+ */
23
+ export function sourceRelativeStylesheetHref(dirs, sourceFile) {
24
+ const filepath = sourceRelativeStylesheetOutput(dirs, sourceFile);
25
+ return filepath && `/${path.relative(dirs.distDir, filepath)}`;
26
+ }
27
+ /**
28
+ * Writes a processed app stylesheet at its source-relative path under `<distDir>/assets`, with the files its
29
+ * relative `url()` references name emitted beside it, and returns that path; `undefined` for a file outside `srcDir`.
30
+ *
31
+ * @remarks
32
+ * Development keeps a stylesheet inside `srcDir` at a stable href so CSS HMR can refresh the `<link>`. Core writes it
33
+ * when a Page links it, and its development stylesheet service rewrites it after an edit; both go through here so the
34
+ * output names the same emitted files. An unchanged file is not rewritten.
35
+ */
36
+ export function writeSourceRelativeStylesheet(dirs, sourceFile, processedCss) {
37
+ const filepath = sourceRelativeStylesheetOutput(dirs, sourceFile);
38
+ if (!filepath)
39
+ return undefined;
40
+ const assetsDir = path.join(dirs.distDir, RESOLVED_ASSETS_DIR);
41
+ assertBrowserOutputInsideDist(dirs.distDir, filepath);
42
+ const css = emitStylesheetReferences(processedCss, sourceFile, {
43
+ assetsDir,
44
+ toReference: (emitted) => path.relative(path.dirname(filepath), emitted),
45
+ });
46
+ if (fileSystem.exists(filepath) && fileSystem.readFileSync(filepath) === css)
47
+ return filepath;
48
+ fileSystem.ensureDir(path.dirname(filepath));
49
+ fileSystem.write(filepath, css);
50
+ return filepath;
51
+ }
@@ -0,0 +1,2 @@
1
+ /** The module a binding import of a stylesheet that never compiled receives: an empty class map or an empty string. */
2
+ export declare function emptyStylesheetModule(isCssModule: boolean): string;
@@ -0,0 +1,5 @@
1
+ import { toClassMapModule, toStylesheetModule } from './stylesheet-module.js';
2
+ /** The module a binding import of a stylesheet that never compiled receives: an empty class map or an empty string. */
3
+ export function emptyStylesheetModule(isCssModule) {
4
+ return isCssModule ? toClassMapModule({}) : toStylesheetModule('');
5
+ }
@@ -0,0 +1,37 @@
1
+ import type { EcoPagesAppConfig } from '../../../../config/internal-types.js';
2
+ /** The module a binding import of a stylesheet compiles to, and the other stylesheets its CSS inlined. */
3
+ export interface CompiledStylesheetModule {
4
+ code: string;
5
+ dependencies: string[];
6
+ }
7
+ /**
8
+ * Compiles a stylesheet a module imports with a binding, as in `import styles from './card.css'`, into an ES module
9
+ * whose default export is the processed CSS, or, for a CSS Module such as `import styles from './card.module.css'`, the
10
+ * class map.
11
+ *
12
+ * @remarks
13
+ * Every environment calls it, so a server build, a browser bundle and the dev transform server give the importer the
14
+ * same string: the output of the app's stylesheet Processor (see {@link applyStylesheetProcessors}). A side-effect
15
+ * import never reaches it, because its CSS reaches the Page as a Dependency. An error the Processor throws rejects.
16
+ *
17
+ * A CSS Module compiles to its `exports` and not to its CSS, which reaches the Page as a Dependency. That CSS comes
18
+ * from the same cached Processor result (see {@link applyStylesheetProcessors}), so the class names the module
19
+ * exports are the ones the delivered stylesheet defines in every environment, from one transform per edit.
20
+ * The dependencies let each caller rebuild the module when an `@import` partial changes.
21
+ */
22
+ export declare function compileStylesheetModule(appConfig: EcoPagesAppConfig, file: string): Promise<CompiledStylesheetModule>;
23
+ /** The ES module a binding import of a stylesheet receives: `css` as its default export. */
24
+ export declare function toStylesheetModule(css: string): string;
25
+ /**
26
+ * Whether a class name can be a named export of its CSS Module: a JavaScript identifier that is not a reserved word.
27
+ *
28
+ * @remarks
29
+ * A name that fails stays on the default export, so `styles['is-active']` keeps working. Names are never renamed,
30
+ * so `is-active` does not become `isActive`.
31
+ */
32
+ export declare function isCssModuleExportName(name: string): boolean;
33
+ /**
34
+ * The ES module a binding import of a CSS Module receives: its class map as the default export, and each class
35
+ * whose name is a valid identifier (see {@link isCssModuleExportName}) as a named export.
36
+ */
37
+ export declare function toClassMapModule(exports: Readonly<Record<string, string>>): string;
@@ -0,0 +1,48 @@
1
+ import { fileSystem } from '@ecopages/file-system';
2
+ import { applyStylesheetProcessors } from './stylesheet-processor-pipeline.js';
3
+ /**
4
+ * Compiles a stylesheet a module imports with a binding, as in `import styles from './card.css'`, into an ES module
5
+ * whose default export is the processed CSS, or, for a CSS Module such as `import styles from './card.module.css'`, the
6
+ * class map.
7
+ *
8
+ * @remarks
9
+ * Every environment calls it, so a server build, a browser bundle and the dev transform server give the importer the
10
+ * same string: the output of the app's stylesheet Processor (see {@link applyStylesheetProcessors}). A side-effect
11
+ * import never reaches it, because its CSS reaches the Page as a Dependency. An error the Processor throws rejects.
12
+ *
13
+ * A CSS Module compiles to its `exports` and not to its CSS, which reaches the Page as a Dependency. That CSS comes
14
+ * from the same cached Processor result (see {@link applyStylesheetProcessors}), so the class names the module
15
+ * exports are the ones the delivered stylesheet defines in every environment, from one transform per edit.
16
+ * The dependencies let each caller rebuild the module when an `@import` partial changes.
17
+ */
18
+ export async function compileStylesheetModule(appConfig, file) {
19
+ const { css, dependencies, exports } = await applyStylesheetProcessors(appConfig, await fileSystem.readFile(file), file);
20
+ return { code: exports ? toClassMapModule(exports) : toStylesheetModule(css), dependencies };
21
+ }
22
+ /** The ES module a binding import of a stylesheet receives: `css` as its default export. */
23
+ export function toStylesheetModule(css) {
24
+ return `export default ${JSON.stringify(css)};\n`;
25
+ }
26
+ const RESERVED_WORDS = new Set(`arguments await break case catch class const continue debugger default delete do else enum eval export extends
27
+ false finally for function if implements import in instanceof interface let new null package private protected
28
+ public return static super switch this throw true try typeof var void while with yield`.split(/\s+/u));
29
+ /**
30
+ * Whether a class name can be a named export of its CSS Module: a JavaScript identifier that is not a reserved word.
31
+ *
32
+ * @remarks
33
+ * A name that fails stays on the default export, so `styles['is-active']` keeps working. Names are never renamed,
34
+ * so `is-active` does not become `isActive`.
35
+ */
36
+ export function isCssModuleExportName(name) {
37
+ return /^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u.test(name) && !RESERVED_WORDS.has(name);
38
+ }
39
+ /**
40
+ * The ES module a binding import of a CSS Module receives: its class map as the default export, and each class
41
+ * whose name is a valid identifier (see {@link isCssModuleExportName}) as a named export.
42
+ */
43
+ export function toClassMapModule(exports) {
44
+ const named = Object.entries(exports)
45
+ .filter(([name]) => isCssModuleExportName(name))
46
+ .map(([name, scoped]) => `export const ${name} = ${JSON.stringify(scoped)};\n`);
47
+ return `${named.join('')}export default ${JSON.stringify(exports)};\n`;
48
+ }