@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
@@ -0,0 +1,101 @@
1
+ import { path } from '@ecopages/file-system/path';
2
+ import { getAssetDependencyKey } from './asset-dependency-keys.js';
3
+ /**
4
+ * The emitted form of every dependency one production build processed or bundled, by dependency key.
5
+ *
6
+ * @remarks
7
+ * `ecopages build` records here every dependency it processes, and each script the app-wide browser build
8
+ * bundled, under the key of every dependency that declared it. It writes the record beside the server bundle;
9
+ * `ecopages start` restores and seals it, so rendering resolves each dependency to its file in `dist/` and never
10
+ * compiles, writes or reads the build machine's source tree. Keys and paths are relative to the app root, which
11
+ * lets the deployed folder sit at any location.
12
+ */
13
+ export class ProcessedAssetLedger {
14
+ entries = new Map();
15
+ browserOutputs;
16
+ sealed = false;
17
+ rootDir;
18
+ constructor(rootDir) {
19
+ this.rootDir = rootDir;
20
+ }
21
+ /** True once `ecopages start` sealed the restored record: a dependency it does not record is an error. */
22
+ get isSealed() {
23
+ return this.sealed;
24
+ }
25
+ /** Serves every dependency from this record from now on; asset processing compiles and writes nothing. */
26
+ seal() {
27
+ this.sealed = true;
28
+ }
29
+ /** True once the app-wide browser build recorded its outputs, in this process or in the restored build. */
30
+ get hasBrowserBuild() {
31
+ return this.browserOutputs !== undefined;
32
+ }
33
+ /**
34
+ * @remarks
35
+ * An inline asset carries its content and no file reaches `dist/`, so its `filepath` is not recorded.
36
+ */
37
+ record(dep, asset) {
38
+ const recorded = asset.inline ? { ...asset, filepath: undefined } : asset;
39
+ this.entries.set(getAssetDependencyKey(dep, this.rootDir), this.toPortable(recorded));
40
+ }
41
+ /** Records the files one app-wide browser build emitted, which marks the ledger as holding that build. */
42
+ recordBrowserOutputs(filepaths) {
43
+ this.browserOutputs ??= new Set();
44
+ for (const filepath of filepaths)
45
+ this.browserOutputs.add(this.relative(filepath));
46
+ }
47
+ /**
48
+ * Forgets the app-wide browser build, so a retried production build records only its own outputs.
49
+ *
50
+ * @remarks
51
+ * Recorded dependencies stay: the next build records the ones it bundles again under the same keys.
52
+ */
53
+ clearBrowserOutputs() {
54
+ this.browserOutputs = undefined;
55
+ }
56
+ /** Returns the recorded asset with paths resolved against the current app root. */
57
+ lookup(dep) {
58
+ const asset = this.entries.get(getAssetDependencyKey(dep, this.rootDir));
59
+ return asset ? this.toAbsolute(asset) : undefined;
60
+ }
61
+ /** Names `dep` in error messages: its app-root relative file, import path or content name. */
62
+ describe(dep) {
63
+ if ('filepath' in dep)
64
+ return this.relative(dep.filepath);
65
+ if ('importPath' in dep)
66
+ return dep.importPath;
67
+ return 'name' in dep && dep.name ? `content ${dep.name}` : 'inline content';
68
+ }
69
+ serialize() {
70
+ const entries = [...this.entries]
71
+ .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
72
+ .map(([key, asset]) => ({ key, asset }));
73
+ return this.browserOutputs ? { entries, browserOutputs: [...this.browserOutputs].sort() } : { entries };
74
+ }
75
+ restore(ledger) {
76
+ this.entries.clear();
77
+ for (const { key, asset } of ledger.entries)
78
+ this.entries.set(key, asset);
79
+ this.browserOutputs = ledger.browserOutputs ? new Set(ledger.browserOutputs) : undefined;
80
+ }
81
+ relative(filepath) {
82
+ return path.relative(this.rootDir, path.resolve(this.rootDir, filepath));
83
+ }
84
+ toPortable(asset) {
85
+ return {
86
+ ...asset,
87
+ filepath: asset.filepath ? this.relative(asset.filepath) : undefined,
88
+ sourceFilepath: asset.sourceFilepath ? this.relative(asset.sourceFilepath) : undefined,
89
+ bundledSourceFilepaths: asset.bundledSourceFilepaths?.map((filepath) => this.relative(filepath)),
90
+ };
91
+ }
92
+ toAbsolute(asset) {
93
+ const resolve = (filepath) => path.resolve(this.rootDir, filepath);
94
+ return {
95
+ ...asset,
96
+ filepath: asset.filepath ? resolve(asset.filepath) : undefined,
97
+ sourceFilepath: asset.sourceFilepath ? resolve(asset.sourceFilepath) : undefined,
98
+ bundledSourceFilepaths: asset.bundledSourceFilepaths?.map(resolve),
99
+ };
100
+ }
101
+ }
@@ -1,4 +1,4 @@
1
- import path from 'node:path';
1
+ import { path } from '@ecopages/file-system/path';
2
2
  import { RESOLVED_ASSETS_DIR } from '../../../../constants.js';
