@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,260 +0,0 @@
1
- import path from 'node:path';
2
- import { isPathStrictlyInside } from '../utils/path-containment.js';
3
- import { fileSystem } from '@ecopages/file-system';
4
- import { ensureProductionBuildId } from '../build/production-build-id.js';
5
- import { getServerBundleOutputPaths } from '../build/server-bundle-deploy-manifest.js';
6
- import { collectHtmlPageModuleScriptBuildInputs, getPrebuiltHtmlPageModuleScriptUrls, } from '../html-pages/html-page-module-scripts.js';
7
- import { createAppBrowserClientEntryKey } from './app-browser-client-build.js';
8
- import { createPageDependencyInstanceKey, createRouteGraphLookupKey, } from '../route-renderer/orchestration/page-browser-graph/route-instance-key.js';
9
- const APP_BROWSER_CLIENT_MANIFEST_FILENAME = 'browser-client-manifest.json';
10
- function getManifestPath(appConfig) {
11
- return path.join(getServerBundleOutputPaths(appConfig).serverOutdir, APP_BROWSER_CLIENT_MANIFEST_FILENAME);
12
- }
13
- function toProjectPath(rootDir, filePath) {
14
- return path.relative(rootDir, filePath).split(path.sep).join('/');
15
- }
16
- /** Rewrites the file path inside a client dependency key so it survives moving the project root. */
17
- export function normalizeAppBrowserClientEntryKey(rootDir, key) {
18
- try {
19
- const parsedKey = JSON.parse(key);
20
- if (!Array.isArray(parsedKey) || parsedKey.length !== 2 || typeof parsedKey[1] !== 'string')
21
- return key;
22
- const dependency = JSON.parse(parsedKey[1]);
23
- if (!isRecord(dependency) || typeof dependency.filepath !== 'string')
24
- return key;
25
- return JSON.stringify([
26
- parsedKey[0],
27
- JSON.stringify({ ...dependency, filepath: toProjectPath(rootDir, path.resolve(dependency.filepath)) }),
28
- ]);
29
- }
30
- catch {
31
- return key;
32
- }
33
- }
34
- /** Creates a browser client key with a project-relative file path. */
35
- export function createNormalizedAppBrowserClientEntryKey(rootDir, integrationName, dependency) {
36
- return normalizeAppBrowserClientEntryKey(rootDir, createAppBrowserClientEntryKey(integrationName, dependency));
37
- }
38
- function serializeProcessedAsset(rootDir, asset) {
39
- return {
40
- ...asset,
41
- filepath: asset.filepath ? toProjectPath(rootDir, asset.filepath) : undefined,
42
- sourceFilepath: asset.sourceFilepath ? toProjectPath(rootDir, asset.sourceFilepath) : undefined,
43
- bundledSourceFilepaths: asset.bundledSourceFilepaths?.map((filePath) => toProjectPath(rootDir, filePath)),
44
- };
45
- }
46
- function isRecord(value) {
47
- return typeof value === 'object' && value !== null && !Array.isArray(value);
48
- }
49
- function isStringRecord(value) {
50
- return isRecord(value) && Object.values(value).every((item) => typeof item === 'string');
51
- }
52
- function isPageParams(value) {
53
- return (isRecord(value) &&
54
- Object.values(value).every((item) => typeof item === 'string' || (Array.isArray(item) && item.every((part) => typeof part === 'string'))));
55
- }
56
- function isOptionalString(record, key) {
57
- return record[key] === undefined || typeof record[key] === 'string';
58
- }
59
- function isOptionalStringArray(record, key) {
60
- const value = record[key];
61
- return value === undefined || (Array.isArray(value) && value.every((item) => typeof item === 'string'));
62
- }
63
- function isOptionalBoolean(record, key) {
64
- return record[key] === undefined || typeof record[key] === 'boolean';
65
- }
66
- function isProcessedAsset(value) {
67
- if (!isRecord(value) || (value.kind !== 'script' && value.kind !== 'stylesheet'))
68
- return false;
69
- return (isOptionalString(value, 'filepath') &&
70
- isOptionalString(value, 'sourceFilepath') &&
71
- isOptionalString(value, 'srcUrl') &&
72
- isOptionalString(value, 'content') &&
73
- (value.attributes === undefined || isStringRecord(value.attributes)) &&
74
- isOptionalStringArray(value, 'bundledSourceFilepaths'));
75
- }
76
- function isStringArray(value) {
77
- return Array.isArray(value) && value.every((item) => typeof item === 'string');
78
- }
79
- function isProcessedAssetArray(value) {
80
- return Array.isArray(value) && value.every(isProcessedAsset);
81
- }
82
- function isManifestEntry(value) {
83
- if (!isRecord(value) || !isRecord(value.pageClientAssets))
84
- return false;
85
- const pageClientAssets = value.pageClientAssets;
86
- return (typeof value.integrationName === 'string' &&
87
- typeof value.routeFile === 'string' &&
88
- (value.params === undefined || isPageParams(value.params)) &&
89
- isOptionalBoolean(value, 'skipStaticProps') &&
90
- isOptionalBoolean(value, 'isRouteTemplate') &&
91
- typeof value.planKey === 'string' &&
92
- isStringArray(value.groupedDependencyKeys) &&
93
- isStringArray(value.pageClientBuildEntryKeys) &&
94
- isProcessedAssetArray(value.groupedAssets) &&
95
- isProcessedAssetArray(pageClientAssets.processedAssets) &&
96
- isStringArray(pageClientAssets.fallbackPageClientBuildEntryKeys));
97
- }
98
- function isManifest(value) {
99
- return (isRecord(value) &&
100
- value.version === 1 &&
101
- isOptionalString(value, 'buildId') &&
102
- Array.isArray(value.entries) &&
103
- value.entries.every(isManifestEntry) &&
104
- isStringRecord(value.htmlPageModuleScriptUrls) &&
105
- typeof value.htmlPageModuleScriptFingerprint === 'string' &&
106
- isStringArray(value.browserOutputPaths));
107
- }
108
- function serializeEntry(rootDir, plan, instance, params) {
109
- const pageClientAssets = instance.prebuiltPageClientBrowserAssets;
110
- const pageClientBuildEntryKeys = (instance.pageClientBuildEntries ?? [])
111
- .map((entry) => createNormalizedAppBrowserClientEntryKey(rootDir, entry.integrationName, entry.dependency))
112
- .sort();
113
- const fallbackPageClientBuildEntryKeys = (pageClientAssets?.fallbackDependencies ?? []).map((fallback) => createNormalizedAppBrowserClientEntryKey(rootDir, fallback.integrationName, fallback.dependency));
114
- for (const fallbackKey of fallbackPageClientBuildEntryKeys) {
115
- if (!pageClientBuildEntryKeys.includes(fallbackKey)) {
116
- throw new Error(`Could not record a fallback client entry for ${instance.routeFile} in the app browser build manifest.`);
117
- }
118
- }
119
- return {
120
- integrationName: plan.integrationName,
121
- routeFile: toProjectPath(rootDir, instance.routeFile),
122
- params,
123
- skipStaticProps: instance.skipStaticProps,
124
- isRouteTemplate: instance.isRouteTemplate,
125
- planKey: plan.planKey,
126
- groupedDependencyKeys: [
127
- ...new Set((instance.contribution?.dependencies ?? []).map((dependency) => createNormalizedAppBrowserClientEntryKey(rootDir, plan.integrationName, dependency))),
128
- ].sort(),
129
- pageClientBuildEntryKeys,
130
- groupedAssets: (instance.prebuiltGroupedAssets ?? []).map((asset) => serializeProcessedAsset(rootDir, asset)),
131
- pageClientAssets: {
132
- processedAssets: (pageClientAssets?.processedAssets ?? []).map((asset) => serializeProcessedAsset(rootDir, asset)),
133
- fallbackPageClientBuildEntryKeys,
134
- },
135
- };
136
- }
137
- function addAssetOutputFilepaths(filepaths, assets = []) {
138
- for (const asset of assets) {
139
- if (asset.filepath)
140
- filepaths.add(path.resolve(asset.filepath));
141
- }
142
- }
143
- function collectInstanceOutputFilepaths(filepaths, instance) {
144
- addAssetOutputFilepaths(filepaths, instance.prebuiltGroupedAssets);
145
- addAssetOutputFilepaths(filepaths, instance.prebuiltPageClientBrowserAssets?.processedAssets);
146
- }
147
- function addHtmlScriptOutputFilepaths(filepaths, distDir, htmlPageModuleScriptUrls) {
148
- for (const url of Object.values(htmlPageModuleScriptUrls)) {
149
- const relativePath = url.replace(/^\/+/, '').split(/[?#]/, 1)[0];
150
- if (relativePath)
151
- filepaths.add(path.resolve(distDir, relativePath));
152
- }
153
- }
154
- function collectOutputFilepaths(appConfig, plans, htmlPageModuleScriptUrls, browserOutputPaths) {
155
- const filepaths = new Set(browserOutputPaths.map((filepath) => path.resolve(filepath)));
156
- for (const plan of plans) {
157
- for (const instance of plan.instances)
158
- collectInstanceOutputFilepaths(filepaths, instance);
159
- }
160
- addHtmlScriptOutputFilepaths(filepaths, appConfig.absolutePaths.distDir, htmlPageModuleScriptUrls);
161
- return filepaths;
162
- }
163
- /** Persists the browser outputs built for production routes so `ecopages start` can reuse them. */
164
- export async function writeAppBrowserClientManifest(appConfig, plans, routeInstances, browserBuild) {
165
- const paramsByRouteKey = new Map(routeInstances.map((instance) => [
166
- JSON.stringify([
167
- createRouteGraphLookupKey(instance.routeFile, createPageDependencyInstanceKey({ params: instance.params })),
168
- instance.skipStaticProps ?? false,
169
- instance.isRouteTemplate ?? false,
170
- ]),
171
- instance.params,
172
- ]));
173
- const entries = plans.flatMap((plan) => plan.instances.map((instance) => {
174
- const routeKey = JSON.stringify([
175
- createRouteGraphLookupKey(instance.routeFile, instance.dependencyInstanceKey),
176
- instance.skipStaticProps ?? false,
177
- instance.isRouteTemplate ?? false,
178
- ]);
179
- if (!paramsByRouteKey.has(routeKey)) {
180
- throw new Error(`Missing route params for app browser client entry ${instance.routeFile}`);
181
- }
182
- return serializeEntry(appConfig.rootDir, plan, instance, paramsByRouteKey.get(routeKey));
183
- }));
184
- const htmlPageModuleScriptUrls = Object.fromEntries([...(await getPrebuiltHtmlPageModuleScriptUrls(appConfig))].map(([filePath, url]) => [
185
- toProjectPath(appConfig.rootDir, filePath),
186
- url,
187
- ]));
188
- const htmlBuildInputs = collectHtmlPageModuleScriptBuildInputs(appConfig);
189
- const manifest = {
190
- version: 1,
191
- buildId: ensureProductionBuildId(appConfig),
192
- entries,
193
- htmlPageModuleScriptUrls,
194
- htmlPageModuleScriptFingerprint: htmlBuildInputs.fingerprint,
195
- browserOutputPaths: [
196
- ...collectOutputFilepaths(appConfig, plans, htmlPageModuleScriptUrls, browserBuild.outputPaths),
197
- ]
198
- .map((filepath) => toProjectPath(appConfig.rootDir, filepath))
199
- .sort(),
200
- };
201
- const manifestPath = getManifestPath(appConfig);
202
- fileSystem.ensureDir(path.dirname(manifestPath));
203
- fileSystem.write(manifestPath, `${JSON.stringify(manifest, null, '\t')}\n`);
204
- }
205
- export function clearAppBrowserClientManifest(appConfig) {
206
- fileSystem.remove(getManifestPath(appConfig));
207
- }
208
- /** Reads the deployable browser build outputs written by `ecopages build`. */
209
- export function readAppBrowserClientManifest(appConfig) {
210
- const manifestPath = getManifestPath(appConfig);
211
- if (!fileSystem.exists(manifestPath))
212
- return undefined;
213
- try {
214
- const parsed = JSON.parse(fileSystem.readFileSync(manifestPath).toString());
215
- if (!isManifest(parsed))
216
- throw new Error('unsupported manifest shape');
217
- return parsed;
218
- }
219
- catch (error) {
220
- const detail = error instanceof Error ? error.message : String(error);
221
- throw new Error(`Could not read ${path.relative(appConfig.rootDir, manifestPath)} (${detail}). Run \`ecopages build\` again.`, { cause: error });
222
- }
223
- }
224
- /** Ensures every HTML module-script URL in the manifest points to a file in dist. */
225
- export function assertAppBrowserClientManifestHtmlOutputsExist(appConfig, htmlPageModuleScriptUrls) {
226
- for (const [sourcePath, url] of Object.entries(htmlPageModuleScriptUrls)) {
227
- const outputPath = path.resolve(appConfig.absolutePaths.distDir, url.replace(/^\/+/, '').split(/[?#]/, 1)[0] ?? '');
228
- if (!isPathStrictlyInside(outputPath, appConfig.absolutePaths.distDir) || !fileSystem.exists(outputPath)) {
229
- throw new Error(`The app browser build manifest references missing HTML module-script output for ${sourcePath}. Run \`ecopages build\` again.`);
230
- }
231
- }
232
- }
233
- /** Ensures every browser output emitted by the app build still exists under dist. */
234
- export function assertAppBrowserClientOutputsExist(appConfig, relativeOutputPaths) {
235
- for (const relativeOutputPath of relativeOutputPaths) {
236
- const outputPath = path.resolve(appConfig.rootDir, relativeOutputPath);
237
- if (!isPathStrictlyInside(outputPath, appConfig.absolutePaths.distDir) || !fileSystem.exists(outputPath)) {
238
- throw new Error(`The app browser build manifest references missing output ${relativeOutputPath}. Run \`ecopages build\` again.`);
239
- }
240
- }
241
- }
242
- /** Resolves the project-relative asset paths in a build manifest for the current runtime. */
243
- export function restoreAppBrowserClientAssets(appConfig, assets) {
244
- return assets.map((asset) => {
245
- const filepath = asset.filepath ? path.resolve(appConfig.rootDir, asset.filepath) : undefined;
246
- if (filepath && !fileSystem.exists(filepath)) {
247
- throw new Error(`The app browser build manifest references missing output ${path.relative(appConfig.rootDir, filepath)}. Run \`ecopages build\` again.`);
248
- }
249
- return {
250
- ...asset,
251
- filepath,
252
- sourceFilepath: asset.sourceFilepath ? path.resolve(appConfig.rootDir, asset.sourceFilepath) : undefined,
253
- bundledSourceFilepaths: asset.bundledSourceFilepaths?.map((filePath) => path.resolve(appConfig.rootDir, filePath)),
254
- };
255
- });
256
- }
257
- /** Resolves an app-relative file path stored in the build manifest. */
258
- export function resolveAppBrowserClientManifestPath(appConfig, filePath) {
259
- return path.resolve(appConfig.rootDir, filePath);
260
- }
@@ -1,2 +0,0 @@
1
- import type { AssetPackageRole } from './assets.types.js';
2
- export declare function isBrowserRuntimeAssetRole(role: AssetPackageRole | undefined): boolean;
@@ -1,3 +0,0 @@
1
- export function isBrowserRuntimeAssetRole(role) {
2
- return role === 'runtime' || role === 'page-script';
3
- }
@@ -1,58 +0,0 @@
1
- import type { EcoBuildPlugin } from '../../build/contracts/build-types.js';
2
- import type { AssetDefinition } from './assets.types.js';
3
- import { type BrowserRuntimeEntryModuleConfig } from './browser-runtime-entry.factory.js';
4
- export declare const BROWSER_RUNTIME_SCRIPT_ATTRIBUTES: {
5
- readonly type: "module";
6
- readonly defer: "";
7
- };
8
- /**
9
- * Builds the public vendor URL used for generated browser runtime assets.
10
- */
11
- export declare function buildBrowserRuntimeAssetUrl(fileName: string): string;
12
- /**
13
- * Declares a browser runtime script asset backed by one importable module.
14
- *
15
- * @remarks
16
- * Runtime assets are emitted as excluded head scripts because integrations often
17
- * need the bundler output and specifier registration without injecting the raw
18
- * asset directly into HTML during dependency resolution.
19
- */
20
- export declare function createBrowserRuntimeScriptAsset(options: {
21
- importPath: string;
22
- name: string;
23
- fileName: string;
24
- bundleOptions?: {
25
- define?: Record<string, string>;
26
- minify?: boolean;
27
- external?: string[];
28
- excludeAppBuildPlugins?: string[];
29
- naming?: string;
30
- plugins?: EcoBuildPlugin[];
31
- };
32
- attributes?: Record<string, string>;
33
- }): AssetDefinition;
34
- /**
35
- * Creates a browser runtime asset from a generated re-export entry module.
36
- *
37
- * @remarks
38
- * This is the shared "module list -> generated entry file -> runtime asset"
39
- * path used by integrations that need browser-side runtime bundles without
40
- * owning bespoke entry-file generation logic.
41
- */
42
- export declare function createBrowserRuntimeModuleAsset(options: {
43
- modules: BrowserRuntimeEntryModuleConfig[];
44
- name: string;
45
- fileName: string;
46
- cacheDirName?: string;
47
- rootDir?: string;
48
- workDir?: string;
49
- bundleOptions?: {
50
- define?: Record<string, string>;
51
- minify?: boolean;
52
- external?: string[];
53
- excludeAppBuildPlugins?: string[];
54
- naming?: string;
55
- plugins?: EcoBuildPlugin[];
56
- };
57
- attributes?: Record<string, string>;
58
- }): AssetDefinition;
@@ -1,61 +0,0 @@
1
- import { AssetFactory } from './asset.factory.js';
2
- import { createBrowserRuntimeEntryModule, } from './browser-runtime-entry.factory.js';
3
- export const BROWSER_RUNTIME_SCRIPT_ATTRIBUTES = {
4
- type: 'module',
5
- defer: '',
6
- };
7
- /**
8
- * Builds the public vendor URL used for generated browser runtime assets.
9
- */
10
- export function buildBrowserRuntimeAssetUrl(fileName) {
11
- return `/${AssetFactory.RESOLVED_ASSETS_VENDORS_DIR}/${fileName}`;
12
- }
13
- /**
14
- * Declares a browser runtime script asset backed by one importable module.
15
- *
16
- * @remarks
17
- * Runtime assets are emitted as excluded head scripts because integrations often
18
- * need the bundler output and specifier registration without injecting the raw
19
- * asset directly into HTML during dependency resolution.
20
- */
21
- export function createBrowserRuntimeScriptAsset(options) {
22
- return AssetFactory.createNodeModuleScript({
23
- position: 'head',
24
- importPath: options.importPath,
25
- name: options.name,
26
- packageRole: 'runtime',
27
- excludeFromHtml: true,
28
- bundleOptions: {
29
- naming: options.fileName,
30
- ...options.bundleOptions,
31
- },
32
- attributes: {
33
- ...BROWSER_RUNTIME_SCRIPT_ATTRIBUTES,
34
- ...(options.attributes ?? {}),
35
- },
36
- });
37
- }
38
- /**
39
- * Creates a browser runtime asset from a generated re-export entry module.
40
- *
41
- * @remarks
42
- * This is the shared "module list -> generated entry file -> runtime asset"
43
- * path used by integrations that need browser-side runtime bundles without
44
- * owning bespoke entry-file generation logic.
45
- */
46
- export function createBrowserRuntimeModuleAsset(options) {
47
- const importPath = createBrowserRuntimeEntryModule({
48
- modules: options.modules,
49
- fileName: `${options.name}-entry.mjs`,
50
- rootDir: options.rootDir,
51
- workDir: options.workDir,
52
- cacheDirName: options.cacheDirName,
53
- });
54
- return createBrowserRuntimeScriptAsset({
55
- importPath,
56
- name: options.name,
57
- fileName: options.fileName,
58
- bundleOptions: options.bundleOptions,
59
- attributes: options.attributes,
60
- });
61
- }
@@ -1,79 +0,0 @@
1
- import type { createRequire } from 'node:module';
2
- export type BrowserRuntimeDefaultExportPolicy = 'emit-default' | 'skip-default';
3
- type RequireFromRoot = ReturnType<typeof createRequire>;
4
- /**
5
- * Resolves a package specifier through Node's ESM import conditions from the app root.
6
- *
7
- * @remarks
8
- * The resolver is rooted at the application directory so package lookup cannot
9
- * accidentally use a dependency with the same name from the framework's own
10
- * installation. The condition order matches the generated vendor import: Node
11
- * compatibility first, then ESM import, then the package default.
12
- */
13
- export declare function resolvePackageEsmEntryPath(specifier: string, rootDir: string): string | undefined;
14
- /**
15
- * Resolves a browser runtime specifier to the absolute file that the generated
16
- * vendor entry will import, when that import is a path.
17
- *
18
- * @remarks
19
- * `node:` specifiers have no file path. `file:` URLs are converted to paths.
20
- */
21
- export declare function resolveBrowserRuntimeEntryPath(options: {
22
- specifier: string;
23
- requireFromRoot: RequireFromRoot;
24
- rootDir: string;
25
- }): string | undefined;
26
- /**
27
- * Builds a relative import path from a generated runtime entry file to a resolved module path.
28
- */
29
- export declare function toRelativeEntryImport(entryDir: string, resolvedPath: string): string;
30
- /**
31
- * Resolves a browser runtime entry import to an ESM file path when possible.
32
- *
33
- * @remarks
34
- * Browser vendor entries resolve through ESM import conditions first. A package
35
- * root without `exports` may instead select its legacy `module` field; CJS
36
- * resolution is the final compatibility fallback.
37
- */
38
- export declare function resolveBrowserRuntimeEntryImport(options: {
39
- specifier: string;
40
- requireFromRoot: RequireFromRoot;
41
- entryDir: string;
42
- rootDir: string;
43
- }): string;
44
- /**
45
- * Decides whether a generated runtime entry should re-export a default binding.
46
- *
47
- * @remarks
48
- * ESM-only packages such as `@tanstack/react-query` expose named exports only.
49
- * Legacy CJS packages such as `react` assign `module.exports` directly and have
50
- * no `.default` under `require()`, but still need a default re-export for
51
- * `import React from 'react'` in browser bundles.
52
- *
53
- * ESM source inspection is a best-effort fast path; when it is inconclusive the
54
- * policy falls back to the shape returned by `require()`.
55
- */
56
- export declare function inferBrowserRuntimeDefaultExportPolicy(options: {
57
- specifier: string;
58
- requireFromRoot: RequireFromRoot;
59
- rootDir: string;
60
- }): BrowserRuntimeDefaultExportPolicy;
61
- /**
62
- * Returns true when the resolved vendor file is an ESM module that Rolldown can
63
- * re-export with `export *`.
64
- *
65
- * @remarks
66
- * React's published "import" files are still CJS wrappers. `export *` from those
67
- * files does not emit named ESM bindings such as `jsx`.
68
- */
69
- export declare function browserRuntimeEntryHasEsmExports(entryPath: string | undefined): boolean;
70
- /**
71
- * Reads enumerable CJS exports from the same file the generated entry imports.
72
- *
73
- * @remarks
74
- * Used only when {@link browserRuntimeEntryHasEsmExports} is false. ESM entries
75
- * must not harvest names from `require()`, which copies class statics that are
76
- * not ESM named exports.
77
- */
78
- export declare function listBrowserRuntimeCjsExportNames(moduleId: string, requireFromRoot: RequireFromRoot): string[];
79
- export {};
@@ -1,200 +0,0 @@
1
- import path from 'node:path';
2
- import { fileSystem } from '@ecopages/file-system';
3
- import { fileURLToPath } from 'node:url';
4
- import { ResolverFactory } from 'oxc-resolver';
5
- import { isBarePackageImportSpecifier } from '../../plugins/tsconfig-import-resolver.js';
6
- import { toPackageRootSpecifier } from '../../plugins/package-specifier.js';
7
- const esmEntryResolvers = new Map();
8
- function getEsmEntryResolver(rootDir) {
9
- const normalizedRoot = path.resolve(rootDir);
10
- const cached = esmEntryResolvers.get(normalizedRoot);
11
- if (cached) {
12
- return cached;
13
- }
14
- const resolver = new ResolverFactory({ conditionNames: ['node', 'import', 'default'] });
15
- esmEntryResolvers.set(normalizedRoot, resolver);
16
- return resolver;
17
- }
18
- /**
19
- * Resolves a package specifier through Node's ESM import conditions from the app root.
20
- *
21
- * @remarks
22
- * The resolver is rooted at the application directory so package lookup cannot
23
- * accidentally use a dependency with the same name from the framework's own
24
- * installation. The condition order matches the generated vendor import: Node
25
- * compatibility first, then ESM import, then the package default.
26
- */
27
- export function resolvePackageEsmEntryPath(specifier, rootDir) {
28
- try {
29
- const result = getEsmEntryResolver(rootDir).sync(path.resolve(rootDir), specifier);
30
- return result.path;
31
- }
32
- catch {
33
- return undefined;
34
- }
35
- }
36
- function resolveLegacyPackageModuleEntry(options) {
37
- if (!isBarePackageImportSpecifier(options.specifier, options.rootDir)) {
38
- return undefined;
39
- }
40
- const packageRoot = toPackageRootSpecifier(options.specifier);
41
- if (options.specifier !== packageRoot) {
42
- return undefined;
43
- }
44
- try {
45
- const packageJsonPath = options.requireFromRoot.resolve(`${packageRoot}/package.json`);
46
- const packageJson = JSON.parse(fileSystem.readFileSync(packageJsonPath));
47
- if (packageJson.exports !== undefined || typeof packageJson.module !== 'string') {
48
- return undefined;
49
- }
50
- const modulePath = path.resolve(path.dirname(packageJsonPath), packageJson.module);
51
- return fileSystem.exists(modulePath) ? modulePath : undefined;
52
- }
53
- catch {
54
- return undefined;
55
- }
56
- }
57
- const ESM_DEFAULT_EXPORT = /\bexport\s+default\b/;
58
- const ESM_NAMED_EXPORT = /\bexport\s+(?:[\w*{]|const|let|var|function|class)/;
59
- const EXPORTABLE_BINDING_NAME = /^[$A-Z_a-z][$\w]*$/;
60
- /**
61
- * Resolves a browser runtime specifier to the absolute file that the generated
62
- * vendor entry will import, when that import is a path.
63
- *
64
- * @remarks
65
- * `node:` specifiers have no file path. `file:` URLs are converted to paths.
66
- */
67
- export function resolveBrowserRuntimeEntryPath(options) {
68
- const { specifier, requireFromRoot, rootDir } = options;
69
- if (specifier.startsWith('node:')) {
70
- return undefined;
71
- }
72
- if (specifier.startsWith('file:')) {
73
- return fileURLToPath(specifier);
74
- }
75
- if (specifier.startsWith('.')) {
76
- return requireFromRoot.resolve(specifier);
77
- }
78
- const legacyModulePath = resolveLegacyPackageModuleEntry({ specifier, requireFromRoot, rootDir });
79
- if (legacyModulePath) {
80
- return legacyModulePath;
81
- }
82
- const esmResolvedPath = isBarePackageImportSpecifier(specifier, rootDir)
83
- ? resolvePackageEsmEntryPath(specifier, rootDir)
84
- : undefined;
85
- if (esmResolvedPath) {
86
- return esmResolvedPath;
87
- }
88
- try {
89
- const resolvedPath = requireFromRoot.resolve(specifier);
90
- const esmSibling = resolvedPath.endsWith('.cjs')
91
- ? `${resolvedPath.slice(0, -4)}.js`
92
- : resolvedPath.endsWith('.cts')
93
- ? `${resolvedPath.slice(0, -4)}.ts`
94
- : undefined;
95
- return esmSibling && fileSystem.exists(esmSibling) ? esmSibling : resolvedPath;
96
- }
97
- catch {
98
- return undefined;
99
- }
100
- }
101
- /**
102
- * Builds a relative import path from a generated runtime entry file to a resolved module path.
103
- */
104
- export function toRelativeEntryImport(entryDir, resolvedPath) {
105
- let relativePath = path.relative(entryDir, resolvedPath).replace(/\\/g, '/');
106
- if (!relativePath.startsWith('.')) {
107
- relativePath = `./${relativePath}`;
108
- }
109
- return relativePath;
110
- }
111
- /**
112
- * Resolves a browser runtime entry import to an ESM file path when possible.
113
- *
114
- * @remarks
115
- * Browser vendor entries resolve through ESM import conditions first. A package
116
- * root without `exports` may instead select its legacy `module` field; CJS
117
- * resolution is the final compatibility fallback.
118
- */
119
- export function resolveBrowserRuntimeEntryImport(options) {
120
- const { specifier, requireFromRoot, entryDir, rootDir } = options;
121
- if (specifier.startsWith('node:') || specifier.startsWith('file:')) {
122
- return specifier;
123
- }
124
- const entryPath = resolveBrowserRuntimeEntryPath({ specifier, requireFromRoot, rootDir });
125
- if (!entryPath) {
126
- throw new Error(`Unable to resolve browser runtime entry for "${specifier}" from "${rootDir}"`);
127
- }
128
- return toRelativeEntryImport(entryDir, entryPath);
129
- }
130
- /**
131
- * Decides whether a generated runtime entry should re-export a default binding.
132
- *
133
- * @remarks
134
- * ESM-only packages such as `@tanstack/react-query` expose named exports only.
135
- * Legacy CJS packages such as `react` assign `module.exports` directly and have
136
- * no `.default` under `require()`, but still need a default re-export for
137
- * `import React from 'react'` in browser bundles.
138
- *
139
- * ESM source inspection is a best-effort fast path; when it is inconclusive the
140
- * policy falls back to the shape returned by `require()`.
141
- */
142
- export function inferBrowserRuntimeDefaultExportPolicy(options) {
143
- const { specifier, requireFromRoot, rootDir } = options;
144
- const entryPath = resolveBrowserRuntimeEntryPath({ specifier, requireFromRoot, rootDir });
145
- if (entryPath && fileSystem.exists(entryPath)) {
146
- const source = fileSystem.readFileSync(entryPath);
147
- if (ESM_DEFAULT_EXPORT.test(source)) {
148
- return 'emit-default';
149
- }
150
- if (ESM_NAMED_EXPORT.test(source)) {
151
- return 'skip-default';
152
- }
153
- }
154
- try {
155
- const moduleExports = requireFromRoot(specifier);
156
- if (moduleExports.default !== undefined) {
157
- return 'emit-default';
158
- }
159
- return moduleExports.__esModule === true ? 'skip-default' : 'emit-default';
160
- }
161
- catch {
162
- return 'skip-default';
163
- }
164
- }
165
- /**
166
- * Returns true when the resolved vendor file is an ESM module that Rolldown can
167
- * re-export with `export *`.
168
- *
169
- * @remarks
170
- * React's published "import" files are still CJS wrappers. `export *` from those
171
- * files does not emit named ESM bindings such as `jsx`.
172
- */
173
- export function browserRuntimeEntryHasEsmExports(entryPath) {
174
- if (!entryPath || !fileSystem.exists(entryPath)) {
175
- return true;
176
- }
177
- const source = fileSystem.readFileSync(entryPath);
178
- return ESM_DEFAULT_EXPORT.test(source) || ESM_NAMED_EXPORT.test(source);
179
- }
180
- /**
181
- * Reads enumerable CJS exports from the same file the generated entry imports.
182
- *
183
- * @remarks
184
- * Used only when {@link browserRuntimeEntryHasEsmExports} is false. ESM entries
185
- * must not harvest names from `require()`, which copies class statics that are
186
- * not ESM named exports.
187
- */
188
- export function listBrowserRuntimeCjsExportNames(moduleId, requireFromRoot) {
189
- let moduleExports;
190
- try {
191
- moduleExports = requireFromRoot(moduleId);
192
- }
193
- catch {
194
- return [];
195
- }
196
- return Object.keys(moduleExports)
197
- .filter((name) => name !== '__esModule' && name !== 'default')
198
- .filter((name) => EXPORTABLE_BINDING_NAME.test(name))
199
- .sort();
200
- }