@ecopages/core 0.2.0-beta.6 → 0.2.0-beta.8
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/package.json +26 -2
- package/src/adapters/abstract/application-adapter.d.ts +12 -1
- package/src/adapters/abstract/application-adapter.js +13 -0
- package/src/adapters/abstract/server-adapter.d.ts +3 -0
- package/src/adapters/bun/client-bridge.d.ts +1 -0
- package/src/adapters/bun/client-bridge.js +3 -0
- package/src/adapters/bun/create-app.d.ts +2 -0
- package/src/adapters/bun/create-app.js +28 -9
- package/src/adapters/bun/server-adapter.d.ts +13 -0
- package/src/adapters/bun/server-adapter.js +29 -4
- package/src/adapters/create-app.d.ts +13 -0
- package/src/adapters/create-app.js +10 -1
- package/src/adapters/node/create-app.d.ts +1 -0
- package/src/adapters/node/create-app.js +17 -7
- package/src/adapters/node/node-client-bridge.d.ts +1 -0
- package/src/adapters/node/node-client-bridge.js +3 -0
- package/src/adapters/node/server-adapter.d.ts +10 -13
- package/src/adapters/node/server-adapter.js +37 -82
- package/src/adapters/node/static-content-server.d.ts +1 -0
- package/src/adapters/node/static-content-server.js +3 -0
- package/src/adapters/shared/copy-runtime-public-dir.d.ts +6 -0
- package/src/adapters/shared/copy-runtime-public-dir.js +24 -0
- package/src/adapters/shared/runtime-app-bootstrap.d.ts +0 -1
- package/src/adapters/shared/runtime-app-bootstrap.js +1 -6
- package/src/adapters/shared/server-static-builder.d.ts +4 -7
- package/src/adapters/shared/server-static-builder.js +89 -49
- package/src/adapters/shared/shared-hmr-manager.d.ts +1 -0
- package/src/adapters/shared/shared-hmr-manager.js +15 -2
- package/src/build/README.md +44 -4
- package/src/build/build-adapter.d.ts +8 -2
- package/src/build/build-adapter.js +71 -33
- package/src/build/build-input-fingerprint.d.ts +28 -0
- package/src/build/build-input-fingerprint.js +31 -0
- package/src/build/jsx-ownership-plugins.d.ts +10 -0
- package/src/build/jsx-ownership-plugins.js +17 -0
- package/src/build/pages-unified-graph-build.d.ts +31 -0
- package/src/build/pages-unified-graph-build.js +208 -0
- package/src/build/parallel-build-executor.d.ts +21 -0
- package/src/build/parallel-build-executor.js +52 -0
- package/src/build/rolldown-adapter-helpers.js +47 -3
- package/src/build/rolldown-build-adapter.js +2 -0
- package/src/build/rolldown-build-invocation-metrics.d.ts +12 -0
- package/src/build/rolldown-build-invocation-metrics.js +43 -0
- package/src/build/rolldown-dev-build-adapter.d.ts +2 -2
- package/src/build/rolldown-dev-build-adapter.js +30 -14
- package/src/build/runtime-build-executor.d.ts +7 -13
- package/src/build/runtime-build-executor.js +31 -7
- package/src/build/runtime-build-output-normalizer.d.ts +7 -0
- package/src/build/runtime-build-output-normalizer.js +85 -1
- package/src/build/server-entry-build-cache.d.ts +44 -0
- package/src/build/server-entry-build-cache.js +169 -0
- package/src/hmr/hmr.test.e2e.js +15 -4
- package/src/plugins/integration-plugin.d.ts +19 -8
- package/src/plugins/integration-plugin.js +7 -2
- package/src/plugins/processor.d.ts +5 -0
- package/src/plugins/processor.js +7 -0
- package/src/route-renderer/GRAPH.md +4 -4
- package/src/route-renderer/README.md +6 -5
- package/src/route-renderer/orchestration/foreign-subtree-execution.service.js +1 -3
- package/src/route-renderer/orchestration/integration-renderer.d.ts +10 -2
- package/src/route-renderer/orchestration/integration-renderer.js +32 -12
- package/src/route-renderer/orchestration/render-output.utils.d.ts +2 -0
- package/src/route-renderer/orchestration/render-output.utils.js +4 -0
- package/src/route-renderer/orchestration/route-render-orchestrator.d.ts +2 -2
- package/src/route-renderer/orchestration/route-render-orchestrator.js +17 -16
- package/src/router/client/navigation-coordinator.js +10 -0
- package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.d.ts +1 -0
- package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.js +1 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +4 -2
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +27 -7
- package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.js +17 -3
- package/src/services/assets/browser-bundle.service.d.ts +1 -0
- package/src/services/assets/browser-bundle.service.js +9 -3
- package/src/services/html/html-transformer.service.d.ts +1 -1
- package/src/services/html/html-transformer.service.js +4 -4
- package/src/services/invalidation/development-invalidation.service.d.ts +10 -1
- package/src/services/invalidation/development-invalidation.service.js +29 -0
- package/src/services/module-loading/README.md +49 -0
- package/src/services/module-loading/app-server-module-transpiler.service.js +4 -17
- package/src/services/module-loading/page-module-import.service.d.ts +4 -1
- package/src/services/module-loading/page-module-import.service.js +52 -29
- package/src/services/module-loading/route-module-build-cache-registry.d.ts +24 -0
- package/src/services/module-loading/route-module-build-cache-registry.js +37 -0
- package/src/services/module-loading/route-module-build-cache.d.ts +4 -0
- package/src/services/module-loading/route-module-build-cache.js +38 -0
- package/src/services/module-loading/route-module-build-cache.store.d.ts +57 -0
- package/src/services/module-loading/route-module-build-cache.store.js +203 -0
- package/src/services/module-loading/route-module-build-manifest.d.ts +61 -0
- package/src/services/module-loading/route-module-build-manifest.js +124 -0
- package/src/services/module-loading/route-module-dependency-hasher.d.ts +81 -0
- package/src/services/module-loading/route-module-dependency-hasher.js +121 -0
- package/src/services/module-loading/server-module-transpiler.service.js +1 -1
- package/src/static-site-generator/README.md +33 -0
- package/src/static-site-generator/static-build-invalidation.d.ts +10 -0
- package/src/static-site-generator/static-build-invalidation.js +78 -0
- package/src/static-site-generator/static-export-context.d.ts +22 -0
- package/src/static-site-generator/static-export-context.js +0 -0
- package/src/static-site-generator/static-site-generator.d.ts +17 -20
- package/src/static-site-generator/static-site-generator.js +188 -85
- package/src/types/internal-types.d.ts +8 -0
- package/src/utils/parse-cli-args.d.ts +1 -0
- package/src/utils/parse-cli-args.js +3 -0
- package/src/watchers/project-watcher.d.ts +8 -0
- package/src/watchers/project-watcher.js +32 -12
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileSystem } from "@ecopages/file-system";
|
|
3
|
+
import {
|
|
4
|
+
createBuildInputsFingerprint,
|
|
5
|
+
hashAppConfigFile,
|
|
6
|
+
haveBuildInputsChanged
|
|
7
|
+
} from "../build/build-input-fingerprint.js";
|
|
8
|
+
import {
|
|
9
|
+
ROUTE_MODULE_BUILD_CACHE_FILENAME
|
|
10
|
+
} from "../services/module-loading/route-module-build-manifest.js";
|
|
11
|
+
import {
|
|
12
|
+
getSharedRouteModuleBuildCache,
|
|
13
|
+
getServerModuleBuildCacheOutdir
|
|
14
|
+
} from "../services/module-loading/route-module-build-cache-registry.js";
|
|
15
|
+
import { resolveInternalExecutionDir } from "../utils/resolve-work-dir.js";
|
|
16
|
+
import {
|
|
17
|
+
collectBuildInputContributors,
|
|
18
|
+
createBuildInputsFingerprint as createBuildInputsFingerprint2,
|
|
19
|
+
didBuildInputContributorChange,
|
|
20
|
+
hashAppConfigFile as hashAppConfigFile2,
|
|
21
|
+
haveBuildInputsChanged as haveBuildInputsChanged2
|
|
22
|
+
} from "../build/build-input-fingerprint.js";
|
|
23
|
+
function createRouteModuleStaticRenderCacheContext(appConfig) {
|
|
24
|
+
return {
|
|
25
|
+
configHash: hashAppConfigFile(appConfig),
|
|
26
|
+
buildInputsFingerprint: createBuildInputsFingerprint(appConfig)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function shouldResetStaticExportDirectory(appConfig, force = false) {
|
|
30
|
+
if (force) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (haveBuildInputsChanged(appConfig)) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
const routeModuleCache = getSharedRouteModuleBuildCache(getServerModuleBuildCacheOutdir(appConfig), appConfig);
|
|
37
|
+
return !routeModuleCache.isIncrementalStaticGenerationAvailable(
|
|
38
|
+
createRouteModuleStaticRenderCacheContext(appConfig)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
const PRODUCTION_BUILD_CACHE_OUTDIRS = [".server-modules", ".server-route-modules"];
|
|
42
|
+
function clearProductionBuildCaches(appConfig) {
|
|
43
|
+
if (process.env.NODE_ENV !== "production") {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const executionDir = resolveInternalExecutionDir(appConfig);
|
|
47
|
+
for (const subdir of PRODUCTION_BUILD_CACHE_OUTDIRS) {
|
|
48
|
+
const manifestPath = path.join(executionDir, subdir, ROUTE_MODULE_BUILD_CACHE_FILENAME);
|
|
49
|
+
if (fileSystem.exists(manifestPath)) {
|
|
50
|
+
fileSystem.remove(manifestPath);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const serverEntryCachePath = path.join(executionDir, ".server-entry", ROUTE_MODULE_BUILD_CACHE_FILENAME);
|
|
54
|
+
if (fileSystem.exists(serverEntryCachePath)) {
|
|
55
|
+
fileSystem.remove(serverEntryCachePath);
|
|
56
|
+
}
|
|
57
|
+
const pagesGraphCachePath = path.join(executionDir, ".server-pages-graph", ROUTE_MODULE_BUILD_CACHE_FILENAME);
|
|
58
|
+
if (fileSystem.exists(pagesGraphCachePath)) {
|
|
59
|
+
fileSystem.remove(pagesGraphCachePath);
|
|
60
|
+
}
|
|
61
|
+
for (const cache of appConfig.runtime?.routeModuleBuildCaches?.values() ?? []) {
|
|
62
|
+
cache.resetMemory();
|
|
63
|
+
}
|
|
64
|
+
appConfig.runtime?.routeModuleBuildCaches?.clear();
|
|
65
|
+
if (appConfig.runtime) {
|
|
66
|
+
appConfig.runtime.serverEntryBuildExecutor = void 0;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
clearProductionBuildCaches,
|
|
71
|
+
collectBuildInputContributors,
|
|
72
|
+
createBuildInputsFingerprint2 as createBuildInputsFingerprint,
|
|
73
|
+
createRouteModuleStaticRenderCacheContext,
|
|
74
|
+
didBuildInputContributorChange,
|
|
75
|
+
hashAppConfigFile2 as hashAppConfigFile,
|
|
76
|
+
haveBuildInputsChanged2 as haveBuildInputsChanged,
|
|
77
|
+
shouldResetStaticExportDirectory
|
|
78
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { EcoPagesAppConfig } from '../types/internal-types.js';
|
|
2
|
+
import type { StaticRoute } from '../types/public-types.js';
|
|
3
|
+
import type { StaticGenerationRendererResolver } from '../route-renderer/route-renderer.js';
|
|
4
|
+
import type { StaticGenerationRoute } from '../router/server/route-registry.js';
|
|
5
|
+
type StaticGenerationRouteSource = {
|
|
6
|
+
listStaticGenerationRoutes(input: {
|
|
7
|
+
runtimeOrigin: string;
|
|
8
|
+
}): Promise<readonly StaticGenerationRoute[]>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Context passed to integration plugins during static export lifecycle hooks.
|
|
12
|
+
*/
|
|
13
|
+
export interface StaticExportContext {
|
|
14
|
+
appConfig: EcoPagesAppConfig;
|
|
15
|
+
router: StaticGenerationRouteSource;
|
|
16
|
+
baseUrl: string;
|
|
17
|
+
routeRendererFactory?: StaticGenerationRendererResolver;
|
|
18
|
+
staticRoutes?: StaticRoute[];
|
|
19
|
+
force: boolean;
|
|
20
|
+
preserveExportDirectory: boolean;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
File without changes
|
|
@@ -2,6 +2,7 @@ import type { EcoPagesAppConfig } from '../types/internal-types.js';
|
|
|
2
2
|
import type { StaticRoute } 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
|
+
import type { RouteModuleBuildCache } from '../services/module-loading/route-module-build-cache.store.js';
|
|
5
6
|
type StaticGenerationRouteSource = {
|
|
6
7
|
listStaticGenerationRoutes(input: {
|
|
7
8
|
runtimeOrigin: string;
|
|
@@ -27,26 +28,19 @@ export declare const STATIC_SITE_GENERATOR_ERRORS: {
|
|
|
27
28
|
*/
|
|
28
29
|
export declare class StaticSiteGenerator {
|
|
29
30
|
appConfig: EcoPagesAppConfig;
|
|
31
|
+
private readonly routeModuleBuildCacheOverride?;
|
|
32
|
+
private staticRenderCacheContext;
|
|
33
|
+
private forceFullStaticGeneration;
|
|
30
34
|
/**
|
|
31
35
|
* Creates the static-site generator for one app config.
|
|
32
36
|
*/
|
|
33
|
-
constructor({ appConfig }: {
|
|
37
|
+
constructor({ appConfig, routeModuleBuildCache, }: {
|
|
34
38
|
appConfig: EcoPagesAppConfig;
|
|
39
|
+
routeModuleBuildCache?: RouteModuleBuildCache;
|
|
35
40
|
});
|
|
41
|
+
private getRouteModuleBuildCache;
|
|
36
42
|
private getExportDir;
|
|
37
|
-
/**
|
|
38
|
-
* Logs the standardized warning emitted when a dynamic-cache page is skipped.
|
|
39
|
-
*/
|
|
40
|
-
private warnDynamicPageSkipped;
|
|
41
|
-
/**
|
|
42
|
-
* Determines whether one filesystem-discovered page should be excluded from
|
|
43
|
-
* static generation.
|
|
44
|
-
*/
|
|
45
43
|
private shouldSkipStaticPageFile;
|
|
46
|
-
/**
|
|
47
|
-
* Determines whether one explicit static route view should be excluded from
|
|
48
|
-
* static generation.
|
|
49
|
-
*/
|
|
50
44
|
private shouldSkipStaticView;
|
|
51
45
|
/**
|
|
52
46
|
* Writes the robots.txt file declared by the app config.
|
|
@@ -61,32 +55,35 @@ export declare class StaticSiteGenerator {
|
|
|
61
55
|
*/
|
|
62
56
|
getDirectories(routes: string[]): string[];
|
|
63
57
|
private writeStaticOutput;
|
|
64
|
-
private
|
|
58
|
+
private writeStaticPageArtifact;
|
|
59
|
+
private pruneStaleStaticOutputs;
|
|
65
60
|
private createFilesystemStaticContents;
|
|
66
61
|
/**
|
|
67
62
|
* Generates static output for all filesystem-discovered routes.
|
|
68
63
|
*
|
|
69
64
|
* @remarks
|
|
70
|
-
* Routes
|
|
71
|
-
* issuing a request against the running server origin. Render-strategy routes
|
|
72
|
-
* go through the normal route renderer directly.
|
|
65
|
+
* Routes are rendered through the normal route renderer directly.
|
|
73
66
|
*/
|
|
74
|
-
generateStaticPages(router: StaticGenerationRouteSource, baseUrl: string, routeRendererFactory?: StaticPageRouteRendererFactory): Promise<void>;
|
|
75
|
-
private
|
|
67
|
+
generateStaticPages(router: StaticGenerationRouteSource, baseUrl: string, routeRendererFactory?: StaticPageRouteRendererFactory, skipped?: string[], activeStaticPathnames?: Set<string>, preloadedRoutes?: readonly StaticGenerationRoute[]): Promise<void>;
|
|
68
|
+
private createStaticExportContext;
|
|
69
|
+
private invokeStaticExportHook;
|
|
76
70
|
/**
|
|
77
71
|
* Executes the full static-generation workflow for one app run.
|
|
78
72
|
*/
|
|
79
|
-
run({ router, baseUrl, routeRendererFactory, staticRoutes, }: {
|
|
73
|
+
run({ router, baseUrl, routeRendererFactory, staticRoutes, force, preserveExportDirectory, }: {
|
|
80
74
|
router: StaticGenerationRouteSource;
|
|
81
75
|
baseUrl: string;
|
|
82
76
|
routeRendererFactory?: StaticGenerationRendererFactory;
|
|
83
77
|
staticRoutes?: StaticRoute[];
|
|
78
|
+
force?: boolean;
|
|
79
|
+
preserveExportDirectory?: boolean;
|
|
84
80
|
}): Promise<void>;
|
|
85
81
|
/**
|
|
86
82
|
* Generates static pages from explicit static routes registered via app.static().
|
|
87
83
|
* These routes use eco.page views via loader functions for HMR support.
|
|
88
84
|
*/
|
|
89
85
|
private generateExplicitStaticPages;
|
|
86
|
+
private resolveExplicitViewSourceFile;
|
|
90
87
|
private generateExplicitStaticRoute;
|
|
91
88
|
private planExplicitStaticRoute;
|
|
92
89
|
private createExplicitStaticContents;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { availableParallelism } from "node:os";
|
|
2
3
|
import { appLogger } from "../global/app-logger.js";
|
|
3
4
|
import { fileSystem } from "@ecopages/file-system";
|
|
4
|
-
import { PathUtils } from "../utils/path-utils.module.js";
|
|
5
5
|
import { prepareExplicitStaticRender } from "../adapters/shared/explicit-static-render-preparation.js";
|
|
6
|
+
import { createRouteModuleStaticRenderCacheContext } from "./static-build-invalidation.js";
|
|
7
|
+
import {
|
|
8
|
+
getServerModuleBuildCacheOutdir,
|
|
9
|
+
getSharedRouteModuleBuildCache
|
|
10
|
+
} from "../services/module-loading/route-module-build-cache-registry.js";
|
|
11
|
+
import { ensurePagesUnifiedGraphBuilt, shouldBuildPagesUnifiedGraph } from "../build/pages-unified-graph-build.js";
|
|
6
12
|
const STATIC_SITE_GENERATOR_ERRORS = {
|
|
7
13
|
ROUTE_RENDERER_FACTORY_REQUIRED: "RouteRendererFactory is required for render strategy",
|
|
8
14
|
unsupportedBodyType: (bodyType) => `Unsupported body type for static generation: ${bodyType}`,
|
|
@@ -10,50 +16,51 @@ const STATIC_SITE_GENERATOR_ERRORS = {
|
|
|
10
16
|
noRendererForIntegration: (integrationName) => `No renderer found for integration: ${integrationName}`,
|
|
11
17
|
dynamicRouteRequiresStaticPaths: (routePath) => `Dynamic route ${routePath} requires staticPaths to be defined on the view.`
|
|
12
18
|
};
|
|
19
|
+
function resolveStaticPageConcurrency() {
|
|
20
|
+
return Math.max(1, availableParallelism() - 1);
|
|
21
|
+
}
|
|
22
|
+
async function runWithConcurrency(items, concurrency, worker) {
|
|
23
|
+
if (items.length === 0) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const limit = Math.max(1, concurrency);
|
|
27
|
+
let nextIndex = 0;
|
|
28
|
+
const runners = Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
29
|
+
while (nextIndex < items.length) {
|
|
30
|
+
const currentIndex = nextIndex++;
|
|
31
|
+
await worker(items[currentIndex]);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
await Promise.all(runners);
|
|
35
|
+
}
|
|
13
36
|
class StaticSiteGenerator {
|
|
14
37
|
appConfig;
|
|
38
|
+
routeModuleBuildCacheOverride;
|
|
39
|
+
staticRenderCacheContext;
|
|
40
|
+
forceFullStaticGeneration = false;
|
|
15
41
|
/**
|
|
16
42
|
* Creates the static-site generator for one app config.
|
|
17
43
|
*/
|
|
18
|
-
constructor({
|
|
44
|
+
constructor({
|
|
45
|
+
appConfig,
|
|
46
|
+
routeModuleBuildCache
|
|
47
|
+
}) {
|
|
19
48
|
this.appConfig = appConfig;
|
|
49
|
+
this.routeModuleBuildCacheOverride = routeModuleBuildCache;
|
|
50
|
+
this.staticRenderCacheContext = createRouteModuleStaticRenderCacheContext(appConfig);
|
|
51
|
+
}
|
|
52
|
+
getRouteModuleBuildCache() {
|
|
53
|
+
return this.routeModuleBuildCacheOverride ?? getSharedRouteModuleBuildCache(getServerModuleBuildCacheOutdir(this.appConfig), this.appConfig);
|
|
20
54
|
}
|
|
21
55
|
getExportDir() {
|
|
22
56
|
return this.appConfig.absolutePaths?.distDir ?? path.join(this.appConfig.rootDir, this.appConfig.distDir);
|
|
23
57
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Logs the standardized warning emitted when a dynamic-cache page is skipped.
|
|
26
|
-
*/
|
|
27
|
-
warnDynamicPageSkipped(filePath) {
|
|
28
|
-
appLogger.warn(
|
|
29
|
-
"Pages with cache: 'dynamic' are not supported in static generation or preview, so they will be skipped\n",
|
|
30
|
-
`\u27A4 ${filePath}`
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Determines whether one filesystem-discovered page should be excluded from
|
|
35
|
-
* static generation.
|
|
36
|
-
*/
|
|
37
58
|
async shouldSkipStaticPageFile(filePath, routeRendererFactory) {
|
|
38
|
-
const module = await routeRendererFactory.getPageRenderer(filePath).loadPageModule(filePath
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
if (module.default?.cache !== "dynamic") {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
this.warnDynamicPageSkipped(filePath);
|
|
45
|
-
return true;
|
|
59
|
+
const module = await routeRendererFactory.getPageRenderer(filePath).loadPageModule(filePath);
|
|
60
|
+
return module.default?.cache === "dynamic";
|
|
46
61
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* static generation.
|
|
50
|
-
*/
|
|
51
|
-
shouldSkipStaticView(routePath, view) {
|
|
52
|
-
if (view.cache !== "dynamic") {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
this.warnDynamicPageSkipped(routePath);
|
|
56
|
-
return true;
|
|
62
|
+
shouldSkipStaticView(_routePath, view) {
|
|
63
|
+
return view.cache === "dynamic";
|
|
57
64
|
}
|
|
58
65
|
/**
|
|
59
66
|
* Writes the robots.txt file declared by the app config.
|
|
@@ -100,29 +107,56 @@ class StaticSiteGenerator {
|
|
|
100
107
|
fileSystem.write(outputPath, contents);
|
|
101
108
|
return outputPath;
|
|
102
109
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
110
|
+
async writeStaticPageArtifact(options) {
|
|
111
|
+
options.activeStaticPathnames?.add(options.pathname);
|
|
112
|
+
const directories = options.directories ?? this.getDirectories([options.pathname]);
|
|
113
|
+
const renderedOutputPath = this.getOutputPath(options.pathname, directories);
|
|
114
|
+
const routeModuleBuildCache = this.getRouteModuleBuildCache();
|
|
115
|
+
if (options.reuseRenderedOutput !== false && options.sourceFile && routeModuleBuildCache.canReuseStaticRender({
|
|
116
|
+
sourceFile: options.sourceFile,
|
|
117
|
+
pathname: options.pathname,
|
|
118
|
+
renderedOutputPath,
|
|
119
|
+
context: this.staticRenderCacheContext,
|
|
120
|
+
force: this.forceFullStaticGeneration
|
|
121
|
+
})) {
|
|
122
|
+
appLogger.debug(`Skipped unchanged static page: ${options.debugLabel ?? options.pathname}`);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const contents = await options.createContents();
|
|
126
|
+
if (contents === null) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const outputPath = this.writeStaticOutput(options.pathname, contents, directories);
|
|
130
|
+
if (options.sourceFile) {
|
|
131
|
+
routeModuleBuildCache.recordStaticRender({
|
|
132
|
+
filePath: options.sourceFile,
|
|
133
|
+
pathname: options.pathname,
|
|
134
|
+
sourceHash: fileSystem.hash(options.sourceFile),
|
|
135
|
+
renderedOutputPath: outputPath,
|
|
136
|
+
context: this.staticRenderCacheContext
|
|
137
|
+
});
|
|
138
|
+
}
|
|
107
139
|
}
|
|
108
|
-
|
|
140
|
+
pruneStaleStaticOutputs(activeStaticPathnames) {
|
|
141
|
+
const removedOutputPaths = this.getRouteModuleBuildCache().pruneStaleRenderedOutputs(activeStaticPathnames);
|
|
142
|
+
for (const outputPath of removedOutputPaths) {
|
|
143
|
+
const resolvedOutputPath = path.isAbsolute(outputPath) ? outputPath : path.resolve(outputPath);
|
|
144
|
+
if (fileSystem.exists(resolvedOutputPath)) {
|
|
145
|
+
fileSystem.remove(resolvedOutputPath);
|
|
146
|
+
appLogger.debug(`Removed stale static output: ${resolvedOutputPath}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async createFilesystemStaticContents(route, _baseUrl, routeRendererFactory, skipped) {
|
|
109
151
|
const {
|
|
110
152
|
templateRoute: { filePath },
|
|
111
153
|
params
|
|
112
154
|
} = route;
|
|
113
|
-
if (this.getStaticBuildStrategy(filePath) === "fetch") {
|
|
114
|
-
const fetchUrl = this.resolveStaticFetchUrl(route.requestUrl, baseUrl);
|
|
115
|
-
const response = await fetch(fetchUrl);
|
|
116
|
-
if (!response.ok) {
|
|
117
|
-
appLogger.error(`Failed to fetch ${fetchUrl}. Status: ${response.status}`);
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
return response.text();
|
|
121
|
-
}
|
|
122
155
|
if (!routeRendererFactory) {
|
|
123
156
|
throw new Error(STATIC_SITE_GENERATOR_ERRORS.ROUTE_RENDERER_FACTORY_REQUIRED);
|
|
124
157
|
}
|
|
125
158
|
if (await this.shouldSkipStaticPageFile(filePath, routeRendererFactory)) {
|
|
159
|
+
skipped?.push(filePath);
|
|
126
160
|
return null;
|
|
127
161
|
}
|
|
128
162
|
const renderer = routeRendererFactory.getPageRenderer(filePath);
|
|
@@ -143,42 +177,51 @@ class StaticSiteGenerator {
|
|
|
143
177
|
* Generates static output for all filesystem-discovered routes.
|
|
144
178
|
*
|
|
145
179
|
* @remarks
|
|
146
|
-
* Routes
|
|
147
|
-
* issuing a request against the running server origin. Render-strategy routes
|
|
148
|
-
* go through the normal route renderer directly.
|
|
180
|
+
* Routes are rendered through the normal route renderer directly.
|
|
149
181
|
*/
|
|
150
|
-
async generateStaticPages(router, baseUrl, routeRendererFactory) {
|
|
151
|
-
const routes = await router.listStaticGenerationRoutes({ runtimeOrigin: baseUrl });
|
|
182
|
+
async generateStaticPages(router, baseUrl, routeRendererFactory, skipped, activeStaticPathnames, preloadedRoutes) {
|
|
183
|
+
const routes = preloadedRoutes ?? await router.listStaticGenerationRoutes({ runtimeOrigin: baseUrl });
|
|
152
184
|
appLogger.debug(
|
|
153
185
|
"Static Pages",
|
|
154
186
|
routes.map((route) => route.requestUrl)
|
|
155
187
|
);
|
|
156
188
|
const directories = this.getDirectories(routes.map((route) => route.requestUrl));
|
|
157
|
-
|
|
189
|
+
await runWithConcurrency(routes, resolveStaticPageConcurrency(), async (route) => {
|
|
158
190
|
try {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
191
|
+
await this.writeStaticPageArtifact({
|
|
192
|
+
pathname: route.pathname,
|
|
193
|
+
sourceFile: route.templateRoute.filePath,
|
|
194
|
+
directories,
|
|
195
|
+
debugLabel: route.requestUrl,
|
|
196
|
+
activeStaticPathnames,
|
|
197
|
+
createContents: () => this.createFilesystemStaticContents(route, baseUrl, routeRendererFactory, skipped)
|
|
198
|
+
});
|
|
164
199
|
} catch (error) {
|
|
165
200
|
appLogger.error(
|
|
166
201
|
`Error generating static page for ${route.requestUrl}:`,
|
|
167
202
|
error instanceof Error ? error : String(error)
|
|
168
203
|
);
|
|
169
204
|
}
|
|
170
|
-
}
|
|
205
|
+
});
|
|
171
206
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
207
|
+
createStaticExportContext(input) {
|
|
208
|
+
return {
|
|
209
|
+
appConfig: this.appConfig,
|
|
210
|
+
router: input.router,
|
|
211
|
+
baseUrl: input.baseUrl,
|
|
212
|
+
routeRendererFactory: input.routeRendererFactory,
|
|
213
|
+
staticRoutes: input.staticRoutes,
|
|
214
|
+
force: input.force,
|
|
215
|
+
preserveExportDirectory: input.preserveExportDirectory
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
async invokeStaticExportHook(hook, context) {
|
|
219
|
+
for (const integration of this.appConfig.integrations) {
|
|
220
|
+
const handler = integration[hook];
|
|
221
|
+
if (typeof handler === "function") {
|
|
222
|
+
await handler.call(integration, context);
|
|
223
|
+
}
|
|
175
224
|
}
|
|
176
|
-
const targetUrl = new URL(route);
|
|
177
|
-
const buildUrl = new URL(baseUrl);
|
|
178
|
-
buildUrl.pathname = targetUrl.pathname;
|
|
179
|
-
buildUrl.search = targetUrl.search;
|
|
180
|
-
buildUrl.hash = targetUrl.hash;
|
|
181
|
-
return buildUrl.href;
|
|
182
225
|
}
|
|
183
226
|
/**
|
|
184
227
|
* Executes the full static-generation workflow for one app run.
|
|
@@ -187,19 +230,71 @@ class StaticSiteGenerator {
|
|
|
187
230
|
router,
|
|
188
231
|
baseUrl,
|
|
189
232
|
routeRendererFactory,
|
|
190
|
-
staticRoutes
|
|
233
|
+
staticRoutes,
|
|
234
|
+
force = false,
|
|
235
|
+
preserveExportDirectory = false
|
|
191
236
|
}) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
237
|
+
const skippedDynamicPages = [];
|
|
238
|
+
const activeStaticPathnames = /* @__PURE__ */ new Set();
|
|
239
|
+
this.forceFullStaticGeneration = force;
|
|
240
|
+
this.staticRenderCacheContext = createRouteModuleStaticRenderCacheContext(this.appConfig);
|
|
241
|
+
if (!force) {
|
|
242
|
+
this.getRouteModuleBuildCache().ensureIncrementalStaticGenerationContext(this.staticRenderCacheContext);
|
|
243
|
+
}
|
|
244
|
+
const routes = await router.listStaticGenerationRoutes({ runtimeOrigin: baseUrl });
|
|
245
|
+
if (shouldBuildPagesUnifiedGraph()) {
|
|
246
|
+
await ensurePagesUnifiedGraphBuilt({
|
|
247
|
+
appConfig: this.appConfig,
|
|
248
|
+
entryPaths: routes.map((route) => route.templateRoute.filePath),
|
|
249
|
+
outdir: getServerModuleBuildCacheOutdir(this.appConfig),
|
|
250
|
+
force
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
const staticExportContext = this.createStaticExportContext({
|
|
254
|
+
router,
|
|
255
|
+
baseUrl,
|
|
256
|
+
routeRendererFactory,
|
|
257
|
+
staticRoutes,
|
|
258
|
+
force,
|
|
259
|
+
preserveExportDirectory
|
|
260
|
+
});
|
|
261
|
+
await this.invokeStaticExportHook("beforeStaticExport", staticExportContext);
|
|
262
|
+
try {
|
|
263
|
+
this.generateRobotsTxt();
|
|
264
|
+
await this.generateStaticPages(
|
|
265
|
+
router,
|
|
266
|
+
baseUrl,
|
|
267
|
+
routeRendererFactory,
|
|
268
|
+
skippedDynamicPages,
|
|
269
|
+
activeStaticPathnames,
|
|
270
|
+
routes
|
|
271
|
+
);
|
|
272
|
+
if (staticRoutes && staticRoutes.length > 0 && routeRendererFactory) {
|
|
273
|
+
await this.generateExplicitStaticPages(
|
|
274
|
+
staticRoutes,
|
|
275
|
+
routeRendererFactory,
|
|
276
|
+
skippedDynamicPages,
|
|
277
|
+
activeStaticPathnames
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
if (preserveExportDirectory) {
|
|
281
|
+
this.pruneStaleStaticOutputs(activeStaticPathnames);
|
|
282
|
+
}
|
|
283
|
+
} finally {
|
|
284
|
+
await this.invokeStaticExportHook("afterStaticExport", staticExportContext);
|
|
285
|
+
}
|
|
286
|
+
if (skippedDynamicPages.length > 0) {
|
|
287
|
+
appLogger.debug(
|
|
288
|
+
`Skipped ${skippedDynamicPages.length} page(s) with cache: 'dynamic' (not supported in static generation)`,
|
|
289
|
+
skippedDynamicPages
|
|
290
|
+
);
|
|
196
291
|
}
|
|
197
292
|
}
|
|
198
293
|
/**
|
|
199
294
|
* Generates static pages from explicit static routes registered via app.static().
|
|
200
295
|
* These routes use eco.page views via loader functions for HMR support.
|
|
201
296
|
*/
|
|
202
|
-
async generateExplicitStaticPages(staticRoutes, routeRendererFactory) {
|
|
297
|
+
async generateExplicitStaticPages(staticRoutes, routeRendererFactory, skipped, activeStaticPathnames) {
|
|
203
298
|
appLogger.debug(
|
|
204
299
|
"Generating explicit static routes",
|
|
205
300
|
staticRoutes.map((r) => r.path)
|
|
@@ -209,9 +304,10 @@ class StaticSiteGenerator {
|
|
|
209
304
|
const mod = await route.loader();
|
|
210
305
|
const view = mod.default;
|
|
211
306
|
if (this.shouldSkipStaticView(route.path, view)) {
|
|
307
|
+
skipped?.push(route.path);
|
|
212
308
|
continue;
|
|
213
309
|
}
|
|
214
|
-
await this.generateExplicitStaticRoute(route.path, view, routeRendererFactory);
|
|
310
|
+
await this.generateExplicitStaticRoute(route.path, view, routeRendererFactory, activeStaticPathnames);
|
|
215
311
|
} catch (error) {
|
|
216
312
|
appLogger.error(
|
|
217
313
|
`Error generating explicit static page for ${route.path}:`,
|
|
@@ -220,18 +316,25 @@ class StaticSiteGenerator {
|
|
|
220
316
|
}
|
|
221
317
|
}
|
|
222
318
|
}
|
|
223
|
-
|
|
319
|
+
resolveExplicitViewSourceFile(view) {
|
|
320
|
+
const sourceFile = view.config?.__eco?.file;
|
|
321
|
+
if (!sourceFile) {
|
|
322
|
+
return void 0;
|
|
323
|
+
}
|
|
324
|
+
return path.isAbsolute(sourceFile) ? sourceFile : path.join(this.appConfig.rootDir, sourceFile);
|
|
325
|
+
}
|
|
326
|
+
async generateExplicitStaticRoute(routePath, view, routeRendererFactory, activeStaticPathnames) {
|
|
224
327
|
const { renderer, routeEntries } = await this.planExplicitStaticRoute(routePath, view, routeRendererFactory);
|
|
328
|
+
const sourceFile = this.resolveExplicitViewSourceFile(view);
|
|
225
329
|
for (const { pathname, params } of routeEntries) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
renderer
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
appLogger.debug(`Generated static page: ${pathname} -> ${outputPath}`);
|
|
330
|
+
await this.writeStaticPageArtifact({
|
|
331
|
+
pathname,
|
|
332
|
+
sourceFile,
|
|
333
|
+
debugLabel: pathname,
|
|
334
|
+
activeStaticPathnames,
|
|
335
|
+
createContents: () => this.createExplicitStaticContents(routePath, view, params, routeRendererFactory, renderer)
|
|
336
|
+
});
|
|
337
|
+
appLogger.debug(`Generated static page: ${pathname}`);
|
|
235
338
|
}
|
|
236
339
|
}
|
|
237
340
|
async planExplicitStaticRoute(routePath, view, routeRendererFactory) {
|
|
@@ -13,6 +13,7 @@ import type { SourceModuleLoader } from '../services/module-loading/module-loadi
|
|
|
13
13
|
import type { EntrypointDependencyGraph } from '../services/runtime-state/entrypoint-dependency-graph.service.js';
|
|
14
14
|
import type { ServerInvalidationState } from '../services/runtime-state/server-invalidation-state.service.js';
|
|
15
15
|
import type { ServerModuleTranspiler } from '../services/module-loading/server-module-transpiler.service.js';
|
|
16
|
+
import type { RouteModuleBuildCache } from '../services/module-loading/route-module-build-cache.store.js';
|
|
16
17
|
export interface RobotsPreference {
|
|
17
18
|
/**
|
|
18
19
|
* The user agent
|
|
@@ -150,12 +151,19 @@ export type EcoPagesAppConfig = {
|
|
|
150
151
|
buildAdapter?: BuildAdapter;
|
|
151
152
|
buildManifest?: AppBuildManifest;
|
|
152
153
|
buildExecutor?: BuildExecutor;
|
|
154
|
+
hmrBuildExecutor?: BuildExecutor;
|
|
155
|
+
routeModuleBuildExecutor?: BuildExecutor;
|
|
153
156
|
devGraphService?: DevGraphService;
|
|
154
157
|
entrypointDependencyGraph?: EntrypointDependencyGraph;
|
|
155
158
|
hostModuleLoader?: SourceModuleLoader;
|
|
156
159
|
rendererModuleContext?: unknown;
|
|
157
160
|
serverInvalidationState?: ServerInvalidationState;
|
|
158
161
|
serverModuleTranspiler?: ServerModuleTranspiler;
|
|
162
|
+
routeModuleBuildCaches?: Map<string, RouteModuleBuildCache>;
|
|
163
|
+
/** Serialized server-entry bundler installed by {@link getInstalledServerEntryBuildExecutor}. */
|
|
164
|
+
serverEntryBuildExecutor?: BuildExecutor;
|
|
165
|
+
/** Set after {@link setupAppRuntimePlugins} runs processor/integration setup once per process. */
|
|
166
|
+
runtimeAssetsPrepared?: boolean;
|
|
159
167
|
};
|
|
160
168
|
/**
|
|
161
169
|
* Experimental features.
|
|
@@ -7,6 +7,7 @@ function getEmbeddedRuntimeCommandOptions() {
|
|
|
7
7
|
build: false,
|
|
8
8
|
start: !isDevelopment,
|
|
9
9
|
dev: isDevelopment,
|
|
10
|
+
force: false,
|
|
10
11
|
port: void 0,
|
|
11
12
|
hostname: void 0,
|
|
12
13
|
reactFastRefresh: void 0
|
|
@@ -25,6 +26,7 @@ function parseCliArgs(options = {}) {
|
|
|
25
26
|
dev: { type: "boolean" },
|
|
26
27
|
preview: { type: "boolean" },
|
|
27
28
|
build: { type: "boolean" },
|
|
29
|
+
force: { type: "boolean" },
|
|
28
30
|
port: { type: "string" },
|
|
29
31
|
hostname: { type: "string" },
|
|
30
32
|
"react-fast-refresh": { type: "boolean" }
|
|
@@ -48,6 +50,7 @@ function parseCliArgs(options = {}) {
|
|
|
48
50
|
build: isBuildCommand,
|
|
49
51
|
start: isStartCommand,
|
|
50
52
|
dev: isDevCommand,
|
|
53
|
+
force: !!values.force,
|
|
51
54
|
port: values.port ? Number(values.port) : void 0,
|
|
52
55
|
hostname: values.hostname,
|
|
53
56
|
reactFastRefresh: values["react-fast-refresh"]
|
|
@@ -133,4 +133,12 @@ export declare class ProjectWatcher {
|
|
|
133
133
|
* rapid file changes efficiently.
|
|
134
134
|
*/
|
|
135
135
|
createWatcherSubscription(): Promise<FSWatcher>;
|
|
136
|
+
/**
|
|
137
|
+
* Closes the active filesystem watcher subscription.
|
|
138
|
+
*
|
|
139
|
+
* @remarks
|
|
140
|
+
* Safe to call multiple times. Used when tearing down dev servers in tests
|
|
141
|
+
* and other short-lived Ecopages runtimes.
|
|
142
|
+
*/
|
|
143
|
+
close(): Promise<void>;
|
|
136
144
|
}
|