@ecopages/core 0.2.0-alpha.7 → 0.2.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (354) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/package.json +212 -92
  3. package/src/adapters/abstract/application-adapter.d.ts +168 -0
  4. package/src/adapters/abstract/application-adapter.js +109 -0
  5. package/src/adapters/abstract/router-adapter.d.ts +26 -0
  6. package/src/adapters/abstract/router-adapter.js +5 -0
  7. package/src/adapters/abstract/server-adapter.d.ts +69 -0
  8. package/src/adapters/abstract/server-adapter.js +15 -0
  9. package/src/adapters/bun/client-bridge.d.ts +34 -0
  10. package/src/adapters/bun/client-bridge.js +48 -0
  11. package/src/adapters/bun/create-app.d.ts +60 -0
  12. package/src/adapters/bun/create-app.js +117 -0
  13. package/src/adapters/bun/hmr-manager.d.ts +143 -0
  14. package/src/adapters/bun/hmr-manager.js +334 -0
  15. package/src/adapters/bun/index.d.ts +2 -0
  16. package/src/adapters/bun/index.js +8 -0
  17. package/src/adapters/bun/server-adapter.d.ts +155 -0
  18. package/src/adapters/bun/server-adapter.js +373 -0
  19. package/src/adapters/bun/server-lifecycle.d.ts +63 -0
  20. package/src/adapters/bun/server-lifecycle.js +92 -0
  21. package/src/adapters/index.d.ts +6 -0
  22. package/src/adapters/index.js +14 -0
  23. package/src/adapters/node/bootstrap-dependency-resolver.d.ts +44 -0
  24. package/src/adapters/node/bootstrap-dependency-resolver.js +172 -0
  25. package/src/adapters/node/create-app.d.ts +21 -0
  26. package/src/adapters/node/create-app.js +143 -0
  27. package/src/adapters/node/index.d.ts +6 -0
  28. package/src/adapters/node/index.js +11 -0
  29. package/src/adapters/node/node-client-bridge.d.ts +26 -0
  30. package/src/adapters/node/node-client-bridge.js +66 -0
  31. package/src/adapters/node/node-hmr-manager.d.ts +133 -0
  32. package/src/adapters/node/node-hmr-manager.js +312 -0
  33. package/src/adapters/node/runtime-adapter.d.ts +46 -0
  34. package/src/adapters/node/runtime-adapter.js +306 -0
  35. package/src/adapters/node/server-adapter.d.ts +161 -0
  36. package/src/adapters/node/server-adapter.js +358 -0
  37. package/src/adapters/node/static-content-server.d.ts +60 -0
  38. package/src/adapters/node/static-content-server.js +194 -0
  39. package/src/adapters/node/write-runtime-manifest.d.ts +26 -0
  40. package/src/adapters/node/write-runtime-manifest.js +12 -0
  41. package/src/adapters/shared/api-response.d.ts +52 -0
  42. package/src/adapters/shared/api-response.js +96 -0
  43. package/src/adapters/shared/application-adapter.d.ts +18 -0
  44. package/src/adapters/shared/application-adapter.js +90 -0
  45. package/src/adapters/shared/define-api-handler.d.ts +25 -0
  46. package/src/adapters/shared/define-api-handler.js +15 -0
  47. package/src/adapters/shared/explicit-static-route-matcher.d.ts +38 -0
  48. package/src/adapters/shared/explicit-static-route-matcher.js +103 -0
  49. package/src/adapters/shared/file-route-middleware-pipeline.d.ts +65 -0
  50. package/src/adapters/shared/file-route-middleware-pipeline.js +99 -0
  51. package/src/adapters/shared/fs-server-response-factory.d.ts +19 -0
  52. package/src/adapters/shared/fs-server-response-factory.js +97 -0
  53. package/src/adapters/shared/fs-server-response-matcher.d.ts +75 -0
  54. package/src/adapters/shared/fs-server-response-matcher.js +160 -0
  55. package/src/adapters/shared/hmr-entrypoint-registrar.d.ts +55 -0
  56. package/src/adapters/shared/hmr-entrypoint-registrar.js +87 -0
  57. package/src/adapters/shared/hmr-html-response.d.ts +22 -0
  58. package/src/adapters/shared/hmr-html-response.js +32 -0
  59. package/src/adapters/shared/render-context.d.ts +14 -0
  60. package/src/adapters/shared/render-context.js +70 -0
  61. package/src/adapters/shared/runtime-bootstrap.d.ts +38 -0
  62. package/src/adapters/shared/runtime-bootstrap.js +43 -0
  63. package/src/adapters/shared/server-adapter.d.ts +97 -0
  64. package/src/adapters/shared/server-adapter.js +386 -0
  65. package/src/adapters/shared/server-route-handler.d.ts +89 -0
  66. package/src/adapters/shared/server-route-handler.js +111 -0
  67. package/src/adapters/shared/server-static-builder.d.ts +70 -0
  68. package/src/adapters/shared/server-static-builder.js +99 -0
  69. package/src/build/build-adapter.d.ts +186 -0
  70. package/src/build/build-adapter.js +168 -0
  71. package/src/build/build-manifest.d.ts +27 -0
  72. package/src/build/build-manifest.js +30 -0
  73. package/src/build/build-types.d.ts +57 -0
  74. package/src/build/build-types.js +0 -0
  75. package/src/build/dev-build-coordinator.d.ts +74 -0
  76. package/src/build/dev-build-coordinator.js +161 -0
  77. package/src/build/esbuild-build-adapter.d.ts +72 -0
  78. package/src/build/esbuild-build-adapter.js +422 -0
  79. package/src/build/runtime-build-executor.d.ts +13 -0
  80. package/src/build/runtime-build-executor.js +20 -0
  81. package/src/build/runtime-specifier-alias-plugin.d.ts +15 -0
  82. package/src/build/runtime-specifier-alias-plugin.js +31 -0
  83. package/src/config/config-builder.d.ts +238 -0
  84. package/src/config/config-builder.js +565 -0
  85. package/src/constants.d.ts +45 -0
  86. package/src/constants.js +25 -0
  87. package/src/create-app.d.ts +17 -0
  88. package/src/create-app.js +66 -0
  89. package/src/dev/sc-server.d.ts +30 -0
  90. package/src/dev/sc-server.js +111 -0
  91. package/src/eco/component-render-context.d.ts +105 -0
  92. package/src/eco/component-render-context.js +87 -0
  93. package/src/eco/eco.d.ts +9 -0
  94. package/src/eco/eco.js +114 -0
  95. package/src/eco/eco.types.d.ts +178 -0
  96. package/src/eco/eco.types.js +0 -0
  97. package/src/eco/eco.utils.d.ts +40 -0
  98. package/src/eco/eco.utils.js +40 -0
  99. package/src/eco/global-injector-map.d.ts +16 -0
  100. package/src/eco/global-injector-map.js +80 -0
  101. package/src/eco/lazy-injector-map.d.ts +8 -0
  102. package/src/eco/lazy-injector-map.js +70 -0
  103. package/src/eco/module-dependencies.d.ts +18 -0
  104. package/src/eco/module-dependencies.js +49 -0
  105. package/src/errors/http-error.d.ts +31 -0
  106. package/src/errors/http-error.js +50 -0
  107. package/src/errors/index.d.ts +2 -0
  108. package/src/errors/index.js +4 -0
  109. package/src/errors/locals-access-error.d.ts +4 -0
  110. package/src/errors/locals-access-error.js +9 -0
  111. package/src/global/app-logger.d.ts +2 -0
  112. package/src/global/app-logger.js +6 -0
  113. package/src/hmr/client/hmr-runtime.d.ts +5 -0
  114. package/src/hmr/client/hmr-runtime.js +109 -0
  115. package/src/hmr/hmr-strategy.d.ts +159 -0
  116. package/src/hmr/hmr-strategy.js +29 -0
  117. package/src/hmr/hmr.postcss.test.e2e.d.ts +1 -0
  118. package/src/hmr/hmr.postcss.test.e2e.js +31 -0
  119. package/src/hmr/hmr.test.e2e.d.ts +1 -0
  120. package/src/hmr/hmr.test.e2e.js +43 -0
  121. package/src/hmr/strategies/default-hmr-strategy.d.ts +43 -0
  122. package/src/hmr/strategies/default-hmr-strategy.js +34 -0
  123. package/src/hmr/strategies/js-hmr-strategy.d.ts +139 -0
  124. package/src/hmr/strategies/js-hmr-strategy.js +178 -0
  125. package/src/index.browser.d.ts +3 -0
  126. package/src/index.browser.js +4 -0
  127. package/src/index.d.ts +5 -0
  128. package/src/index.js +10 -0
  129. package/src/integrations/ghtml/ghtml-renderer.d.ts +15 -0
  130. package/src/integrations/ghtml/ghtml-renderer.js +62 -0
  131. package/src/integrations/ghtml/ghtml.plugin.d.ts +20 -0
  132. package/src/integrations/ghtml/ghtml.plugin.js +21 -0
  133. package/src/internal-types.d.ts +221 -0
  134. package/src/internal-types.js +0 -0
  135. package/src/plugins/alias-resolver-plugin.d.ts +2 -0
  136. package/src/plugins/alias-resolver-plugin.js +53 -0
  137. package/src/plugins/eco-component-meta-plugin.d.ts +97 -0
  138. package/src/plugins/eco-component-meta-plugin.js +157 -0
  139. package/src/plugins/integration-plugin.d.ts +136 -0
  140. package/src/plugins/integration-plugin.js +133 -0
  141. package/src/plugins/processor.d.ts +95 -0
  142. package/src/plugins/processor.js +136 -0
  143. package/src/plugins/runtime-capability.d.ts +9 -0
  144. package/src/plugins/runtime-capability.js +0 -0
  145. package/src/public-types.d.ts +1149 -0
  146. package/src/public-types.js +0 -0
  147. package/src/route-renderer/component-graph/component-graph-executor.d.ts +32 -0
  148. package/src/route-renderer/component-graph/component-graph-executor.js +31 -0
  149. package/src/route-renderer/component-graph/component-graph.d.ts +42 -0
  150. package/src/route-renderer/component-graph/component-graph.js +72 -0
  151. package/src/route-renderer/component-graph/component-marker.d.ts +52 -0
  152. package/src/route-renderer/component-graph/component-marker.js +46 -0
  153. package/src/route-renderer/component-graph/component-reference.d.ts +10 -0
  154. package/src/route-renderer/component-graph/component-reference.js +19 -0
  155. package/src/route-renderer/component-graph/marker-graph-resolver.d.ts +77 -0
  156. package/src/route-renderer/component-graph/marker-graph-resolver.js +95 -0
  157. package/src/route-renderer/orchestration/integration-renderer.d.ts +372 -0
  158. package/src/route-renderer/orchestration/integration-renderer.js +589 -0
  159. package/src/route-renderer/orchestration/render-execution.service.d.ts +103 -0
  160. package/src/route-renderer/orchestration/render-execution.service.js +121 -0
  161. package/src/route-renderer/orchestration/render-preparation.service.d.ts +121 -0
  162. package/src/route-renderer/orchestration/render-preparation.service.js +332 -0
  163. package/src/route-renderer/page-loading/dependency-resolver.d.ts +35 -0
  164. package/src/route-renderer/page-loading/dependency-resolver.js +442 -0
  165. package/src/route-renderer/page-loading/page-module-loader.d.ts +87 -0
  166. package/src/route-renderer/page-loading/page-module-loader.js +124 -0
  167. package/src/route-renderer/route-renderer.d.ts +61 -0
  168. package/src/route-renderer/route-renderer.js +87 -0
  169. package/src/router/client/link-intent.js +34 -0
  170. package/src/router/client/link-intent.test.browser.d.ts +1 -0
  171. package/src/router/client/link-intent.test.browser.js +43 -0
  172. package/src/router/client/navigation-coordinator.d.ts +149 -0
  173. package/src/router/client/navigation-coordinator.js +215 -0
  174. package/src/router/server/fs-router-scanner.d.ts +41 -0
  175. package/src/router/server/fs-router-scanner.js +156 -0
  176. package/src/router/server/fs-router.d.ts +26 -0
  177. package/src/router/server/fs-router.js +100 -0
  178. package/src/services/assets/asset-processing-service/asset-processing.service.d.ts +120 -0
  179. package/src/services/assets/asset-processing-service/asset-processing.service.js +331 -0
  180. package/src/services/assets/asset-processing-service/asset.factory.d.ts +17 -0
  181. package/src/services/assets/asset-processing-service/asset.factory.js +82 -0
  182. package/src/services/assets/asset-processing-service/assets.types.d.ts +89 -0
  183. package/src/services/assets/asset-processing-service/assets.types.js +0 -0
  184. package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.d.ts +55 -0
  185. package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.js +48 -0
  186. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +20 -0
  187. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +41 -0
  188. package/src/services/assets/asset-processing-service/index.d.ts +5 -0
  189. package/src/services/assets/asset-processing-service/index.js +5 -0
  190. package/src/services/assets/asset-processing-service/processor.interface.d.ts +22 -0
  191. package/src/services/assets/asset-processing-service/processor.interface.js +6 -0
  192. package/src/services/assets/asset-processing-service/processor.registry.d.ts +8 -0
  193. package/src/services/assets/asset-processing-service/processor.registry.js +15 -0
  194. package/src/services/assets/asset-processing-service/processors/base/base-processor.d.ts +24 -0
  195. package/src/services/assets/asset-processing-service/processors/base/base-processor.js +64 -0
  196. package/src/services/assets/asset-processing-service/processors/base/base-script-processor.d.ts +17 -0
  197. package/src/services/assets/asset-processing-service/processors/base/base-script-processor.js +72 -0
  198. package/src/services/assets/asset-processing-service/processors/index.d.ts +5 -0
  199. package/src/services/assets/asset-processing-service/processors/index.js +5 -0
  200. package/src/services/assets/asset-processing-service/processors/script/content-script.processor.d.ts +5 -0
  201. package/src/services/assets/asset-processing-service/processors/script/content-script.processor.js +57 -0
  202. package/src/services/assets/asset-processing-service/processors/script/file-script.processor.d.ts +8 -0
  203. package/src/services/assets/asset-processing-service/processors/script/file-script.processor.js +76 -0
  204. package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.d.ts +7 -0
  205. package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.js +75 -0
  206. package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.d.ts +5 -0
  207. package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +25 -0
  208. package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts +9 -0
  209. package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +66 -0
  210. package/src/services/assets/browser-bundle.service.d.ts +32 -0
  211. package/src/services/assets/browser-bundle.service.js +33 -0
  212. package/src/services/cache/cache.types.d.ts +107 -0
  213. package/src/services/cache/cache.types.js +0 -0
  214. package/src/services/cache/index.d.ts +7 -0
  215. package/src/services/cache/index.js +7 -0
  216. package/src/services/cache/memory-cache-store.d.ts +42 -0
  217. package/src/services/cache/memory-cache-store.js +98 -0
  218. package/src/services/cache/page-cache-service.d.ts +70 -0
  219. package/src/services/cache/page-cache-service.js +152 -0
  220. package/src/services/cache/page-request-cache-coordinator.service.d.ts +75 -0
  221. package/src/services/cache/page-request-cache-coordinator.service.js +109 -0
  222. package/src/services/html/html-rewriter-provider.service.d.ts +37 -0
  223. package/src/services/html/html-rewriter-provider.service.js +65 -0
  224. package/src/services/html/html-transformer.service.d.ts +77 -0
  225. package/src/services/html/html-transformer.service.js +221 -0
  226. package/src/services/invalidation/development-invalidation.service.d.ts +74 -0
  227. package/src/services/invalidation/development-invalidation.service.js +189 -0
  228. package/src/services/module-loading/app-server-module-transpiler.service.d.ts +16 -0
  229. package/src/services/module-loading/app-server-module-transpiler.service.js +34 -0
  230. package/src/services/module-loading/page-module-import.service.d.ts +71 -0
  231. package/src/services/module-loading/page-module-import.service.js +132 -0
  232. package/src/services/module-loading/server-loader.service.d.ts +96 -0
  233. package/src/services/module-loading/server-loader.service.js +32 -0
  234. package/src/services/module-loading/server-module-transpiler.service.d.ts +69 -0
  235. package/src/services/module-loading/server-module-transpiler.service.js +61 -0
  236. package/src/services/runtime-manifest/node-runtime-manifest.service.d.ts +35 -0
  237. package/src/services/runtime-manifest/node-runtime-manifest.service.js +60 -0
  238. package/src/services/runtime-state/dev-graph.service.d.ts +118 -0
  239. package/src/services/runtime-state/dev-graph.service.js +162 -0
  240. package/src/services/runtime-state/entrypoint-dependency-graph.service.d.ts +41 -0
  241. package/src/services/runtime-state/entrypoint-dependency-graph.service.js +85 -0
  242. package/src/services/runtime-state/runtime-specifier-registry.service.d.ts +69 -0
  243. package/src/services/runtime-state/runtime-specifier-registry.service.js +37 -0
  244. package/src/services/runtime-state/server-invalidation-state.service.d.ts +26 -0
  245. package/src/services/runtime-state/server-invalidation-state.service.js +35 -0
  246. package/src/services/validation/schema-validation-service.d.ts +122 -0
  247. package/src/services/validation/schema-validation-service.js +101 -0
  248. package/src/services/validation/standard-schema.types.d.ts +65 -0
  249. package/src/services/validation/standard-schema.types.js +0 -0
  250. package/src/static-site-generator/static-site-generator.d.ts +109 -0
  251. package/src/static-site-generator/static-site-generator.js +353 -0
  252. package/src/utils/css.d.ts +1 -0
  253. package/src/utils/css.js +7 -0
  254. package/src/utils/deep-merge.d.ts +14 -0
  255. package/src/utils/deep-merge.js +32 -0
  256. package/src/utils/hash.d.ts +1 -0
  257. package/src/utils/hash.js +7 -0
  258. package/src/utils/html.d.ts +1 -0
  259. package/src/utils/html.js +4 -0
  260. package/src/utils/invariant.d.ts +5 -0
  261. package/src/utils/invariant.js +11 -0
  262. package/src/utils/locals-utils.d.ts +15 -0
  263. package/src/utils/locals-utils.js +24 -0
  264. package/src/utils/parse-cli-args.d.ts +24 -0
  265. package/src/utils/parse-cli-args.js +47 -0
  266. package/src/utils/path-utils.module.d.ts +5 -0
  267. package/src/utils/path-utils.module.js +14 -0
  268. package/src/utils/resolve-work-dir.d.ts +11 -0
  269. package/src/utils/resolve-work-dir.js +31 -0
  270. package/src/utils/runtime.d.ts +11 -0
  271. package/src/utils/runtime.js +40 -0
  272. package/src/utils/server-utils.module.d.ts +19 -0
  273. package/src/utils/server-utils.module.js +56 -0
  274. package/src/watchers/project-watcher.d.ts +136 -0
  275. package/src/watchers/project-watcher.js +281 -0
  276. package/src/watchers/project-watcher.test-helpers.d.ts +4 -0
  277. package/src/watchers/project-watcher.test-helpers.js +52 -0
  278. package/src/adapters/bun/hmr-manager.test.ts +0 -267
  279. package/src/adapters/node/bootstrap-dependency-resolver.test.ts +0 -282
  280. package/src/adapters/node/node-client-bridge.test.ts +0 -198
  281. package/src/adapters/node/node-hmr-manager.test.ts +0 -322
  282. package/src/adapters/node/runtime-adapter.test.ts +0 -868
  283. package/src/adapters/node/static-content-server.test.ts +0 -60
  284. package/src/adapters/shared/api-response.test.ts +0 -97
  285. package/src/adapters/shared/explicit-static-route-matcher.test.ts +0 -381
  286. package/src/adapters/shared/file-route-middleware-pipeline.test.ts +0 -90
  287. package/src/adapters/shared/fs-server-response-factory.test.ts +0 -187
  288. package/src/adapters/shared/fs-server-response-matcher.test.ts +0 -286
  289. package/src/adapters/shared/hmr-manager.contract.test.ts +0 -196
  290. package/src/adapters/shared/hmr-manager.dispatch.test.ts +0 -220
  291. package/src/adapters/shared/render-context.test.ts +0 -146
  292. package/src/adapters/shared/server-adapter.test.ts +0 -77
  293. package/src/adapters/shared/server-route-handler.test.ts +0 -110
  294. package/src/adapters/shared/server-static-builder.test.ts +0 -316
  295. package/src/build/build-adapter-serialization.test.ts +0 -268
  296. package/src/build/build-adapter.test.ts +0 -815
  297. package/src/build/runtime-specifier-alias-plugin.test.ts +0 -43
  298. package/src/config/config-builder.test.ts +0 -410
  299. package/src/eco/eco.test.ts +0 -678
  300. package/src/eco/eco.utils.test.ts +0 -124
  301. package/src/eco/global-injector-map.test.ts +0 -42
  302. package/src/eco/lazy-injector-map.test.ts +0 -66
  303. package/src/eco/module-dependencies.test.ts +0 -30
  304. package/src/errors/http-error.test.ts +0 -134
  305. package/src/global/utils.test.ts +0 -12
  306. package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-have-HMR-script-injected-in-page-1.png +0 -0
  307. package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-load-fixture-app-page-1.png +0 -0
  308. package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-WebSocket-Connection-should-connect-to-correct-HMR-endpoint-1.png +0 -0
  309. package/src/hmr/hmr-strategy.test.ts +0 -124
  310. package/src/hmr/strategies/js-hmr-strategy.test.ts +0 -335
  311. package/src/integrations/ghtml/ghtml-renderer.test.ts +0 -63
  312. package/src/plugins/alias-resolver-plugin.test.ts +0 -41
  313. package/src/plugins/eco-component-meta-plugin.test.ts +0 -380
  314. package/src/plugins/integration-plugin.test.ts +0 -111
  315. package/src/plugins/processor.test.ts +0 -148
  316. package/src/route-renderer/component-graph/component-graph-executor.test.ts +0 -41
  317. package/src/route-renderer/component-graph/component-graph.test.ts +0 -63
  318. package/src/route-renderer/component-graph/component-marker.test.ts +0 -73
  319. package/src/route-renderer/component-graph/marker-graph-resolver.test.ts +0 -135
  320. package/src/route-renderer/orchestration/integration-renderer.test.ts +0 -936
  321. package/src/route-renderer/orchestration/render-execution.service.test.ts +0 -97
  322. package/src/route-renderer/orchestration/render-preparation.service.test.ts +0 -235
  323. package/src/route-renderer/page-loading/dependency-resolver.test.ts +0 -345
  324. package/src/route-renderer/page-loading/page-module-loader.test.ts +0 -96
  325. package/src/router/client/navigation-coordinator.test.ts +0 -237
  326. package/src/router/server/fs-router-scanner.test.ts +0 -83
  327. package/src/router/server/fs-router.test.ts +0 -214
  328. package/src/services/assets/asset-processing-service/asset-processing.service.test.ts +0 -385
  329. package/src/services/assets/asset-processing-service/asset.factory.test.ts +0 -63
  330. package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.test.ts +0 -72
  331. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.test.ts +0 -67
  332. package/src/services/assets/asset-processing-service/processors/base/base-processor.test.ts +0 -59
  333. package/src/services/assets/asset-processing-service/processors/script/file-script.processor.test.ts +0 -286
  334. package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.test.ts +0 -227
  335. package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.test.ts +0 -199
  336. package/src/services/assets/browser-bundle.service.test.ts +0 -36
  337. package/src/services/cache/memory-cache-store.test.ts +0 -225
  338. package/src/services/cache/page-cache-service.test.ts +0 -175
  339. package/src/services/cache/page-request-cache-coordinator.service.test.ts +0 -79
  340. package/src/services/html/html-rewriter-provider.service.test.ts +0 -183
  341. package/src/services/html/html-transformer.service.test.ts +0 -378
  342. package/src/services/invalidation/development-invalidation.service.test.ts +0 -77
  343. package/src/services/module-loading/page-module-import.service.test.ts +0 -253
  344. package/src/services/module-loading/server-loader.service.test.ts +0 -161
  345. package/src/services/module-loading/server-module-transpiler.service.test.ts +0 -115
  346. package/src/services/runtime-manifest/node-runtime-manifest.service.test.ts +0 -95
  347. package/src/services/validation/schema-validation-service.test.ts +0 -223
  348. package/src/static-site-generator/static-site-generator.test.ts +0 -307
  349. package/src/utils/deep-merge.test.ts +0 -114
  350. package/src/utils/invariant.test.ts +0 -22
  351. package/src/utils/path-utils.test.ts +0 -15
  352. package/src/utils/server-utils.test.ts +0 -38
  353. package/src/watchers/project-watcher.integration.test.ts +0 -337
  354. package/src/watchers/project-watcher.test.ts +0 -678
