@ecopages/core 0.2.0-rc.0 → 0.2.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -33
- package/package.json +58 -4
- package/src/adapters/README.md +3 -1
- package/src/adapters/abstract/application-adapter.d.ts +28 -6
- package/src/adapters/abstract/application-adapter.js +58 -5
- package/src/adapters/abstract/segment-path-matcher.js +56 -38
- package/src/adapters/abstract/server-adapter.d.ts +14 -0
- package/src/adapters/abstract/server-adapter.js +10 -0
- package/src/adapters/bun/create-app.d.ts +10 -6
- package/src/adapters/bun/create-app.js +64 -37
- package/src/adapters/bun/server-adapter.d.ts +6 -2
- package/src/adapters/bun/server-adapter.js +14 -1
- package/src/adapters/create-app.d.ts +62 -7
- package/src/adapters/create-app.js +61 -5
- package/src/adapters/node/create-app.d.ts +5 -5
- package/src/adapters/node/create-app.js +18 -5
- package/src/adapters/node/runtime-host.js +9 -4
- package/src/adapters/node/server-adapter.d.ts +5 -1
- package/src/adapters/node/server-adapter.js +16 -1
- package/src/adapters/shared/http/define-api-handler.d.ts +7 -49
- package/src/adapters/shared/http/explicit-static-route-matcher.js +5 -2
- package/src/adapters/shared/http/fs-server-response-factory.d.ts +2 -8
- package/src/adapters/shared/http/fs-server-response-factory.js +5 -30
- package/src/adapters/shared/http/fs-server-response-matcher.d.ts +24 -24
- package/src/adapters/shared/http/fs-server-response-matcher.js +59 -83
- package/src/adapters/shared/runtime/application-adapter.d.ts +1 -0
- package/src/adapters/shared/runtime/application-adapter.js +12 -0
- package/src/adapters/shared/runtime/bind-runtime-server.d.ts +17 -0
- package/src/adapters/shared/runtime/bind-runtime-server.js +50 -0
- package/src/adapters/shared/runtime/port-manager-default-prompt.d.ts +6 -0
- package/src/adapters/shared/runtime/port-manager-default-prompt.js +41 -0
- package/src/adapters/shared/runtime/port-manager.d.ts +3 -3
- package/src/adapters/shared/runtime/port-manager.js +14 -45
- package/src/adapters/shared/runtime/server-adapter.d.ts +14 -5
- package/src/adapters/shared/runtime/server-adapter.js +22 -30
- package/src/adapters/shared/runtime/server-route-handler.js +11 -3
- package/src/adapters/shared/runtime/server-static-builder.d.ts +9 -3
- package/src/adapters/shared/runtime/server-static-builder.js +59 -37
- package/src/build/README.md +5 -1
- package/src/build/cache/server-entry-build-cache.d.ts +24 -1
- package/src/build/cache/server-entry-build-cache.js +125 -8
- package/src/build/contracts/content-virtual-modules.d.ts +3 -1
- package/src/build/contracts/content-virtual-modules.js +8 -0
- package/src/build/rolldown/rolldown-adapter-helpers.js +56 -31
- package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
- package/src/build/rolldown/runtime-build-output-normalizer.js +3 -29
- package/src/build/runtime/build-request-policy.js +1 -1
- package/src/build/server-bundle-publication.d.ts +14 -0
- package/src/build/server-bundle-publication.js +49 -0
- package/src/config/README.md +17 -2
- package/src/config/apply-user-config.d.ts +6 -0
- package/src/config/apply-user-config.js +67 -0
- package/src/config/config-builder.d.ts +10 -1
- package/src/config/config-builder.js +51 -10
- package/src/config/constants.d.ts +4 -0
- package/src/config/constants.js +4 -0
- package/src/config/define-config.d.ts +9 -0
- package/src/config/define-config.js +10 -0
- package/src/config/index.d.ts +5 -0
- package/src/config/index.js +4 -0
- package/src/config/is-finalized-app-config.d.ts +6 -0
- package/src/config/is-finalized-app-config.js +11 -0
- package/src/config/load-eco-config.d.ts +21 -0
- package/src/config/load-eco-config.js +100 -0
- package/src/config/resolve-eco-config-path.d.ts +23 -0
- package/src/config/resolve-eco-config-path.js +47 -0
- package/src/config/server-config-bundle.d.ts +25 -0
- package/src/config/server-config-bundle.js +148 -0
- package/src/config/user-config-types.d.ts +164 -0
- package/src/config/user-config-types.js +1 -0
- package/src/css-imports.d.ts +4 -0
- package/src/declarations.d.ts +11 -5
- package/src/dev/README.md +6 -0
- package/src/dev/development-restart-watch-paths.d.ts +13 -0
- package/src/dev/development-restart-watch-paths.js +37 -0
- package/src/dev/development-restart.d.ts +13 -0
- package/src/dev/development-restart.js +21 -0
- package/src/dev/transform-server/dev-transform-server.d.ts +6 -0
- package/src/dev/transform-server/dev-transform-server.js +16 -5
- package/src/eco/README.md +73 -5
- package/src/eco/component-identity.d.ts +3 -2
- package/src/eco/component-identity.js +5 -2
- package/src/eco/discovered-dependencies.d.ts +45 -0
- package/src/eco/discovered-dependencies.js +87 -0
- package/src/eco/eco.js +6 -0
- package/src/eco/eco.types.d.ts +18 -2
- package/src/eco/lazy-injector-map.js +57 -41
- package/src/eco/page-dependency-contributions.d.ts +19 -0
- package/src/eco/page-dependency-contributions.js +52 -0
- package/src/errors/http-error-page-contract.d.ts +77 -0
- package/src/errors/http-error-page-contract.js +106 -0
- package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
- package/src/hmr/strategies/js-hmr-strategy.js +24 -16
- package/src/index.browser.d.ts +3 -0
- package/src/index.browser.js +3 -0
- package/src/index.d.ts +4 -1
- package/src/index.js +4 -1
- package/src/islands/README.md +5 -1
- package/src/plugins/README.md +10 -2
- package/src/plugins/component-import-discovery.d.ts +19 -0
- package/src/plugins/component-import-discovery.js +241 -0
- package/src/plugins/eco-component-meta-plugin.d.ts +3 -1
- package/src/plugins/eco-component-meta-plugin.js +118 -16
- package/src/plugins/integration-plugin.d.ts +4 -9
- package/src/plugins/processor.d.ts +23 -2
- package/src/plugins/processor.js +25 -0
- package/src/plugins/tsconfig-import-resolver.d.ts +3 -1
- package/src/plugins/tsconfig-import-resolver.js +4 -2
- package/src/route-renderer/GRAPH.md +1 -1
- package/src/route-renderer/README.md +16 -3
- package/src/{adapters/shared/http/explicit-static-render-preparation.d.ts → route-renderer/explicit-view-render-preparation.d.ts} +3 -3
- package/src/route-renderer/orchestration/custom-element-scripts/README.md +9 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +16 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +34 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +80 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +190 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +17 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +41 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +10 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +46 -0
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +7 -2
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +2 -0
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.d.ts +13 -1
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.js +15 -0
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +11 -2
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +10 -2
- package/src/route-renderer/orchestration/integration-renderer.d.ts +11 -5
- package/src/route-renderer/orchestration/integration-renderer.js +42 -29
- package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +2 -5
- package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +2 -68
- package/src/route-renderer/orchestration/ownership-graph/component-graph.js +55 -39
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +6 -0
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +59 -36
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +8 -10
- package/src/route-renderer/orchestration/string-markup-renderer.d.ts +1 -1
- package/src/route-renderer/orchestration/string-markup-renderer.js +10 -8
- package/src/route-renderer/page-loading/component-dependency-collection.d.ts +6 -2
- package/src/route-renderer/page-loading/component-dependency-collection.js +113 -68
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
- package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +10 -3
- package/src/route-renderer/page-loading/file-scoped-dependency-components.js +62 -25
- package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
- package/src/route-renderer/page-loading/resolved-page-dependencies.d.ts +1 -2
- package/src/route-renderer/page-loading/resolved-page-dependencies.js +8 -7
- package/src/route-renderer/route-renderer.d.ts +9 -0
- package/src/route-renderer/route-renderer.js +18 -0
- package/src/router/README.md +7 -1
- package/src/router/server/route-registry.d.ts +13 -0
- package/src/router/server/route-registry.js +46 -32
- package/src/services/README.md +5 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +36 -9
- package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +122 -37
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +2 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +13 -2
- package/src/services/assets/asset-processing-service/page-package.js +42 -39
- package/src/services/error-pages/README.md +9 -0
- package/src/services/error-pages/default-error-pages.d.ts +44 -0
- package/src/services/error-pages/default-error-pages.js +207 -0
- package/src/services/error-pages/error-page-renderer.d.ts +58 -0
- package/src/services/error-pages/error-page-renderer.js +146 -0
- package/src/services/error-pages/semantic-error-page-exporter.d.ts +23 -0
- package/src/services/error-pages/semantic-error-page-exporter.js +35 -0
- package/src/services/invalidation/development-invalidation.service.d.ts +7 -1
- package/src/services/invalidation/development-invalidation.service.js +35 -3
- package/src/services/module-loading/README.md +16 -13
- package/src/services/module-loading/app-server-module-transpiler.service.js +2 -0
- package/src/services/module-loading/collection-server-module-build.service.d.ts +1 -0
- package/src/services/module-loading/collection-server-module-build.service.js +5 -2
- package/src/services/module-loading/page-module-import.service.d.ts +8 -0
- package/src/services/module-loading/page-module-import.service.js +62 -28
- package/src/services/module-loading/route-module-dependency-hasher.js +13 -1
- package/src/services/module-loading/view-module-loader.d.ts +10 -0
- package/src/services/module-loading/view-module-loader.js +46 -0
- package/src/services/validation/schema-validation-service.d.ts +1 -0
- package/src/services/validation/schema-validation-service.js +23 -36
- package/src/static-site-generator/README.md +6 -1
- package/src/static-site-generator/static-site-generator.d.ts +7 -2
- package/src/static-site-generator/static-site-generator.js +90 -49
- package/src/types/internal-types.d.ts +6 -1
- package/src/types/public-types.d.ts +34 -24
- package/src/utils/parse-cli-args.js +29 -22
- package/src/watchers/project-watcher.d.ts +14 -1
- package/src/watchers/project-watcher.js +85 -34
- /package/src/{adapters/shared/http/explicit-static-render-preparation.js → route-renderer/explicit-view-render-preparation.js} +0 -0
|
@@ -6,11 +6,22 @@ export interface ServerBundleDeployManifest {
|
|
|
6
6
|
serverEntry: string;
|
|
7
7
|
distDir: string;
|
|
8
8
|
builtAt: number;
|
|
9
|
+
/** Canonical source config path compiled into the server bundle. */
|
|
10
|
+
sourceConfigPath?: string;
|
|
11
|
+
/** Relative source config path from project root. */
|
|
12
|
+
sourceConfigRelativePath?: string;
|
|
13
|
+
/** Deployed config module path relative to the server bundle directory. */
|
|
14
|
+
emittedConfigModule?: string;
|
|
15
|
+
/** Content hash of the source config file when built. */
|
|
16
|
+
configHash?: string;
|
|
17
|
+
/** Content hash of the emitted production config artifact. */
|
|
18
|
+
emittedConfigHash?: string;
|
|
9
19
|
}
|
|
10
20
|
export interface ServerEntryBuildCacheManifest {
|
|
11
21
|
invalidationVersion: string;
|
|
12
22
|
entryPath: string;
|
|
13
23
|
entryHash: string;
|
|
24
|
+
configHash: string;
|
|
14
25
|
buildInputsFingerprint: string;
|
|
15
26
|
buildKey: string;
|
|
16
27
|
outputPaths: string[];
|
|
@@ -28,7 +39,18 @@ export declare function getServerBundleOutputPaths(appConfig: EcoPagesAppConfig)
|
|
|
28
39
|
manifestPath: string;
|
|
29
40
|
};
|
|
30
41
|
export declare function readServerEntryBuildCacheManifest(appConfig: EcoPagesAppConfig): ServerEntryBuildCacheManifest | undefined;
|
|
31
|
-
export declare function writeServerBundleDeployManifest(appConfig: EcoPagesAppConfig, serverEntryPath: string
|
|
42
|
+
export declare function writeServerBundleDeployManifest(appConfig: EcoPagesAppConfig, serverEntryPath: string, options?: Pick<ServerBundleDeployManifest, 'sourceConfigPath' | 'emittedConfigModule'> & {
|
|
43
|
+
outputDir?: string;
|
|
44
|
+
}): void;
|
|
45
|
+
export declare function readServerBundleDeployManifest(appConfig: EcoPagesAppConfig): ServerBundleDeployManifest | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* @remarks
|
|
48
|
+
* Production `start` must not load a different config than the one compiled into the bundle.
|
|
49
|
+
*/
|
|
50
|
+
export declare function assertProductionConfigIdentity(appConfigOrCwd: EcoPagesAppConfig | string, requestedConfigPath: string | undefined, options?: {
|
|
51
|
+
isExplicitOverride?: boolean;
|
|
52
|
+
}): void;
|
|
53
|
+
export declare function readServerBundleDeployManifestFromDir(cwd?: string): ServerBundleDeployManifest | undefined;
|
|
32
54
|
export declare function lookupServerEntryBuildCache(options: {
|
|
33
55
|
appConfig: EcoPagesAppConfig;
|
|
34
56
|
entryPath: string;
|
|
@@ -38,6 +60,7 @@ export declare function recordServerEntryBuildCache(options: {
|
|
|
38
60
|
appConfig: EcoPagesAppConfig;
|
|
39
61
|
entryPath: string;
|
|
40
62
|
buildResult: BuildResult;
|
|
63
|
+
configBuildResult?: BuildResult;
|
|
41
64
|
outputPaths: string[];
|
|
42
65
|
}): void;
|
|
43
66
|
export declare function resolveProductionServerEntry(cwd?: string): string | undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { fileSystem } from '@ecopages/file-system';
|
|
3
3
|
import { resolveServerAppBuildPlugins } from '../runtime/build-request-policy.js';
|
|
4
|
-
import { createBuildInputsFingerprint } from './build-input-fingerprint.js';
|
|
4
|
+
import { createBuildInputsFingerprint, hashAppConfigFile } from './build-input-fingerprint.js';
|
|
5
5
|
import { isProductionCacheManifestCurrent, matchesProductionCacheBuildKey, matchesProductionCacheFingerprint, readProductionCacheManifest, writeProductionCacheManifest, } from './production-build-cache.js';
|
|
6
6
|
import { createPluginCacheKey, getCorePackageVersion } from './cache-keys.js';
|
|
7
7
|
import { RouteModuleDependencyHasher, createRouteModuleDependencyHashes, } from '../../services/module-loading/route-module-dependency-hasher.js';
|
|
@@ -57,16 +57,125 @@ export function readServerEntryBuildCacheManifest(appConfig) {
|
|
|
57
57
|
function writeServerEntryBuildCacheManifest(appConfig, manifest) {
|
|
58
58
|
writeProductionCacheManifest(path.join(getServerEntryCacheDir(appConfig), SERVER_ENTRY_BUILD_CACHE_FILENAME), manifest);
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
function hashExistingFile(filePath) {
|
|
61
|
+
return filePath && fileSystem.exists(filePath) ? fileSystem.hash(filePath) : undefined;
|
|
62
|
+
}
|
|
63
|
+
export function writeServerBundleDeployManifest(appConfig, serverEntryPath, options) {
|
|
64
|
+
const { distDir, manifestPath: defaultManifestPath } = getServerBundleOutputPaths(appConfig);
|
|
65
|
+
const manifestPath = options?.outputDir
|
|
66
|
+
? path.join(options.outputDir, SERVER_BUNDLE_MANIFEST_FILENAME)
|
|
67
|
+
: defaultManifestPath;
|
|
62
68
|
fileSystem.ensureDir(path.dirname(manifestPath));
|
|
69
|
+
const sourceConfigPath = options?.sourceConfigPath ?? appConfig.absolutePaths?.config;
|
|
70
|
+
const emittedConfigPath = options?.emittedConfigModule
|
|
71
|
+
? path.resolve(path.dirname(manifestPath), options.emittedConfigModule)
|
|
72
|
+
: undefined;
|
|
63
73
|
const payload = {
|
|
64
74
|
serverEntry: path.relative(path.dirname(manifestPath), serverEntryPath) || SERVER_BUNDLE_FILENAME,
|
|
65
75
|
distDir,
|
|
66
76
|
builtAt: Date.now(),
|
|
77
|
+
sourceConfigPath,
|
|
78
|
+
sourceConfigRelativePath: sourceConfigPath ? path.relative(appConfig.rootDir, sourceConfigPath) : undefined,
|
|
79
|
+
emittedConfigModule: options?.emittedConfigModule,
|
|
80
|
+
configHash: hashExistingFile(sourceConfigPath),
|
|
81
|
+
emittedConfigHash: hashExistingFile(emittedConfigPath),
|
|
67
82
|
};
|
|
68
83
|
fileSystem.write(manifestPath, `${JSON.stringify(payload, null, '\t')}\n`);
|
|
69
84
|
}
|
|
85
|
+
export function readServerBundleDeployManifest(appConfig) {
|
|
86
|
+
const { manifestPath } = getServerBundleOutputPaths(appConfig);
|
|
87
|
+
if (!fileSystem.exists(manifestPath)) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
return JSON.parse(fileSystem.readFileSync(manifestPath).toString());
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function isEmittedConfigArtifact(manifest, manifestDir, requestedPath) {
|
|
98
|
+
if (!manifest.emittedConfigModule) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
const emittedArtifactPath = path.resolve(manifestDir, manifest.emittedConfigModule);
|
|
102
|
+
if (path.resolve(requestedPath) !== emittedArtifactPath)
|
|
103
|
+
return false;
|
|
104
|
+
return (!manifest.emittedConfigHash ||
|
|
105
|
+
(fileSystem.exists(requestedPath) && fileSystem.hash(requestedPath) === manifest.emittedConfigHash));
|
|
106
|
+
}
|
|
107
|
+
function matchesBuiltConfigHash(manifest, requestedPath) {
|
|
108
|
+
if (!manifest.configHash || !fileSystem.exists(requestedPath)) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
return fileSystem.hash(requestedPath) === manifest.configHash;
|
|
112
|
+
}
|
|
113
|
+
function matchesBuiltConfigPath(manifest, cwd, requestedPath, isExplicitOverride) {
|
|
114
|
+
if (manifest.configHash)
|
|
115
|
+
return false;
|
|
116
|
+
if (!isExplicitOverride && manifest.sourceConfigRelativePath) {
|
|
117
|
+
if (path.relative(cwd, requestedPath) === manifest.sourceConfigRelativePath) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (manifest.sourceConfigPath && path.resolve(requestedPath) === path.resolve(manifest.sourceConfigPath)) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
function readDeployManifest(appConfigOrCwd) {
|
|
127
|
+
return typeof appConfigOrCwd === 'string'
|
|
128
|
+
? readServerBundleDeployManifestFromDir(appConfigOrCwd)
|
|
129
|
+
: readServerBundleDeployManifest(appConfigOrCwd);
|
|
130
|
+
}
|
|
131
|
+
function hasConfigIdentity(manifest) {
|
|
132
|
+
return Boolean(manifest.emittedConfigModule ||
|
|
133
|
+
manifest.configHash ||
|
|
134
|
+
manifest.sourceConfigPath ||
|
|
135
|
+
manifest.sourceConfigRelativePath);
|
|
136
|
+
}
|
|
137
|
+
function resolveDeployManifestDirectory(appConfigOrCwd) {
|
|
138
|
+
return typeof appConfigOrCwd === 'string'
|
|
139
|
+
? path.join(appConfigOrCwd, 'dist', SERVER_BUNDLE_DIR)
|
|
140
|
+
: getServerBundleOutputPaths(appConfigOrCwd).serverOutdir;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* @remarks
|
|
144
|
+
* Production `start` must not load a different config than the one compiled into the bundle.
|
|
145
|
+
*/
|
|
146
|
+
export function assertProductionConfigIdentity(appConfigOrCwd, requestedConfigPath, options) {
|
|
147
|
+
if (!requestedConfigPath) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const manifest = readDeployManifest(appConfigOrCwd);
|
|
151
|
+
if (!manifest || !hasConfigIdentity(manifest))
|
|
152
|
+
return;
|
|
153
|
+
const manifestDir = resolveDeployManifestDirectory(appConfigOrCwd);
|
|
154
|
+
if (isEmittedConfigArtifact(manifest, manifestDir, requestedConfigPath)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (matchesBuiltConfigHash(manifest, requestedConfigPath)) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const cwd = typeof appConfigOrCwd === 'string' ? appConfigOrCwd : appConfigOrCwd.rootDir;
|
|
161
|
+
if (matchesBuiltConfigPath(manifest, cwd, requestedConfigPath, options?.isExplicitOverride)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const expected = manifest.sourceConfigRelativePath ?? manifest.sourceConfigPath ?? 'bundled config';
|
|
165
|
+
throw new Error(`Ecopages config mismatch: production bundle was built with ${expected}, but start requested ${requestedConfigPath}.`);
|
|
166
|
+
}
|
|
167
|
+
export function readServerBundleDeployManifestFromDir(cwd = process.cwd()) {
|
|
168
|
+
const manifestPath = path.join(cwd, 'dist', SERVER_BUNDLE_DIR, SERVER_BUNDLE_MANIFEST_FILENAME);
|
|
169
|
+
if (!fileSystem.exists(manifestPath)) {
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
return JSON.parse(fileSystem.readFileSync(manifestPath).toString());
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
70
179
|
export function lookupServerEntryBuildCache(options) {
|
|
71
180
|
if (options.force) {
|
|
72
181
|
return undefined;
|
|
@@ -76,6 +185,7 @@ export function lookupServerEntryBuildCache(options) {
|
|
|
76
185
|
}
|
|
77
186
|
const entryPath = path.resolve(options.entryPath);
|
|
78
187
|
const entryHash = fileSystem.hash(entryPath);
|
|
188
|
+
const configHash = hashAppConfigFile(options.appConfig);
|
|
79
189
|
const buildInputsFingerprint = createBuildInputsFingerprint(options.appConfig);
|
|
80
190
|
const buildKey = createServerEntryBuildKey(options.appConfig);
|
|
81
191
|
const manifest = readServerEntryBuildCacheManifest(options.appConfig);
|
|
@@ -87,6 +197,7 @@ export function lookupServerEntryBuildCache(options) {
|
|
|
87
197
|
}
|
|
88
198
|
if (manifest.entryPath !== entryPath ||
|
|
89
199
|
manifest.entryHash !== entryHash ||
|
|
200
|
+
manifest.configHash !== configHash ||
|
|
90
201
|
!matchesProductionCacheFingerprint(manifest, buildInputsFingerprint) ||
|
|
91
202
|
!matchesProductionCacheBuildKey(manifest, buildKey)) {
|
|
92
203
|
return undefined;
|
|
@@ -95,13 +206,13 @@ export function lookupServerEntryBuildCache(options) {
|
|
|
95
206
|
if (!hasher.matchesStoredHashes(manifest.dependencyHashes, entryPath, entryHash)) {
|
|
96
207
|
return undefined;
|
|
97
208
|
}
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
209
|
+
const allOutputsExist = manifest.outputPaths.length > 0 && manifest.outputPaths.every((outputPath) => fileSystem.exists(outputPath));
|
|
210
|
+
if (!allOutputsExist) {
|
|
100
211
|
return undefined;
|
|
101
212
|
}
|
|
102
213
|
return {
|
|
103
214
|
manifest,
|
|
104
|
-
outputPaths:
|
|
215
|
+
outputPaths: manifest.outputPaths,
|
|
105
216
|
};
|
|
106
217
|
}
|
|
107
218
|
export function recordServerEntryBuildCache(options) {
|
|
@@ -110,12 +221,18 @@ export function recordServerEntryBuildCache(options) {
|
|
|
110
221
|
}
|
|
111
222
|
const entryPath = path.resolve(options.entryPath);
|
|
112
223
|
const entryHash = fileSystem.hash(entryPath);
|
|
224
|
+
const configHash = hashAppConfigFile(options.appConfig);
|
|
113
225
|
const hasher = new RouteModuleDependencyHasher();
|
|
114
|
-
const
|
|
226
|
+
const appDependencyHashes = hashDependencyGraph(entryPath, options.buildResult.dependencyGraph, hasher, options.appConfig.rootDir);
|
|
227
|
+
const configDependencyHashes = options.appConfig.absolutePaths?.config && options.configBuildResult?.dependencyGraph
|
|
228
|
+
? hashDependencyGraph(options.appConfig.absolutePaths.config, options.configBuildResult.dependencyGraph, hasher, options.appConfig.rootDir)
|
|
229
|
+
: {};
|
|
230
|
+
const dependencyHashes = { ...appDependencyHashes, ...configDependencyHashes };
|
|
115
231
|
const manifest = {
|
|
116
232
|
invalidationVersion: getCorePackageVersion(),
|
|
117
233
|
entryPath,
|
|
118
234
|
entryHash,
|
|
235
|
+
configHash,
|
|
119
236
|
buildInputsFingerprint: createBuildInputsFingerprint(options.appConfig),
|
|
120
237
|
buildKey: createServerEntryBuildKey(options.appConfig),
|
|
121
238
|
outputPaths: options.outputPaths,
|
|
@@ -128,7 +245,7 @@ export function resolveProductionServerEntry(cwd = process.cwd()) {
|
|
|
128
245
|
const manifestPath = path.join(cwd, 'dist', SERVER_BUNDLE_DIR, SERVER_BUNDLE_MANIFEST_FILENAME);
|
|
129
246
|
if (fileSystem.exists(manifestPath)) {
|
|
130
247
|
try {
|
|
131
|
-
const parsed = JSON.parse(fileSystem.readFileSync(manifestPath));
|
|
248
|
+
const parsed = JSON.parse(fileSystem.readFileSync(manifestPath).toString());
|
|
132
249
|
if (parsed?.serverEntry) {
|
|
133
250
|
const fromManifest = path.isAbsolute(parsed.serverEntry)
|
|
134
251
|
? parsed.serverEntry
|
|
@@ -4,9 +4,11 @@ export declare const CONTENT_VIRTUAL_MODULE_PREFIX = "ecopages:content";
|
|
|
4
4
|
export declare const CONTENT_VIRTUAL_MODULE_PATTERN: RegExp;
|
|
5
5
|
/** Matches `ecopages:content/<collection>/server` component resolver specifiers. */
|
|
6
6
|
export declare const CONTENT_SERVER_VIRTUAL_MODULE_PATTERN: RegExp;
|
|
7
|
+
/** Matches browser-only `ecopages:content/<collection>/browser` component loader specifiers. */
|
|
8
|
+
export declare const CONTENT_BROWSER_VIRTUAL_MODULE_PATTERN: RegExp;
|
|
7
9
|
export type ParsedCollectionSpecifier = {
|
|
8
10
|
collectionName: string;
|
|
9
|
-
variant: 'entries' | 'server';
|
|
11
|
+
variant: 'entries' | 'server' | 'browser';
|
|
10
12
|
};
|
|
11
13
|
export declare function parseCollectionSpecifier(specifier: string): ParsedCollectionSpecifier | null;
|
|
12
14
|
export declare function isContentServerVirtualModule(specifier: string): boolean;
|
|
@@ -4,6 +4,8 @@ export const CONTENT_VIRTUAL_MODULE_PREFIX = 'ecopages:content';
|
|
|
4
4
|
export const CONTENT_VIRTUAL_MODULE_PATTERN = /^ecopages:content\/[a-z][a-z0-9-]*$/;
|
|
5
5
|
/** Matches `ecopages:content/<collection>/server` component resolver specifiers. */
|
|
6
6
|
export const CONTENT_SERVER_VIRTUAL_MODULE_PATTERN = /^ecopages:content\/[a-z][a-z0-9-]+\/server$/;
|
|
7
|
+
/** Matches browser-only `ecopages:content/<collection>/browser` component loader specifiers. */
|
|
8
|
+
export const CONTENT_BROWSER_VIRTUAL_MODULE_PATTERN = /^ecopages:content\/[a-z][a-z0-9-]+\/browser$/;
|
|
7
9
|
export function parseCollectionSpecifier(specifier) {
|
|
8
10
|
const normalized = specifier.startsWith(`${CONTENT_VIRTUAL_MODULE_PREFIX}/`)
|
|
9
11
|
? specifier.slice(`${CONTENT_VIRTUAL_MODULE_PREFIX}/`.length)
|
|
@@ -19,6 +21,12 @@ export function parseCollectionSpecifier(specifier) {
|
|
|
19
21
|
variant: 'server',
|
|
20
22
|
};
|
|
21
23
|
}
|
|
24
|
+
if (normalized.endsWith('/browser')) {
|
|
25
|
+
return {
|
|
26
|
+
collectionName: normalized.slice(0, -'/browser'.length),
|
|
27
|
+
variant: 'browser',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
22
30
|
return {
|
|
23
31
|
collectionName: normalized,
|
|
24
32
|
variant: 'entries',
|
|
@@ -20,6 +20,7 @@ import { isDeclaredAppPackageImport, isWorkspacePackageImport, normalizeNodeRunt
|
|
|
20
20
|
const corePackageRequire = createRequire(new URL('../../../package.json', import.meta.url));
|
|
21
21
|
const nodeBuiltinSpecifiers = new Set(builtinModules);
|
|
22
22
|
let corePackageNames;
|
|
23
|
+
const CORE_RUNTIME_BUNDLED_PACKAGES = new Set(['ws']);
|
|
23
24
|
/**
|
|
24
25
|
* Returns the set of packages declared as direct dependencies in core's own
|
|
25
26
|
* `package.json` (all dependency fields combined).
|
|
@@ -102,12 +103,12 @@ function getAppRootRequire(cache, contextRoot) {
|
|
|
102
103
|
* TypeScript or JSX file (source packages); pre-compiled packages are left
|
|
103
104
|
* external so the app's own resolver handles them at runtime.
|
|
104
105
|
* 3. **Everything else** (undeclared transitives) — split into two sub-cases:
|
|
105
|
-
* - A **direct dependency of core** that resolves to a compiled JS file
|
|
106
|
-
*
|
|
107
|
-
* `
|
|
108
|
-
*
|
|
109
|
-
* core's own `package.json`;
|
|
110
|
-
* core's `require` are excluded.
|
|
106
|
+
* - A **direct dependency of core** that resolves to a compiled JS file:
|
|
107
|
+
* externalized so the `runtime-build-output-normalizer` can rewrite the
|
|
108
|
+
* import to an absolute `file://` URL after the build. Runtime packages
|
|
109
|
+
* that require CommonJS named-export interop (currently `ws`) are
|
|
110
|
+
* bundled instead. "Direct" means declared in core's own `package.json`;
|
|
111
|
+
* transitives that merely *resolve through* core's `require` are excluded.
|
|
111
112
|
* - **Everything else** (true transitives like `lexical`, `@lexical/react`):
|
|
112
113
|
* bundled unconditionally. pnpm strict hoisting means these packages
|
|
113
114
|
* are unreachable as bare specifiers from output directories such as
|
|
@@ -128,6 +129,9 @@ function shouldBundlePackageImport(id, contextRoot, appRootRequireCache) {
|
|
|
128
129
|
return Boolean(appResolvedPath && /\.(?:[cm]?ts|tsx|jsx)$/u.test(appResolvedPath));
|
|
129
130
|
}
|
|
130
131
|
if (isCoreDeclaredPackageImport(id)) {
|
|
132
|
+
if (CORE_RUNTIME_BUNDLED_PACKAGES.has(getPackageName(id))) {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
131
135
|
const coreResolvedPath = tryResolveModule(id, corePackageRequire);
|
|
132
136
|
if (coreResolvedPath && !/\.(?:[cm]?ts|tsx|jsx)$/u.test(coreResolvedPath)) {
|
|
133
137
|
return false;
|
|
@@ -135,6 +139,11 @@ function shouldBundlePackageImport(id, contextRoot, appRootRequireCache) {
|
|
|
135
139
|
}
|
|
136
140
|
return true;
|
|
137
141
|
}
|
|
142
|
+
function getPackageName(specifier) {
|
|
143
|
+
return specifier.startsWith('@')
|
|
144
|
+
? specifier.split('/').slice(0, 2).join('/')
|
|
145
|
+
: (specifier.split('/')[0] ?? specifier);
|
|
146
|
+
}
|
|
138
147
|
function createExternalMatcher(options, appRootRequireCache) {
|
|
139
148
|
const explicitExternals = new Set(options.external ?? []);
|
|
140
149
|
const externalPackages = options.externalPackages === true;
|
|
@@ -289,14 +298,7 @@ export function toBuildLogs(error) {
|
|
|
289
298
|
}
|
|
290
299
|
return [{ message: 'Unknown build error' }];
|
|
291
300
|
}
|
|
292
|
-
|
|
293
|
-
* Translates a {@link BuildOptions} into Rolldown's `InputOptions` and
|
|
294
|
-
* `OutputOptions`. Always sets `experimental.nativeMagicString: true`
|
|
295
|
-
* and always consolidates eco plugins via the bridge.
|
|
296
|
-
*/
|
|
297
|
-
export function resolveRolldownOptions(options, contextRoot, outdir, appRootRequireCache) {
|
|
298
|
-
const rolldownPlatform = mapRolldownPlatform(options.target);
|
|
299
|
-
const external = createExternalMatcher(options, appRootRequireCache);
|
|
301
|
+
function buildRolldownTransformOptions(options) {
|
|
300
302
|
const transformOptions = {};
|
|
301
303
|
if (options.define) {
|
|
302
304
|
transformOptions.define = options.define;
|
|
@@ -307,21 +309,26 @@ export function resolveRolldownOptions(options, contextRoot, outdir, appRootRequ
|
|
|
307
309
|
if (options.target && /^(?:es|chrome|edge|firefox|safari|hermes|deno|ios)/.test(options.target)) {
|
|
308
310
|
transformOptions.target = options.target;
|
|
309
311
|
}
|
|
312
|
+
return Object.keys(transformOptions).length > 0 ? transformOptions : undefined;
|
|
313
|
+
}
|
|
314
|
+
function buildRolldownInputPlugins(options, contextRoot, rolldownPlatform) {
|
|
310
315
|
const bundlePlugins = options.plugins ?? [];
|
|
311
316
|
const sourceTransforms = options.sourceTransforms ?? [];
|
|
312
317
|
const appPlugins = createRolldownPluginBridge(bundlePlugins, contextRoot, sourceTransforms);
|
|
313
|
-
|
|
318
|
+
return [
|
|
314
319
|
...(rolldownPlatform === 'node' ? [createNodeBuiltinExternalPlugin()] : []),
|
|
315
320
|
...(rolldownPlatform === 'browser' ? [createBrowserNodeBuiltinGuardPlugin()] : []),
|
|
316
321
|
...(options.target !== 'browser' ? [createServerSideCssShimPlugin()] : []),
|
|
317
322
|
...appPlugins,
|
|
318
323
|
];
|
|
319
|
-
|
|
324
|
+
}
|
|
325
|
+
function buildRolldownInputOptions(options, contextRoot, external, rolldownPlatform) {
|
|
326
|
+
return {
|
|
320
327
|
input: options.entrypoints,
|
|
321
328
|
cwd: contextRoot,
|
|
322
329
|
external,
|
|
323
|
-
platform:
|
|
324
|
-
transform:
|
|
330
|
+
platform: rolldownPlatform,
|
|
331
|
+
transform: buildRolldownTransformOptions(options),
|
|
325
332
|
resolve: options.conditions ? { conditionNames: options.conditions } : undefined,
|
|
326
333
|
treeshake: typeof options.treeshaking === 'boolean' ? options.treeshaking : true,
|
|
327
334
|
...(process.env.ECOPAGES_PROFILE_BUILD === '1'
|
|
@@ -334,32 +341,50 @@ export function resolveRolldownOptions(options, contextRoot, outdir, appRootRequ
|
|
|
334
341
|
experimental: {
|
|
335
342
|
nativeMagicString: true,
|
|
336
343
|
},
|
|
337
|
-
plugins:
|
|
344
|
+
plugins: buildRolldownInputPlugins(options, contextRoot, rolldownPlatform),
|
|
338
345
|
};
|
|
346
|
+
}
|
|
347
|
+
function resolveRolldownEntryFileNames(options) {
|
|
339
348
|
const entryFileNames = toEntryFileNamesPattern(options.naming);
|
|
340
349
|
const jsExtension = getJavaScriptOutExtension(options, entryFileNames?.literal ?? false);
|
|
341
|
-
|
|
342
|
-
? jsExtension
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
350
|
+
if (entryFileNames) {
|
|
351
|
+
return jsExtension ? `${entryFileNames.pattern}${jsExtension}` : entryFileNames.pattern;
|
|
352
|
+
}
|
|
353
|
+
return jsExtension ? `[name]${jsExtension}` : '[name]';
|
|
354
|
+
}
|
|
355
|
+
function shouldDisableRolldownCodeSplitting(options) {
|
|
356
|
+
if (options.splitting !== false) {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
348
359
|
const entrypointCount = Array.isArray(options.entrypoints)
|
|
349
360
|
? options.entrypoints.length
|
|
350
361
|
: Object.keys(options.entrypoints).length;
|
|
351
|
-
|
|
352
|
-
|
|
362
|
+
return entrypointCount === 1;
|
|
363
|
+
}
|
|
364
|
+
function buildRolldownOutputOptions(options, outdir) {
|
|
365
|
+
return {
|
|
353
366
|
dir: outdir,
|
|
354
367
|
format: mapRolldownFormat(options.format),
|
|
355
368
|
minify: !!options.minify,
|
|
356
|
-
entryFileNames:
|
|
369
|
+
entryFileNames: resolveRolldownEntryFileNames(options),
|
|
357
370
|
chunkFileNames: '[name]-[hash].js',
|
|
358
371
|
assetFileNames: '[name]-[hash][extname]',
|
|
359
372
|
sourcemap: mapRolldownSourcemap(options.sourcemap),
|
|
360
|
-
...(
|
|
373
|
+
...(shouldDisableRolldownCodeSplitting(options) ? { codeSplitting: false } : {}),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Translates a {@link BuildOptions} into Rolldown's `InputOptions` and
|
|
378
|
+
* `OutputOptions`. Always sets `experimental.nativeMagicString: true`
|
|
379
|
+
* and always consolidates eco plugins via the bridge.
|
|
380
|
+
*/
|
|
381
|
+
export function resolveRolldownOptions(options, contextRoot, outdir, appRootRequireCache) {
|
|
382
|
+
const rolldownPlatform = mapRolldownPlatform(options.target);
|
|
383
|
+
const external = createExternalMatcher(options, appRootRequireCache);
|
|
384
|
+
return {
|
|
385
|
+
inputOptions: buildRolldownInputOptions(options, contextRoot, external, rolldownPlatform),
|
|
386
|
+
outputOptions: buildRolldownOutputOptions(options, outdir),
|
|
361
387
|
};
|
|
362
|
-
return { inputOptions, outputOptions };
|
|
363
388
|
}
|
|
364
389
|
/**
|
|
365
390
|
* Rewrites manifest-owned runtime specifiers in emitted JS output
|
|
@@ -73,29 +73,33 @@ function inferRolldownModuleTypeFromPath(filePath) {
|
|
|
73
73
|
return 'js';
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
+
const DIRECT_ROLLDOWN_MODULE_LOADERS = new Set([
|
|
77
|
+
'js',
|
|
78
|
+
'jsx',
|
|
79
|
+
'ts',
|
|
80
|
+
'tsx',
|
|
81
|
+
'json',
|
|
82
|
+
'css',
|
|
83
|
+
'text',
|
|
84
|
+
'base64',
|
|
85
|
+
'dataurl',
|
|
86
|
+
'binary',
|
|
87
|
+
'empty',
|
|
88
|
+
]);
|
|
89
|
+
const ROLLDOWN_LOADER_ALIASES = {
|
|
90
|
+
'global-css': 'css',
|
|
91
|
+
'local-css': 'css',
|
|
92
|
+
file: 'asset',
|
|
93
|
+
copy: 'asset',
|
|
94
|
+
};
|
|
76
95
|
function normalizeRolldownModuleType(loader) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
case 'jsx':
|
|
80
|
-
case 'ts':
|
|
81
|
-
case 'tsx':
|
|
82
|
-
case 'json':
|
|
83
|
-
case 'css':
|
|
84
|
-
case 'text':
|
|
85
|
-
case 'base64':
|
|
86
|
-
case 'dataurl':
|
|
87
|
-
case 'binary':
|
|
88
|
-
case 'empty':
|
|
89
|
-
return loader;
|
|
90
|
-
case 'global-css':
|
|
91
|
-
case 'local-css':
|
|
92
|
-
return 'css';
|
|
93
|
-
case 'file':
|
|
94
|
-
case 'copy':
|
|
95
|
-
return 'asset';
|
|
96
|
-
default:
|
|
97
|
-
return undefined;
|
|
96
|
+
if (typeof loader === 'string' && DIRECT_ROLLDOWN_MODULE_LOADERS.has(loader)) {
|
|
97
|
+
return loader;
|
|
98
98
|
}
|
|
99
|
+
if (typeof loader === 'string' && Object.prototype.hasOwnProperty.call(ROLLDOWN_LOADER_ALIASES, loader)) {
|
|
100
|
+
return ROLLDOWN_LOADER_ALIASES[loader];
|
|
101
|
+
}
|
|
102
|
+
return undefined;
|
|
99
103
|
}
|
|
100
104
|
function convertLoadResultToModuleSource(result) {
|
|
101
105
|
if (result.loader === 'object' && result.exports && typeof result.exports === 'object') {
|
|
@@ -6,19 +6,6 @@ import { isBarePackageImportSpecifier } from '../../plugins/tsconfig-import-reso
|
|
|
6
6
|
const corePackageRequire = createRequire(new URL('../../../package.json', import.meta.url));
|
|
7
7
|
const appDeclaredPackageCache = new Map();
|
|
8
8
|
const appWorkspacePackageCache = new Map();
|
|
9
|
-
/**
|
|
10
|
-
* Core-owned packages that are part of the Node adapter's runtime surface and
|
|
11
|
-
* should therefore be preserved as bare specifiers in bundled output.
|
|
12
|
-
*
|
|
13
|
-
* Only list packages whose bare-specifier form will be resolvable from the
|
|
14
|
-
* app's Node.js runtime (i.e. they ship alongside the framework and do not
|
|
15
|
-
* need to be in the app's own package.json).
|
|
16
|
-
*
|
|
17
|
-
* Build-time tools (e.g. oxc-parser, rolldown) deliberately omitted — their
|
|
18
|
-
* imports in server-side output must be rewritten to absolute file: URLs so
|
|
19
|
-
* the bundler does not embed them in app code.
|
|
20
|
-
*/
|
|
21
|
-
const CORE_RUNTIME_BARE_SPECIFIER_PACKAGES = new Set(['ws']);
|
|
22
9
|
function tryResolveRuntimeImport(specifier, resolver) {
|
|
23
10
|
try {
|
|
24
11
|
return resolver.resolve(specifier);
|
|
@@ -143,24 +130,11 @@ export function isDeclaredAppPackageImport(specifier, rootDir) {
|
|
|
143
130
|
* Whether the given bare specifier should be left as-is (not rewritten to a
|
|
144
131
|
* file URL) in bundled output.
|
|
145
132
|
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* 2. **Core runtime surface packages** — a curated subset of the framework's
|
|
150
|
-
* own dependencies that are part of its public Node adapter surface (e.g.
|
|
151
|
-
* `ws`). These ship alongside the framework and are resolvable from the
|
|
152
|
-
* bundled output's location even when the app has not declared them.
|
|
153
|
-
*
|
|
154
|
-
* Build-time packages declared by core (e.g. `oxc-parser`, `rolldown`) are
|
|
155
|
-
* intentionally *not* included here — their imports must still be rewritten
|
|
156
|
-
* to absolute `file:` URLs so they are not left as bare specifiers in app
|
|
157
|
-
* output.
|
|
133
|
+
* Only app-declared packages qualify: their resolver can find them from a
|
|
134
|
+
* generated server bundle. Core dependencies remain file URLs because a
|
|
135
|
+
* bundle in `dist/.server` is not inside Core's Node.js resolution chain.
|
|
158
136
|
*/
|
|
159
137
|
function isDeclaredInResolutionChain(specifier, rootDir) {
|
|
160
|
-
const packageName = getPackageNameFromSpecifier(specifier);
|
|
161
|
-
if (CORE_RUNTIME_BARE_SPECIFIER_PACKAGES.has(packageName)) {
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
138
|
return isDeclaredAppPackageImport(specifier, rootDir);
|
|
165
139
|
}
|
|
166
140
|
function rewriteRuntimeImportSpecifier(specifier, quote, rootDir) {
|
|
@@ -48,7 +48,7 @@ export function createServerBuildRequest(appConfig, input) {
|
|
|
48
48
|
...overrides,
|
|
49
49
|
entrypoints: input.entrypoints,
|
|
50
50
|
...(plugins.length > 0 ? { plugins } : {}),
|
|
51
|
-
sourceTransforms: getAppSourceTransforms(appConfig),
|
|
51
|
+
sourceTransforms: [...getAppSourceTransforms(appConfig), ...(input.sourceTransforms ?? [])],
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Creates a sibling staging directory so publication stays on one filesystem. */
|
|
2
|
+
export declare function createServerBundleStagingDirectory(serverOutdir: string): string;
|
|
3
|
+
/** Maps build outputs from the staging directory to their published locations. */
|
|
4
|
+
export declare function resolvePublishedServerBundlePaths(outputPaths: readonly string[], stagingDir: string, serverOutdir: string): string[];
|
|
5
|
+
/**
|
|
6
|
+
* Publishes a complete server bundle generation without exposing mixed artifacts.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* The previous directory is retained until the staged directory has been moved
|
|
10
|
+
* into place, allowing rollback if publication fails.
|
|
11
|
+
*/
|
|
12
|
+
export declare function publishServerBundleDirectory(stagingDir: string, serverOutdir: string): void;
|
|
13
|
+
/** Removes an unpublished staging generation after a failed build. */
|
|
14
|
+
export declare function removeServerBundleStagingDirectory(stagingDir: string): void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdtempSync, renameSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
5
|
+
/** Creates a sibling staging directory so publication stays on one filesystem. */
|
|
6
|
+
export function createServerBundleStagingDirectory(serverOutdir) {
|
|
7
|
+
const parentDir = path.dirname(serverOutdir);
|
|
8
|
+
fileSystem.ensureDir(parentDir);
|
|
9
|
+
return mkdtempSync(path.join(parentDir, `.${path.basename(serverOutdir)}.staging-`));
|
|
10
|
+
}
|
|
11
|
+
/** Maps build outputs from the staging directory to their published locations. */
|
|
12
|
+
export function resolvePublishedServerBundlePaths(outputPaths, stagingDir, serverOutdir) {
|
|
13
|
+
return outputPaths.map((outputPath) => {
|
|
14
|
+
const relativePath = path.relative(stagingDir, outputPath);
|
|
15
|
+
if (!relativePath || relativePath.startsWith('..') || path.isAbsolute(relativePath)) {
|
|
16
|
+
throw new Error(`Server bundle output escaped its staging directory: ${outputPath}`);
|
|
17
|
+
}
|
|
18
|
+
return path.join(serverOutdir, relativePath);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Publishes a complete server bundle generation without exposing mixed artifacts.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* The previous directory is retained until the staged directory has been moved
|
|
26
|
+
* into place, allowing rollback if publication fails.
|
|
27
|
+
*/
|
|
28
|
+
export function publishServerBundleDirectory(stagingDir, serverOutdir) {
|
|
29
|
+
const backupDir = path.join(path.dirname(serverOutdir), `.${path.basename(serverOutdir)}.previous-${randomUUID()}`);
|
|
30
|
+
const hadPublishedBundle = fileSystem.exists(serverOutdir);
|
|
31
|
+
try {
|
|
32
|
+
if (hadPublishedBundle)
|
|
33
|
+
renameSync(serverOutdir, backupDir);
|
|
34
|
+
renameSync(stagingDir, serverOutdir);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (hadPublishedBundle && !fileSystem.exists(serverOutdir) && fileSystem.exists(backupDir)) {
|
|
38
|
+
renameSync(backupDir, serverOutdir);
|
|
39
|
+
}
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
if (fileSystem.exists(backupDir))
|
|
43
|
+
fileSystem.remove(backupDir);
|
|
44
|
+
}
|
|
45
|
+
/** Removes an unpublished staging generation after a failed build. */
|
|
46
|
+
export function removeServerBundleStagingDirectory(stagingDir) {
|
|
47
|
+
if (fileSystem.exists(stagingDir))
|
|
48
|
+
fileSystem.remove(stagingDir);
|
|
49
|
+
}
|
package/src/config/README.md
CHANGED
|
@@ -18,14 +18,22 @@ It is responsible for:
|
|
|
18
18
|
|
|
19
19
|
## Main Files
|
|
20
20
|
|
|
21
|
-
- `config
|
|
22
|
-
- `config
|
|
21
|
+
- `define-config.ts`: synchronous `defineConfig()` identity for `eco.config.ts` authoring
|
|
22
|
+
- `load-eco-config.ts`: resolves the config module path, loads user config, and finalizes through `ConfigBuilder`
|
|
23
|
+
- `resolve-eco-config-path.ts`: `eco.config.ts` discovery (`configFile`, `ECOPAGES_CONFIG_FILE`, cwd default, and production `.server/eco.config.mjs`)
|
|
24
|
+
- `apply-user-config.ts`: maps declarative `EcoPagesUserConfig` fields onto `ConfigBuilder`
|
|
25
|
+
- `is-finalized-app-config.ts`: detects leftover `ConfigBuilder.build()` exports so `loadEcoPagesConfig()` can reuse them
|
|
26
|
+
- `user-config-types.ts`: TypeScript contracts for `EcoPagesUserConfig` and config loader options
|
|
27
|
+
- `config-builder.ts`: finalization boundary used by the loader and tests
|
|
28
|
+
- `server-config-bundle.ts`: emits `dist/.server/eco.config.mjs` for production server startup
|
|
29
|
+
- `config-builder.test.ts` / `load-eco-config.test.ts`: validation and loader coverage
|
|
23
30
|
|
|
24
31
|
## Ownership Rules
|
|
25
32
|
|
|
26
33
|
- Integrations and processors declare contributions.
|
|
27
34
|
- `ConfigBuilder.build()` decides ordering, validates compatibility, and seals build ownership for the finalized app config.
|
|
28
35
|
- Runtime startup reuses finalized config/build state; it should not recompute manifest ownership.
|
|
36
|
+
- Production startup loads the emitted config artifact recorded by the server build, even when the source config is still present.
|
|
29
37
|
|
|
30
38
|
App-owned is the default ownership path. Host-owned is explicit and should be selected during config construction when a host-driven compatibility flow must avoid silently falling back to app build execution.
|
|
31
39
|
|
|
@@ -34,3 +42,10 @@ App-owned is the default ownership path. Host-owned is explicit and should be se
|
|
|
34
42
|
The result of this layer is a built `EcoPagesAppConfig` with resolved absolute paths and app-owned runtime services attached under `appConfig.runtime`.
|
|
35
43
|
|
|
36
44
|
That built config is then consumed by server adapters, static generation, route rendering, and HMR.
|
|
45
|
+
|
|
46
|
+
## Tests and fixtures
|
|
47
|
+
|
|
48
|
+
- Production apps call `createApp()` (loads `eco.config.ts`) or pass `appConfig`, `userConfig`, or `configFile` explicitly.
|
|
49
|
+
- In development (`--dev`), adding, changing, or removing the resolved `eco.config` module or a supported project `.env` file triggers a supervised process restart (not in-process reload). The CLI re-merges dotenv files on respawn.
|
|
50
|
+
- `@ecopages/testing` `createTestAppConfig()` finalizes each in-memory user config independently through `finalizeEcoPagesConfig`; only module-backed `loadEcoPagesConfig()` calls are cached.
|
|
51
|
+
- Core fixture helpers live in `packages/core/__fixtures__/app/test-app-config.ts` (`createFixtureAppConfig`, `createFixtureApp`).
|