@ecopages/core 0.2.0-rc.0 → 0.2.0-rc.10

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 (184) hide show
  1. package/README.md +52 -33
  2. package/package.json +58 -4
  3. package/src/adapters/README.md +3 -1
  4. package/src/adapters/abstract/application-adapter.d.ts +28 -6
  5. package/src/adapters/abstract/application-adapter.js +58 -5
  6. package/src/adapters/abstract/segment-path-matcher.js +56 -38
  7. package/src/adapters/abstract/server-adapter.d.ts +14 -0
  8. package/src/adapters/abstract/server-adapter.js +10 -0
  9. package/src/adapters/bun/create-app.d.ts +10 -6
  10. package/src/adapters/bun/create-app.js +64 -37
  11. package/src/adapters/bun/server-adapter.d.ts +6 -2
  12. package/src/adapters/bun/server-adapter.js +14 -1
  13. package/src/adapters/create-app.d.ts +62 -7
  14. package/src/adapters/create-app.js +61 -5
  15. package/src/adapters/node/create-app.d.ts +5 -5
  16. package/src/adapters/node/create-app.js +18 -5
  17. package/src/adapters/node/runtime-host.js +9 -4
  18. package/src/adapters/node/server-adapter.d.ts +5 -1
  19. package/src/adapters/node/server-adapter.js +16 -1
  20. package/src/adapters/shared/http/define-api-handler.d.ts +7 -49
  21. package/src/adapters/shared/http/explicit-static-route-matcher.js +5 -2
  22. package/src/adapters/shared/http/fs-server-response-factory.d.ts +2 -8
  23. package/src/adapters/shared/http/fs-server-response-factory.js +5 -30
  24. package/src/adapters/shared/http/fs-server-response-matcher.d.ts +24 -24
  25. package/src/adapters/shared/http/fs-server-response-matcher.js +59 -83
  26. package/src/adapters/shared/runtime/application-adapter.d.ts +1 -0
  27. package/src/adapters/shared/runtime/application-adapter.js +12 -0
  28. package/src/adapters/shared/runtime/bind-runtime-server.d.ts +17 -0
  29. package/src/adapters/shared/runtime/bind-runtime-server.js +50 -0
  30. package/src/adapters/shared/runtime/port-manager-default-prompt.d.ts +6 -0
  31. package/src/adapters/shared/runtime/port-manager-default-prompt.js +41 -0
  32. package/src/adapters/shared/runtime/port-manager.d.ts +3 -3
  33. package/src/adapters/shared/runtime/port-manager.js +14 -45
  34. package/src/adapters/shared/runtime/server-adapter.d.ts +14 -5
  35. package/src/adapters/shared/runtime/server-adapter.js +22 -30
  36. package/src/adapters/shared/runtime/server-route-handler.js +11 -3
  37. package/src/adapters/shared/runtime/server-static-builder.d.ts +9 -3
  38. package/src/adapters/shared/runtime/server-static-builder.js +59 -37
  39. package/src/build/README.md +5 -1
  40. package/src/build/cache/server-entry-build-cache.d.ts +24 -1
  41. package/src/build/cache/server-entry-build-cache.js +125 -8
  42. package/src/build/contracts/content-virtual-modules.d.ts +3 -1
  43. package/src/build/contracts/content-virtual-modules.js +8 -0
  44. package/src/build/rolldown/rolldown-adapter-helpers.js +56 -31
  45. package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
  46. package/src/build/rolldown/runtime-build-output-normalizer.js +3 -29
  47. package/src/build/runtime/build-request-policy.js +1 -1
  48. package/src/build/server-bundle-publication.d.ts +14 -0
  49. package/src/build/server-bundle-publication.js +49 -0
  50. package/src/config/README.md +17 -2
  51. package/src/config/apply-user-config.d.ts +6 -0
  52. package/src/config/apply-user-config.js +67 -0
  53. package/src/config/config-builder.d.ts +10 -1
  54. package/src/config/config-builder.js +51 -10
  55. package/src/config/constants.d.ts +4 -0
  56. package/src/config/constants.js +4 -0
  57. package/src/config/define-config.d.ts +9 -0
  58. package/src/config/define-config.js +10 -0
  59. package/src/config/index.d.ts +5 -0
  60. package/src/config/index.js +4 -0
  61. package/src/config/is-finalized-app-config.d.ts +6 -0
  62. package/src/config/is-finalized-app-config.js +11 -0
  63. package/src/config/load-eco-config.d.ts +21 -0
  64. package/src/config/load-eco-config.js +100 -0
  65. package/src/config/resolve-eco-config-path.d.ts +23 -0
  66. package/src/config/resolve-eco-config-path.js +47 -0
  67. package/src/config/server-config-bundle.d.ts +25 -0
  68. package/src/config/server-config-bundle.js +148 -0
  69. package/src/config/user-config-types.d.ts +164 -0
  70. package/src/config/user-config-types.js +1 -0
  71. package/src/css-imports.d.ts +4 -0
  72. package/src/declarations.d.ts +11 -5
  73. package/src/dev/README.md +6 -0
  74. package/src/dev/development-restart-watch-paths.d.ts +13 -0
  75. package/src/dev/development-restart-watch-paths.js +37 -0
  76. package/src/dev/development-restart.d.ts +13 -0
  77. package/src/dev/development-restart.js +21 -0
  78. package/src/dev/transform-server/dev-transform-server.d.ts +6 -0
  79. package/src/dev/transform-server/dev-transform-server.js +16 -5
  80. package/src/eco/README.md +73 -5
  81. package/src/eco/component-identity.d.ts +3 -2
  82. package/src/eco/component-identity.js +5 -2
  83. package/src/eco/discovered-dependencies.d.ts +45 -0
  84. package/src/eco/discovered-dependencies.js +87 -0
  85. package/src/eco/eco.js +6 -0
  86. package/src/eco/eco.types.d.ts +18 -2
  87. package/src/eco/lazy-injector-map.js +57 -41
  88. package/src/eco/page-dependency-contributions.d.ts +19 -0
  89. package/src/eco/page-dependency-contributions.js +52 -0
  90. package/src/errors/http-error-page-contract.d.ts +77 -0
  91. package/src/errors/http-error-page-contract.js +106 -0
  92. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
  93. package/src/hmr/strategies/js-hmr-strategy.js +24 -16
  94. package/src/index.browser.d.ts +3 -0
  95. package/src/index.browser.js +3 -0
  96. package/src/index.d.ts +4 -1
  97. package/src/index.js +4 -1
  98. package/src/islands/README.md +5 -1
  99. package/src/plugins/README.md +10 -2
  100. package/src/plugins/component-import-discovery.d.ts +19 -0
  101. package/src/plugins/component-import-discovery.js +241 -0
  102. package/src/plugins/eco-component-meta-plugin.d.ts +3 -1
  103. package/src/plugins/eco-component-meta-plugin.js +118 -16
  104. package/src/plugins/integration-plugin.d.ts +4 -9
  105. package/src/plugins/processor.d.ts +23 -2
  106. package/src/plugins/processor.js +25 -0
  107. package/src/plugins/tsconfig-import-resolver.d.ts +3 -1
  108. package/src/plugins/tsconfig-import-resolver.js +4 -2
  109. package/src/route-renderer/GRAPH.md +1 -1
  110. package/src/route-renderer/README.md +16 -3
  111. package/src/{adapters/shared/http/explicit-static-render-preparation.d.ts → route-renderer/explicit-view-render-preparation.d.ts} +3 -3
  112. package/src/route-renderer/orchestration/custom-element-scripts/README.md +9 -0
  113. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +16 -0
  114. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +34 -0
  115. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +80 -0
  116. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +190 -0
  117. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +17 -0
  118. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +41 -0
  119. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +10 -0
  120. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +46 -0
  121. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +7 -2
  122. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +2 -0
  123. package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.d.ts +13 -1
  124. package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.js +15 -0
  125. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +11 -2
  126. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +10 -2
  127. package/src/route-renderer/orchestration/integration-renderer.d.ts +11 -5
  128. package/src/route-renderer/orchestration/integration-renderer.js +42 -29
  129. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +2 -5
  130. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +2 -68
  131. package/src/route-renderer/orchestration/ownership-graph/component-graph.js +55 -39
  132. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +6 -0
  133. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +59 -36
  134. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +8 -10
  135. package/src/route-renderer/orchestration/string-markup-renderer.d.ts +1 -1
  136. package/src/route-renderer/orchestration/string-markup-renderer.js +10 -8
  137. package/src/route-renderer/page-loading/component-dependency-collection.d.ts +6 -2
  138. package/src/route-renderer/page-loading/component-dependency-collection.js +113 -68
  139. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
  140. package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +10 -3
  141. package/src/route-renderer/page-loading/file-scoped-dependency-components.js +62 -25
  142. package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
  143. package/src/route-renderer/page-loading/resolved-page-dependencies.d.ts +1 -2
  144. package/src/route-renderer/page-loading/resolved-page-dependencies.js +8 -7
  145. package/src/route-renderer/route-renderer.d.ts +9 -0
  146. package/src/route-renderer/route-renderer.js +18 -0
  147. package/src/router/README.md +7 -1
  148. package/src/router/server/route-registry.d.ts +13 -0
  149. package/src/router/server/route-registry.js +46 -32
  150. package/src/services/README.md +5 -0
  151. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +36 -9
  152. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +122 -37
  153. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +2 -0
  154. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +13 -2
  155. package/src/services/assets/asset-processing-service/page-package.js +42 -39
  156. package/src/services/error-pages/README.md +9 -0
  157. package/src/services/error-pages/default-error-pages.d.ts +44 -0
  158. package/src/services/error-pages/default-error-pages.js +207 -0
  159. package/src/services/error-pages/error-page-renderer.d.ts +58 -0
  160. package/src/services/error-pages/error-page-renderer.js +146 -0
  161. package/src/services/error-pages/semantic-error-page-exporter.d.ts +23 -0
  162. package/src/services/error-pages/semantic-error-page-exporter.js +35 -0
  163. package/src/services/invalidation/development-invalidation.service.d.ts +7 -1
  164. package/src/services/invalidation/development-invalidation.service.js +35 -3
  165. package/src/services/module-loading/README.md +16 -13
  166. package/src/services/module-loading/app-server-module-transpiler.service.js +2 -0
  167. package/src/services/module-loading/collection-server-module-build.service.d.ts +1 -0
  168. package/src/services/module-loading/collection-server-module-build.service.js +5 -2
  169. package/src/services/module-loading/page-module-import.service.d.ts +8 -0
  170. package/src/services/module-loading/page-module-import.service.js +62 -28
  171. package/src/services/module-loading/route-module-dependency-hasher.js +13 -1
  172. package/src/services/module-loading/view-module-loader.d.ts +10 -0
  173. package/src/services/module-loading/view-module-loader.js +46 -0
  174. package/src/services/validation/schema-validation-service.d.ts +1 -0
  175. package/src/services/validation/schema-validation-service.js +23 -36
  176. package/src/static-site-generator/README.md +6 -1
  177. package/src/static-site-generator/static-site-generator.d.ts +7 -2
  178. package/src/static-site-generator/static-site-generator.js +90 -49
  179. package/src/types/internal-types.d.ts +6 -1
  180. package/src/types/public-types.d.ts +34 -24
  181. package/src/utils/parse-cli-args.js +29 -22
  182. package/src/watchers/project-watcher.d.ts +14 -1
  183. package/src/watchers/project-watcher.js +85 -34
  184. /package/src/{adapters/shared/http/explicit-static-render-preparation.js → route-renderer/explicit-view-render-preparation.js} +0 -0
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import { availableParallelism } from 'node:os';
3
3
  import { appLogger } from '../global/app-logger.js';
