@ecopages/core 0.2.0-rc.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -38
- package/package.json +22 -152
- package/src/adapters/README.md +11 -3
- package/src/adapters/abstract/application-adapter.d.ts +32 -36
- package/src/adapters/abstract/application-adapter.js +61 -47
- package/src/adapters/abstract/server-adapter.d.ts +14 -0
- package/src/adapters/abstract/server-adapter.js +10 -0
- package/src/adapters/abstract/ws-pattern-matcher.d.ts +0 -5
- package/src/adapters/abstract/ws-pattern-matcher.js +0 -9
- package/src/adapters/bun/create-app.d.ts +12 -16
- package/src/adapters/bun/create-app.js +25 -55
- package/src/adapters/bun/hmr-manager.d.ts +0 -1
- package/src/adapters/bun/hmr-manager.js +2 -4
- package/src/adapters/bun/server-adapter.d.ts +15 -21
- package/src/adapters/bun/server-adapter.js +33 -67
- package/src/adapters/bun/static-preview-host.d.ts +1 -0
- package/src/adapters/bun/static-preview-host.js +1 -1
- package/src/adapters/create-app.d.ts +63 -8
- package/src/adapters/create-app.js +62 -5
- package/src/adapters/node/create-app.d.ts +8 -12
- package/src/adapters/node/create-app.js +22 -14
- package/src/adapters/node/runtime-host.d.ts +10 -10
- package/src/adapters/node/runtime-host.js +13 -8
- package/src/adapters/node/server-adapter-dependencies.d.ts +2 -10
- package/src/adapters/node/server-adapter-dependencies.js +8 -13
- package/src/adapters/node/server-adapter.d.ts +30 -32
- package/src/adapters/node/server-adapter.js +59 -65
- package/src/adapters/shared/hmr/shared-hmr-manager.d.ts +0 -4
- package/src/adapters/shared/hmr/shared-hmr-manager.js +0 -12
- package/src/adapters/shared/http/api-request-pipeline.d.ts +27 -1
- package/src/adapters/shared/http/api-request-pipeline.js +31 -16
- package/src/adapters/shared/http/explicit-static-route-matcher.js +5 -2
- package/src/adapters/shared/http/fs-server-response-factory.d.ts +2 -9
- package/src/adapters/shared/http/fs-server-response-factory.js +5 -33
- 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/collect-dev-prewarm-plan.d.ts +1 -3
- package/src/adapters/shared/runtime/collect-dev-prewarm-plan.js +1 -4
- 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/runtime-app-bootstrap.d.ts +0 -10
- package/src/adapters/shared/runtime/runtime-app-bootstrap.js +0 -7
- package/src/adapters/shared/runtime/runtime-host.d.ts +5 -2
- package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +1 -1
- package/src/adapters/shared/runtime/runtime-server-lifecycle.js +1 -1
- package/src/adapters/shared/runtime/server-adapter.d.ts +26 -5
- package/src/adapters/shared/runtime/server-adapter.js +35 -8
- 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/adapters/shared/ws/node-http-websocket-upgrades.d.ts +9 -1
- package/src/adapters/shared/ws/node-http-websocket-upgrades.js +8 -2
- package/src/build/README.md +12 -8
- package/src/build/cache/cache-constants.d.ts +0 -2
- package/src/build/cache/cache-constants.js +0 -2
- package/src/build/cache/cache-keys.d.ts +0 -2
- package/src/build/cache/cache-keys.js +0 -2
- package/src/build/cache/output-imports.d.ts +35 -0
- package/src/build/cache/output-imports.js +87 -0
- package/src/build/cache/pages-unified-graph-build.d.ts +15 -1
- package/src/build/cache/pages-unified-graph-build.js +73 -22
- package/src/build/cache/production-build-cache.d.ts +2 -2
- package/src/build/cache/production-build-cache.js +2 -2
- package/src/build/cache/server-entry-build-cache.d.ts +25 -3
- package/src/build/cache/server-entry-build-cache.js +129 -13
- package/src/build/contracts/build-contracts.d.ts +1 -13
- package/src/build/rolldown/runtime-build-output-normalizer.js +3 -6
- package/src/build/runtime/build-request-identity.d.ts +2 -6
- package/src/build/runtime/build-request-identity.js +2 -8
- package/src/build/runtime/build-request-policy.js +1 -1
- package/src/build/runtime/deduping-build-executor.d.ts +0 -1
- package/src/build/runtime/deduping-build-executor.js +0 -1
- package/src/build/server-bundle-publication.d.ts +14 -0
- package/src/build/server-bundle-publication.js +49 -0
- package/src/cache/index.d.ts +1 -1
- package/src/cache/index.js +1 -1
- package/src/cache/module-parse-cache.d.ts +2 -29
- package/src/cache/module-parse-cache.js +6 -39
- package/src/config/README.md +17 -2
- package/src/config/apply-user-config.d.ts +8 -0
- package/src/config/apply-user-config.js +68 -0
- package/src/config/config-builder.d.ts +11 -1
- package/src/config/config-builder.js +53 -12
- package/src/config/constants.d.ts +4 -4
- package/src/config/constants.js +4 -4
- 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 +107 -0
- package/src/config/resolve-eco-config-path.d.ts +32 -0
- package/src/config/resolve-eco-config-path.js +58 -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 +170 -0
- package/src/config/user-config-types.js +1 -0
- package/src/dev/README.md +4 -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/host-runtime.d.ts +0 -1
- package/src/dev/host-runtime.js +0 -3
- package/src/dev/sc-server.d.ts +4 -1
- package/src/dev/sc-server.js +11 -20
- package/src/dev/transform-server/dev-transform-import-rewriter.js +2 -2
- package/src/eco/eco.js +4 -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/hmr-file-change-prep.d.ts +0 -1
- package/src/hmr/hmr-file-change-prep.js +2 -5
- package/src/hmr/hmr-strategy.d.ts +3 -8
- package/src/hmr/hmr-strategy.js +3 -8
- package/src/index.browser.d.ts +1 -2
- package/src/index.browser.js +1 -2
- package/src/index.d.ts +5 -6
- package/src/index.js +5 -6
- package/src/islands/island-host.d.ts +0 -9
- package/src/islands/island-host.js +1 -13
- package/src/plugins/component-import-discovery.js +2 -2
- package/src/plugins/eco-component-meta-plugin.js +5 -5
- package/src/plugins/integration-plugin.d.ts +0 -1
- package/src/plugins/integration-plugin.js +0 -4
- package/src/plugins/processor.d.ts +6 -2
- package/src/route-renderer/README.md +4 -0
- 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/document-shell/document-shell-render.service.js +1 -4
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +25 -24
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +18 -20
- package/src/route-renderer/orchestration/integration-renderer.d.ts +24 -7
- package/src/route-renderer/orchestration/integration-renderer.js +44 -33
- package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +1 -1
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -1
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +1 -1
- package/src/route-renderer/route-renderer.d.ts +9 -0
- package/src/route-renderer/route-renderer.js +18 -0
- package/src/services/README.md +2 -1
- package/src/services/assets/browser-bundle.service.d.ts +1 -6
- package/src/services/error-pages/README.md +9 -0
- package/src/services/error-pages/default-error-pages.d.ts +39 -0
- package/src/services/error-pages/default-error-pages.js +199 -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/html/html-rewriter.d.ts +77 -0
- package/src/services/html/html-rewriter.js +751 -0
- package/src/services/html/html-rewriter.parity.test.bun.d.ts +1 -0
- package/src/services/html/html-rewriter.parity.test.bun.js +74 -0
- package/src/services/html/html-transformer.service.d.ts +29 -42
- package/src/services/html/html-transformer.service.js +85 -157
- package/src/services/invalidation/development-invalidation.service.d.ts +9 -20
- package/src/services/invalidation/development-invalidation.service.js +26 -39
- package/src/services/module-loading/README.md +20 -15
- package/src/services/module-loading/app-module-loader.service.d.ts +0 -2
- package/src/services/module-loading/app-server-module-transpiler.service.d.ts +1 -1
- package/src/services/module-loading/app-server-module-transpiler.service.js +2 -10
- package/src/services/module-loading/collection-server-module-build.service.d.ts +0 -1
- package/src/services/module-loading/collection-server-module-build.service.js +0 -3
- package/src/services/module-loading/host-module-loader-registry.d.ts +0 -1
- package/src/services/module-loading/host-module-loader-registry.js +0 -3
- package/src/services/module-loading/route-module-build-cache-registry.d.ts +0 -4
- package/src/services/module-loading/route-module-build-cache-registry.js +0 -4
- package/src/services/module-loading/route-module-build-cache.store.d.ts +8 -0
- package/src/services/module-loading/route-module-build-cache.store.js +25 -7
- package/src/services/module-loading/route-module-build-manifest.d.ts +12 -1
- package/src/services/module-loading/route-module-build-manifest.js +7 -3
- package/src/services/module-loading/route-module-dependency-hasher.d.ts +3 -2
- package/src/services/module-loading/route-module-dependency-hasher.js +13 -1
- package/src/services/module-loading/server-module-transpiler.service.d.ts +1 -15
- package/src/services/module-loading/server-module-transpiler.service.js +0 -24
- 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/runtime-state/entrypoint-dependency-graph.service.js +0 -12
- package/src/services/runtime-state/server-invalidation-state.service.d.ts +4 -2
- package/src/services/runtime-state/server-invalidation-state.service.js +7 -14
- package/src/static-site-generator/README.md +12 -8
- package/src/static-site-generator/static-site-generator.d.ts +3 -2
- package/src/static-site-generator/static-site-generator.js +17 -3
- package/src/types/internal-types.d.ts +1 -38
- package/src/types/public-types.d.ts +28 -130
- package/src/watchers/project-watcher.d.ts +9 -16
- package/src/watchers/project-watcher.js +35 -28
- package/src/watchers/project-watcher.test-helpers.d.ts +10 -1
- package/src/watchers/project-watcher.test-helpers.js +12 -0
- package/src/adapters/abstract/router-adapter.d.ts +0 -26
- package/src/adapters/abstract/router-adapter.js +0 -13
- package/src/adapters/bun/index.d.ts +0 -2
- package/src/adapters/bun/index.js +0 -2
- package/src/adapters/index.d.ts +0 -2
- package/src/adapters/index.js +0 -2
- package/src/eco/eco.utils.d.ts +0 -1
- package/src/eco/eco.utils.js +0 -1
- package/src/services/cache/index.d.ts +0 -9
- package/src/services/cache/index.js +0 -8
- package/src/services/html/html-rewriter-provider.service.d.ts +0 -40
- package/src/services/html/html-rewriter-provider.service.js +0 -68
- package/src/services/module-loading/route-module-build-cache.d.ts +0 -4
- package/src/services/module-loading/route-module-build-cache.js +0 -3
- package/src/services/runtime-state/dev-graph.service.d.ts +0 -118
- package/src/services/runtime-state/dev-graph.service.js +0 -170
- /package/src/{adapters/shared/http/explicit-static-render-preparation.js → route-renderer/explicit-view-render-preparation.js} +0 -0
|
@@ -1,20 +1,19 @@
|
|
|
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';
|
|
8
8
|
import { resolveInternalExecutionDir } from '../../utils/resolve-work-dir.js';
|
|
9
9
|
import { SERVER_BUNDLE_DIR, SERVER_BUNDLE_FILENAME } from '../../utils/resolve-entry-file.js';
|
|
10
|
-
import {
|
|
11
|
-
export { SERVER_ENTRY_BUILD_CACHE_FILENAME } from './cache-constants.js';
|
|
10
|
+
import { ROUTE_MODULE_BUILD_CACHE_FILENAME } from './cache-constants.js';
|
|
12
11
|
export const SERVER_BUNDLE_MANIFEST_FILENAME = 'manifest.json';
|
|
13
12
|
function getServerEntryCacheDir(appConfig) {
|
|
14
13
|
return path.join(resolveInternalExecutionDir(appConfig), '.server-entry');
|
|
15
14
|
}
|
|
16
15
|
function getServerEntryCacheManifestPath(appConfig) {
|
|
17
|
-
return path.join(getServerEntryCacheDir(appConfig),
|
|
16
|
+
return path.join(getServerEntryCacheDir(appConfig), ROUTE_MODULE_BUILD_CACHE_FILENAME);
|
|
18
17
|
}
|
|
19
18
|
function hashDependencyGraph(entryPath, dependencyGraph, hasher, rootDir) {
|
|
20
19
|
if (!dependencyGraph) {
|
|
@@ -55,18 +54,127 @@ export function readServerEntryBuildCacheManifest(appConfig) {
|
|
|
55
54
|
return readProductionCacheManifest(getServerEntryCacheManifestPath(appConfig));
|
|
56
55
|
}
|
|
57
56
|
function writeServerEntryBuildCacheManifest(appConfig, manifest) {
|
|
58
|
-
writeProductionCacheManifest(path.join(getServerEntryCacheDir(appConfig),
|
|
57
|
+
writeProductionCacheManifest(path.join(getServerEntryCacheDir(appConfig), ROUTE_MODULE_BUILD_CACHE_FILENAME), manifest);
|
|
59
58
|
}
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
function hashExistingFile(filePath) {
|
|
60
|
+
return filePath && fileSystem.exists(filePath) ? fileSystem.hash(filePath) : undefined;
|
|
61
|
+
}
|
|
62
|
+
export function writeServerBundleDeployManifest(appConfig, serverEntryPath, options) {
|
|
63
|
+
const { distDir, manifestPath: defaultManifestPath } = getServerBundleOutputPaths(appConfig);
|
|
64
|
+
const manifestPath = options?.outputDir
|
|
65
|
+
? path.join(options.outputDir, SERVER_BUNDLE_MANIFEST_FILENAME)
|
|
66
|
+
: defaultManifestPath;
|
|
62
67
|
fileSystem.ensureDir(path.dirname(manifestPath));
|
|
68
|
+
const sourceConfigPath = options?.sourceConfigPath ?? appConfig.absolutePaths?.config;
|
|
69
|
+
const emittedConfigPath = options?.emittedConfigModule
|
|
70
|
+
? path.resolve(path.dirname(manifestPath), options.emittedConfigModule)
|
|
71
|
+
: undefined;
|
|
63
72
|
const payload = {
|
|
64
73
|
serverEntry: path.relative(path.dirname(manifestPath), serverEntryPath) || SERVER_BUNDLE_FILENAME,
|
|
65
74
|
distDir,
|
|
66
75
|
builtAt: Date.now(),
|
|
76
|
+
sourceConfigPath,
|
|
77
|
+
sourceConfigRelativePath: sourceConfigPath ? path.relative(appConfig.rootDir, sourceConfigPath) : undefined,
|
|
78
|
+
emittedConfigModule: options?.emittedConfigModule,
|
|
79
|
+
configHash: hashExistingFile(sourceConfigPath),
|
|
80
|
+
emittedConfigHash: hashExistingFile(emittedConfigPath),
|
|
67
81
|
};
|
|
68
82
|
fileSystem.write(manifestPath, `${JSON.stringify(payload, null, '\t')}\n`);
|
|
69
83
|
}
|
|
84
|
+
export function readServerBundleDeployManifest(appConfig) {
|
|
85
|
+
const { manifestPath } = getServerBundleOutputPaths(appConfig);
|
|
86
|
+
if (!fileSystem.exists(manifestPath)) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
return JSON.parse(fileSystem.readFileSync(manifestPath).toString());
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function isEmittedConfigArtifact(manifest, manifestDir, requestedPath) {
|
|
97
|
+
if (!manifest.emittedConfigModule) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const emittedArtifactPath = path.resolve(manifestDir, manifest.emittedConfigModule);
|
|
101
|
+
if (path.resolve(requestedPath) !== emittedArtifactPath)
|
|
102
|
+
return false;
|
|
103
|
+
return (!manifest.emittedConfigHash ||
|
|
104
|
+
(fileSystem.exists(requestedPath) && fileSystem.hash(requestedPath) === manifest.emittedConfigHash));
|
|
105
|
+
}
|
|
106
|
+
function matchesBuiltConfigHash(manifest, requestedPath) {
|
|
107
|
+
if (!manifest.configHash || !fileSystem.exists(requestedPath)) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return fileSystem.hash(requestedPath) === manifest.configHash;
|
|
111
|
+
}
|
|
112
|
+
function matchesBuiltConfigPath(manifest, cwd, requestedPath, isExplicitOverride) {
|
|
113
|
+
if (manifest.configHash)
|
|
114
|
+
return false;
|
|
115
|
+
if (!isExplicitOverride && manifest.sourceConfigRelativePath) {
|
|
116
|
+
if (path.relative(cwd, requestedPath) === manifest.sourceConfigRelativePath) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (manifest.sourceConfigPath && path.resolve(requestedPath) === path.resolve(manifest.sourceConfigPath)) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
function readDeployManifest(appConfigOrCwd) {
|
|
126
|
+
return typeof appConfigOrCwd === 'string'
|
|
127
|
+
? readServerBundleDeployManifestFromDir(appConfigOrCwd)
|
|
128
|
+
: readServerBundleDeployManifest(appConfigOrCwd);
|
|
129
|
+
}
|
|
130
|
+
function hasConfigIdentity(manifest) {
|
|
131
|
+
return Boolean(manifest.emittedConfigModule ||
|
|
132
|
+
manifest.configHash ||
|
|
133
|
+
manifest.sourceConfigPath ||
|
|
134
|
+
manifest.sourceConfigRelativePath);
|
|
135
|
+
}
|
|
136
|
+
function resolveDeployManifestDirectory(appConfigOrCwd) {
|
|
137
|
+
return typeof appConfigOrCwd === 'string'
|
|
138
|
+
? path.join(appConfigOrCwd, 'dist', SERVER_BUNDLE_DIR)
|
|
139
|
+
: getServerBundleOutputPaths(appConfigOrCwd).serverOutdir;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* @remarks
|
|
143
|
+
* Production `start` must not load a different config than the one compiled into the bundle.
|
|
144
|
+
*/
|
|
145
|
+
export function assertProductionConfigIdentity(appConfigOrCwd, requestedConfigPath, options) {
|
|
146
|
+
if (!requestedConfigPath) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const manifest = readDeployManifest(appConfigOrCwd);
|
|
150
|
+
if (!manifest || !hasConfigIdentity(manifest))
|
|
151
|
+
return;
|
|
152
|
+
const manifestDir = resolveDeployManifestDirectory(appConfigOrCwd);
|
|
153
|
+
if (isEmittedConfigArtifact(manifest, manifestDir, requestedConfigPath)) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (matchesBuiltConfigHash(manifest, requestedConfigPath)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const cwd = typeof appConfigOrCwd === 'string' ? appConfigOrCwd : appConfigOrCwd.rootDir;
|
|
160
|
+
if (matchesBuiltConfigPath(manifest, cwd, requestedConfigPath, options?.isExplicitOverride)) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const expected = manifest.sourceConfigRelativePath ?? manifest.sourceConfigPath ?? 'bundled config';
|
|
164
|
+
throw new Error(`Ecopages config mismatch: production bundle was built with ${expected}, but start requested ${requestedConfigPath}.`);
|
|
165
|
+
}
|
|
166
|
+
export function readServerBundleDeployManifestFromDir(cwd = process.cwd()) {
|
|
167
|
+
const manifestPath = path.join(cwd, 'dist', SERVER_BUNDLE_DIR, SERVER_BUNDLE_MANIFEST_FILENAME);
|
|
168
|
+
if (!fileSystem.exists(manifestPath)) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
return JSON.parse(fileSystem.readFileSync(manifestPath).toString());
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
70
178
|
export function lookupServerEntryBuildCache(options) {
|
|
71
179
|
if (options.force) {
|
|
72
180
|
return undefined;
|
|
@@ -76,6 +184,7 @@ export function lookupServerEntryBuildCache(options) {
|
|
|
76
184
|
}
|
|
77
185
|
const entryPath = path.resolve(options.entryPath);
|
|
78
186
|
const entryHash = fileSystem.hash(entryPath);
|
|
187
|
+
const configHash = hashAppConfigFile(options.appConfig);
|
|
79
188
|
const buildInputsFingerprint = createBuildInputsFingerprint(options.appConfig);
|
|
80
189
|
const buildKey = createServerEntryBuildKey(options.appConfig);
|
|
81
190
|
const manifest = readServerEntryBuildCacheManifest(options.appConfig);
|
|
@@ -87,6 +196,7 @@ export function lookupServerEntryBuildCache(options) {
|
|
|
87
196
|
}
|
|
88
197
|
if (manifest.entryPath !== entryPath ||
|
|
89
198
|
manifest.entryHash !== entryHash ||
|
|
199
|
+
manifest.configHash !== configHash ||
|
|
90
200
|
!matchesProductionCacheFingerprint(manifest, buildInputsFingerprint) ||
|
|
91
201
|
!matchesProductionCacheBuildKey(manifest, buildKey)) {
|
|
92
202
|
return undefined;
|
|
@@ -95,13 +205,13 @@ export function lookupServerEntryBuildCache(options) {
|
|
|
95
205
|
if (!hasher.matchesStoredHashes(manifest.dependencyHashes, entryPath, entryHash)) {
|
|
96
206
|
return undefined;
|
|
97
207
|
}
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
208
|
+
const allOutputsExist = manifest.outputPaths.length > 0 && manifest.outputPaths.every((outputPath) => fileSystem.exists(outputPath));
|
|
209
|
+
if (!allOutputsExist) {
|
|
100
210
|
return undefined;
|
|
101
211
|
}
|
|
102
212
|
return {
|
|
103
213
|
manifest,
|
|
104
|
-
outputPaths:
|
|
214
|
+
outputPaths: manifest.outputPaths,
|
|
105
215
|
};
|
|
106
216
|
}
|
|
107
217
|
export function recordServerEntryBuildCache(options) {
|
|
@@ -110,12 +220,18 @@ export function recordServerEntryBuildCache(options) {
|
|
|
110
220
|
}
|
|
111
221
|
const entryPath = path.resolve(options.entryPath);
|
|
112
222
|
const entryHash = fileSystem.hash(entryPath);
|
|
223
|
+
const configHash = hashAppConfigFile(options.appConfig);
|
|
113
224
|
const hasher = new RouteModuleDependencyHasher();
|
|
114
|
-
const
|
|
225
|
+
const appDependencyHashes = hashDependencyGraph(entryPath, options.buildResult.dependencyGraph, hasher, options.appConfig.rootDir);
|
|
226
|
+
const configDependencyHashes = options.appConfig.absolutePaths?.config && options.configBuildResult?.dependencyGraph
|
|
227
|
+
? hashDependencyGraph(options.appConfig.absolutePaths.config, options.configBuildResult.dependencyGraph, hasher, options.appConfig.rootDir)
|
|
228
|
+
: {};
|
|
229
|
+
const dependencyHashes = { ...appDependencyHashes, ...configDependencyHashes };
|
|
115
230
|
const manifest = {
|
|
116
|
-
|
|
231
|
+
corePackageVersion: getCorePackageVersion(),
|
|
117
232
|
entryPath,
|
|
118
233
|
entryHash,
|
|
234
|
+
configHash,
|
|
119
235
|
buildInputsFingerprint: createBuildInputsFingerprint(options.appConfig),
|
|
120
236
|
buildKey: createServerEntryBuildKey(options.appConfig),
|
|
121
237
|
outputPaths: options.outputPaths,
|
|
@@ -128,7 +244,7 @@ export function resolveProductionServerEntry(cwd = process.cwd()) {
|
|
|
128
244
|
const manifestPath = path.join(cwd, 'dist', SERVER_BUNDLE_DIR, SERVER_BUNDLE_MANIFEST_FILENAME);
|
|
129
245
|
if (fileSystem.exists(manifestPath)) {
|
|
130
246
|
try {
|
|
131
|
-
const parsed = JSON.parse(fileSystem.readFileSync(manifestPath));
|
|
247
|
+
const parsed = JSON.parse(fileSystem.readFileSync(manifestPath).toString());
|
|
132
248
|
if (parsed?.serverEntry) {
|
|
133
249
|
const fromManifest = path.isAbsolute(parsed.serverEntry)
|
|
134
250
|
? parsed.serverEntry
|
|
@@ -34,21 +34,11 @@ export interface BuildResult {
|
|
|
34
34
|
*
|
|
35
35
|
* @remarks
|
|
36
36
|
* Fields that the adapter can forward are honored. `splitting: false` disables
|
|
37
|
-
* Rolldown code splitting for single-entrypoint builds.
|
|
38
|
-
* are accepted for call-site compatibility but ignored.
|
|
37
|
+
* Rolldown code splitting for single-entrypoint builds.
|
|
39
38
|
*/
|
|
40
39
|
export interface BuildOptions {
|
|
41
40
|
entrypoints: string[] | Record<string, string>;
|
|
42
41
|
outdir?: string;
|
|
43
|
-
/**
|
|
44
|
-
* Base directory for `[dir]` placeholders in `naming`. Currently
|
|
45
|
-
* the bundled adapter derives the base from `root` directly and
|
|
46
|
-
* ignores this field.
|
|
47
|
-
*
|
|
48
|
-
* @deprecated Accepted for call-site compatibility only. Use record-form
|
|
49
|
-
* `entrypoints` keys to preserve directory structure.
|
|
50
|
-
*/
|
|
51
|
-
outbase?: string;
|
|
52
42
|
naming?: string;
|
|
53
43
|
conditions?: string[];
|
|
54
44
|
define?: Record<string, string>;
|
|
@@ -60,8 +50,6 @@ export interface BuildOptions {
|
|
|
60
50
|
/** When `false` with a single entrypoint, inlines dynamic imports into one output file. */
|
|
61
51
|
splitting?: boolean;
|
|
62
52
|
root?: string;
|
|
63
|
-
/** @deprecated Accepted for call-site compatibility only. */
|
|
64
|
-
bundle?: boolean;
|
|
65
53
|
externalPackages?: boolean;
|
|
66
54
|
external?: string[];
|
|
67
55
|
jsx?: {
|
|
@@ -2,6 +2,7 @@ import { createRequire } from 'node:module';
|
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import { appLogger } from '../../global/app-logger.js';
|
|
5
6
|
import { isBarePackageImportSpecifier } from '../../plugins/tsconfig-import-resolver.js';
|
|
6
7
|
const corePackageRequire = createRequire(new URL('../../../package.json', import.meta.url));
|
|
7
8
|
const appDeclaredPackageCache = new Map();
|
|
@@ -201,9 +202,7 @@ function rewriteRuntimeBuildOutputImports(code, rootDir) {
|
|
|
201
202
|
});
|
|
202
203
|
}
|
|
203
204
|
export function normalizeNodeRuntimeBuildOutputFile(filePath, rootDir) {
|
|
204
|
-
|
|
205
|
-
console.log(`[normalizeNodeRuntimeBuildOutputFile] Checking ${filePath}`);
|
|
206
|
-
}
|
|
205
|
+
appLogger.debug(`[normalizeNodeRuntimeBuildOutputFile] Checking ${filePath}`);
|
|
207
206
|
if (!/\.(?:[cm]?js)$/u.test(filePath)) {
|
|
208
207
|
return;
|
|
209
208
|
}
|
|
@@ -214,9 +213,7 @@ export function normalizeNodeRuntimeBuildOutputFile(filePath, rootDir) {
|
|
|
214
213
|
const code = fileSystem.readFileSync(filePath, 'utf-8');
|
|
215
214
|
const rewritten = rewriteRuntimeBuildOutputImports(code, rootDir);
|
|
216
215
|
if (rewritten !== code) {
|
|
217
|
-
|
|
218
|
-
console.log(`[normalizeNodeRuntimeBuildOutputFile] Rewriting ${filePath}`);
|
|
219
|
-
}
|
|
216
|
+
appLogger.debug(`[normalizeNodeRuntimeBuildOutputFile] Rewriting ${filePath}`);
|
|
220
217
|
fileSystem.writeFileSync(filePath, rewritten);
|
|
221
218
|
}
|
|
222
219
|
}
|
|
@@ -7,11 +7,7 @@ import type { BuildOptions } from '../contracts/build-contracts.js';
|
|
|
7
7
|
* are sorted. Plugin, `conditions`, and source-transform order is preserved because
|
|
8
8
|
* Rolldown hook and `conditionNames` precedence depend on it.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* coalesce. Empty `conditions` / `define` / `external` normalize to the same
|
|
13
|
-
* sentinel as `undefined`.
|
|
10
|
+
* Empty `conditions` / `define` / `external` normalize to the same sentinel as
|
|
11
|
+
* `undefined`.
|
|
14
12
|
*/
|
|
15
13
|
export declare function createBuildRequestIdentity(options: BuildOptions): string;
|
|
16
|
-
/** @deprecated Use {@link createBuildRequestIdentity}. */
|
|
17
|
-
export declare const createBuildOptionsDedupeKey: typeof createBuildRequestIdentity;
|
|
@@ -47,19 +47,15 @@ function normalizeDefine(define) {
|
|
|
47
47
|
* are sorted. Plugin, `conditions`, and source-transform order is preserved because
|
|
48
48
|
* Rolldown hook and `conditionNames` precedence depend on it.
|
|
49
49
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* coalesce. Empty `conditions` / `define` / `external` normalize to the same
|
|
53
|
-
* sentinel as `undefined`.
|
|
50
|
+
* Empty `conditions` / `define` / `external` normalize to the same sentinel as
|
|
51
|
+
* `undefined`.
|
|
54
52
|
*/
|
|
55
53
|
export function createBuildRequestIdentity(options) {
|
|
56
54
|
return [
|
|
57
55
|
normalizeEntrypoints(options.entrypoints),
|
|
58
56
|
options.root ? path.resolve(options.root) : 'root:default',
|
|
59
57
|
options.outdir ? path.resolve(options.outdir) : 'outdir:default',
|
|
60
|
-
options.outbase ? path.resolve(options.outbase) : 'outbase:default',
|
|
61
58
|
options.splitting ?? 'splitting:default',
|
|
62
|
-
options.bundle ?? 'bundle:default',
|
|
63
59
|
options.externalPackages ?? 'externalPackages:default',
|
|
64
60
|
options.target ?? 'target:default',
|
|
65
61
|
options.format ?? 'format:default',
|
|
@@ -75,5 +71,3 @@ export function createBuildRequestIdentity(options) {
|
|
|
75
71
|
createSourceTransformCacheKey(options.sourceTransforms),
|
|
76
72
|
].join('::');
|
|
77
73
|
}
|
|
78
|
-
/** @deprecated Use {@link createBuildRequestIdentity}. */
|
|
79
|
-
export const createBuildOptionsDedupeKey = createBuildRequestIdentity;
|
|
@@ -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/cache/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module @ecopages/core/cache
|
|
5
5
|
*/
|
|
6
|
-
export {
|
|
6
|
+
export { parseModuleSource, type ModuleParseOptions } from './module-parse-cache.js';
|
|
7
7
|
export { recordModuleTransformProfile } from './module-transform-profiler.js';
|
package/src/cache/index.js
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module @ecopages/core/cache
|
|
5
5
|
*/
|
|
6
|
-
export {
|
|
6
|
+
export { parseModuleSource } from './module-parse-cache.js';
|
|
7
7
|
export { recordModuleTransformProfile } from './module-transform-profiler.js';
|
|
@@ -22,22 +22,17 @@ export type ModuleParseOptions = ParserOptions & {
|
|
|
22
22
|
*/
|
|
23
23
|
lang?: ParserOptions['lang'];
|
|
24
24
|
};
|
|
25
|
-
export type ParserLanguage = 'js' | 'jsx' | 'ts' | 'tsx';
|
|
26
|
-
/** Resolves the Oxc dialect for a source module from its file extension. */
|
|
27
|
-
export declare function parserLanguageForFile(filePath: string): ParserLanguage;
|
|
28
25
|
/** Parses an ECMAScript module with the shared, normalized cache contract. */
|
|
29
26
|
export declare function parseModuleSource(filePath: string, source: string, options?: ModuleParseOptions): ParseResult;
|
|
30
27
|
/**
|
|
31
28
|
* LRU-bounded module parse cache.
|
|
32
29
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
30
|
+
* One instance is shared across the process; call {@link parseModuleSource}
|
|
31
|
+
* to use it.
|
|
35
32
|
*/
|
|
36
33
|
export declare class ModuleParseCache {
|
|
37
34
|
private readonly entries;
|
|
38
35
|
private readonly maxEntries;
|
|
39
|
-
private hits;
|
|
40
|
-
private misses;
|
|
41
36
|
constructor(maxEntries?: number);
|
|
42
37
|
/**
|
|
43
38
|
* Parse `source` for `filePath`, memoizing by (filePath, source, options).
|
|
@@ -45,26 +40,4 @@ export declare class ModuleParseCache {
|
|
|
45
40
|
* @returns the {@link ParseResult} from `oxc-parser.parseSync`.
|
|
46
41
|
*/
|
|
47
42
|
getOrParse(filePath: string, source: string, options?: ModuleParseOptions): ParseResult;
|
|
48
|
-
/** Clear all cached entries. Useful in tests and on full-rebuild signals. */
|
|
49
|
-
clear(): void;
|
|
50
|
-
/** Current cache size (for observability). */
|
|
51
|
-
get size(): number;
|
|
52
|
-
/** Cumulative hit/miss counters (for observability). */
|
|
53
|
-
stats(): {
|
|
54
|
-
hits: number;
|
|
55
|
-
misses: number;
|
|
56
|
-
size: number;
|
|
57
|
-
hitRate: number;
|
|
58
|
-
};
|
|
59
43
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Default shared cache. Use this from plugin code so the cache is
|
|
62
|
-
* amortized across plugins and build invocations.
|
|
63
|
-
*/
|
|
64
|
-
export declare const moduleParseCache: ModuleParseCache;
|
|
65
|
-
/**
|
|
66
|
-
* Drop-in replacement for `oxc-parser.parseSync` that uses the shared
|
|
67
|
-
* {@link moduleParseCache}. Use everywhere we currently call `parseSync`
|
|
68
|
-
* on user/source files during a build.
|
|
69
|
-
*/
|
|
70
|
-
export declare function cachedParseSync(filePath: string, source: string, options?: ModuleParseOptions): ParseResult;
|
|
@@ -18,7 +18,7 @@ import { parseSync } from 'oxc-parser';
|
|
|
18
18
|
import { rapidhash } from '../utils/hash.js';
|
|
19
19
|
const DEFAULT_MAX_ENTRIES = 10_000;
|
|
20
20
|
/** Resolves the Oxc dialect for a source module from its file extension. */
|
|
21
|
-
|
|
21
|
+
function parserLanguageForFile(filePath) {
|
|
22
22
|
const extension = extname(filePath).toLowerCase();
|
|
23
23
|
if (extension === '.tsx')
|
|
24
24
|
return 'tsx';
|
|
@@ -30,19 +30,17 @@ export function parserLanguageForFile(filePath) {
|
|
|
30
30
|
}
|
|
31
31
|
/** Parses an ECMAScript module with the shared, normalized cache contract. */
|
|
32
32
|
export function parseModuleSource(filePath, source, options = {}) {
|
|
33
|
-
return moduleParseCache.getOrParse(filePath, source,
|
|
33
|
+
return moduleParseCache.getOrParse(filePath, source, options);
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* LRU-bounded module parse cache.
|
|
37
37
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
38
|
+
* One instance is shared across the process; call {@link parseModuleSource}
|
|
39
|
+
* to use it.
|
|
40
40
|
*/
|
|
41
41
|
export class ModuleParseCache {
|
|
42
42
|
entries = new Map();
|
|
43
43
|
maxEntries;
|
|
44
|
-
hits = 0;
|
|
45
|
-
misses = 0;
|
|
46
44
|
constructor(maxEntries = DEFAULT_MAX_ENTRIES) {
|
|
47
45
|
if (maxEntries <= 0) {
|
|
48
46
|
throw new Error(`ModuleParseCache: maxEntries must be > 0, got ${maxEntries}`);
|
|
@@ -60,13 +58,11 @@ export class ModuleParseCache {
|
|
|
60
58
|
const key = makeKey(filePath, hash, normalizedOptions);
|
|
61
59
|
const existing = this.entries.get(key);
|
|
62
60
|
if (existing && existing.hash === hash) {
|
|
63
|
-
this.hits += 1;
|
|
64
61
|
// Refresh LRU position.
|
|
65
62
|
this.entries.delete(key);
|
|
66
63
|
this.entries.set(key, existing);
|
|
67
64
|
return existing.result;
|
|
68
65
|
}
|
|
69
|
-
this.misses += 1;
|
|
70
66
|
const result = parseSync(filePath, source, normalizedOptions);
|
|
71
67
|
this.entries.set(key, { hash, result });
|
|
72
68
|
if (this.entries.size > this.maxEntries) {
|
|
@@ -80,40 +76,11 @@ export class ModuleParseCache {
|
|
|
80
76
|
}
|
|
81
77
|
return result;
|
|
82
78
|
}
|
|
83
|
-
/** Clear all cached entries. Useful in tests and on full-rebuild signals. */
|
|
84
|
-
clear() {
|
|
85
|
-
this.entries.clear();
|
|
86
|
-
this.hits = 0;
|
|
87
|
-
this.misses = 0;
|
|
88
|
-
}
|
|
89
|
-
/** Current cache size (for observability). */
|
|
90
|
-
get size() {
|
|
91
|
-
return this.entries.size;
|
|
92
|
-
}
|
|
93
|
-
/** Cumulative hit/miss counters (for observability). */
|
|
94
|
-
stats() {
|
|
95
|
-
const total = this.hits + this.misses;
|
|
96
|
-
return {
|
|
97
|
-
hits: this.hits,
|
|
98
|
-
misses: this.misses,
|
|
99
|
-
size: this.entries.size,
|
|
100
|
-
hitRate: total === 0 ? 0 : this.hits / total,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
79
|
}
|
|
104
80
|
/**
|
|
105
|
-
* Default shared cache
|
|
106
|
-
* amortized across plugins and build invocations.
|
|
81
|
+
* Default shared cache, amortized across plugins and build invocations.
|
|
107
82
|
*/
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Drop-in replacement for `oxc-parser.parseSync` that uses the shared
|
|
111
|
-
* {@link moduleParseCache}. Use everywhere we currently call `parseSync`
|
|
112
|
-
* on user/source files during a build.
|
|
113
|
-
*/
|
|
114
|
-
export function cachedParseSync(filePath, source, options = {}) {
|
|
115
|
-
return parseModuleSource(filePath, source, options);
|
|
116
|
-
}
|
|
83
|
+
const moduleParseCache = new ModuleParseCache();
|
|
117
84
|
function normalizeModuleParseOptions(filePath, options) {
|
|
118
85
|
return {
|
|
119
86
|
...options,
|
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` (omitted `rootDir` defaults to `cwd`; `baseUrl` defaults during `ConfigBuilder.build()`)
|
|
23
|
+
- `resolve-eco-config-path.ts`: `eco.config.ts` discovery (`configFile`, `ECOPAGES_CONFIG_FILE`, cwd default, and production `.server/eco.config.mjs`) and `resolveUserConfigRootDir()`
|
|
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 (by config path, build ownership, and cwd).
|
|
51
|
+
- Core fixture helpers live in `packages/core/__fixtures__/app/test-app-config.ts` (`createFixtureAppConfig`, `createFixtureApp`).
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ConfigBuilder } from './config-builder.js';
|
|
2
|
+
import type { EcoPagesUserConfig } from './user-config-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Applies author-owned config fields onto a {@link ConfigBuilder} instance.
|
|
5
|
+
*/
|
|
6
|
+
export declare function applyUserConfigToBuilder(builder: ConfigBuilder, userConfig: EcoPagesUserConfig, options?: {
|
|
7
|
+
cwd?: string;
|
|
8
|
+
}): ConfigBuilder;
|