@ecopages/core 0.6.1 → 0.7.1

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 +18 -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,7 +1,10 @@
1
- import path from 'node:path';
1
+ import { path } from '@ecopages/file-system/path';
2
2
  import { fileSystem } from '@ecopages/file-system';
3
3
  import { parseModuleSource } from '../cache/module-parse-cache.js';
4
- import { loadTsconfigPathPrefixes, matchesTsconfigPathPrefix, resolveProjectModulePath, } from './tsconfig-import-resolver.js';
4
+ import { CSS_MODULE_PROCESSOR_FIX, PLAIN_CSS_KINDS } from './stylesheet-kinds.js';
5
+ import { contentHash } from '../utils/content-hash.js';
6
+ import { findPackageRoot } from '../utils/package-path.js';
7
+ import { isBarePackageImportSpecifier, loadTsconfigPathPrefixes, matchesTsconfigPathPrefix, resolvePackageModulePath, resolvePackageStylesheetPath, resolveProjectModulePath, } from './tsconfig-import-resolver.js';
5
8
  function node(value) {
6
9
  return typeof value === 'object' && value !== null ? value : undefined;
7
10
  }
@@ -16,17 +19,155 @@ function identifierName(value) {
16
19
  return named.value;
17
20
  return undefined;
18
21
  }
22
+ function walk(value, visit) {
23
+ if (Array.isArray(value)) {
24
+ for (const child of value)
25
+ walk(child, visit);
26
+ return;
27
+ }
28
+ const current = node(value);
29
+ if (!current)
30
+ return;
31
+ visit(current);
32
+ for (const child of Object.values(current))
33
+ walk(child, visit);
34
+ }
35
+ function isFactoryCallee(callee, names) {
36
+ return ((callee?.type === 'MemberExpression' || callee?.type === 'StaticMemberExpression') &&
37
+ node(callee.object)?.type === 'Identifier' &&
38
+ node(callee.object)?.name === 'eco' &&
39
+ names.includes(String(node(callee.property)?.name)));
40
+ }
19
41
  function isFactory(value) {
20
42
  const call = node(value);
21
- const callee = node(call?.callee);
22
- return (call?.type === 'CallExpression' &&
23
- callee?.type === 'MemberExpression' &&
24
- node(callee.object)?.name === 'eco' &&
25
- ['component', 'layout', 'html'].includes(String(node(callee.property)?.name)));
43
+ return call?.type === 'CallExpression' && isFactoryCallee(node(call.callee), ['component', 'layout', 'html']);
44
+ }
45
+ /**
46
+ * Whether `program` calls `eco.page`, `eco.component`, `eco.layout` or `eco.html` anywhere.
47
+ */
48
+ export function declaresEcoFactory(program) {
49
+ let found = false;
50
+ walk(program, (current) => {
51
+ if (current.type === 'CallExpression' &&
52
+ isFactoryCallee(node(current.callee), ['page', 'component', 'layout', 'html'])) {
53
+ found = true;
54
+ }
55
+ });
56
+ return found;
26
57
  }
27
58
  function isServerSpecifier(source) {
28
59
  return /\.server(?:\.[cm]?[jt]sx?)?$/.test(source);
29
60
  }
61
+ function isLocalSpecifier(source, pathPrefixes) {
62
+ return source.startsWith('.') || matchesTsconfigPathPrefix(source, pathPrefixes);
63
+ }
64
+ function isLocalScript(file) {
65
+ return /\.[cm]?[jt]sx?$/.test(file) && !file.includes(`/node_modules/`);
66
+ }
67
+ const SCRIPT_FILE = /\.[cm]?[jt]sx?$/;
68
+ function isInNodeModules(file) {
69
+ return file.split('/').includes('node_modules');
70
+ }
71
+ /** Whether `file` belongs to an installed or linked package: under `node_modules`, or outside the app root. */
72
+ function isPackageModule(file, projectRoot) {
73
+ return isInNodeModules(file) || !path.isWithin(canonicalFile(projectRoot), canonicalFile(file));
74
+ }
75
+ const packageCssModules = new Map();
76
+ /**
77
+ * Whether the package that holds `file` ships a CSS Module.
78
+ *
79
+ * @remarks
80
+ * Discovery follows a bare import into a package only when it does, since only a CSS Module of a package module
81
+ * has to be delivered by a declaration, and most packages ship none. The answer is kept per package root for the
82
+ * life of the process; a package is not edited while an app runs.
83
+ */
84
+ function packageShipsCssModules(file, kinds) {
85
+ const root = findPackageRoot(file);
86
+ if (!root)
87
+ return false;
88
+ let ships = packageCssModules.get(root);
89
+ if (ships === undefined) {
90
+ ships = containsCssModule(root, kinds);
91
+ packageCssModules.set(root, ships);
92
+ }
93
+ return ships;
94
+ }
95
+ function containsCssModule(directory, kinds) {
96
+ return fileSystem
97
+ .readdir(directory)
98
+ .some((entry) => entry.isFile
99
+ ? kinds.isCssModule(entry.name)
100
+ : entry.isDirectory &&
101
+ entry.name !== 'node_modules' &&
102
+ containsCssModule(path.join(directory, entry.name), kinds));
103
+ }
104
+ /** The module a bare import names in a package that ships CSS Modules, or `undefined`. */
105
+ function resolvePackageModule(importer, source, kinds) {
106
+ let resolved;
107
+ try {
108
+ resolved = resolvePackageModulePath(importer, source);
109
+ }
110
+ catch {
111
+ return undefined;
112
+ }
113
+ return resolved && SCRIPT_FILE.test(resolved) && packageShipsCssModules(resolved, kinds) ? resolved : undefined;
114
+ }
115
+ /** Whether `source` names a plain stylesheet: one of `kinds`, but not a CSS Module. */
116
+ export function isCssImport(source, kinds) {
117
+ return kinds.isStylesheet(source) && !kinds.isCssModule(source);
118
+ }
119
+ /**
120
+ * Lists the static value imports of a module body in source order.
121
+ */
122
+ export function collectStaticImports(program) {
123
+ const imports = [];
124
+ for (const statement of nodes(node(program)?.body)) {
125
+ if (statement.type !== 'ImportDeclaration' || statement.importKind === 'type')
126
+ continue;
127
+ const source = node(statement.source)?.value;
128
+ if (typeof source !== 'string')
129
+ continue;
130
+ const specifiers = nodes(statement.specifiers);
131
+ const bindings = [];
132
+ for (const specifier of specifiers) {
133
+ const local = identifierName(specifier.local);
134
+ if (!local || specifier.importKind === 'type')
135
+ continue;
136
+ if (specifier.type === 'ImportDefaultSpecifier')
137
+ bindings.push({ imported: 'default', local });
138
+ if (specifier.type === 'ImportSpecifier') {
139
+ bindings.push({ imported: identifierName(specifier.imported) ?? local, local });
140
+ }
141
+ }
142
+ imports.push({
143
+ source,
144
+ start: statement.start,
145
+ end: statement.end,
146
+ bindings,
147
+ sideEffectOnly: specifiers.length === 0,
148
+ attributed: nodes(statement.attributes).length > 0 || nodes(statement.assertions).length > 0,
149
+ });
150
+ }
151
+ return imports;
152
+ }
153
+ /**
154
+ * Names a module renders: JSX element names and called identifiers.
155
+ *
156
+ * @remarks
157
+ * Lit and string templates render a component by calling it, so a call counts as a render.
158
+ */
159
+ function collectRenderedNames(program) {
160
+ const names = new Set();
161
+ walk(program, (current) => {
162
+ if (current.type === 'JSXOpeningElement' && node(current.name)?.type === 'JSXIdentifier') {
163
+ names.add(String(node(current.name)?.name));
164
+ }
165
+ if (current.type === 'CallExpression' && node(current.callee)?.type === 'Identifier') {
166
+ names.add(String(node(current.callee)?.name));
167
+ }
168
+ });
169
+ return names;
170
+ }
30
171
  function collectDeclaredFactoryBindings(body) {
31
172
  const declared = new Set();
32
173
  const factories = new Set();
@@ -79,166 +220,609 @@ function indexNamedExportStatement(statement, declared, factories, namedReexport
79
220
  }
80
221
  indexLocalNamedExportSpecifiers(specifiers, declared, factories);
81
222
  }
