@ecopages/core 0.2.0-rc.1 → 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 +50 -32
- package/package.json +50 -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 +8 -4
- 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/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 +4 -0
- 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 +41 -25
- package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
- 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 +8 -1
- 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/processor.d.ts +10 -2
- package/src/plugins/processor.js +4 -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 +15 -2
- 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/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 +9 -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 +2 -1
- 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 +32 -22
- 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
|
@@ -45,6 +45,7 @@ export const CONFIG_BUILDER_ERRORS = {
|
|
|
45
45
|
*/
|
|
46
46
|
export class ConfigBuilder {
|
|
47
47
|
buildOwnership = 'rolldown';
|
|
48
|
+
configModulePath;
|
|
48
49
|
config = {
|
|
49
50
|
baseUrl: '',
|
|
50
51
|
rootDir: '.',
|
|
@@ -88,6 +89,14 @@ export class ConfigBuilder {
|
|
|
88
89
|
publicDir: '',
|
|
89
90
|
srcDir: '',
|
|
90
91
|
htmlTemplatePath: '',
|
|
92
|
+
errorPageTemplatePaths: {
|
|
93
|
+
400: '',
|
|
94
|
+
401: '',
|
|
95
|
+
403: '',
|
|
96
|
+
404: '',
|
|
97
|
+
409: '',
|
|
98
|
+
500: '',
|
|
99
|
+
},
|
|
91
100
|
error404TemplatePath: '',
|
|
92
101
|
error500TemplatePath: '',
|
|
93
102
|
},
|
|
@@ -139,6 +148,17 @@ export class ConfigBuilder {
|
|
|
139
148
|
this.buildOwnership = buildOwnership;
|
|
140
149
|
return this;
|
|
141
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Sets the canonical path of the Ecopages config module on disk.
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* Used by the config loader so {@link EcoPagesAppConfig.absolutePaths.config}
|
|
156
|
+
* reflects `--config` overrides and production-emitted config modules.
|
|
157
|
+
*/
|
|
158
|
+
setConfigModulePath(configModulePath) {
|
|
159
|
+
this.configModulePath = configModulePath;
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
142
162
|
/**
|
|
143
163
|
* Sets the source directory relative to the root directory.
|
|
144
164
|
* This directory contains all the source files for the application.
|
|
@@ -437,8 +457,34 @@ export class ConfigBuilder {
|
|
|
437
457
|
const absoluteWorkDir = path.resolve(projectDir, workDir);
|
|
438
458
|
const absoluteIncludesDir = path.join(absoluteSrcDir, includesDir);
|
|
439
459
|
const absolutePagesDir = path.join(absoluteSrcDir, pagesDir);
|
|
460
|
+
const errorPageTemplatePaths = {
|
|
461
|
+
400: this.resolveSemanticTemplatePath({
|
|
462
|
+
dirPath: absolutePagesDir,
|
|
463
|
+
basename: '400',
|
|
464
|
+
}),
|
|
465
|
+
401: this.resolveSemanticTemplatePath({
|
|
466
|
+
dirPath: absolutePagesDir,
|
|
467
|
+
basename: '401',
|
|
468
|
+
}),
|
|
469
|
+
403: this.resolveSemanticTemplatePath({
|
|
470
|
+
dirPath: absolutePagesDir,
|
|
471
|
+
basename: '403',
|
|
472
|
+
}),
|
|
473
|
+
404: this.resolveSemanticTemplatePath({
|
|
474
|
+
dirPath: absolutePagesDir,
|
|
475
|
+
basename: '404',
|
|
476
|
+
}),
|
|
477
|
+
409: this.resolveSemanticTemplatePath({
|
|
478
|
+
dirPath: absolutePagesDir,
|
|
479
|
+
basename: '409',
|
|
480
|
+
}),
|
|
481
|
+
500: this.resolveSemanticTemplatePath({
|
|
482
|
+
dirPath: absolutePagesDir,
|
|
483
|
+
basename: '500',
|
|
484
|
+
}),
|
|
485
|
+
};
|
|
440
486
|
this.config.absolutePaths = {
|
|
441
|
-
config: path.join(projectDir, 'eco.config.ts'),
|
|
487
|
+
config: this.configModulePath ?? path.join(projectDir, 'eco.config.ts'),
|
|
442
488
|
projectDir: projectDir,
|
|
443
489
|
srcDir: absoluteSrcDir,
|
|
444
490
|
distDir: absoluteDistDir,
|
|
@@ -452,18 +498,13 @@ export class ConfigBuilder {
|
|
|
452
498
|
dirPath: absoluteIncludesDir,
|
|
453
499
|
basename: 'html',
|
|
454
500
|
}),
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
}),
|
|
459
|
-
error500TemplatePath: this.resolveSemanticTemplatePath({
|
|
460
|
-
dirPath: absolutePagesDir,
|
|
461
|
-
basename: '500',
|
|
462
|
-
}),
|
|
501
|
+
errorPageTemplatePaths,
|
|
502
|
+
error404TemplatePath: errorPageTemplatePaths[404],
|
|
503
|
+
error500TemplatePath: errorPageTemplatePaths[500],
|
|
463
504
|
};
|
|
464
505
|
return this;
|
|
465
506
|
}
|
|
466
|
-
resolveSemanticTemplatePath({ dirPath, basename
|
|
507
|
+
resolveSemanticTemplatePath({ dirPath, basename }) {
|
|
467
508
|
const extensions = this.config.templatesExt;
|
|
468
509
|
if (extensions.length === 0) {
|
|
469
510
|
return '';
|
package/src/config/constants.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EcoPagesUserConfig } from './user-config-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Type helper for `eco.config.ts` authoring.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Synchronous identity only. Loading and finalization happen through
|
|
7
|
+
* {@link loadEcoPagesConfig} or {@link createApp}.
|
|
8
|
+
*/
|
|
9
|
+
export declare function defineConfig(config: EcoPagesUserConfig): EcoPagesUserConfig;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { defineConfig } from './define-config.js';
|
|
2
|
+
export { loadEcoPagesConfig, loadEcoPagesUserConfig, finalizeEcoPagesConfig } from './load-eco-config.js';
|
|
3
|
+
export { resolveEcoConfigPath, resolveEmittedEcoConfigPath, DEFAULT_ECO_CONFIG_FILENAME, ECOPAGES_CONFIG_FILE_ENV, } from './resolve-eco-config-path.js';
|
|
4
|
+
export { assertProductionConfigIdentity } from '../build/cache/server-entry-build-cache.js';
|
|
5
|
+
export type { EcoPagesUserConfig, LoadedEcoPagesUserConfig, FinalizeEcoPagesConfigOptions, LoadEcoPagesConfigOptions, } from './user-config-types.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { defineConfig } from './define-config.js';
|
|
2
|
+
export { loadEcoPagesConfig, loadEcoPagesUserConfig, finalizeEcoPagesConfig } from './load-eco-config.js';
|
|
3
|
+
export { resolveEcoConfigPath, resolveEmittedEcoConfigPath, DEFAULT_ECO_CONFIG_FILENAME, ECOPAGES_CONFIG_FILE_ENV, } from './resolve-eco-config-path.js';
|
|
4
|
+
export { assertProductionConfigIdentity } from '../build/cache/server-entry-build-cache.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EcoPagesAppConfig } from '../types/internal-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* @remarks
|
|
4
|
+
* Finalized configs use Maps for processors/loaders; user configs use arrays.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isFinalizedEcoPagesAppConfig(value: unknown): value is EcoPagesAppConfig;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @remarks
|
|
3
|
+
* Finalized configs use Maps for processors/loaders; user configs use arrays.
|
|
4
|
+
*/
|
|
5
|
+
export function isFinalizedEcoPagesAppConfig(value) {
|
|
6
|
+
if (!value || typeof value !== 'object') {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const config = value;
|
|
10
|
+
return config.processors instanceof Map && Array.isArray(config.templatesExt);
|
|
11
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EcoPagesAppConfig } from '../types/internal-types.js';
|
|
2
|
+
import type { FinalizeEcoPagesConfigOptions, LoadEcoPagesConfigOptions, LoadedEcoPagesUserConfig } from './user-config-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Loads the user-owned config object from the resolved config module.
|
|
5
|
+
*/
|
|
6
|
+
export declare function loadEcoPagesUserConfig(options?: LoadEcoPagesConfigOptions): Promise<LoadedEcoPagesUserConfig>;
|
|
7
|
+
/**
|
|
8
|
+
* Finalizes a loaded user config through {@link ConfigBuilder.build}.
|
|
9
|
+
*/
|
|
10
|
+
export declare function finalizeEcoPagesConfig(loaded: LoadedEcoPagesUserConfig, options?: FinalizeEcoPagesConfigOptions): Promise<EcoPagesAppConfig>;
|
|
11
|
+
/**
|
|
12
|
+
* Loads and finalizes the Ecopages config for the current project.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Coalesces concurrent loads and caches by `configFilePath` and `buildOwnership`.
|
|
16
|
+
* Files that still export a finalized {@link ConfigBuilder.build} result are returned as-is
|
|
17
|
+
* so workers and tests can load existing `eco.config.ts` modules.
|
|
18
|
+
*/
|
|
19
|
+
export declare function loadEcoPagesConfig(options?: LoadEcoPagesConfigOptions): Promise<EcoPagesAppConfig>;
|
|
20
|
+
/** @internal */
|
|
21
|
+
export declare function clearEcoPagesConfigCachesForTests(): void;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { pathToFileURL } from 'node:url';
|
|
2
|
+
import { applyUserConfigToBuilder } from './apply-user-config.js';
|
|
3
|
+
import { ConfigBuilder } from './config-builder.js';
|
|
4
|
+
import { isFinalizedEcoPagesAppConfig } from './is-finalized-app-config.js';
|
|
5
|
+
import { resolveEcoConfigPath } from './resolve-eco-config-path.js';
|
|
6
|
+
const moduleLoadCache = new Map();
|
|
7
|
+
const appConfigCache = new Map();
|
|
8
|
+
function createCacheKey(configFilePath, buildOwnership) {
|
|
9
|
+
const ownership = buildOwnership ?? 'rolldown';
|
|
10
|
+
return `${configFilePath}::${ownership}`;
|
|
11
|
+
}
|
|
12
|
+
async function importEcoConfigModule(configFilePath) {
|
|
13
|
+
const moduleUrl = pathToFileURL(configFilePath).href;
|
|
14
|
+
const configModule = await import(moduleUrl);
|
|
15
|
+
return configModule.default ?? configModule;
|
|
16
|
+
}
|
|
17
|
+
function loadConfigModule(configFilePath) {
|
|
18
|
+
const cached = moduleLoadCache.get(configFilePath);
|
|
19
|
+
if (cached) {
|
|
20
|
+
return cached;
|
|
21
|
+
}
|
|
22
|
+
const loadPromise = (async () => {
|
|
23
|
+
const exported = await importEcoConfigModule(configFilePath);
|
|
24
|
+
if (isFinalizedEcoPagesAppConfig(exported)) {
|
|
25
|
+
return { kind: 'finalized', appConfig: exported, configFilePath };
|
|
26
|
+
}
|
|
27
|
+
if (!exported || typeof exported !== 'object') {
|
|
28
|
+
throw new Error(`Ecopages config at ${configFilePath} must default-export an object from defineConfig(...).`);
|
|
29
|
+
}
|
|
30
|
+
const userConfig = exported;
|
|
31
|
+
if (typeof userConfig.rootDir !== 'string' || userConfig.rootDir.length === 0) {
|
|
32
|
+
throw new Error(`Ecopages config at ${configFilePath} must include a non-empty rootDir.`);
|
|
33
|
+
}
|
|
34
|
+
return { kind: 'user', userConfig, configFilePath };
|
|
35
|
+
})();
|
|
36
|
+
moduleLoadCache.set(configFilePath, loadPromise);
|
|
37
|
+
return loadPromise.catch((error) => {
|
|
38
|
+
moduleLoadCache.delete(configFilePath);
|
|
39
|
+
throw error;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Loads the user-owned config object from the resolved config module.
|
|
44
|
+
*/
|
|
45
|
+
export async function loadEcoPagesUserConfig(options = {}) {
|
|
46
|
+
const configFilePath = resolveEcoConfigPath(options);
|
|
47
|
+
const loaded = await loadConfigModule(configFilePath);
|
|
48
|
+
if (loaded.kind === 'finalized') {
|
|
49
|
+
throw new Error(`Ecopages config at ${configFilePath} exported a finalized app config. Use defineConfig(...) and let createApp() finalize the config.`);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
config: loaded.userConfig,
|
|
53
|
+
configFilePath,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Finalizes a loaded user config through {@link ConfigBuilder.build}.
|
|
58
|
+
*/
|
|
59
|
+
export async function finalizeEcoPagesConfig(loaded, options = {}) {
|
|
60
|
+
const buildOwnership = options.buildOwnership ?? loaded.config.buildOwnership ?? 'rolldown';
|
|
61
|
+
const builder = new ConfigBuilder();
|
|
62
|
+
applyUserConfigToBuilder(builder, loaded.config);
|
|
63
|
+
builder.setBuildOwnership(buildOwnership);
|
|
64
|
+
builder.setConfigModulePath(loaded.configFilePath);
|
|
65
|
+
return await builder.build();
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Loads and finalizes the Ecopages config for the current project.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* Coalesces concurrent loads and caches by `configFilePath` and `buildOwnership`.
|
|
72
|
+
* Files that still export a finalized {@link ConfigBuilder.build} result are returned as-is
|
|
73
|
+
* so workers and tests can load existing `eco.config.ts` modules.
|
|
74
|
+
*/
|
|
75
|
+
export async function loadEcoPagesConfig(options = {}) {
|
|
76
|
+
const configFilePath = resolveEcoConfigPath(options);
|
|
77
|
+
const buildOwnership = options.buildOwnership ?? 'rolldown';
|
|
78
|
+
const cacheKey = createCacheKey(configFilePath, buildOwnership);
|
|
79
|
+
const cached = appConfigCache.get(cacheKey);
|
|
80
|
+
if (cached) {
|
|
81
|
+
return cached;
|
|
82
|
+
}
|
|
83
|
+
const loadPromise = (async () => {
|
|
84
|
+
const loaded = await loadConfigModule(configFilePath);
|
|
85
|
+
if (loaded.kind === 'finalized') {
|
|
86
|
+
return loaded.appConfig;
|
|
87
|
+
}
|
|
88
|
+
return await finalizeEcoPagesConfig({ config: loaded.userConfig, configFilePath }, { buildOwnership: options.buildOwnership });
|
|
89
|
+
})();
|
|
90
|
+
appConfigCache.set(cacheKey, loadPromise);
|
|
91
|
+
return loadPromise.catch((error) => {
|
|
92
|
+
appConfigCache.delete(cacheKey);
|
|
93
|
+
throw error;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** @internal */
|
|
97
|
+
export function clearEcoPagesConfigCachesForTests() {
|
|
98
|
+
moduleLoadCache.clear();
|
|
99
|
+
appConfigCache.clear();
|
|
100
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const DEFAULT_ECO_CONFIG_FILENAME = "eco.config.ts";
|
|
2
|
+
export declare const ECOPAGES_CONFIG_FILE_ENV = "ECOPAGES_CONFIG_FILE";
|
|
3
|
+
export type ResolveEcoConfigPathOptions = {
|
|
4
|
+
configFile?: string;
|
|
5
|
+
cwd?: string;
|
|
6
|
+
required?: boolean;
|
|
7
|
+
/** Prefer the emitted production config over the source config when both exist. */
|
|
8
|
+
preferEmitted?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/** Resolves the emitted production config without consulting source overrides. */
|
|
11
|
+
export declare function resolveEmittedEcoConfigPath(cwd?: string): string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Resolves the canonical absolute path to the Ecopages config module.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Precedence: explicit `configFile`, then `ECOPAGES_CONFIG_FILE`, then
|
|
17
|
+
* `<cwd>/eco.config.ts`, then the emitted production config. When `preferEmitted`
|
|
18
|
+
* is enabled, the emitted config precedes the source config.
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveEcoConfigPath(options: ResolveEcoConfigPathOptions & {
|
|
21
|
+
required: false;
|
|
22
|
+
}): string | undefined;
|
|
23
|
+
export declare function resolveEcoConfigPath(options?: ResolveEcoConfigPathOptions): string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
3
|
+
import { SERVER_BUNDLE_DIR } from '../utils/resolve-entry-file.js';
|
|
4
|
+
import { EMITTED_ECO_CONFIG_FILENAME } from './server-config-bundle.js';
|
|
5
|
+
export const DEFAULT_ECO_CONFIG_FILENAME = 'eco.config.ts';
|
|
6
|
+
export const ECOPAGES_CONFIG_FILE_ENV = 'ECOPAGES_CONFIG_FILE';
|
|
7
|
+
/** Resolves the emitted production config without consulting source overrides. */
|
|
8
|
+
export function resolveEmittedEcoConfigPath(cwd = process.cwd()) {
|
|
9
|
+
const candidates = [
|
|
10
|
+
path.resolve(cwd, 'dist', SERVER_BUNDLE_DIR, EMITTED_ECO_CONFIG_FILENAME),
|
|
11
|
+
path.resolve(cwd, SERVER_BUNDLE_DIR, EMITTED_ECO_CONFIG_FILENAME),
|
|
12
|
+
];
|
|
13
|
+
return candidates.find((candidate) => fileSystem.exists(candidate));
|
|
14
|
+
}
|
|
15
|
+
export function resolveEcoConfigPath(options = {}) {
|
|
16
|
+
const cwd = options.cwd ?? process.cwd();
|
|
17
|
+
const required = options.required ?? true;
|
|
18
|
+
if (options.configFile) {
|
|
19
|
+
const resolved = path.isAbsolute(options.configFile)
|
|
20
|
+
? options.configFile
|
|
21
|
+
: path.resolve(cwd, options.configFile);
|
|
22
|
+
if (!fileSystem.exists(resolved)) {
|
|
23
|
+
throw new Error(`Ecopages config file not found: ${resolved}`);
|
|
24
|
+
}
|
|
25
|
+
return resolved;
|
|
26
|
+
}
|
|
27
|
+
const envPath = process.env[ECOPAGES_CONFIG_FILE_ENV];
|
|
28
|
+
if (envPath) {
|
|
29
|
+
const resolved = path.isAbsolute(envPath) ? envPath : path.resolve(cwd, envPath);
|
|
30
|
+
if (!fileSystem.exists(resolved)) {
|
|
31
|
+
throw new Error(`Ecopages config file not found: ${resolved}`);
|
|
32
|
+
}
|
|
33
|
+
return resolved;
|
|
34
|
+
}
|
|
35
|
+
const defaultPath = path.resolve(cwd, DEFAULT_ECO_CONFIG_FILENAME);
|
|
36
|
+
const emittedConfigPath = resolveEmittedEcoConfigPath(cwd);
|
|
37
|
+
if (options.preferEmitted && emittedConfigPath)
|
|
38
|
+
return emittedConfigPath;
|
|
39
|
+
if (fileSystem.exists(defaultPath))
|
|
40
|
+
return defaultPath;
|
|
41
|
+
if (emittedConfigPath)
|
|
42
|
+
return emittedConfigPath;
|
|
43
|
+
if (!required) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`Ecopages config file not found: ${defaultPath}`);
|
|
47
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BuildResult } from '../build/contracts/build-contracts.js';
|
|
2
|
+
import type { EcoSourceTransform } from '../plugins/source-transform.js';
|
|
3
|
+
import type { EcoPagesAppConfig } from '../types/internal-types.js';
|
|
4
|
+
export declare const EMITTED_ECO_CONFIG_FILENAME = "eco.config.mjs";
|
|
5
|
+
export interface BundleEcoConfigModuleResult {
|
|
6
|
+
emittedConfigPath: string;
|
|
7
|
+
buildResult: BuildResult;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates a source transform that preserves source module directory semantics
|
|
11
|
+
* when `eco.config.ts` is relocated into `dist/.server/eco.config.mjs`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createPreserveImportMetaTransform(serverOutdir: string): EcoSourceTransform;
|
|
14
|
+
/**
|
|
15
|
+
* Compiles the selected Ecopages config module for production server startup.
|
|
16
|
+
*/
|
|
17
|
+
export declare function bundleEcoConfigModule(appConfig: EcoPagesAppConfig, options?: {
|
|
18
|
+
outputDir?: string;
|
|
19
|
+
runtimeDir?: string;
|
|
20
|
+
}): Promise<BundleEcoConfigModuleResult | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* @remarks
|
|
23
|
+
* Ensures build ownership allows app-owned bundling before emitting config artifacts.
|
|
24
|
+
*/
|
|
25
|
+
export declare function assertCanBundleServerConfig(appConfig: EcoPagesAppConfig): void;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
3
|
+
import { build, getAppBuildAdapter } from '../build/build-adapter.js';
|
|
4
|
+
import { cachedParseSync } from '../cache/module-parse-cache.js';
|
|
5
|
+
import { createServerBuildRequest } from '../build/runtime/build-request-policy.js';
|
|
6
|
+
import { requireBuildRuntime } from '../build/runtime/build-runtime.js';
|
|
7
|
+
import { getServerBundleOutputPaths } from '../build/cache/server-entry-build-cache.js';
|
|
8
|
+
export const EMITTED_ECO_CONFIG_FILENAME = 'eco.config.mjs';
|
|
9
|
+
function isAstNode(value) {
|
|
10
|
+
return typeof value === 'object' && value !== null;
|
|
11
|
+
}
|
|
12
|
+
function walkAst(value, visit) {
|
|
13
|
+
if (Array.isArray(value)) {
|
|
14
|
+
for (const child of value)
|
|
15
|
+
walkAst(child, visit);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (!isAstNode(value))
|
|
19
|
+
return;
|
|
20
|
+
visit(value);
|
|
21
|
+
for (const child of Object.values(value))
|
|
22
|
+
walkAst(child, visit);
|
|
23
|
+
}
|
|
24
|
+
function isImportMeta(node) {
|
|
25
|
+
if (!isAstNode(node) || node.type !== 'MetaProperty')
|
|
26
|
+
return false;
|
|
27
|
+
return (isAstNode(node.meta) &&
|
|
28
|
+
node.meta.type === 'Identifier' &&
|
|
29
|
+
node.meta.name === 'import' &&
|
|
30
|
+
isAstNode(node.property) &&
|
|
31
|
+
node.property.type === 'Identifier' &&
|
|
32
|
+
node.property.name === 'meta');
|
|
33
|
+
}
|
|
34
|
+
function collectImportMetaEdits(code, id, serverOutdir) {
|
|
35
|
+
const program = cachedParseSync(id, code, { sourceType: 'module' }).program;
|
|
36
|
+
const fileDir = path.dirname(id);
|
|
37
|
+
const relativeDir = path.relative(serverOutdir, fileDir).replaceAll('\\', '/');
|
|
38
|
+
const relativeFile = relativeDir ? `${relativeDir}/${path.basename(id)}` : `./${path.basename(id)}`;
|
|
39
|
+
const edits = [];
|
|
40
|
+
let needsNodePath = false;
|
|
41
|
+
const identifiers = new Set();
|
|
42
|
+
walkAst(program, (node) => {
|
|
43
|
+
if (node.type === 'Identifier' && typeof node.name === 'string')
|
|
44
|
+
identifiers.add(node.name);
|
|
45
|
+
});
|
|
46
|
+
let pathBinding = '__ecoConfigPath';
|
|
47
|
+
while (identifiers.has(pathBinding))
|
|
48
|
+
pathBinding = `_${pathBinding}`;
|
|
49
|
+
walkAst(program, (node) => {
|
|
50
|
+
if (node.type !== 'MemberExpression' && node.type !== 'StaticMemberExpression')
|
|
51
|
+
return;
|
|
52
|
+
if (!isImportMeta(node.object) || !isAstNode(node.property) || node.property.type !== 'Identifier')
|
|
53
|
+
return;
|
|
54
|
+
if (typeof node.start !== 'number' || typeof node.end !== 'number')
|
|
55
|
+
return;
|
|
56
|
+
if (node.property.name === 'dirname' || node.property.name === 'dir') {
|
|
57
|
+
needsNodePath = true;
|
|
58
|
+
edits.push({
|
|
59
|
+
start: node.start,
|
|
60
|
+
end: node.end,
|
|
61
|
+
replacement: `${pathBinding}.resolve(import.meta.dirname, ${JSON.stringify(relativeDir || '.')})`,
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (node.property.name === 'url') {
|
|
66
|
+
edits.push({
|
|
67
|
+
start: node.start,
|
|
68
|
+
end: node.end,
|
|
69
|
+
replacement: `new URL(${JSON.stringify(relativeFile)}, import.meta.url).href`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return { edits, needsNodePath, pathBinding };
|
|
74
|
+
}
|
|
75
|
+
function applySourceEdits(code, edits) {
|
|
76
|
+
let transformed = code;
|
|
77
|
+
for (const edit of edits.sort((left, right) => right.start - left.start)) {
|
|
78
|
+
transformed = `${transformed.slice(0, edit.start)}${edit.replacement}${transformed.slice(edit.end)}`;
|
|
79
|
+
}
|
|
80
|
+
return transformed;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Creates a source transform that preserves source module directory semantics
|
|
84
|
+
* when `eco.config.ts` is relocated into `dist/.server/eco.config.mjs`.
|
|
85
|
+
*/
|
|
86
|
+
export function createPreserveImportMetaTransform(serverOutdir) {
|
|
87
|
+
return {
|
|
88
|
+
name: 'preserve-import-meta-for-server-config',
|
|
89
|
+
filter: /\.[cm]?[jt]sx?$/,
|
|
90
|
+
transform(code, id) {
|
|
91
|
+
if (!code.includes('import.meta')) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const { edits, needsNodePath, pathBinding } = collectImportMetaEdits(code, id, serverOutdir);
|
|
95
|
+
if (edits.length === 0)
|
|
96
|
+
return undefined;
|
|
97
|
+
const transformed = applySourceEdits(code, edits);
|
|
98
|
+
return {
|
|
99
|
+
code: needsNodePath ? `import * as ${pathBinding} from 'node:path';\n${transformed}` : transformed,
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Compiles the selected Ecopages config module for production server startup.
|
|
106
|
+
*/
|
|
107
|
+
export async function bundleEcoConfigModule(appConfig, options = {}) {
|
|
108
|
+
const configSourcePath = appConfig.absolutePaths?.config;
|
|
109
|
+
if (!configSourcePath || !fileSystem.exists(configSourcePath)) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
const { serverOutdir } = getServerBundleOutputPaths(appConfig);
|
|
113
|
+
const outputDir = options.outputDir ?? serverOutdir;
|
|
114
|
+
const runtimeDir = options.runtimeDir ?? serverOutdir;
|
|
115
|
+
const emittedConfigPath = path.join(outputDir, EMITTED_ECO_CONFIG_FILENAME);
|
|
116
|
+
fileSystem.ensureDir(outputDir);
|
|
117
|
+
const buildOptions = createServerBuildRequest(appConfig, {
|
|
118
|
+
profile: 'server-entry',
|
|
119
|
+
entrypoints: [configSourcePath],
|
|
120
|
+
outdir: outputDir,
|
|
121
|
+
naming: EMITTED_ECO_CONFIG_FILENAME,
|
|
122
|
+
sourcemap: 'hidden',
|
|
123
|
+
sourceTransforms: [createPreserveImportMetaTransform(runtimeDir)],
|
|
124
|
+
});
|
|
125
|
+
const result = await build(buildOptions, requireBuildRuntime(appConfig).getProfile('server-entry'));
|
|
126
|
+
if (!result.success) {
|
|
127
|
+
const errorMessages = result.logs.map((log) => log.message).join('\n');
|
|
128
|
+
throw new Error(`Failed to bundle Ecopages config module:\n${errorMessages}`);
|
|
129
|
+
}
|
|
130
|
+
if (!fileSystem.exists(emittedConfigPath)) {
|
|
131
|
+
throw new Error(`Ecopages config bundle missing at ${emittedConfigPath}`);
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
emittedConfigPath,
|
|
135
|
+
buildResult: result,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @remarks
|
|
140
|
+
* Ensures build ownership allows app-owned bundling before emitting config artifacts.
|
|
141
|
+
*/
|
|
142
|
+
export function assertCanBundleServerConfig(appConfig) {
|
|
143
|
+
const buildAdapter = getAppBuildAdapter(appConfig);
|
|
144
|
+
if (buildAdapter.ownership === 'vite-host') {
|
|
145
|
+
throw new Error('Cannot bundle the server config: build ownership is "vite-host". ' +
|
|
146
|
+
'The host runtime is expected to produce its own server bundle.');
|
|
147
|
+
}
|
|
148
|
+
}
|