@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
@@ -1,20 +1,20 @@
1
1
  import type { EcoPagesAppConfig } from '../config/internal-types.js';
2
2
  /**
3
- * Describes the server bundle in `<distDir>/.server/manifest.json`.
3
+ * Describes the server bundle in `<distDir>/server/manifest.json`.
4
4
  *
5
5
  * @remarks
6
- * Every path is relative, so the bundle runs from any directory that keeps `dist/`
7
- * and the sources in their relative positions. `serverEntry` and `emittedConfigModule`
8
- * are relative to the manifest directory, `sourceConfigRelativePath` to the project root.
6
+ * Every path is relative, so the bundle runs from any directory that holds
7
+ * `dist/` and `node_modules/`. `serverEntry` and `emittedConfigModule` are
8
+ * relative to the manifest directory. `buildId` is shared with the other
9
+ * production manifests so `ecopages start` can refuse a mixed `dist/`.
9
10
  */
10
11
  export interface ServerBundleDeployManifest {
11
12
  serverEntry: string;
12
- sourceConfigRelativePath?: string;
13
13
  emittedConfigModule?: string;
14
- /** Content hash of the source config file when built. */
15
- configHash?: string;
16
14
  /** Content hash of the emitted production config artifact. */
17
15
  emittedConfigHash?: string;
16
+ /** Id shared with `routes.json`, `server-modules.json`, and the browser-client manifest. */
17
+ buildId?: string;
18
18
  }
