@ecopages/core 0.2.0-alpha.8 → 0.2.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 (357) hide show
  1. package/CHANGELOG.md +18 -11
  2. package/README.md +23 -26
  3. package/package.json +76 -58
  4. package/src/adapters/README.md +2 -2
  5. package/src/adapters/abstract/application-adapter.d.ts +28 -2
  6. package/src/adapters/abstract/application-adapter.js +14 -2
  7. package/src/adapters/abstract/router-adapter.d.ts +1 -1
  8. package/src/adapters/abstract/server-adapter.d.ts +2 -2
  9. package/src/adapters/bun/client-bridge.d.ts +1 -1
  10. package/src/adapters/bun/create-app.d.ts +4 -12
  11. package/src/adapters/bun/create-app.js +4 -5
  12. package/src/adapters/bun/hmr-manager.d.ts +4 -4
  13. package/src/adapters/bun/hmr-manager.js +8 -8
  14. package/src/adapters/bun/index.d.ts +1 -1
  15. package/src/adapters/bun/index.js +2 -2
  16. package/src/adapters/bun/server-adapter.d.ts +5 -5
  17. package/src/adapters/bun/server-adapter.js +6 -5
  18. package/src/adapters/bun/server-lifecycle.d.ts +4 -4
  19. package/src/adapters/bun/server-lifecycle.js +2 -2
  20. package/src/{create-app.d.ts → adapters/create-app.d.ts} +9 -6
  21. package/src/{create-app.js → adapters/create-app.js} +4 -4
  22. package/src/adapters/index.d.ts +1 -5
  23. package/src/adapters/index.js +1 -7
  24. package/src/adapters/node/create-app.d.ts +6 -9
  25. package/src/adapters/node/create-app.js +12 -6
  26. package/src/adapters/node/node-client-bridge.d.ts +1 -1
  27. package/src/adapters/node/node-hmr-manager.d.ts +2 -2
  28. package/src/adapters/node/node-hmr-manager.js +3 -3
  29. package/src/adapters/node/server-adapter.d.ts +4 -4
  30. package/src/adapters/node/server-adapter.js +13 -12
  31. package/src/adapters/node/static-content-server.d.ts +1 -1
  32. package/src/adapters/node/static-content-server.js +1 -1
  33. package/src/adapters/shared/application-adapter.d.ts +1 -1
  34. package/src/adapters/shared/define-api-handler.d.ts +1 -1
  35. package/src/adapters/shared/explicit-static-route-matcher.d.ts +2 -2
  36. package/src/adapters/shared/file-route-middleware-pipeline.d.ts +1 -1
  37. package/src/adapters/shared/fs-server-response-factory.d.ts +2 -2
  38. package/src/adapters/shared/fs-server-response-factory.js +1 -1
  39. package/src/adapters/shared/fs-server-response-matcher.d.ts +1 -1
  40. package/src/adapters/shared/hmr-entrypoint-registrar.js +1 -1
  41. package/src/adapters/shared/hmr-html-response.d.ts +1 -1
  42. package/src/adapters/shared/render-context.d.ts +2 -1
  43. package/src/adapters/shared/render-context.js +3 -1
  44. package/src/adapters/shared/runtime-bootstrap.d.ts +1 -1
  45. package/src/adapters/shared/runtime-bootstrap.js +1 -1
  46. package/src/adapters/shared/server-adapter.d.ts +1 -1
  47. package/src/adapters/shared/server-adapter.js +5 -1
  48. package/src/adapters/shared/server-route-handler.d.ts +4 -4
  49. package/src/adapters/shared/server-route-handler.js +3 -3
  50. package/src/adapters/shared/server-static-builder.d.ts +5 -5
  51. package/src/adapters/shared/server-static-builder.js +5 -4
  52. package/src/build/README.md +19 -13
  53. package/src/build/build-adapter.d.ts +67 -20
  54. package/src/build/build-adapter.js +420 -19
  55. package/src/build/dev-build-coordinator.d.ts +10 -12
  56. package/src/build/dev-build-coordinator.js +8 -15
  57. package/src/build/esbuild-build-adapter.d.ts +6 -0
  58. package/src/build/esbuild-build-adapter.js +94 -11
  59. package/src/build/runtime-build-executor.d.ts +5 -4
  60. package/src/build/runtime-build-executor.js +5 -3
  61. package/src/build/runtime-specifier-alias-plugin.js +19 -15
  62. package/src/build/runtime-specifier-aliases.d.ts +5 -0
  63. package/src/build/runtime-specifier-aliases.js +95 -0
  64. package/src/config/README.md +5 -2
  65. package/src/config/config-builder.d.ts +25 -2
  66. package/src/config/config-builder.js +44 -7
  67. package/src/declarations.d.ts +1 -1
  68. package/src/dev/sc-server.d.ts +1 -1
  69. package/src/dev/sc-server.js +1 -1
  70. package/src/eco/eco.browser.d.ts +2 -0
  71. package/src/eco/eco.browser.js +83 -0
  72. package/src/eco/eco.js +19 -48
  73. package/src/eco/eco.types.d.ts +1 -1
  74. package/src/eco/eco.utils.d.ts +1 -40
  75. package/src/eco/eco.utils.js +5 -35
  76. package/src/eco/global-injector-map.d.ts +1 -1
  77. package/src/eco/lazy-injector-map.d.ts +1 -1
  78. package/src/hmr/hmr-strategy.d.ts +16 -13
  79. package/src/hmr/hmr-strategy.js +22 -7
  80. package/src/hmr/strategies/default-hmr-strategy.d.ts +2 -2
  81. package/src/hmr/strategies/default-hmr-strategy.js +1 -1
  82. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -2
  83. package/src/hmr/strategies/js-hmr-strategy.js +2 -2
  84. package/src/index.browser.d.ts +2 -2
  85. package/src/index.browser.js +1 -1
  86. package/src/index.d.ts +3 -2
  87. package/src/index.js +15 -4
  88. package/src/integrations/ghtml/ghtml-renderer.d.ts +6 -1
  89. package/src/integrations/ghtml/ghtml-renderer.js +29 -28
  90. package/src/integrations/ghtml/ghtml.plugin.d.ts +2 -2
  91. package/src/integrations/ghtml/ghtml.plugin.js +2 -2
  92. package/src/plugins/README.md +1 -0
  93. package/src/plugins/eco-component-meta-plugin.d.ts +12 -1
  94. package/src/plugins/eco-component-meta-plugin.js +26 -20
  95. package/src/plugins/foreign-jsx-override-plugin.d.ts +31 -0
  96. package/src/plugins/foreign-jsx-override-plugin.js +35 -0
  97. package/src/plugins/integration-plugin.d.ts +99 -33
  98. package/src/plugins/integration-plugin.js +68 -21
  99. package/src/plugins/processor.d.ts +2 -2
  100. package/src/plugins/processor.js +2 -2
  101. package/src/plugins/source-transform.d.ts +46 -0
  102. package/src/plugins/source-transform.js +71 -0
  103. package/src/route-renderer/GRAPH.md +54 -84
  104. package/src/route-renderer/README.md +14 -20
  105. package/src/route-renderer/orchestration/component-render-context.d.ts +83 -0
  106. package/src/route-renderer/orchestration/component-render-context.js +147 -0
  107. package/src/route-renderer/orchestration/integration-renderer.d.ts +233 -76
  108. package/src/route-renderer/orchestration/integration-renderer.js +500 -143
  109. package/src/route-renderer/orchestration/queued-boundary-runtime.service.d.ts +93 -0
  110. package/src/route-renderer/orchestration/queued-boundary-runtime.service.js +155 -0
  111. package/src/route-renderer/orchestration/render-execution.service.d.ts +11 -71
  112. package/src/route-renderer/orchestration/render-execution.service.js +65 -80
  113. package/src/{eco/eco.utils.ts → route-renderer/orchestration/render-output.utils.d.ts} +10 -53
  114. package/src/route-renderer/orchestration/render-output.utils.js +65 -0
  115. package/src/route-renderer/orchestration/render-preparation.service.d.ts +2 -8
  116. package/src/route-renderer/orchestration/render-preparation.service.js +10 -17
  117. package/src/route-renderer/orchestration/template-serialization.d.ts +38 -0
  118. package/src/route-renderer/orchestration/template-serialization.js +45 -0
  119. package/src/route-renderer/page-loading/dependency-resolver.d.ts +2 -2
  120. package/src/route-renderer/page-loading/dependency-resolver.js +10 -8
  121. package/src/route-renderer/page-loading/page-module-loader.d.ts +6 -4
  122. package/src/route-renderer/page-loading/page-module-loader.js +7 -5
  123. package/src/route-renderer/route-renderer.d.ts +5 -3
  124. package/src/route-renderer/route-renderer.js +13 -3
  125. package/src/router/README.md +79 -8
  126. package/src/router/client/navigation-coordinator.js +2 -2
  127. package/src/router/server/fs-router-scanner.d.ts +1 -1
  128. package/src/router/server/fs-router-scanner.js +6 -1
  129. package/src/router/server/fs-router.d.ts +1 -1
  130. package/src/services/assets/asset-processing-service/asset-processing.service.d.ts +3 -3
  131. package/src/services/assets/asset-processing-service/asset-processing.service.js +6 -6
  132. package/src/services/assets/asset-processing-service/asset.factory.d.ts +1 -1
  133. package/src/services/assets/asset-processing-service/asset.factory.js +2 -2
  134. package/src/services/assets/asset-processing-service/index.d.ts +5 -5
  135. package/src/services/assets/asset-processing-service/index.js +5 -5
  136. package/src/services/assets/asset-processing-service/processor.interface.d.ts +2 -2
  137. package/src/services/assets/asset-processing-service/processor.registry.d.ts +2 -2
  138. package/src/services/assets/asset-processing-service/processors/base/base-processor.d.ts +1 -1
  139. package/src/services/assets/asset-processing-service/processors/base/base-processor.js +1 -1
  140. package/src/services/assets/asset-processing-service/processors/base/base-script-processor.d.ts +3 -3
  141. package/src/services/assets/asset-processing-service/processors/base/base-script-processor.js +2 -2
  142. package/src/services/assets/asset-processing-service/processors/index.d.ts +5 -5
  143. package/src/services/assets/asset-processing-service/processors/index.js +5 -5
  144. package/src/services/assets/asset-processing-service/processors/script/content-script.processor.d.ts +2 -2
  145. package/src/services/assets/asset-processing-service/processors/script/content-script.processor.js +1 -1
  146. package/src/services/assets/asset-processing-service/processors/script/file-script.processor.d.ts +4 -3
  147. package/src/services/assets/asset-processing-service/processors/script/file-script.processor.js +15 -3
  148. package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.d.ts +3 -3
  149. package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.js +1 -1
  150. package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.d.ts +2 -2
  151. package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +1 -1
  152. package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts +2 -2
  153. package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +1 -1
  154. package/src/services/assets/browser-bundle.service.d.ts +1 -1
  155. package/src/services/assets/browser-bundle.service.js +2 -2
  156. package/src/services/html/html-rewriter-provider.service.js +4 -1
  157. package/src/services/html/html-transformer.service.d.ts +2 -2
  158. package/src/services/html/html-transformer.service.js +4 -10
  159. package/src/services/invalidation/development-invalidation.service.d.ts +1 -1
  160. package/src/services/invalidation/development-invalidation.service.js +1 -0
  161. package/src/services/module-loading/app-module-loader.service.d.ts +25 -0
  162. package/src/services/module-loading/app-module-loader.service.js +31 -0
  163. package/src/services/module-loading/app-server-module-transpiler.service.d.ts +9 -1
  164. package/src/services/module-loading/app-server-module-transpiler.service.js +77 -2
  165. package/src/services/module-loading/host-module-loader-registry.d.ts +4 -0
  166. package/src/services/module-loading/host-module-loader-registry.js +15 -0
  167. package/src/services/module-loading/module-loading-types.d.ts +2 -0
  168. package/src/{adapters/node/bootstrap-dependency-resolver.d.ts → services/module-loading/node-bootstrap-plugin.d.ts} +2 -24
  169. package/src/{adapters/node/bootstrap-dependency-resolver.js → services/module-loading/node-bootstrap-plugin.js} +42 -22
  170. package/src/services/module-loading/page-module-import.service.d.ts +4 -0
  171. package/src/services/module-loading/page-module-import.service.js +38 -9
  172. package/src/services/module-loading/server-module-transpiler.service.d.ts +3 -0
  173. package/src/services/module-loading/server-module-transpiler.service.js +4 -1
  174. package/src/services/runtime-state/dev-graph.service.d.ts +6 -6
  175. package/src/services/runtime-state/dev-graph.service.js +10 -10
  176. package/src/services/runtime-state/entrypoint-dependency-graph.service.d.ts +1 -1
  177. package/src/services/runtime-state/runtime-specifier-registry.service.d.ts +1 -1
  178. package/src/services/runtime-state/server-invalidation-state.service.d.ts +1 -1
  179. package/src/static-site-generator/static-site-generator.d.ts +2 -2
  180. package/src/static-site-generator/static-site-generator.js +1 -1
  181. package/src/{internal-types.d.ts → types/internal-types.d.ts} +24 -14
  182. package/src/{public-types.d.ts → types/public-types.d.ts} +30 -14
  183. package/src/types/public-types.js +0 -0
  184. package/src/utils/html-escaping.d.ts +7 -0
  185. package/src/utils/html-escaping.js +6 -0
  186. package/src/utils/locals-utils.d.ts +1 -1
  187. package/src/utils/parse-cli-args.d.ts +4 -1
  188. package/src/utils/parse-cli-args.js +16 -1
  189. package/src/utils/resolve-work-dir.js +1 -1
  190. package/src/watchers/project-watcher.d.ts +4 -4
  191. package/src/watchers/project-watcher.js +4 -10
  192. package/src/watchers/project-watcher.test-helpers.d.ts +2 -2
  193. package/src/adapters/abstract/application-adapter.ts +0 -337
  194. package/src/adapters/abstract/router-adapter.ts +0 -30
  195. package/src/adapters/abstract/server-adapter.ts +0 -79
  196. package/src/adapters/bun/client-bridge.ts +0 -62
  197. package/src/adapters/bun/create-app.ts +0 -189
  198. package/src/adapters/bun/hmr-manager.ts +0 -409
  199. package/src/adapters/bun/index.ts +0 -2
  200. package/src/adapters/bun/server-adapter.ts +0 -499
  201. package/src/adapters/bun/server-lifecycle.ts +0 -124
  202. package/src/adapters/index.ts +0 -6
  203. package/src/adapters/node/bootstrap-dependency-resolver.ts +0 -301
  204. package/src/adapters/node/create-app.ts +0 -179
  205. package/src/adapters/node/index.d.ts +0 -6
  206. package/src/adapters/node/index.js +0 -11
  207. package/src/adapters/node/index.ts +0 -16
  208. package/src/adapters/node/node-client-bridge.ts +0 -79
  209. package/src/adapters/node/node-hmr-manager.ts +0 -381
  210. package/src/adapters/node/runtime-adapter.d.ts +0 -46
  211. package/src/adapters/node/runtime-adapter.js +0 -306
  212. package/src/adapters/node/runtime-adapter.ts +0 -439
  213. package/src/adapters/node/server-adapter.ts +0 -488
  214. package/src/adapters/node/static-content-server.ts +0 -239
  215. package/src/adapters/node/write-runtime-manifest.d.ts +0 -26
  216. package/src/adapters/node/write-runtime-manifest.js +0 -12
  217. package/src/adapters/node/write-runtime-manifest.ts +0 -38
  218. package/src/adapters/shared/api-response.ts +0 -104
  219. package/src/adapters/shared/application-adapter.ts +0 -199
  220. package/src/adapters/shared/define-api-handler.ts +0 -66
  221. package/src/adapters/shared/explicit-static-route-matcher.ts +0 -140
  222. package/src/adapters/shared/file-route-middleware-pipeline.ts +0 -127
  223. package/src/adapters/shared/fs-server-response-factory.ts +0 -118
  224. package/src/adapters/shared/fs-server-response-matcher.ts +0 -205
  225. package/src/adapters/shared/hmr-entrypoint-registrar.ts +0 -149
  226. package/src/adapters/shared/hmr-html-response.ts +0 -52
  227. package/src/adapters/shared/render-context.ts +0 -120
  228. package/src/adapters/shared/runtime-bootstrap.ts +0 -79
  229. package/src/adapters/shared/server-adapter.ts +0 -489
  230. package/src/adapters/shared/server-route-handler.ts +0 -153
  231. package/src/adapters/shared/server-static-builder.ts +0 -166
  232. package/src/build/build-adapter.ts +0 -361
  233. package/src/build/build-manifest.ts +0 -54
  234. package/src/build/build-types.ts +0 -83
  235. package/src/build/dev-build-coordinator.ts +0 -221
  236. package/src/build/esbuild-build-adapter.ts +0 -559
  237. package/src/build/runtime-build-executor.ts +0 -34
  238. package/src/build/runtime-specifier-alias-plugin.ts +0 -58
  239. package/src/config/config-builder.ts +0 -706
  240. package/src/constants.ts +0 -54
  241. package/src/create-app.ts +0 -87
  242. package/src/dev/sc-server.ts +0 -143
  243. package/src/eco/component-render-context.d.ts +0 -105
  244. package/src/eco/component-render-context.js +0 -87
  245. package/src/eco/component-render-context.ts +0 -224
  246. package/src/eco/eco.ts +0 -242
  247. package/src/eco/eco.types.ts +0 -221
  248. package/src/eco/global-injector-map.ts +0 -112
  249. package/src/eco/lazy-injector-map.ts +0 -120
  250. package/src/eco/module-dependencies.ts +0 -75
  251. package/src/errors/http-error.ts +0 -72
  252. package/src/errors/index.ts +0 -2
  253. package/src/errors/locals-access-error.ts +0 -7
  254. package/src/global/app-logger.ts +0 -4
  255. package/src/hmr/client/hmr-runtime.ts +0 -152
  256. package/src/hmr/hmr-strategy.ts +0 -172
  257. package/src/hmr/hmr.postcss.test.e2e.ts +0 -41
  258. package/src/hmr/hmr.test.e2e.ts +0 -66
  259. package/src/hmr/strategies/default-hmr-strategy.ts +0 -60
  260. package/src/hmr/strategies/js-hmr-strategy.ts +0 -320
  261. package/src/index.browser.ts +0 -3
  262. package/src/index.ts +0 -5
  263. package/src/integrations/ghtml/ghtml-renderer.ts +0 -96
  264. package/src/integrations/ghtml/ghtml.plugin.ts +0 -32
  265. package/src/internal-types.ts +0 -232
  266. package/src/plugins/alias-resolver-plugin.ts +0 -63
  267. package/src/plugins/eco-component-meta-plugin.ts +0 -481
  268. package/src/plugins/integration-plugin.ts +0 -226
  269. package/src/plugins/processor.ts +0 -240
  270. package/src/plugins/runtime-capability.ts +0 -14
  271. package/src/public-types.ts +0 -1317
  272. package/src/route-renderer/component-graph/component-graph-executor.d.ts +0 -32
  273. package/src/route-renderer/component-graph/component-graph-executor.js +0 -31
  274. package/src/route-renderer/component-graph/component-graph-executor.ts +0 -84
  275. package/src/route-renderer/component-graph/component-graph.d.ts +0 -42
  276. package/src/route-renderer/component-graph/component-graph.js +0 -72
  277. package/src/route-renderer/component-graph/component-graph.ts +0 -159
  278. package/src/route-renderer/component-graph/component-marker.d.ts +0 -52
  279. package/src/route-renderer/component-graph/component-marker.js +0 -46
  280. package/src/route-renderer/component-graph/component-marker.ts +0 -117
  281. package/src/route-renderer/component-graph/component-reference.d.ts +0 -10
  282. package/src/route-renderer/component-graph/component-reference.js +0 -19
  283. package/src/route-renderer/component-graph/component-reference.ts +0 -29
  284. package/src/route-renderer/component-graph/marker-graph-resolver.d.ts +0 -77
  285. package/src/route-renderer/component-graph/marker-graph-resolver.js +0 -95
  286. package/src/route-renderer/component-graph/marker-graph-resolver.ts +0 -155
  287. package/src/route-renderer/orchestration/integration-renderer.ts +0 -790
  288. package/src/route-renderer/orchestration/render-execution.service.ts +0 -230
  289. package/src/route-renderer/orchestration/render-preparation.service.ts +0 -476
  290. package/src/route-renderer/page-loading/dependency-resolver.ts +0 -612
  291. package/src/route-renderer/page-loading/page-module-loader.ts +0 -181
  292. package/src/route-renderer/route-renderer.ts +0 -115
  293. package/src/router/client/link-intent.test.browser.ts +0 -51
  294. package/src/router/client/link-intent.ts +0 -92
  295. package/src/router/client/navigation-coordinator.ts +0 -433
  296. package/src/router/server/fs-router-scanner.ts +0 -219
  297. package/src/router/server/fs-router.ts +0 -122
  298. package/src/services/assets/asset-processing-service/asset-processing.service.ts +0 -401
  299. package/src/services/assets/asset-processing-service/asset.factory.ts +0 -105
  300. package/src/services/assets/asset-processing-service/assets.types.ts +0 -113
  301. package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.ts +0 -95
  302. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.ts +0 -78
  303. package/src/services/assets/asset-processing-service/index.ts +0 -5
  304. package/src/services/assets/asset-processing-service/processor.interface.ts +0 -27
  305. package/src/services/assets/asset-processing-service/processor.registry.ts +0 -18
  306. package/src/services/assets/asset-processing-service/processors/base/base-processor.ts +0 -82
  307. package/src/services/assets/asset-processing-service/processors/base/base-script-processor.ts +0 -95
  308. package/src/services/assets/asset-processing-service/processors/index.ts +0 -5
  309. package/src/services/assets/asset-processing-service/processors/script/content-script.processor.ts +0 -66
  310. package/src/services/assets/asset-processing-service/processors/script/file-script.processor.ts +0 -88
  311. package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.ts +0 -85
  312. package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.ts +0 -27
  313. package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.ts +0 -80
  314. package/src/services/assets/browser-bundle.service.ts +0 -53
  315. package/src/services/cache/cache.types.ts +0 -126
  316. package/src/services/cache/index.ts +0 -18
  317. package/src/services/cache/memory-cache-store.ts +0 -130
  318. package/src/services/cache/page-cache-service.ts +0 -202
  319. package/src/services/cache/page-request-cache-coordinator.service.ts +0 -131
  320. package/src/services/html/html-rewriter-provider.service.ts +0 -103
  321. package/src/services/html/html-transformer.service.ts +0 -279
  322. package/src/services/invalidation/development-invalidation.service.ts +0 -261
  323. package/src/services/module-loading/app-server-module-transpiler.service.ts +0 -52
  324. package/src/services/module-loading/page-module-import.service.ts +0 -200
  325. package/src/services/module-loading/server-loader.service.d.ts +0 -96
  326. package/src/services/module-loading/server-loader.service.js +0 -32
  327. package/src/services/module-loading/server-loader.service.ts +0 -130
  328. package/src/services/module-loading/server-module-transpiler.service.ts +0 -105
  329. package/src/services/runtime-manifest/node-runtime-manifest.service.d.ts +0 -35
  330. package/src/services/runtime-manifest/node-runtime-manifest.service.js +0 -60
  331. package/src/services/runtime-manifest/node-runtime-manifest.service.ts +0 -101
  332. package/src/services/runtime-state/dev-graph.service.ts +0 -217
  333. package/src/services/runtime-state/entrypoint-dependency-graph.service.ts +0 -136
  334. package/src/services/runtime-state/runtime-specifier-registry.service.ts +0 -96
  335. package/src/services/runtime-state/server-invalidation-state.service.ts +0 -68
  336. package/src/services/validation/schema-validation-service.ts +0 -204
  337. package/src/services/validation/standard-schema.types.ts +0 -68
  338. package/src/static-site-generator/static-site-generator.ts +0 -462
  339. package/src/utils/css.d.ts +0 -1
  340. package/src/utils/css.js +0 -7
  341. package/src/utils/css.ts +0 -5
  342. package/src/utils/deep-merge.ts +0 -47
  343. package/src/utils/hash.ts +0 -5
  344. package/src/utils/html.ts +0 -1
  345. package/src/utils/invariant.ts +0 -15
  346. package/src/utils/locals-utils.ts +0 -37
  347. package/src/utils/parse-cli-args.ts +0 -83
  348. package/src/utils/path-utils.module.ts +0 -14
  349. package/src/utils/resolve-work-dir.ts +0 -45
  350. package/src/utils/runtime.ts +0 -44
  351. package/src/utils/server-utils.module.ts +0 -67
  352. package/src/watchers/project-watcher.test-helpers.ts +0 -41
  353. package/src/watchers/project-watcher.ts +0 -363
  354. /package/src/{constants.d.ts → config/constants.d.ts} +0 -0
  355. /package/src/{constants.js → config/constants.js} +0 -0
  356. /package/src/{internal-types.js → services/module-loading/module-loading-types.js} +0 -0
  357. /package/src/{public-types.js → types/internal-types.js} +0 -0