4
4
  import { fileSystem } from '@ecopages/file-system';
5
- import { prepareExplicitStaticRender } from '../adapters/shared/http/explicit-static-render-preparation.js';
5
+ import { prepareExplicitStaticRender } from '../route-renderer/explicit-view-render-preparation.js';
6
6
  import { createRouteModuleStaticRenderCacheContext } from './static-build-invalidation.js';
7
7
  import { getServerModuleBuildCacheOutdir, getSharedRouteModuleBuildCache, } from '../services/module-loading/route-module-build-cache-registry.js';
8
8
  import { ensurePagesUnifiedGraphBuilt, shouldBuildPagesUnifiedGraph, } from '../build/cache/pages-unified-graph-build.js';
@@ -12,6 +12,8 @@ import { renderSitemap } from './sitemap.js';
12
12
  import { resolveSitemapLocations } from './sitemap-routes.js';
13
13
  import { toEcopagesRouteInfo } from '../utils/ecopages-route-info.js';
14
14
  import { normalizePathname } from '../utils/path-pattern.js';
15
+ import { ErrorPageRenderer } from '../services/error-pages/error-page-renderer.js';
16
+ import { SemanticErrorPageExporter, SEMANTIC_ERROR_PAGE_PATHNAMES, } from '../services/error-pages/semantic-error-page-exporter.js';
15
17
  export const STATIC_SITE_GENERATOR_ERRORS = {
16
18
  ROUTE_RENDERER_FACTORY_REQUIRED: 'RouteRendererFactory is required for render strategy',
17
19
  unsupportedBodyType: (bodyType) => `Unsupported body type for static generation: ${bodyType}`,
@@ -319,13 +321,7 @@ export class StaticSiteGenerator {
319
321
  }
320
322
  }
