@ecopages/react 0.2.0-rc.7 → 0.2.0-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/app/client-only.js +3 -8
- package/src/client-graph/ast-transform-eco-page.d.ts +10 -0
- package/src/client-graph/ast-transform-eco-page.js +71 -0
- package/src/client-graph/ast-transform-import-edits.d.ts +13 -0
- package/src/client-graph/ast-transform-import-edits.js +75 -0
- package/src/client-graph/ast-transform-walk-imports.d.ts +19 -0
- package/src/client-graph/ast-transform-walk-imports.js +103 -0
- package/src/client-graph/ast-transform.d.ts +1 -7
- package/src/client-graph/ast-transform.js +42 -379
- package/src/client-graph/ast-walk.d.ts +10 -0
- package/src/client-graph/ast-walk.js +26 -0
- package/src/client-graph/boundary-plugin-read-file-inline.d.ts +8 -0
- package/src/client-graph/boundary-plugin-read-file-inline.js +45 -0
- package/src/client-graph/boundary-plugin-transform.d.ts +18 -0
- package/src/client-graph/boundary-plugin-transform.js +61 -0
- package/src/client-graph/boundary-plugin.d.ts +0 -20
- package/src/client-graph/boundary-plugin.js +16 -98
- package/src/client-graph/reachability-analyzer.d.ts +2 -43
- package/src/client-graph/reachability-analyzer.js +20 -518
- package/src/client-graph/reachability-client-roots.d.ts +8 -0
- package/src/client-graph/reachability-client-roots.js +59 -0
- package/src/client-graph/reachability-export-names.d.ts +5 -0
- package/src/client-graph/reachability-export-names.js +34 -0
- package/src/client-graph/reachability-fallback-roots.d.ts +3 -0
- package/src/client-graph/reachability-fallback-roots.js +71 -0
- package/src/client-graph/reachability-preload.d.ts +10 -0
- package/src/client-graph/reachability-preload.js +30 -0
- package/src/client-graph/reachability-top-level-index.d.ts +14 -0
- package/src/client-graph/reachability-top-level-index.js +93 -0
- package/src/client-graph/reachability-traverse.d.ts +7 -0
- package/src/client-graph/reachability-traverse.js +201 -0
- package/src/hmr/hmr-strategy-process.d.ts +34 -0
- package/src/hmr/hmr-strategy-process.js +83 -0
- package/src/hmr/hmr-strategy.d.ts +1 -0
- package/src/hmr/hmr-strategy.js +42 -84
- package/src/hydration/browser/page-hydration-hmr.d.ts +11 -0
- package/src/hydration/browser/page-hydration-hmr.js +56 -0
- package/src/hydration/browser/page-hydration-module.d.ts +8 -0
- package/src/hydration/browser/page-hydration-module.js +17 -0
- package/src/hydration/browser/page-hydration.d.ts +2 -18
- package/src/hydration/browser/page-hydration.js +3 -80
- package/src/hydration/compiled-page-hydration-options.d.ts +20 -0
- package/src/hydration/compiled-page-hydration-options.js +1 -0
- package/src/hydration/hydration-lifecycle.test.browser.js +12 -11
- package/src/hydration/hydration-page-entry-source.d.ts +5 -0
- package/src/hydration/hydration-page-entry-source.js +87 -0
- package/src/hydration/hydration-script-compiler.d.ts +2 -20
- package/src/hydration/hydration-script-compiler.js +14 -69
|
@@ -3,19 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Build plugin securing the Ecopages isomorphic compilation pipeline.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import { dirname, extname, resolve, sep } from 'node:path';
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
8
7
|
import { ClientGraphBoundaryCache } from './boundary-cache.js';
|
|
9
|
-
import { parseDeclaredModules, toModuleBaseSpecifier,
|
|
10
|
-
import {
|
|
11
|
-
import { classifyClientGraphModule, isPageOrLayoutEntry } from './module-classification.js';
|
|
8
|
+
import { parseDeclaredModules, toModuleBaseSpecifier, normalizeRequestedExportsKey, } from './specifier-classification.js';
|
|
9
|
+
import { classifyClientGraphModule } from './module-classification.js';
|
|
12
10
|
import { recordModuleTransformProfile } from '@ecopages/core/cache';
|
|
11
|
+
import { replayCachedClientGraphTransform, transformClientGraphModule } from './boundary-plugin-transform.js';
|
|
13
12
|
const SOURCE_FILE_FILTER = /\.(tsx?|jsx?)$/;
|
|
14
13
|
/**
|
|
15
14
|
* Instantiates the client graph boundary build plugin.
|
|
16
|
-
*
|
|
17
|
-
* @param options - Configuration options for the graph boundary.
|
|
18
|
-
* @returns The resulting `EcoBuildPlugin`.
|
|
19
15
|
*/
|
|
20
16
|
export function createClientGraphBoundaryPlugin(options) {
|
|
21
17
|
return {
|
|
@@ -40,13 +36,17 @@ export function createClientGraphBoundaryPlugin(options) {
|
|
|
40
36
|
catch {
|
|
41
37
|
return undefined;
|
|
42
38
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Fast path: if the cache has a transform result for this
|
|
45
|
-
* exact (filePath, source, allowListRules, inboundRules) tuple,
|
|
46
|
-
* replay the captured `rulesAdded` into the live registry and
|
|
47
|
-
* return the cached transformed source.
|
|
48
|
-
*/
|
|
49
39
|
const inboundRules = requestedExports.get(normalizeRequestedExportsKey(args.path));
|
|
40
|
+
const transformOptions = {
|
|
41
|
+
filePath: args.path,
|
|
42
|
+
source,
|
|
43
|
+
absWorkingDir,
|
|
44
|
+
category,
|
|
45
|
+
globallyDeclaredSources,
|
|
46
|
+
requestedExports,
|
|
47
|
+
cache,
|
|
48
|
+
inboundRules,
|
|
49
|
+
};
|
|
50
50
|
if (cache) {
|
|
51
51
|
const cacheStartedAt = performance.now();
|
|
52
52
|
const cached = cache.get(args.path, source, globallyDeclaredSources, inboundRules);
|
|
@@ -57,93 +57,11 @@ export function createClientGraphBoundaryPlugin(options) {
|
|
|
57
57
|
cacheHit: Boolean(cached),
|
|
58
58
|
});
|
|
59
59
|
if (cached) {
|
|
60
|
-
|
|
61
|
-
mergeRequestedExportRules(requestedExports, moduleKey, rules);
|
|
62
|
-
}
|
|
63
|
-
if (!cached.modified)
|
|
64
|
-
return undefined;
|
|
65
|
-
const ext = extname(args.path).slice(1);
|
|
66
|
-
return { contents: cached.transformed, loader: ext, resolveDir: dirname(args.path) };
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
let transformed = source;
|
|
70
|
-
let modified = false;
|
|
71
|
-
let inlinedExternalFile = false;
|
|
72
|
-
if (source.includes('readFileSync')) {
|
|
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) => {
|
|
74
|
-
modified = true;
|
|
75
|
-
inlinedExternalFile = true;
|
|
76
|
-
try {
|
|
77
|
-
const sourceDir = dirname(args.path);
|
|
78
|
-
const inferredProjectRoot = inferProjectRootFromSourcePath(args.path);
|
|
79
|
-
const candidates = [
|
|
80
|
-
resolve(absWorkingDir, relPath),
|
|
81
|
-
resolve(process.cwd(), relPath),
|
|
82
|
-
resolve(sourceDir, relPath),
|
|
83
|
-
...(inferredProjectRoot ? [resolve(inferredProjectRoot, relPath)] : []),
|
|
84
|
-
];
|
|
85
|
-
const absolutePath = candidates.find((candidate) => existsSync(candidate));
|
|
86
|
-
if (!absolutePath)
|
|
87
|
-
return '""';
|
|
88
|
-
const content = readFileSync(absolutePath, 'utf-8');
|
|
89
|
-
return JSON.stringify(content);
|
|
90
|
-
}
|
|
91
|
-
catch {
|
|
92
|
-
return '""';
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
transformed = readFileTransformed;
|
|
96
|
-
}
|
|
97
|
-
// Snapshot the live registry so we can diff per-key after
|
|
98
|
-
// the transform. We must capture the **after-state** of
|
|
99
|
-
// every key the transform touched — including keys that
|
|
100
|
-
// already existed and grew via Set union or were promoted
|
|
101
|
-
// to `'*'`. A snapshot keyed only on newly-added entries
|
|
102
|
-
// would under-populate the registry on cache hit.
|
|
103
|
-
const registryBefore = snapshotRegistry(requestedExports);
|
|
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
|
-
});
|
|
111
|
-
if (importsModified) {
|
|
112
|
-
modified = true;
|
|
113
|
-
transformed = oxcTransformed;
|
|
114
|
-
}
|
|
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) {
|
|
120
|
-
const rulesAdded = new Map();
|
|
121
|
-
for (const [key, afterRules] of requestedExports) {
|
|
122
|
-
const beforeRules = registryBefore.get(key);
|
|
123
|
-
const diff = diffRequestedExportRules(beforeRules, afterRules);
|
|
124
|
-
if (!diff)
|
|
125
|
-
continue;
|
|
126
|
-
rulesAdded.set(key, diff);
|
|
60
|
+
return replayCachedClientGraphTransform(transformOptions, cached);
|
|
127
61
|
}
|
|
128
|
-
const entry = {
|
|
129
|
-
transformed,
|
|
130
|
-
modified,
|
|
131
|
-
rulesAdded,
|
|
132
|
-
};
|
|
133
|
-
cache.set(args.path, source, globallyDeclaredSources, entry, inboundRules);
|
|
134
62
|
}
|
|
135
|
-
|
|
136
|
-
return undefined;
|
|
137
|
-
const ext = extname(args.path).slice(1);
|
|
138
|
-
return { contents: transformed, loader: ext, resolveDir: dirname(args.path) };
|
|
63
|
+
return transformClientGraphModule(transformOptions);
|
|
139
64
|
});
|
|
140
65
|
},
|
|
141
66
|
};
|
|
142
67
|
}
|
|
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
|
-
}
|
|
@@ -4,64 +4,23 @@
|
|
|
4
4
|
* This module is responsible for performing static analysis on Ecopages client components
|
|
5
5
|
* using the Oxc AST parser. It computes a strict "reachability graph" of all JavaScript/TypeScript
|
|
6
6
|
* dependencies (imports, variables, functions, and classes) that begin from explicit client roots.
|
|
7
|
-
*
|
|
8
|
-
* In Ecopages, client roots are the `render`, `errorBoundary`, and `loadingFallback`
|
|
9
|
-
* properties passed into `eco.page()`, `eco.layout()`, or `eco.component()`. A Page's named
|
|
10
|
-
* `preload` export is an additional root. By tracing from these roots, the analyzer determines
|
|
11
|
-
* which modules and bindings the browser needs and which imports it can prune.
|
|
12
7
|
*/
|
|
13
8
|
import type { ParseResult } from 'oxc-parser';
|
|
9
|
+
export { hasPagePreloadExport } from './reachability-preload.js';
|
|
10
|
+
import type { ExplicitlyRequestedExports } from './reachability-export-names.js';
|
|
14
11
|
/**
|
|
15
12
|
* Represents the computed results of a reachability analysis pass.
|
|
16
13
|
*/
|
|
17
14
|
export type ReachabilityResult = {
|
|
18
|
-
/**
|
|
19
|
-
* Map from import specifier (e.g. 'node:fs', '@/components/Button')
|
|
20
|
-
* to a Set of imported bindings, or '*' for namespace imports.
|
|
21
|
-
*/
|
|
22
15
|
reachableImports: Map<string, Set<string> | '*'>;
|
|
23
|
-
/**
|
|
24
|
-
* AST nodes of top-level declarations that are reachable.
|
|
25
|
-
*/
|
|
26
16
|
reachableDeclarations: Set<unknown>;
|
|
27
17
|
unreachableSideEffectImports: unknown[];
|
|
28
|
-
/**
|
|
29
|
-
* Indicates whether the file had explicit eco client roots, or fell back to treating all exports as roots.
|
|
30
|
-
*/
|
|
31
18
|
isFallbackRoots: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Whether the file was successfully parsed and analyzed.
|
|
34
|
-
*/
|
|
35
19
|
analyzed: boolean;
|
|
36
20
|
};
|
|
37
|
-
/**
|
|
38
|
-
* Returns whether a module exports a named `preload` binding.
|
|
39
|
-
*
|
|
40
|
-
* @remarks
|
|
41
|
-
* Hydration entries only wire `preload` when this is true, so Pages without
|
|
42
|
-
* that export do not produce a missing-named-import warning.
|
|
43
|
-
*/
|
|
44
|
-
export declare function hasPagePreloadExport(source: string, filename: string): boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Optional export filter supplied by the client graph boundary when a local
|
|
47
|
-
* module is imported through a narrower named-export surface.
|
|
48
|
-
*
|
|
49
|
-
* `'*'` means the whole module namespace is considered reachable, while a
|
|
50
|
-
* `Set` restricts analysis to the named exports that are actually requested by
|
|
51
|
-
* downstream client-reachable modules.
|
|
52
|
-
*/
|
|
53
|
-
type ExplicitlyRequestedExports = Set<string> | '*';
|
|
54
21
|
/**
|
|
55
22
|
* Analyzes a module using Oxc AST and extracts a strict reachability graph
|
|
56
23
|
* starting from client roots: `render`, `errorBoundary`, and `loadingFallback` of
|
|
57
24
|
* `eco.page`, `eco.layout`, or `eco.component`, plus a Page's named `preload` export.
|
|
58
|
-
*
|
|
59
|
-
* @param source - Raw source string of the module.
|
|
60
|
-
* @param filename - Absolute or relative path to the module file.
|
|
61
|
-
* @param program - Optional pre-parsed Oxc program AST. When supplied, the
|
|
62
|
-
* internal `parseSync` call is skipped entirely (avoids double-parsing).
|
|
63
|
-
* @param explicitlyRequestedExports - Optional named export filter propagated
|
|
64
|
-
* from a downstream importer when this module is only partially reachable.
|
|
65
25
|
*/
|
|
66
26
|
export declare function analyzeReachability(source: string, filename: string, program?: ParseResult['program'], explicitlyRequestedExports?: ExplicitlyRequestedExports): ReachabilityResult;
|
|
67
|
-
export {};
|