@@ -1,489 +0,0 @@
1
- import path from 'node:path';
2
- import { AbstractServerAdapter } from '../abstract/server-adapter.ts';
3
- import type { ServerAdapterOptions, ServerAdapterResult } from '../abstract/server-adapter.ts';
4
- import { RouteRendererFactory } from '../../route-renderer/route-renderer.ts';
5
- import { FSRouter } from '../../router/server/fs-router.ts';
6
- import { FSRouterScanner } from '../../router/server/fs-router-scanner.ts';
7
- import { MemoryCacheStore } from '../../services/cache/memory-cache-store.ts';
8
- import { PageCacheService } from '../../services/cache/page-cache-service.ts';
9
- import { SchemaValidationService } from '../../services/validation/schema-validation-service.ts';
10
- import { StaticSiteGenerator } from '../../static-site-generator/static-site-generator.ts';
11
- import { ServerStaticBuilder } from './server-static-builder.ts';
12
- import { ExplicitStaticRouteMatcher } from './explicit-static-route-matcher.ts';
13
- import { FileSystemServerResponseFactory } from './fs-server-response-factory.ts';
14
- import { FileSystemResponseMatcher } from './fs-server-response-matcher.ts';
15
- import { ServerRouteHandler } from './server-route-handler.ts';
16
- import { createRenderContext } from './render-context.ts';
17
- import { createRequire } from '../../utils/locals-utils.ts';
18
- import { HttpError } from '../../errors/http-error.ts';
19
- import { ApiResponseBuilder } from './api-response.ts';
20
- import { appLogger } from '../../global/app-logger.ts';
21
- import { fileSystem } from '@ecopages/file-system';
22
- import type {
23
- ApiHandler,
24
- ApiHandlerContext,
25
- CacheInvalidator,
26
- ErrorHandler,
27
- RenderContext,
28
- StaticRoute,
29
- } from '../../public-types.ts';
30
-
31
- export abstract class SharedServerAdapter<
32
- TOptions extends ServerAdapterOptions,
33
- TResult extends ServerAdapterResult,
34
- > extends AbstractServerAdapter<TOptions, TResult> {
35
- protected router!: FSRouter;
36
- protected fileSystemResponseMatcher!: FileSystemResponseMatcher;
37
- protected routeRendererFactory!: RouteRendererFactory;
38
- protected routeHandler!: ServerRouteHandler;
39
- protected staticSiteGenerator!: StaticSiteGenerator;
40
- protected staticBuilder!: ServerStaticBuilder;
41
- protected readonly schemaValidator = new SchemaValidationService();
42
-
43
- protected async initializeSharedRouteHandling(options: {
44
- staticRoutes: StaticRoute[];
45
- hmrManager?: any;
46
- }): Promise<void> {
47
- await this.initSharedRouter();
48
- this.configureSharedResponseHandlers(options.staticRoutes, options.hmrManager);
49
- }
50
-
51
- protected createSharedWatchRefreshCallback(options: {
52
- staticRoutes: StaticRoute[];
53
- hmrManager?: any;
54
- onRoutesReady?: () => Promise<void> | void;
55
- onError?: (error: Error) => Promise<void> | void;
56
- }): () => Promise<void> {
57
- return async () => {
58
- try {
59
- await this.initializeSharedRouteHandling({
60
- staticRoutes: options.staticRoutes,
61
- hmrManager: options.hmrManager,
62
- });
63
-
64
- if (options.onRoutesReady) {
65
- await options.onRoutesReady();
66
- }
67
- } catch (error) {
68
- if (options.onError) {
69
- await options.onError(error instanceof Error ? error : new Error(String(error)));
70
- return;
71
- }
72
-
73
- throw error;
74
- }
75
- };
76
- }
77
-
78
- /**
79
- * Scans the filesystem and dynamically constructs the universal router map.
80
- *
81
- * This process runs identically across both Bun and Node wrappers. It analyzes the configured pages
82
- * directory, building a map of all available UI routes and API endpoints.
83
- * The resulting `FSRouter` instance becomes the central nervous system for mapping WinterCG incoming
84
- * Web Requests (`Request`) to their corresponding internal execution paths.
85
- */
86
- protected async initSharedRouter(): Promise<void> {
87
- const scanner = new FSRouterScanner({
88
- dir: path.join(this.appConfig.rootDir, this.appConfig.srcDir, this.appConfig.pagesDir),
89
- appConfig: this.appConfig,
90
- origin: this.runtimeOrigin,
91
- templatesExt: this.appConfig.templatesExt,
92
- options: {
93
- buildMode: !this.options?.watch,
94
- },
95
- });
96
-
97
- this.router = new FSRouter({
98
- origin: this.runtimeOrigin,
99
- assetPrefix: path.join(this.appConfig.rootDir, this.appConfig.distDir),
100
- scanner,
101
- });
102
-
103
- await this.router.init();
104
- }
105
-
106
- /**
107
- * Sets up the unified rendering pipeline and response matching chain.
108
- *
109
- * It bridges several sub-systems together so that when an incoming request is received, the adapter knows:
110
- * 1. How to render React/Lit pages via `RouteRendererFactory`
111
- * 2. How to match logical routes to physical filesystem artifacts via `FileSystemResponseMatcher`
112
- * 3. Whether to serve the response from the embedded `PageCacheService` or generate it fresh on the fly.
113
- *
114
- * Because `HmrManager` implementations rely heavily on runtime-specific WebSocket APIs (e.g. Bun.serve Websockets vs Node WS),
115
- * we leave it untyped (`any`) here at the common denominator core.
116
- *
117
- * @param staticRoutes - A map of explicitly served static assets.
118
- * @param hmrManager - The runtime-specific Hot Module Replacement orchestrator (if watching).
119
- */
120
- protected configureSharedResponseHandlers(staticRoutes: StaticRoute[], hmrManager?: any): void {
121
- this.routeRendererFactory = new RouteRendererFactory({
122
- appConfig: this.appConfig,
123
- runtimeOrigin: this.runtimeOrigin,
124
- });
125
-
126
- const fileSystemResponseFactory = new FileSystemServerResponseFactory({
127
- appConfig: this.appConfig,
128
- routeRendererFactory: this.routeRendererFactory,
129
- options: {
130
- watchMode: !!this.options?.watch,
131
- },
132
- });
133
-
134
- const cacheConfig = this.appConfig.cache;
135
- const isCacheEnabled = cacheConfig?.enabled ?? !this.options?.watch;
136
- let cacheService: PageCacheService | null = null;
137
-
138
- if (isCacheEnabled) {
139
- const store =
140
- cacheConfig?.store === 'memory' || !cacheConfig?.store
141
- ? new MemoryCacheStore({ maxEntries: cacheConfig?.maxEntries })
142
- : cacheConfig.store;
143
- cacheService = new PageCacheService({ store, enabled: true });
144
- }
145
-
146
- this.fileSystemResponseMatcher = new FileSystemResponseMatcher({
147
- appConfig: this.appConfig,
148
- router: this.router,
149
- routeRendererFactory: this.routeRendererFactory,
150
- fileSystemResponseFactory,
151
- cacheService,
152
- defaultCacheStrategy: cacheConfig?.defaultStrategy ?? 'static',
153
- });
154
-
155
- const explicitStaticRouteMatcher =
156
- staticRoutes.length > 0
157
- ? new ExplicitStaticRouteMatcher({
158
- appConfig: this.appConfig,
159
- routeRendererFactory: this.routeRendererFactory,
160
- staticRoutes,
161
- })
162
- : undefined;
163
-
164
- this.routeHandler = new ServerRouteHandler({
165
- router: this.router,
166
- fileSystemResponseMatcher: this.fileSystemResponseMatcher,
167
- explicitStaticRouteMatcher,
168
- watch: !!this.options?.watch,
169
- hmrManager,
170
- });
171
- }
172
-
173
- protected getCacheService(): CacheInvalidator | null {
174
- return this.fileSystemResponseMatcher?.getCacheService() ?? null;
175
- }
176
-
177
- protected getRenderContext(): RenderContext {
178
- return createRenderContext({ integrations: this.appConfig.integrations });
179
- }
180
-
181
- /**
182
- * Executes an Application Programming Interface (API) handler in an environment-agnostic manner.
183
- *
184
- * API routes in Ecopages are universally written using standard WinterCG `Request` and `Response` objects.
185
- * This execution pipeline takes the raw `Request`, extracts its dynamic segments, runs our high-speed JSON schema
186
- * validator against the body/query/headers, and triggers the developer's middleware chain sequentially.
187
- *
188
- * If the execution throws an error, it is gracefully caught, logged, and mutated into a standardized Http error payload,
189
- * ensuring the consuming client receives a parsable response even upon internal catastrophic failure.
190
- *
191
- * @param request - The incoming Web standard `Request`.
192
- * @param params - The extracted dynamic URL parameters (e.g., `{ id: '123' }`).
193
- * @param routeConfig - The user-defined API handler object containing their business logic (`handler`) and `middleware`.
194
- * @param serverInstance - Untyped reference to the underlying native server instance (BunServer/NodeServer) for potential escape hatches.
195
- * @param errorHandler - Optional global error trap defined in project configuration.
196
- * @returns The resulting Web standard `Response` constructed by the user's handler.
197
- */
198
- protected async executeApiHandler(
199
- request: Request,
200
- params: Record<string, string | string[]>,
201
- routeConfig: ApiHandler,
202
- serverInstance: any,
203
- errorHandler?: ErrorHandler,
204
- ): Promise<Response> {
205
- let context: ApiHandlerContext<Request, any> | undefined;
206
-
207
- try {
208
- const middleware = routeConfig.middleware || [];
209
- const schema = routeConfig.schema;
210
- const locals: Record<string, unknown> = {};
211
-
212
- const normalizedParams = Object.fromEntries(
213
- Object.entries(params).map(([key, value]) => [key, Array.isArray(value) ? value.join('/') : value]),
214
- );
215
-
216
- context = {
217
- request,
218
- params: normalizedParams,
219
- response: new ApiResponseBuilder(),
220
- server: serverInstance,
221
- locals,
222
- require: createRequire((): Record<string, unknown> => locals),
223
- services: {
224
- cache: this.getCacheService(),
225
- },
226
- ...this.getRenderContext(),
227
- };
228
-
229
- if (schema) {
230
- const url = new URL(request.url);
231
- const queryParams = Object.fromEntries(url.searchParams);
232
- const headers = Object.fromEntries(request.headers);
233
-
234
- let body: unknown;
235
- if (schema.body) {
236
- try {
237
- const contentType = request.headers.get('Content-Type') || '';
238
- if (contentType.includes('application/json')) body = await request.clone().json();
239
- else if (contentType.includes('text/plain')) body = await request.clone().text();
240
- } catch {
241
- return context.response.status(400).json({ error: 'Invalid request body' });
242
- }
243
- }
244
-
245
- const validationResult = await this.schemaValidator.validateRequest(
246
- { body, query: queryParams, headers, params: normalizedParams },
247
- schema,
248
- );
249
-
250
- if (!validationResult.success) {
251
- return context.response.status(400).json({
252
- error: 'Validation failed',
253
- issues: validationResult.errors,
254
- });
255
- }
256
-
257
- const validated = validationResult.data!;
258
- if (validated.body !== undefined) context.body = validated.body;
259
- if (validated.query !== undefined) context.query = validated.query;
260
- if (validated.headers !== undefined) context.headers = validated.headers;
261
- if (validated.params !== undefined) context.params = validated.params as Record<string, string>;
262
- }
263
-
264
- if (middleware.length === 0) {
265
- return await routeConfig.handler(context);
266
- }
267
-
268
- let index = 0;
269
- const executeNext = async (): Promise<Response> => {
270
- if (index < middleware.length) {
271
- const currentMiddleware = middleware[index++];
272
- return await currentMiddleware(context!, executeNext);
273
- }
274
- return await routeConfig.handler(context!);
275
- };
276
-
277
- return await executeNext();
278
- } catch (error) {
279
- if (error instanceof Response) return error;
280
-
281
- if (errorHandler) {
282
- try {
283
- if (!context) {
284
- const locals: Record<string, unknown> = {};
285
- context = {
286
- request,
287
- params: Object.fromEntries(
288
- Object.entries(params).map(([key, value]) => [
289
- key,
290
- Array.isArray(value) ? value.join('/') : value,
291
- ]),
292
- ),
293
- response: new ApiResponseBuilder(),
294
- server: serverInstance,
295
- locals,
296
- require: createRequire((): Record<string, unknown> => locals),
297
- services: { cache: this.getCacheService() },
298
- ...this.getRenderContext(),
299
- };
300
- }
301
- return await errorHandler(error, context);
302
- } catch (handlerError) {
303
- appLogger.error(`[ecopages] Error in custom error handler: ${handlerError}`);
304
- }
305
- }
306
-
307
- if (error instanceof HttpError) return error.toResponse();
308
- appLogger.error(`[ecopages] Error handling API request: ${error}`);
309
- return new Response('Internal Server Error', { status: 500 });
310
- }
311
- }
312
-
313
- private normalizePath(pathname: string): string {
314
- if (pathname.length > 1 && pathname.endsWith('/')) {
315
- return pathname.slice(0, -1);
316
- }
317
-
318
- return pathname;
319
- }
320
-
321
- private matchApiPath(pattern: string, pathname: string): Record<string, string | string[]> | null {
322
- const normalizedPattern = this.normalizePath(pattern);
323
- const normalizedPathname = this.normalizePath(pathname);
324
-
325
- const patternSegments = normalizedPattern.split('/').filter(Boolean);
326
- const pathSegments = normalizedPathname.split('/').filter(Boolean);
327
- const params: Record<string, string | string[]> = {};
328
-
329
- let patternIndex = 0;
330
- let pathIndex = 0;
331
-
332
- while (patternIndex < patternSegments.length && pathIndex < pathSegments.length) {
333
- const patternSegment = patternSegments[patternIndex];
334
- const pathSegment = pathSegments[pathIndex];
335
-
336
- if (patternSegment === '*') {
337
- return params;
338
- }
339
-
340
- if (patternSegment.startsWith('[...') && patternSegment.endsWith(']')) {
341
- const paramName = patternSegment.slice(4, -1);
342
- params[paramName] = pathSegments.slice(pathIndex);
343
- return params;
344
- }
345
-
346
- if (patternSegment.startsWith(':')) {
347
- params[patternSegment.slice(1)] = pathSegment;
348
- patternIndex++;
349
- pathIndex++;
350
- continue;
351
- }
352
-
353
- if (patternSegment.startsWith('[') && patternSegment.endsWith(']')) {
354
- params[patternSegment.slice(1, -1)] = pathSegment;
355
- patternIndex++;
356
- pathIndex++;
357
- continue;
358
- }
359
-
360
- if (patternSegment !== pathSegment) {
361
- return null;
362
- }
363
-
364
- patternIndex++;
365
- pathIndex++;
366
- }
367
-
368
- if (patternIndex < patternSegments.length) {
369
- const remaining = patternSegments.slice(patternIndex);
370
- const catchAll = remaining[0];
371
-
372
- if (
373
- remaining.length === 1 &&
374
- (catchAll === '*' || (catchAll.startsWith('[...') && catchAll.endsWith(']')))
375
- ) {
376
- if (catchAll.startsWith('[...')) {
377
- const paramName = catchAll.slice(4, -1);
378
- params[paramName] = [];
379
- }
380
- return params;
381
- }
382
-
383
- return null;
384
- }
385
-
386
- if (pathIndex < pathSegments.length) {
387
- return null;
388
- }
389
-
390
- return params;
391
- }
392
-
393
- private getApiPathScore(pattern: string): number {
394
- const segments = this.normalizePath(pattern).split('/').filter(Boolean);
395
- let score = 0;
396
- for (const segment of segments) {
397
- if (segment === '*' || (segment.startsWith('[...') && segment.endsWith(']'))) {
398
- score += 10;
399
- } else if (segment.startsWith(':') || (segment.startsWith('[') && segment.endsWith(']'))) {
400
- score += 50;
401
- } else {
402
- score += 100;
403
- }
404
- }
405
- return score;
406
- }
407
-
408
- protected matchApiHandler(
409
- request: Request,
410
- apiHandlers: ApiHandler[],
411
- ): { routeConfig: ApiHandler; params: Record<string, string | string[]> } | null {
412
- const pathname = new URL(request.url).pathname;
413
- const method = request.method.toUpperCase();
414
-
415
- const sortedHandlers = [...apiHandlers].sort((a, b) => {
416
- return this.getApiPathScore(b.path) - this.getApiPathScore(a.path);
417
- });
418
-
419
- for (const routeConfig of sortedHandlers) {
420
- const routeMethod = (routeConfig.method || 'GET').toUpperCase();
421
- if (routeMethod !== method) {
422
- continue;
423
- }
424
-
425
- const params = this.matchApiPath(routeConfig.path, pathname);
426
- if (params) {
427
- return { routeConfig, params };
428
- }
429
- }
430
-
431
- return null;
432
- }
433
-
434
- /**
435
- * Universally processes an incoming WinterCG Web standard Request.
436
- *
437
- * 1. Resolves static Hot Module Replacement runtime blobs if development.
438
- * 2. Checks if the incoming request matches any parsed API route schemas.
439
- * - Routes through `executeApiHandler` which performs strict validation.
440
- * 3. Falls through to standard `ServerRouteHandler` for React/Lit filesystem pages.
441
- *
442
- * Both Bun and Node bindings fall back to this exact function once they have mapped their
443
- * native HTTP objects into Web Standard Requests.
444
- */
445
- public async handleSharedRequest(
446
- request: Request,
447
- context: {
448
- apiHandlers: ApiHandler[];
449
- errorHandler?: ErrorHandler;
450
- serverInstance?: any;
451
- hmrManager?: any;
452
- },
453
- ): Promise<Response> {
454
- const url = new URL(request.url);
455
-
456
- if (url.pathname === '/_hmr_runtime.js' && context.hmrManager) {
457
- const runtimePath = context.hmrManager.getRuntimePath();
458
- if (fileSystem.exists(runtimePath)) {
459
- return new Response(fileSystem.readFileAsBuffer(runtimePath) as BodyInit, {
460
- headers: { 'Content-Type': 'application/javascript' },
461
- });
462
- }
463
- }
464
-
465
- if (url.pathname.startsWith('/assets/_hmr/') && context.hmrManager) {
466
- const relativePath = url.pathname.slice('/assets/_hmr/'.length);
467
- const assetPath = path.join(context.hmrManager.getDistDir(), relativePath);
468
-
469
- if (fileSystem.exists(assetPath)) {
470
- return new Response(fileSystem.readFileAsBuffer(assetPath) as BodyInit, {
471
- headers: { 'Content-Type': 'application/javascript' },
472
- });
473
- }
474
- }
475
-
476
- const apiMatch = this.matchApiHandler(request, context.apiHandlers);
477
- if (apiMatch) {
478
- return this.executeApiHandler(
479
- request,
480
- apiMatch.params,
481
- apiMatch.routeConfig,
482
- context.serverInstance,
483
- context.errorHandler,
484
- );
485
- }
486
-
487
- return this.routeHandler.handleResponse(request);
488
- }
489
- }
@@ -1,153 +0,0 @@
1
- import type { IHmrManager } from '../../public-types';
2
- import type { FSRouter } from '../../router/server/fs-router';
3
- import type { ExplicitStaticRouteMatcher } from './explicit-static-route-matcher';
4
- import type { FileSystemResponseMatcher } from './fs-server-response-matcher';
5
- import { appLogger } from '../../global/app-logger';
6
- import { HttpError } from '../../errors/http-error';
7
- import { injectHmrRuntimeIntoHtmlResponse, isHtmlResponse, shouldInjectHmrHtmlResponse } from './hmr-html-response';
8
-
9
- /**
10
- * Configuration parameters for ServerRouteHandler.
11
- */
12
- export interface ServerRouteHandlerParams {
13
- /** File system router for matching request URLs to route handlers. */
14
- router: FSRouter;
15
- /** Matcher for handling file system route responses. */
16
- fileSystemResponseMatcher: FileSystemResponseMatcher;
17
- /** Optional matcher for explicit static routes like processed images or sitemaps. */
18
- explicitStaticRouteMatcher?: ExplicitStaticRouteMatcher;
19
- /** Enable watch mode for development. */
20
- watch?: boolean;
21
- /** HMR manager for broadcasting hot module reload events in development. */
22
- hmrManager?: IHmrManager;
23
- }
24
-
25
- /**
26
- * Handles HTTP requests and routing for the server.
27
- *
28
- * This class manages the request routing flow with a priority-based approach:
29
- * 1. Explicit static routes (highest priority - intentional mappings like /sitemap.xml)
30
- * 2. File-based routes without extensions (application routes)
31
- * 3. Static file fallback (lowest priority - disk serving)
32
- *
33
- * In development mode, it also injects HMR scripts into HTML responses.
34
- */
35
- export class ServerRouteHandler {
36
- private readonly router: FSRouter;
37
- private readonly fileSystemResponseMatcher: FileSystemResponseMatcher;
38
- private readonly explicitStaticRouteMatcher?: ExplicitStaticRouteMatcher;
39
- private readonly watch: boolean;
40
- private readonly hmrManager?: IHmrManager;
41
-
42
- /**
43
- * Creates a new ServerRouteHandler instance.
44
- *
45
- * @param params - Configuration parameters
46
- */
47
- constructor({
48
- router,
49
- fileSystemResponseMatcher,
50
- explicitStaticRouteMatcher,
51
- watch = false,
52
- hmrManager,
53
- }: ServerRouteHandlerParams) {
54
- this.router = router;
55
- this.fileSystemResponseMatcher = fileSystemResponseMatcher;
56
- this.explicitStaticRouteMatcher = explicitStaticRouteMatcher;
57
- this.watch = watch;
58
- this.hmrManager = hmrManager;
59
- }
60
-
61
- /**
62
- * Determines if HMR script should be injected.
63
- *
64
- * @returns true if in watch mode and HMR manager is enabled
65
- */
66
- shouldInjectHmrScript(): boolean {
67
- return shouldInjectHmrHtmlResponse(this.watch, this.hmrManager);
68
- }
69
-
70
- /**
71
- * Checks if a response contains HTML content.
72
- *
73
- * @param response - The HTTP response to check
74
- * @returns true if Content-Type header starts with 'text/html'
75
- */
76
- isHtmlResponse(response: Response): boolean {
77
- return isHtmlResponse(response);
78
- }
79
-
80
- /**
81
- * Handles HTTP requests from the router adapter.
82
- *
83
- * Priority-based routing flow:
84
- * 1. Check explicit static routes first (e.g., /sitemap.xml, /image.webp from plugins)
85
- * 2. Match file-based routes without extensions (application routes)
86
- * 3. Fall back to static file serving from disk
87
- *
88
- * @param request - The incoming HTTP request
89
- * @returns HTTP response, potentially with injected HMR script in dev mode
90
- */
91
- async handleResponse(request: Request): Promise<Response> {
92
- const pathname = new URL(request.url).pathname;
93
-
94
- const explicitMatch = this.explicitStaticRouteMatcher?.match(request.url);
95
-
96
- if (explicitMatch) {
97
- const response = await this.explicitStaticRouteMatcher!.handleMatch(explicitMatch);
98
- return this.maybeInjectHmrScript(response);
99
- }
100
-
101
- const fsMatch = !pathname.includes('.') && this.router.match(request.url);
102
-
103
- const response = await (fsMatch
104
- ? this.fileSystemResponseMatcher.handleMatch(fsMatch, request)
105
- : this.handleNoMatch(request));
106
-
107
- return this.maybeInjectHmrScript(response);
108
- }
109
-
110
- /**
111
- * Injects HMR script into HTML responses in development mode.
112
- *
113
- * The script is inserted before the closing </html> tag to enable
114
- * hot module reloading without full page refreshes.
115
- *
116
- * @param response - The HTTP response to potentially modify
117
- * @returns Original response or modified response with HMR script
118
- */
119
- private async maybeInjectHmrScript(response: Response): Promise<Response> {
120
- if (this.shouldInjectHmrScript() && this.isHtmlResponse(response)) {
121
- return injectHmrRuntimeIntoHtmlResponse(response);
122
- }
123
-
124
- return response;
125
- }
126
-
127
- /**
128
- * Handles requests that do not match any routes.
129
- *
130
- * This is the final fallback that attempts to serve static files from disk.
131
- * If the requested path corresponds to an HTML file or no file is found,
132
- * a custom 404 response is returned.
133
- *
134
- * @param request - The HTTP request to handle
135
- * @returns Response from file system or error response
136
- * @throws HttpError for standard HTTP errors
137
- */
138
- async handleNoMatch(request: Request): Promise<Response> {
139
- try {
140
- const pathname = new URL(request.url).pathname;
141
- return await this.fileSystemResponseMatcher.handleNoMatch(pathname);
142
- } catch (error) {
143
- if (error instanceof HttpError) {
144
- return error.toResponse();
145
- }
146
- if (error instanceof Error) {
147
- this.hmrManager?.broadcast({ type: 'error', message: error.message });
148
- appLogger.error('Error handling no match:', error);
149
- }
150
- return new Response('Internal Server Error', { status: 500 });
151
- }
152
- }
153
- }