@ecopages/core 0.4.0 → 0.6.0

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 (163) hide show
  1. package/README.md +19 -15
  2. package/package.json +13 -4
  3. package/src/adapters/create-app.js +9 -5
  4. package/src/adapters/node/create-app.d.ts +18 -16
  5. package/src/adapters/node/create-app.js +26 -30
  6. package/src/adapters/node/server-adapter.d.ts +26 -9
  7. package/src/adapters/node/server-adapter.js +38 -8
  8. package/src/adapters/shared/hmr/hmr-manager.js +3 -2
  9. package/src/adapters/shared/http/api-request-pipeline.js +2 -2
  10. package/src/adapters/shared/http/dist-file-handler.js +25 -7
  11. package/src/adapters/shared/runtime/render-context.d.ts +2 -1
  12. package/src/adapters/shared/runtime/render-context.js +18 -21
  13. package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +4 -3
  14. package/src/adapters/shared/runtime/runtime-server-lifecycle.js +6 -4
  15. package/src/adapters/shared/runtime/server-request-pipeline.d.ts +6 -1
  16. package/src/adapters/shared/runtime/server-request-pipeline.js +11 -10
  17. package/src/adapters/shared/runtime/server-route-handler.js +4 -4
  18. package/src/adapters/shared/runtime/server-static-builder.d.ts +11 -11
  19. package/src/adapters/shared/runtime/server-static-builder.js +37 -18
  20. package/src/assets/app-browser-client-build.js +8 -21
  21. package/src/assets/app-browser-client-manifest.d.ts +1 -4
  22. package/src/assets/app-browser-client-manifest.js +6 -78
  23. package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +2 -2
  24. package/src/assets/asset-processing-service/processors/script/file-script.processor.js +2 -2
  25. package/src/assets/browser-asset-output.d.ts +1 -1
  26. package/src/assets/browser-asset-output.js +1 -1
  27. package/src/build/app-build-manifest-runtime.d.ts +11 -1
  28. package/src/build/app-build-manifest-runtime.js +17 -3
  29. package/src/build/cache/pages-unified-graph-build.d.ts +32 -35
  30. package/src/build/cache/pages-unified-graph-build.js +206 -124
  31. package/src/build/cache/server-module-entries.d.ts +35 -0
  32. package/src/build/cache/server-module-entries.js +109 -0
  33. package/src/build/contracts/build-contracts.d.ts +5 -0
  34. package/src/build/contracts/content-virtual-modules.d.ts +9 -3
  35. package/src/build/contracts/content-virtual-modules.js +11 -5
  36. package/src/build/contracts.d.ts +1 -1
  37. package/src/build/contracts.js +1 -1
  38. package/src/build/copy-server-files.d.ts +10 -0
  39. package/src/build/copy-server-files.js +37 -0
  40. package/src/build/preserve-import-meta-transform.d.ts +1 -1
  41. package/src/build/preserve-import-meta-transform.js +1 -1
  42. package/src/build/production-build-id.d.ts +9 -0
  43. package/src/build/production-build-id.js +19 -0
  44. package/src/build/production-dist-complete.d.ts +5 -0
  45. package/src/build/production-dist-complete.js +101 -0
  46. package/src/build/production-route-list.d.ts +26 -0
  47. package/src/build/production-route-list.js +78 -0
  48. package/src/build/rolldown/rolldown-adapter-helpers.d.ts +2 -2
  49. package/src/build/rolldown/rolldown-adapter-helpers.js +56 -4
  50. package/src/build/rolldown/rolldown-build-adapter.js +1 -1
  51. package/src/build/rolldown/rolldown-plugin-bridge.js +2 -2
  52. package/src/build/runtime/build-request-identity.js +2 -1
  53. package/src/build/runtime/build-request-policy.d.ts +3 -2
  54. package/src/build/runtime/build-request-policy.js +5 -3
  55. package/src/build/server/import-view-module.d.ts +11 -0
  56. package/src/build/server/import-view-module.js +21 -0
  57. package/src/build/server/imported-view-plugin.d.ts +16 -0
  58. package/src/build/server/imported-view-plugin.js +59 -0
  59. package/src/build/server/page-module-import.service.d.ts +19 -20
  60. package/src/build/server/page-module-import.service.js +65 -36
  61. package/src/build/server/resolve-static-view.d.ts +9 -0
  62. package/src/build/server/resolve-static-view.js +28 -0
  63. package/src/build/server/route-module-build-cache-registry.d.ts +5 -3
  64. package/src/build/server/route-module-build-cache-registry.js +5 -3
  65. package/src/build/server/server-modules-manifest.d.ts +51 -0
  66. package/src/build/server/server-modules-manifest.js +129 -0
  67. package/src/build/server/view-reference.d.ts +38 -0
  68. package/src/build/server/view-reference.js +112 -0
  69. package/src/build/server-bundle-deploy-manifest.d.ts +9 -9
  70. package/src/build/server-bundle-deploy-manifest.js +24 -28
  71. package/src/build.d.ts +4 -2
  72. package/src/build.js +4 -2
  73. package/src/config/assembly/app-runtime.d.ts +15 -2
  74. package/src/config/assembly/app-runtime.js +3 -1
  75. package/src/config/assembly/finalize-config.js +64 -13
  76. package/src/config/index.d.ts +1 -0
  77. package/src/config/index.js +1 -0
  78. package/src/config/internal-types.d.ts +6 -0
  79. package/src/config/load-eco-config.d.ts +1 -0
  80. package/src/config/load-eco-config.js +11 -2
  81. package/src/config/resolve-eco-config-path.d.ts +2 -1
  82. package/src/config/resolve-eco-config-path.js +21 -15
  83. package/src/config/user-config-types.d.ts +9 -2
  84. package/src/dev/transform-server/dev-transform-server.js +1 -1
  85. package/src/dev/transform-server/dev-transform-vendor-registry.d.ts +29 -6
  86. package/src/dev/transform-server/dev-transform-vendor-registry.js +101 -53
  87. package/src/errors/http-error.d.ts +9 -0
  88. package/src/errors/http-error.js +11 -0
  89. package/src/html/html-transformer.service.d.ts +0 -21
  90. package/src/html/html-transformer.service.js +0 -32
  91. package/src/html-pages/html-page-module.d.ts +19 -0
  92. package/src/html-pages/html-page-module.js +66 -13
  93. package/src/html-pages/html-page-renderer.d.ts +6 -1
  94. package/src/html-pages/html-page-renderer.js +14 -6
  95. package/src/html-pages/html-pages.plugin.d.ts +10 -0
  96. package/src/html-pages/html-pages.plugin.js +7 -1
  97. package/src/index.d.ts +2 -0
  98. package/src/index.js +2 -0
  99. package/src/integration.d.ts +2 -2
  100. package/src/integration.js +1 -1
  101. package/src/islands/island-host.d.ts +1 -2
  102. package/src/islands/island-host.js +1 -2
  103. package/src/page-cache/page-cache-service.d.ts +8 -0
  104. package/src/page-cache/page-cache-service.js +12 -0
  105. package/src/plugins/integration-plugin.d.ts +34 -7
  106. package/src/plugins/integration-plugin.js +14 -2
  107. package/src/plugins/processor.d.ts +18 -1
  108. package/src/plugins/processor.js +20 -1
  109. package/src/plugins/server-dom.d.ts +29 -0
  110. package/src/plugins/server-dom.js +36 -0
  111. package/src/plugins/tsconfig-import-resolver.d.ts +3 -1
  112. package/src/plugins/tsconfig-import-resolver.js +4 -2
  113. package/src/processor.d.ts +1 -1
  114. package/src/route-renderer/error-pages/error-page-renderer.d.ts +6 -4
  115. package/src/route-renderer/error-pages/error-page-renderer.js +9 -5
  116. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +2 -44
  117. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +14 -89
  118. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +4 -16
  119. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +2 -10
  120. package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +3 -5
  121. package/src/route-renderer/orchestration/integration-renderer.d.ts +21 -44
  122. package/src/route-renderer/orchestration/integration-renderer.js +69 -117
  123. package/src/route-renderer/orchestration/ownership-graph/page-client-browser-assets.d.ts +3 -4
  124. package/src/route-renderer/orchestration/ownership-graph/page-client-browser-assets.js +4 -15
  125. package/src/route-renderer/orchestration/ownership-graph/prepared-graph-membership.d.ts +22 -0
  126. package/src/route-renderer/orchestration/ownership-graph/prepared-graph-membership.js +45 -0
  127. package/src/route-renderer/orchestration/page-browser-graph/grouped-graph-build-plan.d.ts +0 -1
  128. package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.d.ts +21 -0
  129. package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.js +31 -0
  130. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +58 -24
  131. package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.d.ts +12 -0
  132. package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.js +55 -0
  133. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +4 -3
  134. package/src/router/server/route-registry.d.ts +23 -1
  135. package/src/router/server/route-registry.js +41 -14
  136. package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +8 -2
  137. package/src/static-site-generator/production-page-browser-graph-prebuild.js +14 -13
  138. package/src/static-site-generator/static-site-generator.d.ts +19 -3
  139. package/src/static-site-generator/static-site-generator.js +78 -40
  140. package/src/types/build-types.d.ts +6 -0
  141. package/src/types/contracts.d.ts +26 -35
  142. package/src/types/eco-api-types.d.ts +1 -1
  143. package/src/types/public-types.d.ts +1 -0
  144. package/src/types/view-reference.d.ts +31 -0
  145. package/src/types/view-reference.js +15 -0
  146. package/src/utils/additional-watch-paths.d.ts +3 -3
  147. package/src/utils/additional-watch-paths.js +3 -1
  148. package/src/utils/resolve-entry-file.d.ts +4 -2
  149. package/src/utils/resolve-entry-file.js +4 -2
  150. package/src/utils/root-relative-path.d.ts +4 -0
  151. package/src/utils/root-relative-path.js +8 -0
  152. package/src/utils/server-bundle-context.d.ts +14 -0
  153. package/src/utils/server-bundle-context.js +45 -0
  154. package/src/watchers/project-watcher-ignore.d.ts +2 -5
  155. package/src/watchers/project-watcher-ignore.js +2 -5
  156. package/src/watchers/project-watcher.d.ts +9 -7
  157. package/src/watchers/project-watcher.js +100 -52
  158. package/src/watchers/workspace-package-watch-roots.d.ts +4 -4
  159. package/src/watchers/workspace-package-watch-roots.js +41 -25
  160. package/src/build/server/view-module-loader.d.ts +0 -10
  161. package/src/build/server/view-module-loader.js +0 -46
  162. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-merge.utils.d.ts +0 -12
  163. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-merge.utils.js +0 -32
