@ecopages/core 0.3.0 → 0.3.1
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 +29 -11
- package/src/adapters/node/create-app.js +78 -67
- 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 +23 -6
- package/src/adapters/node/runtime-host.js +27 -8
- 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 +9 -5
- package/src/adapters/shared/hmr/hmr-manager.js +38 -54
- 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 +5 -11
- package/src/adapters/shared/runtime/port-manager.d.ts +2 -11
- package/src/adapters/shared/runtime/port-manager.js +3 -28
- 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/build/build-adapter.d.ts +2 -19
- package/src/build/build-adapter.js +0 -21
- 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/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/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.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/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/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/plugins/alias-resolver-cache.d.ts +4 -3
- package/src/plugins/alias-resolver-cache.js +4 -3
- 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 +2 -1
- 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 -6
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +0 -6
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +10 -32
- 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 +2 -11
- 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
|
@@ -50,13 +50,7 @@ import { resetBuildErrors, reportBuildError } from './build-error-presentation.j
|
|
|
50
50
|
break;
|
|
51
51
|
case 'layout-update': {
|
|
52
52
|
await waitForNavigationToSettle(navigationRuntime);
|
|
53
|
-
|
|
54
|
-
clearCache: true,
|
|
55
|
-
moduleUrl: getActiveHmrModuleUrl(),
|
|
56
|
-
})) {
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
location.reload();
|
|
53
|
+
await reloadPage();
|
|
60
54
|
break;
|
|
61
55
|
}
|
|
62
56
|
case 'error':
|
|
@@ -83,8 +77,23 @@ import { resetBuildErrors, reportBuildError } from './build-error-presentation.j
|
|
|
83
77
|
reloadCurrentPage: async (request) => Boolean(await navigationRuntime.reloadCurrentPage(request)),
|
|
84
78
|
importModule: (url) => import(url),
|
|
85
79
|
waitForSettled: async () => waitForNavigationToSettle(navigationRuntime),
|
|
80
|
+
reloadPage,
|
|
86
81
|
}, timestamp);
|
|
87
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* @remarks
|
|
85
|
+
* Prefers a soft reload by the navigation owner and falls back to a full document reload when none handles it.
|
|
86
|
+
*/
|
|
87
|
+
async function reloadPage() {
|
|
88
|
+
const navigationRuntime = getEcoNavigationRuntime(window);
|
|
89
|
+
const handled = await navigationRuntime.reloadCurrentPage({
|
|
90
|
+
clearCache: true,
|
|
91
|
+
moduleUrl: getActiveHmrModuleUrl(),
|
|
92
|
+
});
|
|
93
|
+
if (!handled) {
|
|
94
|
+
location.reload();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
88
97
|
function getActiveHmrModuleUrl() {
|
|
89
98
|
return resolveActiveModuleUrl(window.__ECO_PAGES__?.hmrHandlers ?? {}, window.__ECO_PAGES__?.page?.module);
|
|
90
99
|
}
|
|
@@ -8,6 +8,13 @@ export type ApplyModuleUpdateContext = {
|
|
|
8
8
|
}) => Promise<boolean>;
|
|
9
9
|
importModule: (url: string) => Promise<unknown>;
|
|
10
10
|
waitForSettled: () => Promise<void>;
|
|
11
|
+
reloadPage: () => Promise<void>;
|
|
11
12
|
};
|
|
12
13
|
export declare function resolveActiveModuleUrl(handlers: HmrModuleHandlers, pageModule?: string): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* @remarks
|
|
16
|
+
* A hot update that cannot be applied leaves the page running stale modules, so every failure path ends in
|
|
17
|
+
* `reloadPage`: a handler or import that throws, an active page module the navigation owner does not reload, and a
|
|
18
|
+
* module without a handler. Thrown errors are still logged.
|
|
19
|
+
*/
|
|
13
20
|
export declare function applyModuleUpdate(path: string, context: ApplyModuleUpdateContext, timestamp?: number): Promise<void>;
|
|
@@ -15,25 +15,42 @@ export function resolveActiveModuleUrl(handlers, pageModule) {
|
|
|
15
15
|
}
|
|
16
16
|
return handlerPaths[handlerPaths.length - 1];
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* @remarks
|
|
20
|
+
* A hot update that cannot be applied leaves the page running stale modules, so every failure path ends in
|
|
21
|
+
* `reloadPage`: a handler or import that throws, an active page module the navigation owner does not reload, and a
|
|
22
|
+
* module without a handler. Thrown errors are still logged.
|
|
23
|
+
*/
|
|
18
24
|
export async function applyModuleUpdate(path, context, timestamp) {
|
|
19
25
|
const basePath = stripModuleUrlQuery(path);
|
|
20
26
|
const url = withModuleCacheBust(basePath, timestamp);
|
|
21
27
|
const handlers = context.getHandlers();
|
|
22
28
|
await context.waitForSettled();
|
|
29
|
+
try {
|
|
30
|
+
if (await applyHotUpdate(basePath, url, handlers, context)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.error(`[ecopages] HMR update failed for ${basePath}:`, error);
|
|
36
|
+
}
|
|
37
|
+
await context.reloadPage();
|
|
38
|
+
}
|
|
39
|
+
async function applyHotUpdate(basePath, url, handlers, context) {
|
|
23
40
|
const handler = handlers?.[basePath];
|
|
24
41
|
if (handler) {
|
|
25
42
|
await handler(url);
|
|
26
|
-
return;
|
|
43
|
+
return true;
|
|
27
44
|
}
|
|
28
45
|
if (isDevTransformModuleUrl(basePath)) {
|
|
29
46
|
const activePageModule = context.getActivePageModule?.();
|
|
30
47
|
const isActivePageModule = activePageModule !== undefined && stripModuleUrlQuery(activePageModule) === basePath;
|
|
31
48
|
if (isActivePageModule) {
|
|
32
|
-
|
|
33
|
-
return;
|
|
49
|
+
return context.reloadCurrentPage({ clearCache: false, moduleUrl: url });
|
|
34
50
|
}
|
|
35
51
|
await context.importModule(url);
|
|
36
|
-
return;
|
|
52
|
+
return true;
|
|
37
53
|
}
|
|
38
54
|
console.warn(`[ecopages] No HMR handler for module update: ${basePath}`);
|
|
55
|
+
return false;
|
|
39
56
|
}
|
|
@@ -51,9 +51,6 @@ export declare const HmrStrategyType: {
|
|
|
51
51
|
readonly FALLBACK: 0;
|
|
52
52
|
};
|
|
53
53
|
export type HmrStrategyType = (typeof HmrStrategyType)[keyof typeof HmrStrategyType];
|
|
54
|
-
/**
|
|
55
|
-
* Represents an action to be taken after processing a file change.
|
|
56
|
-
*/
|
|
57
54
|
/**
|
|
58
55
|
* Base class for HMR strategies.
|
|
59
56
|
*
|
package/src/hmr/hmr-strategy.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* JavaScript HMR Strategy
|
|
3
3
|
*
|
|
4
4
|
* Handles hot module replacement for JavaScript and TypeScript entrypoints.
|
|
5
|
-
*
|
|
6
|
-
* the
|
|
5
|
+
* Decides whether the browser can hot-accept the change or must reload; `HmrManager`
|
|
6
|
+
* has already invalidated the affected dev-transform modules.
|
|
7
7
|
*
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
@@ -29,7 +29,6 @@ export interface JsHmrContext extends HmrRegisteredEntrypointsContext {
|
|
|
29
29
|
* dependency changes.
|
|
30
30
|
*/
|
|
31
31
|
shouldProcessEntrypoint?(entrypointPath: string): boolean;
|
|
32
|
-
invalidateDevTransformSource?(sourcePath: string): void;
|
|
33
32
|
consumeRegisteredScriptReloadRequired?(filePath: string): boolean;
|
|
34
33
|
}
|
|
35
34
|
/**
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* JavaScript HMR Strategy
|
|
3
3
|
*
|
|
4
4
|
* Handles hot module replacement for JavaScript and TypeScript entrypoints.
|
|
5
|
-
*
|
|
6
|
-
* the
|
|
5
|
+
* Decides whether the browser can hot-accept the change or must reload; `HmrManager`
|
|
6
|
+
* has already invalidated the affected dev-transform modules.
|
|
7
7
|
*
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
@@ -11,7 +11,6 @@ import path from 'node:path';
|
|
|
11
11
|
import { HmrStrategy, HmrStrategyType } from '../hmr-strategy.js';
|
|
12
12
|
import { appLogger } from '../../global/app-logger.js';
|
|
13
13
|
import { isRegisteredDevTransformEntrypoint, isRegisteredScriptEntrypoint } from '../hmr-entrypoint-output.js';
|
|
14
|
-
import { isDevTransformModuleUrl } from '../hmr-asset-paths.js';
|
|
15
14
|
/**
|
|
16
15
|
* Strategy for handling JavaScript/TypeScript file changes with hot reloading.
|
|
17
16
|
*/
|
|
@@ -65,11 +64,9 @@ export class JsHmrStrategy extends HmrStrategy {
|
|
|
65
64
|
for (const entrypoint of buildableEntrypoints) {
|
|
66
65
|
const resolvedEntrypoint = path.resolve(entrypoint);
|
|
67
66
|
const outputUrl = watchedFiles.get(resolvedEntrypoint);
|
|
68
|
-
if (!outputUrl
|
|
69
|
-
appLogger.debug(`[JsHmrStrategy] Skipping non-dev-transform entrypoint ${resolvedEntrypoint}: ${outputUrl ?? 'unregistered'}`);
|
|
67
|
+
if (!outputUrl) {
|
|
70
68
|
continue;
|
|
71
69
|
}
|
|
72
|
-
this.context.invalidateDevTransformSource?.(resolvedEntrypoint);
|
|
73
70
|
if (isRegisteredScriptEntrypoint(registeredEntrypoints, resolvedEntrypoint)) {
|
|
74
71
|
if (this.context.consumeRegisteredScriptReloadRequired?.(resolvedEntrypoint)) {
|
|
75
72
|
devTransformReloadRequired = true;
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
* concrete file paths using the app's tsconfig `paths`. Each resolution goes
|
|
7
7
|
* through oxc-resolver and may read barrel re-export targets.
|
|
8
8
|
*
|
|
9
|
-
* This cache memoizes the result keyed by `(projectRoot, specifier)`.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* This cache memoizes the result keyed by `(projectRoot, specifier)`. Each
|
|
10
|
+
* plugin instance owns one, and the request policy creates the plugin for
|
|
11
|
+
* every build request, so a cached resolution lasts one build and needs no
|
|
12
|
+
* watcher invalidation.
|
|
12
13
|
*/
|
|
13
14
|
export declare class AliasResolverCache {
|
|
14
15
|
private readonly entries;
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
* concrete file paths using the app's tsconfig `paths`. Each resolution goes
|
|
7
7
|
* through oxc-resolver and may read barrel re-export targets.
|
|
8
8
|
*
|
|
9
|
-
* This cache memoizes the result keyed by `(projectRoot, specifier)`.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* This cache memoizes the result keyed by `(projectRoot, specifier)`. Each
|
|
10
|
+
* plugin instance owns one, and the request policy creates the plugin for
|
|
11
|
+
* every build request, so a cached resolution lasts one build and needs no
|
|
12
|
+
* watcher invalidation.
|
|
12
13
|
*/
|
|
13
14
|
const DEFAULT_MAX_ENTRIES = 2_000;
|
|
14
15
|
export class AliasResolverCache {
|
|
@@ -15,7 +15,16 @@ export interface EcoComponentDirPluginOptions {
|
|
|
15
15
|
* into its Component Dependencies, removing them from the module.
|
|
16
16
|
*/
|
|
17
17
|
export declare function stripsSideEffectStylesheetImports(config: EcoPagesAppConfig, filePath: string, contents: string): boolean;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Attributes real `eco.*()` factory calls with canonical component identity.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Each call gets its own `id`, hashed from the file, the declaration name, and how many earlier calls in the
|
|
23
|
+
* file share that name. Server and browser builds of one source derive the same id, and a named declaration
|
|
24
|
+
* keeps it while other code in the file changes. Calls bound to no name (an inline argument, a call inside an
|
|
25
|
+
* anonymous function) are numbered in source order, so adding or removing another unnamed call before them
|
|
26
|
+
* changes their id. `file` stays the module path for every call in the file.
|
|
27
|
+
*/
|
|
19
28
|
export declare function attributeComponentIdentity(contents: string, filePath: string, integration: string, projectRoot?: string, jsxImportSource?: string): EcoBuildOnTransformResult;
|
|
20
29
|
/**
|
|
21
30
|
* Attributes a compiled MDX module with canonical component identity and discovered dependencies.
|
|
@@ -4,6 +4,7 @@ import { composeSourceMaps, isUsableSourceMap } from '../build/source-maps.js';
|
|
|
4
4
|
import { createCoreTransformPlugin, createMappedSourceTransformResult } from '../build/mapped-source-transform.js';
|
|
5
5
|
import { parseModuleSource } from '../cache/module-parse-cache.js';
|
|
6
6
|
import { contentHash } from '../utils/content-hash.js';
|
|
7
|
+
import { escapeRegExp } from '../utils/regex-escaping.js';
|
|
7
8
|
import { discoverComponentImports } from './component-import-discovery.js';
|
|
8
9
|
import { findIntegrationForFile } from './find-integration-for-file.js';
|
|
9
10
|
function applySourceEdits(contents, edits, filePath, options = {}) {
|
|
@@ -72,6 +73,37 @@ function walkAst(node, visit) {
|
|
|
72
73
|
for (const value of Object.values(node))
|
|
73
74
|
walkAst(value, visit);
|
|
74
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Visits each `eco.*()` call with the name of the declaration it belongs to.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* The name is the nearest enclosing variable or function binding, or `default` inside `export default`; a call
|
|
81
|
+
* bound to neither gets an empty name.
|
|
82
|
+
*/
|
|
83
|
+
function walkEcoFactoryCalls(node, binding, visit) {
|
|
84
|
+
if (Array.isArray(node)) {
|
|
85
|
+
for (const child of node)
|
|
86
|
+
walkEcoFactoryCalls(child, binding, visit);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!isAstNode(node))
|
|
90
|
+
return;
|
|
91
|
+
if (isEcoFactoryCall(node))
|
|
92
|
+
visit(node, binding);
|
|
93
|
+
let scope = binding;
|
|
94
|
+
if (node.type === 'ExportDefaultDeclaration')
|
|
95
|
+
scope = 'default';
|
|
96
|
+
if ((node.type === 'VariableDeclarator' || node.type === 'FunctionDeclaration') && isAstNode(node.id)) {
|
|
97
|
+
if (node.id.type === 'Identifier')
|
|
98
|
+
scope = String(node.id.name);
|
|
99
|
+
}
|
|
100
|
+
for (const value of Object.values(node))
|
|
101
|
+
walkEcoFactoryCalls(value, scope, visit);
|
|
102
|
+
}
|
|
103
|
+
function createIdentityLiteral(identitySource, filePath, integration) {
|
|
104
|
+
const id = BigInt(`0x${contentHash(identitySource, 16)}`).toString(36);
|
|
105
|
+
return `{ id: ${JSON.stringify(id)}, file: ${JSON.stringify(filePath)}, integration: ${JSON.stringify(integration)} }`;
|
|
106
|
+
}
|
|
75
107
|
function createNamedImportEdit(program, sourceModule, importedName) {
|
|
76
108
|
const importedNames = typeof importedName === 'string' ? [importedName] : [...importedName];
|
|
77
109
|
const imports = program.body.filter((node) => isAstNode(node) &&
|
|
@@ -147,7 +179,16 @@ export function stripsSideEffectStylesheetImports(config, filePath, contents) {
|
|
|
147
179
|
return false;
|
|
148
180
|
}
|
|
149
181
|
}
|
|
150
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* Attributes real `eco.*()` factory calls with canonical component identity.
|
|
184
|
+
*
|
|
185
|
+
* @remarks
|
|
186
|
+
* Each call gets its own `id`, hashed from the file, the declaration name, and how many earlier calls in the
|
|
187
|
+
* file share that name. Server and browser builds of one source derive the same id, and a named declaration
|
|
188
|
+
* keeps it while other code in the file changes. Calls bound to no name (an inline argument, a call inside an
|
|
189
|
+
* anonymous function) are numbered in source order, so adding or removing another unnamed call before them
|
|
190
|
+
* changes their id. `file` stays the module path for every call in the file.
|
|
191
|
+
*/
|
|
151
192
|
export function attributeComponentIdentity(contents, filePath, integration, projectRoot, jsxImportSource) {
|
|
152
193
|
const pragma = jsxImportSource && !contents.includes('@jsxImportSource')
|
|
153
194
|
? createJsxImportSourcePragma(jsxImportSource)
|
|
@@ -162,20 +203,26 @@ export function attributeComponentIdentity(contents, filePath, integration, proj
|
|
|
162
203
|
catch {
|
|
163
204
|
return applySourceEdits(contents, [], filePath, { prepend: pragma });
|
|
164
205
|
}
|
|
165
|
-
const identityLiteral = `{ id: ${JSON.stringify(BigInt(`0x${contentHash(filePath, 16)}`).toString(36))}, file: ${JSON.stringify(filePath)}, integration: ${JSON.stringify(integration)} }`;
|
|
166
206
|
if (!hasEcoFactoryCall(program)) {
|
|
167
207
|
return applySourceEdits(contents, [], filePath, { prepend: pragma });
|
|
168
208
|
}
|
|
169
209
|
const factoryArguments = [];
|
|
170
|
-
|
|
171
|
-
|
|
210
|
+
const bindingOccurrences = new Map();
|
|
211
|
+
walkEcoFactoryCalls(program, '', (node, binding) => {
|
|
212
|
+
const occurrence = bindingOccurrences.get(binding) ?? 0;
|
|
213
|
+
bindingOccurrences.set(binding, occurrence + 1);
|
|
214
|
+
if (!Array.isArray(node.arguments))
|
|
172
215
|
return;
|
|
173
216
|
const firstArgument = node.arguments[0];
|
|
174
217
|
if (!isAstNode(firstArgument) || isIdentityBinding(firstArgument))
|
|
175
218
|
return;
|
|
176
219
|
if (typeof firstArgument.start !== 'number' || typeof firstArgument.end !== 'number')
|
|
177
220
|
return;
|
|
178
|
-
factoryArguments.push({
|
|
221
|
+
factoryArguments.push({
|
|
222
|
+
start: firstArgument.start,
|
|
223
|
+
end: firstArgument.end,
|
|
224
|
+
identityLiteral: createIdentityLiteral(`${filePath}:${binding}:${occurrence}`, filePath, integration),
|
|
225
|
+
});
|
|
179
226
|
});
|
|
180
227
|
if (factoryArguments.length === 0) {
|
|
181
228
|
return applySourceEdits(contents, [], filePath, { prepend: pragma });
|
|
@@ -185,7 +232,7 @@ export function attributeComponentIdentity(contents, filePath, integration, proj
|
|
|
185
232
|
const edits = factoryArguments.map((firstArgument) => ({
|
|
186
233
|
start: firstArgument.start,
|
|
187
234
|
end: firstArgument.end,
|
|
188
|
-
prefix: `bindComponentIdentity(${identityLiteral}, `,
|
|
235
|
+
prefix: `bindComponentIdentity(${firstArgument.identityLiteral}, `,
|
|
189
236
|
suffix: `${discoveryArgument})`,
|
|
190
237
|
}));
|
|
191
238
|
edits.push(...(discovered?.removals ?? []));
|
|
@@ -257,7 +304,7 @@ export function attributeMdxComponentIdentity(contents, filePath, integration, p
|
|
|
257
304
|
return { code: contents, map: previousMap };
|
|
258
305
|
}
|
|
259
306
|
const discovered = discoverComponentImports(program, filePath, projectRoot);
|
|
260
|
-
const identityLiteral =
|
|
307
|
+
const identityLiteral = createIdentityLiteral(filePath, filePath, integration);
|
|
261
308
|
const discoveryArgument = serializeDiscoveryArgument(discovered);
|
|
262
309
|
const edits = buildMdxConfigIdentityEdits({
|
|
263
310
|
contents,
|
|
@@ -283,12 +330,21 @@ export function attributeMdxComponentIdentity(contents, filePath, integration, p
|
|
|
283
330
|
: transformed.map,
|
|
284
331
|
};
|
|
285
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* Matches the ids of modules with a script extension that an Integration owns, before an optional query.
|
|
335
|
+
*
|
|
336
|
+
* @remarks
|
|
337
|
+
* With no such extension it matches no id, so the hook filter skips every module rather than an empty
|
|
338
|
+
* alternation matching all of them, `node_modules` included.
|
|
339
|
+
*/
|
|
286
340
|
function createComponentMetaFilter(config) {
|
|
287
341
|
const extensions = config.integrations
|
|
288
342
|
.flatMap((integration) => integration.extensions)
|
|
289
|
-
.filter((extension) => ['.ts', '.tsx', '.js', '.jsx'].some((suffix) => extension.endsWith(suffix)))
|
|
290
|
-
|
|
291
|
-
|
|
343
|
+
.filter((extension) => ['.ts', '.tsx', '.js', '.jsx'].some((suffix) => extension.endsWith(suffix)));
|
|
344
|
+
if (extensions.length === 0) {
|
|
345
|
+
return /(?!)/;
|
|
346
|
+
}
|
|
347
|
+
return new RegExp(`(${extensions.map(escapeRegExp).join('|')})(\\?.*)?$`);
|
|
292
348
|
}
|
|
293
349
|
/**
|
|
294
350
|
* Creates the build plugin that attributes component identity in every Integration's script files.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { escapeRegExp } from '../utils/regex-escaping.js';
|
|
2
3
|
import { createJsxImportSourcePragma, filterJsxSourceExtensions } from './jsx-import-source.utils.js';
|
|
3
4
|
/**
|
|
4
5
|
* Build plugin that prepends a `@jsxImportSource` pragma to foreign integration
|
|
@@ -28,7 +29,7 @@ export function createForeignJsxOverridePlugin(options) {
|
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
31
|
const pragma = createJsxImportSourcePragma(options.hostJsxImportSource);
|
|
31
|
-
const filter = new RegExp(`(${extensions.map(
|
|
32
|
+
const filter = new RegExp(`(${extensions.map(escapeRegExp).join('|')})$`);
|
|
32
33
|
return {
|
|
33
34
|
name: options.name ?? 'foreign-jsx-override',
|
|
34
35
|
cacheKey: JSON.stringify([options.hostJsxImportSource, extensions, excludedExtensions]),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isDevelopmentRuntime } from '../../utils/runtime.js';
|
|
2
|
+
import { formatErrorChain } from '../../utils/format-error-chain.js';
|
|
2
3
|
import { escapeHtml } from '../../utils/html-escaping.js';
|
|
3
4
|
import { ERROR_PAGE_COPY, isHttpErrorPageStatus, isHttpErrorStatus } from '../../errors/http-error-page-contract.js';
|
|
4
5
|
/** Stable class hooks exposed by the framework-owned error documents. */
|
|
@@ -179,7 +180,7 @@ export function getDefaultServerErrorDetails(error) {
|
|
|
179
180
|
return undefined;
|
|
180
181
|
}
|
|
181
182
|
if (error instanceof Error) {
|
|
182
|
-
return { message: error.message, stack: error
|
|
183
|
+
return { message: error.message, stack: formatErrorChain(error) };
|
|
183
184
|
}
|
|
184
185
|
return { message: String(error) };
|
|
185
186
|
}
|
|
@@ -156,6 +156,6 @@ export async function finalizeDocumentShellHtml(htmlTransformer, options) {
|
|
|
156
156
|
const context = getComponentRenderContext()?.renderState;
|
|
157
157
|
return htmlTransformer.injectPageAssets(html, {
|
|
158
158
|
contributions: options.htmlContributions,
|
|
159
|
-
pagePackage: context?.session?.pagePackage
|
|
159
|
+
pagePackage: context?.session?.pagePackage,
|
|
160
160
|
});
|
|
161
161
|
}
|
|
@@ -29,7 +29,7 @@ export type RouteModuleLoadOptions = {
|
|
|
29
29
|
/**
|
|
30
30
|
* Response options for an explicit view render.
|
|
31
31
|
*/
|
|
32
|
-
export interface
|
|
32
|
+
export interface ExplicitViewResponseOptions {
|
|
33
33
|
partial?: boolean;
|
|
34
34
|
status?: number;
|
|
35
35
|
headers?: HeadersInit;
|
|
@@ -37,7 +37,7 @@ export interface RenderToResponseContext {
|
|
|
37
37
|
/**
|
|
38
38
|
* Request data an explicit view render forwards to the route pipeline.
|
|
39
39
|
*/
|
|
40
|
-
export type ExplicitViewRenderContext =
|
|
40
|
+
export type ExplicitViewRenderContext = ExplicitViewResponseOptions & Partial<Pick<RouteRendererOptions, 'params' | 'query' | 'locals' | 'file'>>;
|
|
41
41
|
export type HtmlDocumentContributionContext<C = EcoPagesElement> = {
|
|
42
42
|
renderOptions?: IntegrationRendererRenderOptions<C>;
|
|
43
43
|
partial?: boolean;
|
|
@@ -170,7 +170,11 @@ export declare abstract class IntegrationRenderer<C = EcoPagesElement> {
|
|
|
170
170
|
private getPrebuiltRoutePreparation;
|
|
171
171
|
getPrebuiltRouteComponentGraphs(routeOptions: RouteRendererOptions): PreparedRouteComponentGraphs | undefined;
|
|
172
172
|
/**
|
|
173
|
-
* Drops
|
|
173
|
+
* Drops every production prebuild result for a route, including its grouped plan and page-client assets.
|
|
174
|
+
*
|
|
175
|
+
* @remarks
|
|
176
|
+
* Static export calls this when it skips a dynamic route. A render only consumes the one-shot route preparation,
|
|
177
|
+
* so the grouped plan and page-client assets keep serving later renders of the same route in production start.
|
|
174
178
|
*/
|
|
175
179
|
clearPrebuiltRoutePreparation(input: Pick<RouteRendererOptions, 'file' | 'params' | 'query'>): void;
|
|
176
180
|
/**
|
|
@@ -196,12 +200,13 @@ export declare abstract class IntegrationRenderer<C = EcoPagesElement> {
|
|
|
196
200
|
* @param ctx - Render context with status and headers
|
|
197
201
|
* @returns Response object
|
|
198
202
|
*/
|
|
199
|
-
protected createHtmlResponse(body: BodyInit, ctx:
|
|
203
|
+
protected createHtmlResponse(body: BodyInit, ctx: ExplicitViewResponseOptions): Response;
|
|
200
204
|
/**
|
|
201
205
|
* Create an HttpError for unexpected render failures.
|
|
202
206
|
* @param message - Error message
|
|
203
207
|
* @param cause - Original error if available
|
|
204
|
-
* @returns The original HttpError when the cause is already one, otherwise a 500 HttpError
|
|
208
|
+
* @returns The original HttpError when the cause is already one, otherwise a 500 HttpError that keeps the
|
|
209
|
+
* original failure as `cause`
|
|
205
210
|
* @remarks HttpError from pages (for example NotFound from content lookup) must keep its
|
|
206
211
|
* status so the request matcher can serve a 404 instead of a 500.
|
|
207
212
|
*/
|
|
@@ -230,7 +230,11 @@ export class IntegrationRenderer {
|
|
|
230
230
|
return this.getPrebuiltRoutePreparation(routeOptions)?.componentGraphs;
|
|
231
231
|
}
|
|
232
232
|
/**
|
|
233
|
-
* Drops
|
|
233
|
+
* Drops every production prebuild result for a route, including its grouped plan and page-client assets.
|
|
234
|
+
*
|
|
235
|
+
* @remarks
|
|
236
|
+
* Static export calls this when it skips a dynamic route. A render only consumes the one-shot route preparation,
|
|
237
|
+
* so the grouped plan and page-client assets keep serving later renders of the same route in production start.
|
|
234
238
|
*/
|
|
235
239
|
clearPrebuiltRoutePreparation(input) {
|
|
236
240
|
const routeKey = createPrebuiltRoutePreparationKey(input);
|
|
@@ -285,7 +289,8 @@ export class IntegrationRenderer {
|
|
|
285
289
|
* Create an HttpError for unexpected render failures.
|
|
286
290
|
* @param message - Error message
|
|
287
291
|
* @param cause - Original error if available
|
|
288
|
-
* @returns The original HttpError when the cause is already one, otherwise a 500 HttpError
|
|
292
|
+
* @returns The original HttpError when the cause is already one, otherwise a 500 HttpError that keeps the
|
|
293
|
+
* original failure as `cause`
|
|
289
294
|
* @remarks HttpError from pages (for example NotFound from content lookup) must keep its
|
|
290
295
|
* status so the request matcher can serve a 404 instead of a 500.
|
|
291
296
|
*/
|
|
@@ -294,7 +299,7 @@ export class IntegrationRenderer {
|
|
|
294
299
|
return cause;
|
|
295
300
|
}
|
|
296
301
|
const errorMessage = cause instanceof Error ? `${message}: ${cause.message}` : message;
|
|
297
|
-
return HttpError.InternalServerError(errorMessage);
|
|
302
|
+
return HttpError.InternalServerError(errorMessage, { cause });
|
|
298
303
|
}
|
|
299
304
|
async resolvePageBrowserGraphForFile(filePath) {
|
|
300
305
|
/**
|
|
@@ -341,9 +346,8 @@ export class IntegrationRenderer {
|
|
|
341
346
|
if (nextDependencies.length === 0) {
|
|
342
347
|
return nextDependencies;
|
|
343
348
|
}
|
|
344
|
-
const
|
|
345
|
-
const
|
|
346
|
-
const existingPackage = session?.pagePackage ?? renderState?.pagePackage;
|
|
349
|
+
const session = getComponentRenderContext()?.renderState?.session;
|
|
350
|
+
const existingPackage = session?.pagePackage;
|
|
347
351
|
const existingDependencies = existingPackage?.assets ?? [];
|
|
348
352
|
const mergedDependencies = this.htmlTransformer.dedupeProcessedAssets([
|
|
349
353
|
...existingDependencies,
|
|
@@ -355,9 +359,6 @@ export class IntegrationRenderer {
|
|
|
355
359
|
if (session) {
|
|
356
360
|
session.pagePackage = pagePackage;
|
|
357
361
|
}
|
|
358
|
-
if (renderState) {
|
|
359
|
-
renderState.pagePackage = pagePackage;
|
|
360
|
-
}
|
|
361
362
|
return nextDependencies;
|
|
362
363
|
}
|
|
363
364
|
/**
|
|
@@ -501,7 +502,7 @@ export class IntegrationRenderer {
|
|
|
501
502
|
return HtmlTemplate;
|
|
502
503
|
}
|
|
503
504
|
catch (error) {
|
|
504
|
-
invariant(false, `Error importing HtmlTemplate: ${error}
|
|
505
|
+
invariant(false, `Error importing HtmlTemplate: ${error}`, { cause: error });
|
|
505
506
|
}
|
|
506
507
|
}
|
|
507
508
|
normalizeImportedPageFile(file, pageModule) {
|
|
@@ -570,8 +571,7 @@ export class IntegrationRenderer {
|
|
|
570
571
|
});
|
|
571
572
|
}
|
|
572
573
|
async transformRouteResponse(response, htmlContributions, pagePackage, renderOptions) {
|
|
573
|
-
const
|
|
574
|
-
const resolvedPagePackage = renderState?.session?.pagePackage ?? renderState?.pagePackage ?? pagePackage;
|
|
574
|
+
const resolvedPagePackage = getComponentRenderContext()?.renderState?.session?.pagePackage ?? pagePackage;
|
|
575
575
|
const transformedResponse = this.htmlTransformer.transform(response, {
|
|
576
576
|
contributions: htmlContributions,
|
|
577
577
|
pagePackage: resolvedPagePackage,
|
|
@@ -739,7 +739,6 @@ export class IntegrationRenderer {
|
|
|
739
739
|
if (renderState) {
|
|
740
740
|
renderState.pageClientPlan = renderOptions.pageClientPlan;
|
|
741
741
|
renderState.islandRenderAssetsByFile = renderOptions.islandRenderAssetsByFile;
|
|
742
|
-
renderState.pagePackage = renderOptions.pagePackage;
|
|
743
742
|
}
|
|
744
743
|
session.pagePackage = renderOptions.pagePackage;
|
|
745
744
|
return this.routeRenderOrchestrator.executePrepared(renderOptions, this);
|
|
@@ -748,7 +747,7 @@ export class IntegrationRenderer {
|
|
|
748
747
|
}
|
|
749
748
|
finally {
|
|
750
749
|
if (preparation) {
|
|
751
|
-
this.
|
|
750
|
+
this.prebuiltRoutePreparations.delete(createPrebuiltRoutePreparationKey(options));
|
|
752
751
|
}
|
|
753
752
|
}
|
|
754
753
|
}
|
|
@@ -32,11 +32,6 @@ type GroupedGraphRecord = {
|
|
|
32
32
|
dependencyPaths: ReadonlySet<string>;
|
|
33
33
|
generation: number;
|
|
34
34
|
};
|
|
35
|
-
export type GroupedGraphBuildOutcome = GroupedGraphRecord | {
|
|
36
|
-
skipCache: true;
|
|
37
|
-
assetsByRoute: Map<string, ProcessedAsset[]>;
|
|
38
|
-
dependencyPaths: ReadonlySet<string>;
|
|
39
|
-
};
|
|
40
35
|
export type AffectedGraphIdentity = {
|
|
41
36
|
integrationName: string;
|
|
42
37
|
routeFile: string;
|
|
@@ -73,7 +68,7 @@ export declare class SessionPageBrowserGraphCache {
|
|
|
73
68
|
reuseCachedResult?: boolean;
|
|
74
69
|
}): Promise<PageBrowserGraphResult | undefined>;
|
|
75
70
|
private buildGraphWithoutCaching;
|
|
76
|
-
resolveGroupedGraph(scope: GroupedGraphScope, build: () => Promise<
|
|
71
|
+
resolveGroupedGraph(scope: GroupedGraphScope, build: () => Promise<GroupedGraphRecord | undefined>): Promise<Map<string, ProcessedAsset[]>>;
|
|
77
72
|
peekGroupedGraph(scope: GroupedGraphScope): Map<string, ProcessedAsset[]> | undefined;
|
|
78
73
|
invalidateByFilePath(filePath: string): number;
|
|
79
74
|
invalidateRoute(integrationName: string, routeFile: string): void;
|
|
@@ -7,9 +7,6 @@ import { requireAppRuntime } from '../../../utils/app-runtime.js';
|
|
|
7
7
|
function graphBinding(key) {
|
|
8
8
|
return { consumer: 'page-browser-graph', key };
|
|
9
9
|
}
|
|
10
|
-
function isSkipCacheGroupedOutcome(outcome) {
|
|
11
|
-
return 'skipCache' in outcome;
|
|
12
|
-
}
|
|
13
10
|
function serializeGraphKey(key) {
|
|
14
11
|
return JSON.stringify([
|
|
15
12
|
'graph',
|
|
@@ -343,9 +340,6 @@ export class SessionPageBrowserGraphCache {
|
|
|
343
340
|
if (!buildResult) {
|
|
344
341
|
return new Map();
|
|
345
342
|
}
|
|
346
|
-
if (isSkipCacheGroupedOutcome(buildResult)) {
|
|
347
|
-
return buildResult.assetsByRoute;
|
|
348
|
-
}
|
|
349
343
|
if (!this.canCommitGroupedBuild(cacheKey, buildGeneration)) {
|
|
350
344
|
const existing = this.groupedRecords.get(cacheKey);
|
|
351
345
|
return existing?.assetsByRoute ?? new Map();
|