321
323
  }
322
- /**
323
- * Executes the full static-generation workflow for one app run.
324
- */
325
- async run({ router, baseUrl, routeRendererFactory, staticRoutes, force = false, preserveExportDirectory = false, }) {
326
- const skippedDynamicPages = [];
327
- const activeStaticPathnames = new Set();
328
- const sitemapEligiblePathnames = this.appConfig.sitemap?.enabled ? new Set() : undefined;
324
+ resetStaticGenerationState(force) {
329
325
  this.forceFullStaticGeneration = force;
330
326
  this.staticRenderCacheContext = createRouteModuleStaticRenderCacheContext(this.appConfig);
331
327
  this.pageModuleLoader = undefined;
@@ -335,16 +331,83 @@ export class StaticSiteGenerator {
335
331
  if (shouldPrebuildProductionPageBrowserGraphs() && force) {
336
332
  clearProductionPageBrowserGraphSession(this.appConfig);
337
333
  }
338
- const routes = await router.listStaticGenerationRoutes({ runtimeOrigin: baseUrl });
339
- const exportRoutes = routes.map((route) => toEcopagesRouteInfo(route));
340
- if (shouldBuildPagesUnifiedGraph()) {
341
- await ensurePagesUnifiedGraphBuilt({
342
- appConfig: this.appConfig,
343
- entryPaths: routes.map((route) => route.templateRoute.filePath),
344
- outdir: getServerModuleBuildCacheOutdir(this.appConfig),
345
- force,
334
+ }
335
+ async ensureUnifiedGraphForStaticGeneration(routes, force) {
336
+ if (!shouldBuildPagesUnifiedGraph()) {
337
+ return;
338
+ }
339
+ await ensurePagesUnifiedGraphBuilt({
340
+ appConfig: this.appConfig,
341
+ entryPaths: routes.map((route) => route.templateRoute.filePath),
342
+ outdir: getServerModuleBuildCacheOutdir(this.appConfig),
343
+ force,
344
+ });
345
+ }
346
+ async executeStaticGenerationBody(input) {
347
+ if (shouldPrebuildProductionPageBrowserGraphs() && input.routeRendererFactory) {
348
+ await prebuildProductionPageBrowserGraphs(input.routes.map((route) => ({
349
+ routeFile: route.templateRoute.filePath,
350
+ params: route.params,
351
+ })), input.routeRendererFactory);
352
+ }
353
+ this.generateRobotsTxt();
354
+ const semanticErrorPathnames = new Set(SEMANTIC_ERROR_PAGE_PATHNAMES);
355
+ const pageRoutes = input.routes.filter((route) => !semanticErrorPathnames.has(route.pathname));
356
+ await this.generateStaticPages({
357
+ router: input.router,
358
+ baseUrl: input.baseUrl,
359
+ routeRendererFactory: input.routeRendererFactory,
360
+ skipped: input.skippedDynamicPages,
361
+ activeStaticPathnames: input.activeStaticPathnames,
362
+ preloadedRoutes: pageRoutes,
363
+ sitemapEligiblePathnames: input.sitemapEligiblePathnames,
364
+ });
365
+ if (input.staticRoutes && input.staticRoutes.length > 0 && input.routeRendererFactory) {
366
+ await this.generateExplicitStaticPages({
367
+ staticRoutes: input.staticRoutes,
368
+ routeRendererFactory: input.routeRendererFactory,
369
+ skipped: input.skippedDynamicPages,
370
+ activeStaticPathnames: input.activeStaticPathnames,
371
+ sitemapEligiblePathnames: input.sitemapEligiblePathnames,
346
372
  });
347
373
  }
374
+ const errorPageRenderer = new ErrorPageRenderer({
375
+ appConfig: this.appConfig,
376
+ routeRendererFactory: input.routeRendererFactory,
377
+ errorPageLoaders: input.errorPageLoaders,
378
+ });
379
+ await new SemanticErrorPageExporter({
380
+ errorPageRenderer,
381
+ writeArtifact: async (artifact) => await this.writeStaticPageArtifact(artifact),
382
+ }).export(input.activeStaticPathnames);
383
+ if (input.preserveExportDirectory) {
384
+ this.pruneStaleStaticOutputs(input.activeStaticPathnames);
385
+ }
386
+ }
387
+ finalizeStaticGenerationRun(input) {
388
+ if (this.appConfig.sitemap?.enabled && input.sitemapEligiblePathnames) {
389
+ const locations = resolveSitemapLocations({
390
+ eligiblePathnames: [...input.sitemapEligiblePathnames],
391
+ sitemap: this.appConfig.sitemap,
392
+ baseUrl: input.baseUrl,
393
+ });
394
+ this.generateSitemap(locations, this.appConfig.sitemap);
395
+ }
396
+ if (input.skippedDynamicPages.length > 0) {
397
+ appLogger.debug(`Skipped ${input.skippedDynamicPages.length} page(s) with cache: 'dynamic' (not supported in static generation)`, input.skippedDynamicPages);
398
+ }
399
+ }
400
+ /**
401
+ * Executes the full static-generation workflow for one app run.
402
+ */
403
+ async run({ router, baseUrl, routeRendererFactory, staticRoutes, errorPageLoaders, force = false, preserveExportDirectory = false, }) {
404
+ const skippedDynamicPages = [];
405
+ const activeStaticPathnames = new Set();
406
+ const sitemapEligiblePathnames = this.appConfig.sitemap?.enabled ? new Set() : undefined;
407
+ this.resetStaticGenerationState(force);
408
+ const routes = await router.listStaticGenerationRoutes({ runtimeOrigin: baseUrl });
409
+ const exportRoutes = routes.map((route) => toEcopagesRouteInfo(route));
410
+ await this.ensureUnifiedGraphForStaticGeneration(routes, force);
348
411
  const staticExportContext = this.createStaticExportContext({
349
412
  router,
350
413
  baseUrl,
@@ -356,34 +419,18 @@ export class StaticSiteGenerator {
356
419
  });
357
420
  await this.invokeStaticExportHook('beforeStaticExport', staticExportContext);
358
421
  try {
359
- if (shouldPrebuildProductionPageBrowserGraphs() && routeRendererFactory) {
360
- await prebuildProductionPageBrowserGraphs(routes.map((route) => ({
361
- routeFile: route.templateRoute.filePath,
362
- params: route.params,
363
- })), routeRendererFactory);
364
- }
365
- this.generateRobotsTxt();
366
- await this.generateStaticPages({
422
+ await this.executeStaticGenerationBody({
367
423
  router,
368
424
  baseUrl,
369
425
  routeRendererFactory,
370
- skipped: skippedDynamicPages,
426
+ staticRoutes,
427
+ errorPageLoaders,
428
+ preserveExportDirectory,
429
+ routes,
430
+ skippedDynamicPages,
371
431
  activeStaticPathnames,
372
- preloadedRoutes: routes,
373
432
  sitemapEligiblePathnames,
374
433
  });
375
- if (staticRoutes && staticRoutes.length > 0 && routeRendererFactory) {
376
- await this.generateExplicitStaticPages({
377
- staticRoutes,
378
- routeRendererFactory,
379
- skipped: skippedDynamicPages,
380
- activeStaticPathnames,
381
- sitemapEligiblePathnames,
382
- });
383
- }
384
- if (preserveExportDirectory) {
385
- this.pruneStaleStaticOutputs(activeStaticPathnames);
386
- }
387
434
  }
388
435
  catch (error) {
389
436
  if (shouldPrebuildProductionPageBrowserGraphs()) {
@@ -394,17 +441,11 @@ export class StaticSiteGenerator {
394
441
  finally {
395
442
  await this.invokeStaticExportHook('afterStaticExport', staticExportContext);
396
443
  }
397
- if (this.appConfig.sitemap?.enabled && sitemapEligiblePathnames) {
398
- const locations = resolveSitemapLocations({
399
- eligiblePathnames: [...sitemapEligiblePathnames],
400
- sitemap: this.appConfig.sitemap,
401
- baseUrl,
402
- });
403
- this.generateSitemap(locations, this.appConfig.sitemap);
404
- }
405
- if (skippedDynamicPages.length > 0) {
406
- appLogger.debug(`Skipped ${skippedDynamicPages.length} page(s) with cache: 'dynamic' (not supported in static generation)`, skippedDynamicPages);
407
- }
444
+ this.finalizeStaticGenerationRun({
445
+ baseUrl,
446
+ skippedDynamicPages,
447
+ sitemapEligiblePathnames,
448
+ });
408
449
  }
409
450
  async generateExplicitStaticPages(input) {
410
451
  appLogger.debug('Generating explicit static routes', input.staticRoutes.map((r) => r.path));
@@ -5,7 +5,11 @@ import type { BuildRuntime } from '../build/runtime/build-runtime.js';
5
5
  import type { AnyIntegrationPlugin } from '../plugins/integration-plugin.js';
6
6
  import type { Processor } from '../plugins/processor.js';
7
7
  import type { EcoSourceTransform } from '../plugins/source-transform.js';
8
- import type { PageMetadataProps, SitemapConfig } from './public-types.js';
8
+ import type { ComponentRenderInput, EcoComponent, PageMetadataProps, SitemapConfig } from './public-types.js';
9
+ /** Internal render input carrying route-resolved dependency roots. */
10
+ export type InternalComponentRenderInput = ComponentRenderInput & {
11
+ foreignChildRoots?: ReadonlyArray<EcoComponent | Partial<EcoComponent>>;
12
+ };
9
13
  import type { RouteRegistry } from '../router/server/route-registry.js';
10
14
  import type { CacheConfig } from '../services/cache/cache.types.js';
11
15
  import type { DevGraphService } from '../services/runtime-state/dev-graph.service.js';
@@ -132,6 +136,7 @@ export type EcoPagesAppConfig = {
132
136
  publicDir: string;
133
137
  srcDir: string;
134
138
  htmlTemplatePath: string;
139
+ errorPageTemplatePaths?: Record<400 | 401 | 403 | 404 | 409 | 500, string>;
135
140
  error404TemplatePath: string;
136
141
  error500TemplatePath: string;
137
142
  };
@@ -11,7 +11,7 @@ import type { InteractionEventsString as ScriptsInjectorInteractionEventsString
11
11
  import type { EntrypointDependencyGraph } from '../services/runtime-state/entrypoint-dependency-graph.service.js';
12
12
  import type { DevTransformBundleContributor } from '../dev/transform-server/types.js';
13
13
  export type { EcoPagesAppConfig } from './internal-types.js';
14
- export type { EcoPageComponent, GetPageDependencies, GetPageDependenciesContext, PageDependenciesResult, } from '../eco/eco.types.js';
14
+ export type { EcoPageComponent, FileOwnedDependencyContribution, GetPageDependencies, GetPageDependenciesContext, PageDependenciesResult, } from '../eco/eco.types.js';
15
15
  export type { ProcessedAsset } from '../services/assets/asset-processing-service/assets.types.js';
16
16
  /**
17
17
  * Runtime-agnostic incoming WebSocket frame.
@@ -367,10 +367,7 @@ export type EcoChildren = string | Promise<string> | number | bigint | boolean |
367
367
  strings: readonly string[];
368
368
  values?: readonly EcoChildren[];
369
369
  };
370
- /**
371
- * Represents the input configuration for EcoPages.
372
- */
373
- export type EcoPagesConfig = Omit<Partial<EcoPagesAppConfig>, 'baseUrl' | 'derivedPaths' | 'templatesExt' | 'integrationsDependencies'> & Pick<EcoPagesAppConfig, 'baseUrl' | 'rootDir'>;
370
+ export type { EcoPagesUserConfig } from '../config/user-config-types.js';
374
371
  export type EcoComponentConfig = {
375
372
  /** Canonical integration, module, and stable component attribution. */
376
373
  identity?: ComponentIdentity;
@@ -603,8 +600,8 @@ export interface HtmlTemplateProps<T = EcoPagesElement> extends PageHeadProps<T>
603
600
  * Request-scoped context available to layout prop factories on `eco.page`.
604
601
  */
605
602
  export type LayoutPropsContext = {
606
- params?: Record<string, string>;
607
- query?: Record<string, string>;
603
+ params?: PageParams;
604
+ query?: PageQuery;
608
605
  locals?: RequestLocals;
609
606
  };
610
607
  /**
@@ -645,27 +642,25 @@ export type EcoLayoutComponent<T = EcoPagesElement> = EcoComponent<LayoutProps<T
645
642
  */
646
643
  export type EcoHtmlComponent<T = EcoPagesElement> = EcoComponent<HtmlTemplateProps, T>;
647
644
  /**
648
- * Props type for the semantic `404.*` page template.
649
- * @remarks Semantic error templates receive safe empty `pageLocals` rather than
650
- * request-scoped locals. The runtime does not currently pass `message` / `stack`
651
- * when rendering the custom 404 page.
652
- */
653
- export interface Error404TemplateProps extends Omit<HtmlTemplateProps, 'children'> {
654
- message: string;
655
- stack?: string;
656
- }
657
- /**
658
- * Props type for the semantic `500.*` page template.
659
- * @remarks In development, the page-pipeline passes `message` and `stack` from the
660
- * thrown error when rendering this page after a failure. In production those
661
- * fields are omitted so stacks are not serialized into HTML. Direct visits to
662
- * `/500` also omit them. Semantic error templates receive safe empty
645
+ * Props passed to semantic HTML error pages (`pages/{status}.*` and `app.*()` loaders).
646
+ *
647
+ * @remarks
648
+ * `status` is the HTTP status being rendered. `message` is the public `HttpError`
649
+ * text for 4xx page-pipeline failures; unmatched URLs omit it. `stack` is only
650
+ * passed for 5xx pages in development. Semantic error pages receive safe empty
663
651
  * `pageLocals` rather than request-scoped locals.
664
652
  */
665
- export interface Error500TemplateProps extends Omit<HtmlTemplateProps, 'children'> {
653
+ export interface ErrorPageTemplateProps extends Omit<HtmlTemplateProps, 'children'> {
654
+ status: number;
666
655
  message?: string;
667
656
  stack?: string;
668
657
  }
658
+ export type Error400TemplateProps = ErrorPageTemplateProps;
659
+ export type Error401TemplateProps = ErrorPageTemplateProps;
660
+ export type Error403TemplateProps = ErrorPageTemplateProps;
661
+ export type Error404TemplateProps = ErrorPageTemplateProps;
662
+ export type Error409TemplateProps = ErrorPageTemplateProps;
663
+ export type Error500TemplateProps = ErrorPageTemplateProps;
669
664
  /**
670
665
  * Represents the parameters for a page.
671
666
  * The keys are strings, and the values can be either a string or an array of strings.
@@ -1509,7 +1504,9 @@ export interface RouteGroupBuilder<TRequest extends Request = Request, TServer =
1509
1504
  }
1510
1505
  /**
1511
1506
  * A function that dynamically imports a view module.
1512
- * Used by app.static() to enable HMR in development.
1507
+ * Used by `app.static()` and the HTML error-page helpers (`app.notFound()`,
1508
+ * `app.forbidden()`, `app.serverError()`, `app.errorPage()`, …) to enable HMR
1509
+ * in development.
1513
1510
  */
1514
1511
  export type ViewLoader<P = any> = () => Promise<{
1515
1512
  default: EcoPageComponent<P>;
@@ -1522,3 +1519,16 @@ export interface StaticRoute<P = any> {
1522
1519
  path: string;
1523
1520
  loader: ViewLoader<P>;
1524
1521
  }
1522
+ /**
1523
+ * Lazy view loaders registered through `app.errorPage()` and the named
1524
+ * `app.badRequest()` / `app.unauthorized()` / `app.forbidden()` /
1525
+ * `app.notFound()` / `app.conflict()` / `app.serverError()` helpers.
1526
+ */
1527
+ export type ErrorPageLoaders = {
1528
+ badRequest?: ViewLoader<ErrorPageTemplateProps>;
1529
+ unauthorized?: ViewLoader<ErrorPageTemplateProps>;
1530
+ forbidden?: ViewLoader<ErrorPageTemplateProps>;
1531
+ notFound?: ViewLoader<ErrorPageTemplateProps>;
1532
+ conflict?: ViewLoader<ErrorPageTemplateProps>;
1533
+ serverError?: ViewLoader<ErrorPageTemplateProps>;
1534
+ };
@@ -16,6 +16,32 @@ function getEmbeddedRuntimeCommandOptions() {
16
16
  }
17
17
  const ECOPAGES_BIN_FILES = ['ecopages.ts', 'ecopages.js', 'cli.js'];
18
18
  const ECOPAGES_AVAILABLE_COMMANDS = ['dev', 'build', 'start', 'preview'];
19
+ function resolveEcopagesSubcommand(runtimeArgv) {
20
+ const ecopagesIndex = runtimeArgv.findIndex((arg) => ECOPAGES_BIN_FILES.some((filename) => arg.endsWith(filename)));
21
+ if (ecopagesIndex === -1) {
22
+ return '';
23
+ }
24
+ if (ecopagesIndex < runtimeArgv.length - 1 &&
25
+ ECOPAGES_AVAILABLE_COMMANDS.some((cmd) => runtimeArgv[ecopagesIndex + 1] === cmd)) {
26
+ return runtimeArgv[ecopagesIndex + 1];
27
+ }
28
+ return 'start';
29
+ }
30
+ function deriveCliCommandFlags(command, values) {
31
+ const isStartCommand = command === 'start' || (!values.dev && !values.build && !values.preview);
32
+ const isDevCommand = command === 'dev' || !!values.dev;
33
+ const isBuildCommand = command === 'build' || !!values.build;
34
+ const isPreviewCommand = command === 'preview' || !!values.preview;
35
+ return { isStartCommand, isDevCommand, isBuildCommand, isPreviewCommand };
36
+ }
37
+ function applyNodeEnvForCliCommand(isDevCommand) {
38
+ if (isDevCommand) {
39
+ process.env.NODE_ENV ??= 'development';
40
+ }
41
+ else {
42
+ process.env.NODE_ENV = 'production';
43
+ }
44
+ }
19
45
  /**
20
46
  * Parses command line arguments for the server.
21
47
  * It returns {@link ReturnParseCliArgs}
@@ -39,22 +65,8 @@ export function parseCliArgs(options = {}) {
39
65
  },
40
66
  allowPositionals: true,
41
67
  });
42
- let command = '';
43
- const ecopagesIndex = runtimeArgv.findIndex((arg) => ECOPAGES_BIN_FILES.some((filename) => arg.endsWith(filename)));
44
- const isAvailableCommand = ecopagesIndex !== -1;
45
- if (isAvailableCommand) {
46
- command =
47
- ecopagesIndex < runtimeArgv.length - 1 &&
48
- ECOPAGES_AVAILABLE_COMMANDS.some((cmd) => {
49
- return runtimeArgv[ecopagesIndex + 1] === cmd;
50
- })
51
- ? runtimeArgv[ecopagesIndex + 1]
52
- : 'start';
53
- }
54
- const isStartCommand = command === 'start' || (!values.dev && !values.build && !values.preview);
55
- const isDevCommand = command === 'dev' || !!values.dev;
56
- const isBuildCommand = command === 'build' || !!values.build;
57
- const isPreviewCommand = command === 'preview' || !!values.preview;
68
+ const command = resolveEcopagesSubcommand(runtimeArgv);
69
+ const { isStartCommand, isDevCommand, isBuildCommand, isPreviewCommand } = deriveCliCommandFlags(command, values);
58
70
  const parsedCommandOptions = {
59
71
  preview: isPreviewCommand,
60
72
  build: isBuildCommand,
@@ -66,11 +78,6 @@ export function parseCliArgs(options = {}) {
66
78
  hostname: values.hostname,
67
79
  reactFastRefresh: values['react-fast-refresh'],
68
80
  };
69
- if (isDevCommand) {
70
- process.env.NODE_ENV ??= 'development';
71
- }
72
- else {
73
- process.env.NODE_ENV = 'production';
74
- }
81
+ applyNodeEnvForCliCommand(isDevCommand);
75
82
  return parsedCommandOptions;
76
83
  }
@@ -17,6 +17,10 @@ export interface ProjectWatcherConfig {
17
17
  hostOwnsDevClient?: boolean;
18
18
  /** Delay before a change event is processed; 0 disables debouncing. */
19
19
  changeDebounceMs?: number;
20
+ /** Applies a config or dotenv change through the owning runtime lifecycle. */
21
+ onRestartRequest?: (filePath: string) => Promise<void>;
22
+ /** Whether an entry watcher already owns changes to the config module. */
23
+ entryWatcherOwnsConfig?: boolean;
20
24
  }
21
25
  /**
22
26
  * ProjectWatcher handles file system changes for hot module replacement (HMR).
@@ -49,11 +53,14 @@ export declare class ProjectWatcher {
49
53
  private readonly hostOwnsDevClient;
50
54
  private readonly invalidationService;
51
55
  private readonly changeDebounceMs;
56
+ private readonly onRestartRequest?;
57
+ private readonly entryWatcherOwnsConfig;
58
+ private restartRequestScheduled;
52
59
  private watcher;
53
60
  private closed;
54
61
  private pendingChangeEvents;
55
62
  private changeQueue;
56
- constructor({ config, refreshRouterRoutesCallback, hmrManager, bridge, hostOwnsDevClient, changeDebounceMs, }: ProjectWatcherConfig);
63
+ constructor({ config, refreshRouterRoutesCallback, hmrManager, bridge, hostOwnsDevClient, changeDebounceMs, onRestartRequest, entryWatcherOwnsConfig, }: ProjectWatcherConfig);
57
64
  /**
58
65
  * Uncaches modules in the source directory to ensure fresh imports.
59
66
  * This is necessary for hot module replacement to work correctly.
@@ -92,6 +99,12 @@ export declare class ProjectWatcher {
92
99
  * @param event - The type of file system event
93
100
  */
94
101
  private handleFileChange;
102
+ private invalidatePageCachesForChange;
103
+ private applyRouteAndServerInvalidation;
104
+ private shouldDeferProcessorNotifications;
105
+ private handleDeferredHmrFileChange;
106
+ private handleStandardHmrFileChange;
107
+ private handleRuntimeRestart;
95
108
  private processFileChange;
96
109
  /**
97
110
  * Re-imports server modules before HMR broadcast so reload/refetch does not
@@ -9,6 +9,7 @@ import { getAppPageBrowserGraphSession } from '../route-renderer/orchestration/p
9
9
  import { isRegisteredDevTransformEntrypoint } from '../hmr/hmr-entrypoint-output.js';
10
10
  import { resolveInternalExecutionDir } from '../utils/resolve-work-dir.js';
11
11
  import { createProjectWatcherIgnorePredicate } from './project-watcher-ignore.js';
12
+ import { resolveRuntimeRestartWatchPaths } from '../dev/development-restart-watch-paths.js';
12
13
  /**
13
14
  * ProjectWatcher handles file system changes for hot module replacement (HMR).
14
15
  * It uses chokidar to watch for file changes and triggers appropriate actions:
@@ -40,11 +41,14 @@ export class ProjectWatcher {
40
41
  hostOwnsDevClient;
41
42
  invalidationService;
42
43
  changeDebounceMs;
44
+ onRestartRequest;
45
+ entryWatcherOwnsConfig;
46
+ restartRequestScheduled = false;
43
47
  watcher = null;
44
48
  closed = false;
45
49
  pendingChangeEvents = new Map();
46
50
  changeQueue = Promise.resolve();
47
- constructor({ config, refreshRouterRoutesCallback, hmrManager, bridge, hostOwnsDevClient, changeDebounceMs, }) {
51
+ constructor({ config, refreshRouterRoutesCallback, hmrManager, bridge, hostOwnsDevClient, changeDebounceMs, onRestartRequest, entryWatcherOwnsConfig, }) {
48
52
  this.appConfig = config;
49
53
  this.refreshRouterRoutesCallback = refreshRouterRoutesCallback;
50
54
  this.hmrManager = hmrManager;
@@ -55,6 +59,8 @@ export class ProjectWatcher {
55
59
  changeDebounceMs ??
56
60
  (envDebounceMs !== undefined && envDebounceMs !== '' ? Number(envDebounceMs) : undefined) ??
57
61
  ProjectWatcher.duplicateChangeWindowMs;
62
+ this.onRestartRequest = onRestartRequest;
63
+ this.entryWatcherOwnsConfig = entryWatcherOwnsConfig === true;
58
64
  this.invalidationService = new DevelopmentInvalidationService(config);
59
65
  this.triggerRouterRefresh = this.triggerRouterRefresh.bind(this);
60
66
  this.handleError = this.handleError.bind(this);
@@ -155,58 +161,97 @@ export class ProjectWatcher {
155
161
  this.pendingChangeEvents.set(filePath, { event, timer });
156
162
  return Promise.resolve();
157
163
  }
164
+ async invalidatePageCachesForChange(plan, resolvedFilePath) {
165
+ if (shouldClearAllPageHtmlCache(plan.category)) {
166
+ await clearAppPageCache(this.appConfig);
167
+ return;
168
+ }
169
+ await invalidateAppPageCacheBySourcePaths(this.appConfig, [resolvedFilePath]);
170
+ }
171
+ async applyRouteAndServerInvalidation(plan, filePath, resolvedFilePath, event, isRegisteredDevTransformEdit) {
172
+ if (plan.refreshRoutes && (event === 'unlink' || event === 'add')) {
173
+ getAppPageBrowserGraphSession(this.appConfig).invalidateByRouteFile(resolvedFilePath);
174
+ }
175
+ if (plan.invalidateServerModules && !isRegisteredDevTransformEdit) {
176
+ this.invalidationService.invalidateServerModules([filePath]);
177
+ }
178
+ if (plan.refreshRoutes) {
179
+ await this.refreshRouterRoutesCallback();
180
+ }
181
+ }
182
+ shouldDeferProcessorNotifications(plan, isRegisteredDevTransformEdit) {
183
+ return (plan.category === 'include-source' ||
184
+ plan.category === 'explicit-server-view' ||
185
+ isRegisteredDevTransformEdit);
186
+ }
187
+ async handleDeferredHmrFileChange(filePath, resolvedFilePath, event, plan, graphPreparation) {
188
+ await this.prewarmBeforeHmr(resolvedFilePath, plan);
189
+ await this.hmrManager.handleFileChange(filePath, {
190
+ graphIdentities: graphPreparation?.affectedGraphIdentities,
191
+ });
192
+ await this.notifyProcessors(filePath, event);
193
+ }
194
+ async handleStandardHmrFileChange(filePath, event, plan, graphPreparation) {
195
+ await this.notifyProcessors(filePath, event);
196
+ if (plan.processorHandledAsset) {
197
+ return;
198
+ }
199
+ if (plan.delegateToHmr) {
200
+ await this.hmrManager.handleFileChange(filePath, {
201
+ graphIdentities: graphPreparation?.affectedGraphIdentities,
202
+ });
203
+ }
204
+ }
205
+ handleRuntimeRestart(filePath) {
206
+ const onRestartRequest = this.onRestartRequest;
207
+ if (!onRestartRequest) {
208
+ appLogger.warn(`Configuration or environment file changed (${filePath}). Restart the development server to apply it.`);
209
+ return;
210
+ }
211
+ if (this.restartRequestScheduled) {
212
+ return;
213
+ }
214
+ this.restartRequestScheduled = true;
215
+ void this.changeQueue
216
+ .then(() => onRestartRequest(filePath))
217
+ .catch((error) => this.handleError(error))
218
+ .finally(() => {
219
+ this.restartRequestScheduled = false;
220
+ });
221
+ }
158
222
  async processFileChange(filePath, event) {
159
223
  try {
160
224
  const plan = this.invalidationService.planFileChange(filePath);
225
+ if (plan.category === 'runtime-restart') {
226
+ if (this.entryWatcherOwnsConfig && this.invalidationService.isConfigModuleFile(filePath)) {
227
+ return;
228
+ }
229
+ this.handleRuntimeRestart(filePath);
230
+ return;
231
+ }
161
232
  if (plan.category === 'public-asset') {
162
233
  await this.handlePublicDirFileChange(filePath);
163
234
  return;
164
235
  }
165
236
  this.uncacheModules();
166
237
  const resolvedFilePath = path.resolve(filePath);
167
- if (shouldClearAllPageHtmlCache(plan.category)) {
168
- await clearAppPageCache(this.appConfig);
169
- }
170
- else {
171
- await invalidateAppPageCacheBySourcePaths(this.appConfig, [resolvedFilePath]);
172
- }
238
+ await this.invalidatePageCachesForChange(plan, resolvedFilePath);
173
239
  const graphPreparation = this.hmrManager.isEnabled()
174
240
  ? prepareHmrFileChange(this.appConfig, resolvedFilePath)
175
241
  : undefined;
176
- if (plan.refreshRoutes && (event === 'unlink' || event === 'add')) {
177
- getAppPageBrowserGraphSession(this.appConfig).invalidateByRouteFile(resolvedFilePath);
178
- }
179
242
  const isRegisteredDevTransformEdit = isRegisteredDevTransformEntrypoint(this.hmrManager.getRegisteredEntrypoints(), resolvedFilePath);
180
- if (plan.invalidateServerModules && !isRegisteredDevTransformEdit) {
181
- this.invalidationService.invalidateServerModules([filePath]);
182
- }
183
- if (plan.refreshRoutes) {
184
- await this.refreshRouterRoutesCallback();
185
- }
243
+ await this.applyRouteAndServerInvalidation(plan, filePath, resolvedFilePath, event, isRegisteredDevTransformEdit);
186
244
  if (plan.reloadBrowser) {
245
+ await this.notifyProcessors(filePath, event);
187
246
  this.requestBrowserReload();
188
247
  return;
189
248
  }
190
- const deferProcessorNotifications = plan.category === 'include-source' ||
191
- plan.category === 'explicit-server-view' ||
192
- isRegisteredDevTransformEdit;
249
+ const deferProcessorNotifications = this.shouldDeferProcessorNotifications(plan, isRegisteredDevTransformEdit);
193
250
  if (deferProcessorNotifications && plan.delegateToHmr) {
194
- await this.prewarmBeforeHmr(resolvedFilePath, plan);
195
- await this.hmrManager.handleFileChange(filePath, {
196
- graphIdentities: graphPreparation?.affectedGraphIdentities,
197
- });
198
- await this.notifyProcessors(filePath, event);
251
+ await this.handleDeferredHmrFileChange(filePath, resolvedFilePath, event, plan, graphPreparation);
199
252
  return;
200
253
  }
201
- await this.notifyProcessors(filePath, event);
202
- if (plan.processorHandledAsset) {
203
- return;
204
- }
205
- if (plan.delegateToHmr) {
206
- await this.hmrManager.handleFileChange(filePath, {
207
- graphIdentities: graphPreparation?.affectedGraphIdentities,
208
- });
209
- }
254
+ await this.handleStandardHmrFileChange(filePath, event, plan, graphPreparation);
210
255
  }
211
256
  catch (error) {
212
257
  if (error instanceof Error) {
@@ -364,7 +409,13 @@ export class ProjectWatcher {
364
409
  processorPaths.add(this.appConfig.absolutePaths.publicDir);
365
410
  }
366
411
  for (const watchPath of this.appConfig.additionalWatchPaths) {
367
- processorPaths.add(watchPath);
412
+ const resolvedWatchPath = path.isAbsolute(watchPath) || watchPath.includes('*')
413
+ ? watchPath
414
+ : path.resolve(this.appConfig.rootDir, watchPath);
415
+ processorPaths.add(resolvedWatchPath);
416
+ }
417
+ for (const restartPath of resolveRuntimeRestartWatchPaths(this.appConfig)) {
418
+ processorPaths.add(restartPath);
368
419
  }
369
420
  const ignored = createProjectWatcherIgnorePredicate(this.appConfig.absolutePaths);
370
421
  this.watcher = chokidar.watch(Array.from(processorPaths), {