3
3
  import { contentHash } from '../../../../utils/content-hash.js';
4
4
  import { isDevelopmentRuntime, isProductionRuntime } from '../../../../utils/runtime.js';
@@ -1,4 +1,4 @@
1
- import path from 'node:path';
1
+ import { path } from '@ecopages/file-system/path';
2
2
  import { BaseProcessor } from './base-processor.js';
3
3
  import { BrowserBundleService } from '../../../browser-bundle.service.js';
4
4
  import { collectBuildEntryInputPaths, getBuildEntryOutput } from '../../../../build/build-graph.js';
@@ -1,6 +1,22 @@
1
+ import type { EcoPagesAppConfig, IHmrManager } from '../../../../config/internal-types.js';
1
2
  import type { ContentScriptAsset, ProcessedAsset } from '../../assets.types.js';
2
3
  import { BaseScriptProcessor } from '../base/base-script-processor.js';
3
4
  export declare class ContentScriptProcessor extends BaseScriptProcessor<ContentScriptAsset> {
5
+ private readonly getHmrManager;
6
+ constructor(options: {
7
+ appConfig: EcoPagesAppConfig;
8
+ getHmrManager?: () => IHmrManager | undefined;
9
+ });
10
+ /**
11
+ * Returns the source of an unbundled script file as the browser should load it.
12
+ *
13
+ * @remarks
14
+ * With HMR active, a module script's imports are rewritten like a dev-transform module's, so a generated
15
+ * bootstrap can import a package by name and get the one vendor URL every other importer gets. This holds for an
16
+ * inline script too, whose body is the rewritten source. A script that is not a module, or HMR being off, keeps
17
+ * its source.
18
+ */
19
+ private resolveUnbundledScriptSource;
4
20
  private getContentScriptEntryDir;
5
21
  private getContentScriptEntryPath;
6
22
  private toProcessedAsset;
@@ -14,6 +30,14 @@ export declare class ContentScriptProcessor extends BaseScriptProcessor<ContentS
14
30
  * another in-flight Rolldown graph.
15
31
  */
16
32
  processGrouped(deps: ContentScriptAsset[]): Promise<ProcessedAsset[]>;
33
+ /**
34
+ * Bundles an inline script and returns its code as the asset content, with no output file.
35
+ *
36
+ * @remarks
37
+ * The page embeds the code, so nothing may load a file. The bundle is built without chunks in a work-directory
38
+ * folder that is removed once read, so no bundle reaches `dist/`.
39
+ */
40
+ private processInlineBundledScript;
17
41
  /**
18
42
  * Emits one content script asset. Cache reuse is owned by {@link AssetProcessingService}.
19
43
  */
@@ -1,9 +1,30 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import path from 'node:path';
2
+ import { path } from '@ecopages/file-system/path';
3
3
  import { fileSystem } from '@ecopages/file-system';
4
4
  import { resolveInlineContentScriptBody } from '../../inline-content-script-body.js';
5
5
  import { BaseScriptProcessor } from '../base/base-script-processor.js';
6
6
  export class ContentScriptProcessor extends BaseScriptProcessor {
7
+ getHmrManager;
8
+ constructor(options) {
9
+ super(options);
10
+ this.getHmrManager = options.getHmrManager ?? (() => undefined);
11
+ }
12
+ /**
13
+ * Returns the source of an unbundled script file as the browser should load it.
14
+ *
15
+ * @remarks
16
+ * With HMR active, a module script's imports are rewritten like a dev-transform module's, so a generated
17
+ * bootstrap can import a package by name and get the one vendor URL every other importer gets. This holds for an
18
+ * inline script too, whose body is the rewritten source. A script that is not a module, or HMR being off, keeps
19
+ * its source.
20
+ */
21
+ async resolveUnbundledScriptSource(dep, filepath) {
22
+ const hmrManager = this.getHmrManager();
23
+ if (!dep.content || dep.attributes?.type !== 'module' || !hmrManager?.isEnabled()) {
24
+ return dep.content;
25
+ }
26
+ return hmrManager.rewriteModuleImports(dep.content, filepath);
27
+ }
7
28
  getContentScriptEntryDir() {
8
29
  const dir = path.join(this.appConfig.absolutePaths.workDir, 'content-script-entries');
9
30
  fileSystem.ensureDir(dir);
@@ -52,6 +73,36 @@ export class ContentScriptProcessor extends BaseScriptProcessor {
52
73
  toProcessedAsset: (dep, output, entrypoint) => this.toProcessedAsset(dep, output.filepath, output.inputPaths, entrypoint),
53
74
  });
54
75
  }
76
+ /**
77
+ * Bundles an inline script and returns its code as the asset content, with no output file.
78
+ *
79
+ * @remarks
80
+ * The page embeds the code, so nothing may load a file. The bundle is built without chunks in a work-directory
81
+ * folder that is removed once read, so no bundle reaches `dist/`.
82
+ */
83
+ async processInlineBundledScript(dep, filename) {
84
+ const bundleDir = path.join(this.getContentScriptEntryDir(), randomUUID());
85
+ const entryPath = path.join(bundleDir, 'entry.js');
86
+ fileSystem.ensureDir(bundleDir);
87
+ fileSystem.write(entryPath, dep.content);
88
+ try {
89
+ const bundledOutput = await this.bundleScript({
90
+ entrypoint: entryPath,
91
+ outdir: path.join(bundleDir, 'out'),
92
+ minify: this.isProduction,
93
+ naming: `${path.parse(filename).name}-[hash].[ext]`,
94
+ ...this.getBundlerOptions(dep),
95
+ splitting: false,
96
+ });
97
+ return {
98
+ ...this.toProcessedAsset(dep, bundledOutput.filepath, bundledOutput.inputPaths, entryPath),
99
+ filepath: undefined,
100
+ };
101
+ }
102
+ finally {
103
+ fileSystem.remove(bundleDir);
104
+ }
105
+ }
55
106
  /**
56
107
  * Emits one content script asset. Cache reuse is owned by {@link AssetProcessingService}.
57
108
  */
@@ -61,14 +112,18 @@ export class ContentScriptProcessor extends BaseScriptProcessor {
61
112
  const filename = dep.name ? `${dep.name}.js` : `script-${hash}.js`;
62
113
  const filepath = path.join(this.getAssetsDir(), 'scripts', filename);
63
114
  if (!shouldBundle) {
64
- if (!dep.inline) {
65
- fileSystem.write(filepath, dep.content);
115
+ const unbundled = { ...dep, content: await this.resolveUnbundledScriptSource(dep, filepath) };
116
+ if (!unbundled.inline) {
117
+ fileSystem.write(filepath, unbundled.content);
66
118
  }
67
- return this.toProcessedAsset(dep, filepath);
119
+ return this.toProcessedAsset(unbundled, filepath);
68
120
  }
69
121
  if (!dep.content) {
70
122
  throw new Error('No content found for script asset');
71
123
  }
124
+ if (dep.inline) {
125
+ return this.processInlineBundledScript(dep, filename);
126
+ }
72
127
  const entryPath = this.getContentScriptEntryPath();
73
128
  fileSystem.write(entryPath, dep.content);
74
129
  try {
@@ -1,6 +1,11 @@
1
1
  import type { EcoPagesAppConfig, IHmrManager } from '../../../../config/internal-types.js';
2
2
  import type { FileScriptAsset, ProcessedAsset } from '../../assets.types.js';
3
3
  import { BaseScriptProcessor } from '../base/base-script-processor.js';
4
+ /**
5
+ * @throws When an inline script, or a module it imports, starts a worker the build emits: inline, the script's
6
+ * `import.meta.url` is the page URL, so the worker URL would resolve against the page instead of the worker file.
7
+ */
8
+ export declare function assertInlineScriptStartsNoWorker(scriptPath: string, inputPaths: readonly string[]): void;
4
9
  export declare class FileScriptProcessor extends BaseScriptProcessor<FileScriptAsset> {
5
10
  private readonly getHmrManager;
6
11
  /** Source file of each classic script output, so `a.ts` and `a.js` cannot both become `a.js`. */
@@ -21,14 +26,13 @@ export declare class FileScriptProcessor extends BaseScriptProcessor<FileScriptA
21
26
  processGrouped(deps: FileScriptAsset[]): Promise<ProcessedAsset[]>;
22
27
  /**
23
28
  * @remarks
24
- * With HMR active, a bundled script is built and watched by the HMR manager, which emits an ES
25
- * module and serves the dev-transform URL. In production, a `bundle: false` script is written
29
+ * With HMR active, a bundled script is registered with the HMR manager, which returns its
30
+ * dev-transform URL; the dev transform server compiles the module when the browser requests it. In production, a `bundle: false` script is written
26
31
  * under a hash of its bytes. In development, a non-classic `bundle: false` file inside `srcDir`
27
32
  * is copied to its source-relative path. A classic script inside `srcDir` is compiled and written
28
33
  * under that path with a `.js` name. A file outside `srcDir` has no such path that stays inside
29
34
  * `dist`: an unbundled or classic script is written under a content hash, and a bundled script
30
- * is emitted in `dist/client/assets` under the bundler's `[name]-[hash]` name. Vendor runtimes inside
31
- * `src` keep their stable names.
35
+ * is emitted in `dist/client/assets` under the bundler's `[name]-[hash]` name.
32
36
  */
33
37
  process(dep: FileScriptAsset): Promise<ProcessedAsset>;
34
38
  private processWithHmr;
@@ -1,9 +1,20 @@
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 { assertBrowserOutputInsideDist, sourceRelativeBrowserAssetPath } from '../../../browser-asset-output.js';
4
4
  import { writeHashedBrowserAsset } from '../../../hashed-browser-asset.js';
5
5
  import { BaseScriptProcessor } from '../base/base-script-processor.js';
6
6
  import { classicScriptOutputName, compileClassicScript } from './classic-script-compiler.js';
7
+ import { findWorkerEntrySource } from '../../../../build/worker-urls.js';
8
+ /**
9
+ * @throws When an inline script, or a module it imports, starts a worker the build emits: inline, the script's
10
+ * `import.meta.url` is the page URL, so the worker URL would resolve against the page instead of the worker file.
11
+ */
12
+ export function assertInlineScriptStartsNoWorker(scriptPath, inputPaths) {
13
+ const worker = findWorkerEntrySource([scriptPath, ...inputPaths]);
14
+ if (!worker)
15
+ return;
16
+ throw new Error(`${scriptPath} is inline, but ${worker.sourcePath} starts new ${worker.url.constructorName}(new URL(${JSON.stringify(worker.url.specifier)}, import.meta.url)): an inline script resolves import.meta.url against the page, so declare it without inline.`);
17
+ }
7
18
  export class FileScriptProcessor extends BaseScriptProcessor {
8
19
  getHmrManager;
9
20
  /** Source file of each classic script output, so `a.ts` and `a.js` cannot both become `a.js`. */
@@ -50,14 +61,13 @@ export class FileScriptProcessor extends BaseScriptProcessor {
50
61
  }
51
62
  /**
52
63
  * @remarks
53
- * With HMR active, a bundled script is built and watched by the HMR manager, which emits an ES
54
- * module and serves the dev-transform URL. In production, a `bundle: false` script is written
64
+ * With HMR active, a bundled script is registered with the HMR manager, which returns its
65
+ * dev-transform URL; the dev transform server compiles the module when the browser requests it. In production, a `bundle: false` script is written
55
66
  * under a hash of its bytes. In development, a non-classic `bundle: false` file inside `srcDir`
56
67
  * is copied to its source-relative path. A classic script inside `srcDir` is compiled and written
57
68
  * under that path with a `.js` name. A file outside `srcDir` has no such path that stays inside
58
69
  * `dist`: an unbundled or classic script is written under a content hash, and a bundled script
59
- * is emitted in `dist/client/assets` under the bundler's `[name]-[hash]` name. Vendor runtimes inside
60
- * `src` keep their stable names.
70
+ * is emitted in `dist/client/assets` under the bundler's `[name]-[hash]` name.
61
71
  */
62
72
  async process(dep) {
63
73
  const hmrManager = this.getActiveHmrManager();
@@ -91,7 +101,7 @@ export class FileScriptProcessor extends BaseScriptProcessor {
91
101
  const output = dep.classic ? this.emitClassicScript(dep, outFilepath, content.toString()) : undefined;
92
102
  let filepath = output?.filepath;
93
103
  if (!dep.classic && !dep.inline) {
94
- if (outFilepath && (dep.packageRole === 'runtime' || !this.isProduction)) {
104
+ if (outFilepath && !this.isProduction) {
95
105
  const destination = path.join(this.getAssetsDir(), outFilepath);
96
106
  assertBrowserOutputInsideDist(this.appConfig.absolutePaths.distDir, destination);
97
107
  fileSystem.copyFile(dep.filepath, destination);
@@ -134,6 +144,8 @@ export class FileScriptProcessor extends BaseScriptProcessor {
134
144
  ...bundlerOptions,
135
145
  plugins: bundlerOptions.plugins,
136
146
  });
147
+ if (dep.inline)
148
+ assertInlineScriptStartsNoWorker(dep.filepath, bundledOutput.inputPaths);
137
149
  return {
138
150
  filepath: bundledOutput.filepath,
139
151
  sourceFilepath: dep.filepath,
@@ -1,5 +1,4 @@
1
- import path from 'node:path';
2
- import { fileURLToPath, pathToFileURL } from 'node:url';
1
+ import { path } from '@ecopages/file-system/path';
3
2
  import { fileSystem } from '@ecopages/file-system';
4
3
  import { requireAppRuntime } from '../../../../utils/app-runtime.js';
5
4
  import { BaseScriptProcessor } from '../base/base-script-processor.js';
@@ -92,7 +91,7 @@ export class NodeModuleScriptProcessor extends BaseScriptProcessor {
92
91
  */
93
92
  resolveModulePathFallback(importPath, rootDir, maxDepth = 5) {
94
93
  try {
95
- return fileURLToPath(import.meta.resolve(importPath, pathToFileURL(path.join(rootDir, 'package.json')).href));
94
+ return path.fromFileUrl(import.meta.resolve(importPath, path.toFileUrl(path.join(rootDir, 'package.json')).href));
96
95
  }
97
96
  catch { }
98
97
  let currentDir = rootDir;
@@ -0,0 +1,34 @@
1
+ /** The real path of `file`, or `file` itself when it does not exist (yet). */
2
+ export declare function realPath(file: string): string;
3
+ /** The real directory of `file`. */
4
+ export declare function realDirectory(file: string): string;
5
+ /**
6
+ * Rebases the relative `url()` and `image-set()` string references of CSS inlined from `sourceFile` onto
7
+ * `entryFile`, so they name the same files from the importing stylesheet.
8
+ *
9
+ * @remarks
10
+ * Uses the core CSS scanner, so strings, comments and escapes are honoured. Both ends are real directories.
11
+ * A target on another Windows drive has no relative form and is written as its absolute path, which
12
+ * `emitStylesheetReferences` reads as a file.
13
+ */
14
+ export declare function rebaseStylesheetReferences(css: string, sourceFile: string, entryFile: string): string;
15
+ /** An app stylesheet after its relative `@import`s are inlined, and the partials that took part. */
16
+ export type InlinedStylesheet = {
17
+ css: string;
18
+ /** Absolute paths, without duplicates or the stylesheet itself. */
19
+ dependencies: string[];
20
+ };
21
+ /**
22
+ * Inlines the relative `@import`s of an app stylesheet, as a package stylesheet's are, so plain CSS with no Processor
23
+ * works once it is written to another folder.
24
+ *
25
+ * @remarks
26
+ * Runs on the output of the Processor, which has usually inlined them already (`postcss-import`, Lightning CSS), and
27
+ * then finds nothing to do. A partial's references are rebased onto the stylesheet, so
28
+ * `emitStylesheetReferences` finds the files they name. Its `layer`, `supports()` and media conditions wrap its
29
+ * CSS, a partial imported more than once keeps only its last instance, as the cascade and Lightning CSS order it, and remote and root-relative `@import`s and the first `@charset` move to the top. Only a `.css` file is
30
+ * inlined, never a dotfile. An `@import` that names no file is left as written with a warning; a bare specifier that
31
+ * names no sibling, such as a package, is left for the Processor. The returned dependencies include a missing `.css`
32
+ * partial, so creating it rebuilds the stylesheet.
33
+ */
34
+ export declare function inlineStylesheetImports(css: string, stylesheet: string): InlinedStylesheet;
@@ -0,0 +1,115 @@
1
+ import { path } from '@ecopages/file-system/path';
2
+ import { fileSystem } from '@ecopages/file-system';
3
+ import { appLogger } from '../../../../global/app-logger.js';
4
+ import { isExternalReference, scanCss, splitReference, wrapInConditions } from './css-scanner.js';
5
+ import { ImportOrder } from './import-order.js';
6
+ import { warnStylesheetOnce } from './stylesheet-warnings.js';
7
+ /** The real path of `file`, or `file` itself when it does not exist (yet). */
8
+ export function realPath(file) {
9
+ return fileSystem.exists(file) ? fileSystem.realpath(file) : file;
10
+ }
11
+ /** The real directory of `file`. */
12
+ export function realDirectory(file) {
13
+ return realPath(path.dirname(file));
14
+ }
15
+ /** Rewrites a relative reference written in a file of `sourceDir` to name the same file from `entryDir`. */
16
+ function rebaseReference(reference, sourceDir, entryDir) {
17
+ const { filePart, suffix } = splitReference(reference);
18
+ return `${path.relative(entryDir, path.resolve(sourceDir, filePart))}${suffix}`;
19
+ }
20
+ /**
21
+ * Rebases the relative `url()` and `image-set()` string references of CSS inlined from `sourceFile` onto
22
+ * `entryFile`, so they name the same files from the importing stylesheet.
23
+ *
24
+ * @remarks
25
+ * Uses the core CSS scanner, so strings, comments and escapes are honoured. Both ends are real directories.
26
+ * A target on another Windows drive has no relative form and is written as its absolute path, which
27
+ * `emitStylesheetReferences` reads as a file.
28
+ */
29
+ export function rebaseStylesheetReferences(css, sourceFile, entryFile) {
30
+ const entryDir = realDirectory(entryFile);
31
+ const sourceDir = realDirectory(sourceFile);
32
+ return scanCss(css, { reference: (reference) => rebaseReference(reference, sourceDir, entryDir) });
33
+ }
34
+ function warn(context, message) {
35
+ warnStylesheetOnce(context.stylesheet, context.source, `${context.stylesheet}: ${message}`, (text) => appLogger.warn(text));
36
+ }
37
+ /** Inlines the partial an `@import` of `importer` names. Returns `undefined` to leave the `@import` as written. */
38
+ function inlineImport(statement, importer, context) {
39
+ if (isExternalReference(statement.specifier)) {
40
+ return context.order.hoist(statement.statement);
41
+ }
42
+ const { decoded } = splitReference(statement.specifier);
43
+ const partial = path.resolve(path.dirname(importer), decoded);
44
+ if (!fileSystem.exists(partial)) {
45
+ if (!decoded.startsWith('.'))
46
+ return undefined;
47
+ if (path.extname(partial).toLowerCase() === '.css')
48
+ context.dependencies.add(partial);
49
+ warn(context, `@import ${JSON.stringify(statement.specifier)} in ${importer} names ${partial}, which does not exist, so it is left as written.`);
50
+ return undefined;
51
+ }
52
+ const real = fileSystem.realpath(partial);
53
+ if (path.extname(real).toLowerCase() !== '.css' || path.basename(real).startsWith('.')) {
54
+ warn(context, `@import ${JSON.stringify(statement.specifier)} in ${importer} names ${real}, which is not a stylesheet, so it is left as written.`);
55
+ return undefined;
56
+ }
57
+ if (context.ancestors.includes(real))
58
+ return '';
59
+ if (statement.conditions && wrapInConditions('', statement.conditions) === undefined) {
60
+ warn(context, `cannot read the conditions of ${statement.statement} in ${importer}, so it is left as written.`);
61
+ return undefined;
62
+ }
63
+ context.dependencies.add(partial);
64
+ context.ancestors.push(real);
65
+ const inlined = inlineFile(fileSystem.readFileSync(real), partial, context, false);
66
+ context.ancestors.pop();
67
+ return context.order.add(real, inlined, statement.conditions);
68
+ }
69
+ /** Scans one file: inlines its `@import`s, hoists its `@charset`, and rebases a partial's references onto the entry. */
70
+ function inlineFile(css, file, context, isEntry) {
71
+ const dir = realDirectory(file);
72
+ return scanCss(css, {
73
+ reference: isEntry ? undefined : (reference) => rebaseReference(reference, dir, context.entryDir),
74
+ import: (statement) => inlineImport(statement, file, context),
75
+ charset: (statement) => {
76
+ context.charset ??= statement;
77
+ return '';
78
+ },
79
+ });
80
+ }
81
+ /**
82
+ * Inlines the relative `@import`s of an app stylesheet, as a package stylesheet's are, so plain CSS with no Processor
83
+ * works once it is written to another folder.
84
+ *
85
+ * @remarks
86
+ * Runs on the output of the Processor, which has usually inlined them already (`postcss-import`, Lightning CSS), and
87
+ * then finds nothing to do. A partial's references are rebased onto the stylesheet, so
88
+ * `emitStylesheetReferences` finds the files they name. Its `layer`, `supports()` and media conditions wrap its
89
+ * CSS, a partial imported more than once keeps only its last instance, as the cascade and Lightning CSS order it, and remote and root-relative `@import`s and the first `@charset` move to the top. Only a `.css` file is
90
+ * inlined, never a dotfile. An `@import` that names no file is left as written with a warning; a bare specifier that
91
+ * names no sibling, such as a package, is left for the Processor. The returned dependencies include a missing `.css`
92
+ * partial, so creating it rebuilds the stylesheet.
93
+ */
94
+ export function inlineStylesheetImports(css, stylesheet) {
95
+ if (!/@import/i.test(css))
96
+ return { css, dependencies: [] };
97
+ const entry = path.resolve(stylesheet);
98
+ const context = {
99
+ stylesheet: entry,
100
+ source: css,
101
+ entryDir: realDirectory(entry),
102
+ ancestors: [realPath(entry)],
103
+ order: new ImportOrder(),
104
+ dependencies: new Set(),
105
+ };
106
+ const inlinedBody = inlineFile(css, entry, context, true);
107
+ if (context.order.isEmpty)
108
+ return { css, dependencies: [...context.dependencies] };
109
+ const { css: body, hoisted } = context.order.resolve(inlinedBody);
110
+ const head = [...(context.charset ? [context.charset] : []), ...hoisted];
111
+ return {
112
+ css: head.length > 0 ? `${head.join('\n')}\n${body}` : body,
113
+ dependencies: [...context.dependencies].filter((dependency) => dependency !== entry),
114
+ };
115
+ }
@@ -1,4 +1,4 @@
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 { writeHashedBrowserAsset } from '../../../hashed-browser-asset.js';
4
4
  import { BaseProcessor } from '../base/base-processor.js';
@@ -6,7 +6,7 @@ import { applyStylesheetProcessors } from './stylesheet-processor-pipeline.js';
6
6
  export class ContentStylesheetProcessor extends BaseProcessor {
7
7
  async process(dep) {
8
8
  const virtualFilepath = dep.processingOrigin ?? path.join(this.appConfig.absolutePaths.distDir, 'styles', 'page-bundle.css');
9
- const processedContent = await applyStylesheetProcessors(this.appConfig, dep.content, virtualFilepath);
9
+ const { css: processedContent } = await applyStylesheetProcessors(this.appConfig, dep.content, virtualFilepath);
10
10
  const hash = this.generateHash(processedContent);
11
11
  let filepath;
12
12
  if (!dep.inline) {
@@ -0,0 +1,39 @@
1
+ import type { EcoPagesAppConfig } from '../../../../config/internal-types.js';
2
+ /** The module name of the generated `@types` package that holds the declarations of the app's CSS Modules. */
3
+ export declare const CSS_MODULE_TYPES_MODULE = "ecopages-css-modules";
4
+ /**
5
+ * The declaration of a CSS Module whose class map is `exports`: the default export, typed with each class name as a
6
+ * literal key, and a named export for each name that is a valid identifier (see {@link isCssModuleExportName}).
7
+ *
8
+ * @remarks
9
+ * The default export is bound to a local name that no class takes, so a class named `styles` stays a named export.
10
+ */
11
+ export declare function toCssModuleDeclaration(exports: Readonly<Record<string, string>>): string;
12
+ /**
13
+ * Writes the declaration of the CSS Module `file` into the generated `@types` package, so a named import of its
14
+ * classes type-checks.
15
+ *
16
+ * @remarks
17
+ * The declaration sits at the path of the module under `srcDir`, which resolves for an app that lists the package
18
+ * folder in `rootDirs` (and, for an alias such as `@/*`, in `paths`; see the CSS Modules guide). Unchanged
19
+ * content is not rewritten, so a watcher on the folder stays quiet.
20
+ */
21
+ export declare function writeCssModuleDeclaration(appConfig: EcoPagesAppConfig, file: string, exports: Readonly<Record<string, string>>): void;
22
+ /** Removes the declaration of the CSS Module `file`, as when the module is deleted. */
23
+ export declare function removeCssModuleDeclaration(appConfig: EcoPagesAppConfig, file: string): void;
24
+ /**
25
+ * Writes the declarations of every CSS Module in `srcDir`, and drops the ones an earlier run left for modules that
26
+ * are gone. Writes nothing when no stylesheet Processor scopes CSS Modules.
27
+ *
28
+ * @remarks
29
+ * A module the Processor rejects is logged and skipped, so one broken file does not hide the types of the others.
30
+ */
31
+ export declare function writeCssModuleDeclarations(appConfig: EcoPagesAppConfig): Promise<void>;
32
+ /**
33
+ * Warns when the app has CSS Module declarations but its tsconfig cannot find them, and prints the lines to add.
34
+ *
35
+ * @remarks
36
+ * The caller runs it once, after the declarations are written. TypeScript resolves a declaration only through `rootDirs`, and an alias such as `@/*` also needs the package folder
37
+ * as a second `paths` target. Until they are listed, a named import of a CSS Module class fails type checking.
38
+ */
39
+ export declare function warnMissingCssModuleRootDirs(appConfig: EcoPagesAppConfig): void;