@@ -0,0 +1,65 @@
1
+ import type { Middleware, ApiHandlerContext, RequestLocals } from '../../public-types.js';
2
+ import type { PageCacheService } from '../../services/cache/page-cache-service.js';
3
+ export declare const FILE_ROUTE_MIDDLEWARE_PIPELINE_ERRORS: {
4
+ readonly CTX_RENDER_UNAVAILABLE: "[ecopages] ctx.render is not available in file-route middleware";
5
+ readonly CTX_RENDER_PARTIAL_UNAVAILABLE: "[ecopages] ctx.renderPartial is not available in file-route middleware";
6
+ readonly middlewareRequiresDynamic: (filePath: string) => string;
7
+ };
8
+ /**
9
+ * Executes middleware for file-based page routes.
10
+ *
11
+ * This pipeline owns the middleware-specific rules that are distinct from route
12
+ * matching and rendering, including request-local storage, the middleware
13
+ * execution context, and the invariant that page middleware only runs for
14
+ * request-time dynamic rendering.
15
+ */
16
+ export declare class FileRouteMiddlewarePipeline {
17
+ private cacheService;
18
+ constructor(cacheService: PageCacheService | null);
19
+ /**
20
+ * Enforces the current middleware contract for file-routed pages.
21
+ *
22
+ * Middleware depends on request-scoped locals and therefore must not run when
23
+ * the page is treated as statically cacheable.
24
+ *
25
+ * @param input Middleware list, effective cache strategy, and page path.
26
+ * @throws LocalsAccessError When middleware is configured for a non-dynamic page.
27
+ */
28
+ assertValidConfiguration(input: {
29
+ middleware: Middleware[];
30
+ pageCacheStrategy: 'static' | 'dynamic' | {
31
+ revalidate: number;
32
+ tags?: string[];
33
+ };
34
+ filePath: string;
35
+ }): void;
36
+ /**
37
+ * Creates the request-scoped middleware context used by page middleware.
38
+ *
39
+ * The context intentionally disables `render()` and `renderPartial()` inside
40
+ * file-route middleware because rendering is owned by the page route pipeline,
41
+ * not by middleware stages.
42
+ *
43
+ * @param input Request details and the mutable locals store.
44
+ * @returns Middleware execution context.
45
+ */
46
+ createContext(input: {
47
+ request: Request;
48
+ params: Record<string, string>;
49
+ locals: RequestLocals;
50
+ }): ApiHandlerContext;
51
+ /**
52
+ * Runs the middleware chain and eventually delegates to the render callback.
53
+ *
54
+ * Middleware may short-circuit by returning a response directly. If the chain
55
+ * completes, the supplied `renderResponse` callback is executed exactly once.
56
+ *
57
+ * @param input Middleware context, chain, and terminal render callback.
58
+ * @returns Response from middleware or final render stage.
59
+ */
60
+ run(input: {
61
+ middleware: Middleware[];
62
+ context: ApiHandlerContext;
63
+ renderResponse: () => Promise<Response>;
64
+ }): Promise<Response>;
65
+ }
@@ -0,0 +1,99 @@
1
+ import { createRequire } from "../../utils/locals-utils.js";
2
+ import { ApiResponseBuilder } from "./api-response.js";
3
+ import { LocalsAccessError } from "../../errors/locals-access-error.js";
4
+ const FILE_ROUTE_MIDDLEWARE_PIPELINE_ERRORS = {
5
+ CTX_RENDER_UNAVAILABLE: "[ecopages] ctx.render is not available in file-route middleware",
6
+ CTX_RENDER_PARTIAL_UNAVAILABLE: "[ecopages] ctx.renderPartial is not available in file-route middleware",
7
+ middlewareRequiresDynamic: (filePath) => `[ecopages] Page middleware requires cache: 'dynamic'. Page: ${filePath}`
8
+ };
9
+ class FileRouteMiddlewarePipeline {
10
+ cacheService;
11
+ constructor(cacheService) {
12
+ this.cacheService = cacheService;
13
+ }
14
+ /**
15
+ * Enforces the current middleware contract for file-routed pages.
16
+ *
17
+ * Middleware depends on request-scoped locals and therefore must not run when
18
+ * the page is treated as statically cacheable.
19
+ *
20
+ * @param input Middleware list, effective cache strategy, and page path.
21
+ * @throws LocalsAccessError When middleware is configured for a non-dynamic page.
22
+ */
23
+ assertValidConfiguration(input) {
24
+ if (input.middleware.length > 0 && input.pageCacheStrategy !== "dynamic") {
25
+ throw new LocalsAccessError(
26
+ FILE_ROUTE_MIDDLEWARE_PIPELINE_ERRORS.middlewareRequiresDynamic(input.filePath)
27
+ );
28
+ }
29
+ }
30
+ /**
31
+ * Creates the request-scoped middleware context used by page middleware.
32
+ *
33
+ * The context intentionally disables `render()` and `renderPartial()` inside
34
+ * file-route middleware because rendering is owned by the page route pipeline,
35
+ * not by middleware stages.
36
+ *
37
+ * @param input Request details and the mutable locals store.
38
+ * @returns Middleware execution context.
39
+ */
40
+ createContext(input) {
41
+ const context = {
42
+ request: input.request,
43
+ params: input.params,
44
+ response: new ApiResponseBuilder(),
45
+ server: null,
46
+ services: {
47
+ cache: this.cacheService
48
+ },
49
+ locals: input.locals,
50
+ require: createRequire(() => context.locals),
51
+ render: async () => {
52
+ throw new Error(FILE_ROUTE_MIDDLEWARE_PIPELINE_ERRORS.CTX_RENDER_UNAVAILABLE);
53
+ },
54
+ renderPartial: async () => {
55
+ throw new Error(FILE_ROUTE_MIDDLEWARE_PIPELINE_ERRORS.CTX_RENDER_PARTIAL_UNAVAILABLE);
56
+ },
57
+ json: (data, options) => {
58
+ const builder = new ApiResponseBuilder();
59
+ if (options?.status) builder.status(options.status);
60
+ if (options?.headers) builder.headers(options.headers);
61
+ return builder.json(data);
62
+ },
63
+ html: (content, options) => {
64
+ const builder = new ApiResponseBuilder();
65
+ if (options?.status) builder.status(options.status);
66
+ if (options?.headers) builder.headers(options.headers);
67
+ return builder.html(content);
68
+ }
69
+ };
70
+ return context;
71
+ }
72
+ /**
73
+ * Runs the middleware chain and eventually delegates to the render callback.
74
+ *
75
+ * Middleware may short-circuit by returning a response directly. If the chain
76
+ * completes, the supplied `renderResponse` callback is executed exactly once.
77
+ *
78
+ * @param input Middleware context, chain, and terminal render callback.
79
+ * @returns Response from middleware or final render stage.
80
+ */
81
+ async run(input) {
82
+ if (input.middleware.length === 0) {
83
+ return input.renderResponse();
84
+ }
85
+ let index = 0;
86
+ const executeNext = async () => {
87
+ if (index < input.middleware.length) {
88
+ const current = input.middleware[index++];
89
+ return current(input.context, executeNext);
90
+ }
91
+ return input.renderResponse();
92
+ };
93
+ return executeNext();
94
+ }
95
+ }
96
+ export {
97
+ FILE_ROUTE_MIDDLEWARE_PIPELINE_ERRORS,
98
+ FileRouteMiddlewarePipeline
99
+ };
@@ -0,0 +1,19 @@
1
+ import type { EcoPagesAppConfig, FileSystemServerOptions } from '../../internal-types.js';
2
+ import type { RouteRendererBody } from '../../public-types.js';
3
+ import type { RouteRendererFactory } from '../../route-renderer/route-renderer.js';
4
+ export declare class FileSystemServerResponseFactory {
5
+ private appConfig;
6
+ private routeRendererFactory;
7
+ private options;
8
+ constructor({ appConfig, routeRendererFactory, options, }: {
9
+ appConfig: EcoPagesAppConfig;
10
+ routeRendererFactory: RouteRendererFactory;
11
+ options: FileSystemServerOptions;
12
+ });
13
+ isHtml(contentType: string): contentType is "text/html";
14
+ shouldEnableGzip(contentType: string): boolean;
15
+ createResponseWithBody(body: RouteRendererBody, init?: ResponseInit): Promise<Response>;
16
+ createDefaultNotFoundResponse(): Promise<Response>;
17
+ createCustomNotFoundResponse(): Promise<Response>;
18
+ createFileResponse(filePath: string, contentType: string): Promise<Response>;
19
+ }
@@ -0,0 +1,97 @@
1
+ import { STATUS_MESSAGE } from "../../constants.js";
2
+ import { appLogger } from "../../global/app-logger.js";
3
+ import { fileSystem } from "@ecopages/file-system";
4
+ class FileSystemServerResponseFactory {
5
+ appConfig;
6
+ routeRendererFactory;
7
+ options;
8
+ constructor({
9
+ appConfig,
10
+ routeRendererFactory,
11
+ options
12
+ }) {
13
+ this.appConfig = appConfig;
14
+ this.routeRendererFactory = routeRendererFactory;
15
+ this.options = options;
16
+ }
17
+ isHtml(contentType) {
18
+ return contentType === "text/html";
19
+ }
20
+ shouldEnableGzip(contentType) {
21
+ if (this.options.watchMode) return false;
22
+ const gzipEnabledExtensions = ["text/javascript", "text/css"];
23
+ return gzipEnabledExtensions.includes(contentType);
24
+ }
25
+ async createResponseWithBody(body, init = {
26
+ headers: {
27
+ "Content-Type": "text/html"
28
+ }
29
+ }) {
30
+ return new Response(body, init);
31
+ }
32
+ async createDefaultNotFoundResponse() {
33
+ return new Response(STATUS_MESSAGE[404], {
34
+ status: 404
35
+ });
36
+ }
37
+ async createCustomNotFoundResponse() {
38
+ const error404TemplatePath = this.appConfig.absolutePaths.error404TemplatePath;
39
+ try {
40
+ fileSystem.verifyFileExists(error404TemplatePath);
41
+ } catch {
42
+ appLogger.debug(
43
+ "Custom 404 template not found, falling back to default 404 response",
44
+ error404TemplatePath
45
+ );
46
+ return this.createDefaultNotFoundResponse();
47
+ }
48
+ const routeRenderer = this.routeRendererFactory.createRenderer(error404TemplatePath);
49
+ const result = await routeRenderer.createRoute({
50
+ file: error404TemplatePath
51
+ });
52
+ return await this.createResponseWithBody(result.body, {
53
+ status: 404,
54
+ statusText: STATUS_MESSAGE[404],
55
+ headers: {
56
+ "Content-Type": "text/html"
57
+ }
58
+ });
59
+ }
60
+ async createFileResponse(filePath, contentType) {
61
+ try {
62
+ let file;
63
+ const contentEncodingHeader = {};
64
+ if (this.shouldEnableGzip(contentType)) {
65
+ const gzipPath = `${filePath}.gz`;
66
+ if (fileSystem.exists(gzipPath)) {
67
+ file = fileSystem.readFileAsBuffer(gzipPath);
68
+ contentEncodingHeader["Content-Encoding"] = "gzip";
69
+ contentEncodingHeader["Vary"] = "Accept-Encoding";
70
+ } else {
71
+ appLogger.debug("Gzip file not found, serving uncompressed", gzipPath);
72
+ file = fileSystem.readFileAsBuffer(filePath);
73
+ }
74
+ } else {
75
+ file = fileSystem.readFileAsBuffer(filePath);
76
+ }
77
+ return await this.createResponseWithBody(file, {
78
+ headers: {
79
+ "Content-Type": contentType,
80
+ ...contentEncodingHeader
81
+ }
82
+ });
83
+ } catch (error) {
84
+ const err = error;
85
+ const code = err.code || err.cause?.code;
86
+ if (code === "ENOENT") {
87
+ appLogger.debug("File not found", filePath);
88
+ } else {
89
+ appLogger.error("Error reading file", filePath, err);
90
+ }
91
+ return this.createCustomNotFoundResponse();
92
+ }
93
+ }
94
+ }
95
+ export {
96
+ FileSystemServerResponseFactory
97
+ };
@@ -0,0 +1,75 @@
1
+ import type { EcoPagesAppConfig, MatchResult } from '../../internal-types.js';
2
+ import type { RouteRendererFactory } from '../../route-renderer/route-renderer.js';
3
+ import type { FSRouter } from '../../router/server/fs-router.js';
4
+ import type { PageCacheService } from '../../services/cache/page-cache-service.js';
5
+ import type { CacheStrategy } from '../../services/cache/cache.types.js';
6
+ import type { FileSystemServerResponseFactory } from './fs-server-response-factory.js';
7
+ export declare const FILE_SYSTEM_RESPONSE_MATCHER_ERRORS: {
8
+ readonly transpilePageModuleFailed: (details: string) => string;
9
+ readonly noTranspiledOutputForPageModule: (filePath: string) => string;
10
+ };
11
+ export interface FileSystemResponseMatcherOptions {
12
+ appConfig: EcoPagesAppConfig;
13
+ router: FSRouter;
14
+ routeRendererFactory: RouteRendererFactory;
15
+ fileSystemResponseFactory: FileSystemServerResponseFactory;
16
+ /** Optional cache service. When null, caching is disabled. */
17
+ cacheService?: PageCacheService | null;
18
+ /** Default cache strategy when caching is enabled. @default 'static' */
19
+ defaultCacheStrategy?: CacheStrategy;
20
+ }
21
+ /**
22
+ * Matches file-system routes to rendered HTML responses.
23
+ *
24
+ * This class sits at the request-time boundary between router matches and the
25
+ * render pipeline. It coordinates page module inspection, request-local policy,
26
+ * renderer invocation, middleware execution, cache integration, and fallback
27
+ * error translation.
28
+ */
29
+ export declare class FileSystemResponseMatcher {
30
+ private appConfig;
31
+ private router;
32
+ private routeRendererFactory;
33
+ private fileSystemResponseFactory;
34
+ private serverModuleTranspiler;
35
+ private pageRequestCacheCoordinator;
36
+ private fileRouteMiddlewarePipeline;
37
+ constructor({ appConfig, router, routeRendererFactory, fileSystemResponseFactory, cacheService, defaultCacheStrategy, }: FileSystemResponseMatcherOptions);
38
+ /**
39
+ * Resolves unmatched paths either as static asset requests or as the custom
40
+ * not-found page.
41
+ *
42
+ * @param requestUrl Incoming pathname.
43
+ * @returns Static file response or rendered 404 response.
44
+ */
45
+ handleNoMatch(requestUrl: string): Promise<Response>;
46
+ /**
47
+ * Handles a matched file-system page route.
48
+ *
49
+ * The method inspects page metadata needed for request-time execution,
50
+ * prepares the renderer invocation, validates middleware/cache constraints,
51
+ * and delegates caching plus middleware execution to dedicated collaborators.
52
+ *
53
+ * @param match Router match result.
54
+ * @param request Optional incoming request. A synthetic GET request is created when omitted.
55
+ * @returns Final response for the matched route.
56
+ */
57
+ handleMatch(match: MatchResult, request?: Request): Promise<Response>;
58
+ /**
59
+ * Loads the matched page module for request-time inspection.
60
+ *
61
+ * The matcher needs access to page-level metadata such as `cache` and
62
+ * `middleware` before full rendering starts, so it uses the shared module
63
+ * import service directly rather than going through route rendering. The
64
+ * app config is injected explicitly so build ownership stays at the adapter
65
+ * boundary instead of leaking through nested router collaborators.
66
+ *
67
+ * @param filePath Absolute page module path.
68
+ * @returns Imported page module.
69
+ */
70
+ private importPageModule;
71
+ /**
72
+ * Get the underlying cache service for external invalidation.
73
+ */
74
+ getCacheService(): PageCacheService | null;
75
+ }
@@ -0,0 +1,160 @@
1
+ import path from "node:path";
2
+ import { appLogger } from "../../global/app-logger.js";
3
+ import { PageRequestCacheCoordinator } from "../../services/cache/page-request-cache-coordinator.service.js";
4
+ import { getAppServerModuleTranspiler } from "../../services/module-loading/app-server-module-transpiler.service.js";
5
+ import { resolveInternalExecutionDir } from "../../utils/resolve-work-dir.js";
6
+ import { ServerUtils } from "../../utils/server-utils.module.js";
7
+ import { FileRouteMiddlewarePipeline } from "./file-route-middleware-pipeline.js";
8
+ import { LocalsAccessError } from "../../errors/locals-access-error.js";
9
+ import { isDevelopmentRuntime } from "../../utils/runtime.js";
10
+ const FILE_SYSTEM_RESPONSE_MATCHER_ERRORS = {
11
+ transpilePageModuleFailed: (details) => `Error transpiling page module: ${details}`,
12
+ noTranspiledOutputForPageModule: (filePath) => `No transpiled output generated for page module: ${filePath}`
13
+ };
14
+ class FileSystemResponseMatcher {
15
+ appConfig;
16
+ router;
17
+ routeRendererFactory;
18
+ fileSystemResponseFactory;
19
+ serverModuleTranspiler;
20
+ pageRequestCacheCoordinator;
21
+ fileRouteMiddlewarePipeline;
22
+ constructor({
23
+ appConfig,
24
+ router,
25
+ routeRendererFactory,
26
+ fileSystemResponseFactory,
27
+ cacheService = null,
28
+ defaultCacheStrategy = "static"
29
+ }) {
30
+ this.appConfig = appConfig;
31
+ this.router = router;
32
+ this.routeRendererFactory = routeRendererFactory;
33
+ this.fileSystemResponseFactory = fileSystemResponseFactory;
34
+ this.serverModuleTranspiler = getAppServerModuleTranspiler(appConfig);
35
+ this.pageRequestCacheCoordinator = new PageRequestCacheCoordinator(cacheService, defaultCacheStrategy);
36
+ this.fileRouteMiddlewarePipeline = new FileRouteMiddlewarePipeline(cacheService);
37
+ }
38
+ /**
39
+ * Resolves unmatched paths either as static asset requests or as the custom
40
+ * not-found page.
41
+ *
42
+ * @param requestUrl Incoming pathname.
43
+ * @returns Static file response or rendered 404 response.
44
+ */
45
+ async handleNoMatch(requestUrl) {
46
+ const isStaticFileRequest = ServerUtils.hasKnownExtension(requestUrl);
47
+ if (!isStaticFileRequest) {
48
+ return this.fileSystemResponseFactory.createCustomNotFoundResponse();
49
+ }
50
+ const relativeUrl = requestUrl.startsWith("/") ? requestUrl.slice(1) : requestUrl;
51
+ const filePath = path.join(this.router.assetPrefix, relativeUrl);
52
+ const contentType = ServerUtils.getContentType(filePath);
53
+ return this.fileSystemResponseFactory.createFileResponse(filePath, contentType);
54
+ }
55
+ /**
56
+ * Handles a matched file-system page route.
57
+ *
58
+ * The method inspects page metadata needed for request-time execution,
59
+ * prepares the renderer invocation, validates middleware/cache constraints,
60
+ * and delegates caching plus middleware execution to dedicated collaborators.
61
+ *
62
+ * @param match Router match result.
63
+ * @param request Optional incoming request. A synthetic GET request is created when omitted.
64
+ * @returns Final response for the matched route.
65
+ */
66
+ async handleMatch(match, request) {
67
+ const cacheKey = this.pageRequestCacheCoordinator.buildCacheKey(match);
68
+ try {
69
+ const resolvedRequest = request ?? new Request(new URL(cacheKey, this.router.origin).toString(), {
70
+ method: "GET"
71
+ });
72
+ const localsStore = {};
73
+ const pageModule = await this.importPageModule(match.filePath);
74
+ const Page = pageModule?.default;
75
+ const pageMiddleware = Page?.middleware ?? [];
76
+ const pageCacheStrategy = Page?.cache ?? this.pageRequestCacheCoordinator.getDefaultCacheStrategy();
77
+ const localsForRender = pageCacheStrategy === "dynamic" ? localsStore : void 0;
78
+ this.fileRouteMiddlewarePipeline.assertValidConfiguration({
79
+ middleware: pageMiddleware,
80
+ pageCacheStrategy,
81
+ filePath: match.filePath
82
+ });
83
+ const routeRenderer = this.routeRendererFactory.createRenderer(match.filePath);
84
+ const middlewareContext = this.fileRouteMiddlewarePipeline.createContext({
85
+ request: resolvedRequest,
86
+ params: match.params,
87
+ locals: localsStore
88
+ });
89
+ const renderFn = async () => {
90
+ const result = await routeRenderer.createRoute({
91
+ file: match.filePath,
92
+ params: match.params,
93
+ query: match.query,
94
+ locals: localsForRender
95
+ });
96
+ const html = await this.pageRequestCacheCoordinator.bodyToString(result.body);
97
+ const strategy = result.cacheStrategy ?? this.pageRequestCacheCoordinator.getDefaultCacheStrategy();
98
+ return { html, strategy };
99
+ };
100
+ const renderResponse = async () => {
101
+ return this.pageRequestCacheCoordinator.render({
102
+ cacheKey,
103
+ pageCacheStrategy,
104
+ renderFn
105
+ });
106
+ };
107
+ return await this.fileRouteMiddlewarePipeline.run({
108
+ middleware: pageMiddleware,
109
+ context: middlewareContext,
110
+ renderResponse
111
+ });
112
+ } catch (error) {
113
+ if (error instanceof Response) {
114
+ return error;
115
+ }
116
+ if (error instanceof LocalsAccessError) {
117
+ return new Response(error.message, {
118
+ status: 500,
119
+ headers: { "Content-Type": "text/plain; charset=utf-8" }
120
+ });
121
+ }
122
+ if (error instanceof Error) {
123
+ if (isDevelopmentRuntime() || appLogger.isDebugEnabled()) {
124
+ appLogger.error(`[FileSystemResponseMatcher] ${error.message} at ${match.pathname}`);
125
+ }
126
+ }
127
+ return this.fileSystemResponseFactory.createCustomNotFoundResponse();
128
+ }
129
+ }
130
+ /**
131
+ * Loads the matched page module for request-time inspection.
132
+ *
133
+ * The matcher needs access to page-level metadata such as `cache` and
134
+ * `middleware` before full rendering starts, so it uses the shared module
135
+ * import service directly rather than going through route rendering. The
136
+ * app config is injected explicitly so build ownership stays at the adapter
137
+ * boundary instead of leaking through nested router collaborators.
138
+ *
139
+ * @param filePath Absolute page module path.
140
+ * @returns Imported page module.
141
+ */
142
+ async importPageModule(filePath) {
143
+ return this.serverModuleTranspiler.importModule({
144
+ filePath,
145
+ outdir: path.join(resolveInternalExecutionDir(this.appConfig), ".server-modules-meta"),
146
+ transpileErrorMessage: FILE_SYSTEM_RESPONSE_MATCHER_ERRORS.transpilePageModuleFailed,
147
+ noOutputMessage: FILE_SYSTEM_RESPONSE_MATCHER_ERRORS.noTranspiledOutputForPageModule
148
+ });
149
+ }
150
+ /**
151
+ * Get the underlying cache service for external invalidation.
152
+ */
153
+ getCacheService() {
154
+ return this.pageRequestCacheCoordinator.getCacheService();
155
+ }
156
+ }
157
+ export {
158
+ FILE_SYSTEM_RESPONSE_MATCHER_ERRORS,
159
+ FileSystemResponseMatcher
160
+ };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Shared runtime state used while registering HMR-owned entrypoints.
3
+ */
4
+ export interface HmrEntrypointRegistrarOptions {
5
+ /** Absolute source directory used to derive the emitted HMR path. */
6
+ srcDir: string;
7
+ /** Absolute distribution directory where HMR outputs are written. */
8
+ distDir: string;
9
+ /** In-flight registrations keyed by normalized absolute entrypoint path. */
10
+ entrypointRegistrations: Map<string, Promise<string>>;
11
+ /** Stable entrypoint-to-output mapping retained once an entrypoint is registered. */
12
+ watchedFiles: Map<string, string>;
13
+ /** Runtime-specific cleanup invoked when an entrypoint registration fails. */
14
+ clearFailedRegistration?: (entrypointPath: string) => void;
15
+ /** Development-only guardrail for integrations that never finish producing output. */
16
+ registrationTimeoutMs: number;
17
+ }
18
+ /**
19
+ * Runtime-specific hooks required to materialize a single HMR entrypoint.
20
+ */
21
+ export interface HmrEntrypointRegistrationOptions {
22
+ /**
23
+ * Emits the browser-consumable HMR artifact for an entrypoint.
24
+ */
25
+ emit(entrypointPath: string, outputPath: string): Promise<void>;
26
+ /**
27
+ * Creates the runtime-specific error raised when the emit hook completes without producing output.
28
+ */
29
+ getMissingOutputError(entrypointPath: string, outputPath: string): Error;
30
+ }
31
+ /**
32
+ * Coordinates the shared HMR entrypoint registration lifecycle for both Node and Bun managers.
33
+ *
34
+ * The registrar owns the cross-runtime policy: normalize entrypoint identities, dedupe concurrent
35
+ * registrations, derive the emitted `_hmr` output path, clear stale output before rebuilding, and
36
+ * apply the development timeout that prevents unresolved registrations from hanging navigation.
37
+ * Runtime-specific managers remain responsible for the actual emit step and any cleanup outside
38
+ * this shared registration flow.
39
+ */
40
+ export declare class HmrEntrypointRegistrar {
41
+ private readonly options;
42
+ constructor(options: HmrEntrypointRegistrarOptions);
43
+ /**
44
+ * Registers a single source entrypoint and returns the browser URL for its emitted HMR module.
45
+ *
46
+ * Concurrent requests for the same normalized entrypoint share the same in-flight promise so the
47
+ * integration only builds once per registration cycle.
48
+ */
49
+ registerEntrypoint(entrypointPath: string, registrationOptions: HmrEntrypointRegistrationOptions): Promise<string>;
50
+ private registerEntrypointInternal;
51
+ private awaitEntrypointRegistration;
52
+ private getEntrypointOutput;
53
+ private removeStaleEntrypointOutput;
54
+ private encodeDynamicSegments;
55
+ }
@@ -0,0 +1,87 @@
1
+ import path from "node:path";
2
+ import { fileSystem } from "@ecopages/file-system";
3
+ import { appLogger } from "../../global/app-logger.js";
4
+ import { RESOLVED_ASSETS_DIR } from "../../constants.js";
5
+ class HmrEntrypointRegistrar {
6
+ options;
7
+ constructor(options) {
8
+ this.options = options;
9
+ }
10
+ /**
11
+ * Registers a single source entrypoint and returns the browser URL for its emitted HMR module.
12
+ *
13
+ * Concurrent requests for the same normalized entrypoint share the same in-flight promise so the
14
+ * integration only builds once per registration cycle.
15
+ */
16
+ async registerEntrypoint(entrypointPath, registrationOptions) {
17
+ const normalizedEntrypoint = path.resolve(entrypointPath);
18
+ const existingRegistration = this.options.entrypointRegistrations.get(normalizedEntrypoint);
19
+ if (existingRegistration) {
20
+ return await this.awaitEntrypointRegistration(existingRegistration, normalizedEntrypoint);
21
+ }
22
+ const registration = this.registerEntrypointInternal(normalizedEntrypoint, registrationOptions);
23
+ this.options.entrypointRegistrations.set(normalizedEntrypoint, registration);
24
+ try {
25
+ return await this.awaitEntrypointRegistration(registration, normalizedEntrypoint);
26
+ } catch (error) {
27
+ this.options.clearFailedRegistration?.(normalizedEntrypoint);
28
+ throw error;
29
+ } finally {
30
+ this.options.entrypointRegistrations.delete(normalizedEntrypoint);
31
+ }
32
+ }
33
+ async registerEntrypointInternal(entrypointPath, registrationOptions) {
34
+ if (this.options.watchedFiles.has(entrypointPath)) {
35
+ return this.options.watchedFiles.get(entrypointPath);
36
+ }
37
+ const { outputPath, outputUrl } = this.getEntrypointOutput(entrypointPath);
38
+ this.options.watchedFiles.set(entrypointPath, outputUrl);
39
+ this.removeStaleEntrypointOutput(outputPath);
40
+ await registrationOptions.emit(entrypointPath, outputPath);
41
+ if (!fileSystem.exists(outputPath)) {
42
+ throw registrationOptions.getMissingOutputError(entrypointPath, outputPath);
43
+ }
44
+ return outputUrl;
45
+ }
46
+ async awaitEntrypointRegistration(registration, entrypointPath) {
47
+ if (process.env.NODE_ENV !== "development") {
48
+ return await registration;
49
+ }
50
+ return await Promise.race([
51
+ registration,
52
+ new Promise((_, reject) => {
53
+ setTimeout(() => {
54
+ reject(new Error(`[HMR] Timed out registering entrypoint: ${entrypointPath}`));
55
+ }, this.options.registrationTimeoutMs);
56
+ })
57
+ ]);
58
+ }
59
+ getEntrypointOutput(entrypointPath) {
60
+ const relativePath = path.relative(this.options.srcDir, entrypointPath);
61
+ const relativePathJs = relativePath.replace(/\.(tsx?|jsx?|mdx?)$/, ".js");
62
+ const encodedPathJs = this.encodeDynamicSegments(relativePathJs);
63
+ const urlPath = encodedPathJs.split(path.sep).join("/");
64
+ return {
65
+ outputUrl: `/${path.join(RESOLVED_ASSETS_DIR, "_hmr", urlPath)}`,
66
+ outputPath: path.join(this.options.distDir, urlPath)
67
+ };
68
+ }
69
+ removeStaleEntrypointOutput(outputPath) {
70
+ if (!fileSystem.exists(outputPath)) {
71
+ return;
72
+ }
73
+ try {
74
+ fileSystem.remove(outputPath);
75
+ } catch (error) {
76
+ appLogger.warn(
77
+ `[HMR] Failed to remove stale entrypoint output ${outputPath}: ${error instanceof Error ? error.message : String(error)}`
78
+ );
79
+ }
80
+ }
81
+ encodeDynamicSegments(filepath) {
82
+ return filepath.replace(/\[([^\]]+)\]/g, "_$1_");
83
+ }
84
+ }
85
+ export {
86
+ HmrEntrypointRegistrar
87
+ };
@@ -0,0 +1,22 @@
1
+ import type { IHmrManager } from '../../public-types';
2
+ /**
3
+ * Returns whether a response is HTML and therefore eligible for development HMR
4
+ * runtime injection.
5
+ */
6
+ export declare function isHtmlResponse(response: Response): boolean;
7
+ /**
8
+ * Returns whether HTML responses should receive the HMR runtime bootstrap.
9
+ *
10
+ * This is shared because filesystem page responses and adapter-level HTML
11
+ * responses flow through different layers, but both need identical injection
12
+ * behavior in watch mode.
13
+ */
14
+ export declare function shouldInjectHmrHtmlResponse(watch: boolean, hmrManager?: Pick<IHmrManager, 'isEnabled'>): boolean;
15
+ /**
16
+ * Injects the development HMR runtime script into an HTML response if it is not
17
+ * already present.
18
+ *
19
+ * The check is intentionally idempotent because an HTML response can pass
20
+ * through more than one development-layer wrapper before reaching the client.
21
+ */
22
+ export declare function injectHmrRuntimeIntoHtmlResponse(response: Response): Promise<Response>;