@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
|
@@ -20,10 +20,10 @@ Call site (route scan, renderer, SSG, API)
|
|
|
20
20
|
|
|
21
21
|
## Host vs app ownership
|
|
22
22
|
|
|
23
|
-
| Path | When
|
|
24
|
-
| ----------------------- |
|
|
25
|
-
| Host loader | `appConfig.runtime.hostModuleLoader` set (Vite host) and file supports direct source loading
|
|
26
|
-
| Ecopages build pipeline | Framework-owned template files under `pages/`, `includes/`,
|
|
23
|
+
| Path | When |
|
|
24
|
+
| ----------------------- | ----------------------------------------------------------------------------------------------- |
|
|
25
|
+
| Host loader | `appConfig.runtime.hostModuleLoader` set (Vite host) and file supports direct source loading |
|
|
26
|
+
| Ecopages build pipeline | Framework-owned template files under `pages/`, `includes/`, `layouts/`, `components/`, `views/` |
|
|
27
27
|
|
|
28
28
|
`shouldAppUseHostModuleLoader()` encodes the directory + extension rules. Bun always uses the build pipeline today.
|
|
29
29
|
|
|
@@ -35,17 +35,20 @@ Call site (route scan, renderer, SSG, API)
|
|
|
35
35
|
|
|
36
36
|
Development import URLs use `sourceHash` plus a per-service import generation counter. Node uses that value in its `?update=` query. Bun also receives a generation-specific compiled output filename because it retains a previously imported file when only its query changes. Both paths advance after `invalidateDevelopmentGraph()` without a process-wide invalidation version in reuse keys.
|
|
37
37
|
|
|
38
|
+
Compiled collection server modules also include the app-owned server invalidation version in their output filename (`<collection>-<buildIdentity>-<invalidationVersion>.mjs`) so Node's ESM loader treats recompiled bundles as new modules after co-located helper files change.
|
|
39
|
+
|
|
38
40
|
## Files
|
|
39
41
|
|
|
40
|
-
| File | Role
|
|
41
|
-
| ----------------------------------------- |
|
|
42
|
-
| `page-module-import.service.ts` | Core import/cache/build orchestration
|
|
43
|
-
| `route-module-build-manifest.ts` | Content-derived reuse identity and disk cache manifest
|
|
44
|
-
| `app-module-loader.service.ts` | App-facing loader interface
|
|
45
|
-
| `app-server-module-transpiler.service.ts` | Factory for app-scoped loader + transpiler
|
|
46
|
-
| `server-module-transpiler.service.ts` | Injectable transpiler boundary for tests and bootstrap
|
|
47
|
-
| `
|
|
48
|
-
| `
|
|
42
|
+
| File | Role |
|
|
43
|
+
| ----------------------------------------- | ---------------------------------------------------------------- |
|
|
44
|
+
| `page-module-import.service.ts` | Core import/cache/build orchestration |
|
|
45
|
+
| `route-module-build-manifest.ts` | Content-derived reuse identity and disk cache manifest |
|
|
46
|
+
| `app-module-loader.service.ts` | App-facing loader interface |
|
|
47
|
+
| `app-server-module-transpiler.service.ts` | Factory for app-scoped loader + transpiler |
|
|
48
|
+
| `server-module-transpiler.service.ts` | Injectable transpiler boundary for tests and bootstrap |
|
|
49
|
+
| `view-module-loader.ts` | Normalizes string/URL view registrations into transpiler loaders |
|
|
50
|
+
| `host-module-loader-registry.ts` | Process-global host loader fallback for embedded runtimes |
|
|
51
|
+
| `source-module-support.ts` | Extension allowlist for host direct loading |
|
|
49
52
|
|
|
50
53
|
## Development invalidation
|
|
51
54
|
|
|
@@ -10,11 +10,13 @@ export function shouldAppUseHostModuleLoader(appConfig, filePath) {
|
|
|
10
10
|
return supportsSourceModuleLoading(filePath);
|
|
11
11
|
}
|
|
12
12
|
const normalizedFilePath = path.normalize(filePath);
|
|
13
|
+
const viewsDir = path.join(appConfig.absolutePaths.srcDir, 'views');
|
|
13
14
|
const frameworkOwnedDirectories = [
|
|
14
15
|
appConfig.absolutePaths.pagesDir,
|
|
15
16
|
appConfig.absolutePaths.includesDir,
|
|
16
17
|
appConfig.absolutePaths.layoutsDir,
|
|
17
18
|
appConfig.absolutePaths.componentsDir,
|
|
19
|
+
viewsDir,
|
|
18
20
|
].map((directoryPath) => path.normalize(directoryPath));
|
|
19
21
|
const isFrameworkOwnedModule = frameworkOwnedDirectories.some((directoryPath) => {
|
|
20
22
|
return normalizedFilePath === directoryPath || normalizedFilePath.startsWith(`${directoryPath}${path.sep}`);
|
|
@@ -5,6 +5,7 @@ export type CollectionServerBuildArtifact = {
|
|
|
5
5
|
outputUrl: string;
|
|
6
6
|
sourcePaths: string[];
|
|
7
7
|
buildIdentity: string;
|
|
8
|
+
invalidationVersion: number;
|
|
8
9
|
};
|
|
9
10
|
export declare function getCollectionServerBuildArtifact(appConfig: EcoPagesAppConfig, collectionName: string): CollectionServerBuildArtifact | undefined;
|
|
10
11
|
export declare function clearCollectionServerBuildArtifacts(appConfig: EcoPagesAppConfig): void;
|
|
@@ -7,6 +7,7 @@ import { createServerBuildRequest } from '../../build/runtime/build-request-poli
|
|
|
7
7
|
import { recordCollectionBuild } from '../../diagnostics/request-pipeline-metrics.js';
|
|
8
8
|
import { resolveInternalExecutionDir } from '../../utils/resolve-work-dir.js';
|
|
9
9
|
import { fileSystem } from '@ecopages/file-system';
|
|
10
|
+
import { getAppServerInvalidationState } from '../runtime-state/server-invalidation-state.service.js';
|
|
10
11
|
const artifactsByCollection = new WeakMap();
|
|
11
12
|
function getArtifactMap(appConfig) {
|
|
12
13
|
let artifacts = artifactsByCollection.get(appConfig);
|
|
@@ -51,13 +52,14 @@ export async function buildCollectionServerModule(input) {
|
|
|
51
52
|
splitting: false,
|
|
52
53
|
externalPackages: true,
|
|
53
54
|
});
|
|
55
|
+
const invalidationVersion = getAppServerInvalidationState(appConfig).getServerInvalidationVersion();
|
|
54
56
|
const buildIdentity = createCollectionBuildIdentity(createBuildRequestIdentity(buildRequest), sourceFilePath, ownedSourcePaths);
|
|
55
57
|
const artifacts = getArtifactMap(appConfig);
|
|
56
58
|
const existing = artifacts.get(collectionName);
|
|
57
|
-
if (existing?.buildIdentity === buildIdentity) {
|
|
59
|
+
if (existing?.buildIdentity === buildIdentity && existing?.invalidationVersion === invalidationVersion) {
|
|
58
60
|
return existing;
|
|
59
61
|
}
|
|
60
|
-
const outputFileName = `${collectionName}-${buildIdentity}.mjs`;
|
|
62
|
+
const outputFileName = `${collectionName}-${buildIdentity}-${invalidationVersion}.mjs`;
|
|
61
63
|
const buildOptions = { ...buildRequest, naming: outputFileName.replace(/\.mjs$/u, '.[ext]') };
|
|
62
64
|
recordCollectionBuild();
|
|
63
65
|
const buildResult = await build(buildOptions);
|
|
@@ -77,6 +79,7 @@ export async function buildCollectionServerModule(input) {
|
|
|
77
79
|
outputUrl: pathToFileURL(compiledOutput).href,
|
|
78
80
|
sourcePaths: [...ownedSourcePaths, sourceFilePath],
|
|
79
81
|
buildIdentity,
|
|
82
|
+
invalidationVersion,
|
|
80
83
|
};
|
|
81
84
|
artifacts.set(collectionName, artifact);
|
|
82
85
|
return artifact;
|
|
@@ -16,6 +16,8 @@ interface PageModuleImportBaseOptions {
|
|
|
16
16
|
export interface PageModuleBuildImportOptions extends PageModuleImportBaseOptions {
|
|
17
17
|
rootDir: string;
|
|
18
18
|
outdir: string;
|
|
19
|
+
/** Use the server build pipeline even when a development host can load source modules. */
|
|
20
|
+
forceBuild?: boolean;
|
|
19
21
|
buildExecutor?: BuildExecutor;
|
|
20
22
|
splitting?: boolean;
|
|
21
23
|
externalPackages?: boolean;
|
|
@@ -87,6 +89,12 @@ export declare class PageModuleImportService {
|
|
|
87
89
|
* @returns The loaded module.
|
|
88
90
|
*/
|
|
89
91
|
importModule<T = unknown>(options: PageModuleBuildImportOptions): Promise<T>;
|
|
92
|
+
private createRouteModuleBuildOptions;
|
|
93
|
+
private createRouteModuleCacheBuildOptions;
|
|
94
|
+
private tryLoadCachedRouteModuleBuild;
|
|
95
|
+
private tryLoadPagesUnifiedGraphModule;
|
|
96
|
+
private resolveCompiledRouteModuleOutput;
|
|
97
|
+
private importCompiledRouteModule;
|
|
90
98
|
private loadModule;
|
|
91
99
|
private getRouteModuleBuildCache;
|
|
92
100
|
}
|
|
@@ -72,7 +72,8 @@ export class PageModuleImportService {
|
|
|
72
72
|
async importModule(options) {
|
|
73
73
|
const { filePath } = options;
|
|
74
74
|
const fileHash = this.dependencies.hashFile(filePath);
|
|
75
|
-
const hostModuleLoader =
|
|
75
|
+
const hostModuleLoader = !options.forceBuild &&
|
|
76
|
+
typeof Bun === 'undefined' &&
|
|
76
77
|
process.env.NODE_ENV === 'development' &&
|
|
77
78
|
this.dependencies.canLoadSourceModuleFromHost(filePath)
|
|
78
79
|
? this.dependencies.getHostModuleLoader()
|
|
@@ -124,12 +125,8 @@ export class PageModuleImportService {
|
|
|
124
125
|
fileHash,
|
|
125
126
|
});
|
|
126
127
|
}
|
|
127
|
-
|
|
128
|
-
const { filePath,
|
|
129
|
-
const { rootDir, outdir, splitting, externalPackages, transpileErrorMessage = (details) => `Error transpiling page module: ${details}`, noOutputMessage = (targetFilePath) => `No transpiled output generated for page module: ${targetFilePath}`, } = options;
|
|
130
|
-
const outputFileName = createRuntimeBuildOutputFileName(resolvePageModuleOutputFileName({ filePath, fileHash }), this.developmentImportGeneration);
|
|
131
|
-
const outputNamingTemplate = outputFileName.replace(/\.mjs$/u, '.[ext]');
|
|
132
|
-
const preferredOutputPath = path.join(outdir, outputFileName);
|
|
128
|
+
createRouteModuleBuildOptions(options, outputNamingTemplate) {
|
|
129
|
+
const { filePath, rootDir, outdir, splitting, externalPackages } = options;
|
|
133
130
|
const buildOptions = this.appConfig
|
|
134
131
|
? createServerBuildRequest(this.appConfig, {
|
|
135
132
|
profile: 'route-module',
|
|
@@ -155,10 +152,17 @@ export class PageModuleImportService {
|
|
|
155
152
|
root: rootDir,
|
|
156
153
|
entrypoints: [filePath],
|
|
157
154
|
};
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
return {
|
|
156
|
+
buildOptions,
|
|
160
157
|
rootDir: buildOptions.root ?? rootDir,
|
|
161
158
|
outdir: buildOptions.outdir ?? outdir,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
createRouteModuleCacheBuildOptions(options, buildOptions, resolvedRootDir, resolvedOutdir, fileHash) {
|
|
162
|
+
return {
|
|
163
|
+
...options,
|
|
164
|
+
rootDir: resolvedRootDir,
|
|
165
|
+
outdir: resolvedOutdir,
|
|
162
166
|
splitting: buildOptions.splitting,
|
|
163
167
|
externalPackages: buildOptions.externalPackages,
|
|
164
168
|
jsx: buildOptions.jsx,
|
|
@@ -166,32 +170,36 @@ export class PageModuleImportService {
|
|
|
166
170
|
sourceTransforms: buildOptions.sourceTransforms,
|
|
167
171
|
fileHash,
|
|
168
172
|
};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return loadedModule;
|
|
173
|
+
}
|
|
174
|
+
async tryLoadCachedRouteModuleBuild(cacheBuildOptions, outdir) {
|
|
175
|
+
const cachedBuild = this.getRouteModuleBuildCache(outdir).lookup(cacheBuildOptions);
|
|
176
|
+
if (!cachedBuild) {
|
|
177
|
+
return undefined;
|
|
175
178
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
const loadedModule = (await import(/* @vite-ignore */ pathToFileURL(cachedBuild.outputPath).href));
|
|
180
|
+
recordPageModuleLoad('disk-cache-hit');
|
|
181
|
+
return loadedModule;
|
|
182
|
+
}
|
|
183
|
+
async tryLoadPagesUnifiedGraphModule(filePath) {
|
|
184
|
+
if (!shouldBuildPagesUnifiedGraph() || !this.appConfig || !isPagesUnifiedGraphPage(filePath, this.appConfig)) {
|
|
185
|
+
return undefined;
|
|
182
186
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (!buildResult.success) {
|
|
187
|
-
const details = buildResult.logs.map((log) => log.message).join(' | ');
|
|
188
|
-
throw new Error(transpileErrorMessage(details));
|
|
187
|
+
const graphModule = await importPagesUnifiedGraphModule(this.appConfig, filePath);
|
|
188
|
+
if (graphModule === undefined) {
|
|
189
|
+
return undefined;
|
|
189
190
|
}
|
|
191
|
+
recordPageModuleLoad('unified-graph');
|
|
192
|
+
return graphModule;
|
|
193
|
+
}
|
|
194
|
+
resolveCompiledRouteModuleOutput(buildResult, preferredOutputPath, filePath, noOutputMessage) {
|
|
190
195
|
const compiledOutput = buildResult.outputs.find((output) => output.path === preferredOutputPath)?.path ??
|
|
191
196
|
buildResult.outputs.find((output) => /\.(?:[cm]?js)$/u.test(output.path))?.path;
|
|
192
197
|
if (!compiledOutput) {
|
|
193
198
|
throw new Error(noOutputMessage(filePath));
|
|
194
199
|
}
|
|
200
|
+
return compiledOutput;
|
|
201
|
+
}
|
|
202
|
+
async importCompiledRouteModule(compiledOutput, filePath, fileHash, rootDir, buildResult, importCacheKey, cacheBuildOptions, outdir) {
|
|
195
203
|
const dependencyModulePaths = resolveRouteModuleDependencyPaths(buildResult, filePath, rootDir);
|
|
196
204
|
const dependencyHashes = this.dependencyHasher.createDependencyHashes(dependencyModulePaths);
|
|
197
205
|
dependencyHashes[path.normalize(filePath)] = fileHash;
|
|
@@ -201,7 +209,7 @@ export class PageModuleImportService {
|
|
|
201
209
|
cacheEntry.dependencyHashes = dependencyHashes;
|
|
202
210
|
}
|
|
203
211
|
}
|
|
204
|
-
|
|
212
|
+
this.getRouteModuleBuildCache(outdir).recordBuild({
|
|
205
213
|
...cacheBuildOptions,
|
|
206
214
|
outputPath: compiledOutput,
|
|
207
215
|
dependencyModulePaths,
|
|
@@ -212,6 +220,32 @@ export class PageModuleImportService {
|
|
|
212
220
|
}
|
|
213
221
|
return (await import(/* @vite-ignore */ compiledOutputUrl.href));
|
|
214
222
|
}
|
|
223
|
+
async loadModule(options) {
|
|
224
|
+
const { filePath, fileHash, importCacheKey } = options;
|
|
225
|
+
const { outdir, transpileErrorMessage = (details) => `Error transpiling page module: ${details}`, noOutputMessage = (targetFilePath) => `No transpiled output generated for page module: ${targetFilePath}`, } = options;
|
|
226
|
+
const outputFileName = createRuntimeBuildOutputFileName(resolvePageModuleOutputFileName({ filePath, fileHash }), this.developmentImportGeneration);
|
|
227
|
+
const outputNamingTemplate = outputFileName.replace(/\.mjs$/u, '.[ext]');
|
|
228
|
+
const preferredOutputPath = path.join(outdir, outputFileName);
|
|
229
|
+
const { buildOptions, rootDir: resolvedRootDir, outdir: resolvedOutdir, } = this.createRouteModuleBuildOptions(options, outputNamingTemplate);
|
|
230
|
+
const cacheBuildOptions = this.createRouteModuleCacheBuildOptions(options, buildOptions, resolvedRootDir, resolvedOutdir, fileHash);
|
|
231
|
+
const cachedModule = await this.tryLoadCachedRouteModuleBuild(cacheBuildOptions, resolvedOutdir);
|
|
232
|
+
if (cachedModule !== undefined) {
|
|
233
|
+
return cachedModule;
|
|
234
|
+
}
|
|
235
|
+
const unifiedGraphModule = await this.tryLoadPagesUnifiedGraphModule(filePath);
|
|
236
|
+
if (unifiedGraphModule !== undefined) {
|
|
237
|
+
return unifiedGraphModule;
|
|
238
|
+
}
|
|
239
|
+
recordPageModuleBuildInvocation();
|
|
240
|
+
const buildResult = await this.dependencies.buildModule(buildOptions, options.buildExecutor);
|
|
241
|
+
recordPageModuleLoad('cold-build', buildResult.outputs.length);
|
|
242
|
+
if (!buildResult.success) {
|
|
243
|
+
const details = buildResult.logs.map((log) => log.message).join(' | ');
|
|
244
|
+
throw new Error(transpileErrorMessage(details));
|
|
245
|
+
}
|
|
246
|
+
const compiledOutput = this.resolveCompiledRouteModuleOutput(buildResult, preferredOutputPath, filePath, noOutputMessage);
|
|
247
|
+
return await this.importCompiledRouteModule(compiledOutput, filePath, fileHash, resolvedRootDir, buildResult, importCacheKey, cacheBuildOptions, resolvedOutdir);
|
|
248
|
+
}
|
|
215
249
|
getRouteModuleBuildCache(outdir) {
|
|
216
250
|
return getSharedRouteModuleBuildCache(outdir, this.appConfig);
|
|
217
251
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import { fileSystem } from '@ecopages/file-system';
|
|
3
4
|
/**
|
|
@@ -129,10 +130,21 @@ export function resolveRouteModuleDependencyPaths(buildResult, entrypointPath, r
|
|
|
129
130
|
const normalizedEntrypoint = path.isAbsolute(entrypointPath)
|
|
130
131
|
? path.normalize(entrypointPath)
|
|
131
132
|
: path.normalize(path.resolve(rootDir, entrypointPath));
|
|
133
|
+
let realEntrypoint;
|
|
134
|
+
try {
|
|
135
|
+
realEntrypoint = fileSystem.exists(normalizedEntrypoint) ? fs.realpathSync(normalizedEntrypoint) : undefined;
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// fall back
|
|
139
|
+
}
|
|
132
140
|
const graphEntrypoints = buildResult.dependencyGraph?.entrypoints ?? {};
|
|
133
141
|
const dependencyPaths = graphEntrypoints[normalizedEntrypoint] ??
|
|
142
|
+
(realEntrypoint ? graphEntrypoints[realEntrypoint] : undefined) ??
|
|
134
143
|
graphEntrypoints[entrypointPath] ??
|
|
135
|
-
Object.entries(graphEntrypoints).find(([candidate]) =>
|
|
144
|
+
Object.entries(graphEntrypoints).find(([candidate]) => {
|
|
145
|
+
const norm = path.normalize(candidate);
|
|
146
|
+
return norm === normalizedEntrypoint || (realEntrypoint !== undefined && norm === realEntrypoint);
|
|
147
|
+
})?.[1];
|
|
136
148
|
if (!dependencyPaths || dependencyPaths.length === 0) {
|
|
137
149
|
return [normalizedEntrypoint];
|
|
138
150
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EcoPagesAppConfig } from '../../types/internal-types.js';
|
|
2
|
+
import type { ViewLoader } from '../../types/public-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a view loader that imports through the app server-module transpiler.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Use this for `app.static()` and HTML error-page registrations instead of
|
|
8
|
+
* raw dynamic `import()` so Node applies Ecopages build transforms (component identity).
|
|
9
|
+
*/
|
|
10
|
+
export declare function createViewModuleLoader<P = Record<string, unknown>>(appConfig: EcoPagesAppConfig, modulePath: string | URL): ViewLoader<P>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
4
|
+
import { resolveInternalExecutionDir } from '../../utils/resolve-work-dir.js';
|
|
5
|
+
import { getAppServerModuleTranspiler } from './app-server-module-transpiler.service.js';
|
|
6
|
+
function resolveViewModuleOnDisk(filePath, templatesExt) {
|
|
7
|
+
if (fileSystem.exists(filePath)) {
|
|
8
|
+
return filePath;
|
|
9
|
+
}
|
|
10
|
+
for (const extension of templatesExt) {
|
|
11
|
+
const withExtension = `${filePath}${extension}`;
|
|
12
|
+
if (fileSystem.exists(withExtension)) {
|
|
13
|
+
return withExtension;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const pathWithoutTerminalExtension = filePath.replace(/\.[^./]+$/, '');
|
|
17
|
+
for (const extension of templatesExt) {
|
|
18
|
+
const candidate = `${pathWithoutTerminalExtension}${extension}`;
|
|
19
|
+
if (fileSystem.exists(candidate)) {
|
|
20
|
+
return candidate;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return filePath;
|
|
24
|
+
}
|
|
25
|
+
function resolveViewModuleFilePath(appConfig, modulePath) {
|
|
26
|
+
const filePath = modulePath instanceof URL ? fileURLToPath(modulePath) : modulePath;
|
|
27
|
+
const rootedPath = path.isAbsolute(filePath)
|
|
28
|
+
? filePath
|
|
29
|
+
: path.join(appConfig.rootDir, filePath.replace(/^\.\//, ''));
|
|
30
|
+
return resolveViewModuleOnDisk(rootedPath, appConfig.templatesExt);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates a view loader that imports through the app server-module transpiler.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* Use this for `app.static()` and HTML error-page registrations instead of
|
|
37
|
+
* raw dynamic `import()` so Node applies Ecopages build transforms (component identity).
|
|
38
|
+
*/
|
|
39
|
+
export function createViewModuleLoader(appConfig, modulePath) {
|
|
40
|
+
const filePath = resolveViewModuleFilePath(appConfig, modulePath);
|
|
41
|
+
return async () => await getAppServerModuleTranspiler(appConfig).importModule({
|
|
42
|
+
filePath,
|
|
43
|
+
outdir: path.join(resolveInternalExecutionDir(appConfig), '.server-modules'),
|
|
44
|
+
externalPackages: true,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -110,6 +110,7 @@ export declare class SchemaValidationService {
|
|
|
110
110
|
* }
|
|
111
111
|
* ```
|
|
112
112
|
*/
|
|
113
|
+
private validateRequestPart;
|
|
113
114
|
validateRequest(source: ValidationSource, schemas: ValidationSchemas): Promise<ValidationResult<ValidatedData>>;
|
|
114
115
|
/**
|
|
115
116
|
* Validates a single value against a Standard Schema.
|
|
@@ -84,45 +84,32 @@ export class SchemaValidationService {
|
|
|
84
84
|
* }
|
|
85
85
|
* ```
|
|
86
86
|
*/
|
|
87
|
+
async validateRequestPart(schema, value, assign, allErrors, shouldValidate) {
|
|
88
|
+
if (!schema || !shouldValidate) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const result = await this.validateWithSchema(schema, value);
|
|
92
|
+
if (!result.success) {
|
|
93
|
+
allErrors.push(...(result.errors || []));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
assign(result.data);
|
|
97
|
+
}
|
|
87
98
|
async validateRequest(source, schemas) {
|
|
88
99
|
const validated = {};
|
|
89
100
|
const allErrors = [];
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
allErrors.push(...(result.errors || []));
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
validated.query = result.data;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (schemas.headers && source.headers) {
|
|
109
|
-
const result = await this.validateWithSchema(schemas.headers, source.headers);
|
|
110
|
-
if (!result.success) {
|
|
111
|
-
allErrors.push(...(result.errors || []));
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
validated.headers = result.data;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (schemas.params && source.params) {
|
|
118
|
-
const result = await this.validateWithSchema(schemas.params, source.params);
|
|
119
|
-
if (!result.success) {
|
|
120
|
-
allErrors.push(...(result.errors || []));
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
validated.params = result.data;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
101
|
+
await this.validateRequestPart(schemas.body, source.body, (data) => {
|
|
102
|
+
validated.body = data;
|
|
103
|
+
}, allErrors, schemas.body !== undefined && source.body !== undefined);
|
|
104
|
+
await this.validateRequestPart(schemas.query, source.query, (data) => {
|
|
105
|
+
validated.query = data;
|
|
106
|
+
}, allErrors, !!schemas.query && !!source.query);
|
|
107
|
+
await this.validateRequestPart(schemas.headers, source.headers, (data) => {
|
|
108
|
+
validated.headers = data;
|
|
109
|
+
}, allErrors, !!schemas.headers && !!source.headers);
|
|
110
|
+
await this.validateRequestPart(schemas.params, source.params, (data) => {
|
|
111
|
+
validated.params = data;
|
|
112
|
+
}, allErrors, !!schemas.params && !!source.params);
|
|
126
113
|
if (allErrors.length > 0) {
|
|
127
114
|
return { success: false, errors: allErrors };
|
|
128
115
|
}
|
|
@@ -11,6 +11,7 @@ It is responsible for:
|
|
|
11
11
|
- enumerating renderable routes
|
|
12
12
|
- rendering static outputs through the normal rendering pipeline
|
|
13
13
|
- respecting route-level constraints such as cache policy and unsupported dynamic server-only paths
|
|
14
|
+
- emitting semantic 404/500 artifacts through the shared error-page renderer
|
|
14
15
|
|
|
15
16
|
## Design Rule
|
|
16
17
|
|
|
@@ -25,6 +26,8 @@ That means it should reuse:
|
|
|
25
26
|
|
|
26
27
|
It should not invent a parallel rendering stack just for build mode.
|
|
27
28
|
|
|
29
|
+
Semantic error pages are excluded from ordinary page enumeration and emitted once by `services/error-pages/semantic-error-page-exporter.ts`, so runtime and static output share source precedence and rendering behavior.
|
|
30
|
+
|
|
28
31
|
## Files
|
|
29
32
|
|
|
30
33
|
| File | Role |
|
|
@@ -58,10 +61,12 @@ Integrations may implement:
|
|
|
58
61
|
- `beforeStaticExport(context)` — runs after unified-graph prebuild, before page rendering
|
|
59
62
|
- `afterStaticExport(context)` — runs in a `finally` block after generation completes
|
|
60
63
|
|
|
61
|
-
When `appConfig.sitemap.enabled` is true, `sitemap.xml` is written **after** `afterStaticExport` so integration-generated URLs can be listed via `extraUrls`.
|
|
64
|
+
When `appConfig.sitemap.enabled` is true, `sitemap.xml` is written **after** `afterStaticExport` so integration-generated URLs can be listed via `extraUrls`. Development (`ecopages dev`) does not emit this file.
|
|
62
65
|
|
|
63
66
|
Sitemap eligibility is decided during successful page export (`activeStaticPathnames` plus `robots.index !== false`, fail-closed on metadata errors). `resolveSitemapLocations` then applies `exclude` and appends `extraUrls`.
|
|
64
67
|
|
|
65
68
|
`StaticExportContext.routes` is the unfiltered static-generation route list. Sitemap filtering is applied separately.
|
|
66
69
|
|
|
67
70
|
See `StaticExportContext` in `static-export-context.ts`.
|
|
71
|
+
|
|
72
|
+
User-facing guide: [Sitemap](https://github.com/ecopages/ecopages/blob/main/apps/docs/src/content/docs/core/sitemap.mdx) in the docs app.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EcoPagesAppConfig } from '../types/internal-types.js';
|
|
2
|
-
import type { SitemapConfig, StaticRoute } from '../types/public-types.js';
|
|
2
|
+
import type { SitemapConfig, StaticRoute, ErrorPageLoaders } from '../types/public-types.js';
|
|
3
3
|
import type { PageRendererResolver, StaticGenerationRendererResolver } from '../route-renderer/route-renderer.js';
|
|
4
4
|
import type { StaticGenerationRoute } from '../router/server/route-registry.js';
|
|
5
5
|
import type { RouteModuleBuildCache } from '../services/module-loading/route-module-build-cache.store.js';
|
|
@@ -92,14 +92,19 @@ export declare class StaticSiteGenerator {
|
|
|
92
92
|
}): Promise<void>;
|
|
93
93
|
private createStaticExportContext;
|
|
94
94
|
private invokeStaticExportHook;
|
|
95
|
+
private resetStaticGenerationState;
|
|
96
|
+
private ensureUnifiedGraphForStaticGeneration;
|
|
97
|
+
private executeStaticGenerationBody;
|
|
98
|
+
private finalizeStaticGenerationRun;
|
|
95
99
|
/**
|
|
96
100
|
* Executes the full static-generation workflow for one app run.
|
|
97
101
|
*/
|
|
98
|
-
run({ router, baseUrl, routeRendererFactory, staticRoutes, force, preserveExportDirectory, }: {
|
|
102
|
+
run({ router, baseUrl, routeRendererFactory, staticRoutes, errorPageLoaders, force, preserveExportDirectory, }: {
|
|
99
103
|
router: StaticGenerationRouteSource;
|
|
100
104
|
baseUrl: string;
|
|
101
105
|
routeRendererFactory?: StaticGenerationRendererFactory;
|
|
102
106
|
staticRoutes?: StaticRoute[];
|
|
107
|
+
errorPageLoaders?: ErrorPageLoaders;
|
|
103
108
|
force?: boolean;
|
|
104
109
|
preserveExportDirectory?: boolean;
|
|
105
110
|
}): Promise<void>;
|