@ecopages/core 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -14
- package/package.json +13 -4
- package/src/adapters/create-app.js +9 -5
- package/src/adapters/node/create-app.d.ts +18 -16
- package/src/adapters/node/create-app.js +26 -30
- package/src/adapters/node/server-adapter.d.ts +26 -9
- package/src/adapters/node/server-adapter.js +38 -8
- package/src/adapters/shared/hmr/hmr-manager.js +3 -2
- package/src/adapters/shared/http/dist-file-handler.js +25 -7
- package/src/adapters/shared/runtime/render-context.d.ts +2 -1
- package/src/adapters/shared/runtime/render-context.js +18 -21
- package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +4 -3
- package/src/adapters/shared/runtime/runtime-server-lifecycle.js +6 -4
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +6 -1
- package/src/adapters/shared/runtime/server-request-pipeline.js +10 -10
- package/src/adapters/shared/runtime/server-static-builder.d.ts +11 -11
- package/src/adapters/shared/runtime/server-static-builder.js +37 -18
- package/src/assets/app-browser-client-manifest.d.ts +1 -3
- package/src/assets/app-browser-client-manifest.js +5 -58
- package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +2 -2
- package/src/assets/asset-processing-service/processors/script/file-script.processor.js +2 -2
- package/src/assets/browser-asset-output.d.ts +1 -1
- package/src/assets/browser-asset-output.js +1 -1
- package/src/build/app-build-manifest-runtime.d.ts +11 -1
- package/src/build/app-build-manifest-runtime.js +17 -3
- package/src/build/cache/pages-unified-graph-build.d.ts +32 -35
- package/src/build/cache/pages-unified-graph-build.js +206 -124
- package/src/build/cache/server-module-entries.d.ts +35 -0
- package/src/build/cache/server-module-entries.js +109 -0
- package/src/build/contracts/build-contracts.d.ts +5 -0
- package/src/build/copy-server-files.d.ts +10 -0
- package/src/build/copy-server-files.js +37 -0
- package/src/build/preserve-import-meta-transform.d.ts +1 -1
- package/src/build/preserve-import-meta-transform.js +1 -1
- package/src/build/production-build-id.d.ts +9 -0
- package/src/build/production-build-id.js +19 -0
- package/src/build/production-dist-complete.d.ts +5 -0
- package/src/build/production-dist-complete.js +101 -0
- package/src/build/production-route-list.d.ts +26 -0
- package/src/build/production-route-list.js +78 -0
- package/src/build/rolldown/rolldown-adapter-helpers.d.ts +2 -2
- package/src/build/rolldown/rolldown-adapter-helpers.js +56 -4
- package/src/build/rolldown/rolldown-build-adapter.js +1 -1
- package/src/build/runtime/build-request-identity.js +2 -1
- package/src/build/runtime/build-request-policy.d.ts +3 -2
- package/src/build/runtime/build-request-policy.js +5 -3
- package/src/build/server/import-view-module.d.ts +11 -0
- package/src/build/server/import-view-module.js +21 -0
- package/src/build/server/imported-view-plugin.d.ts +16 -0
- package/src/build/server/imported-view-plugin.js +59 -0
- package/src/build/server/page-module-import.service.d.ts +19 -20
- package/src/build/server/page-module-import.service.js +65 -36
- package/src/build/server/resolve-static-view.d.ts +9 -0
- package/src/build/server/resolve-static-view.js +28 -0
- package/src/build/server/route-module-build-cache-registry.d.ts +5 -3
- package/src/build/server/route-module-build-cache-registry.js +5 -3
- package/src/build/server/server-modules-manifest.d.ts +51 -0
- package/src/build/server/server-modules-manifest.js +129 -0
- package/src/build/server/view-reference.d.ts +38 -0
- package/src/build/server/view-reference.js +112 -0
- package/src/build/server-bundle-deploy-manifest.d.ts +9 -9
- package/src/build/server-bundle-deploy-manifest.js +24 -28
- package/src/build.d.ts +3 -1
- package/src/build.js +3 -1
- package/src/config/assembly/app-runtime.d.ts +15 -2
- package/src/config/assembly/app-runtime.js +3 -1
- package/src/config/assembly/finalize-config.js +64 -13
- package/src/config/index.d.ts +1 -0
- package/src/config/index.js +1 -0
- package/src/config/internal-types.d.ts +6 -0
- package/src/config/load-eco-config.d.ts +1 -0
- package/src/config/load-eco-config.js +11 -2
- package/src/config/resolve-eco-config-path.d.ts +2 -1
- package/src/config/resolve-eco-config-path.js +21 -15
- package/src/config/user-config-types.d.ts +9 -2
- package/src/html-pages/html-page-module.d.ts +19 -0
- package/src/html-pages/html-page-module.js +66 -13
- package/src/html-pages/html-page-renderer.d.ts +4 -0
- package/src/html-pages/html-page-renderer.js +9 -3
- package/src/html-pages/html-pages.plugin.d.ts +10 -0
- package/src/html-pages/html-pages.plugin.js +7 -1
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
- package/src/integration.d.ts +2 -1
- package/src/integration.js +1 -0
- package/src/page-cache/page-cache-service.d.ts +8 -0
- package/src/page-cache/page-cache-service.js +12 -0
- package/src/plugins/integration-plugin.d.ts +33 -6
- package/src/plugins/integration-plugin.js +14 -2
- package/src/plugins/processor.d.ts +17 -0
- package/src/plugins/processor.js +20 -1
- package/src/plugins/server-dom.d.ts +29 -0
- package/src/plugins/server-dom.js +36 -0
- package/src/route-renderer/error-pages/error-page-renderer.d.ts +6 -4
- package/src/route-renderer/error-pages/error-page-renderer.js +9 -5
- package/src/route-renderer/orchestration/integration-renderer.d.ts +1 -0
- package/src/route-renderer/orchestration/integration-renderer.js +17 -2
- package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.d.ts +21 -0
- package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.js +31 -0
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +58 -24
- package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.d.ts +12 -0
- package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.js +55 -0
- package/src/router/client/navigation-commit.js +16 -2
- package/src/router/client/navigation-head-order.fixture.css +3 -0
- package/src/router/client/navigation-head.d.ts +2 -1
- package/src/router/client/navigation-head.fixture.css +3 -0
- package/src/router/client/navigation-head.js +222 -39
- package/src/router/server/route-registry.d.ts +22 -2
- package/src/router/server/route-registry.js +39 -15
- package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +8 -2
- package/src/static-site-generator/production-page-browser-graph-prebuild.js +14 -9
- package/src/static-site-generator/static-site-generator.d.ts +19 -3
- package/src/static-site-generator/static-site-generator.js +78 -40
- package/src/types/contracts.d.ts +20 -31
- package/src/types/public-types.d.ts +1 -0
- package/src/types/view-reference.d.ts +31 -0
- package/src/types/view-reference.js +15 -0
- package/src/utils/additional-watch-paths.d.ts +3 -3
- package/src/utils/additional-watch-paths.js +3 -1
- package/src/utils/resolve-entry-file.d.ts +4 -2
- package/src/utils/resolve-entry-file.js +4 -2
- package/src/utils/root-relative-path.d.ts +4 -0
- package/src/utils/root-relative-path.js +8 -0
- package/src/utils/server-bundle-context.d.ts +14 -0
- package/src/utils/server-bundle-context.js +45 -0
- package/src/watchers/project-watcher-ignore.d.ts +2 -5
- package/src/watchers/project-watcher-ignore.js +2 -5
- package/src/watchers/project-watcher.d.ts +9 -7
- package/src/watchers/project-watcher.js +100 -52
- package/src/watchers/workspace-package-watch-roots.d.ts +4 -4
- package/src/watchers/workspace-package-watch-roots.js +41 -25
- package/src/build/server/view-module-loader.d.ts +0 -10
- package/src/build/server/view-module-loader.js +0 -46
|
@@ -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
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type { EcoPagesAppConfig } from '../config/internal-types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Describes the server bundle in `<distDir
|
|
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
|
|
7
|
-
* and
|
|
8
|
-
*
|
|
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
|
|
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 =
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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.
|
|
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
|
-
|
|
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
|
@@ -5,8 +5,10 @@ export { isLitStaticRenderWorkerThread } from './build/browser/lit-static-render
|
|
|
5
5
|
export { type BuildAdapter, type BuildExecutor, type BuildOptions, type BuildResult, setupAppRuntimeIntegrations, setupAppRuntimePlugins, teardownAppRuntimeIntegrations, } from './build/build-adapter.js';
|
|
6
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
|
@@ -5,8 +5,10 @@ export { isLitStaticRenderWorkerThread } from './build/browser/lit-static-render
|
|
|
5
5
|
export { setupAppRuntimeIntegrations, setupAppRuntimePlugins, teardownAppRuntimeIntegrations, } from './build/build-adapter.js';
|
|
6
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
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
125
|
-
*
|
|
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
|
|
131
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
...
|
|
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)),
|
package/src/config/index.d.ts
CHANGED
|
@@ -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';
|
package/src/config/index.js
CHANGED
|
@@ -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>;
|