@ecopages/core 0.2.0-rc.1 → 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 (179) hide show
  1. package/README.md +50 -32
  2. package/package.json +50 -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 +8 -4
  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/explicit-static-route-matcher.js +5 -2
  21. package/src/adapters/shared/http/fs-server-response-factory.d.ts +2 -8
  22. package/src/adapters/shared/http/fs-server-response-factory.js +5 -30
  23. package/src/adapters/shared/http/fs-server-response-matcher.d.ts +24 -24
  24. package/src/adapters/shared/http/fs-server-response-matcher.js +59 -83
  25. package/src/adapters/shared/runtime/application-adapter.d.ts +1 -0
  26. package/src/adapters/shared/runtime/application-adapter.js +12 -0
  27. package/src/adapters/shared/runtime/bind-runtime-server.d.ts +17 -0
  28. package/src/adapters/shared/runtime/bind-runtime-server.js +50 -0
  29. package/src/adapters/shared/runtime/port-manager-default-prompt.d.ts +6 -0
  30. package/src/adapters/shared/runtime/port-manager-default-prompt.js +41 -0
  31. package/src/adapters/shared/runtime/port-manager.d.ts +3 -3
  32. package/src/adapters/shared/runtime/port-manager.js +14 -45
  33. package/src/adapters/shared/runtime/server-adapter.d.ts +14 -5
  34. package/src/adapters/shared/runtime/server-adapter.js +22 -30
  35. package/src/adapters/shared/runtime/server-route-handler.js +11 -3
  36. package/src/adapters/shared/runtime/server-static-builder.d.ts +9 -3
  37. package/src/adapters/shared/runtime/server-static-builder.js +59 -37
  38. package/src/build/README.md +4 -0
  39. package/src/build/cache/server-entry-build-cache.d.ts +24 -1
  40. package/src/build/cache/server-entry-build-cache.js +125 -8
  41. package/src/build/contracts/content-virtual-modules.d.ts +3 -1
  42. package/src/build/contracts/content-virtual-modules.js +8 -0
  43. package/src/build/rolldown/rolldown-adapter-helpers.js +41 -25
  44. package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
  45. package/src/build/runtime/build-request-policy.js +1 -1
  46. package/src/build/server-bundle-publication.d.ts +14 -0
  47. package/src/build/server-bundle-publication.js +49 -0
  48. package/src/config/README.md +17 -2
  49. package/src/config/apply-user-config.d.ts +6 -0
  50. package/src/config/apply-user-config.js +67 -0
  51. package/src/config/config-builder.d.ts +10 -1
  52. package/src/config/config-builder.js +51 -10
  53. package/src/config/constants.d.ts +4 -0
  54. package/src/config/constants.js +4 -0
  55. package/src/config/define-config.d.ts +9 -0
  56. package/src/config/define-config.js +10 -0
  57. package/src/config/index.d.ts +5 -0
  58. package/src/config/index.js +4 -0
  59. package/src/config/is-finalized-app-config.d.ts +6 -0
  60. package/src/config/is-finalized-app-config.js +11 -0
  61. package/src/config/load-eco-config.d.ts +21 -0
  62. package/src/config/load-eco-config.js +100 -0
  63. package/src/config/resolve-eco-config-path.d.ts +23 -0
  64. package/src/config/resolve-eco-config-path.js +47 -0
  65. package/src/config/server-config-bundle.d.ts +25 -0
  66. package/src/config/server-config-bundle.js +148 -0
  67. package/src/config/user-config-types.d.ts +164 -0
  68. package/src/config/user-config-types.js +1 -0
  69. package/src/css-imports.d.ts +4 -0
  70. package/src/declarations.d.ts +11 -5
  71. package/src/dev/README.md +6 -0
  72. package/src/dev/development-restart-watch-paths.d.ts +13 -0
  73. package/src/dev/development-restart-watch-paths.js +37 -0
  74. package/src/dev/development-restart.d.ts +13 -0
  75. package/src/dev/development-restart.js +21 -0
  76. package/src/dev/transform-server/dev-transform-server.d.ts +6 -0
  77. package/src/dev/transform-server/dev-transform-server.js +16 -5
  78. package/src/eco/README.md +73 -5
  79. package/src/eco/component-identity.d.ts +3 -2
  80. package/src/eco/component-identity.js +5 -2
  81. package/src/eco/discovered-dependencies.d.ts +45 -0
  82. package/src/eco/discovered-dependencies.js +87 -0
  83. package/src/eco/eco.js +6 -0
  84. package/src/eco/eco.types.d.ts +18 -2
  85. package/src/eco/lazy-injector-map.js +57 -41
  86. package/src/eco/page-dependency-contributions.d.ts +19 -0
  87. package/src/eco/page-dependency-contributions.js +52 -0
  88. package/src/errors/http-error-page-contract.d.ts +77 -0
  89. package/src/errors/http-error-page-contract.js +106 -0
  90. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
  91. package/src/hmr/strategies/js-hmr-strategy.js +24 -16
  92. package/src/index.browser.d.ts +3 -0
  93. package/src/index.browser.js +3 -0
  94. package/src/index.d.ts +4 -1
  95. package/src/index.js +4 -1
  96. package/src/islands/README.md +5 -1
  97. package/src/plugins/README.md +8 -1
  98. package/src/plugins/component-import-discovery.d.ts +19 -0
  99. package/src/plugins/component-import-discovery.js +241 -0
  100. package/src/plugins/eco-component-meta-plugin.d.ts +3 -1
  101. package/src/plugins/eco-component-meta-plugin.js +118 -16
  102. package/src/plugins/processor.d.ts +10 -2
  103. package/src/plugins/processor.js +4 -0
  104. package/src/plugins/tsconfig-import-resolver.d.ts +3 -1
  105. package/src/plugins/tsconfig-import-resolver.js +4 -2
  106. package/src/route-renderer/GRAPH.md +1 -1
  107. package/src/route-renderer/README.md +15 -2
  108. package/src/{adapters/shared/http/explicit-static-render-preparation.d.ts → route-renderer/explicit-view-render-preparation.d.ts} +3 -3
  109. package/src/route-renderer/orchestration/custom-element-scripts/README.md +9 -0
  110. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +16 -0
  111. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +34 -0
  112. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +80 -0
  113. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +190 -0
  114. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +17 -0
  115. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +41 -0
  116. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +10 -0
  117. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +46 -0
  118. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +7 -2
  119. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +2 -0
  120. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +11 -2
  121. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +10 -2
  122. package/src/route-renderer/orchestration/integration-renderer.d.ts +9 -5
  123. package/src/route-renderer/orchestration/integration-renderer.js +42 -29
  124. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +2 -5
  125. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +2 -68
  126. package/src/route-renderer/orchestration/ownership-graph/component-graph.js +55 -39
  127. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +6 -0
  128. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +59 -36
  129. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +8 -10
  130. package/src/route-renderer/orchestration/string-markup-renderer.d.ts +1 -1
  131. package/src/route-renderer/orchestration/string-markup-renderer.js +2 -1
  132. package/src/route-renderer/page-loading/component-dependency-collection.d.ts +6 -2
  133. package/src/route-renderer/page-loading/component-dependency-collection.js +113 -68
  134. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
  135. package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +10 -3
  136. package/src/route-renderer/page-loading/file-scoped-dependency-components.js +62 -25
  137. package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
  138. package/src/route-renderer/page-loading/resolved-page-dependencies.d.ts +1 -2
  139. package/src/route-renderer/page-loading/resolved-page-dependencies.js +8 -7
  140. package/src/route-renderer/route-renderer.d.ts +9 -0
  141. package/src/route-renderer/route-renderer.js +18 -0
  142. package/src/router/README.md +7 -1
  143. package/src/router/server/route-registry.d.ts +13 -0
  144. package/src/router/server/route-registry.js +46 -32
  145. package/src/services/README.md +5 -0
  146. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +36 -9
  147. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +122 -37
  148. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +2 -0
  149. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +13 -2
  150. package/src/services/assets/asset-processing-service/page-package.js +42 -39
  151. package/src/services/error-pages/README.md +9 -0
  152. package/src/services/error-pages/default-error-pages.d.ts +44 -0
  153. package/src/services/error-pages/default-error-pages.js +207 -0
  154. package/src/services/error-pages/error-page-renderer.d.ts +58 -0
  155. package/src/services/error-pages/error-page-renderer.js +146 -0
  156. package/src/services/error-pages/semantic-error-page-exporter.d.ts +23 -0
  157. package/src/services/error-pages/semantic-error-page-exporter.js +35 -0
  158. package/src/services/invalidation/development-invalidation.service.d.ts +7 -1
  159. package/src/services/invalidation/development-invalidation.service.js +35 -3
  160. package/src/services/module-loading/README.md +16 -13
  161. package/src/services/module-loading/app-server-module-transpiler.service.js +2 -0
  162. package/src/services/module-loading/collection-server-module-build.service.d.ts +1 -0
  163. package/src/services/module-loading/collection-server-module-build.service.js +5 -2
  164. package/src/services/module-loading/page-module-import.service.d.ts +8 -0
  165. package/src/services/module-loading/page-module-import.service.js +62 -28
  166. package/src/services/module-loading/route-module-dependency-hasher.js +13 -1
  167. package/src/services/module-loading/view-module-loader.d.ts +10 -0
  168. package/src/services/module-loading/view-module-loader.js +46 -0
  169. package/src/services/validation/schema-validation-service.d.ts +1 -0
  170. package/src/services/validation/schema-validation-service.js +23 -36
  171. package/src/static-site-generator/README.md +6 -1
  172. package/src/static-site-generator/static-site-generator.d.ts +7 -2
  173. package/src/static-site-generator/static-site-generator.js +90 -49
  174. package/src/types/internal-types.d.ts +6 -1
  175. package/src/types/public-types.d.ts +32 -22
  176. package/src/utils/parse-cli-args.js +29 -22
  177. package/src/watchers/project-watcher.d.ts +14 -1
  178. package/src/watchers/project-watcher.js +85 -34
  179. /package/src/{adapters/shared/http/explicit-static-render-preparation.js → route-renderer/explicit-view-render-preparation.js} +0 -0
