@ecopages/react 0.2.0-beta.38 → 0.2.0-beta.39
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 -0
- package/package.json +4 -4
- package/src/bundling/bundle.d.ts +2 -0
- package/src/bundling/bundle.js +1 -0
- package/src/client-graph/ast-transform.d.ts +1 -1
- package/src/client-graph/ast-transform.js +10 -29
- package/src/client-graph/boundary-cache.d.ts +25 -10
- package/src/client-graph/boundary-cache.js +46 -20
- package/src/client-graph/boundary-plugin.js +43 -19
- package/src/client-graph/module-classification.d.ts +3 -0
- package/src/client-graph/module-classification.js +43 -0
- package/src/client-graph/reachability-analyzer.d.ts +2 -10
- package/src/client-graph/reachability-analyzer.js +2 -22
- package/src/hmr/hmr-strategy.js +4 -2
- package/src/hydration/hydration-asset.d.ts +1 -1
- package/src/hydration/hydration-asset.js +3 -3
- package/src/hydration/hydration-scripts.js +3 -3
- package/src/mdx/mdx-config-dependency.d.ts +1 -1
- package/src/mdx/mdx-config-dependency.js +2 -1
- package/src/page/page-module.d.ts +3 -3
- package/src/page/page-module.js +10 -14
- package/src/plugin/react.plugin.js +1 -0
- package/src/plugin/react.types.d.ts +3 -0
- package/src/render/component-ownership.d.ts +2 -3
- package/src/render/component-ownership.js +3 -4
- package/src/render/component-ssr.js +2 -2
- package/src/render/react-renderer.js +3 -1
package/README.md
CHANGED
|
@@ -109,6 +109,8 @@ Think about each React page as two related graphs:
|
|
|
109
109
|
|
|
110
110
|
The React integration builds the client graph conservatively. If a server-only module becomes reachable from the hydrated render path, the build should fail rather than silently shipping unsafe code.
|
|
111
111
|
|
|
112
|
+
The boundary cache is owned by the React plugin and shared by normal Page Browser Graph bundles and HMR. Cache entries include the module source, allow-list package names with their permitted exports, and inbound requested exports; each build still starts with a fresh requested-export registry. Modules that inline external file contents are never cached. Set `ECO_AST_PROFILE=1` to emit one structured timing record per client-graph cache lookup and analysis while investigating a docs build or development rebuild.
|
|
113
|
+
|
|
112
114
|
### `explicitGraph` option
|
|
113
115
|
|
|
114
116
|
`reactPlugin({ explicitGraph: true })` forces the page browser graph (hydration assets) to emit for every React page, even when the page does not declare `dependencies.modules` and no router is configured.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/react",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.39",
|
|
4
4
|
"description": "React integration for Ecopages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecopages",
|
|
@@ -93,16 +93,16 @@
|
|
|
93
93
|
"directory": "packages/integrations/react"
|
|
94
94
|
},
|
|
95
95
|
"peerDependencies": {
|
|
96
|
-
"@ecopages/core": "0.2.0-beta.
|
|
96
|
+
"@ecopages/core": "0.2.0-beta.39",
|
|
97
97
|
"@types/react": "^19",
|
|
98
98
|
"@types/react-dom": "^19",
|
|
99
99
|
"react": "^19",
|
|
100
100
|
"react-dom": "^19"
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@ecopages/file-system": "0.2.0-beta.
|
|
103
|
+
"@ecopages/file-system": "0.2.0-beta.39",
|
|
104
104
|
"@ecopages/logger": "^0.2.3",
|
|
105
|
-
"@ecopages/mdx": "0.2.0-beta.
|
|
105
|
+
"@ecopages/mdx": "0.2.0-beta.39",
|
|
106
106
|
"@mdx-js/mdx": "^3.1.1",
|
|
107
107
|
"oxc-parser": "^0.141.0",
|
|
108
108
|
"oxc-transform": "^0.141.0",
|
package/src/bundling/bundle.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
|
|
|
12
12
|
import type { CompileOptions } from '@mdx-js/mdx';
|
|
13
13
|
import { type ReactRuntimeImports } from './runtime-bundle.js';
|
|
14
14
|
import type { ResolvedReactPluginRuntimeModule } from './runtime-modules.js';
|
|
15
|
+
import type { ClientGraphBoundaryCache } from '../client-graph/boundary-cache.js';
|
|
15
16
|
/**
|
|
16
17
|
* Configuration for the BundleService.
|
|
17
18
|
*/
|
|
@@ -22,6 +23,7 @@ export interface BundleServiceConfig {
|
|
|
22
23
|
routerAdapter?: ReactRouterAdapter;
|
|
23
24
|
runtimeModules?: ResolvedReactPluginRuntimeModule[];
|
|
24
25
|
mdxCompilerOptions?: CompileOptions;
|
|
26
|
+
clientGraphBoundaryCache?: ClientGraphBoundaryCache;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
29
|
* Optional flags that adjust how a React client entry is bundled.
|
package/src/bundling/bundle.js
CHANGED
|
@@ -88,6 +88,7 @@ export class BundleService {
|
|
|
88
88
|
absWorkingDir: this.config.rootDir,
|
|
89
89
|
declaredModules,
|
|
90
90
|
alwaysAllowSpecifiers: getReactClientGraphAllowSpecifiers(this.runtimeBundleService.getConfiguredRuntimeModuleSpecifiers(), this.config.routerAdapter),
|
|
91
|
+
cache: this.config.clientGraphBoundaryCache,
|
|
91
92
|
});
|
|
92
93
|
const [foreignJsxOverridePlugin] = getHostScopedJsxOwnershipPlugins(this.config.appConfig, this.config.hostIntegrationName, { name: 'react-renderer-foreign-jsx-override' });
|
|
93
94
|
const runtimeManifest = this.runtimeBundleService.getRuntimeManifest();
|
|
@@ -12,7 +12,7 @@ import type { RequestedExportRules } from './boundary-cache.js';
|
|
|
12
12
|
* @param requestedExports - Local requested-export registry used to propagate named reachability across files.
|
|
13
13
|
* @returns An object containing the transformed string and a boolean indicating if changes occurred.
|
|
14
14
|
*/
|
|
15
|
-
export declare function transformModuleImports(source: string, filename: string, globallyAllowed: Map<string, Set<string> | '*'>, requestedExports: Map<string, RequestedExportRules>, projectRoot?: string): {
|
|
15
|
+
export declare function transformModuleImports(source: string, filename: string, globallyAllowed: Map<string, Set<string> | '*'>, requestedExports: Map<string, RequestedExportRules>, projectRoot?: string, stripServerOnlyPageOptions?: boolean): {
|
|
16
16
|
transformed: string;
|
|
17
17
|
modified: boolean;
|
|
18
18
|
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AST transforms for the client graph boundary plugin.
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import { cachedParseSync } from '@ecopages/core/cache';
|
|
4
|
+
import { parseModuleSource } from '@ecopages/core/cache';
|
|
6
5
|
import { analyzeReachability } from './reachability-analyzer.js';
|
|
7
6
|
import { isBareSpecifier, isProjectAliasSpecifier, isServerOnlySpecifier, toModuleBaseSpecifier, parseDeclaredModules, mergeDeclaredModulesMap, normalizeRequestedExportsKey, resolveRequestedExportsKey, mergeRequestedExportRules, } from './specifier-classification.js';
|
|
8
7
|
const SERVER_ONLY_ECO_PAGE_OPTION_KEYS = new Set([
|
|
@@ -13,22 +12,6 @@ const SERVER_ONLY_ECO_PAGE_OPTION_KEYS = new Set([
|
|
|
13
12
|
'staticProps',
|
|
14
13
|
'staticPaths',
|
|
15
14
|
]);
|
|
16
|
-
/**
|
|
17
|
-
* Returns the proper OxC parser dialect to use for string source parsing.
|
|
18
|
-
*
|
|
19
|
-
* @param filename - File path.
|
|
20
|
-
* @returns Language string.
|
|
21
|
-
*/
|
|
22
|
-
function parserLanguageForFile(filename) {
|
|
23
|
-
const extension = extname(filename).toLowerCase();
|
|
24
|
-
if (extension === '.tsx')
|
|
25
|
-
return 'tsx';
|
|
26
|
-
if (extension === '.ts')
|
|
27
|
-
return 'ts';
|
|
28
|
-
if (extension === '.jsx')
|
|
29
|
-
return 'jsx';
|
|
30
|
-
return 'js';
|
|
31
|
-
}
|
|
32
15
|
/**
|
|
33
16
|
* Extracts a static property key name from an object literal property node.
|
|
34
17
|
*
|
|
@@ -127,7 +110,7 @@ function stripServerOnlyEcoPageOptions(source, program) {
|
|
|
127
110
|
* @param requestedExports - Local requested-export registry used to propagate named reachability across files.
|
|
128
111
|
* @returns An object containing the transformed string and a boolean indicating if changes occurred.
|
|
129
112
|
*/
|
|
130
|
-
export function transformModuleImports(source, filename, globallyAllowed, requestedExports, projectRoot) {
|
|
113
|
+
export function transformModuleImports(source, filename, globallyAllowed, requestedExports, projectRoot, stripServerOnlyPageOptions = false) {
|
|
131
114
|
/**
|
|
132
115
|
* Parse the source
|
|
133
116
|
*
|
|
@@ -138,10 +121,7 @@ export function transformModuleImports(source, filename, globallyAllowed, reques
|
|
|
138
121
|
*/
|
|
139
122
|
let result;
|
|
140
123
|
try {
|
|
141
|
-
result =
|
|
142
|
-
sourceType: 'module',
|
|
143
|
-
lang: parserLanguageForFile(filename),
|
|
144
|
-
});
|
|
124
|
+
result = parseModuleSource(filename, source);
|
|
145
125
|
}
|
|
146
126
|
catch {
|
|
147
127
|
return { transformed: source, modified: false };
|
|
@@ -420,7 +400,9 @@ export function transformModuleImports(source, filename, globallyAllowed, reques
|
|
|
420
400
|
}
|
|
421
401
|
walkImports(program);
|
|
422
402
|
if (edits.length === 0) {
|
|
423
|
-
return
|
|
403
|
+
return stripServerOnlyPageOptions
|
|
404
|
+
? stripServerOnlyEcoPageOptions(source, program)
|
|
405
|
+
: { transformed: source, modified: false };
|
|
424
406
|
}
|
|
425
407
|
edits.sort((a, b) => b.start - a.start);
|
|
426
408
|
let transformed = source;
|
|
@@ -429,15 +411,14 @@ export function transformModuleImports(source, filename, globallyAllowed, reques
|
|
|
429
411
|
}
|
|
430
412
|
let reparsedResult;
|
|
431
413
|
try {
|
|
432
|
-
reparsedResult =
|
|
433
|
-
sourceType: 'module',
|
|
434
|
-
lang: parserLanguageForFile(filename),
|
|
435
|
-
});
|
|
414
|
+
reparsedResult = parseModuleSource(filename, transformed);
|
|
436
415
|
}
|
|
437
416
|
catch {
|
|
438
417
|
return { transformed, modified: true };
|
|
439
418
|
}
|
|
440
|
-
const strippedPageOptions =
|
|
419
|
+
const strippedPageOptions = stripServerOnlyPageOptions
|
|
420
|
+
? stripServerOnlyEcoPageOptions(transformed, reparsedResult.program)
|
|
421
|
+
: { transformed, modified: false };
|
|
441
422
|
if (strippedPageOptions.modified) {
|
|
442
423
|
return strippedPageOptions;
|
|
443
424
|
}
|
|
@@ -17,6 +17,14 @@
|
|
|
17
17
|
* The cache is content-hashed (via `rapidhash`) so a `touch`/`utimes`
|
|
18
18
|
* does not invalidate a still-valid entry.
|
|
19
19
|
*
|
|
20
|
+
* Cache identity is `(filePath, source, allowListRules, inboundRules)`.
|
|
21
|
+
* Allow-list hashing includes each package's permitted exports, not just
|
|
22
|
+
* package names — otherwise `node:fs{readFileSync}` and
|
|
23
|
+
* `node:fs{writeFileSync}` would collide.
|
|
24
|
+
*
|
|
25
|
+
* Modules that inline external file contents (`readFileSync` rewrite) are
|
|
26
|
+
* not stored: their output depends on files outside the importer source.
|
|
27
|
+
*
|
|
20
28
|
* **`rulesAdded` semantics:** the map holds the **after-state** of
|
|
21
29
|
* every registry key this transform touched — both newly added keys
|
|
22
30
|
* and keys that were grown (Set union) or promoted to `'*'`. On
|
|
@@ -27,11 +35,15 @@
|
|
|
27
35
|
* registry as well.
|
|
28
36
|
*/
|
|
29
37
|
export type RequestedExportRules = Set<string> | '*';
|
|
38
|
+
/** Globally declared modules with their permitted export rules. */
|
|
39
|
+
export type ClientGraphAllowList = ReadonlyMap<string, RequestedExportRules>;
|
|
30
40
|
export type CachedTransform = {
|
|
31
41
|
/** Hash of the source string at the time the transform was cached. */
|
|
32
42
|
sourceHash: number | bigint;
|
|
33
43
|
/** Hash of the globally-allowed modules map at the time the transform was cached. */
|
|
34
44
|
allowListHash: number | bigint;
|
|
45
|
+
/** Hash of the requested export rules already propagated to this module. */
|
|
46
|
+
inboundRulesHash: number | bigint;
|
|
35
47
|
/** The transformed source (or original if `modified` is false). */
|
|
36
48
|
transformed: string;
|
|
37
49
|
/** Whether the transform changed the source. */
|
|
@@ -53,9 +65,10 @@ export type CachedTransform = {
|
|
|
53
65
|
* LRU-bounded cache for client-graph-boundary transform results.
|
|
54
66
|
*
|
|
55
67
|
* One instance is owned by the React plugin for the app's lifetime and
|
|
56
|
-
* shared across all builds. The cache key is
|
|
57
|
-
*
|
|
58
|
-
*
|
|
68
|
+
* shared across all builds. The cache key is
|
|
69
|
+
* `(filePath, source, allowListRules, inboundRules)` so a file whose
|
|
70
|
+
* source, allow-list export rules, or inbound requested exports change
|
|
71
|
+
* gets a fresh entry.
|
|
59
72
|
*/
|
|
60
73
|
export declare class ClientGraphBoundaryCache {
|
|
61
74
|
private readonly entries;
|
|
@@ -66,11 +79,10 @@ export declare class ClientGraphBoundaryCache {
|
|
|
66
79
|
/**
|
|
67
80
|
* Look up a cached transform for `filePath`.
|
|
68
81
|
*
|
|
69
|
-
* Returns `undefined` if the source
|
|
70
|
-
* the entry was stored.
|
|
71
|
-
* transform in that case and calling `set` to update the entry.
|
|
82
|
+
* Returns `undefined` if the source, allow-list rules, or inbound
|
|
83
|
+
* requested exports have changed since the entry was stored.
|
|
72
84
|
*/
|
|
73
|
-
get(filePath: string, source: string,
|
|
85
|
+
get(filePath: string, source: string, allowList: ClientGraphAllowList, inboundRules?: RequestedExportRules): CachedTransform | undefined;
|
|
74
86
|
/**
|
|
75
87
|
* Store a transform result.
|
|
76
88
|
*
|
|
@@ -78,15 +90,14 @@ export declare class ClientGraphBoundaryCache {
|
|
|
78
90
|
* capacity. Defensively copies any `Set`-typed rules in `rulesAdded`
|
|
79
91
|
* so later mutations to the caller's sets cannot corrupt the cache.
|
|
80
92
|
*/
|
|
81
|
-
set(filePath: string, source: string,
|
|
93
|
+
set(filePath: string, source: string, allowList: ClientGraphAllowList, entry: Omit<CachedTransform, 'sourceHash' | 'allowListHash' | 'inboundRulesHash'>, inboundRules?: RequestedExportRules): void;
|
|
82
94
|
/**
|
|
83
95
|
* Invalidate a single file's entry. Call this from the file watcher
|
|
84
96
|
* when `filePath`'s content has changed.
|
|
85
97
|
*/
|
|
86
98
|
invalidate(filePath: string): void;
|
|
87
99
|
/**
|
|
88
|
-
* Invalidate every file whose key matches a
|
|
89
|
-
* "anything under `src/pages/` changed" signals.
|
|
100
|
+
* Invalidate every file whose key matches a predicate.
|
|
90
101
|
*/
|
|
91
102
|
invalidateMatching(predicate: (filePath: string) => boolean): number;
|
|
92
103
|
/** Clear all entries. */
|
|
@@ -101,3 +112,7 @@ export declare class ClientGraphBoundaryCache {
|
|
|
101
112
|
hitRate: number;
|
|
102
113
|
};
|
|
103
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Hash allow-list package names together with each package's permitted exports.
|
|
117
|
+
*/
|
|
118
|
+
export declare function hashAllowList(allowList: ClientGraphAllowList): number | bigint;
|
|
@@ -17,6 +17,14 @@
|
|
|
17
17
|
* The cache is content-hashed (via `rapidhash`) so a `touch`/`utimes`
|
|
18
18
|
* does not invalidate a still-valid entry.
|
|
19
19
|
*
|
|
20
|
+
* Cache identity is `(filePath, source, allowListRules, inboundRules)`.
|
|
21
|
+
* Allow-list hashing includes each package's permitted exports, not just
|
|
22
|
+
* package names — otherwise `node:fs{readFileSync}` and
|
|
23
|
+
* `node:fs{writeFileSync}` would collide.
|
|
24
|
+
*
|
|
25
|
+
* Modules that inline external file contents (`readFileSync` rewrite) are
|
|
26
|
+
* not stored: their output depends on files outside the importer source.
|
|
27
|
+
*
|
|
20
28
|
* **`rulesAdded` semantics:** the map holds the **after-state** of
|
|
21
29
|
* every registry key this transform touched — both newly added keys
|
|
22
30
|
* and keys that were grown (Set union) or promoted to `'*'`. On
|
|
@@ -38,9 +46,10 @@ function cloneRules(rules) {
|
|
|
38
46
|
* LRU-bounded cache for client-graph-boundary transform results.
|
|
39
47
|
*
|
|
40
48
|
* One instance is owned by the React plugin for the app's lifetime and
|
|
41
|
-
* shared across all builds. The cache key is
|
|
42
|
-
*
|
|
43
|
-
*
|
|
49
|
+
* shared across all builds. The cache key is
|
|
50
|
+
* `(filePath, source, allowListRules, inboundRules)` so a file whose
|
|
51
|
+
* source, allow-list export rules, or inbound requested exports change
|
|
52
|
+
* gets a fresh entry.
|
|
44
53
|
*/
|
|
45
54
|
export class ClientGraphBoundaryCache {
|
|
46
55
|
entries = new Map();
|
|
@@ -56,17 +65,19 @@ export class ClientGraphBoundaryCache {
|
|
|
56
65
|
/**
|
|
57
66
|
* Look up a cached transform for `filePath`.
|
|
58
67
|
*
|
|
59
|
-
* Returns `undefined` if the source
|
|
60
|
-
* the entry was stored.
|
|
61
|
-
* transform in that case and calling `set` to update the entry.
|
|
68
|
+
* Returns `undefined` if the source, allow-list rules, or inbound
|
|
69
|
+
* requested exports have changed since the entry was stored.
|
|
62
70
|
*/
|
|
63
|
-
get(filePath, source,
|
|
71
|
+
get(filePath, source, allowList, inboundRules) {
|
|
64
72
|
const sourceHash = rapidhash(source);
|
|
65
|
-
const allowListHash = hashAllowList(
|
|
73
|
+
const allowListHash = hashAllowList(allowList);
|
|
74
|
+
const inboundRulesHash = hashRequestedExportRules(inboundRules);
|
|
66
75
|
const existing = this.entries.get(filePath);
|
|
67
|
-
if (existing &&
|
|
76
|
+
if (existing &&
|
|
77
|
+
existing.sourceHash === sourceHash &&
|
|
78
|
+
existing.allowListHash === allowListHash &&
|
|
79
|
+
existing.inboundRulesHash === inboundRulesHash) {
|
|
68
80
|
this.hits += 1;
|
|
69
|
-
// Refresh LRU position.
|
|
70
81
|
this.entries.delete(filePath);
|
|
71
82
|
this.entries.set(filePath, existing);
|
|
72
83
|
return existing;
|
|
@@ -81,9 +92,10 @@ export class ClientGraphBoundaryCache {
|
|
|
81
92
|
* capacity. Defensively copies any `Set`-typed rules in `rulesAdded`
|
|
82
93
|
* so later mutations to the caller's sets cannot corrupt the cache.
|
|
83
94
|
*/
|
|
84
|
-
set(filePath, source,
|
|
95
|
+
set(filePath, source, allowList, entry, inboundRules) {
|
|
85
96
|
const sourceHash = rapidhash(source);
|
|
86
|
-
const allowListHash = hashAllowList(
|
|
97
|
+
const allowListHash = hashAllowList(allowList);
|
|
98
|
+
const inboundRulesHash = hashRequestedExportRules(inboundRules);
|
|
87
99
|
const rulesAddedCopy = new Map();
|
|
88
100
|
for (const [key, rules] of entry.rulesAdded) {
|
|
89
101
|
rulesAddedCopy.set(key, cloneRules(rules));
|
|
@@ -91,6 +103,7 @@ export class ClientGraphBoundaryCache {
|
|
|
91
103
|
const full = {
|
|
92
104
|
sourceHash,
|
|
93
105
|
allowListHash,
|
|
106
|
+
inboundRulesHash,
|
|
94
107
|
transformed: entry.transformed,
|
|
95
108
|
modified: entry.modified,
|
|
96
109
|
rulesAdded: rulesAddedCopy,
|
|
@@ -111,8 +124,7 @@ export class ClientGraphBoundaryCache {
|
|
|
111
124
|
this.entries.delete(filePath);
|
|
112
125
|
}
|
|
113
126
|
/**
|
|
114
|
-
* Invalidate every file whose key matches a
|
|
115
|
-
* "anything under `src/pages/` changed" signals.
|
|
127
|
+
* Invalidate every file whose key matches a predicate.
|
|
116
128
|
*/
|
|
117
129
|
invalidateMatching(predicate) {
|
|
118
130
|
let removed = 0;
|
|
@@ -146,11 +158,25 @@ export class ClientGraphBoundaryCache {
|
|
|
146
158
|
}
|
|
147
159
|
}
|
|
148
160
|
/**
|
|
149
|
-
* Hash
|
|
150
|
-
* must be stable for the hash to be deterministic; we sort before
|
|
151
|
-
* hashing.
|
|
161
|
+
* Hash allow-list package names together with each package's permitted exports.
|
|
152
162
|
*/
|
|
153
|
-
function hashAllowList(
|
|
154
|
-
const
|
|
155
|
-
|
|
163
|
+
export function hashAllowList(allowList) {
|
|
164
|
+
const lines = [];
|
|
165
|
+
for (const packageName of Array.from(allowList.keys()).sort()) {
|
|
166
|
+
const rules = allowList.get(packageName);
|
|
167
|
+
if (rules === '*') {
|
|
168
|
+
lines.push(`${packageName}=*`);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const named = rules ? Array.from(rules).sort().join(',') : '';
|
|
172
|
+
lines.push(`${packageName}={${named}}`);
|
|
173
|
+
}
|
|
174
|
+
return rapidhash(lines.join('\n'));
|
|
175
|
+
}
|
|
176
|
+
function hashRequestedExportRules(rules) {
|
|
177
|
+
if (rules === '*')
|
|
178
|
+
return rapidhash('*');
|
|
179
|
+
if (!rules)
|
|
180
|
+
return rapidhash('');
|
|
181
|
+
return rapidhash(Array.from(rules).sort().join('\n'));
|
|
156
182
|
}
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
* Build plugin securing the Ecopages isomorphic compilation pipeline.
|
|
5
5
|
*/
|
|
6
6
|
import { existsSync, readFileSync } from 'node:fs';
|
|
7
|
-
import { dirname, extname, resolve } from 'node:path';
|
|
7
|
+
import { dirname, extname, resolve, sep } from 'node:path';
|
|
8
8
|
import { ClientGraphBoundaryCache } from './boundary-cache.js';
|
|
9
|
-
import { parseDeclaredModules, toModuleBaseSpecifier, mergeRequestedExportRules, snapshotRegistry, diffRequestedExportRules, } from './specifier-classification.js';
|
|
9
|
+
import { parseDeclaredModules, toModuleBaseSpecifier, mergeRequestedExportRules, normalizeRequestedExportsKey, snapshotRegistry, diffRequestedExportRules, } from './specifier-classification.js';
|
|
10
10
|
import { transformModuleImports } from './ast-transform.js';
|
|
11
|
+
import { classifyClientGraphModule, isPageOrLayoutEntry } from './module-classification.js';
|
|
12
|
+
import { recordModuleTransformProfile } from '@ecopages/core/cache';
|
|
11
13
|
const SOURCE_FILE_FILTER = /\.(tsx?|jsx?)$/;
|
|
12
14
|
/**
|
|
13
15
|
* Instantiates the client graph boundary build plugin.
|
|
@@ -26,13 +28,11 @@ export function createClientGraphBoundaryPlugin(options) {
|
|
|
26
28
|
for (const alwaysAllow of options?.alwaysAllowSpecifiers ?? []) {
|
|
27
29
|
globallyDeclaredSources.set(toModuleBaseSpecifier(alwaysAllow), '*');
|
|
28
30
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Stable list of globally-allowed specifiers, used as part of
|
|
31
|
-
* the cache key. Sorted on construction so iteration order is
|
|
32
|
-
* deterministic for hashing.
|
|
33
|
-
*/
|
|
34
|
-
const allowListForCache = Array.from(globallyDeclaredSources.keys()).sort();
|
|
35
31
|
build.onLoad({ filter: SOURCE_FILE_FILTER }, (args) => {
|
|
32
|
+
const category = classifyClientGraphModule(args.path, options?.projectRoot);
|
|
33
|
+
if (category === 'package' || category === 'vendored' || category === 'virtual') {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
36
|
let source;
|
|
37
37
|
try {
|
|
38
38
|
source = readFileSync(args.path, 'utf-8');
|
|
@@ -42,13 +42,20 @@ export function createClientGraphBoundaryPlugin(options) {
|
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* Fast path: if the cache has a transform result for this
|
|
45
|
-
* exact (filePath, source,
|
|
46
|
-
* captured `rulesAdded` into the live registry and
|
|
47
|
-
* the cached transformed source.
|
|
48
|
-
* `parseSync` + AST walk on a no-op rebuild.
|
|
45
|
+
* exact (filePath, source, allowListRules, inboundRules) tuple,
|
|
46
|
+
* replay the captured `rulesAdded` into the live registry and
|
|
47
|
+
* return the cached transformed source.
|
|
49
48
|
*/
|
|
49
|
+
const inboundRules = requestedExports.get(normalizeRequestedExportsKey(args.path));
|
|
50
50
|
if (cache) {
|
|
51
|
-
const
|
|
51
|
+
const cacheStartedAt = performance.now();
|
|
52
|
+
const cached = cache.get(args.path, source, globallyDeclaredSources, inboundRules);
|
|
53
|
+
recordModuleTransformProfile({
|
|
54
|
+
category,
|
|
55
|
+
phase: 'cache-lookup',
|
|
56
|
+
ms: performance.now() - cacheStartedAt,
|
|
57
|
+
cacheHit: Boolean(cached),
|
|
58
|
+
});
|
|
52
59
|
if (cached) {
|
|
53
60
|
for (const [moduleKey, rules] of cached.rulesAdded) {
|
|
54
61
|
mergeRequestedExportRules(requestedExports, moduleKey, rules);
|
|
@@ -61,13 +68,14 @@ export function createClientGraphBoundaryPlugin(options) {
|
|
|
61
68
|
}
|
|
62
69
|
let transformed = source;
|
|
63
70
|
let modified = false;
|
|
71
|
+
let inlinedExternalFile = false;
|
|
64
72
|
if (source.includes('readFileSync')) {
|
|
65
73
|
const readFileTransformed = transformed.replace(/\bfs\.readFileSync\s*\(\s*path\.resolve\s*\(\s*(['"`])([^'"`\n]+)\1\s*\)\s*,\s*['"`]utf-?8['"`]\s*\)/g, (_match, _q, relPath) => {
|
|
66
74
|
modified = true;
|
|
75
|
+
inlinedExternalFile = true;
|
|
67
76
|
try {
|
|
68
77
|
const sourceDir = dirname(args.path);
|
|
69
|
-
const
|
|
70
|
-
const inferredProjectRoot = srcDirIndex >= 0 ? args.path.slice(0, srcDirIndex) : undefined;
|
|
78
|
+
const inferredProjectRoot = inferProjectRootFromSourcePath(args.path);
|
|
71
79
|
const candidates = [
|
|
72
80
|
resolve(absWorkingDir, relPath),
|
|
73
81
|
resolve(process.cwd(), relPath),
|
|
@@ -93,13 +101,22 @@ export function createClientGraphBoundaryPlugin(options) {
|
|
|
93
101
|
// to `'*'`. A snapshot keyed only on newly-added entries
|
|
94
102
|
// would under-populate the registry on cache hit.
|
|
95
103
|
const registryBefore = snapshotRegistry(requestedExports);
|
|
96
|
-
const
|
|
104
|
+
const analysisStartedAt = performance.now();
|
|
105
|
+
const { transformed: oxcTransformed, modified: importsModified } = transformModuleImports(transformed, args.path, globallyDeclaredSources, requestedExports, options?.projectRoot, isPageOrLayoutEntry(args.path));
|
|
106
|
+
recordModuleTransformProfile({
|
|
107
|
+
category,
|
|
108
|
+
phase: 'analysis',
|
|
109
|
+
ms: performance.now() - analysisStartedAt,
|
|
110
|
+
});
|
|
97
111
|
if (importsModified) {
|
|
98
112
|
modified = true;
|
|
99
113
|
transformed = oxcTransformed;
|
|
100
114
|
}
|
|
101
|
-
|
|
102
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Skip persistent cache when the transform inlined another file:
|
|
117
|
+
* output depends on content outside the importer source hash.
|
|
118
|
+
*/
|
|
119
|
+
if (cache && !inlinedExternalFile) {
|
|
103
120
|
const rulesAdded = new Map();
|
|
104
121
|
for (const [key, afterRules] of requestedExports) {
|
|
105
122
|
const beforeRules = registryBefore.get(key);
|
|
@@ -113,7 +130,7 @@ export function createClientGraphBoundaryPlugin(options) {
|
|
|
113
130
|
modified,
|
|
114
131
|
rulesAdded,
|
|
115
132
|
};
|
|
116
|
-
cache.set(args.path, source,
|
|
133
|
+
cache.set(args.path, source, globallyDeclaredSources, entry, inboundRules);
|
|
117
134
|
}
|
|
118
135
|
if (!modified)
|
|
119
136
|
return undefined;
|
|
@@ -123,3 +140,10 @@ export function createClientGraphBoundaryPlugin(options) {
|
|
|
123
140
|
},
|
|
124
141
|
};
|
|
125
142
|
}
|
|
143
|
+
function inferProjectRootFromSourcePath(filePath) {
|
|
144
|
+
const parts = filePath.split(/[\\/]/);
|
|
145
|
+
const srcIndex = parts.lastIndexOf('src');
|
|
146
|
+
if (srcIndex <= 0)
|
|
147
|
+
return undefined;
|
|
148
|
+
return parts.slice(0, srcIndex).join(sep);
|
|
149
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type ClientGraphModuleKind = 'app' | 'workspace' | 'package' | 'vendored' | 'virtual';
|
|
2
|
+
export declare function classifyClientGraphModule(filePath: string, projectRoot?: string): ClientGraphModuleKind;
|
|
3
|
+
export declare function isPageOrLayoutEntry(filePath: string): boolean;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* Splits a file path into OS-agnostic segments.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Bundlers may pass POSIX or Windows separators; classification must not depend
|
|
7
|
+
* on the host's `path.sep` alone.
|
|
8
|
+
*/
|
|
9
|
+
function pathSegments(filePath) {
|
|
10
|
+
return filePath.split(/[\\/]+/).filter(Boolean);
|
|
11
|
+
}
|
|
12
|
+
function hasPathSegment(filePath, segment) {
|
|
13
|
+
return pathSegments(filePath).includes(segment);
|
|
14
|
+
}
|
|
15
|
+
function hasPathSuffix(filePath, segments) {
|
|
16
|
+
const parts = pathSegments(filePath);
|
|
17
|
+
for (let index = 0; index <= parts.length - segments.length; index += 1) {
|
|
18
|
+
if (segments.every((segment, offset) => parts[index + offset] === segment)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
export function classifyClientGraphModule(filePath, projectRoot) {
|
|
25
|
+
if (filePath.startsWith('\0') || filePath.includes('?'))
|
|
26
|
+
return 'virtual';
|
|
27
|
+
if (hasPathSegment(filePath, 'node_modules'))
|
|
28
|
+
return 'package';
|
|
29
|
+
if (hasPathSegment(filePath, '.eco') || hasPathSuffix(filePath, ['assets', 'vendors']))
|
|
30
|
+
return 'vendored';
|
|
31
|
+
if (projectRoot) {
|
|
32
|
+
const resolvedRoot = path.resolve(projectRoot);
|
|
33
|
+
const resolvedFile = path.resolve(filePath);
|
|
34
|
+
if (resolvedFile === resolvedRoot || resolvedFile.startsWith(`${resolvedRoot}${path.sep}`)) {
|
|
35
|
+
return 'app';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return 'workspace';
|
|
39
|
+
}
|
|
40
|
+
export function isPageOrLayoutEntry(filePath) {
|
|
41
|
+
const segments = pathSegments(filePath);
|
|
42
|
+
return segments.includes('pages') || segments.includes('layouts');
|
|
43
|
+
}
|
|
@@ -10,15 +10,7 @@
|
|
|
10
10
|
* these roots, the analyzer determines exactly which modules and bindings are actually needed
|
|
11
11
|
* by the browser to hydrate the page, and which imports are unused on the client (and thus can be pruned).
|
|
12
12
|
*/
|
|
13
|
-
import {
|
|
14
|
-
type ParserLanguage = 'js' | 'jsx' | 'ts' | 'tsx';
|
|
15
|
-
/**
|
|
16
|
-
* Determines the appropriate parser language configuration for a given file name.
|
|
17
|
-
*
|
|
18
|
-
* @param filename - The absolute or relative path to the file.
|
|
19
|
-
* @returns The Oxc parser language dialect to use ('js', 'jsx', 'ts', or 'tsx').
|
|
20
|
-
*/
|
|
21
|
-
export declare function parserLanguageForFile(filename: string): ParserLanguage;
|
|
13
|
+
import type { ParseResult } from 'oxc-parser';
|
|
22
14
|
/**
|
|
23
15
|
* Represents the computed results of a reachability analysis pass.
|
|
24
16
|
*/
|
|
@@ -62,5 +54,5 @@ type ExplicitlyRequestedExports = Set<string> | '*';
|
|
|
62
54
|
* @param explicitlyRequestedExports - Optional named export filter propagated
|
|
63
55
|
* from a downstream importer when this module is only partially reachable.
|
|
64
56
|
*/
|
|
65
|
-
export declare function analyzeReachability(source: string, filename: string, program?:
|
|
57
|
+
export declare function analyzeReachability(source: string, filename: string, program?: ParseResult['program'], explicitlyRequestedExports?: ExplicitlyRequestedExports): ReachabilityResult;
|
|
66
58
|
export {};
|
|
@@ -10,24 +10,7 @@
|
|
|
10
10
|
* these roots, the analyzer determines exactly which modules and bindings are actually needed
|
|
11
11
|
* by the browser to hydrate the page, and which imports are unused on the client (and thus can be pruned).
|
|
12
12
|
*/
|
|
13
|
-
import {
|
|
14
|
-
import { extname } from 'node:path';
|
|
15
|
-
/**
|
|
16
|
-
* Determines the appropriate parser language configuration for a given file name.
|
|
17
|
-
*
|
|
18
|
-
* @param filename - The absolute or relative path to the file.
|
|
19
|
-
* @returns The Oxc parser language dialect to use ('js', 'jsx', 'ts', or 'tsx').
|
|
20
|
-
*/
|
|
21
|
-
export function parserLanguageForFile(filename) {
|
|
22
|
-
const extension = extname(filename).toLowerCase();
|
|
23
|
-
if (extension === '.tsx')
|
|
24
|
-
return 'tsx';
|
|
25
|
-
if (extension === '.ts')
|
|
26
|
-
return 'ts';
|
|
27
|
-
if (extension === '.jsx')
|
|
28
|
-
return 'jsx';
|
|
29
|
-
return 'js';
|
|
30
|
-
}
|
|
13
|
+
import { parseModuleSource } from '@ecopages/core/cache';
|
|
31
14
|
/**
|
|
32
15
|
* Analyzes a module using Oxc AST and extracts a strict reachability graph
|
|
33
16
|
* starting from client roots (`render`, `errorBoundary`, `loadingFallback` of `eco.page`, `eco.layout`, or `eco.component`).
|
|
@@ -54,10 +37,7 @@ export function analyzeReachability(source, filename, program, explicitlyRequest
|
|
|
54
37
|
else {
|
|
55
38
|
let result;
|
|
56
39
|
try {
|
|
57
|
-
result =
|
|
58
|
-
sourceType: 'module',
|
|
59
|
-
lang: parserLanguageForFile(filename),
|
|
60
|
-
});
|
|
40
|
+
result = parseModuleSource(filename, source);
|
|
61
41
|
}
|
|
62
42
|
catch {
|
|
63
43
|
return {
|
package/src/hmr/hmr-strategy.js
CHANGED
|
@@ -16,6 +16,7 @@ import { createClientGraphBoundaryPlugin } from '../client-graph/boundary-plugin
|
|
|
16
16
|
import { ClientGraphBoundaryCache } from '../client-graph/boundary-cache.js';
|
|
17
17
|
import { someInConfigTree } from '../client-graph/component-config-traversal.js';
|
|
18
18
|
import { getReactClientGraphAllowSpecifiers } from '../bundling/runtime-alias-map.js';
|
|
19
|
+
import { getComponentIdentity } from '@ecopages/core';
|
|
19
20
|
import { buildReactDevTransformPlugins, resolveReactDeclaredModulesForEntrypoint, } from './react-hmr-dev-transform-plugins.js';
|
|
20
21
|
const appLogger = new Logger('[ReactHmrStrategy]');
|
|
21
22
|
/**
|
|
@@ -115,10 +116,11 @@ export class ReactHmrStrategy extends HmrStrategy {
|
|
|
115
116
|
configContainsFile(config, filePath) {
|
|
116
117
|
const resolvedFilePath = path.resolve(filePath);
|
|
117
118
|
return someInConfigTree(config, (node) => {
|
|
118
|
-
|
|
119
|
+
const identity = getComponentIdentity(node);
|
|
120
|
+
if (!identity?.file) {
|
|
119
121
|
return false;
|
|
120
122
|
}
|
|
121
|
-
return path.resolve(
|
|
123
|
+
return path.resolve(identity.file) === resolvedFilePath;
|
|
122
124
|
});
|
|
123
125
|
}
|
|
124
126
|
pageModuleRequiresLayoutRefresh(pageModule, filePath) {
|
|
@@ -62,7 +62,7 @@ export declare class HydrationAssetService {
|
|
|
62
62
|
* Includes the bundled component entry and a shared hydration bootstrap script.
|
|
63
63
|
*
|
|
64
64
|
* @param componentFile - Absolute path to the component source file
|
|
65
|
-
* @param config - Optional component config with
|
|
65
|
+
* @param config - Optional component config with identity attribution
|
|
66
66
|
* @returns Processed assets ready for injection
|
|
67
67
|
*/
|
|
68
68
|
buildComponentRenderAssets(componentFile: string, config?: EcoComponentConfig): Promise<ProcessedAsset[]>;
|
|
@@ -15,7 +15,7 @@ import { createHydrationScript, createIslandHydrationScript } from './hydration-
|
|
|
15
15
|
import { resolveHydrationBootstrapImports } from './bootstrap-imports.js';
|
|
16
16
|
import { collectDeclaredModulesInConfig } from '../client-graph/declared-modules.js';
|
|
17
17
|
export function getIslandComponentKey(componentFile, config) {
|
|
18
|
-
return rapidhash(`${componentFile}:${config?.
|
|
18
|
+
return rapidhash(`${componentFile}:${config?.identity?.id ?? ''}`).toString();
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Manages the creation of client-side hydration assets for React pages and component islands.
|
|
@@ -123,7 +123,7 @@ export class HydrationAssetService {
|
|
|
123
123
|
* Includes the bundled component entry and a shared hydration bootstrap script.
|
|
124
124
|
*
|
|
125
125
|
* @param componentFile - Absolute path to the component source file
|
|
126
|
-
* @param config - Optional component config with
|
|
126
|
+
* @param config - Optional component config with identity attribution
|
|
127
127
|
* @returns Processed assets ready for injection
|
|
128
128
|
*/
|
|
129
129
|
async buildComponentRenderAssets(componentFile, config) {
|
|
@@ -143,7 +143,7 @@ export class HydrationAssetService {
|
|
|
143
143
|
reactImportPath: runtimeImports.react,
|
|
144
144
|
reactDomClientImportPath: runtimeImports.reactDomClient,
|
|
145
145
|
targetSelector: `[data-eco-component-key="${componentKey}"]`,
|
|
146
|
-
componentRef: config?.
|
|
146
|
+
componentRef: config?.identity?.id,
|
|
147
147
|
componentFile,
|
|
148
148
|
minify: !hmrEnabled,
|
|
149
149
|
hmrEnabled,
|
|
@@ -124,7 +124,7 @@ function getRouterHmrHandlerScript(options) {
|
|
|
124
124
|
const nextProps = getPageData();
|
|
125
125
|
${getHmrImportStatement(isMdx)}
|
|
126
126
|
const currentPageLayoutStack = (Component) =>
|
|
127
|
-
(Component.config?.layouts ?? []).map((layout) => layout?.config?.
|
|
127
|
+
(Component.config?.layouts ?? []).map((layout) => layout?.config?.identity?.file ?? '').join('|');
|
|
128
128
|
const currentPageLayoutStackKey = currentPageLayoutStack(Page);
|
|
129
129
|
const nextPageLayoutStackKey = currentPageLayoutStack(NewPage);
|
|
130
130
|
|
|
@@ -412,7 +412,7 @@ export function createIslandHydrationScript(options) {
|
|
|
412
412
|
? getIslandHmrHandlerScript({ importPath: options.importPath, targetSelector: options.targetSelector })
|
|
413
413
|
: '';
|
|
414
414
|
if (options.minify) {
|
|
415
|
-
return `import{createRoot as cr}from"${options.reactDomClientImportPath}";import{createElement as ce}from"${options.reactImportPath}";import*as M from"${options.importPath}";const r=${componentRef};const f=${componentFile};const mv=Object.values(M);const c=mv.find((e)=>{if(typeof e!=="function")return false;const ec=e.config?.
|
|
415
|
+
return `import{createRoot as cr}from"${options.reactDomClientImportPath}";import{createElement as ce}from"${options.reactImportPath}";import*as M from"${options.importPath}";const r=${componentRef};const f=${componentFile};const mv=Object.values(M);const c=mv.find((e)=>{if(typeof e!=="function")return false;const ec=e.config?.identity;if(!ec)return false;if(r&&ec.id===r)return true;if(f&&ec.file===f)return true;return false;})??(typeof M.default==="function"?M.default:mv.find((e)=>typeof e==="function")??null);const m=()=>{const ts=document.querySelectorAll(${targetSelector});if(!c||ts.length===0)return;ts.forEach((t)=>{if(!(t instanceof HTMLElement))return;const p=JSON.parse(atob(t.getAttribute("data-eco-props")||"e30="));const ct=document.createElement("eco-island");ct.style.display="block";t.replaceWith(ct);cr(ct).render(ce(c,p))})};window.__ECO_PAGES__=window.__ECO_PAGES__||{};window.__ECO_PAGES__.rerunScripts=window.__ECO_PAGES__.rerunScripts||{};window.__ECO_PAGES__.rerunScripts[${JSON.stringify(scriptId)}]=m;document.readyState==="loading"?document.addEventListener("DOMContentLoaded",m,{once:true}):m()`;
|
|
416
416
|
}
|
|
417
417
|
return `
|
|
418
418
|
import { createRoot } from "${options.reactDomClientImportPath}";
|
|
@@ -427,7 +427,7 @@ const resolveComponent = (module = ComponentModule) => {
|
|
|
427
427
|
const matchByMetadata = moduleValues.find((entry) => {
|
|
428
428
|
if (typeof entry !== "function") return false;
|
|
429
429
|
const config = entry.config;
|
|
430
|
-
const eco = config?.
|
|
430
|
+
const eco = config?.identity;
|
|
431
431
|
if (!eco) return false;
|
|
432
432
|
if (id && eco.id === id) return true;
|
|
433
433
|
if (file && eco.file === file) return true;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type EcoComponent, type EcoComponentConfig } from '@ecopages/core';
|
|
2
2
|
import { type AssetProcessingService, type ProcessedAsset } from '@ecopages/core/services/asset-processing-service';
|
|
3
3
|
import type { PageModuleService } from '../page/page-module.js';
|
|
4
4
|
type MdxConfigDependencyProcessor = (components: Partial<EcoComponent>[]) => Promise<ProcessedAsset[]>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { getComponentIdentity, } from '@ecopages/core';
|
|
2
3
|
import { attachEcoFileMetadataToConfig } from '@ecopages/core/route-renderer/page-loading/file-scoped-dependency-components';
|
|
3
4
|
import { AssetFactory, } from '@ecopages/core/services/asset-processing-service';
|
|
4
5
|
import { collectFromConfigForest, getComponentConfigs } from '../client-graph/component-config-traversal.js';
|
|
@@ -64,7 +65,7 @@ export class MdxConfigDependencyService {
|
|
|
64
65
|
...(attributes ?? {}),
|
|
65
66
|
});
|
|
66
67
|
collectFromConfigForest(getComponentConfigs(components), (config) => {
|
|
67
|
-
const componentFile = config
|
|
68
|
+
const componentFile = getComponentIdentity(config)?.file;
|
|
68
69
|
if (!componentFile) {
|
|
69
70
|
return [];
|
|
70
71
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Page module loading and configuration resolution service for React integration.
|
|
3
3
|
*
|
|
4
|
-
* Handles component
|
|
4
|
+
* Handles component identity resolution and module hydration analysis.
|
|
5
5
|
* MDX page modules load through the core {@link PageModuleImportService} path
|
|
6
6
|
* using the React plugin's server build contributions.
|
|
7
7
|
*
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
|
-
import type
|
|
10
|
+
import { type EcoComponentConfig, type EcoPageFile } from '@ecopages/core';
|
|
11
11
|
/**
|
|
12
12
|
* Configuration for the PageModuleService.
|
|
13
13
|
*/
|
|
@@ -29,7 +29,7 @@ export declare class PageModuleService {
|
|
|
29
29
|
*/
|
|
30
30
|
isMdxFile(filePath: string): boolean;
|
|
31
31
|
/**
|
|
32
|
-
* Ensures that an EcoComponentConfig has
|
|
32
|
+
* Ensures that an EcoComponentConfig has canonical identity attached.
|
|
33
33
|
*/
|
|
34
34
|
ensureConfigFileMetadata(config: EcoComponentConfig, pagePath: string): EcoComponentConfig;
|
|
35
35
|
hasModulesInConfig(config: EcoComponentConfig | undefined): boolean;
|
package/src/page/page-module.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Page module loading and configuration resolution service for React integration.
|
|
3
3
|
*
|
|
4
|
-
* Handles component
|
|
4
|
+
* Handles component identity resolution and module hydration analysis.
|
|
5
5
|
* MDX page modules load through the core {@link PageModuleImportService} path
|
|
6
6
|
* using the React plugin's server build contributions.
|
|
7
7
|
*
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
import path from 'node:path';
|
|
11
|
+
import { bindComponentIdentity, getComponentIdentity } from '@ecopages/core';
|
|
11
12
|
import { rapidhash } from '@ecopages/core/hash';
|
|
12
13
|
import { fileSystem } from '@ecopages/file-system';
|
|
13
14
|
import { someInConfigTree } from '../client-graph/component-config-traversal.js';
|
|
@@ -27,15 +28,16 @@ export class PageModuleService {
|
|
|
27
28
|
return this.config.mdxExtensions.some((ext) => filePath.endsWith(ext));
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
30
|
-
* Ensures that an EcoComponentConfig has
|
|
31
|
+
* Ensures that an EcoComponentConfig has canonical identity attached.
|
|
31
32
|
*/
|
|
32
33
|
ensureConfigFileMetadata(config, pagePath) {
|
|
33
|
-
|
|
34
|
+
const identity = getComponentIdentity(config);
|
|
35
|
+
if (identity?.file) {
|
|
34
36
|
return config;
|
|
35
37
|
}
|
|
36
|
-
const
|
|
37
|
-
id:
|
|
38
|
-
integration:
|
|
38
|
+
const buildIdentity = (file) => ({
|
|
39
|
+
id: identity?.id ?? rapidhash(file).toString(36),
|
|
40
|
+
integration: identity?.integration ?? this.config.integrationName,
|
|
39
41
|
file,
|
|
40
42
|
});
|
|
41
43
|
const resolveDependencyValue = (value) => typeof value === 'string' ? value : value.src;
|
|
@@ -50,17 +52,11 @@ export class PageModuleService {
|
|
|
50
52
|
for (const candidateDir of candidateDirs) {
|
|
51
53
|
const resolvedDependency = path.resolve(candidateDir, dependencyPath);
|
|
52
54
|
if (fileSystem.exists(resolvedDependency)) {
|
|
53
|
-
return
|
|
54
|
-
...config,
|
|
55
|
-
__eco: buildEcoMeta(path.join(candidateDir, path.basename(pagePath))),
|
|
56
|
-
};
|
|
55
|
+
return bindComponentIdentity(buildIdentity(path.join(candidateDir, path.basename(pagePath))), config);
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
|
-
return
|
|
61
|
-
...config,
|
|
62
|
-
__eco: buildEcoMeta(pagePath),
|
|
63
|
-
};
|
|
59
|
+
return bindComponentIdentity(buildIdentity(pagePath), config);
|
|
64
60
|
}
|
|
65
61
|
hasModulesInConfig(config) {
|
|
66
62
|
return someInConfigTree(config, (node) => node.dependencies?.modules?.some((entry) => entry.trim().length > 0) ?? false);
|
|
@@ -100,6 +100,7 @@ export class ReactPlugin extends IntegrationPlugin {
|
|
|
100
100
|
mdxExtensions: this.mdxExtensions,
|
|
101
101
|
hmrPageMetadataCache: this.hmrPageMetadataCache,
|
|
102
102
|
forceBrowserGraph: this.forceBrowserGraph,
|
|
103
|
+
clientGraphBoundaryCache: this.clientGraphBoundaryCache,
|
|
103
104
|
};
|
|
104
105
|
if (this.mdxEnabled) {
|
|
105
106
|
appLogger.debug('MDX mode enabled with React jsx runtime');
|
|
@@ -3,6 +3,7 @@ import type { CompileOptions } from '@mdx-js/mdx';
|
|
|
3
3
|
import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
|
|
4
4
|
import type { HmrPageMetadataCache } from '../hmr/page-metadata-cache.js';
|
|
5
5
|
import type { ReactPluginRuntimeModule, ResolvedReactPluginRuntimeModule } from '../bundling/runtime-modules.js';
|
|
6
|
+
import type { ClientGraphBoundaryCache } from '../client-graph/boundary-cache.js';
|
|
6
7
|
/**
|
|
7
8
|
* MDX configuration options for the React plugin.
|
|
8
9
|
*/
|
|
@@ -138,6 +139,8 @@ export type ReactRendererConfig = {
|
|
|
138
139
|
mdxCompilerOptions?: CompileOptions;
|
|
139
140
|
mdxExtensions?: string[];
|
|
140
141
|
hmrPageMetadataCache?: HmrPageMetadataCache;
|
|
142
|
+
/** Persistent React-plugin-owned cache shared by bundles and HMR transforms. */
|
|
143
|
+
clientGraphBoundaryCache?: ClientGraphBoundaryCache;
|
|
141
144
|
/**
|
|
142
145
|
* When true, always emit page browser graph / hydration assets for React pages.
|
|
143
146
|
*
|
|
@@ -15,9 +15,8 @@ export type RequiresAwareComponent = {
|
|
|
15
15
|
* Reads the declared integration name for a component or layout.
|
|
16
16
|
*
|
|
17
17
|
* @remarks
|
|
18
|
-
* Honors both the explicit `config.integration` override and
|
|
19
|
-
* `
|
|
20
|
-
* config as well as build-time component metadata.
|
|
18
|
+
* Honors both the explicit `config.integration` override and build-time
|
|
19
|
+
* `getComponentIdentity(component)?.integration` attribution.
|
|
21
20
|
*/
|
|
22
21
|
export declare function getComponentIntegration(component?: {
|
|
23
22
|
config?: EcoComponentConfig;
|
|
@@ -5,12 +5,11 @@
|
|
|
5
5
|
* Reads the declared integration name for a component or layout.
|
|
6
6
|
*
|
|
7
7
|
* @remarks
|
|
8
|
-
* Honors both the explicit `config.integration` override and
|
|
9
|
-
* `
|
|
10
|
-
* config as well as build-time component metadata.
|
|
8
|
+
* Honors both the explicit `config.integration` override and build-time
|
|
9
|
+
* `getComponentIdentity(component)?.integration` attribution.
|
|
11
10
|
*/
|
|
12
11
|
export function getComponentIntegration(component) {
|
|
13
|
-
return component?.config?.integration ?? component?.config?.
|
|
12
|
+
return component?.config?.integration ?? component?.config?.identity?.integration;
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
16
15
|
* Returns whether a component should stay inside the React render lane.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* React component SSR helpers: renderToString, foreign-subtree HTML, island attributes.
|
|
3
3
|
*/
|
|
4
|
-
import { buildIslandHostAttributes } from '@ecopages/core';
|
|
4
|
+
import { buildIslandHostAttributes, getComponentIdentity } from '@ecopages/core';
|
|
5
5
|
import { isValidElement } from 'react';
|
|
6
6
|
import { hasSingleRootElement } from './html-boundary.js';
|
|
7
7
|
import { getIslandComponentKey } from '../hydration/hydration-asset.js';
|
|
@@ -141,7 +141,7 @@ export async function renderReactManagedComponent(options) {
|
|
|
141
141
|
html = queuedForeignSubtreeResolution.html;
|
|
142
142
|
const canAttachAttributes = hasSingleRootElement(html);
|
|
143
143
|
const rootTag = getRootTagName(html);
|
|
144
|
-
const componentFile = componentConfig?.
|
|
144
|
+
const componentFile = getComponentIdentity(componentConfig)?.file;
|
|
145
145
|
let rootAttributes;
|
|
146
146
|
let assets;
|
|
147
147
|
if (canAttachAttributes &&
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @module
|
|
10
10
|
*/
|
|
11
|
+
import { getComponentIdentity } from '@ecopages/core';
|
|
11
12
|
import { IntegrationRenderer, } from '@ecopages/core/route-renderer/orchestration/integration-renderer';
|
|
12
13
|
import { RESOLVED_ASSETS_DIR } from '@ecopages/core/constants';
|
|
13
14
|
import { ECO_DOCUMENT_OWNER_ATTRIBUTE } from '@ecopages/core/router/navigation-coordinator';
|
|
@@ -72,6 +73,7 @@ export class ReactRenderer extends IntegrationRenderer {
|
|
|
72
73
|
routerAdapter: this.routerAdapter,
|
|
73
74
|
runtimeModules: reactConfig?.runtimeModules,
|
|
74
75
|
mdxCompilerOptions: this.mdxCompilerOptions,
|
|
76
|
+
clientGraphBoundaryCache: reactConfig?.clientGraphBoundaryCache,
|
|
75
77
|
});
|
|
76
78
|
this.pageModuleService = new PageModuleService({
|
|
77
79
|
layoutsDir: this.appConfig.absolutePaths.layoutsDir,
|
|
@@ -365,7 +367,7 @@ export class ReactRenderer extends IntegrationRenderer {
|
|
|
365
367
|
}
|
|
366
368
|
await this.prepareViewDependencies(input.view, input.layout);
|
|
367
369
|
if (!input.ctx.partial) {
|
|
368
|
-
await this.appendHydrationAssetsForFile(input.view
|
|
370
|
+
await this.appendHydrationAssetsForFile(getComponentIdentity(input.view)?.file);
|
|
369
371
|
}
|
|
370
372
|
const HtmlTemplate = await this.getHtmlTemplate();
|
|
371
373
|
const metadata = await this.resolveViewMetadata(input.view, input.props);
|