@ecopages/core 0.2.0-rc.13 → 0.2.0-rc.14

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/core",
3
- "version": "0.2.0-rc.13",
3
+ "version": "0.2.0-rc.14",
4
4
  "description": "Core package for Ecopages",
5
5
  "keywords": [
6
6
  "ecopages",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@clack/prompts": "^1.7.0",
24
- "@ecopages/file-system": "0.2.0-rc.13",
24
+ "@ecopages/file-system": "0.2.0-rc.14",
25
25
  "@ecopages/logger": "^0.2.3",
26
26
  "@ecopages/scripts-injector": "^0.1.5",
27
27
  "@oxc-project/runtime": "0.141.0",
@@ -34,7 +34,7 @@
34
34
  "@standard-schema/utils": "^0.3.0"
35
35
  },
36
36
  "peerDependencies": {
37
- "@ecopages/dev-toolbar": "0.2.0-rc.13"
37
+ "@ecopages/dev-toolbar": "0.2.0-rc.14"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "@ecopages/dev-toolbar": {
@@ -166,14 +166,15 @@ Set `ECOPAGES_ROLLDOWN_BUILD_METRICS=1` to log Rolldown invocation counts during
166
166
 
167
167
  ## Production build caches
168
168
 
169
- Two persisted cache layers accelerate production builds. Both use `.build-cache.json` manifests keyed by dependency hashes and a build-inputs fingerprint.
169
+ Three persisted cache layers accelerate production builds. All use `.build-cache.json` manifests keyed by dependency hashes and build-input fingerprints.
170
170
 
171
171
  | Cache | On-disk location | Module |
172
172
  | -------------------------------------- | --------------------------------------------------- | ---------------------------------------------------- |
173
173
  | Server-entry bundle | `.eco/.server-entry/.build-cache.json` | `cache/server-entry-build-cache.ts` |
174
174
  | Route-module transpile + static render | `<server-outdir>/.server-modules/.build-cache.json` | `route-module-build-cache.store.ts` (module-loading) |
175
+ | Unified pages graph | `.eco/.server-pages-graph/.build-cache.json` | `cache/pages-unified-graph-build.ts` |
175
176
 
176
- `requireBuildRuntime(appConfig).getProfile('server-entry')` serves server-entry bundling. `clearProductionBuildCaches()` wipes both manifest trees, resets in-memory route-module state, and clears `buildRuntime`.
177
+ `requireBuildRuntime(appConfig).getProfile('server-entry')` serves server-entry bundling. `clearProductionBuildCaches()` wipes all three manifest trees, resets in-memory route-module state, and clears `buildRuntime`.
177
178
 
178
179
  Server-entry cache hits require every recorded runtime artifact. Cache misses build the server entry and emitted config in a sibling staging directory; the deploy manifest joins that generation before the directory is published. A failed build therefore leaves the previous server generation intact.
179
180
 
@@ -190,7 +191,7 @@ Production static exports compile all template pages in one Rolldown invocation
190
191
 
191
192
  `StaticSiteGenerator` calls `ensurePagesUnifiedGraphBuilt()` before the export loop. `PageModuleImportService` imports prebuilt chunks via `importPagesUnifiedGraphModule()` and falls back to per-page Rolldown on miss.
192
193
 
193
- A persisted graph is reused only when it matches the core package version, the build inputs and the build key, and every local file reachable from its outputs still exists. `importPagesUnifiedGraphModule()` applies the same check, because pages can be imported before the export loop runs. This is separate from production Page Browser Graph prebuild (`production-page-browser-graph-prebuild.ts`), which warms browser assets in `page-browser-graph-session`.
194
+ A persisted graph is reused only when it matches the core package version, the build inputs and the build key, every local file reachable from its outputs still exists, every recorded source-file hash still matches, and the exact active template route set matches recorded outputs. Manifests without `dependencyHashes` are treated as absent, so a deleted layout or component cannot keep serving its compiled chunk. `importPagesUnifiedGraphModule()` applies the same check, because pages can be imported before the export loop runs. This is separate from production Page Browser Graph prebuild (`production-page-browser-graph-prebuild.ts`), which warms browser assets in `page-browser-graph-session`.
194
195
 
195
196
  `ECOPAGES_ROLLDOWN_BUILD_METRICS=1` enables `rolldown/rolldown-build-invocation-metrics.ts` counters used by bench and parity tests.
196
197
 
@@ -6,6 +6,7 @@
6
6
  * registered on the app config.
7
7
  */
8
8
  import type { EcoPagesAppConfig } from '../../types/internal-types.js';
9
+ import { type RouteModuleDependencyHashes } from '../../services/module-loading/route-module-dependency-hasher.js';
9
10
  export declare const PAGES_UNIFIED_GRAPH_CACHE_DIR = ".server-pages-graph";
10
11
  export declare const PAGES_UNIFIED_GRAPH_CACHE_FILENAME = ".build-cache.json";
11
12
  export interface PagesUnifiedGraphCacheManifest {
@@ -19,6 +20,14 @@ export interface PagesUnifiedGraphCacheManifest {
19
20
  * shared chunks. The graph is reused only while all of them exist.
20
21
  */
21
22
  outputImports: string[];
23
+ /**
24
+ * Content hashes for every trackable source file in the graph.
25
+ *
26
+ * @remarks
27
+ * Compiled chunks can outlive a deleted layout or component. Reuse also
28
+ * requires these hashes so a source edit or deletion rebuilds the graph.
29
+ */
30
+ dependencyHashes: RouteModuleDependencyHashes;
22
31
  }
23
32
  export declare function isPagesUnifiedGraphEnabled(): boolean;
24
33
  /** True when the unified graph should build or serve prebuilt page modules. */
@@ -18,7 +18,7 @@ import { getCorePackageVersion } from './cache-keys.js';
18
18
  import { collectReachableLocalImports } from './output-imports.js';
19
19
  import { resolveInternalExecutionDir } from '../../utils/resolve-work-dir.js';
20
20
  import { getServerModuleBuildCacheOutdir, getSharedRouteModuleBuildCache, } from '../../services/module-loading/route-module-build-cache-registry.js';
21
- import { resolveRouteModuleDependencyPaths } from '../../services/module-loading/route-module-dependency-hasher.js';
21
+ import { RouteModuleDependencyHasher, resolveRouteModuleDependencyPaths, } from '../../services/module-loading/route-module-dependency-hasher.js';
22
22
  export const PAGES_UNIFIED_GRAPH_CACHE_DIR = '.server-pages-graph';
23
23
  export const PAGES_UNIFIED_GRAPH_CACHE_FILENAME = '.build-cache.json';
24
24
  export function isPagesUnifiedGraphEnabled() {
@@ -59,16 +59,22 @@ function createPagesUnifiedGraphBuildKey(appConfig, outdir) {
59
59
  }
60
60
  /**
61
61
  * @remarks
62
- * Manifests without `outputImports` predate import validation and cannot show
63
- * that their chunks still exist, so they are treated as absent.
62
+ * Manifests without `outputImports` or `dependencyHashes` predate those
63
+ * checks, so they cannot prove their chunks and sources are still current.
64
64
  */
65
65
  function readPagesUnifiedGraphManifest(appConfig) {
66
66
  const manifest = readProductionCacheManifest(getPagesUnifiedGraphCachePath(appConfig));
67
- if (!manifest?.outputs || !Array.isArray(manifest.outputImports)) {
67
+ if (!manifest?.outputs ||
68
+ !Array.isArray(manifest.outputImports) ||
69
+ !manifest.dependencyHashes ||
70
+ Object.keys(manifest.dependencyHashes).length === 0) {
68
71
  return undefined;
69
72
  }
70
73
  return manifest;
71
74
  }
75
+ function sourceDependenciesAreCurrent(manifest) {
76
+ return new RouteModuleDependencyHasher().matchesStoredHashes(manifest.dependencyHashes);
77
+ }
72
78
  function writePagesUnifiedGraphManifest(appConfig, manifest) {
73
79
  writeProductionCacheManifest(getPagesUnifiedGraphCachePath(appConfig), manifest);
74
80
  }
@@ -103,16 +109,24 @@ function resolveOutputForEntrypoint(entryPath, entryKey, buildResult) {
103
109
  }
104
110
  /**
105
111
  * Whether `manifest` was written by the current core version, build inputs and graph
106
- * setup, and every file its outputs import still exists.
112
+ * setup, every file its outputs import still exists, and source hashes still match.
107
113
  */
108
114
  function isGraphManifestCurrent(manifest, appConfig, outdir) {
109
115
  return (isProductionCacheManifestCurrent(manifest, getCorePackageVersion()) &&
110
116
  matchesProductionCacheFingerprint(manifest, createBuildInputsFingerprint(appConfig)) &&
111
117
  matchesProductionCacheBuildKey(manifest, createPagesUnifiedGraphBuildKey(appConfig, outdir)) &&
112
- manifest.outputImports.every((filePath) => fileSystem.exists(filePath)));
118
+ manifest.outputImports.every((filePath) => fileSystem.exists(filePath)) &&
119
+ sourceDependenciesAreCurrent(manifest));
113
120
  }
121
+ /**
122
+ * @remarks
123
+ * In addition to graph freshness and chunk existence on disk, the manifest must
124
+ * match the exact count of active template entries so removing or adding a page
125
+ * invalidates the graph.
126
+ */
114
127
  function isManifestValidForEntries(manifest, appConfig, outdir, entryPaths) {
115
128
  return (isGraphManifestCurrent(manifest, appConfig, outdir) &&
129
+ entryPaths.length === Object.keys(manifest.outputs).length &&
116
130
  entryPaths.every((entryPath) => {
117
131
  const outputPath = manifest.outputs[path.resolve(entryPath)];
118
132
  return outputPath ? fileSystem.exists(outputPath) : false;
@@ -142,9 +156,9 @@ export async function ensurePagesUnifiedGraphBuilt(options) {
142
156
  if (!shouldBuildPagesUnifiedGraph()) {
143
157
  return undefined;
144
158
  }
145
- const eligibleEntryPaths = options.entryPaths
159
+ const eligibleEntryPaths = Array.from(new Set(options.entryPaths
146
160
  .map((entryPath) => path.resolve(entryPath))
147
- .filter((entryPath) => isPagesUnifiedGraphPage(entryPath, options.appConfig));
161
+ .filter((entryPath) => isPagesUnifiedGraphPage(entryPath, options.appConfig))));
148
162
  if (eligibleEntryPaths.length === 0) {
149
163
  return undefined;
150
164
  }
@@ -181,6 +195,8 @@ export async function ensurePagesUnifiedGraphBuilt(options) {
181
195
  const outputs = {};
182
196
  const outputImports = new Set();
183
197
  const directImportsCache = new Map();
198
+ const dependencyHasher = new RouteModuleDependencyHasher();
199
+ const dependencyHashes = {};
184
200
  for (const entryPath of eligibleEntryPaths) {
185
201
  const fileHash = fileSystem.hash(entryPath);
186
202
  const entryKey = entryKeysByPath.get(entryPath);
@@ -192,13 +208,16 @@ export async function ensurePagesUnifiedGraphBuilt(options) {
192
208
  const compiledOutputImports = collectReachableLocalImports(compiledOutput, { directImportsCache });
193
209
  for (const importPath of compiledOutputImports)
194
210
  outputImports.add(importPath);
211
+ const dependencyModulePaths = resolveRouteModuleDependencyPaths(buildResult, entryPath, options.appConfig.rootDir);
212
+ Object.assign(dependencyHashes, dependencyHasher.createDependencyHashes(dependencyModulePaths));
213
+ dependencyHashes[path.normalize(entryPath)] = fileHash;
195
214
  routeModuleBuildCache.recordBuild({
196
215
  filePath: entryPath,
197
216
  rootDir: options.appConfig.rootDir,
198
217
  outdir,
199
218
  fileHash,
200
219
  outputPath: compiledOutput,
201
- dependencyModulePaths: resolveRouteModuleDependencyPaths(buildResult, entryPath, options.appConfig.rootDir),
220
+ dependencyModulePaths,
202
221
  externalPackages: true,
203
222
  plugins,
204
223
  outputImports: compiledOutputImports,
@@ -211,6 +230,7 @@ export async function ensurePagesUnifiedGraphBuilt(options) {
211
230
  builtAt: Date.now(),
212
231
  outputs,
213
232
  outputImports: [...outputImports],
233
+ dependencyHashes,
214
234
  };
215
235
  writePagesUnifiedGraphManifest(options.appConfig, manifest);
216
236
  appLogger.debug(`Built pages unified graph for ${eligibleEntryPaths.length} entries`);
@@ -30,8 +30,8 @@ Call site (route scan, renderer, SSG, API)
30
30
  ## Caching layers
31
31
 
32
32
  1. **In-memory promise cache** (`PageModuleImportService.importCache`) — keyed by runtime, file path, content-derived reuse identity (`createRouteModuleReuseIdentity`), and source hash. Cleared by `invalidateDevelopmentGraph()`.
33
- 2. **Disk transpile cache** (`.eco/.server-modules/.build-cache.json`) — production and stable development graphs when dependency hashes match. Manifest field `corePackageVersion` invalidates entries when the framework package changes. An entry is also reused only while every local file its compiled output imports still exists.
34
- 3. **Unified graph manifest** — production static export fast path only; see build layer docs.
33
+ 2. **Disk transpile cache** (`.eco/.server-modules/.build-cache.json`) — production and stable development graphs when dependency hashes match. Manifest field `corePackageVersion` invalidates entries when the framework package changes. An entry is also reused only while every local file its compiled output imports still exists. Rebuilding a route module (`recordBuild()`) drops `renderedOutputs` so incremental static generation re-renders HTML instead of serving stale output after dependency or template edits.
34
+ 3. **Unified graph manifest** — production static export fast path only; see build layer docs. Reuse also requires matching source-file hashes and an exact match against the active template route set, so a deleted or edited layout or component cannot keep serving its compiled chunk.
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
 
@@ -39,16 +39,20 @@ Compiled collection server modules also include the app-owned server invalidatio
39
39
 
40
40
  ## Files
41
41
 
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 |
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
+ | `route-module-build-cache.store.ts` | Persisted route-module transpile and static-render cache store |
47
+ | `route-module-build-cache-registry.ts` | Shared cache instance registry per `(appConfig, outdir)` pair |
48
+ | `route-module-dependency-hasher.ts` | Dependency graph source file hashing and staleness validation |
49
+ | `collection-server-module-build.service.ts` | Compiles collection server modules with invalidation stamping |
50
+ | `app-module-loader.service.ts` | App-facing loader interface |
51
+ | `app-server-module-transpiler.service.ts` | Factory for app-scoped loader + transpiler |
52
+ | `server-module-transpiler.service.ts` | Injectable transpiler boundary for tests and bootstrap |
53
+ | `view-module-loader.ts` | Normalizes string/URL view registrations into transpiler loaders |
54
+ | `host-module-loader-registry.ts` | Process-global host loader fallback for embedded runtimes |
55
+ | `source-module-support.ts` | Extension allowlist for host direct loading |
52
56
 
53
57
  ## Development invalidation
54
58
 
@@ -23,6 +23,11 @@ export declare class RouteModuleBuildCache {
23
23
  lookup(options: PageModuleBuildImportOptions & {
24
24
  fileHash: string;
25
25
  }): RouteModuleBuildCacheLookup | undefined;
26
+ /**
27
+ * @remarks
28
+ * Replaces the transpile entry and drops `renderedOutputs`. Rebuilt modules
29
+ * must re-render HTML; otherwise a layout edit can keep the previous page.
30
+ */
26
31
  recordBuild(options: PageModuleBuildImportOptions & {
27
32
  fileHash: string;
28
33
  outputPath: string;
@@ -52,6 +52,11 @@ export class RouteModuleBuildCache {
52
52
  }
53
53
  return { outputPath, entry };
54
54
  }
55
+ /**
56
+ * @remarks
57
+ * Replaces the transpile entry and drops `renderedOutputs`. Rebuilt modules
58
+ * must re-render HTML; otherwise a layout edit can keep the previous page.
59
+ */
55
60
  recordBuild(options) {
56
61
  if (!shouldPersistRouteModuleBuildCache(options)) {
57
62
  return;
@@ -64,7 +69,6 @@ export class RouteModuleBuildCache {
64
69
  dependencyHashes[cacheFilePath] = options.fileHash;
65
70
  const outputPath = resolveOutputPath(options.outputPath, options.outdir);
66
71
  const manifest = this.loadManifest();
67
- const existingEntry = manifest.entries[cacheFilePath];
68
72
  manifest.corePackageVersion = this.dependencies.getCorePackageVersion();
69
73
  manifest.entries[cacheFilePath] = {
70
74
  sourceHash: options.fileHash,
@@ -79,7 +83,6 @@ export class RouteModuleBuildCache {
79
83
  readFile: (filePath) => this.dependencies.readFile(filePath),
80
84
  },
81
85
  }),
82
- renderedOutputs: existingEntry?.renderedOutputs,
83
86
  };
84
87
  this.persistManifest(manifest);
85
88
  }
@@ -30,13 +30,14 @@ Semantic error pages are excluded from ordinary page enumeration and emitted onc
30
30
 
31
31
  ## Files
32
32
 
33
- | File | Role |
34
- | ------------------------------ | ---------------------------------------------------------------------------- |
35
- | `static-site-generator.ts` | Route enumeration, HTML artifact writes, integration export hooks, sitemap |
36
- | `static-export-context.ts` | Hook context type for `beforeStaticExport` / `afterStaticExport` |
37
- | `sitemap.ts` | Pure sitemap.xml renderer |
38
- | `sitemap-routes.ts` | Sitemap location assembly (`exclude`, `extraUrls`, dedupe) |
39
- | `static-build-invalidation.ts` | `dist/` reset policy, production cache clearing, static-render cache context |
33
+ | File | Role |
34
+ | ------------------------------------------- | ---------------------------------------------------------------------------- |
35
+ | `static-site-generator.ts` | Route enumeration, HTML artifact writes, integration export hooks, sitemap |
36
+ | `static-export-context.ts` | Hook context type for `beforeStaticExport` / `afterStaticExport` |
37
+ | `sitemap.ts` | Pure sitemap.xml renderer |
38
+ | `sitemap-routes.ts` | Sitemap location assembly (`exclude`, `extraUrls`, dedupe) |
39
+ | `static-build-invalidation.ts` | `dist/` reset policy, production cache clearing, static-render cache context |
40
+ | `production-page-browser-graph-prebuild.ts` | Warms and prebuilds browser asset graphs before static export rendering |
40
41
 
41
42
  Build-input fingerprinting (`hashAppConfigFile`, `createBuildInputsFingerprint`) lives in `packages/core/src/build/cache/build-input-fingerprint.ts` and is shared with server-entry and unified-graph caches.
42
43
 
@@ -50,7 +51,7 @@ Build-input fingerprinting (`hashAppConfigFile`, `createBuildInputsFingerprint`)
50
51
 
51
52
  When `dist/` is preserved (`preserveExportDirectory: true`), `StaticSiteGenerator.run()` prunes HTML files no longer in the active route set.
52
53
 
53
- Rendered HTML reuse is tracked in `.eco/.server-modules/.build-cache.json` under each route module's `renderedOutputs`. `canReuseStaticRender()` skips re-rendering when the source file, dependency hashes, and output path are unchanged.
54
+ Rendered HTML reuse is tracked in `.eco/.server-modules/.build-cache.json` under each route module's `renderedOutputs`. `canReuseStaticRender()` skips re-rendering when the source file, dependency hashes, and output path are unchanged. Rebuilding a route module (`recordBuild()`) drops `renderedOutputs` so a layout or component edit cannot keep the previous HTML.
54
55
 
55
56
  `clearProductionBuildCaches()` runs on `force` builds and removes all persisted `.eco` build manifests (route modules, server entry, unified pages graph).
56
57