@@ -7,6 +7,7 @@ import { createServerBuildRequest } from '../../build/runtime/build-request-poli
7
7
  import { recordCollectionBuild } from '../../diagnostics/request-pipeline-metrics.js';
8
8
  import { resolveInternalExecutionDir } from '../../utils/resolve-work-dir.js';
9
9
  import { fileSystem } from '@ecopages/file-system';
10
+ import { getAppServerInvalidationState } from '../runtime-state/server-invalidation-state.service.js';
10
11
  const artifactsByCollection = new WeakMap();
11
12
  function getArtifactMap(appConfig) {
12
13
  let artifacts = artifactsByCollection.get(appConfig);
@@ -51,13 +52,14 @@ export async function buildCollectionServerModule(input) {
51
52
  splitting: false,
52
53
  externalPackages: true,
53
54
  });
55
+ const invalidationVersion = getAppServerInvalidationState(appConfig).getServerInvalidationVersion();
54
56
  const buildIdentity = createCollectionBuildIdentity(createBuildRequestIdentity(buildRequest), sourceFilePath, ownedSourcePaths);
55
57
  const artifacts = getArtifactMap(appConfig);
56
58
  const existing = artifacts.get(collectionName);
57
- if (existing?.buildIdentity === buildIdentity) {
59
+ if (existing?.buildIdentity === buildIdentity && existing?.invalidationVersion === invalidationVersion) {
58
60
  return existing;
59
61
  }
60
- const outputFileName = `${collectionName}-${buildIdentity}.mjs`;
62
+ const outputFileName = `${collectionName}-${buildIdentity}-${invalidationVersion}.mjs`;
61
63
  const buildOptions = { ...buildRequest, naming: outputFileName.replace(/\.mjs$/u, '.[ext]') };
62
64
  recordCollectionBuild();
63
65
  const buildResult = await build(buildOptions);
@@ -77,6 +79,7 @@ export async function buildCollectionServerModule(input) {
77
79
  outputUrl: pathToFileURL(compiledOutput).href,
78
80
  sourcePaths: [...ownedSourcePaths, sourceFilePath],
79
81
  buildIdentity,
82
+ invalidationVersion,
80
83
  };
81
84
  artifacts.set(collectionName, artifact);
82
85
  return artifact;
@@ -16,6 +16,8 @@ interface PageModuleImportBaseOptions {
16
16
  export interface PageModuleBuildImportOptions extends PageModuleImportBaseOptions {
17
17
  rootDir: string;
18
18
  outdir: string;
19
+ /** Use the server build pipeline even when a development host can load source modules. */
20
+ forceBuild?: boolean;
19
21
  buildExecutor?: BuildExecutor;
20
22
  splitting?: boolean;
21
23
  externalPackages?: boolean;
@@ -87,6 +89,12 @@ export declare class PageModuleImportService {
87
89
  * @returns The loaded module.
88
90
  */
89
91
  importModule<T = unknown>(options: PageModuleBuildImportOptions): Promise<T>;
92
+ private createRouteModuleBuildOptions;
93
+ private createRouteModuleCacheBuildOptions;
94
+ private tryLoadCachedRouteModuleBuild;
95
+ private tryLoadPagesUnifiedGraphModule;
96
+ private resolveCompiledRouteModuleOutput;
97
+ private importCompiledRouteModule;
90
98
  private loadModule;
91
99
  private getRouteModuleBuildCache;
92
100
  }
@@ -72,7 +72,8 @@ export class PageModuleImportService {
72
72
  async importModule(options) {
73
73
  const { filePath } = options;
74
74
  const fileHash = this.dependencies.hashFile(filePath);
75
- const hostModuleLoader = typeof Bun === 'undefined' &&
75
+ const hostModuleLoader = !options.forceBuild &&
76
+ typeof Bun === 'undefined' &&
76
77
  process.env.NODE_ENV === 'development' &&
77
78
  this.dependencies.canLoadSourceModuleFromHost(filePath)
78
79
  ? this.dependencies.getHostModuleLoader()
@@ -124,12 +125,8 @@ export class PageModuleImportService {
124
125
  fileHash,
125
126
  });
126
127
  }
127
- async loadModule(options) {
128
- const { filePath, fileHash, importCacheKey } = options;
129
- const { rootDir, outdir, splitting, externalPackages, transpileErrorMessage = (details) => `Error transpiling page module: ${details}`, noOutputMessage = (targetFilePath) => `No transpiled output generated for page module: ${targetFilePath}`, } = options;
130
- const outputFileName = createRuntimeBuildOutputFileName(resolvePageModuleOutputFileName({ filePath, fileHash }), this.developmentImportGeneration);
131
- const outputNamingTemplate = outputFileName.replace(/\.mjs$/u, '.[ext]');
132
- const preferredOutputPath = path.join(outdir, outputFileName);
128
+ createRouteModuleBuildOptions(options, outputNamingTemplate) {
129
+ const { filePath, rootDir, outdir, splitting, externalPackages } = options;
133
130
  const buildOptions = this.appConfig
134
131
  ? createServerBuildRequest(this.appConfig, {
135
132
  profile: 'route-module',
@@ -155,10 +152,17 @@ export class PageModuleImportService {
155
152
  root: rootDir,
156
153
  entrypoints: [filePath],
157
154
  };
158
- const cacheBuildOptions = {
159
- ...options,
155
+ return {
156
+ buildOptions,
160
157
  rootDir: buildOptions.root ?? rootDir,
161
158
  outdir: buildOptions.outdir ?? outdir,
159
+ };
160
+ }
161
+ createRouteModuleCacheBuildOptions(options, buildOptions, resolvedRootDir, resolvedOutdir, fileHash) {
162
+ return {
163
+ ...options,
164
+ rootDir: resolvedRootDir,
165
+ outdir: resolvedOutdir,
162
166
  splitting: buildOptions.splitting,
163
167
  externalPackages: buildOptions.externalPackages,
164
168
  jsx: buildOptions.jsx,
@@ -166,32 +170,36 @@ export class PageModuleImportService {
166
170
  sourceTransforms: buildOptions.sourceTransforms,
167
171
  fileHash,
168
172
  };
169
- const routeModuleBuildCache = this.getRouteModuleBuildCache(outdir);
170
- const cachedBuild = routeModuleBuildCache.lookup(cacheBuildOptions);
171
- if (cachedBuild) {
172
- const loadedModule = (await import(/* @vite-ignore */ pathToFileURL(cachedBuild.outputPath).href));
173
- recordPageModuleLoad('disk-cache-hit');
174
- return loadedModule;
173
+ }
174
+ async tryLoadCachedRouteModuleBuild(cacheBuildOptions, outdir) {
175
+ const cachedBuild = this.getRouteModuleBuildCache(outdir).lookup(cacheBuildOptions);
176
+ if (!cachedBuild) {
177
+ return undefined;
175
178
  }
176
- if (shouldBuildPagesUnifiedGraph() && this.appConfig && isPagesUnifiedGraphPage(filePath, this.appConfig)) {
177
- const graphModule = await importPagesUnifiedGraphModule(this.appConfig, filePath);
178
- if (graphModule !== undefined) {
179
- recordPageModuleLoad('unified-graph');
180
- return graphModule;
181
- }
179
+ const loadedModule = (await import(/* @vite-ignore */ pathToFileURL(cachedBuild.outputPath).href));
180
+ recordPageModuleLoad('disk-cache-hit');
181
+ return loadedModule;
182
+ }
183
+ async tryLoadPagesUnifiedGraphModule(filePath) {
184
+ if (!shouldBuildPagesUnifiedGraph() || !this.appConfig || !isPagesUnifiedGraphPage(filePath, this.appConfig)) {
185
+ return undefined;
182
186
  }
183
- recordPageModuleBuildInvocation();
184
- const buildResult = await this.dependencies.buildModule(buildOptions, options.buildExecutor);
185
- recordPageModuleLoad('cold-build', buildResult.outputs.length);
186
- if (!buildResult.success) {
187
- const details = buildResult.logs.map((log) => log.message).join(' | ');
188
- throw new Error(transpileErrorMessage(details));
187
+ const graphModule = await importPagesUnifiedGraphModule(this.appConfig, filePath);
188
+ if (graphModule === undefined) {
189
+ return undefined;
189
190
  }
191
+ recordPageModuleLoad('unified-graph');
192
+ return graphModule;
193
+ }
194
+ resolveCompiledRouteModuleOutput(buildResult, preferredOutputPath, filePath, noOutputMessage) {
190
195
  const compiledOutput = buildResult.outputs.find((output) => output.path === preferredOutputPath)?.path ??
191
196
  buildResult.outputs.find((output) => /\.(?:[cm]?js)$/u.test(output.path))?.path;
192
197
  if (!compiledOutput) {
193
198
  throw new Error(noOutputMessage(filePath));
194
199
  }
200
+ return compiledOutput;
201
+ }
202
+ async importCompiledRouteModule(compiledOutput, filePath, fileHash, rootDir, buildResult, importCacheKey, cacheBuildOptions, outdir) {
195
203
  const dependencyModulePaths = resolveRouteModuleDependencyPaths(buildResult, filePath, rootDir);
196
204
  const dependencyHashes = this.dependencyHasher.createDependencyHashes(dependencyModulePaths);
197
205
  dependencyHashes[path.normalize(filePath)] = fileHash;
@@ -201,7 +209,7 @@ export class PageModuleImportService {
201
209
  cacheEntry.dependencyHashes = dependencyHashes;
202
210
  }
203
211
  }
204
- routeModuleBuildCache.recordBuild({
212
+ this.getRouteModuleBuildCache(outdir).recordBuild({
205
213
  ...cacheBuildOptions,
206
214
  outputPath: compiledOutput,
207
215
  dependencyModulePaths,
@@ -212,6 +220,32 @@ export class PageModuleImportService {
212
220
  }
213
221
  return (await import(/* @vite-ignore */ compiledOutputUrl.href));
214
222
  }
223
+ async loadModule(options) {
224
+ const { filePath, fileHash, importCacheKey } = options;
225
+ const { outdir, transpileErrorMessage = (details) => `Error transpiling page module: ${details}`, noOutputMessage = (targetFilePath) => `No transpiled output generated for page module: ${targetFilePath}`, } = options;
226
+ const outputFileName = createRuntimeBuildOutputFileName(resolvePageModuleOutputFileName({ filePath, fileHash }), this.developmentImportGeneration);
227
+ const outputNamingTemplate = outputFileName.replace(/\.mjs$/u, '.[ext]');
228
+ const preferredOutputPath = path.join(outdir, outputFileName);
229
+ const { buildOptions, rootDir: resolvedRootDir, outdir: resolvedOutdir, } = this.createRouteModuleBuildOptions(options, outputNamingTemplate);
230
+ const cacheBuildOptions = this.createRouteModuleCacheBuildOptions(options, buildOptions, resolvedRootDir, resolvedOutdir, fileHash);
231
+ const cachedModule = await this.tryLoadCachedRouteModuleBuild(cacheBuildOptions, resolvedOutdir);
232
+ if (cachedModule !== undefined) {
233
+ return cachedModule;
234
+ }
235
+ const unifiedGraphModule = await this.tryLoadPagesUnifiedGraphModule(filePath);
236
+ if (unifiedGraphModule !== undefined) {
237
+ return unifiedGraphModule;
238
+ }
239
+ recordPageModuleBuildInvocation();
240
+ const buildResult = await this.dependencies.buildModule(buildOptions, options.buildExecutor);
241
+ recordPageModuleLoad('cold-build', buildResult.outputs.length);
242
+ if (!buildResult.success) {
243
+ const details = buildResult.logs.map((log) => log.message).join(' | ');
244
+ throw new Error(transpileErrorMessage(details));
245
+ }
246
+ const compiledOutput = this.resolveCompiledRouteModuleOutput(buildResult, preferredOutputPath, filePath, noOutputMessage);
247
+ return await this.importCompiledRouteModule(compiledOutput, filePath, fileHash, resolvedRootDir, buildResult, importCacheKey, cacheBuildOptions, resolvedOutdir);
248
+ }
215
249
  getRouteModuleBuildCache(outdir) {
216
250
  return getSharedRouteModuleBuildCache(outdir, this.appConfig);
217
251
  }
@@ -1,3 +1,4 @@
1
+ import fs from 'node:fs';
1
2
  import path from 'node:path';
2
3
  import { fileSystem } from '@ecopages/file-system';
3
4
  /**
@@ -129,10 +130,21 @@ export function resolveRouteModuleDependencyPaths(buildResult, entrypointPath, r
129
130
  const normalizedEntrypoint = path.isAbsolute(entrypointPath)
130
131
  ? path.normalize(entrypointPath)
131
132
  : path.normalize(path.resolve(rootDir, entrypointPath));
133
+ let realEntrypoint;
134
+ try {
135
+ realEntrypoint = fileSystem.exists(normalizedEntrypoint) ? fs.realpathSync(normalizedEntrypoint) : undefined;
136
+ }
137
+ catch {
138
+ // fall back
139
+ }
132
140
  const graphEntrypoints = buildResult.dependencyGraph?.entrypoints ?? {};
133
141
  const dependencyPaths = graphEntrypoints[normalizedEntrypoint] ??
142
+ (realEntrypoint ? graphEntrypoints[realEntrypoint] : undefined) ??
134
143
  graphEntrypoints[entrypointPath] ??
135
- Object.entries(graphEntrypoints).find(([candidate]) => path.normalize(candidate) === normalizedEntrypoint)?.[1];
144
+ Object.entries(graphEntrypoints).find(([candidate]) => {
145
+ const norm = path.normalize(candidate);
146
+ return norm === normalizedEntrypoint || (realEntrypoint !== undefined && norm === realEntrypoint);
147
+ })?.[1];
136
148
  if (!dependencyPaths || dependencyPaths.length === 0) {
137
149
  return [normalizedEntrypoint];
138
150
  }
@@ -0,0 +1,10 @@
1
+ import type { EcoPagesAppConfig } from '../../types/internal-types.js';
2
+ import type { ViewLoader } from '../../types/public-types.js';
3
+ /**
4
+ * Creates a view loader that imports through the app server-module transpiler.
5
+ *
6
+ * @remarks
7
+ * Use this for `app.static()` and HTML error-page registrations instead of
8
+ * raw dynamic `import()` so Node applies Ecopages build transforms (component identity).
9
+ */
10
+ export declare function createViewModuleLoader<P = Record<string, unknown>>(appConfig: EcoPagesAppConfig, modulePath: string | URL): ViewLoader<P>;
@@ -0,0 +1,46 @@
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { fileSystem } from '@ecopages/file-system';
4
+ import { resolveInternalExecutionDir } from '../../utils/resolve-work-dir.js';
5
+ import { getAppServerModuleTranspiler } from './app-server-module-transpiler.service.js';
6
+ function resolveViewModuleOnDisk(filePath, templatesExt) {
7
+ if (fileSystem.exists(filePath)) {
8
+ return filePath;
9
+ }
10
+ for (const extension of templatesExt) {
11
+ const withExtension = `${filePath}${extension}`;
12
+ if (fileSystem.exists(withExtension)) {
13
+ return withExtension;
14
+ }
15
+ }
16
+ const pathWithoutTerminalExtension = filePath.replace(/\.[^./]+$/, '');
17
+ for (const extension of templatesExt) {
18
+ const candidate = `${pathWithoutTerminalExtension}${extension}`;
19
+ if (fileSystem.exists(candidate)) {
20
+ return candidate;
21
+ }
22
+ }
23
+ return filePath;
24
+ }
25
+ function resolveViewModuleFilePath(appConfig, modulePath) {
26
+ const filePath = modulePath instanceof URL ? fileURLToPath(modulePath) : modulePath;
27
+ const rootedPath = path.isAbsolute(filePath)
28
+ ? filePath
29
+ : path.join(appConfig.rootDir, filePath.replace(/^\.\//, ''));
30
+ return resolveViewModuleOnDisk(rootedPath, appConfig.templatesExt);
31
+ }
32
+ /**
33
+ * Creates a view loader that imports through the app server-module transpiler.
34
+ *
35
+ * @remarks
36
+ * Use this for `app.static()` and HTML error-page registrations instead of
37
+ * raw dynamic `import()` so Node applies Ecopages build transforms (component identity).
38
+ */
39
+ export function createViewModuleLoader(appConfig, modulePath) {
40
+ const filePath = resolveViewModuleFilePath(appConfig, modulePath);
41
+ return async () => await getAppServerModuleTranspiler(appConfig).importModule({
42
+ filePath,
43
+ outdir: path.join(resolveInternalExecutionDir(appConfig), '.server-modules'),
44
+ externalPackages: true,
45
+ });
46
+ }
@@ -110,6 +110,7 @@ export declare class SchemaValidationService {
110
110
  * }
111
111
  * ```
112
112
  */
113
+ private validateRequestPart;
113
114
  validateRequest(source: ValidationSource, schemas: ValidationSchemas): Promise<ValidationResult<ValidatedData>>;
114
115
  /**
115
116
  * Validates a single value against a Standard Schema.
@@ -84,45 +84,32 @@ export class SchemaValidationService {
84
84
  * }
85
85
  * ```
86
86
  */
87
+ async validateRequestPart(schema, value, assign, allErrors, shouldValidate) {
88
+ if (!schema || !shouldValidate) {
89
+ return;
90
+ }
91
+ const result = await this.validateWithSchema(schema, value);
92
+ if (!result.success) {
93
+ allErrors.push(...(result.errors || []));
94
+ return;
95
+ }
96
+ assign(result.data);
97
+ }
87
98
  async validateRequest(source, schemas) {
88
99
  const validated = {};
89
100
  const allErrors = [];
90
- if (schemas.body && source.body !== undefined) {
91
- const result = await this.validateWithSchema(schemas.body, source.body);
92
- if (!result.success) {
93
- allErrors.push(...(result.errors || []));
94
- }
95
- else {
96
- validated.body = result.data;
97
- }
98
- }
99
- if (schemas.query && source.query) {
100
- const result = await this.validateWithSchema(schemas.query, source.query);
101
- if (!result.success) {
102
- allErrors.push(...(result.errors || []));
103
- }
104
- else {
105
- validated.query = result.data;
106
- }
107
- }
108
- if (schemas.headers && source.headers) {
109
- const result = await this.validateWithSchema(schemas.headers, source.headers);
110
- if (!result.success) {
111
- allErrors.push(...(result.errors || []));
112
- }
113
- else {
114
- validated.headers = result.data;
115
- }
116
- }
117
- if (schemas.params && source.params) {
118
- const result = await this.validateWithSchema(schemas.params, source.params);
119
- if (!result.success) {
120
- allErrors.push(...(result.errors || []));
121
- }
122
- else {
123
- validated.params = result.data;
124
- }
125
- }
101
+ await this.validateRequestPart(schemas.body, source.body, (data) => {
102
+ validated.body = data;
103
+ }, allErrors, schemas.body !== undefined && source.body !== undefined);
104
+ await this.validateRequestPart(schemas.query, source.query, (data) => {
105
+ validated.query = data;
106
+ }, allErrors, !!schemas.query && !!source.query);
107
+ await this.validateRequestPart(schemas.headers, source.headers, (data) => {
108
+ validated.headers = data;
109
+ }, allErrors, !!schemas.headers && !!source.headers);
110
+ await this.validateRequestPart(schemas.params, source.params, (data) => {
111
+ validated.params = data;
112
+ }, allErrors, !!schemas.params && !!source.params);
126
113
  if (allErrors.length > 0) {
127
114
  return { success: false, errors: allErrors };
128
115
  }
@@ -11,6 +11,7 @@ It is responsible for:
11
11
  - enumerating renderable routes
12
12
  - rendering static outputs through the normal rendering pipeline
13
13
  - respecting route-level constraints such as cache policy and unsupported dynamic server-only paths
14
+ - emitting semantic 404/500 artifacts through the shared error-page renderer
14
15
 
15
16
  ## Design Rule
16
17
 
@@ -25,6 +26,8 @@ That means it should reuse:
25
26
 
26
27
  It should not invent a parallel rendering stack just for build mode.
27
28
 
29
+ Semantic error pages are excluded from ordinary page enumeration and emitted once by `services/error-pages/semantic-error-page-exporter.ts`, so runtime and static output share source precedence and rendering behavior.
30
+
28
31
  ## Files
29
32
 
30
33
  | File | Role |
@@ -58,10 +61,12 @@ Integrations may implement:
58
61
  - `beforeStaticExport(context)` — runs after unified-graph prebuild, before page rendering
59
62
  - `afterStaticExport(context)` — runs in a `finally` block after generation completes
60
63
 
61
- When `appConfig.sitemap.enabled` is true, `sitemap.xml` is written **after** `afterStaticExport` so integration-generated URLs can be listed via `extraUrls`.
64
+ When `appConfig.sitemap.enabled` is true, `sitemap.xml` is written **after** `afterStaticExport` so integration-generated URLs can be listed via `extraUrls`. Development (`ecopages dev`) does not emit this file.
62
65
 
63
66
  Sitemap eligibility is decided during successful page export (`activeStaticPathnames` plus `robots.index !== false`, fail-closed on metadata errors). `resolveSitemapLocations` then applies `exclude` and appends `extraUrls`.
64
67
 
65
68
  `StaticExportContext.routes` is the unfiltered static-generation route list. Sitemap filtering is applied separately.
66
69
 
67
70
  See `StaticExportContext` in `static-export-context.ts`.
71
+
72
+ User-facing guide: [Sitemap](https://github.com/ecopages/ecopages/blob/main/apps/docs/src/content/docs/core/sitemap.mdx) in the docs app.
@@ -1,5 +1,5 @@
1
1
  import type { EcoPagesAppConfig } from '../types/internal-types.js';
2
- import type { SitemapConfig, StaticRoute } from '../types/public-types.js';
2
+ import type { SitemapConfig, StaticRoute, ErrorPageLoaders } from '../types/public-types.js';
3
3
  import type { PageRendererResolver, StaticGenerationRendererResolver } from '../route-renderer/route-renderer.js';
4
4
  import type { StaticGenerationRoute } from '../router/server/route-registry.js';
5
5
  import type { RouteModuleBuildCache } from '../services/module-loading/route-module-build-cache.store.js';
@@ -92,14 +92,19 @@ export declare class StaticSiteGenerator {
92
92
  }): Promise<void>;
93
93
  private createStaticExportContext;
94
94
  private invokeStaticExportHook;
95
+ private resetStaticGenerationState;
96
+ private ensureUnifiedGraphForStaticGeneration;
97
+ private executeStaticGenerationBody;
98
+ private finalizeStaticGenerationRun;
95
99
  /**
96
100
  * Executes the full static-generation workflow for one app run.
97
101
  */
98
- run({ router, baseUrl, routeRendererFactory, staticRoutes, force, preserveExportDirectory, }: {
102
+ run({ router, baseUrl, routeRendererFactory, staticRoutes, errorPageLoaders, force, preserveExportDirectory, }: {
99
103
  router: StaticGenerationRouteSource;
100
104
  baseUrl: string;
101
105
  routeRendererFactory?: StaticGenerationRendererFactory;
102
106
  staticRoutes?: StaticRoute[];
107
+ errorPageLoaders?: ErrorPageLoaders;
103
108
  force?: boolean;
104
109
  preserveExportDirectory?: boolean;
105
110
  }): Promise<void>;
@@ -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
  };