@ecopages/core 0.3.0 → 0.3.2
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 +2 -2
- package/package.json +3 -3
- package/src/adapters/node/create-app.d.ts +40 -11
- package/src/adapters/node/create-app.js +95 -69
- package/src/adapters/node/dev-session.js +0 -1
- package/src/adapters/node/http-request-bridge.d.ts +4 -0
- package/src/adapters/node/http-request-bridge.js +9 -1
- package/src/adapters/node/runtime-host.d.ts +28 -6
- package/src/adapters/node/runtime-host.js +35 -9
- package/src/adapters/node/server-adapter.d.ts +10 -35
- package/src/adapters/node/server-adapter.js +21 -58
- package/src/adapters/shared/hmr/hmr-manager.d.ts +21 -7
- package/src/adapters/shared/hmr/hmr-manager.js +58 -70
- package/src/adapters/shared/http/api-request-pipeline.d.ts +3 -12
- package/src/adapters/shared/http/api-request-pipeline.js +7 -7
- package/src/adapters/shared/http/dist-file-handler.d.ts +16 -0
- package/src/adapters/shared/http/dist-file-handler.js +172 -0
- package/src/adapters/shared/http/explicit-static-route-matcher.js +2 -1
- package/src/adapters/shared/http/fs-server-response-matcher.js +3 -2
- package/src/adapters/shared/runtime/bind-runtime-server.d.ts +5 -7
- package/src/adapters/shared/runtime/bind-runtime-server.js +8 -12
- package/src/adapters/shared/runtime/copy-runtime-public-dir.js +10 -9
- package/src/adapters/shared/runtime/port-manager.d.ts +8 -11
- package/src/adapters/shared/runtime/port-manager.js +19 -30
- package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +6 -9
- package/src/adapters/shared/runtime/runtime-server-lifecycle.js +2 -5
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +1 -3
- package/src/adapters/shared/runtime/server-request-pipeline.js +1 -5
- package/src/adapters/shared/runtime/server-static-builder.d.ts +3 -3
- package/src/adapters/shared/runtime/server-static-builder.js +3 -3
- package/src/adapters/shared/ws/node-http-websocket-upgrades.js +2 -1
- package/src/adapters/shared/ws/websocket-lifecycle.d.ts +5 -6
- package/src/adapters/shared/ws/websocket-lifecycle.js +1 -2
- package/src/assets/app-browser-client-build.js +1 -2
- package/src/assets/asset-processing-service/browser-runtime-entry-resolution.js +8 -8
- package/src/assets/asset-processing-service/browser-runtime-entry.factory.js +4 -4
- package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +12 -8
- package/src/assets/asset-processing-service/processors/script/file-script.processor.js +36 -16
- package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +11 -6
- package/src/assets/browser-asset-output.d.ts +19 -0
- package/src/assets/browser-asset-output.js +30 -0
- package/src/assets/hashed-browser-asset.d.ts +8 -6
- package/src/assets/hashed-browser-asset.js +8 -6
- package/src/build/build-adapter.d.ts +2 -19
- package/src/build/build-adapter.js +0 -21
- package/src/build/build-graph.js +2 -2
- package/src/build/cache/cache-keys.d.ts +0 -3
- package/src/build/cache/cache-keys.js +0 -14
- package/src/build/cache/pages-unified-graph-build.js +2 -17
- package/src/build/contracts/build-contracts.d.ts +0 -3
- package/src/build/preserve-import-meta-transform.js +2 -2
- package/src/build/rolldown/app-package-declarations.js +3 -3
- package/src/build/rolldown/rolldown-adapter-helpers.js +3 -3
- package/src/build/rolldown/rolldown-build-adapter.d.ts +0 -1
- package/src/build/rolldown/rolldown-build-adapter.js +1 -2
- package/src/build/rolldown/rolldown-build-invocation-metrics.d.ts +1 -2
- package/src/build/rolldown/rolldown-build-invocation-metrics.js +5 -12
- package/src/build/rolldown/server-side-css-shim-plugin.js +3 -3
- package/src/build/runtime/build-queue.d.ts +8 -13
- package/src/build/runtime/build-queue.js +6 -17
- package/src/build/server/app-module-loader.service.d.ts +1 -1
- package/src/build/server/app-module-loader.service.js +0 -2
- package/src/build/server/page-module-import.service.d.ts +2 -3
- package/src/build/server/page-module-import.service.js +3 -4
- package/src/build/server-bundle-deploy-manifest.d.ts +5 -0
- package/src/build/server-bundle-deploy-manifest.js +15 -1
- package/src/build/server-bundle-publication.js +4 -5
- package/src/build.d.ts +2 -2
- package/src/build.js +2 -2
- package/src/config/assembly/app-runtime.d.ts +2 -2
- package/src/config/assembly/app-runtime.js +2 -2
- package/src/config/assembly/finalize-config.d.ts +4 -4
- package/src/config/assembly/finalize-config.js +4 -5
- package/src/config/config-module-files.js +2 -3
- package/src/config/internal-types.d.ts +0 -7
- package/src/config/user-config-types.d.ts +0 -4
- package/src/diagnostics/request-pipeline-metrics.d.ts +3 -3
- package/src/diagnostics/request-pipeline-metrics.js +4 -4
- package/src/diagnostics/startup-trace.js +2 -5
- package/src/errors/http-error.d.ts +2 -2
- package/src/errors/http-error.js +4 -4
- package/src/hmr/client/hmr-runtime.js +16 -7
- package/src/hmr/client/module-update.d.ts +7 -0
- package/src/hmr/client/module-update.js +21 -4
- package/src/hmr/hmr-strategy.d.ts +0 -3
- package/src/hmr/hmr-strategy.js +0 -3
- package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -3
- package/src/hmr/strategies/js-hmr-strategy.js +3 -6
- package/src/html-pages/html-page-module-scripts.js +4 -3
- package/src/html-pages/html-page-renderer.js +2 -3
- package/src/plugins/alias-resolver-cache.d.ts +4 -3
- package/src/plugins/alias-resolver-cache.js +4 -3
- package/src/plugins/component-import-discovery.js +4 -4
- package/src/plugins/eco-component-meta-plugin.d.ts +10 -1
- package/src/plugins/eco-component-meta-plugin.js +66 -10
- package/src/plugins/foreign-jsx-override-plugin.js +4 -3
- package/src/plugins/tsconfig-import-resolver.js +12 -12
- package/src/route-renderer/error-pages/default-error-pages.js +2 -1
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +1 -1
- package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +0 -1
- package/src/route-renderer/orchestration/integration-renderer.d.ts +10 -5
- package/src/route-renderer/orchestration/integration-renderer.js +13 -14
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -23
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +0 -29
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +10 -32
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +2 -2
- package/src/route-renderer/page-loading/page-dependency-bundling.js +5 -5
- package/src/route-renderer/page-loading/page-module-loader.js +1 -1
- package/src/route-renderer/route-renderer.d.ts +2 -5
- package/src/route-renderer/route-renderer.js +2 -4
- package/src/router/client/link-navigation-policy.d.ts +4 -1
- package/src/router/client/link-navigation-policy.js +20 -6
- package/src/router/server/route-registry.d.ts +0 -1
- package/src/router/server/route-registry.js +3 -13
- package/src/router/server/segment-path-matcher.d.ts +12 -0
- package/src/router/server/segment-path-matcher.js +30 -0
- package/src/static-site-generator/static-site-generator.d.ts +0 -5
- package/src/static-site-generator/static-site-generator.js +2 -15
- package/src/types/contracts.d.ts +17 -27
- package/src/types/public-types.d.ts +1 -1
- package/src/utils/format-error-chain.d.ts +9 -0
- package/src/utils/format-error-chain.js +20 -0
- package/src/utils/invariant.d.ts +6 -1
- package/src/utils/invariant.js +7 -2
- package/src/watchers/project-watcher.d.ts +20 -1
- package/src/watchers/project-watcher.js +40 -9
- package/src/watchers/workspace-package-watch-roots.js +5 -5
- package/src/adapters/README.md +0 -58
- package/src/adapters/shared/hmr/hmr-manager.test-helpers.d.ts +0 -28
- package/src/adapters/shared/hmr/hmr-manager.test-helpers.js +0 -53
- package/src/adapters/shared/runtime/runtime-host.d.ts +0 -15
- package/src/adapters/shared/runtime/runtime-host.js +0 -1
- package/src/assets/README.md +0 -35
- package/src/build/README.md +0 -298
- package/src/build/server/README.md +0 -50
- package/src/cache/README.md +0 -5
- package/src/client/README.md +0 -5
- package/src/client/navigation-scripts/navigation-scripts.test.browser.d.ts +0 -1
- package/src/client/navigation-scripts/navigation-scripts.test.browser.js +0 -111
- package/src/client/scroll.test.browser.d.ts +0 -1
- package/src/client/scroll.test.browser.js +0 -31
- package/src/client/view-transitions.test.browser.d.ts +0 -1
- package/src/client/view-transitions.test.browser.js +0 -53
- package/src/config/README.md +0 -58
- package/src/config/constants.d.ts +0 -1
- package/src/config/constants.js +0 -1
- package/src/dev/README.md +0 -61
- package/src/dev/invalidation/README.md +0 -11
- package/src/dev-toolbar/README.md +0 -66
- package/src/diagnostics/README.md +0 -11
- package/src/eco/README.md +0 -776
- package/src/errors/README.md +0 -5
- package/src/global/README.md +0 -5
- package/src/hmr/README.md +0 -64
- package/src/hmr/client/build-error-overlay.test.browser.d.ts +0 -1
- package/src/hmr/client/build-error-overlay.test.browser.js +0 -48
- package/src/hmr/client/hmr-runtime.test.browser.d.ts +0 -1
- package/src/hmr/client/hmr-runtime.test.browser.js +0 -32
- package/src/hmr/entrypoint-dependency-graph.d.ts +0 -12
- package/src/hmr/entrypoint-dependency-graph.js +0 -27
- package/src/hmr/hmr-file-change-prep.d.ts +0 -9
- package/src/hmr/hmr-file-change-prep.js +0 -11
- package/src/html/README.md +0 -15
- package/src/html-pages/README.md +0 -104
- package/src/islands/README.md +0 -44
- package/src/page-cache/README.md +0 -17
- package/src/plugins/README.md +0 -53
- package/src/route-renderer/GRAPH.md +0 -142
- package/src/route-renderer/README.md +0 -160
- package/src/route-renderer/error-pages/README.md +0 -11
- package/src/route-renderer/orchestration/custom-element-scripts/README.md +0 -15
- package/src/route-renderer/orchestration/integration-renderer.test-fixtures.d.ts +0 -39
- package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +0 -94
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.d.ts +0 -35
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.js +0 -69
- package/src/router/README.md +0 -160
- package/src/router/client/link-intent.test.browser.d.ts +0 -1
- package/src/router/client/link-intent.test.browser.js +0 -33
- package/src/router/client/link-navigation-policy.test.browser.d.ts +0 -1
- package/src/router/client/link-navigation-policy.test.browser.js +0 -142
- package/src/router/client/navigation-commit.test.browser.d.ts +0 -1
- package/src/router/client/navigation-commit.test.browser.js +0 -116
- package/src/router/client/navigation-document.test.browser.d.ts +0 -1
- package/src/router/client/navigation-document.test.browser.js +0 -77
- package/src/router/client/navigation-head.test.browser.d.ts +0 -1
- package/src/router/client/navigation-head.test.browser.js +0 -101
- package/src/router/client/navigation-lifecycle.test.browser.d.ts +0 -1
- package/src/router/client/navigation-lifecycle.test.browser.js +0 -97
- package/src/router/client/navigation-view-transition.test.browser.d.ts +0 -1
- package/src/router/client/navigation-view-transition.test.browser.js +0 -189
- package/src/router/client/staged-stylesheets.test-fixtures.d.ts +0 -18
- package/src/router/client/staged-stylesheets.test-fixtures.js +0 -31
- package/src/static-site-generator/README.md +0 -67
- package/src/static-site-generator/static-site-generator.test-utils.d.ts +0 -2
- package/src/static-site-generator/static-site-generator.test-utils.js +0 -41
- package/src/types/README.md +0 -5
- package/src/utils/README.md +0 -7
- package/src/validation/README.md +0 -9
- package/src/watchers/README.md +0 -15
- package/src/watchers/project-watcher.test-helpers.d.ts +0 -60
- package/src/watchers/project-watcher.test-helpers.js +0 -108
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface RuntimeHost<TServer, TServeOptions> {
|
|
2
|
-
start(options: RuntimeHostStartOptions<TServeOptions>): Promise<TServer>;
|
|
3
|
-
stop(server: TServer, options?: {
|
|
4
|
-
force?: boolean;
|
|
5
|
-
}): Promise<void>;
|
|
6
|
-
getOrigin(server: TServer, fallbackServeOptions: TServeOptions): string;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* @remarks
|
|
10
|
-
* Request handling travels inside `serveOptions`, as Bun's `fetch` does, so each
|
|
11
|
-
* runtime host receives only the callbacks it actually calls.
|
|
12
|
-
*/
|
|
13
|
-
export interface RuntimeHostStartOptions<TServeOptions> {
|
|
14
|
-
serveOptions: TServeOptions;
|
|
15
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/assets/README.md
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# Asset Processing
|
|
2
|
-
|
|
3
|
-
**Layer:** Build.
|
|
4
|
-
|
|
5
|
-
This directory owns shared browser-build coordination and processed-asset pipelines.
|
|
6
|
-
|
|
7
|
-
Asset processing reads per-app state from the `AppRuntime` installed during config finalization. Each Integration owns an `AssetProcessingService` and its processed-asset cache. App-wide browser builds use the shared build queue, so static export can combine route assets before SSR requests.
|
|
8
|
-
|
|
9
|
-
## Purpose
|
|
10
|
-
|
|
11
|
-
Asset processing centralizes app-wide browser builds and processor-owned asset transformations.
|
|
12
|
-
|
|
13
|
-
Typical responsibilities include:
|
|
14
|
-
|
|
15
|
-
- asset factories, processors, and the processed-asset cache
|
|
16
|
-
- app-wide browser build coordination and runtime asset declarations
|
|
17
|
-
|
|
18
|
-
## Main Areas
|
|
19
|
-
|
|
20
|
-
- `asset-processing-service/`: the only processed-asset cache, plus typed processors and asset factories. Dependency identity includes attributes, position, and package role; grouped results are reused only while their complete dependency sets match.
|
|
21
|
-
- `app-browser-client-build.ts`: combines static-export renderer plans, route islands, lazy client entries, and HTML Page module scripts into compatible app-wide groups. `app-browser-client-manifest.ts` persists route associations so `ecopages start` can restore outputs before SSR requests. Non-exact route templates receive a parameter-free plan without running route data hooks; later params reuse its output when dependencies match, with request-time fallback for a new graph.
|
|
22
|
-
- `browser-bundle.service.ts`: coordinates browser builds for assets and HMR. Production outputs record their content-addressed paths in `hashed-browser-asset.ts` for `immutable` file caching; development keeps source-relative names so CSS HMR can refresh the same URL.
|
|
23
|
-
|
|
24
|
-
The asset-processing service owns the only processed-asset cache for its five processors. Dependency identity includes attributes, position and package role; file outputs retain their source path so development can verify freshness and invalidate imported inputs. Grouped and ungrouped processing share that cache, and a complete grouped result is reused only while its full dependency set matches. Integration-owned processing calls pass their Integration, whose optional `prepareAssetDependencies()` hook runs before dispatch; calls without an owning Integration pass `undefined`. The file-script processor reads the current HMR manager through the service getter rather than retaining a separately forwarded manager.
|
|
25
|
-
|
|
26
|
-
Grouped script assets share one processing path for file and content entries and use exact entry facade output lookup, so Page names such as `blog` and `blog-post` cannot select one another's hydration output. Static export combines compatible grouped entries from every Integration and the HTML shell scripts into app-wide browser build groups, then attaches each emitted entry to its routes. The ordinary grouped cache reuses outputs only when the complete dependency-key set matches; entries from differently composed Page builds are never mixed. Grouped builds carry each entry's external modules, define values, and plugin instances; conflicting define values fail before bundling.
|
|
27
|
-
In development, each applied change batch is announced on the shared build-input index, and every asset-processing service evicts the cached assets whose source or bundled inputs it touched. Shared layout styles are therefore not rebuilt for every navigated page, and a bundle is never served after one of its imports changed.
|
|
28
|
-
|
|
29
|
-
Browser runtime module assets resolve bare package roots through their ESM import target. For legacy packages without an `exports` map, they prefer `package.json#module` over CJS `main`; CJS resolution is only a compatibility fallback. Generated entries use `export *` for ESM files and explicit named re-exports for CJS files (so bindings such as React `jsx` exist on the vendor). A default binding is added only when the selected entry exposes one. Runtime vendors are package-root contracts: subpath imports need their own vendor declaration or remain in the consuming bundle.
|
|
30
|
-
|
|
31
|
-
Package entry lookup is rooted at the application directory, so a framework-local dependency with the same name cannot shadow the application's installed package. ESM export conditions are evaluated in the same order as the generated vendor import (`node`, `import`, then `default`).
|
|
32
|
-
|
|
33
|
-
## Design Rule
|
|
34
|
-
|
|
35
|
-
Shared asset processing belongs here; framework-specific asset declarations stay with their Integration.
|
package/src/build/README.md
DELETED
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
# Build Layer
|
|
2
|
-
|
|
3
|
-
**Layer:** Build.
|
|
4
|
-
|
|
5
|
-
The build layer is the bundler contract for Ecopages. Rolldown is the bundled adapter.
|
|
6
|
-
|
|
7
|
-
## Contents
|
|
8
|
-
|
|
9
|
-
- [Mental Model](#mental-model)
|
|
10
|
-
- [Files](#files)
|
|
11
|
-
- [Default Flow](#default-flow)
|
|
12
|
-
- [App build manifest](#app-build-manifest)
|
|
13
|
-
- [Plugin Authoring](#plugin-authoring)
|
|
14
|
-
- [Build diagnostics](#build-diagnostics)
|
|
15
|
-
- [BuildOptions Caveats](#buildoptions-caveats)
|
|
16
|
-
- [Dev / watch path](#dev--watch-path)
|
|
17
|
-
- [Metrics](#metrics)
|
|
18
|
-
- [Production builds](#production-builds)
|
|
19
|
-
- [Server bundle deploy layout](#server-bundle-deploy-layout)
|
|
20
|
-
- [Unified pages graph](#unified-pages-graph)
|
|
21
|
-
- [JSX Ownership Plugins](#jsx-ownership-plugins)
|
|
22
|
-
- [Rolldown operator notes](#rolldown-operator-notes)
|
|
23
|
-
- [Testing Strategy](#testing-strategy)
|
|
24
|
-
|
|
25
|
-
## Mental Model
|
|
26
|
-
|
|
27
|
-
Three concentric shapes, plus one build queue and request policy:
|
|
28
|
-
|
|
29
|
-
| Shape | Lives in | Purpose |
|
|
30
|
-
| --------------------------- | ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
31
|
-
| `BuildAdapter` | `build-adapter.ts` | Low-level backend. `RolldownBuildAdapter` is the bundled implementation. |
|
|
32
|
-
| `resolveBuildParallelism()` | `build-parallelism.ts` | One CPU-based concurrency limit shared by queued builds, static export, and the startup trace. |
|
|
33
|
-
| `BuildQueue` | `runtime/build-queue.ts` | The one queue every build of an app goes through: lane concurrency limits, one build per identical in-flight request, request-scope reuse. |
|
|
34
|
-
| `BuildExecutor` | `contracts/build-contracts.ts` | Narrower runtime facade. Only `build` is exposed. `BuildQueue` implements it, on the `build` lane. |
|
|
35
|
-
| `build-request-policy.ts` | `runtime/build-request-policy.ts` | Assembles complete `BuildOptions` before scheduling. Server and browser: plugins, then core's own `transform` plugins, plus JSX ownership. |
|
|
36
|
-
| `build-request-identity.ts` | `runtime/build-request-identity.ts` | Canonical request identity for in-flight and request-scope dedupe: every `BuildOptions` field except `plugins`, plus plugin names and `cacheKey`s. |
|
|
37
|
-
|
|
38
|
-
Plus one translation bridge:
|
|
39
|
-
|
|
40
|
-
- `rolldown/rolldown-plugin-bridge.ts` — converts the runtime-agnostic `EcoBuildPlugin[]` array (the contract integrations and processors register) into one Rolldown plugin. Its resolve and load registrations are checked in `EcoBuildPlugin[]` order and the first non-null result wins, so array position sets priority.
|
|
41
|
-
|
|
42
|
-
Each finalized `EcoPagesAppConfig` owns one `AppRuntime` with its build adapter, manifest, input index, and queue. Build services require that runtime; a service given an unfinalized config fails with `Missing app runtime` instead of inventing fallback state.
|
|
43
|
-
|
|
44
|
-
## Files
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
build/
|
|
48
|
-
build-adapter.ts adapter factories and runtime plugin setup re-exports
|
|
49
|
-
build-parallelism.ts shared build and static-export concurrency limit
|
|
50
|
-
server/ app-scoped source loading and route-module caches
|
|
51
|
-
server-module.ts builds an independent server module through the app request policy
|
|
52
|
-
app-build-manifest-runtime.ts contributor collection at startup
|
|
53
|
-
contracts/ EcoBuildPlugin, BuildOptions, AppBuildManifest
|
|
54
|
-
runtime/ build queue, request policy/identity
|
|
55
|
-
server-bundle-publication.ts staged server/config artifact publication
|
|
56
|
-
rolldown/ bundler adapter, plugin bridge, package externalization
|
|
57
|
-
cache/ fingerprints, build-input reverse index, leftover-manifest cleanup, unified pages graph
|
|
58
|
-
browser/ client runtime rewrites, JSX ownership, Lit worker guard
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
- `contracts/build-manifest.ts` + `app-build-manifest-runtime.ts`: the `AppBuildManifest` sealed once, with its plugins selected by environment, and contributor validation.
|
|
62
|
-
- `build-adapter.ts`: types, factories, and runtime plugin setup helpers.
|
|
63
|
-
- `runtime/build-queue.ts`: the `BuildQueue` and its installation on `AppRuntime.buildQueue`.
|
|
64
|
-
- `runtime/build-request-policy.ts`: server/browser request constructors and plugin collision rules.
|
|
65
|
-
- `runtime/build-request-identity.ts` / `cache/cache-keys.ts`: canonical request identity and shared cache fingerprints.
|
|
66
|
-
- `server/README.md`: app-scoped module imports, route-module caches, dependency tracking, and development invalidation.
|
|
67
|
-
- `contracts/build-types.ts`: the `EcoBuildPlugin` contract used by integrations and processors. `onLoad` receives the loaded `path` and `namespace`, and `loader` is one of `js`, `jsx`, `ts`, `tsx` or `object`.
|
|
68
|
-
- `cache/build-input-dependency-index.ts`: one reverse index from recorded filesystem inputs to Page Browser Graphs, HTML cache entries, browser entrypoints, and server route modules. Plugin loads and module closures travel on each `BuildResult`; cache owners bind those inputs to the result they retain. Processor watch roots also feed the index. The Project Watcher subscribes to that set plus `additionalWatchPaths`. The Rolldown adapter captures the active index before handing hooks to Rolldown, then passes an explicit per-build recorder through the bridge because hook callbacks do not inherit the caller's AsyncLocalStorage context.
|
|
69
|
-
- `contracts.ts`: the stable, dependency-light build contracts. Import `@ecopages/core/build/contracts` when a browser graph needs contract helpers such as the `.server` naming predicate; the broader `@ecopages/core/build` entry also exposes Node-only build tools.
|
|
70
|
-
- `rolldown/rolldown-build-adapter.ts`: the production `BuildAdapter`. Wraps the bundler and exposes a normalized `BuildResult`. With `externalPackages`, compiled packages the app declares stay bare imports, so Integration renderers and server bundles share one instance (one React). Source code is bundled: the app, workspace packages and TypeScript or JSX packages, including Core when it resolves to its TypeScript source. Every other compiled package installed in `node_modules` stays external as a `./` or `../` path from the output directory to the installed file, whichever source package imports it, because a compiled package may find files relative to itself at runtime (a native binding such as `sharp`, a platform package, a sibling file loaded through `createRequire(import.meta.url)`), which fails once it is bundled into another folder. A Rolldown `resolveId` hook resolves these packages through Rolldown with the `node` and `import` conditions and writes the path; a build whose chunk lands in a subdirectory of the output directory and imports such a path fails. The exceptions are the runtime packages that need CommonJS named-export interop (`ws`), which are bundled. Isolated package-manager installs do not expose undeclared packages as bare specifiers to the app, so a path is used instead. Server output therefore needs no app-level framework dependencies and its code holds no absolute paths of the build machine: `dist` keeps working after it moves together with `node_modules`. Named output hashes cover the bytes that are written; the adapter does not rewrite emitted files after `bundle.write()`.
|
|
71
|
-
- `rolldown/rolldown-plugin-bridge.ts`: `EcoBuildPlugin[]` → bundler-plugin translation.
|
|
72
|
-
- `server-bundle-deploy-manifest.ts`: the deploy manifest (`<distDir>/.server/manifest.json`) written beside the server entry, and the lookups that read it: `resolveProductionDistDir` selects the build output `ecopages start` runs (`--dist-dir`, else the only directory, dot-prefixed ones included, one level below the app root that holds a manifest; none or several fail, and nested or symlinked outputs need `--dist-dir`), then the production server entry and config identity lookups take that directory.
|
|
73
|
-
- `server-bundle-publication.ts`: stages the server entry, emitted config, and deploy manifest together, then publishes the complete directory with rollback.
|
|
74
|
-
- `rolldown/entry-module-closures.ts`: records each entry's static and dynamic source module closure in `generateBundle`, including inlined and tree-shaken imports.
|
|
75
|
-
- `build-graph.ts`: shared entry path and output lookup (caller path, real path, and named grouped keys), emitted chunk reachability for in-process cache artifact checks, and dependency input collection. Browser build fingerprints can include package inputs under `node_modules`; local external imports remain leaves, including missing generated server modules.
|
|
76
|
-
- `server-module.ts`: builds one server entry through the app's server request policy and returns its emitted path. The content processor owns collection-specific build identity and caching.
|
|
77
|
-
- `*.test.ts`: regression coverage colocated with each module.
|
|
78
|
-
|
|
79
|
-
## Default Flow
|
|
80
|
-
|
|
81
|
-
`finalizeEcoPagesConfig()` creates one app-owned adapter, manifest, and build queue on `AppRuntime`. When a server adapter initializes, it calls `installBuildQueue(appConfig)` to install a fresh queue on that runtime.
|
|
82
|
-
|
|
83
|
-
## App build manifest
|
|
84
|
-
|
|
85
|
-
`AppBuildManifest` stores a `server` and a `browser` plugin list, already selected by environment, and a separate `browserRuntimeManifest` on `AppRuntime.buildManifest`. Integrations and Processors both expose `plugins(app)`. Each build plugin declares `environments: ['server']`, `['browser']`, or both; omitted environments apply to both. Config loaders are registered with them. The browser list holds the plugins that also apply to the server first, then the browser runtime plugin, then the browser-only plugins; readers take a list as it is.
|
|
86
|
-
|
|
87
|
-
Config finalization rejects duplicate plugin names within an environment and identifies both contributors. The same name can be registered once for server and once for browser. Browser runtime declarations remain data from an Integration's `browserRuntimeManifest`, from which core synthesizes import rewrites.
|
|
88
|
-
|
|
89
|
-
**Sealing flow**
|
|
90
|
-
|
|
91
|
-
1. `sealAppBuildManifest(config)` registers the config loaders, then reads `plugins(app)` of each processor and integration once. It is synchronous and calls no other Processor method.
|
|
92
|
-
2. `createAppBuildManifest(registrations, browserRuntimeManifest)` validates every registration once and stores `{ server, browser, browserRuntimeManifest }`.
|
|
93
|
-
3. `createServerBuildRequest` / `createBrowserBuildRequest` order the request's plugins with `resolveBuildPluginOrder` (`runtime/build-request-policy.ts`): caller plugins that apply to the environment, then the app plugins (the alias resolver, the manifest list, JSX ownership), then core's own `transform` plugins: component identity attribution and, on server requests, the `import.meta` rewrite. Rolldown asks plugins in that order and the first result of a resolve or load hook wins, so the position is the priority.
|
|
94
|
-
|
|
95
|
-
**Rule of thumb**
|
|
96
|
-
|
|
97
|
-
- Shared transforms (MDX loaders, virtual modules, route-module hooks) → `plugins`, with both environments.
|
|
98
|
-
- Client-bundle-only work (vendor aliasing, async production CSS) → `plugins`, with `environments: ['browser']`.
|
|
99
|
-
- Vendor specifier → public URL rewrites → `browserRuntimeManifest` (not a plugin list).
|
|
100
|
-
|
|
101
|
-
`createAppRuntime(config)` calls `sealAppBuildManifest(config)` once and stores the manifest on `AppRuntime.buildManifest`.
|
|
102
|
-
|
|
103
|
-
```
|
|
104
|
-
Caller intent
|
|
105
|
-
→ createServerBuildRequest / createBrowserBuildRequest (plugins assembled once, with core's own transforms last)
|
|
106
|
-
→ BuildQueue.build(options, lane) (lane: build | nested | hmr)
|
|
107
|
-
→ RolldownBuildAdapter
|
|
108
|
-
→ RolldownBuildAdapter resolves Node and browser runtime specifiers during the build
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
The queue uses one-shot Rolldown in both dev and production. A lane runs at most its limit of builds at once and starts the rest in arrival order: `build` serves ordinary server and browser builds (all cores but one), `hmr` serves the development server's browser rebuilds (at most three), and `nested` serves a build that a running build waits for, such as the collection bundle a content plugin requests from `onResolve`. A running build keeps its lane's slot, so a child in the same lane could wait for a slot its parent holds; `nested` builds never wait on each other. A request identical to a queued or running one, by `createBuildRequestIdentity`, shares that build whichever lane it asks for. Inside `withRequestScope`, which wraps each request the server handles, a finished build is also shared with later identical requests of the same scope. A build that rejects is not kept.
|
|
112
|
-
|
|
113
|
-
Runtime code calls `requireBuildQueue(appConfig).build(options, lane)` with a complete `BuildOptions` object from the request-policy helpers. The queue is scheduling-only: it does **not** inject app plugins.
|
|
114
|
-
|
|
115
|
-
The exported `defaultBuildAdapter` is a non-app-aware escape hatch. Runtime code uses `requireAppRuntime(appConfig).buildAdapter`, `requireBuildQueue()`, `createServerBuildRequest()` and `createBrowserBuildRequest()`.
|
|
116
|
-
|
|
117
|
-
Every `BuildOptions` request requires `environment: 'server' | 'browser'`. Environment selects the platform, default target/format, and plugin participation. Browser requests also define `import.meta.env.NODE_ENV` from the Ecopages process mode so browser runtime helpers receive the same mode. An explicit numeric `target` changes language transpilation without changing the environment. `resolveBuildEnvironmentOptions()` holds those defaults, one table per environment; a request names only what differs, as the server entry and the emitted config do with `reportPackagesOutsideRoot`. The lane (`build` | `hmr`) selects scheduling only. `BrowserBundleService` takes an explicit lane; regular browser bundles use `build`, and development HMR rebuilds use `hmr`. Every request retains browser defaults on either lane.
|
|
118
|
-
|
|
119
|
-
Migration: move Integration `browserBuildPlugins` and Processor `buildPlugins` into `plugins` with `environments: ['browser']`. Keep server-only hooks in `plugins` with `environments: ['server']`. Replace the old transpile profile arguments with `'browser'` or `'server'`.
|
|
120
|
-
|
|
121
|
-
## Plugin Authoring
|
|
122
|
-
|
|
123
|
-
`EcoBuildPlugin` is the runtime-agnostic contract integrations and processors register. The shape:
|
|
124
|
-
|
|
125
|
-
- `name: string`
|
|
126
|
-
- `environments?: ('server' | 'browser')[]` (omitted means both)
|
|
127
|
-
- `setup(build: EcoBuildPluginBuilder): void | Promise<void>`
|
|
128
|
-
- `cacheKey?: string` — set by a factory that captures an option which changes its output: the `import.meta` transform sets its runtime directory, the alias resolver its project root and tsconfig path prefixes, the browser runtime plugin its manifest entries and resolve options, the foreign JSX override its import source and extensions, and the MDX loader its compiler options (plugin functions by name). A build request is identified by every `BuildOptions` field except `plugins`, plus each plugin's name, environments and `cacheKey` in order, so two plugins of one name from different options are separate builds only through `cacheKey`. The source of `setup` is not hashed.
|
|
129
|
-
- `bundleGroupKey?: string` — lets entry-specific plugin instances with the same name, key and position relative to other plugins join one app-wide browser build. Every instance is retained so it can contribute its own entry configuration; an entry without that plugin can join too. Use `cacheKey` as well when captured options change the build output.
|
|
130
|
-
|
|
131
|
-
`EcoBuildPluginBuilder` exposes four hooks and build context:
|
|
132
|
-
|
|
133
|
-
- `entrypoints?: Readonly<Record<string, string>>` — the named entry files for the active build. Every plugin builder created for that build receives the same map, so plugins that coordinate work across entries can share build-scoped state. It is absent when the adapter cannot provide entrypoints.
|
|
134
|
-
|
|
135
|
-
- `onResolve({ filter, namespace? }, callback)` — the bundler's `resolveId` mapped to the shared plugin shape.
|
|
136
|
-
- `onLoad({ filter, namespace? }, callback)` — the bundler's `load` mapped the same way. The loaded `path` is recorded as a build input automatically. A `loader` of `js`, `jsx`, `ts` or `tsx` sets the module type, `object` builds a module from `exports`, and without a loader the type follows the file extension. Rewritten contents can return `map` to preserve their original locations.
|
|
137
|
-
- With a `namespace`, a filter matches only ids that start with `<namespace>:`, and is tested against the path after it.
|
|
138
|
-
- `transform({ filter }, callback)` — the bundler's `transform` hook, for source rewrites that must run after `load` and can return a source map. The bridge composes maps from chained transforms in registration order. A rewrite that changes code without a map clears earlier mappings and returns `{ mappings: '' }`, so debug locations do not point at stale source positions; `map: null` declares that the transform does not move code and preserves an incoming Rolldown map.
|
|
139
|
-
|
|
140
|
-
Core's own transforms use MagicString to keep unchanged source locations through JSX pragma, component identity, and `import.meta` edits. `BuildOptions.sourcemap` accepts `none`, `inline`, `external`, `linked`, or `hidden`: `linked` writes a map and a `sourceMappingURL`, `external` and `hidden` write a map without a link, `inline` embeds it, and `none` disables it.
|
|
141
|
-
|
|
142
|
-
- `module(specifier, callback)` — declares a virtual module by name, with bundler-side namespace encoding.
|
|
143
|
-
|
|
144
|
-
App-manifest plugins keep canonical registration order and cannot be silently replaced by caller plugins. Use `excludeAppBuildPlugins` on browser requests to omit app-owned plugins that the request replaces; the environment cannot express that. A core transform whose name is the name of a plugin in the same request throws instead of being dropped. A contributed plugin that registers a `transform` runs before the core transforms, in manifest order: loaders, processors, then integrations.
|
|
145
|
-
|
|
146
|
-
The browser runtime plugin maps each manifest specifier to its public URL in `onResolve` only, for every form a bundler resolves (static import, re-export, side-effect import, `import()`), and marks it external. It does not read or rewrite source. Package subpaths that the manifest does not list are left alone. Two consequences of resolving instead of rewriting: a browser request drops a manifest specifier from its `external` list (Rolldown checks `external` before any plugin, so it would otherwise stay a bare import and skip the public URL), and a tsconfig `paths` alias with the same name as a manifest specifier wins over the public URL, because the alias resolver runs first.
|
|
147
|
-
|
|
148
|
-
## Build diagnostics
|
|
149
|
-
|
|
150
|
-
`BuildResult` is a `BuildSuccess` or a `BuildFailure`, told apart by `success`. A `BuildFailure` has only `logs`, the errors of the build. A `BuildSuccess` always has `outputs`, `warnings`, `loadedInputs`, `loadedInputsByModule`, `dependencyGraph`, `entryOutputs` and `outputGraph`; `assertBuildSucceeded` narrows a result to it. `loadedInputs` lists the absolute filesystem paths recorded by plugin load hooks for that build; `loadedInputsByModule` retains those paths under the module load that recorded them. `dependencyGraph.entrypoints` carries each entry's source-module closure. Cache owners combine the relevant entry closure with only the plugin inputs recorded by modules in that closure, so another entry's source module can still be retained when a plugin explicitly reads it. Both logs and warnings are `BuildLog`s: `message` plus, when Rolldown or the plugin provides them, `code`, `plugin`, `hook`, `id`, `loc`, `frame` and `stack`. Other fields of a thrown error, such as PostCSS's `source`, are not copied. Terminal colour codes are stripped from `message` and `frame`.
|
|
151
|
-
|
|
152
|
-
- Each `BuildOutput` records whether Rolldown gave it a content-addressed name (`contentHashed`: assets, non-entry chunks, and entries named with `[hash]`). `BrowserBundleService` records those paths beside the output files (`.ecopages-hashed-assets`) so runtime file serving and the Node preview apply `immutable` from the build's record instead of a filename guess. `writeToDisk: false` calls Rolldown `generate()` and returns the output content in memory; the dev transform vendor registry uses it to keep vendor bundles process-local.
|
|
153
|
-
|
|
154
|
-
- An unattributed Rolldown `BundleError` becomes one log per underlying error; any other error, including an `AggregateError`, becomes one log (`toBuildLogs` in `rolldown/rolldown-adapter-helpers.ts`).
|
|
155
|
-
- `EcoBuildPlugin` callbacks run inside the single Rolldown plugin the bridge creates, and Rolldown overwrites `plugin` on a thrown error with that Rolldown plugin's name. The bridge therefore catches errors from `setup`, `onResolve`, `onLoad`, `module()` and `transform` callbacks and throws a new error that keeps the `EcoBuildPlugin` name, the thrown value as `cause`, its message, stack, `loc` and `frame`, and its `id` or else the module (the loaded or transformed file, or the importer for a resolve). The thrown value is never changed, so a plugin can share or freeze it. The log conversion restores `plugin` to the `EcoBuildPlugin` name.
|
|
156
|
-
- Warnings are collected through Rolldown's `onLog` input option and still printed by Rolldown's default handler. Rolldown reports them only once a build completes, so a failed build has none.
|
|
157
|
-
- `formatBuildLog()` (`build-log.ts`) is the one text form of a log, `[plugin] file:line:column: message` followed by the frame and stack frames. `assertBuildSucceeded()` throws an error built from it, and `buildOrThrow(appConfig, options, failure, lane)` (`runtime/build-queue.ts`) queues a build and does the same, so no caller joins `log.message` or formats the logs itself.
|
|
158
|
-
|
|
159
|
-
## BuildOptions Caveats
|
|
160
|
-
|
|
161
|
-
Core-owned browser builds reject Node builtins during resolution and imports matching the `.server` naming convention (including extensionless `./db.server`) by the resolved module, so an alias such as a `package.json` `imports` entry or a tsconfig path to `db.server.ts` fails like a relative import. Query and fragment suffixes do not change the naming classification. The error names the resolved module and its importer. This applies to browser scripts from every Integration, including Lit and ecopages-jsx, and to static imports, re-exports, side-effect imports, and dynamic imports that reach resolution. Server builds allow `.server` imports.
|
|
162
|
-
|
|
163
|
-
An Integration can prune server-only imports before resolution. React uses the shared naming predicate while removing server-only Page options, so a middleware-only `.server` import does not fail the browser build. No `server-only` package marker is interpreted by this guard.
|
|
164
|
-
|
|
165
|
-
`BuildOptions` is modeled on the bundler's options shape. Most fields map cleanly. The exception:
|
|
166
|
-
|
|
167
|
-
- `splitting` — when `false` with a single entrypoint, maps to Rolldown `codeSplitting: false` so dynamic imports stay in one file. Multi-entrypoint builds ignore `splitting: false` because Rolldown cannot inline across multiple inputs.
|
|
168
|
-
|
|
169
|
-
## Dev / watch path
|
|
170
|
-
|
|
171
|
-
`installBuildQueue` installs the app's `BuildQueue`. The development server's `hmr-entrypoint` and `hmr-runtime` rebuilds run on the `hmr` lane (limit three). A build that waits on another running build uses the `nested` lane; all other builds use the `build` lane.
|
|
172
|
-
|
|
173
|
-
`ProjectWatcher` deduplicates watch roots, ignores `.eco/` and `dist/`, and coalesces duplicate chokidar events within 150ms.
|
|
174
|
-
|
|
175
|
-
## Metrics
|
|
176
|
-
|
|
177
|
-
Set `ECOPAGES_ROLLDOWN_BUILD_METRICS=1` to log Rolldown invocation counts during dev and production builds. Compare kitchen-sink dev navigation and `static-build-bench` before/after runtime changes.
|
|
178
|
-
|
|
179
|
-
## Production builds
|
|
180
|
-
|
|
181
|
-
Every new process compiles from source. Route-module transpile, the unified pages graph, and static HTML reuse stay in memory for the current process. They are keyed by a hash of the config module and the project files it imports, and by hashes of every local module each entry loads, including modules in shared chunks and in chunks loaded through `import()`. Editing any of them rebuilds in this process. A later `ecopages build` does not read `.build-cache.json` files from an earlier run.
|
|
182
|
-
|
|
183
|
-
The adapter records source closures from Rolldown's module graph and all emitted chunk edges separately. `BuildResult.entryOutputs` is keyed by the path or grouped name the caller passed, plus the bundler's facade path when that spelling differs, so a symlink root or Windows drive casing still finds the chunk. Consumers look entries up through `getBuildEntryOutput` rather than by filename prefix. `outputGraph` supplies static and dynamic output reachability without parsing emitted JavaScript.
|
|
184
|
-
|
|
185
|
-
`requireBuildQueue(appConfig)` queues server-entry bundling on the `build` lane. Every process bundles the server entry from source.
|
|
186
|
-
|
|
187
|
-
Static production export collects every renderer's grouped Page Browser Graph plan, each route's island and lazy client entries, and the HTML Page shell module scripts, then sends compatible browser entries through app-wide `BrowserBundleService` build groups. Entries with matching `bundleOptions` share a group across Integrations and HTML shell scripts and can share chunks when splitting is enabled; entries with different options use separate build groups so an entry's external modules, defines, plugins, plugin exclusions, minification, and splitting settings do not affect unrelated entries. The resulting entry assets are attached to their routes before export rendering; development and non-static runtime requests keep the regular grouped asset path.
|
|
188
|
-
|
|
189
|
-
The deploy manifest (`dist/.server/manifest.json`) names the server entry and the emitted config relative to `dist/.server/`, and the source config relative to the project root, so it holds no absolute path and the bundle can move. It records SHA-256 hashes of the source and emitted config whatever runtime ran the build, because `ecopages start` checks them from the Node CLI. The build writes it under the app's `distDir`; `resolveProductionServerEntry()`, `assertProductionConfigIdentity()` and `resolveEmittedEcoConfigPath()` take that `distDir` as a required argument, and a server entry without a manifest counts as no bundle.
|
|
190
|
-
|
|
191
|
-
The server entry and emitted config are built 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.
|
|
192
|
-
|
|
193
|
-
The route-module registry (`route-module-build-cache-registry.ts`) shares one `RouteModuleBuildCache` per `(app, outdir)` pair on `AppRuntime.routeModuleBuildCaches`. Compiled chunks go to `.eco/.server-modules`.
|
|
194
|
-
|
|
195
|
-
## Server bundle deploy layout
|
|
196
|
-
|
|
197
|
-
An app with API or WebSocket handlers builds a server bundle into `dist/.server/` (`app.mjs`, its chunks, `eco.config.mjs` and `manifest.json`). The bundle imports the compiled packages the app declares as bare specifiers and every other compiled package, such as the dependencies of bundled Core and of workspace processors and integrations, as paths relative to `dist/.server/`. Every server build (the server entry, the emitted config, route modules in `.eco/.server-modules/`, the unified pages graph and collections) rewrites `import.meta.url`, `import.meta.dirname` and `import.meta.filename` of bundled `.ts`, `.tsx`, `.js` and `.jsx` modules to paths relative to the output that point at their source files, so bundled Core reads its own `package.json` and a page that globs `import.meta.dirname` scans `src/pages`. Bundled `.mjs`, `.cjs`, `.mts` and `.cts` modules are not rewritten in this release, because the `import.meta` transform only runs on those four extensions, and `import.meta.resolve()` is not rewritten anywhere and resolves from the output folder. The bundle holds no absolute paths of the build machine, so it runs from any root as long as these entries of the app folder keep their relative positions:
|
|
198
|
-
|
|
199
|
-
| Entry | Why the server needs it |
|
|
200
|
-
| --------------- | ----------------------------------------------------------------------------------------- |
|
|
201
|
-
| `dist/` | Server bundle, emitted config and the static export. |
|
|
202
|
-
| `src/` | The server reads routes from `src/pages` at startup. |
|
|
203
|
-
| `node_modules/` | The install the build ran against, on the server's operating system and CPU architecture. |
|
|
204
|
-
| `package.json` | Declares `"type": "module"` for the `.js` chunks. |
|
|
205
|
-
|
|
206
|
-
Start the server from that folder with `node dist/.server/app.mjs`. A server started from a `.server` folder loads the `eco.config.mjs` beside its entry, even when `eco.config.ts` is present, so the deploy may include the source config. `ecopages start` passes the emitted config explicitly.
|
|
207
|
-
|
|
208
|
-
Relative imports name the package manager's store folders (`node_modules/.pnpm/<name>@<version>_<peers>/...`), so a reinstall works only when it reproduces those names: the same lockfile, package manager version and layout settings (pnpm `node-linker`, `virtual-store-dir`, `virtual-store-dir-max-length`). Copy the install the build used instead, built on the target platform, because native bindings are per platform.
|
|
209
|
-
|
|
210
|
-
Only installs whose package paths contain a `node_modules` folder are kept external. A package manager store whose real path has no `node_modules` segment is bundled as before, and so is a Yarn Plug'n'Play install, whose packages live in `.zip` archives that Node cannot import without the PnP loader; relocated server output does not support Plug'n'Play.
|
|
211
|
-
|
|
212
|
-
`node_modules` must hold the packages themselves. When externalized packages resolve outside the app root, the server entry and emitted config builds of `ecopages build` each log one line per server output file, named by its path (`dist/.server/app.mjs`, `dist/.server/eco.config.mjs`), with that file's complete count, the first five names and a link to the deployment docs. Route-module and other builds, including those the running server makes on the deploy target, stay silent. In a workspace, these packages live in the workspace root `node_modules`, outside the app folder, so build from a standalone install (for example the output of `pnpm deploy`) instead of copying the app folder alone. The same applies to a package manager store linked from outside the project, such as pnpm's global virtual store.
|
|
213
|
-
|
|
214
|
-
## Unified pages graph
|
|
215
|
-
|
|
216
|
-
Production static exports compile all template pages in one Rolldown invocation when `shouldBuildPagesUnifiedGraph()` is true (default in production; opt out with `ECOPAGES_UNIFIED_PAGES_GRAPH=false` or `0`). Pages of an Integration that implements `compilePageModule()`, such as [HTML Pages](../html-pages/README.md), are compiled in-process and stay out of the graph.
|
|
217
|
-
|
|
218
|
-
| Artifact | Location |
|
|
219
|
-
| ------------- | ----------------------------------------------------- |
|
|
220
|
-
| Chunk outputs | `.eco/.server-modules/` (shared with per-route cache) |
|
|
221
|
-
|
|
222
|
-
`StaticSiteGenerator` calls `ensurePagesUnifiedGraphBuilt()` before the export loop. `PageModuleImportService` imports prebuilt chunks via `importPagesUnifiedGraphModule()` and falls back to per-page Rolldown on miss.
|
|
223
|
-
|
|
224
|
-
The graph is reused only in this process, and only when it matches the build key (output directory, config module hash, template extensions and build plugins), 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. `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`.
|
|
225
|
-
|
|
226
|
-
`ECOPAGES_ROLLDOWN_BUILD_METRICS=1` enables `rolldown/rolldown-build-invocation-metrics.ts` counters used by bench and parity tests.
|
|
227
|
-
|
|
228
|
-
`cache/app-config-hash.ts` hashes the config module and the project files it imports. The unified pages graph and the route-module cache key on it.
|
|
229
|
-
|
|
230
|
-
## JSX Ownership Plugins
|
|
231
|
-
|
|
232
|
-
Mixed-integration apps need explicit `@jsxImportSource` handling in two different shapes:
|
|
233
|
-
|
|
234
|
-
| Helper | Use when | Behavior |
|
|
235
|
-
| ------------------------------------ | ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
236
|
-
| `getJsxOwnershipPlugins()` | App-wide server/transpile builds | Each JSX integration extension gets its **own** `jsxImportSource` so native files keep their owning runtime. |
|
|
237
|
-
| `getHostScopedJsxOwnershipPlugins()` | One integration's **client** bundle graph | Foreign `.tsx`/`.jsx` files compile with the **host** integration JSX runtime (for example React bundling `.kita.tsx`). |
|
|
238
|
-
| component identity build plugin | Component identity attribution | Prepends the **owning** integration pragma when injecting `identity` into native files. |
|
|
239
|
-
|
|
240
|
-
`foreign-jsx-override-plugin.ts` is the shared implementation. Prefer the helpers above instead of calling it directly from integrations.
|
|
241
|
-
|
|
242
|
-
## Rolldown operator notes
|
|
243
|
-
|
|
244
|
-
Ecopages bundles with Rolldown for Node server and browser targets.
|
|
245
|
-
|
|
246
|
-
### Plugin hook filters
|
|
247
|
-
|
|
248
|
-
Rolldown evaluates plugin hooks on the Rust side and only calls JavaScript when the filter matches. Hooks without filters run for every module through Rust→JS FFI, causing **3–4× slowdown** with multiple plugins.
|
|
249
|
-
|
|
250
|
-
```typescript
|
|
251
|
-
// BAD — called for every module
|
|
252
|
-
resolveId(source, importer) { /* ... */ }
|
|
253
|
-
|
|
254
|
-
// GOOD — skipped unless the filter matches
|
|
255
|
-
resolveId: {
|
|
256
|
-
filter: { id: /\.tsx?$/ },
|
|
257
|
-
handler(source, importer) { /* ... */ },
|
|
258
|
-
}
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
Rolldown reads hook filters when a plugin is registered, before `buildStart`, so filters cannot come from registrations made during the build. See [rolldown.rs/reference/plugin-hooks](https://rolldown.rs/reference/plugin-hooks).
|
|
262
|
-
|
|
263
|
-
### The bridge plugin
|
|
264
|
-
|
|
265
|
-
Each Rolldown plugin adds FFI overhead per module per hook. `rolldown-plugin-bridge.ts` merges all `EcoBuildPlugin` instances into one Rolldown plugin and routes in JavaScript.
|
|
266
|
-
|
|
267
|
-
Every build creates a new bridge. The bridge runs each plugin's `setup` before it creates the Rolldown plugin, then declares the union of the registered filters as the `resolveId`, `load`, and `transform` hook filters. A handler registered after its plugin's `setup` has finished would miss the filters, so the builder throws. A module that no registration can match never calls into JavaScript. Rolldown tests the filters against ids with `/` separators.
|
|
268
|
-
|
|
269
|
-
| Registration | Hook filter |
|
|
270
|
-
| --------------------------- | ------------------------------------------------------- |
|
|
271
|
-
| `onResolve` / `onLoad` | the registered `filter` |
|
|
272
|
-
| the same with a `namespace` | `^<namespace>:`; the exact `filter` runs in JS |
|
|
273
|
-
| `module(specifier)` | `^<specifier>$` on resolve, its namespace on load |
|
|
274
|
-
| `transform` | the registered `filter`, tested on the id without query |
|
|
275
|
-
|
|
276
|
-
Within the handler, `onResolve` and `onLoad` registrations run in `EcoBuildPlugin[]` order and the first non-null result wins. `transform` runs every matching registration in that same order. A hook with no registrations is not declared. In a kitchen-sink production build, the filters cut JS `resolveId` calls from 7344 to 323 and `load` calls from 4146 to 2826. Source-transform plugins use the `transform` hook, so they no longer admit most source files to `load`. The transform filter is tested with the query and hash stripped, so `/\.tsx$/` still matches `page.tsx?v=1`.
|
|
277
|
-
|
|
278
|
-
### Benchmarks
|
|
279
|
-
|
|
280
|
-
Kitchen-sink benchmarks (`ECOPAGES_BENCH=1 pnpm vitest bench`) show Rolldown winning 15/18 scenarios versus esbuild, with a **1.21×** geometric mean speedup. Largest wins: React page rebuilds (1.56×), production single page (1.49×), Lit (1.52×), Ecopages-JSX (1.47×). Three scenarios regressed (KitaJS postcss, dynamic route, no-op rebuild); route-module disk cache and fingerprinted production caches reduce repeated work on warm paths.
|
|
281
|
-
|
|
282
|
-
### Native MagicString and CSS shim
|
|
283
|
-
|
|
284
|
-
- `experimental.nativeMagicString: true` enables Rust-native string manipulation for faster transforms.
|
|
285
|
-
- Server-side builds use `createServerSideCssShimPlugin()` to turn `.css` imports into empty ESM modules. Skipped for browser builds.
|
|
286
|
-
- Core's own hooks (the browser server-only guard's builtin check and the CSS shim) declare Rolldown hook filters, so Rolldown calls them only for the ids they handle instead of for every module. The adapter closes its Rolldown bundle in a `finally`, so a failed write does not leave it open.
|
|
287
|
-
|
|
288
|
-
## Testing Strategy
|
|
289
|
-
|
|
290
|
-
- `rolldown/rolldown-build-adapter.test.ts` covers the adapter's `build`, `resolve`, and dependency-graph extraction end-to-end.
|
|
291
|
-
- `rolldown/rolldown-plugin-bridge.test.ts` covers the `EcoBuildPlugin[]` → plugin translation in isolation.
|
|
292
|
-
- `build-adapter.test.ts` covers the adapter factories, manifest sealing, and runtime plugin setup.
|
|
293
|
-
- `runtime/build-queue.test.ts` covers lane limits, shared in-flight builds, builds that wait for a child build, and request-scope reuse.
|
|
294
|
-
- `runtime/build-request-policy.test.ts` and `runtime/build-request-identity.test.ts` cover request assembly and dedupe identity.
|
|
295
|
-
- `rolldown/app-package-declarations.test.ts` covers the app `package.json` lookups that decide which packages stay external.
|
|
296
|
-
- `server-bundle-relocation.test.ts` builds an app installed with an isolated (pnpm-style) layout, moves the deploy layout to another root, and serves the home page with `node`.
|
|
297
|
-
|
|
298
|
-
If you change option mapping or plugin-bridge semantics, update the adapter and bridge tests first. If you change the app-owned helper contracts, update `build-adapter.test.ts` first.
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# Module Loading
|
|
2
|
-
|
|
3
|
-
**Layer:** Build.
|
|
4
|
-
|
|
5
|
-
Server-side source loading for framework-owned page modules, includes, and related templates.
|
|
6
|
-
|
|
7
|
-
## Import stack
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
Call site (route scan, renderer, SSG, API)
|
|
11
|
-
└─ AppModuleLoader.importModule() app-module-loader.service.ts
|
|
12
|
-
├─ uses the app root and BuildQueue
|
|
13
|
-
└─ PageModuleImportService.importModule()
|
|
14
|
-
├─ owning Integration's compilePageModule() → compiled in-process, no bundler (HTML Pages)
|
|
15
|
-
├─ in-process module import promise cache → route-module build cache
|
|
16
|
-
├─ unified pages graph → prebuilt chunk import (production only)
|
|
17
|
-
└─ Rolldown per-page build → dynamic import of transpiled output
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Config finalization creates one `AppModuleLoader` for the app runtime. It requires the app config and uses that app's root directory and build queue for every import. Runtime call sites share it through `requireAppRuntime(appConfig).moduleLoader`; callers provide only the module path and request-specific build options.
|
|
21
|
-
|
|
22
|
-
Every server import goes through the Ecopages build pipeline. HTML Pages can still compile in process. Bun and Node both use that pipeline.
|
|
23
|
-
|
|
24
|
-
## Caching layers
|
|
25
|
-
|
|
26
|
-
Source dependency hashes use the adapter's entry module closure and plugin-recorded inputs, including inlined and tree-shaken imports. Each server route module registers those paths in the shared build-input index, including when a cached module is loaded. HTML cache entries include the route's registered closure. Compiled artifact checks use the emitted chunk graph, including static and dynamic chunks and local external generated modules as leaves. The cache store receives this reachable artifact list from its build caller and never reparses emitted JavaScript.
|
|
27
|
-
|
|
28
|
-
1. **In-memory module import promise cache** (`PageModuleImportService.importCache`) — bundled imports are keyed by file path, the canonical identity of the assembled `BuildOptions` request (`createRouteModuleReuseIdentity`), and source hash. The `compilePageModule` branch instead keys by file path, Integration name, and source hash. Route output naming is normalized because it contains only the separately keyed source hash and development generation; the complete `BuildOptions` identity otherwise keeps every field and ordered plugin cache keys. Diagnostic callbacks and the injected executor stay outside it. A production process keeps the entry file's immutable hash after its first load, so later cache hits do not hash it again. The cache is cleared by `invalidateDevelopmentGraph()`, which the watcher batch calls for every edit to a recorded server module closure.
|
|
29
|
-
2. **In-process transpile cache** (`RouteModuleBuildCache`, stored on `AppRuntime.routeModuleBuildCaches`) — production and development graphs in this process when dependency hashes match. The build key uses the same complete `BuildOptions` identity plus a hash of the config module and the project files it imports, so output-affecting options and plugin options defined in config invalidate entries. An entry is also reused only while every local file its compiled output imports still exists. Entries live in memory only; a later process compiles from source. Development invalidation clears them once per `applyDevFileChanges` batch.
|
|
30
|
-
3. **Unified graph** (`AppRuntime.pagesUnifiedGraphManifest`) — production static export fast path only, in this process; 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.
|
|
31
|
-
|
|
32
|
-
Development import URLs use `sourceHash` plus `getDevelopmentGeneration()` in the `?update=` query. The compiled output filename includes that generation on every runtime, because Bun retains a previously imported file when only its query changes. On a finalized config that generation is the app runtime's server invalidation counter. Both advance after `invalidateDevelopmentGraph()` without a process-wide invalidation version in reuse keys.
|
|
33
|
-
|
|
34
|
-
The content processor owns compiled collection server modules and their cache. Output filenames include the development generation (`<collection>-<buildIdentity>-<generation>.mjs`) so Node's ESM loader treats recompiled bundles as new modules after co-located helper files change.
|
|
35
|
-
|
|
36
|
-
## Files
|
|
37
|
-
|
|
38
|
-
| File | Role |
|
|
39
|
-
| -------------------------------------- | ---------------------------------------------------------------- |
|
|
40
|
-
| `page-module-import.service.ts` | Core import/cache/build orchestration |
|
|
41
|
-
| `route-module-build-manifest.ts` | Content-derived reuse identity and in-process cache shape |
|
|
42
|
-
| `route-module-build-cache.store.ts` | In-process route-module transpile cache store |
|
|
43
|
-
| `route-module-build-cache-registry.ts` | Shared cache instance registry per `(appConfig, outdir)` pair |
|
|
44
|
-
| `route-module-dependency-hasher.ts` | Dependency graph source file hashing and staleness validation |
|
|
45
|
-
| `app-module-loader.service.ts` | App-scoped server module loader |
|
|
46
|
-
| `view-module-loader.ts` | Normalizes string/URL view registrations into app-module loaders |
|
|
47
|
-
|
|
48
|
-
## Development invalidation
|
|
49
|
-
|
|
50
|
-
`DevelopmentInvalidationService.invalidateServerModules()` calls `appModuleLoader.invalidateDevelopmentGraph()`, which clears the in-memory import cache, bumps the development generation (`appModuleLoader.getDevelopmentGeneration()`), the one counter of "server source changed", which runtime URLs, compiled output filenames, collection builds and the Lit render worker compare. It also clears the in-process route-module entries: externalized generated modules can change without appearing in a route bundle's dependency graph, so retaining those entries could reload stale server HTML.
|
package/src/cache/README.md
DELETED
package/src/client/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { isNonExecutableHeadScript } from './classification.js';
|
|
3
|
-
import { activateScriptsInOrder } from './activation.js';
|
|
4
|
-
import { collectRerunScripts, toRerunScriptActivation } from './rerun-queue.js';
|
|
5
|
-
import { RERUN_SRC_ATTR } from './registry.js';
|
|
6
|
-
describe('isNonExecutableHeadScript', () => {
|
|
7
|
-
it('treats JSON-LD scripts as non-executable', () => {
|
|
8
|
-
const script = document.createElement('script');
|
|
9
|
-
script.type = 'application/ld+json';
|
|
10
|
-
expect(isNonExecutableHeadScript(script)).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
it('treats untyped scripts as executable', () => {
|
|
13
|
-
const script = document.createElement('script');
|
|
14
|
-
expect(isNonExecutableHeadScript(script)).toBe(false);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
describe('collectRerunScripts and script activations', () => {
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
document.head.replaceChildren();
|
|
20
|
-
document.body.replaceChildren();
|
|
21
|
-
});
|
|
22
|
-
it('replays registered rerun callbacks without duplicating script tags', async () => {
|
|
23
|
-
const callback = vi.fn();
|
|
24
|
-
window.__ECO_PAGES__ = {
|
|
25
|
-
rerunScripts: { 'eco-test': callback },
|
|
26
|
-
};
|
|
27
|
-
try {
|
|
28
|
-
const incoming = new DOMParser().parseFromString('<html><head><script data-eco-rerun data-eco-script-id="eco-test"></script></head><body></body></html>', 'text/html');
|
|
29
|
-
await activateScriptsInOrder(collectRerunScripts(incoming).map(toRerunScriptActivation));
|
|
30
|
-
expect(callback).toHaveBeenCalledOnce();
|
|
31
|
-
expect(document.head.querySelector('script[data-eco-script-id="eco-test"]')).toBeNull();
|
|
32
|
-
}
|
|
33
|
-
finally {
|
|
34
|
-
delete window.__ECO_PAGES__;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
it('cache-busts external module rerun scripts', async () => {
|
|
38
|
-
const html = '<html><head><script data-eco-rerun src="/app.js" type="module"></script></head></html>';
|
|
39
|
-
const parsed = new DOMParser().parseFromString(html, 'text/html');
|
|
40
|
-
const scripts = collectRerunScripts(parsed);
|
|
41
|
-
await activateScriptsInOrder(scripts.map(toRerunScriptActivation));
|
|
42
|
-
const inserted = document.head.querySelector(`script[${RERUN_SRC_ATTR}]`);
|
|
43
|
-
expect(inserted?.getAttribute('src')).not.toBe('/app.js');
|
|
44
|
-
expect(inserted?.getAttribute('src')).toMatch(/__eco_rerun=\d+/);
|
|
45
|
-
expect(inserted?.getAttribute(RERUN_SRC_ATTR)).toBe('/app.js');
|
|
46
|
-
});
|
|
47
|
-
describe('an external module rerun script visited twice', () => {
|
|
48
|
-
const html = '<html><head><script type="module" src="/assets/counter.js" data-eco-rerun data-eco-script-id="counter"></script></head></html>';
|
|
49
|
-
const activateVisit = async () => {
|
|
50
|
-
const incoming = new DOMParser().parseFromString(html, 'text/html');
|
|
51
|
-
await activateScriptsInOrder(collectRerunScripts(incoming).map(toRerunScriptActivation));
|
|
52
|
-
};
|
|
53
|
-
const counterScripts = () => document.head.querySelectorAll('script[src*="/assets/counter.js"]');
|
|
54
|
-
it('runs the registered callback each visit and keeps the first script element as it was', async () => {
|
|
55
|
-
const callback = vi.fn();
|
|
56
|
-
window.__ECO_PAGES__ = {
|
|
57
|
-
rerunScripts: { counter: callback },
|
|
58
|
-
};
|
|
59
|
-
try {
|
|
60
|
-
await activateVisit();
|
|
61
|
-
const firstSrc = counterScripts()[0]?.getAttribute('src');
|
|
62
|
-
await activateVisit();
|
|
63
|
-
expect(callback).toHaveBeenCalledTimes(2);
|
|
64
|
-
expect(counterScripts()).toHaveLength(1);
|
|
65
|
-
expect(counterScripts()[0]?.getAttribute('src')).toBe(firstSrc);
|
|
66
|
-
expect(firstSrc).toBe('/assets/counter.js');
|
|
67
|
-
}
|
|
68
|
-
finally {
|
|
69
|
-
delete window.__ECO_PAGES__;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
it('replaces the script with a fresh URL each visit when no callback is registered for its id', async () => {
|
|
73
|
-
await activateVisit();
|
|
74
|
-
const firstSrc = counterScripts()[0]?.getAttribute('src');
|
|
75
|
-
await activateVisit();
|
|
76
|
-
expect(firstSrc).toMatch(/__eco_rerun=\d+/);
|
|
77
|
-
expect(counterScripts()).toHaveLength(1);
|
|
78
|
-
expect(counterScripts()[0]?.getAttribute('src')).toMatch(/__eco_rerun=\d+/);
|
|
79
|
-
expect(counterScripts()[0]?.getAttribute('src')).not.toBe(firstSrc);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
it('appends a unique nonce on each module rerun url', () => {
|
|
83
|
-
const incoming = new DOMParser().parseFromString('<html><head><script data-eco-rerun src="/app.js" type="module"></script></head></html>', 'text/html');
|
|
84
|
-
const [script] = collectRerunScripts(incoming);
|
|
85
|
-
const first = toRerunScriptActivation(script).attributes;
|
|
86
|
-
const second = toRerunScriptActivation(script).attributes;
|
|
87
|
-
expect(Array.from(first).find(([name]) => name === 'src')?.[1]).not.toBe(Array.from(second).find(([name]) => name === 'src')?.[1]);
|
|
88
|
-
});
|
|
89
|
-
it('replaces rerun scripts by their original relative src across different base urls', () => {
|
|
90
|
-
const liveBase = document.createElement('base');
|
|
91
|
-
liveBase.href = 'https://example.test/static/';
|
|
92
|
-
document.head.appendChild(liveBase);
|
|
93
|
-
const existing = document.createElement('script');
|
|
94
|
-
existing.setAttribute('data-eco-rerun', '');
|
|
95
|
-
existing.setAttribute(RERUN_SRC_ATTR, 'app.js');
|
|
96
|
-
existing.setAttribute('src', 'https://example.test/static/app.js?__eco_rerun=old');
|
|
97
|
-
existing.type = 'module';
|
|
98
|
-
document.head.appendChild(existing);
|
|
99
|
-
const incoming = new DOMParser().parseFromString('<html><head><base href="https://example.test/docs/guide/"><script data-eco-rerun src="app.js" type="module"></script></head></html>', 'text/html');
|
|
100
|
-
const [script] = collectRerunScripts(incoming);
|
|
101
|
-
const activation = toRerunScriptActivation(script);
|
|
102
|
-
const replacement = document.createElement('script');
|
|
103
|
-
for (const [name, value] of activation.attributes)
|
|
104
|
-
replacement.setAttribute(name, value);
|
|
105
|
-
activation.insert(replacement);
|
|
106
|
-
expect(existing.isConnected).toBe(false);
|
|
107
|
-
expect(document.head.querySelectorAll('script[data-eco-rerun]')).toHaveLength(1);
|
|
108
|
-
expect(replacement.getAttribute(RERUN_SRC_ATTR)).toBe('app.js');
|
|
109
|
-
expect(replacement.getAttribute('src')).toMatch(/^https:\/\/example\.test\/docs\/guide\/app\.js\?__eco_rerun=\d+$/);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { manageWindowScroll } from './scroll.js';
|
|
3
|
-
const options = { scrollBehavior: 'top', smoothScroll: false };
|
|
4
|
-
describe('manageWindowScroll', () => {
|
|
5
|
-
afterEach(() => {
|
|
6
|
-
history.replaceState({}, '', '/');
|
|
7
|
-
document.body.replaceChildren();
|
|
8
|
-
vi.restoreAllMocks();
|
|
9
|
-
});
|
|
10
|
-
it('scrolls to top by default', () => {
|
|
11
|
-
const scrollTo = vi.spyOn(window, 'scrollTo').mockImplementation(() => { });
|
|
12
|
-
manageWindowScroll(new URL('/next', window.location.origin), new URL('/prev', window.location.origin), options);
|
|
13
|
-
expect(scrollTo).toHaveBeenCalledWith({ top: 0, left: 0, behavior: 'instant' });
|
|
14
|
-
});
|
|
15
|
-
it('preserves scroll when scrollBehavior is preserve', () => {
|
|
16
|
-
const scrollTo = vi.spyOn(window, 'scrollTo').mockImplementation(() => { });
|
|
17
|
-
manageWindowScroll(new URL('/next', window.location.origin), new URL('/prev', window.location.origin), {
|
|
18
|
-
...options,
|
|
19
|
-
scrollBehavior: 'preserve',
|
|
20
|
-
});
|
|
21
|
-
expect(scrollTo).not.toHaveBeenCalled();
|
|
22
|
-
});
|
|
23
|
-
it('scrolls to hash target by element id', () => {
|
|
24
|
-
const section = document.createElement('section');
|
|
25
|
-
section.id = 'section';
|
|
26
|
-
section.scrollIntoView = vi.fn();
|
|
27
|
-
document.body.append(section);
|
|
28
|
-
manageWindowScroll(new URL('/page#section', window.location.origin), new URL('/page', window.location.origin), options);
|
|
29
|
-
expect(section.scrollIntoView).toHaveBeenCalledWith({ behavior: 'instant' });
|
|
30
|
-
});
|
|
31
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|