@@ -42,19 +42,15 @@ export interface PageModuleImportDependencies {
42
42
  buildModule(options: BuildOptions): Promise<BuildResult>;
43
43
  }
44
44
  /**
45
- * Loads page-like modules through the Ecopages build pipeline.
45
+ * Loads page-like modules for route scanning, page data loading, and request-time inspection.
46
46
  *
47
- * This service centralizes the shared build-first import strategy used by route
48
- * scanning, page data loading, and request-time page inspection.
49
- *
50
- * Keeping this logic in one place prevents subtle drift in cache-busting,
51
- * transpilation settings, and error semantics across the different callers.
47
+ * Production imports the module `ecopages build` emitted. Development compiles
48
+ * from source through the Ecopages build pipeline.
52
49
  */
53
50
  export declare class PageModuleImportService {
54
51
  private readonly appConfig;
55
52
  private readonly dependencies;
56
53
  private readonly importCache;
57
- private readonly productionFileHashes;
58
54
  private recordPipelineLoad;
59
55
  constructor(appConfig: EcoPagesAppConfig, dependencies?: Partial<PageModuleImportDependencies>);
60
56
  /**
@@ -72,12 +68,14 @@ export declare class PageModuleImportService {
72
68
  */
73
69
  invalidateDevelopmentGraph(): void;
74
70
  /**
75
- * Imports a page-like module from source.
71
+ * Imports a page-like module.
76
72
  *
77
- * The caller controls the output directory and error wording so different
78
- * subsystems can reuse the same loading mechanism while preserving their
79
- * current diagnostics. Module identities stay stable for unchanged files and
80
- * roll forward automatically when the source hash changes during watch mode.
73
+ * Production loads the module `ecopages build` emitted. Development compiles
74
+ * from source. The caller controls the output directory and error wording so
75
+ * different subsystems can reuse the same loading mechanism while preserving
76
+ * their current diagnostics. Development module identities stay stable for
77
+ * unchanged files and roll forward automatically when the source hash changes
78
+ * during watch mode.
81
79
  *
82
80
  * @typeParam T Expected module shape.
83
81
  * @param options Runtime-specific import settings.
@@ -85,18 +83,19 @@ export declare class PageModuleImportService {
85
83
  */
86
84
  importModule<T = unknown>(options: PageModuleBuildImportOptions): Promise<T>;
87
85
  /**
88
- * Imports a module whose sources cannot change while the process runs.
86
+ * Imports a compiled server module emitted by `ecopages build`.
89
87
  *
90
88
  * @remarks
91
- * In production nothing edits the sources and no watcher invalidates them: every build
92
- * compiles from source in a fresh process. The entry source hash is read once per service and
93
- * memoized for the build identity. An in-memory hit therefore avoids file hashing; after that
94
- * cache is cleared, the route-module cache may still hash tracked dependencies to validate its
95
- * compiled output.
89
+ * Production serving never compiles: a missing map entry or missing file is an
90
+ * error that names the source and says to run `ecopages build`. During
91
+ * `ecopages build`, before the map exists on disk, listing routes still compiles
92
+ * from source. `bypassCache` only skips the in-memory import promise, not the
93
+ * manifest. A path outside the deploy root still matches when it ends with a
94
+ * recorded source key, so `identity.file` from the build machine can load.
96
95
  */
97
- private importUnchangedModule;
96
+ private importFromProductionManifest;
97
+ private loadProductionManifestModule;
98
98
  private importWithCache;
99
- private getProductionFileHash;
100
99
  private resolveRouteModuleOutputNaming;
101
100
  private createRouteModuleBuildOptions;
102
101
  private createRouteModuleCacheBuildOptions;
@@ -6,7 +6,7 @@ import { requireAppRuntime } from '../../utils/app-runtime.js';
6
6
  import {} from '../../build/build-adapter.js';
7
7
  import { requireBuildQueue } from '../../build/runtime/build-queue.js';
8
8
  import { createServerBuildRequest } from '../../build/runtime/build-request-policy.js';
9
- import { importPagesUnifiedGraphModule, isPagesUnifiedGraphPage, shouldBuildPagesUnifiedGraph, } from '../../build/cache/pages-unified-graph-build.js';
9
+ import { importEmittedServerModule, importPagesUnifiedGraphModule, isPagesUnifiedGraphPage, } from '../../build/cache/pages-unified-graph-build.js';
10
10
  import { findIntegrationForFile } from '../../plugins/find-integration-for-file.js';
11
11
  import { recordPageModuleBuildInvocation } from '../../build/rolldown/rolldown-build-invocation-metrics.js';
12
12
  import { recordPageModuleLoad } from '../../diagnostics/request-pipeline-metrics.js';
@@ -15,20 +15,18 @@ import { getSharedRouteModuleBuildCache } from './route-module-build-cache-regis
15
15
  import { resolveRouteModuleDependencyPaths } from './route-module-dependency-hasher.js';
16
16
  import { assertBuildSucceeded } from '../../build/build-log.js';
17
17
  import { isDevelopmentRuntime, isProductionRuntime } from '../../utils/runtime.js';
18
+ import { toRootRelativePath } from '../../utils/root-relative-path.js';
19
+ import { loadProductionServerModules, matchProductionModuleKey, missingProductionServerModuleError, } from './server-modules-manifest.js';
18
20
  /**
19
- * Loads page-like modules through the Ecopages build pipeline.
21
+ * Loads page-like modules for route scanning, page data loading, and request-time inspection.
20
22
  *
21
- * This service centralizes the shared build-first import strategy used by route
22
- * scanning, page data loading, and request-time page inspection.
23
- *
24
- * Keeping this logic in one place prevents subtle drift in cache-busting,
25
- * transpilation settings, and error semantics across the different callers.
23
+ * Production imports the module `ecopages build` emitted. Development compiles
24
+ * from source through the Ecopages build pipeline.
26
25
  */
27
26
  export class PageModuleImportService {
28
27
  appConfig;
29
28
  dependencies;
30
29
  importCache = new Map();
31
- productionFileHashes = new Map();
32
30
  recordPipelineLoad(outcome, artifactCount = 0) {
33
31
  recordPageModuleLoad(requireAppRuntime(this.appConfig).requestPipelineMetrics, outcome, artifactCount);
34
32
  }
@@ -61,38 +59,78 @@ export class PageModuleImportService {
61
59
  this.clearImportCache();
62
60
  }
63
61
  /**
64
- * Imports a page-like module from source.
62
+ * Imports a page-like module.
65
63
  *
66
- * The caller controls the output directory and error wording so different
67
- * subsystems can reuse the same loading mechanism while preserving their
68
- * current diagnostics. Module identities stay stable for unchanged files and
69
- * roll forward automatically when the source hash changes during watch mode.
64
+ * Production loads the module `ecopages build` emitted. Development compiles
65
+ * from source. The caller controls the output directory and error wording so
66
+ * different subsystems can reuse the same loading mechanism while preserving
67
+ * their current diagnostics. Development module identities stay stable for
68
+ * unchanged files and roll forward automatically when the source hash changes
69
+ * during watch mode.
70
70
  *
71
71
  * @typeParam T Expected module shape.
72
72
  * @param options Runtime-specific import settings.
73
73
  * @returns The loaded module.
74
74
  */
75
75
  async importModule(options) {
76
- const { filePath } = options;
77
- if (!options.bypassCache && isProductionRuntime()) {
78
- return this.importUnchangedModule(options);
76
+ if (isProductionRuntime() && loadProductionServerModules(this.appConfig)) {
77
+ return this.importFromProductionManifest(options);
79
78
  }
80
- const fileHash = this.dependencies.hashFile(filePath);
79
+ const fileHash = this.dependencies.hashFile(options.filePath);
81
80
  return this.importWithCache(options, fileHash, !options.bypassCache);
82
81
  }
83
82
  /**
84
- * Imports a module whose sources cannot change while the process runs.
83
+ * Imports a compiled server module emitted by `ecopages build`.
85
84
  *
86
85
  * @remarks
87
- * In production nothing edits the sources and no watcher invalidates them: every build
88
- * compiles from source in a fresh process. The entry source hash is read once per service and
89
- * memoized for the build identity. An in-memory hit therefore avoids file hashing; after that
90
- * cache is cleared, the route-module cache may still hash tracked dependencies to validate its
91
- * compiled output.
86
+ * Production serving never compiles: a missing map entry or missing file is an
87
+ * error that names the source and says to run `ecopages build`. During
88
+ * `ecopages build`, before the map exists on disk, listing routes still compiles
89
+ * from source. `bypassCache` only skips the in-memory import promise, not the
90
+ * manifest. A path outside the deploy root still matches when it ends with a
91
+ * recorded source key, so `identity.file` from the build machine can load.
92
92
  */
93
- async importUnchangedModule(options) {
94
- const fileHash = this.getProductionFileHash(options.filePath);
95
- return this.importWithCache(options, fileHash, true);
93
+ async importFromProductionManifest(options) {
94
+ const manifest = loadProductionServerModules(this.appConfig);
95
+ const sourceKey = (manifest && matchProductionModuleKey(this.appConfig.rootDir, options.filePath, manifest.modules)) ??
96
+ toRootRelativePath(this.appConfig.rootDir, options.filePath);
97
+ const relativePath = manifest?.modules[sourceKey];
98
+ const cacheKey = `production::${relativePath ? path.resolve(manifest.outdir, relativePath) : sourceKey}`;
99
+ if (!options.bypassCache) {
100
+ const cachedModule = this.importCache.get(cacheKey);
101
+ if (cachedModule) {
102
+ const loadedModule = (await cachedModule.promise);
103
+ this.recordPipelineLoad('import-cache-hit');
104
+ return loadedModule;
105
+ }
106
+ }
107
+ const importPromise = this.loadProductionManifestModule(sourceKey);
108
+ if (!options.bypassCache) {
109
+ this.importCache.set(cacheKey, { promise: importPromise });
110
+ }
111
+ try {
112
+ return await importPromise;
113
+ }
114
+ catch (error) {
115
+ this.importCache.delete(cacheKey);
116
+ throw error;
117
+ }
118
+ }
119
+ async loadProductionManifestModule(sourceKey) {
120
+ const manifest = loadProductionServerModules(this.appConfig);
121
+ if (!manifest) {
122
+ throw missingProductionServerModuleError(sourceKey);
123
+ }
124
+ const relativePath = manifest.modules[sourceKey];
125
+ if (!relativePath) {
126
+ throw missingProductionServerModuleError(sourceKey);
127
+ }
128
+ const outputPath = path.join(manifest.outdir, relativePath);
129
+ if (!fileSystem.exists(outputPath)) {
130
+ throw missingProductionServerModuleError(sourceKey);
131
+ }
132
+ this.recordPipelineLoad('unified-graph');
133
+ return importEmittedServerModule(this.appConfig, path.resolve(this.appConfig.rootDir, sourceKey), outputPath);
96
134
  }
97
135
  async importWithCache(options, fileHash, cacheEnabled) {
98
136
  if (!cacheEnabled) {
@@ -128,15 +166,6 @@ export class PageModuleImportService {
128
166
  throw error;
129
167
  }
130
168
  }
131
- getProductionFileHash(filePath) {
132
- const cached = this.productionFileHashes.get(filePath);
133
- if (cached !== undefined) {
134
- return cached;
135
- }
136
- const fileHash = this.dependencies.hashFile(filePath);
137
- this.productionFileHashes.set(filePath, fileHash);
138
- return fileHash;
139
- }
140
169
  resolveRouteModuleOutputNaming(filePath, fileHash) {
141
170
  const outputFileName = createRuntimeBuildOutputFileName(resolvePageModuleOutputFileName({ filePath, fileHash }), this.getDevelopmentGeneration());
142
171
  return outputFileName.replace(/\.mjs$/u, '.[ext]');
@@ -179,7 +208,7 @@ export class PageModuleImportService {
179
208
  return loadedModule;
180
209
  }
181
210
  async tryLoadPagesUnifiedGraphModule(filePath) {
182
- if (!shouldBuildPagesUnifiedGraph() || !isPagesUnifiedGraphPage(filePath, this.appConfig)) {
211
+ if (!isProductionRuntime() || !isPagesUnifiedGraphPage(filePath, this.appConfig)) {
183
212
  return undefined;
184
213
  }
185
214
  const graphModule = await importPagesUnifiedGraphModule(this.appConfig, filePath);
@@ -0,0 +1,9 @@
1
+ import type { EcoPagesAppConfig } from '../../config/internal-types.js';
2
+ import type { EcoPageComponent, ViewLoader } from '../../types/contracts.js';
3
+ import { type ViewReference } from '../../types/view-reference.js';
4
+ export type StaticViewInput<P = Record<string, unknown>> = ViewLoader<P> | ViewReference<P> | EcoPageComponent<P>;
5
+ /**
6
+ * Turns an imported view, an inline `eco.page` component, or a loader into the
7
+ * lazy loader `app.static` and error pages store.
8
+ */
9
+ export declare function resolveStaticView<P>(appConfig: EcoPagesAppConfig, view: StaticViewInput<P>): ViewLoader<P>;
@@ -0,0 +1,28 @@
1
+ import { getComponentIdentity } from '../../eco/component-identity.js';
2
+ import { isViewReference } from '../../types/view-reference.js';
3
+ import { createViewLoaderFromFilePath } from './import-view-module.js';
4
+ const PATH_VIEW_REMOVED = 'String and URL view paths are removed. Import the view and pass it to app.static(), ctx.render(), or the error-page helpers.';
5
+ /**
6
+ * Turns an imported view, an inline `eco.page` component, or a loader into the
7
+ * lazy loader `app.static` and error pages store.
8
+ */
9
+ export function resolveStaticView(appConfig, view) {
10
+ if (typeof view === 'string' || view instanceof URL) {
11
+ throw new Error(PATH_VIEW_REMOVED);
12
+ }
13
+ if (isViewReference(view)) {
14
+ return createViewLoaderFromFilePath(appConfig, view.filePath);
15
+ }
16
+ if (typeof view === 'function' && 'config' in view && view.config) {
17
+ const loader = async () => ({ default: view });
18
+ const filePath = getComponentIdentity(view)?.file;
19
+ if (filePath) {
20
+ loader.filePath = filePath;
21
+ }
22
+ return loader;
23
+ }
24
+ if (typeof view === 'function') {
25
+ return view;
26
+ }
27
+ throw new Error('app.static and error pages expect an imported view, an eco.page component, or a view loader.');
28
+ }
@@ -1,11 +1,13 @@
1
1
  import type { EcoPagesAppConfig } from '../../config/internal-types.js';
2
2
  import { RouteModuleBuildCache } from './route-module-build-cache.store.js';
3
3
  /**
4
- * Returns the outdir whose transpile cache backs in-process static generation.
4
+ * Returns the outdir of route-module server builds and their transpile cache.
5
5
  *
6
6
  * @remarks
7
- * Static pages render through `.eco/.server-modules`; `.server-route-modules` only
8
- * serves route-registry scanning.
7
+ * Development builds every server module here. Production imports the modules emitted
8
+ * into `dist/server/` and builds here only for a module the server-modules map does not
9
+ * list, or for every module when `ECOPAGES_UNIFIED_PAGES_GRAPH` disables the map.
10
+ * `.server-route-modules` only serves route-registry scanning.
9
11
  */
10
12
  export declare function getServerModuleBuildCacheOutdir(appConfig: EcoPagesAppConfig): string;
11
13
  /**
@@ -4,11 +4,13 @@ import { requireAppRuntime } from '../../utils/app-runtime.js';
4
4
  import { resolveInternalExecutionDir } from '../../utils/resolve-work-dir.js';
5
5
  import { RouteModuleBuildCache } from './route-module-build-cache.store.js';
6
6
  /**
7
- * Returns the outdir whose transpile cache backs in-process static generation.
7
+ * Returns the outdir of route-module server builds and their transpile cache.
8
8
  *
9
9
  * @remarks
10
- * Static pages render through `.eco/.server-modules`; `.server-route-modules` only
11
- * serves route-registry scanning.
10
+ * Development builds every server module here. Production imports the modules emitted
11
+ * into `dist/server/` and builds here only for a module the server-modules map does not
12
+ * list, or for every module when `ECOPAGES_UNIFIED_PAGES_GRAPH` disables the map.
13
+ * `.server-route-modules` only serves route-registry scanning.
12
14
  */
13
15
  export function getServerModuleBuildCacheOutdir(appConfig) {
14
16
  return path.join(resolveInternalExecutionDir(appConfig), '.server-modules');
@@ -0,0 +1,51 @@
1
+ import type { EcoPagesAppConfig } from '../../config/internal-types.js';
2
+ export declare const SERVER_MODULES_MANIFEST_FILENAME = "server-modules.json";
3
+ /**
4
+ * Maps each server entry's root-relative source path to its emitted module,
5
+ * relative to {@link ProductionServerModulesManifest.outdir}.
6
+ */
7
+ export type ProductionServerModulesManifest = {
8
+ outdir: string;
9
+ buildId?: string;
10
+ modules: Record<string, string>;
11
+ };
12
+ export declare function getServerModulesManifestPath(outdir: string): string;
13
+ /**
14
+ * Writes the production server-modules map beside the emitted modules.
15
+ */
16
+ export declare function writeProductionServerModulesManifest(manifest: ProductionServerModulesManifest): void;
17
+ /**
18
+ * Source keys from `dist/server/server-modules.json`, before the app runtime exists.
19
+ */
20
+ export declare function listProductionServerModuleKeysFromDist(rootDir: string, distDir: string): string[] | undefined;
21
+ /**
22
+ * Returns the production server-modules map for this app, loading it from
23
+ * `dist/server/server-modules.json` when this process has not emitted one.
24
+ */
25
+ export declare function loadProductionServerModules(appConfig: EcoPagesAppConfig): ProductionServerModulesManifest | undefined;
26
+ /**
27
+ * Loads the production server-modules map or throws if `ecopages build` has not written it.
28
+ */
29
+ export declare function requireProductionServerModules(appConfig: EcoPagesAppConfig): ProductionServerModulesManifest;
30
+ /**
31
+ * Error when production cannot resolve a compiled server module.
32
+ *
33
+ * @remarks
34
+ * Names the source file and tells the operator to run `ecopages build`. It is
35
+ * never a compile fallback.
36
+ */
37
+ export declare function missingProductionServerModuleError(sourceKey: string): Error;
38
+ /**
39
+ * Finds the production map key for `filePath`.
40
+ *
41
+ * @remarks
42
+ * Prefers the path relative to `rootDir`. When `identity.file` still names the
43
+ * build machine (an absolute path outside the deploy root), the longest map key
44
+ * that is a suffix of that path wins, so a copied `dist/` can load scripts
45
+ * resolved from that identity.
46
+ */
47
+ export declare function matchProductionModuleKey(rootDir: string, filePath: string, modules: Record<string, string>): string | undefined;
48
+ /**
49
+ * True when `ecopages build` recorded a compiled module for `filePath`.
50
+ */
51
+ export declare function hasProductionServerModule(appConfig: EcoPagesAppConfig, filePath: string): boolean;
@@ -0,0 +1,129 @@
1
+ import path from 'node:path';
2
+ import { fileSystem } from '@ecopages/file-system';
3
+ import { requireAppRuntime } from '../../utils/app-runtime.js';
4
+ import { toRootRelativePath } from '../../utils/root-relative-path.js';
5
+ import { getServerBundleOutputPaths } from '../server-bundle-deploy-manifest.js';
6
+ import { SERVER_BUNDLE_DIR } from '../../utils/resolve-entry-file.js';
7
+ export const SERVER_MODULES_MANIFEST_FILENAME = 'server-modules.json';
8
+ export function getServerModulesManifestPath(outdir) {
9
+ return path.join(outdir, SERVER_MODULES_MANIFEST_FILENAME);
10
+ }
11
+ /**
12
+ * Writes the production server-modules map beside the emitted modules.
13
+ */
14
+ export function writeProductionServerModulesManifest(manifest) {
15
+ fileSystem.ensureDir(manifest.outdir);
16
+ const payload = {
17
+ ...(manifest.buildId ? { buildId: manifest.buildId } : {}),
18
+ modules: manifest.modules,
19
+ };
20
+ fileSystem.write(getServerModulesManifestPath(manifest.outdir), `${JSON.stringify(payload, null, '\t')}\n`);
21
+ }
22
+ /**
23
+ * Source keys from `dist/server/server-modules.json`, before the app runtime exists.
24
+ */
25
+ export function listProductionServerModuleKeysFromDist(rootDir, distDir) {
26
+ const payload = readProductionServerModulesFile(path.join(path.resolve(rootDir, distDir), SERVER_BUNDLE_DIR));
27
+ return payload ? Object.keys(payload.modules) : undefined;
28
+ }
29
+ function readProductionServerModulesFile(outdir) {
30
+ const manifestPath = getServerModulesManifestPath(outdir);
31
+ if (!fileSystem.exists(manifestPath)) {
32
+ return undefined;
33
+ }
34
+ try {
35
+ const payload = JSON.parse(fileSystem.readFileSync(manifestPath).toString());
36
+ if (!payload?.modules || typeof payload.modules !== 'object') {
37
+ return undefined;
38
+ }
39
+ return payload;
40
+ }
41
+ catch {
42
+ return undefined;
43
+ }
44
+ }
45
+ /**
46
+ * Returns the production server-modules map for this app, loading it from
47
+ * `dist/server/server-modules.json` when this process has not emitted one.
48
+ */
49
+ export function loadProductionServerModules(appConfig) {
50
+ const runtime = requireAppRuntime(appConfig);
51
+ if (runtime.productionServerModules) {
52
+ return runtime.productionServerModules;
53
+ }
54
+ const { serverOutdir } = getServerBundleOutputPaths(appConfig);
55
+ const payload = readProductionServerModulesFile(serverOutdir);
56
+ if (!payload) {
57
+ return undefined;
58
+ }
59
+ const manifest = {
60
+ outdir: serverOutdir,
61
+ buildId: payload.buildId,
62
+ modules: payload.modules,
63
+ };
64
+ runtime.productionServerModules = manifest;
65
+ return manifest;
66
+ }
67
+ /**
68
+ * Loads the production server-modules map or throws if `ecopages build` has not written it.
69
+ */
70
+ export function requireProductionServerModules(appConfig) {
71
+ const manifest = loadProductionServerModules(appConfig);
72
+ if (!manifest) {
73
+ throw new Error('No production server-modules map. Run `ecopages build`.');
74
+ }
75
+ return manifest;
76
+ }
77
+ /**
78
+ * Error when production cannot resolve a compiled server module.
79
+ *
80
+ * @remarks
81
+ * Names the source file and tells the operator to run `ecopages build`. It is
82
+ * never a compile fallback.
83
+ */
84
+ export function missingProductionServerModuleError(sourceKey) {
85
+ return new Error(`No compiled server module for ${sourceKey}. Run \`ecopages build\`.`);
86
+ }
87
+ function modulePathWithoutQuery(filePath) {
88
+ const query = filePath.indexOf('?');
89
+ return query === -1 ? filePath : filePath.slice(0, query);
90
+ }
91
+ /**
92
+ * Finds the production map key for `filePath`.
93
+ *
94
+ * @remarks
95
+ * Prefers the path relative to `rootDir`. When `identity.file` still names the
96
+ * build machine (an absolute path outside the deploy root), the longest map key
97
+ * that is a suffix of that path wins, so a copied `dist/` can load scripts
98
+ * resolved from that identity.
99
+ */
100
+ export function matchProductionModuleKey(rootDir, filePath, modules) {
101
+ const file = modulePathWithoutQuery(filePath);
102
+ const sourceKey = toRootRelativePath(rootDir, file);
103
+ if (sourceKey in modules) {
104
+ return sourceKey;
105
+ }
106
+ const posix = file.split(path.sep).join('/');
107
+ let match;
108
+ for (const key of Object.keys(modules)) {
109
+ if (posix === key || posix.endsWith(`/${key}`)) {
110
+ if (!match || key.length > match.length) {
111
+ match = key;
112
+ }
113
+ }
114
+ }
115
+ return match;
116
+ }
117
+ /**
118
+ * True when `ecopages build` recorded a compiled module for `filePath`.
119
+ */
120
+ export function hasProductionServerModule(appConfig, filePath) {
121
+ if (!appConfig.appRuntime) {
122
+ return false;
123
+ }
124
+ const manifest = loadProductionServerModules(appConfig);
125
+ if (!manifest) {
126
+ return false;
127
+ }
128
+ return matchProductionModuleKey(appConfig.rootDir, filePath, manifest.modules) !== undefined;
129
+ }
@@ -0,0 +1,38 @@
1
+ import { type ViewReference } from '../../types/view-reference.js';
2
+ export { isViewReference, VIEW_REFERENCE, type ViewReference } from '../../types/view-reference.js';
3
+ export type ViewIntegrationMatch = {
4
+ name: string;
5
+ extensions: readonly string[];
6
+ };
7
+ /**
8
+ * Integrations whose files become view references when imported from the server entry.
9
+ *
10
+ * @remarks
11
+ * Core owns `.html` unless an Integration already claims it, matching config finalization.
12
+ */
13
+ export declare function collectViewIntegrations(integrations: readonly ViewIntegrationMatch[] | undefined): ViewIntegrationMatch[];
14
+ /** True when a native import of this path must stay a real module. */
15
+ export declare function isIgnoredViewPath(filePath: string): boolean;
16
+ /**
17
+ * True when rewriting this file into a view reference would replace the server
18
+ * entry, the app config, or a module the app module loader still needs.
19
+ */
20
+ export declare function isExemptFromViewReference(filePath: string, options?: {
21
+ entryPath?: string;
22
+ importerPath?: string | null;
23
+ appRoot?: string;
24
+ requireAppImporter?: boolean;
25
+ }): boolean;
26
+ export declare function findViewOwner(integrations: readonly ViewIntegrationMatch[], filePath: string): ViewIntegrationMatch | undefined;
27
+ export declare function viewExtensionFilter(extensions: readonly string[]): RegExp;
28
+ /**
29
+ * Returns the one view reference for `filePath`.
30
+ *
31
+ * @remarks
32
+ * Two imports of the same file, including from the server-entry bundle and the
33
+ * development preload, share this object.
34
+ */
35
+ export declare function createViewReference<P = Record<string, unknown>>(filePath: string, integration?: string | null): ViewReference<P>;
36
+ /** Synthetic ESM source the CLI hook and server-entry plugin evaluate instead of the view. */
37
+ export declare function viewReferenceModuleSource(filePath: string, integrationName?: string): string;
38
+ export declare function assertIsViewReference(value: unknown): asserts value is ViewReference;
@@ -0,0 +1,112 @@
1
+ import path from 'node:path';
2
+ import { findIntegrationForFile } from '../../plugins/find-integration-for-file.js';
3
+ import { escapeRegExp } from '../../utils/regex-escaping.js';
4
+ import { isViewReference, VIEW_REFERENCE } from '../../types/view-reference.js';
5
+ export { isViewReference, VIEW_REFERENCE } from '../../types/view-reference.js';
6
+ const HTML_VIEW_EXTENSION = '.html';
7
+ /** Same name as `HTML_PAGES_INTEGRATION_NAME`; this file cannot import the Rendering layer. */
8
+ const HTML_VIEW_INTEGRATION = 'html-pages';
9
+ const viewReferences = new Map();
10
+ /**
11
+ * Integrations whose files become view references when imported from the server entry.
12
+ *
13
+ * @remarks
14
+ * Core owns `.html` unless an Integration already claims it, matching config finalization.
15
+ */
16
+ export function collectViewIntegrations(integrations) {
17
+ const listed = [...(integrations ?? [])];
18
+ if (!listed.some((integration) => integration.extensions.includes(HTML_VIEW_EXTENSION))) {
19
+ listed.push({ name: HTML_VIEW_INTEGRATION, extensions: [HTML_VIEW_EXTENSION] });
20
+ }
21
+ return listed;
22
+ }
23
+ const ECO_CONFIG_BASENAME = /^eco\.config(?:\.[cm]?[jt]sx?)?$/;
24
+ /** True when a native import of this path must stay a real module. */
25
+ export function isIgnoredViewPath(filePath) {
26
+ return filePath.split(path.sep).includes('node_modules');
27
+ }
28
+ function isInsideDir(filePath, dir) {
29
+ const relative = path.relative(path.resolve(dir), path.resolve(filePath));
30
+ return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
31
+ }
32
+ /**
33
+ * True when rewriting this file into a view reference would replace the server
34
+ * entry, the app config, or a module the app module loader still needs.
35
+ */
36
+ export function isExemptFromViewReference(filePath, options = {}) {
37
+ if (isIgnoredViewPath(filePath)) {
38
+ return true;
39
+ }
40
+ const resolvedPath = path.resolve(filePath);
41
+ if (options.entryPath && resolvedPath === path.resolve(options.entryPath)) {
42
+ return true;
43
+ }
44
+ if (ECO_CONFIG_BASENAME.test(path.basename(resolvedPath))) {
45
+ return true;
46
+ }
47
+ if (options.appRoot && !isInsideDir(resolvedPath, options.appRoot)) {
48
+ return true;
49
+ }
50
+ if (!options.requireAppImporter) {
51
+ return false;
52
+ }
53
+ const importerPath = options.importerPath;
54
+ if (!importerPath) {
55
+ return true;
56
+ }
57
+ if (isIgnoredViewPath(importerPath)) {
58
+ return true;
59
+ }
60
+ const appRoot = options.appRoot;
61
+ return appRoot !== undefined && !isInsideDir(importerPath, appRoot);
62
+ }
63
+ export function findViewOwner(integrations, filePath) {
64
+ if (isIgnoredViewPath(filePath)) {
65
+ return undefined;
66
+ }
67
+ return findIntegrationForFile(integrations, filePath);
68
+ }
69
+ export function viewExtensionFilter(extensions) {
70
+ return new RegExp(`(${extensions.map(escapeRegExp).join('|')})$`);
71
+ }
72
+ /**
73
+ * Returns the one view reference for `filePath`.
74
+ *
75
+ * @remarks
76
+ * Two imports of the same file, including from the server-entry bundle and the
77
+ * development preload, share this object.
78
+ */
79
+ export function createViewReference(filePath, integration) {
80
+ const resolvedPath = path.resolve(filePath);
81
+ const existing = viewReferences.get(resolvedPath);
82
+ if (existing) {
83
+ return existing;
84
+ }
85
+ const integrationName = integration ?? undefined;
86
+ const reference = {
87
+ [VIEW_REFERENCE]: true,
88
+ filePath: resolvedPath,
89
+ config: {
90
+ identity: {
91
+ id: resolvedPath,
92
+ file: resolvedPath,
93
+ integration: integrationName,
94
+ },
95
+ },
96
+ };
97
+ viewReferences.set(resolvedPath, reference);
98
+ return reference;
99
+ }
100
+ /** Synthetic ESM source the CLI hook and server-entry plugin evaluate instead of the view. */
101
+ export function viewReferenceModuleSource(filePath, integrationName) {
102
+ const pathLiteral = JSON.stringify(path.resolve(filePath));
103
+ const integrationLiteral = JSON.stringify(integrationName);
104
+ return `import { createViewReference } from '@ecopages/core/view-reference';
105
+ export default createViewReference(${pathLiteral}, ${integrationLiteral});
106
+ `;
107
+ }
108
+ export function assertIsViewReference(value) {
109
+ if (!isViewReference(value)) {
110
+ throw new Error('Expected an imported view reference.');
111
+ }
112
+ }