19
19
  export declare function getServerBundleOutputPaths(appConfig: EcoPagesAppConfig): {
20
20
  distDir: string;
@@ -37,7 +37,7 @@ export declare function writeServerBundleDeployManifest(appConfig: EcoPagesAppCo
37
37
  *
38
38
  * @remarks
39
39
  * `ecopages start` does not load the app config, so it cannot read `distDir` from it. A given `distDir` is used
40
- * as is. Otherwise the directories directly below `cwd` that hold `.server/manifest.json` are the candidates:
40
+ * as is. Otherwise the directories directly below `cwd` that hold `server/manifest.json` are the candidates:
41
41
  * one is used, none or several fail. Dot-prefixed directories count; symlinked and nested outputs (`out/web`) do
42
42
  * not, and need `--dist-dir`. Guessing between several would run a stale bundle from an earlier build
43
43
  * that used another `distDir`.
@@ -65,6 +65,7 @@ export declare function resolveProductionServerEntry(rootDir: string, distDir: s
65
65
  /**
66
66
  * @remarks
67
67
  * Production `start` must not load a different config than the one compiled into the bundle.
68
+ * It compares only the emitted config artifact; it does not read source files.
68
69
  *
69
70
  * @param rootDir - Project root; `options.distDir` is relative to it.
70
71
  * @param options.distDir - The build output directory whose manifest is checked.
@@ -72,5 +73,4 @@ export declare function resolveProductionServerEntry(rootDir: string, distDir: s
72
73
  */
73
74
  export declare function assertProductionConfigIdentity(rootDir: string, requestedConfigPath: string | undefined, options: {
74
75
  distDir: string;
75
- isExplicitOverride?: boolean;
76
76
  }): void;
@@ -1,11 +1,12 @@
1
1
  import { contentHash } from '../utils/content-hash.js';
2
2
  import path from 'node:path';
3
3
  import { fileSystem } from '@ecopages/file-system';
4
- import { SERVER_BUNDLE_DIR, SERVER_BUNDLE_FILENAME } from '../utils/resolve-entry-file.js';
4
+ import { CLIENT_OUTPUT_DIR, SERVER_BUNDLE_DIR, SERVER_BUNDLE_FILENAME } from '../utils/resolve-entry-file.js';
5
+ import { ensureProductionBuildId } from './production-build-id.js';
5
6
  const SERVER_BUNDLE_MANIFEST_FILENAME = 'manifest.json';
6
7
  const DEFAULT_DIST_DIR = 'dist';
7
8
  export function getServerBundleOutputPaths(appConfig) {
8
- const distDir = appConfig.absolutePaths?.distDir ?? path.join(appConfig.rootDir, appConfig.distDir);
9
+ const distDir = path.resolve(appConfig.rootDir, appConfig.distDir);
9
10
  const serverOutdir = path.join(distDir, SERVER_BUNDLE_DIR);
10
11
  const serverEntryPath = path.join(serverOutdir, SERVER_BUNDLE_FILENAME);
11
12
  const manifestPath = path.join(serverOutdir, SERVER_BUNDLE_MANIFEST_FILENAME);
@@ -17,7 +18,7 @@ export function getServerBundleOutputPaths(appConfig) {
17
18
  * @remarks
18
19
  * The build may run under Bun while `ecopages start` checks the manifest under Node, so the hash must not depend
19
20
  * on the runtime or on the file-system implementation. SHA-256 is computed here rather than through
20
- * `fileSystem.hash`; it equals that hash today, so manifests written by earlier builds stay valid.
21
+ * `fileSystem.hash`. Start compares this hash of the emitted config only.
21
22
  */
22
23
  function hashDeployConfigFile(filePath) {
23
24
  return contentHash(fileSystem.readFileAsBuffer(filePath));
@@ -33,19 +34,18 @@ function hashExistingFile(filePath) {
33
34
  */
34
35
  export function writeServerBundleDeployManifest(appConfig, serverEntryPath, options) {
35
36
  const manifestDir = options?.outputDir ?? getServerBundleOutputPaths(appConfig).serverOutdir;
36
- const sourceConfigPath = appConfig.absolutePaths?.config;
37
37
  const emittedConfigPath = options?.emittedConfigModule
38
38
  ? path.join(manifestDir, options.emittedConfigModule)
39
39
  : undefined;
40
40
  const payload = {
41
41
  serverEntry: path.relative(manifestDir, serverEntryPath),
42
- sourceConfigRelativePath: sourceConfigPath ? path.relative(appConfig.rootDir, sourceConfigPath) : undefined,
43
42
  emittedConfigModule: options?.emittedConfigModule,
44
- configHash: hashExistingFile(sourceConfigPath),
45
43
  emittedConfigHash: hashExistingFile(emittedConfigPath),
44
+ buildId: ensureProductionBuildId(appConfig),
46
45
  };
47
46
  fileSystem.ensureDir(manifestDir);
48
47
  fileSystem.write(path.join(manifestDir, SERVER_BUNDLE_MANIFEST_FILENAME), `${JSON.stringify(payload, null, '\t')}\n`);
48
+ fileSystem.write(path.join(manifestDir, 'package.json'), `${JSON.stringify({ type: 'module' }, null, '\t')}\n`);
49
49
  }
50
50
  function resolveServerBundleDir(rootDir, distDir) {
51
51
  return path.resolve(rootDir, distDir, SERVER_BUNDLE_DIR);
@@ -56,18 +56,24 @@ function readServerBundleDeployManifest(serverDir) {
56
56
  return undefined;
57
57
  }
58
58
  try {
59
- return JSON.parse(fileSystem.readFileSync(manifestPath).toString());
59
+ const manifest = JSON.parse(fileSystem.readFileSync(manifestPath).toString());
60
+ return isServerBundleDeployManifest(manifest) ? manifest : undefined;
60
61
  }
61
62
  catch {
62
63
  return undefined;
63
64
  }
64
65
  }
66
+ function isServerBundleDeployManifest(value) {
67
+ return (typeof value === 'object' &&
68
+ value !== null &&
69
+ typeof value.serverEntry === 'string');
70
+ }
65
71
  /**
66
72
  * Selects the build output directory whose server bundle `ecopages start` runs.
67
73
  *
68
74
  * @remarks
69
75
  * `ecopages start` does not load the app config, so it cannot read `distDir` from it. A given `distDir` is used
70
- * as is. Otherwise the directories directly below `cwd` that hold `.server/manifest.json` are the candidates:
76
+ * as is. Otherwise the directories directly below `cwd` that hold `server/manifest.json` are the candidates:
71
77
  * one is used, none or several fail. Dot-prefixed directories count; symlinked and nested outputs (`out/web`) do
72
78
  * not, and need `--dist-dir`. Guessing between several would run a stale bundle from an earlier build
73
79
  * that used another `distDir`.
@@ -84,8 +90,8 @@ function readServerBundleDeployManifest(serverDir) {
84
90
  export async function resolveProductionDistDir(options = {}) {
85
91
  const cwd = path.resolve(options.cwd ?? process.cwd());
86
92
  const describe = (distDir) => path.relative(cwd, distDir) || '.';
87
- const staticOnlyError = (distDir) => new Error(`${describe(distDir)}/ holds a static-only build: it has no server bundle, so \`ecopages start\` cannot run it. Serve it with \`ecopages preview\` or deploy ${describe(distDir)}/ to a static host.`);
88
- const holdsBuiltHtml = (distDir) => fileSystem.exists(path.join(distDir, 'index.html'));
93
+ const staticOnlyError = (distDir) => new Error(`${describe(distDir)}/ holds a static-only build: it has no server bundle, so \`ecopages start\` cannot run it. Serve it with \`ecopages preview\` or deploy ${describe(distDir)}/${CLIENT_OUTPUT_DIR}/ to a static host.`);
94
+ const holdsBuiltHtml = (distDir) => fileSystem.exists(path.join(distDir, CLIENT_OUTPUT_DIR, 'index.html'));
89
95
  if (options.distDir !== undefined) {
90
96
  const distDir = path.resolve(cwd, options.distDir);
91
97
  if (!fileSystem.exists(path.join(resolveServerBundleDir(cwd, distDir), SERVER_BUNDLE_MANIFEST_FILENAME))) {
@@ -98,7 +104,10 @@ export async function resolveProductionDistDir(options = {}) {
98
104
  const manifests = await fileSystem.glob([`{*,.*}/${SERVER_BUNDLE_DIR}/${SERVER_BUNDLE_MANIFEST_FILENAME}`], {
99
105
  cwd,
100
106
  });
101
- const distDirs = manifests.map((manifest) => path.resolve(cwd, manifest, '..', '..')).sort();
107
+ const distDirs = manifests
108
+ .map((manifest) => path.resolve(cwd, manifest, '..', '..'))
109
+ .filter((distDir) => resolveProductionServerEntry(cwd, distDir) !== undefined)
110
+ .sort();
102
111
  if (distDirs.length > 1) {
103
112
  throw new Error(`Multiple production bundles found: ${distDirs.map(describe).join(', ')}. Pass --dist-dir <dir> to select one.`);
104
113
  }
@@ -135,23 +144,13 @@ function isEmittedConfigArtifact(manifest, manifestDir, requestedPath) {
135
144
  return (!manifest.emittedConfigHash ||
136
145
  (fileSystem.exists(requestedPath) && hashDeployConfigFile(requestedPath) === manifest.emittedConfigHash));
137
146
  }
138
- function matchesBuiltConfigHash(manifest, requestedPath) {
139
- if (!manifest.configHash || !fileSystem.exists(requestedPath)) {
140
- return false;
141
- }
142
- return hashDeployConfigFile(requestedPath) === manifest.configHash;
143
- }
144
- function matchesBuiltConfigPath(manifest, rootDir, requestedPath, isExplicitOverride) {
145
- if (manifest.configHash || isExplicitOverride || !manifest.sourceConfigRelativePath)
146
- return false;
147
- return path.relative(rootDir, requestedPath) === manifest.sourceConfigRelativePath;
148
- }
149
147
  function hasConfigIdentity(manifest) {
150
- return Boolean(manifest.emittedConfigModule || manifest.configHash || manifest.sourceConfigRelativePath);
148
+ return Boolean(manifest.emittedConfigModule || manifest.emittedConfigHash);
151
149
  }
152
150
  /**
153
151
  * @remarks
154
152
  * Production `start` must not load a different config than the one compiled into the bundle.
153
+ * It compares only the emitted config artifact; it does not read source files.
155
154
  *
156
155
  * @param rootDir - Project root; `options.distDir` is relative to it.
157
156
  * @param options.distDir - The build output directory whose manifest is checked.
@@ -168,11 +167,8 @@ export function assertProductionConfigIdentity(rootDir, requestedConfigPath, opt
168
167
  }
169
168
  if (!hasConfigIdentity(manifest))
170
169
  return;
171
- if (isEmittedConfigArtifact(manifest, manifestDir, requestedConfigPath) ||
172
- matchesBuiltConfigHash(manifest, requestedConfigPath) ||
173
- matchesBuiltConfigPath(manifest, rootDir, requestedConfigPath, options.isExplicitOverride)) {
170
+ if (isEmittedConfigArtifact(manifest, manifestDir, requestedConfigPath)) {
174
171
  return;
175
172
  }
176
- const expected = manifest.sourceConfigRelativePath ?? 'bundled config';
177
- throw new Error(`Ecopages config mismatch: production bundle was built with ${expected}, but start requested ${requestedConfigPath}.`);
173
+ throw new Error(`Ecopages config mismatch: production bundle was built with bundled config, but start requested ${requestedConfigPath}.`);
178
174
  }
package/src/build.d.ts CHANGED
@@ -3,10 +3,12 @@ export { createBrowserRuntimePlugin, DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME, getBro
3
3
  export { getHostScopedJsxOwnershipPlugins } from './build/browser/jsx-ownership-plugins.js';
4
4
  export { isLitStaticRenderWorkerThread } from './build/browser/lit-static-render-worker-context.js';
5
5
  export { type BuildAdapter, type BuildExecutor, type BuildOptions, type BuildResult, setupAppRuntimeIntegrations, setupAppRuntimePlugins, teardownAppRuntimeIntegrations, } from './build/build-adapter.js';
6
- export { CONTENT_BROWSER_VIRTUAL_MODULE_PATTERN, CONTENT_SERVER_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PREFIX, isContentServerVirtualModule, parseCollectionSpecifier, type ParsedCollectionSpecifier, } from './build/contracts/content-virtual-modules.js';
6
+ export { CONTENT_COMPONENT_VIRTUAL_MODULE_PATTERN, CONTENT_SERVER_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PREFIX, isContentServerVirtualModule, parseCollectionSpecifier, type ParsedCollectionSpecifier, } from './build/contracts/content-virtual-modules.js';
7
7
  export { isServerOnlyModuleSpecifier } from './build/contracts/server-only-specifier.js';
8
+ export { shouldBuildPagesUnifiedGraph } from './build/cache/pages-unified-graph-build.js';
8
9
  export { BuildQueue } from './build/runtime/build-queue.js';
9
10
  export { buildServerModule } from './build/server-module.js';
11
+ export { loadProductionServerModules, missingProductionServerModuleError, } from './build/server/server-modules-manifest.js';
10
12
  export { parseModuleSource, recordModuleTransformProfile } from './cache/index.js';
11
13
  export { GENERATED_BASE_PATHS, RESOLVED_ASSETS_DIR } from './constants.js';
12
14
  export { ECOPAGES_DEV_RESTART_EXIT_CODE, ECOPAGES_DEV_RESTART_REASON_ENV, ECOPAGES_ENTRY_WATCH_ENV, getDevEnvFileNames, resolveDevelopmentRecoveryWatch, } from './dev/development-restart.js';
@@ -15,5 +17,5 @@ export { toPackageRootSpecifier } from './plugins/package-specifier.js';
15
17
  export { loadTsconfigPathPrefixes, matchesTsconfigPathPrefix } from './plugins/tsconfig-import-resolver.js';
16
18
  export { contentHash } from './utils/content-hash.js';
17
19
  export { isPathInside } from './utils/path-containment.js';
18
- export { SERVER_BUNDLE_DIR, SERVER_BUNDLE_FILENAME } from './utils/resolve-entry-file.js';
20
+ export { CLIENT_OUTPUT_DIR, SERVER_BUNDLE_DIR, SERVER_BUNDLE_FILENAME } from './utils/resolve-entry-file.js';
19
21
  export { getEcopagesEnv, isDevelopmentRuntime, isEcopagesEnvDisabled, isEcopagesEnvEnabled, isProductionRuntime, type EcopagesBooleanEnvironmentVariable, type EcopagesEnvironmentVariable, } from './env.js';
package/src/build.js CHANGED
@@ -3,10 +3,12 @@ export { createBrowserRuntimePlugin, DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME, getBro
3
3
  export { getHostScopedJsxOwnershipPlugins } from './build/browser/jsx-ownership-plugins.js';
4
4
  export { isLitStaticRenderWorkerThread } from './build/browser/lit-static-render-worker-context.js';
5
5
  export { setupAppRuntimeIntegrations, setupAppRuntimePlugins, teardownAppRuntimeIntegrations, } from './build/build-adapter.js';
6
- export { CONTENT_BROWSER_VIRTUAL_MODULE_PATTERN, CONTENT_SERVER_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PREFIX, isContentServerVirtualModule, parseCollectionSpecifier, } from './build/contracts/content-virtual-modules.js';
6
+ export { CONTENT_COMPONENT_VIRTUAL_MODULE_PATTERN, CONTENT_SERVER_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PREFIX, isContentServerVirtualModule, parseCollectionSpecifier, } from './build/contracts/content-virtual-modules.js';
7
7
  export { isServerOnlyModuleSpecifier } from './build/contracts/server-only-specifier.js';
8
+ export { shouldBuildPagesUnifiedGraph } from './build/cache/pages-unified-graph-build.js';
8
9
  export { BuildQueue } from './build/runtime/build-queue.js';
9
10
  export { buildServerModule } from './build/server-module.js';
11
+ export { loadProductionServerModules, missingProductionServerModuleError, } from './build/server/server-modules-manifest.js';
10
12
  export { parseModuleSource, recordModuleTransformProfile } from './cache/index.js';
11
13
  export { GENERATED_BASE_PATHS, RESOLVED_ASSETS_DIR } from './constants.js';
12
14
  export { ECOPAGES_DEV_RESTART_EXIT_CODE, ECOPAGES_DEV_RESTART_REASON_ENV, ECOPAGES_ENTRY_WATCH_ENV, getDevEnvFileNames, resolveDevelopmentRecoveryWatch, } from './dev/development-restart.js';
@@ -15,5 +17,5 @@ export { toPackageRootSpecifier } from './plugins/package-specifier.js';
15
17
  export { loadTsconfigPathPrefixes, matchesTsconfigPathPrefix } from './plugins/tsconfig-import-resolver.js';
16
18
  export { contentHash } from './utils/content-hash.js';
17
19
  export { isPathInside } from './utils/path-containment.js';
18
- export { SERVER_BUNDLE_DIR, SERVER_BUNDLE_FILENAME } from './utils/resolve-entry-file.js';
20
+ export { CLIENT_OUTPUT_DIR, SERVER_BUNDLE_DIR, SERVER_BUNDLE_FILENAME } from './utils/resolve-entry-file.js';
19
21
  export { getEcopagesEnv, isDevelopmentRuntime, isEcopagesEnvDisabled, isEcopagesEnvEnabled, isProductionRuntime, } from './env.js';
@@ -3,9 +3,9 @@ import { BuildQueue } from '../../build/runtime/build-queue.js';
3
3
  import { SessionPageBrowserGraphCache } from '../../route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js';
4
4
  import type { EcoPagesAppConfig } from '../internal-types.js';
5
5
  import type { BuildAdapter } from '../../build/build-adapter.js';
6
- import type { PagesUnifiedGraphCacheManifest } from '../../build/cache/pages-unified-graph-build.js';
7
6
  import type { AppBuildManifest } from '../../build/contracts/build-manifest.js';
8
7
  import type { AppModuleLoaderContract } from '../../build/server/app-module-loader.service.js';
8
+ import type { ProductionServerModulesManifest } from '../../build/server/server-modules-manifest.js';
9
9
  import type { RouteModuleBuildCache } from '../../build/server/route-module-build-cache.store.js';
10
10
  import type { RequestPipelineMetricsState } from '../../diagnostics/request-pipeline-metrics.js';
11
11
  import type { HtmlPageWarningState } from '../../html-pages/html-page-warning-state.js';
@@ -42,7 +42,7 @@ export interface AppRuntime {
42
42
  buildManifest: AppBuildManifest;
43
43
  buildQueue: BuildQueue;
44
44
  buildInputIndex: BuildInputDependencyIndex;
45
- pagesUnifiedGraphManifest: PagesUnifiedGraphCacheManifest | null;
45
+ productionServerModules: ProductionServerModulesManifest | null;
46
46
  pageBrowserGraphSession: SessionPageBrowserGraphCache;
47
47
  serverInvalidation: ServerInvalidationState;
48
48
  developmentInvalidation: DevelopmentInvalidationService | null;
@@ -52,12 +52,25 @@ export interface AppRuntime {
52
52
  integrationActivations: Map<string, Promise<void>>;
53
53
  runtimeAssetsPrepared: boolean;
54
54
  hmrAttachedToIntegrations: boolean;
55
+ /**
56
+ * Id shared by every production manifest written during one `ecopages build`.
57
+ *
58
+ * @remarks
59
+ * Null until a production export creates one. `ecopages start` reads the id
60
+ * from the files in `dist/` instead of this field.
61
+ */
62
+ productionBuildId: string | null;
55
63
  htmlPageModuleScripts: HtmlPageModuleScriptState;
56
64
  htmlPageWarnings: HtmlPageWarningState;
57
65
  customElementSsrPreloadScopes: Map<string, CustomElementScriptPreloadScopeState>;
58
66
  requestPipelineMetrics: RequestPipelineMetricsState;
59
67
  origin: string;
60
68
  hmr: IHmrManager | null;
69
+ /**
70
+ * When true, a production request whose Page Browser Graph is not in the browser client
71
+ * manifest is an error. `ecopages start` sets this after it restores the manifest.
72
+ */
73
+ productionBrowserGraphsSealed: boolean;
61
74
  }
62
75
  /**
63
76
  * Builds the one {@link AppRuntime} for `appConfig` and stores it on the config.
@@ -53,7 +53,7 @@ export function createAppRuntime(appConfig) {
53
53
  buildManifest: createAppBuildManifest([]),
54
54
  buildQueue,
55
55
  buildInputIndex,
56
- pagesUnifiedGraphManifest: null,
56
+ productionServerModules: null,
57
57
  pageBrowserGraphSession: new SessionPageBrowserGraphCache(buildInputIndex),
58
58
  serverInvalidation: new ServerInvalidationState(),
59
59
  developmentInvalidation: null,
@@ -63,12 +63,14 @@ export function createAppRuntime(appConfig) {
63
63
  integrationActivations: new Map(),
64
64
  runtimeAssetsPrepared: false,
65
65
  hmrAttachedToIntegrations: false,
66
+ productionBuildId: null,
66
67
  htmlPageModuleScripts: createHtmlPageModuleScriptState(),
67
68
  htmlPageWarnings: createHtmlPageWarningState(),
68
69
  customElementSsrPreloadScopes: new Map(),
69
70
  requestPipelineMetrics: createRequestPipelineMetricsState(),
70
71
  origin: appConfig.baseUrl,
71
72
  hmr: null,
73
+ productionBrowserGraphsSealed: false,
72
74
  };
73
75
  appConfig.appRuntime = runtime;
74
76
  try {
@@ -11,6 +11,9 @@ import { ENDPOINT_FILE_EXTENSIONS, findEndpointFileExtension } from '../../utils
11
11
  import { DEFAULT_ECOPAGES_DIST_DIR, DEFAULT_ECOPAGES_HOSTNAME, DEFAULT_ECOPAGES_PORT, DEFAULT_ECOPAGES_WORK_DIR, } from '../../constants.js';
12
12
  import { collectConfigModuleFiles } from '../config-module-files.js';
13
13
  import { DEFAULT_ECO_CONFIG_FILENAME, resolveUserConfigRootDir } from '../resolve-eco-config-path.js';
14
+ import { listProductionServerModuleKeysFromDist } from '../../build/server/server-modules-manifest.js';
15
+ import { toRootRelativePath } from '../../utils/root-relative-path.js';
16
+ import { CLIENT_OUTPUT_DIR, SERVER_BUNDLE_DIR } from '../../utils/resolve-entry-file.js';
14
17
  const finalizedPluginInstances = new WeakSet();
15
18
  /**
16
19
  * Rejects values that are not a `defineConfig(...)` object.
@@ -29,6 +32,37 @@ function assertUserConfig(userConfig, configFilePath) {
29
32
  throw new Error('finalizeEcoPagesConfig() takes the user config first: finalizeEcoPagesConfig(userConfig, { configFilePath }).');
30
33
  }
31
34
  }
35
+ /**
36
+ * Treats an emitted `dist/server/eco.config.mjs` as living under the deploy root.
37
+ *
38
+ * @remarks
39
+ * Production no longer rewrites `import.meta` to the source config, so the
40
+ * emitted file's directory is `dist/server/`. The app root is the directory
41
+ * that contains `dist/`, taken from the config path so a worker that reloads
42
+ * the emitted file does not need `process.cwd()` to be the deploy root.
43
+ */
44
+ function resolveEmittedConfigRootDir(rootDir, configFilePath, distDirName, cwd) {
45
+ const resolvedConfig = path.resolve(configFilePath);
46
+ const serverDir = path.dirname(resolvedConfig);
47
+ if (path.basename(serverDir) === SERVER_BUNDLE_DIR) {
48
+ const emittedDistDir = path.dirname(serverDir);
49
+ const normalizedDistDir = path.normalize(distDirName);
50
+ const distSegments = normalizedDistDir.split(/[\\/]/u).filter((segment) => segment !== '' && segment !== '.');
51
+ const deployRoot = path.resolve(emittedDistDir, ...distSegments.map(() => '..'));
52
+ if (path.resolve(deployRoot, distDirName) === emittedDistDir) {
53
+ return deployRoot;
54
+ }
55
+ }
56
+ const distCandidates = [path.resolve(cwd, distDirName), path.resolve(rootDir, distDirName)];
57
+ const isEmitted = distCandidates.some((candidate) => isPathInside(resolvedConfig, candidate));
58
+ if (!isEmitted) {
59
+ return rootDir;
60
+ }
61
+ if (distCandidates.some((candidate) => isPathInside(rootDir, candidate) || rootDir === candidate)) {
62
+ return cwd;
63
+ }
64
+ return rootDir;
65
+ }
32
66
  /** An empty string keeps the default, as an omitted field does. */
33
67
  function resolveDirectories(userConfig) {
34
68
  return {
@@ -121,17 +155,30 @@ function getPluginInstances(userConfig) {
121
155
  * Resolves `dirPath/basename` against the registered template extensions.
122
156
  *
123
157
  * @remarks
124
- * When no file exists, the path uses the first extension so callers still get a
125
- * stable, non-existent candidate.
158
+ * A file on disk wins. When none exists, a unique recorded source key in
159
+ * `dist/server/server-modules.json` is the production template, so
160
+ * `ecopages start` from a copied `dist/` still finds `404.html` instead of the
161
+ * first Integration extension. Otherwise the path uses the first extension so
162
+ * callers still get a stable, non-existent candidate.
126
163
  *
127
164
  * @throws When more than one extension matches, such as `html.tsx` next to `html.html`.
128
165
  */
129
- function resolveSemanticTemplatePath(dirPath, basename, extensions) {
130
- const matches = extensions
131
- .map((extension) => path.join(dirPath, `${basename}${extension}`))
132
- .filter((candidate) => fileSystem.exists(candidate));
166
+ function resolveSemanticTemplatePath(dirPath, basename, extensions, rootDir, distDir) {
167
+ const candidates = extensions.map((extension) => path.join(dirPath, `${basename}${extension}`));
168
+ const matches = candidates.filter((candidate) => fileSystem.exists(candidate));
133
169
  invariant(matches.length <= 1, `Multiple ${basename} templates found: ${matches.join(', ')}`);
134
- return matches[0] ?? path.join(dirPath, `${basename}${extensions[0]}`);
170
+ if (matches[0]) {
171
+ return matches[0];
172
+ }
173
+ const recordedKeys = listProductionServerModuleKeysFromDist(rootDir, distDir) ?? [];
174
+ const recorded = candidates
175
+ .map((candidate) => toRootRelativePath(rootDir, candidate))
176
+ .filter((key) => recordedKeys.includes(key));
177
+ invariant(recorded.length <= 1, `Multiple ${basename} templates found in the production map: ${recorded.join(', ')}`);
178
+ if (recorded[0]) {
179
+ return path.resolve(rootDir, recorded[0]);
180
+ }
181
+ return path.join(dirPath, `${basename}${extensions[0]}`);
135
182
  }
136
183
  /**
137
184
  * @remarks
@@ -149,7 +196,7 @@ function createAbsolutePaths(config, configFilePath, configModuleFiles) {
149
196
  const srcDir = path.resolve(config.rootDir, config.srcDir);
150
197
  const includesDir = path.join(srcDir, config.includesDir);
151
198
  const pagesDir = path.join(srcDir, config.pagesDir);
152
- const errorPage = (status) => resolveSemanticTemplatePath(pagesDir, String(status), config.templatesExt);
199
+ const errorPage = (status) => resolveSemanticTemplatePath(pagesDir, String(status), config.templatesExt, config.rootDir, config.distDir);
153
200
  const errorPageTemplatePaths = {
154
201
  400: errorPage(400),
155
202
  401: errorPage(401),
@@ -163,14 +210,14 @@ function createAbsolutePaths(config, configFilePath, configModuleFiles) {
163
210
  configModuleFiles,
164
211
  projectDir: config.rootDir,
165
212
  srcDir,
166
- distDir: path.resolve(config.rootDir, config.distDir),
213
+ distDir: path.resolve(config.rootDir, config.distDir, CLIENT_OUTPUT_DIR),
167
214
  workDir: path.resolve(config.rootDir, config.workDir),
168
215
  componentsDir: path.join(srcDir, config.componentsDir),
169
216
  includesDir,
170
217
  layoutsDir: path.join(srcDir, config.layoutsDir),
171
218
  pagesDir,
172
219
  publicDir: path.join(srcDir, config.publicDir),
173
- htmlTemplatePath: resolveSemanticTemplatePath(includesDir, 'html', config.templatesExt),
220
+ htmlTemplatePath: resolveSemanticTemplatePath(includesDir, 'html', config.templatesExt, config.rootDir, config.distDir),
174
221
  errorPageTemplatePaths,
175
222
  error404TemplatePath: errorPageTemplatePaths[404],
176
223
  error500TemplatePath: errorPageTemplatePaths[500],
@@ -209,12 +256,16 @@ export async function finalizeEcoPagesConfig(userConfig, options = {}) {
209
256
  for (const plugin of pluginInstances)
210
257
  finalizedPluginInstances.add(plugin);
211
258
  try {
212
- const rootDir = resolveUserConfigRootDir(userConfig.rootDir, options.cwd);
259
+ const cwd = options.cwd ?? process.cwd();
260
+ const directories = resolveDirectories(userConfig);
261
+ let rootDir = resolveUserConfigRootDir(userConfig.rootDir, cwd);
262
+ const configFilePath = options.configFilePath ?? path.join(rootDir, DEFAULT_ECO_CONFIG_FILENAME);
263
+ rootDir = resolveEmittedConfigRootDir(rootDir, configFilePath, directories.distDir, cwd);
213
264
  const integrations = withHtmlPagesIntegration(userConfig.integrations ?? []);
214
265
  const partialConfig = {
215
266
  baseUrl: resolveBaseUrl(userConfig.baseUrl),
216
267
  rootDir,
217
- ...resolveDirectories(userConfig),
268
+ ...directories,
218
269
  robotsTxt: userConfig.robotsTxt ?? { preferences: { '*': [] } },
219
270
  sitemap: resolveSitemap(userConfig.sitemap),
220
271
  defaultMetadata: {
@@ -228,10 +279,10 @@ export async function finalizeEcoPagesConfig(userConfig, options = {}) {
228
279
  loaders: indexByName('Loader', userConfig.loaders),
229
280
  additionalWatchPaths: userConfig.additionalWatchPaths ?? [],
230
281
  devPrewarmPaths: userConfig.devPrewarmPaths ?? [],
282
+ serverFiles: userConfig.serverFiles,
231
283
  cache: userConfig.cache,
232
284
  devToolbar: userConfig.devToolbar,
233
285
  };
234
- const configFilePath = options.configFilePath ?? path.join(rootDir, DEFAULT_ECO_CONFIG_FILENAME);
235
286
  const config = {
236
287
  ...partialConfig,
237
288
  absolutePaths: createAbsolutePaths(partialConfig, configFilePath, await resolveConfigModuleFiles(configFilePath, options.configFilePath !== undefined, rootDir, partialConfig.distDir)),
@@ -3,4 +3,5 @@ export { loadEcoPagesConfig, loadEcoPagesUserConfig } from './load-eco-config.js
3
3
  export { finalizeEcoPagesConfig } from './assembly/finalize-config.js';
4
4
  export { resolveEcoConfigPath, resolveEmittedEcoConfigPath, resolveUserConfigRootDir, DEFAULT_ECO_CONFIG_FILENAME, ECOPAGES_CONFIG_FILE_ENV, } from './resolve-eco-config-path.js';
5
5
  export { assertProductionConfigIdentity, resolveProductionServerEntry, resolveProductionDistDir, } from '../build/server-bundle-deploy-manifest.js';
6
+ export { assertProductionDistComplete } from '../build/production-dist-complete.js';
6
7
  export type { EcoPagesUserConfig, EcoPagesUserConfigFactory, LoadedEcoPagesUserConfig, LoadEcoPagesConfigOptions, } from './user-config-types.js';
@@ -3,3 +3,4 @@ export { loadEcoPagesConfig, loadEcoPagesUserConfig } from './load-eco-config.js
3
3
  export { finalizeEcoPagesConfig } from './assembly/finalize-config.js';
4
4
  export { resolveEcoConfigPath, resolveEmittedEcoConfigPath, resolveUserConfigRootDir, DEFAULT_ECO_CONFIG_FILENAME, ECOPAGES_CONFIG_FILE_ENV, } from './resolve-eco-config-path.js';
5
5
  export { assertProductionConfigIdentity, resolveProductionServerEntry, resolveProductionDistDir, } from '../build/server-bundle-deploy-manifest.js';
6
+ export { assertProductionDistComplete } from '../build/production-dist-complete.js';
@@ -96,6 +96,11 @@ export type EcoPagesAppConfig = {
96
96
  sitemap: SitemapConfig;
97
97
  /** Additional paths to watch. Use this to monitor extra files. It is relative to the rootDir */
98
98
  additionalWatchPaths: string[];
99
+ /**
100
+ * Globs, relative to `rootDir`, of files copied into `dist/server/` at build
101
+ * so production modules can read them next to `import.meta`.
102
+ */
103
+ serverFiles?: string[];
99
104
  /**
100
105
  * Static paths to SSR-prewarm in the background during development.
101
106
  *
@@ -124,6 +129,7 @@ export type EcoPagesAppConfig = {
124
129
  */
125
130
  configModuleFiles: string[];
126
131
  componentsDir: string;
132
+ /** Public output directory served by the runtime (`<distDir>/client`). */
127
133
  distDir: string;
128
134
  workDir: string;
129
135
  includesDir: string;
@@ -13,3 +13,4 @@ export declare function loadEcoPagesUserConfig(options?: LoadEcoPagesConfigOptio
13
13
  * state belongs to each caller.
14
14
  */
15
15
  export declare function loadEcoPagesConfig(options?: LoadEcoPagesConfigOptions): Promise<EcoPagesAppConfig>;
16
+ export declare function loadEcoPagesConfigFromServerBundle(options: LoadEcoPagesConfigOptions, serverBundleDir: string): Promise<EcoPagesAppConfig>;
@@ -1,7 +1,8 @@
1
1
  import path from 'node:path';
2
2
  import { pathToFileURL } from 'node:url';
3
3
  import { finalizeEcoPagesConfig } from './assembly/finalize-config.js';
4
- import { resolveEcoConfigPath } from './resolve-eco-config-path.js';
4
+ import { resolveEcoConfigPath, resolveEcoConfigPathFromServerBundle } from './resolve-eco-config-path.js';
5
+ import { getProductionServerBundleDir } from '../utils/server-bundle-context.js';
5
6
  const moduleLoadCache = new Map();
6
7
  function resolveLoaderCwd(cwd) {
7
8
  return path.resolve(cwd ?? process.cwd());
@@ -64,8 +65,16 @@ export async function loadEcoPagesUserConfig(options = {}) {
64
65
  * state belongs to each caller.
65
66
  */
66
67
  export async function loadEcoPagesConfig(options = {}) {
68
+ return await loadEcoPagesConfigWithBundleDir(options, getProductionServerBundleDir());
69
+ }
70
+ export async function loadEcoPagesConfigFromServerBundle(options, serverBundleDir) {
71
+ return await loadEcoPagesConfigWithBundleDir(options, serverBundleDir);
72
+ }
73
+ async function loadEcoPagesConfigWithBundleDir(options, serverBundleDir) {
67
74
  const cwd = resolveLoaderCwd(options.cwd);
68
- const configFilePath = resolveEcoConfigPath({ ...options, cwd });
75
+ const configFilePath = serverBundleDir
76
+ ? resolveEcoConfigPathFromServerBundle({ ...options, cwd }, serverBundleDir)
77
+ : resolveEcoConfigPath({ ...options, cwd });
69
78
  const exported = await loadConfigModule(configFilePath);
70
79
  const userConfig = materializeUserConfig(exported, configFilePath);
71
80
  return await finalizeEcoPagesConfig(userConfig, { configFilePath, cwd });
@@ -5,7 +5,7 @@ export declare const ECOPAGES_CONFIG_FILE_ENV = "ECOPAGES_CONFIG_FILE";
5
5
  *
6
6
  * @remarks
7
7
  * Defaults to `cwd` so source configs, in-memory `createApp({ userConfig })`,
8
- * and production loads of `dist/.server/eco.config.mjs` share one rule.
8
+ * and production loads of `dist/server/eco.config.mjs` share one rule.
9
9
  * `path.resolve` keeps an explicit absolute `rootDir` unchanged.
10
10
  */
11
11
  export declare function resolveUserConfigRootDir(rootDir?: string, cwd?: string): string;
@@ -36,3 +36,4 @@ export declare function resolveEcoConfigPath(options: ResolveEcoConfigPathOption
36
36
  required: false;
37
37
  }): string | undefined;
38
38
  export declare function resolveEcoConfigPath(options?: ResolveEcoConfigPathOptions): string;
39
+ export declare function resolveEcoConfigPathFromServerBundle(options: ResolveEcoConfigPathOptions, serverBundleDir: string): string;
@@ -2,6 +2,7 @@ import path from 'node:path';
2
2
  import { getEcopagesEnv } from '../env.js';
3
3
  import { fileSystem } from '@ecopages/file-system';
4
4
  import { SERVER_BUNDLE_DIR } from '../utils/resolve-entry-file.js';
5
+ import { getProductionServerBundleDir } from '../utils/server-bundle-context.js';
5
6
  import { EMITTED_ECO_CONFIG_FILENAME } from './server-config-bundle.js';
6
7
  export const DEFAULT_ECO_CONFIG_FILENAME = 'eco.config.ts';
7
8
  export const ECOPAGES_CONFIG_FILE_ENV = 'ECOPAGES_CONFIG_FILE';
@@ -10,7 +11,7 @@ export const ECOPAGES_CONFIG_FILE_ENV = 'ECOPAGES_CONFIG_FILE';
10
11
  *
11
12
  * @remarks
12
13
  * Defaults to `cwd` so source configs, in-memory `createApp({ userConfig })`,
13
- * and production loads of `dist/.server/eco.config.mjs` share one rule.
14
+ * and production loads of `dist/server/eco.config.mjs` share one rule.
14
15
  * `path.resolve` keeps an explicit absolute `rootDir` unchanged.
15
16
  */
16
17
  export function resolveUserConfigRootDir(rootDir, cwd = process.cwd()) {
@@ -22,26 +23,31 @@ export function resolveEmittedEcoConfigPath(cwd, distDir) {
22
23
  return fileSystem.exists(candidate) ? candidate : undefined;
23
24
  }
24
25
  /**
25
- * Returns the emitted config next to the running entry when that entry is a
26
- * server bundle, such as `node dist/.server/app.mjs` or `bun dist/.server/app.mjs`.
26
+ * Returns the emitted config next to the running server bundle.
27
27
  *
28
28
  * @remarks
29
- * Reads `process.argv[1]` rather than `import.meta`, because server builds
30
- * rewrite bundled `import.meta` to the source location. The source config
31
- * would make Node import TypeScript from `node_modules`, which it does not
32
- * strip. `ecopages dev` runs the source entry, so it keeps `eco.config.ts`.
29
+ * The generated loader records its own directory before dynamically importing the
30
+ * application bundle. The application may be launched by a wrapper, so `process.argv[1]`
31
+ * does not reliably identify the server bundle. `ecopages dev` has no loader context and
32
+ * keeps using `eco.config.ts`.
33
33
  */
34
- function resolveRunningServerBundleConfigPath() {
35
- const entry = process.argv[1];
36
- if (!entry)
34
+ function resolveRunningServerBundleConfigPath(serverBundleDir) {
35
+ const resolvedServerBundleDir = serverBundleDir ?? getProductionServerBundleDir();
36
+ if (!resolvedServerBundleDir)
37
37
  return undefined;
38
- const entryDir = path.dirname(path.resolve(entry));
39
- if (path.basename(entryDir) !== SERVER_BUNDLE_DIR)
40
- return undefined;
41
- const candidate = path.join(entryDir, EMITTED_ECO_CONFIG_FILENAME);
38
+ const candidate = path.join(resolvedServerBundleDir, EMITTED_ECO_CONFIG_FILENAME);
42
39
  return fileSystem.exists(candidate) ? candidate : undefined;
43
40
  }
44
41
  export function resolveEcoConfigPath(options = {}) {
42
+ return resolveEcoConfigPathWithServerBundleDir(options, getProductionServerBundleDir());
43
+ }
44
+ export function resolveEcoConfigPathFromServerBundle(options, serverBundleDir) {
45
+ const resolvedPath = resolveEcoConfigPathWithServerBundleDir(options, serverBundleDir);
46
+ if (!resolvedPath)
47
+ throw new Error('Ecopages config path was unexpectedly unresolved.');
48
+ return resolvedPath;
49
+ }
50
+ function resolveEcoConfigPathWithServerBundleDir(options, serverBundleDir) {
45
51
  const cwd = options.cwd ?? process.cwd();
46
52
  const required = options.required ?? true;
47
53
  const explicitPath = options.configFile || getEcopagesEnv(ECOPAGES_CONFIG_FILE_ENV);
@@ -52,7 +58,7 @@ export function resolveEcoConfigPath(options = {}) {
52
58
  }
53
59
  return resolved;
54
60
  }
55
- const serverBundleConfigPath = resolveRunningServerBundleConfigPath();
61
+ const serverBundleConfigPath = resolveRunningServerBundleConfigPath(serverBundleDir);
56
62
  if (serverBundleConfigPath)
57
63
  return serverBundleConfigPath;
58
64
  const defaultPath = path.resolve(cwd, DEFAULT_ECO_CONFIG_FILENAME);
@@ -42,7 +42,7 @@ export type EcoPagesUserConfig = {
42
42
  */
43
43
  srcDir?: string;
44
44
  /**
45
- * Directory for static public assets copied directly to `distDir`, relative to `rootDir`.
45
+ * Directory for static public assets copied into `<distDir>/client`, relative to `rootDir`.
46
46
  *
47
47
  * @default 'public'
48
48
  */
@@ -66,7 +66,7 @@ export type EcoPagesUserConfig = {
66
66
  */
67
67
  layoutsDir?: string;
68
68
  /**
69
- * Output directory for the production build, relative to `rootDir`.
69
+ * Output root for the production build, relative to `rootDir`. Public files are written to `client/` and private server output to `server/` beneath it.
70
70
  *
71
71
  * @default 'dist'
72
72
  */
@@ -97,6 +97,13 @@ export type EcoPagesUserConfig = {
97
97
  * Additional file or directory paths to watch during development.
98
98
  */
99
99
  additionalWatchPaths?: string[];
100
+ /**
101
+ * Globs, relative to `rootDir`, of files copied into `dist/server/` by
102
+ * basename so production code can read them next to `import.meta`. Two
103
+ * matches that share a basename fail the build. Prefer `public/` for static
104
+ * files the browser should fetch.
105
+ */
106
+ serverFiles?: string[];
100
107
  /**
101
108
  * URL route paths to prewarm in the background when the development server starts.
102
109
  */