223
+ const moduleIndexes = new Map();
82
224
  /**
83
- * Indexes local `eco.*()` factory exports and named `export { X } from` re-exports.
225
+ * Indexes a module's `eco.*()` factory exports, named `export { X } from` re-exports and static imports.
84
226
  *
85
227
  * @remarks
86
- * `export *` is ignored so a barrel cannot pull an entire kit into the graph.
228
+ * The index lives for the process and is keyed by a hash of the file's contents, so each module is parsed
229
+ * once and an edit refreshes it on the next read without watcher wiring. It keeps only derived data, not
230
+ * the AST, which the bounded parse cache owns. `export *` is ignored so a barrel cannot
231
+ * pull an entire kit into the graph.
87
232
  */
88
- function indexModuleExports(file, cache) {
89
- const cached = cache.get(file);
90
- if (cached)
91
- return cached;
233
+ function indexModule(file, cache) {
234
+ const built = cache?.indexes.get(file);
235
+ if (built)
236
+ return built;
92
237
  const source = fileSystem.readFileSync(file);
93
- const parsed = parseModuleSource(file, source, { sourceType: 'module' });
94
- const body = nodes(parsed.program.body);
238
+ const hash = contentHash(source, 16);
239
+ const cached = moduleIndexes.get(file);
240
+ if (cached?.hash === hash) {
241
+ cache?.indexes.set(file, cached);
242
+ return cached;
243
+ }
244
+ const program = parseModuleSource(file, source, { sourceType: 'module' }).program;
245
+ const body = nodes(node(program)?.body);
95
246
  const { declared, factories } = collectDeclaredFactoryBindings(body);
96
247
  const namedReexports = new Map();
97
248
  for (const statement of body) {
98
249
  indexNamedExportStatement(statement, declared, factories, namedReexports);
99
250
  }
100
- const indexed = { factories, namedReexports };
101
- cache.set(file, indexed);
251
+ const indexed = {
252
+ hash,
253
+ declaresEcoFactory: source.includes('eco.') && declaresEcoFactory(program),
254
+ jsxImportSource: jsxPragmaOf(source),
255
+ renderedNames: collectRenderedNames(program),
256
+ factories,
257
+ namedReexports,
258
+ imports: collectStaticImports(program),
259
+ };
260
+ moduleIndexes.set(file, indexed);
261
+ cache?.indexes.set(file, indexed);
102
262
  return indexed;
103
263
  }
264
+ /** The leading `@jsxImportSource` pragma of a module, ignoring mentions further down. */
265
+ function jsxPragmaOf(source) {
266
+ return /^\s*\/\*[\s\S]*?@jsxImportSource\s+(\S+)[\s\S]*?\*\//.exec(source)?.[1];
267
+ }
268
+ /**
269
+ * Per app root: each walked plain module, each stylesheet a declaration delivers, and the declaration files whose
270
+ * discovery reached them.
271
+ */
272
+ const reachOwners = new Map();
273
+ function canonicalFile(file) {
274
+ return fileSystem.exists(file) ? fileSystem.realpath(file) : path.resolve(file);
275
+ }
276
+ function reachIn(projectRoot) {
277
+ const key = path.resolve(projectRoot);
278
+ let reach = reachOwners.get(key);
279
+ if (!reach) {
280
+ reach = { byModule: new Map(), byOwner: new Map() };
281
+ reachOwners.set(key, reach);
282
+ }
283
+ return reach;
284
+ }
285
+ /**
286
+ * Drops what discovery from the declaration in `ownerFile` recorded as reached.
287
+ *
288
+ * @remarks
289
+ * Each discovery of a declaration replaces its previous record, so a plain module stops counting as reached
290
+ * once no declaration imports it. The development watcher calls this for a deleted file, and the meta
291
+ * plugin for a module that no longer declares anything.
292
+ */
293
+ export function forgetDiscoveryOwner(projectRoot, ownerFile) {
294
+ const reach = reachIn(projectRoot);
295
+ const owner = canonicalFile(ownerFile);
296
+ for (const module of reach.byOwner.get(owner) ?? []) {
297
+ const owners = reach.byModule.get(module);
298
+ owners?.delete(owner);
299
+ if (owners?.size === 0)
300
+ reach.byModule.delete(module);
301
+ }
302
+ reach.byOwner.delete(owner);
303
+ }
304
+ function recordDiscoveryOwner(projectRoot, ownerFile, modules) {
305
+ forgetDiscoveryOwner(projectRoot, ownerFile);
306
+ const reach = reachIn(projectRoot);
307
+ const owner = canonicalFile(ownerFile);
308
+ const reached = new Set(modules);
309
+ reach.byOwner.set(owner, reached);
310
+ for (const module of reached) {
311
+ const owners = reach.byModule.get(module) ?? new Set();
312
+ owners.add(owner);
313
+ reach.byModule.set(module, owners);
314
+ }
315
+ }
316
+ /**
317
+ * Whether the latest discovery of some Eco declaration of the app at `projectRoot` walked into `file`.
318
+ *
319
+ * @remarks
320
+ * A bundler transforms an importer before the modules it imports in most builds, and the meta plugin checks
321
+ * again once its build is transformed, so a plain module reached from a declaration is recorded in time.
322
+ */
323
+ export function isReachedByDiscovery(projectRoot, file) {
324
+ return reachIn(projectRoot).byModule.has(canonicalFile(file));
325
+ }
326
+ /**
327
+ * Whether discovery has seen `file`, as a module a declaration walked into or as a declaration itself.
328
+ *
329
+ * @remarks
330
+ * A declaration in a linked package delivers its own CSS Module when discovery runs from it, so its CSS Module
331
+ * import is not left undelivered even when no walk reached the file.
332
+ */
333
+ export function hasDiscoveryRecord(projectRoot, file) {
334
+ const reach = reachIn(projectRoot);
335
+ const canonical = canonicalFile(file);
336
+ return reach.byModule.has(canonical) || reach.byOwner.has(canonical);
337
+ }
338
+ function relativeToRoot(projectRoot, file) {
339
+ const relative = path.relative(canonicalFile(projectRoot), canonicalFile(file));
340
+ return relative.startsWith('..') || path.isAbsolute(relative) ? file : relative;
341
+ }
342
+ function createPackageProcessedStylesheetError(projectRoot, importer, source) {
343
+ return new Error(`[ecopages] ${relativeToRoot(projectRoot, importer)}: ${JSON.stringify(source)} is a package stylesheet that is not CSS. Packages must ship built CSS, because Ecopages does not run a stylesheet Processor on a package file. Import the package's built .css file instead, or copy the source into the app.`);
344
+ }
345
+ function createUnscopedCssModuleError(projectRoot, importer, source) {
346
+ return new Error(`[ecopages] ${relativeToRoot(projectRoot, importer)}: ${JSON.stringify(source)} is a CSS Module. ${CSS_MODULE_PROCESSOR_FIX}`);
347
+ }
348
+ /**
349
+ * Classifies an import as delivering a local stylesheet, a CSS Module or a package stylesheet, or none of them.
350
+ *
351
+ * @remarks
352
+ * The one rule behind both stripping and discovery, so the two cannot drift. A plain stylesheet is delivered by a
353
+ * side-effect import alone, as the module has no binding to keep. A CSS Module is delivered by any import without
354
+ * attributes, since the importer keeps its class map. A package specifier names a stylesheet as
355
+ * {@link resolvePackageStylesheetPath} decides, and a CSS Module of a package is delivered by any import. Throws for a CSS Module,
356
+ * local or from a package, when no Processor scopes them (naming the package to install), for a package stylesheet
357
+ * named with `.css` that does not resolve,
358
+ * and for a `.css` specifier that is neither relative, aliased nor a package, such as `#styles/x.css` or an absolute
359
+ * path, which no Page could receive.
360
+ */
361
+ function classifyStylesheetImport(entry, importer, projectRoot, pathPrefixes, kinds) {
362
+ if (entry.attributed)
363
+ return undefined;
364
+ const isModule = kinds.isCssModule(entry.source);
365
+ if (isLocalSpecifier(entry.source, pathPrefixes)) {
366
+ if (isModule) {
367
+ if (!kinds.scopesCssModules)
368
+ throw createUnscopedCssModuleError(projectRoot, importer, entry.source);
369
+ return { kind: 'css-module' };
370
+ }
371
+ return entry.sideEffectOnly && isCssImport(entry.source, kinds) ? { kind: 'local' } : undefined;
372
+ }
373
+ if (!isBarePackageImportSpecifier(entry.source)) {
374
+ if (!kinds.isStylesheet(entry.source) || !(isModule || entry.sideEffectOnly))
375
+ return undefined;
376
+ throw new Error(`[ecopages] ${relativeToRoot(projectRoot, importer)}: ${JSON.stringify(entry.source)} is neither a relative, aliased nor package stylesheet import, so Ecopages cannot add it to a Page.`);
377
+ }
378
+ return classifyPackageStylesheetImport(entry, importer, projectRoot, kinds);
379
+ }
380
+ /**
381
+ * Classifies an import of a bare package specifier.
382
+ *
383
+ * @remarks
384
+ * A CSS Module of a package is delivered by any import without attributes, like a local one, and a plain package
385
+ * stylesheet by a side-effect import alone.
386
+ */
387
+ function classifyPackageStylesheetImport(entry, importer, projectRoot, kinds) {
388
+ const isModule = kinds.isCssModule(entry.source);
389
+ if (isModule && !kinds.scopesCssModules)
390
+ throw createUnscopedCssModuleError(projectRoot, importer, entry.source);
391
+ if (!isModule && !entry.sideEffectOnly)
392
+ return classifyBoundPackageStylesheet(entry, importer, projectRoot, kinds);
393
+ if (kinds.isStylesheet(entry.source) && !entry.source.toLowerCase().endsWith('.css')) {
394
+ throw createPackageProcessedStylesheetError(projectRoot, importer, entry.source);
395
+ }
396
+ const file = resolvePackageStylesheetPath(importer, entry.source);
397
+ if (file && kinds.isCssModule(file) && !kinds.scopesCssModules) {
398
+ throw createUnscopedCssModuleError(projectRoot, importer, entry.source);
399
+ }
400
+ return file ? { kind: 'package', file } : undefined;
401
+ }
402
+ /**
403
+ * Classifies a binding import of a `.css` package specifier that is not named like a CSS Module.
404
+ *
405
+ * @remarks
406
+ * The package may export a CSS Module under that name (`"./module.css": "./dist/x.module.css"`), which the importer
407
+ * keeps the class map of and which is delivered like any package CSS Module. Any other file stays the importer's own
408
+ * string, and a specifier that does not resolve is left to the build that imports it.
409
+ */
410
+ function classifyBoundPackageStylesheet(entry, importer, projectRoot, kinds) {
411
+ if (!entry.source.toLowerCase().endsWith('.css'))
412
+ return undefined;
413
+ let file;
414
+ try {
415
+ file = resolvePackageStylesheetPath(importer, entry.source);
416
+ }
417
+ catch {
418
+ return undefined;
419
+ }
420
+ if (!file || !kinds.isCssModule(file))
421
+ return undefined;
422
+ if (!kinds.scopesCssModules)
423
+ throw createUnscopedCssModuleError(projectRoot, importer, entry.source);
424
+ return { kind: 'package', file };
425
+ }
426
+ /**
427
+ * Whether discovery delivers `entry`: an import, without attributes, of a local plain stylesheet or of a package
428
+ * stylesheet when it is a side-effect import, or of a CSS Module in any form.
429
+ *
430
+ * @remarks
431
+ * The meta plugin strips the side-effect ones from plain modules and keeps a CSS Module import, whose class map
432
+ * the module uses. Throws as {@link classifyStylesheetImport} does.
433
+ */
434
+ export function isDeliveredStylesheetImport(entry, importer, projectRoot, pathPrefixes, kinds) {
435
+ return classifyStylesheetImport(entry, importer, projectRoot, pathPrefixes, kinds) !== undefined;
436
+ }
437
+ /**
438
+ * Builds the error for a CSS Module a package module imports when no Eco declaration reaches that module.
439
+ */
440
+ export function createUndeliverablePackageCssModuleError(projectRoot, file, source) {
441
+ const module = relativeToRoot(projectRoot, file);
442
+ return new Error(`[ecopages] ${module}: ${JSON.stringify(source)} is a CSS Module of a package module that never reaches a Page, because no eco.page(), eco.layout(), eco.html() or eco.component() module imports ${module} with a static import. Import it from one of them, or list the stylesheet in eco.component({ dependencies: { stylesheets } }).`);
443
+ }
444
+ /**
445
+ * Builds the error for a CSS Module an app module binds when no Eco declaration reaches that module or delivers the CSS Module.
446
+ */
447
+ export function createUndeliverableCssModuleError(projectRoot, file, source) {
448
+ const module = relativeToRoot(projectRoot, file);
449
+ return new Error(`[ecopages] ${module}: ${JSON.stringify(source)} is a CSS Module that never reaches a Page, because no eco.page(), eco.layout(), eco.html() or eco.component() module imports ${module} or ${JSON.stringify(source)} with a static import. Import one of them from one of those modules.`);
450
+ }
451
+ /**
452
+ * Builds the error for a side-effect stylesheet import in a module no Eco declaration reaches.
453
+ */
454
+ export function createUndeliverableStylesheetError(projectRoot, file, source) {
455
+ const module = relativeToRoot(projectRoot, file);
456
+ return new Error(`[ecopages] ${module}: ${JSON.stringify(source)} never reaches a Page, because no eco.page(), eco.layout(), eco.html() or eco.component() module imports ${module}. Import it from one of them, or list the stylesheet in eco.component({ dependencies }).`);
457
+ }
458
+ /**
459
+ * Builds the error for a side-effect stylesheet import of a package module that reaches a browser build.
460
+ *
461
+ * @remarks
462
+ * Discovery delivers the side-effect stylesheet imports of app modules and of the packages it reaches. A package
463
+ * module's own import reaches the build untouched, so its CSS would never load.
464
+ */
465
+ export function createUndeliverablePackageStylesheetError(projectRoot, importer, source) {
466
+ const module = relativeToRoot(projectRoot, importer);
467
+ return new Error(`[ecopages] ${module}: ${JSON.stringify(source)} never reaches a Page, because no eco.page(), eco.layout(), eco.html() or eco.component() delivers the stylesheets a package module imports. List the stylesheet in eco.component({ dependencies: { stylesheets } }) of the component that uses the package.`);
468
+ }
469
+ export function createDiscoveryCache() {
470
+ return { indexes: new Map(), walks: new Map() };
471
+ }
472
+ function resolveReexport(file, reexport, state) {
473
+ if (!reexport || isServerSpecifier(reexport.source) || !isLocalSpecifier(reexport.source, state.pathPrefixes)) {
474
+ return undefined;
475
+ }
476
+ const resolved = resolveProjectModulePath(state.projectRoot, file, reexport.source, { preserveBarrel: true });
477
+ if (!resolved) {
478
+ throw new Error(`[ecopages] Cannot resolve import ${JSON.stringify(reexport.source)} from ${file}`);
479
+ }
480
+ return isLocalScript(resolved) ? { file: resolved, imported: reexport.imported } : undefined;
481
+ }
104
482
  /**
105
483
  * True when `exportName` is an `eco.*()` factory, including through named barrel re-exports.
106
484
  *
107
485
  * @remarks
108
- * Completed answers are memoized on `resolved`. `path` is only the current walk, so a
486
+ * Completed answers are memoized on `resolved`. `pending` is only the current walk, so a
109
487
  * second alias of the same Component is not treated as a cycle miss.
110
488
  */
111
- function isFactoryExport(file, exportName, projectRoot, pathPrefixes, state) {
489
+ function isFactoryExport(file, exportName, state, pending = new Set()) {
112
490
  const visitKey = `${file}\0${exportName}`;
113
491
  const known = state.resolved.get(visitKey);
114
492
  if (known !== undefined)
115
493
  return known;
116
- if (state.path.has(visitKey))
494
+ if (pending.has(visitKey))
117
495
  return false;
118
- state.path.add(visitKey);
496
+ pending.add(visitKey);
119
497
  let result = false;
120
- if (!file.includes(`${path.sep}node_modules${path.sep}`) && !isServerSpecifier(file)) {
121
- const { factories, namedReexports } = indexModuleExports(file, state.moduleIndex);
498
+ if (!file.includes(`/node_modules/`) && !isServerSpecifier(file)) {
499
+ const { factories, namedReexports } = indexModule(file, state.cache);
122
500
  if (factories.has(exportName)) {
123
501
  result = true;
124
502
  state.watchFiles.add(file);
125
503
  }
126
504
  else {
127
- const reexport = namedReexports.get(exportName);
128
- if (reexport &&
129
- !isServerSpecifier(reexport.source) &&
130
- (reexport.source.startsWith('.') || matchesTsconfigPathPrefix(reexport.source, pathPrefixes))) {
131
- const resolved = resolveProjectModulePath(projectRoot, file, reexport.source, { preserveBarrel: true });
132
- if (!resolved) {
133
- throw new Error(`[ecopages] Cannot resolve import ${JSON.stringify(reexport.source)} from ${file}`);
134
- }
135
- if (/\.[jt]sx?$/.test(resolved) && !resolved.includes(`${path.sep}node_modules${path.sep}`)) {
136
- result = isFactoryExport(resolved, reexport.imported, projectRoot, pathPrefixes, state);
137
- if (result)
138
- state.watchFiles.add(file);
139
- }
505
+ const target = resolveReexport(file, namedReexports.get(exportName), state);
506
+ if (target) {
507
+ result = isFactoryExport(target.file, target.imported, state, pending);
508
+ if (result)
509
+ state.watchFiles.add(file);
140
510
  }
141
511
  }
142
512
  }
143
- state.path.delete(visitKey);
513
+ pending.delete(visitKey);
144
514
  state.resolved.set(visitKey, result);
145
515
  return result;
146
516
  }
147
- export function isCssImport(source) {
148
- return source.endsWith('.css') && !source.endsWith('.module.css');
149
- }
150
- function resolveStylesheetImportPath(source, ownerFile, projectRoot, pathPrefixes) {
151
- const isRelative = source.startsWith('.');
152
- const isAlias = matchesTsconfigPathPrefix(source, pathPrefixes);
153
- if (!isRelative && !isAlias) {
154
- return undefined;
517
+ /**
518
+ * Follows named re-exports of `exportName` from `file` and lists every module on the way, ending with the
519
+ * module that defines the binding.
520
+ */
521
+ function plainBindingModules(file, exportName, state) {
522
+ const modules = [];
523
+ const seen = new Set();
524
+ let current = { file, imported: exportName };
525
+ while (current && !seen.has(`${current.file}\0${current.imported}`)) {
526
+ seen.add(`${current.file}\0${current.imported}`);
527
+ modules.push(current.file);
528
+ current = resolveReexport(current.file, indexModule(current.file, state.cache).namedReexports.get(current.imported), state);
155
529
  }
156
- if (isRelative) {
530
+ return modules;
531
+ }
532
+ function resolveStylesheetImportPath(source, ownerFile, state) {
533
+ if (source.startsWith('.')) {
157
534
  const candidate = path.resolve(path.dirname(ownerFile), source);
158
535
  return fileSystem.exists(candidate) ? fileSystem.realpath(candidate) : undefined;
159
536
  }
160
- return resolveProjectModulePath(projectRoot, ownerFile, source, { preserveBarrel: true });
537
+ return resolveProjectModulePath(state.projectRoot, ownerFile, source, { preserveBarrel: true });
161
538
  }
162
- function tryRecordSideEffectStylesheetImport(statement, source, ownerFile, projectRoot, pathPrefixes, result) {
163
- const specifiers = nodes(statement.specifiers);
164
- if (!isCssImport(source) || specifiers.length > 0) {
165
- return false;
166
- }
167
- const resolved = resolveStylesheetImportPath(source, ownerFile, projectRoot, pathPrefixes);
168
- if (!resolved) {
169
- if (source.startsWith('.') || matchesTsconfigPathPrefix(source, pathPrefixes)) {
170
- throw new Error(`[ecopages] Cannot resolve stylesheet import ${JSON.stringify(source)} from ${ownerFile}`);
171
- }
172
- return false;
173
- }
174
- if (!fileSystem.exists(resolved)) {
175
- throw new Error(`[ecopages] Cannot resolve stylesheet import ${JSON.stringify(source)} from ${ownerFile}`);
539
+ /**
540
+ * Resolves a stylesheet import that discovery delivers, local, a CSS Module or from a package, or returns `undefined`
541
+ * for any other import.
542
+ *
543
+ * @remarks
544
+ * Throws as {@link classifyStylesheetImport} does, and for a local stylesheet that does not resolve.
545
+ */
546
+ function resolveDeliveredStylesheet(entry, importer, state) {
547
+ const target = classifyStylesheetImport(entry, importer, state.projectRoot, state.pathPrefixes, state.stylesheets);
548
+ if (!target)
549
+ return undefined;
550
+ if (target.kind === 'package')
551
+ return { file: target.file, fromPackage: true };
552
+ const resolved = resolveStylesheetImportPath(entry.source, importer, state);
553
+ if (!resolved || !fileSystem.exists(resolved)) {
554
+ throw new Error(`[ecopages] Cannot resolve stylesheet import ${JSON.stringify(entry.source)} from ${importer}`);
176
555
  }
177
- result.stylesheets.push(resolved);
178
- result.removals.push({ start: statement.start, end: statement.end, replacement: '' });
179
- return true;
556
+ return {
557
+ file: resolved,
558
+ fromPackage: target.kind === 'css-module' && isPackageModule(importer, state.projectRoot),
559
+ };
180
560
  }
181
- function collectFactoryComponentsFromImport(statement, source, ownerFile, projectRoot, pathPrefixes, factoryState, result) {
182
- const specifiers = nodes(statement.specifiers);
183
- const values = specifiers.filter((entry) => entry.importKind !== 'type' &&
184
- (entry.type === 'ImportSpecifier' || entry.type === 'ImportDefaultSpecifier'));
185
- if (!values.length || (!source.startsWith('.') && !matchesTsconfigPathPrefix(source, pathPrefixes))) {
561
+ function jsxRuntimeOf(file, state) {
562
+ const integration = state.integrationOf?.(file);
563
+ if (!integration)
564
+ return undefined;
565
+ const pragma = file === state.ownerFile && state.ownerSource !== undefined
566
+ ? jsxPragmaOf(state.ownerSource)
567
+ : indexModule(file, state.cache).jsxImportSource;
568
+ return { integration: integration.name, runtime: pragma ?? integration.jsxImportSource };
569
+ }
570
+ /**
571
+ * Throws when `importer` renders a plain component that another Integration owns.
572
+ *
573
+ * @remarks
574
+ * Only a capitalized binding the importer renders counts, so helpers shared across Integrations pass. Two
575
+ * Integrations that compile JSX with the same runtime, or one that leaves the runtime to the app's
576
+ * tsconfig, render each other's plain components, so the check needs both runtimes known and different.
577
+ * A `@jsxImportSource` pragma in either file wins over its Integration's runtime.
578
+ */
579
+ function assertSameIntegration(importer, local, component, renderedNames, state) {
580
+ if (!state.integrationOf || !/^[A-Z]/.test(local))
186
581
  return;
187
- }
188
- if (isServerSpecifier(source)) {
582
+ const importerOwner = jsxRuntimeOf(importer, state);
583
+ const componentOwner = jsxRuntimeOf(component, state);
584
+ if (!importerOwner || !componentOwner || importerOwner.integration === componentOwner.integration)
189
585
  return;
190
- }
191
- const resolved = resolveProjectModulePath(projectRoot, ownerFile, source, { preserveBarrel: true });
192
- if (!resolved)
193
- throw new Error(`[ecopages] Cannot resolve import ${JSON.stringify(source)} from ${ownerFile}`);
194
- if (!/\.[jt]sx?$/.test(resolved) || resolved.includes(`${path.sep}node_modules${path.sep}`)) {
586
+ if (!importerOwner.runtime || !componentOwner.runtime || importerOwner.runtime === componentOwner.runtime)
195
587
  return;
196
- }
197
- for (const specifier of values) {
198
- const imported = specifier.type === 'ImportDefaultSpecifier' ? 'default' : identifierName(specifier.imported);
199
- const local = identifierName(specifier.local);
200
- if (typeof local === 'string' &&
201
- imported &&
202
- isFactoryExport(resolved, imported, projectRoot, pathPrefixes, {
203
- ...factoryState,
204
- path: new Set(),
205
- })) {
206
- result.components.push(local);
207
- factoryState.watchFiles.add(resolved);
208
- }
209
- }
588
+ if (!renderedNames().has(local))
589
+ return;
590
+ throw new Error(`[ecopages] ${relativeToRoot(state.projectRoot, importer)} renders ${local} from ${relativeToRoot(state.projectRoot, component)}, a plain ${componentOwner.integration} component, inside ${importerOwner.integration}. Plain components do not cross Integrations: wrap ${local} in eco.component() so ${componentOwner.integration} renders it as a Foreign Child.`);
210
591
  }
211
592
  /**
212
- * Discovers local Eco Component imports and relative or aliased side-effect CSS.
593
+ * The module of a package that `entry` imports and discovery walks, or `undefined` when it follows none.
213
594
  *
214
595
  * @remarks
215
- * Named `export { X } from` barrels are followed for the imported binding only.
216
- * The imported module, the factory file, and successful re-export hops are recorded in
217
- * `watchFiles` so component and barrel edits invalidate caches.
218
- * `export *`, dynamic imports, namespace imports, packages, and `.server` modules are not.
596
+ * A bare import is followed from any module, and every import from a module installed under `node_modules`, but
597
+ * only into a package that ships a CSS Module (see {@link packageShipsCssModules}).
219
598
  */
220
- export function discoverComponentImports(program, ownerFile, projectRoot) {
221
- const result = { components: [], stylesheets: [], watchFiles: [], removals: [] };
222
- const pathPrefixes = loadTsconfigPathPrefixes(projectRoot);
223
- const factoryState = {
224
- moduleIndex: new Map(),
225
- resolved: new Map(),
226
- watchFiles: new Set(),
227
- path: new Set(),
228
- };
229
- for (const statement of nodes(node(program)?.body)) {
230
- if (statement.type !== 'ImportDeclaration' || statement.importKind === 'type')
599
+ function followPackageImport(entry, importer, state) {
600
+ if (!isInNodeModules(importer) && !isBarePackageImportSpecifier(entry.source, state.projectRoot))
601
+ return undefined;
602
+ return resolvePackageModule(importer, entry.source, state.stylesheets);
603
+ }
604
+ /** Whether `entry` imports a script module for its bindings or its side effects, not a stylesheet or a `.server` module. */
605
+ function isScriptEdge(entry, state) {
606
+ if (entry.attributed || state.stylesheets.isStylesheet(entry.source) || isServerSpecifier(entry.source))
607
+ return false;
608
+ return entry.sideEffectOnly || entry.bindings.length > 0;
609
+ }
610
+ /**
611
+ * Sorts the script imports of `importer` into Eco Component bindings and the plain local modules to walk.
612
+ */
613
+ function collectModuleEdges(importer, imports, renderedNames, state, onComponent) {
614
+ const plainModules = [];
615
+ for (const entry of imports) {
616
+ if (!isScriptEdge(entry, state))
231
617
  continue;
232
- if (nodes(statement.attributes).length || nodes(statement.assertions).length)
618
+ if (isInNodeModules(importer) || !isLocalSpecifier(entry.source, state.pathPrefixes)) {
619
+ const module = followPackageImport(entry, importer, state);
620
+ if (module)
621
+ plainModules.push(module);
233
622
  continue;
234
- const source = node(statement.source)?.value;
235
- if (typeof source !== 'string')
623
+ }
624
+ const resolved = resolveProjectModulePath(state.projectRoot, importer, entry.source, { preserveBarrel: true });
625
+ if (!resolved) {
626
+ if (entry.sideEffectOnly)
627
+ continue;
628
+ throw new Error(`[ecopages] Cannot resolve import ${JSON.stringify(entry.source)} from ${importer}`);
629
+ }
630
+ if (!isLocalScript(resolved))
236
631
  continue;
237
- if (tryRecordSideEffectStylesheetImport(statement, source, ownerFile, projectRoot, pathPrefixes, result)) {
632
+ if (entry.sideEffectOnly) {
633
+ plainModules.push(resolved);
238
634
  continue;
239
635
  }
240
- collectFactoryComponentsFromImport(statement, source, ownerFile, projectRoot, pathPrefixes, factoryState, result);
636
+ for (const binding of entry.bindings) {
637
+ if (isFactoryExport(resolved, binding.imported, state)) {
638
+ onComponent(binding, resolved);
639
+ continue;
640
+ }
641
+ const modules = plainBindingModules(resolved, binding.imported, state);
642
+ assertSameIntegration(importer, binding.local, modules[modules.length - 1], renderedNames, state);
643
+ plainModules.push(...modules);
644
+ }
645
+ }
646
+ return plainModules;
647
+ }
648
+ /**
649
+ * Records the stylesheets `file` imports that discovery delivers on `walk`.
650
+ *
651
+ * @remarks
652
+ * A module installed under `node_modules` delivers only its CSS Modules: a package ships built CSS, and the
653
+ * side-effect CSS of its modules is not delivered by discovery.
654
+ */
655
+ function collectWalkStylesheets(file, imports, state, walk) {
656
+ for (const entry of imports) {
657
+ if (isInNodeModules(file) && !state.stylesheets.isCssModule(entry.source))
658
+ continue;
659
+ const stylesheet = resolveDeliveredStylesheet(entry, file, state);
660
+ if (!stylesheet)
661
+ continue;
662
+ if (!walk.stylesheets.includes(stylesheet.file))
663
+ walk.stylesheets.push(stylesheet.file);
664
+ if (stylesheet.fromPackage && !walk.packageStylesheets.has(stylesheet.file))
665
+ walk.packageStylesheets.set(stylesheet.file, file);
666
+ }
667
+ }
668
+ /**
669
+ * Collects the side-effect stylesheets of a plain local module and of the plain modules it imports.
670
+ *
671
+ * @remarks
672
+ * A module's own stylesheets come before those of the modules it imports, the order collection gives a
673
+ * declaration and the Components it renders. A package stylesheet a module imports is collected in the same
674
+ * place. The walk enters a package's modules only in a package that ships a CSS Module (see
675
+ * {@link packageShipsCssModules}). It stops at Eco modules, other packages and `.server`
676
+ * modules, and follows only static named, default and side-effect imports. An Eco Component it imports is
677
+ * recorded on the walk. A walk is kept in the build cache unless it skipped a module still being walked
678
+ * higher up a cycle, since that walk lacks what the skipped module contributes.
679
+ */
680
+ function walkPlainModule(file, state, inProgress) {
681
+ const memo = state.cache?.walks.get(file);
682
+ if (memo)
683
+ return { walk: memo, pending: new Set() };
684
+ if (inProgress.has(file))
685
+ return { pending: new Set([file]) };
686
+ const index = indexModule(file, state.cache);
687
+ const walk = {
688
+ stylesheets: [],
689
+ packageStylesheets: new Map(),
690
+ components: new Map(),
691
+ modules: new Set(),
692
+ watchFiles: new Set(),
693
+ };
694
+ if (index.declaresEcoFactory)
695
+ return { walk, pending: new Set() };
696
+ inProgress.add(file);
697
+ const local = { ...state, resolved: new Map(), watchFiles: walk.watchFiles };
698
+ walk.modules.add(canonicalFile(file));
699
+ walk.watchFiles.add(file);
700
+ collectWalkStylesheets(file, index.imports, local, walk);
701
+ const children = collectModuleEdges(file, index.imports, () => index.renderedNames, local, (binding, target) => {
702
+ const key = `${target}\0${binding.imported}`;
703
+ if (!walk.components.has(key))
704
+ walk.components.set(key, { file: target, imported: binding.imported });
705
+ });
706
+ const pending = new Set();
707
+ for (const child of children) {
708
+ const result = walkPlainModule(child, state, inProgress);
709
+ for (const skipped of result.pending)
710
+ pending.add(skipped);
711
+ if (result.walk)
712
+ mergePlainModuleWalk(walk, result.walk);
713
+ }
714
+ inProgress.delete(file);
715
+ pending.delete(file);
716
+ if (pending.size === 0)
717
+ state.cache?.walks.set(file, walk);
718
+ return { walk, pending };
719
+ }
720
+ function mergePlainModuleWalk(into, from) {
721
+ for (const stylesheet of from.stylesheets)
722
+ if (!into.stylesheets.includes(stylesheet))
723
+ into.stylesheets.push(stylesheet);
724
+ for (const [stylesheet, importer] of from.packageStylesheets)
725
+ if (!into.packageStylesheets.has(stylesheet))
726
+ into.packageStylesheets.set(stylesheet, importer);
727
+ for (const [key, component] of from.components)
728
+ if (!into.components.has(key))
729
+ into.components.set(key, component);
730
+ for (const module of from.modules)
731
+ into.modules.add(module);
732
+ for (const watchFile of from.watchFiles)
733
+ into.watchFiles.add(watchFile);
734
+ }
735
+ /**
736
+ * Records the stylesheets the declaring module imports itself on `result`, and returns those a package import named.
737
+ *
738
+ * @remarks
739
+ * A side-effect import is removed from the module, and a CSS Module import stays for its class map.
740
+ */
741
+ function collectOwnStylesheets(imports, ownerFile, state, result) {
742
+ const packageStylesheets = new Map();
743
+ for (const entry of imports) {
744
+ const stylesheet = resolveDeliveredStylesheet(entry, ownerFile, state);
745
+ if (!stylesheet)
746
+ continue;
747
+ if (!result.stylesheets.includes(stylesheet.file))
748
+ result.stylesheets.push(stylesheet.file);
749
+ if (stylesheet.fromPackage && !packageStylesheets.has(stylesheet.file))
750
+ packageStylesheets.set(stylesheet.file, ownerFile);
751
+ if (entry.sideEffectOnly)
752
+ result.removals.push({ start: entry.start, end: entry.end, replacement: '' });
753
+ }
754
+ return packageStylesheets;
755
+ }
756
+ /**
757
+ * Discovers local Eco Component imports and the CSS that reaches an Eco declaration.
758
+ *
759
+ * @remarks
760
+ * The CSS Modules the declaring module imports count as its side-effect CSS: their scoped CSS reaches the Page the
761
+ * same way, though the import stays for the class map. Side-effect CSS of the declaring module, relative, aliased or from a package, is kept apart from the CSS of the
762
+ * plain local modules it imports (see {@link walkPlainModule}), which collection places after the CSS of every
763
+ * declaration that imports those modules. Eco Components a plain module imports become Components of the
764
+ * declaration too, so their Dependencies reach the Page. Named `export { X } from`
765
+ * barrels are followed for the imported binding only. Imported Eco modules, successful re-export hops and
766
+ * every walked plain module are recorded in `watchFiles` so their edits invalidate caches. Each stylesheet is
767
+ * listed once by real path, and `packageStylesheets` marks those a package import named.
768
+ * `export *`, dynamic imports, namespace imports, packages that ship no CSS Module, and `.server` modules are not
769
+ * followed.
770
+ */
771
+ export function discoverComponentImports(program, ownerFile, projectRoot, options = {}) {
772
+ const result = {
773
+ components: [],
774
+ stylesheets: [],
775
+ plainModuleStylesheets: [],
776
+ packageStylesheets: [],
777
+ plainModuleComponents: [],
778
+ watchFiles: [],
779
+ removals: [],
780
+ };
781
+ const state = {
782
+ projectRoot,
783
+ stylesheets: options.stylesheets ?? PLAIN_CSS_KINDS,
784
+ pathPrefixes: loadTsconfigPathPrefixes(projectRoot),
785
+ integrationOf: options.integrationOf,
786
+ ownerFile,
787
+ ownerSource: options.ownerSource,
788
+ cache: options.cache,
789
+ resolved: new Map(),
790
+ watchFiles: new Set(),
791
+ };
792
+ const imports = collectStaticImports(program);
793
+ const packageStylesheets = collectOwnStylesheets(imports, ownerFile, state, result);
794
+ let renderedNames;
795
+ const ownComponents = new Set();
796
+ const plainModules = collectModuleEdges(ownerFile, imports, () => (renderedNames ??= collectRenderedNames(program)), state, (binding, file) => {
797
+ result.components.push(binding.local);
798
+ ownComponents.add(`${file}\0${binding.imported}`);
799
+ state.watchFiles.add(file);
800
+ });
801
+ const plain = {
802
+ stylesheets: [],
803
+ packageStylesheets: new Map(),
804
+ components: new Map(),
805
+ modules: new Set(),
806
+ watchFiles: new Set(),
807
+ };
808
+ const inProgress = new Set([canonicalFile(ownerFile)]);
809
+ for (const file of plainModules) {
810
+ const { walk } = walkPlainModule(file, state, inProgress);
811
+ if (walk)
812
+ mergePlainModuleWalk(plain, walk);
813
+ }
814
+ recordDiscoveryOwner(projectRoot, ownerFile, [...plain.modules, ...result.stylesheets, ...plain.stylesheets]);
815
+ for (const watchFile of plain.watchFiles)
816
+ state.watchFiles.add(watchFile);
817
+ for (const [key, component] of plain.components) {
818
+ if (!ownComponents.has(key))
819
+ result.plainModuleComponents.push(component);
241
820
  }
242
- result.watchFiles.push(...factoryState.watchFiles);
821
+ result.plainModuleStylesheets.push(...plain.stylesheets.filter((file) => !result.stylesheets.includes(file)));
822
+ for (const [file, importer] of plain.packageStylesheets)
823
+ if (!packageStylesheets.has(file))
824
+ packageStylesheets.set(file, importer);
825
+ result.packageStylesheets.push(...[...packageStylesheets].map(([file, importer]) => ({ file, importer })));
826
+ result.watchFiles.push(...state.watchFiles);
243
827
  return result;
244
828
  }