@ecopages/react 0.2.0-beta.9 → 0.2.0-rc.0
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 +179 -7
- package/package.json +53 -28
- package/src/app/client-only.js +15 -0
- package/src/app/dynamic.js +9 -0
- package/src/app/dynamic.test.browser.js +31 -0
- package/src/bundling/bootstrap-package-paths.d.ts +5 -0
- package/src/bundling/bootstrap-package-paths.js +5 -0
- package/src/{services/react-bundle.service.d.ts → bundling/bundle.d.ts} +23 -8
- package/src/bundling/bundle.js +120 -0
- package/src/bundling/discover-layout-runtime-modules.d.ts +32 -0
- package/src/bundling/discover-layout-runtime-modules.js +185 -0
- package/src/bundling/runtime-alias-map.d.ts +13 -0
- package/src/bundling/runtime-alias-map.js +113 -0
- package/src/{services/react-runtime-bundle.service.d.ts → bundling/runtime-bundle.d.ts} +25 -4
- package/src/bundling/runtime-bundle.js +258 -0
- package/src/bundling/runtime-interop-plugin.js +34 -0
- package/src/bundling/runtime-mode.d.ts +9 -0
- package/src/bundling/runtime-mode.js +11 -0
- package/src/bundling/runtime-modules.d.ts +29 -0
- package/src/bundling/runtime-modules.js +49 -0
- package/src/client-graph/ast-transform.d.ts +18 -0
- package/src/client-graph/ast-transform.js +426 -0
- package/src/{utils/client-graph-boundary-cache.d.ts → client-graph/boundary-cache.d.ts} +23 -13
- package/src/client-graph/boundary-cache.js +182 -0
- package/src/{utils/client-graph-boundary-plugin.d.ts → client-graph/boundary-plugin.d.ts} +4 -13
- package/src/client-graph/boundary-plugin.js +149 -0
- package/src/client-graph/component-config-traversal.js +77 -0
- package/src/client-graph/declared-modules.js +69 -0
- package/src/client-graph/module-classification.d.ts +3 -0
- package/src/client-graph/module-classification.js +43 -0
- package/src/{utils → client-graph}/reachability-analyzer.d.ts +4 -12
- package/src/client-graph/reachability-analyzer.js +515 -0
- package/src/client-graph/specifier-classification.d.ts +75 -0
- package/src/client-graph/specifier-classification.js +214 -0
- package/src/contracts/router-adapter.js +6 -0
- package/src/dev-transform/react-dev-transform-contributor.d.ts +17 -0
- package/src/dev-transform/react-dev-transform-contributor.js +22 -0
- package/src/hmr/hmr-scripts.js +44 -0
- package/src/hmr/hmr-strategy.d.ts +74 -0
- package/src/hmr/hmr-strategy.js +351 -0
- package/src/{services/react-hmr-page-metadata-cache.d.ts → hmr/page-metadata-cache.d.ts} +5 -1
- package/src/hmr/page-metadata-cache.js +44 -0
- package/src/hmr/react-hmr-dev-transform-plugins.d.ts +23 -0
- package/src/hmr/react-hmr-dev-transform-plugins.js +20 -0
- package/src/hydration/assert-no-bare-ecopages-imports.d.ts +4 -0
- package/src/hydration/assert-no-bare-ecopages-imports.js +7 -0
- package/src/hydration/bootstrap-imports.d.ts +25 -0
- package/src/hydration/bootstrap-imports.js +33 -0
- package/src/hydration/hydration-asset.d.ts +84 -0
- package/src/hydration/hydration-asset.js +227 -0
- package/src/hydration/hydration-scripts.d.ts +104 -0
- package/src/hydration/hydration-scripts.js +483 -0
- package/src/hydration/hydration-scripts.test.browser.js +199 -0
- package/src/hydration/page-data-manifest.d.ts +58 -0
- package/src/hydration/page-data-manifest.js +97 -0
- package/src/hydration/page-data-reader.d.ts +31 -0
- package/src/hydration/page-data-reader.js +77 -0
- package/src/hydration/page-payload.d.ts +67 -0
- package/src/hydration/page-payload.js +106 -0
- package/src/hydration/serialize-page-data-script.d.ts +27 -0
- package/src/hydration/serialize-page-data-script.js +30 -0
- package/src/{services/react-mdx-config-dependency.service.d.ts → mdx/mdx-config-dependency.d.ts} +6 -6
- package/src/mdx/mdx-config-dependency.js +110 -0
- package/src/mdx/mdx-loader-plugin.d.ts +2 -0
- package/src/mdx/mdx-loader-plugin.js +8 -0
- package/src/page/page-module.d.ts +46 -0
- package/src/page/page-module.js +74 -0
- package/src/plugin/react.constants.js +1 -0
- package/src/{react.plugin.d.ts → plugin/react.plugin.d.ts} +9 -3
- package/src/plugin/react.plugin.js +241 -0
- package/src/plugin/react.types.d.ts +156 -0
- package/src/plugin/react.types.js +1 -0
- package/src/render/component-ownership.d.ts +49 -0
- package/src/render/component-ownership.js +46 -0
- package/src/render/component-ssr.d.ts +113 -0
- package/src/render/component-ssr.js +180 -0
- package/src/render/eco-embed.js +9 -0
- package/src/render/errors.d.ts +16 -0
- package/src/render/errors.js +23 -0
- package/src/render/html-boundary.js +59 -0
- package/src/render/layout-compose.d.ts +66 -0
- package/src/render/layout-compose.js +134 -0
- package/src/render/react-renderer.d.ts +138 -0
- package/src/render/react-renderer.js +448 -0
- package/src/render/react-runtime.d.ts +13 -0
- package/src/render/react-runtime.js +26 -0
- package/src/render/unified-layout-composition.d.ts +53 -0
- package/src/render/unified-layout-composition.js +78 -0
- package/src/runtime/use-sync-external-store-with-selector.js +52 -54
- package/src/eco-embed.js +0 -11
- package/src/react-hmr-strategy.d.ts +0 -230
- package/src/react-hmr-strategy.js +0 -657
- package/src/react-renderer.d.ts +0 -233
- package/src/react-renderer.js +0 -622
- package/src/react.constants.js +0 -4
- package/src/react.plugin.js +0 -209
- package/src/react.types.d.ts +0 -88
- package/src/react.types.js +0 -0
- package/src/router-adapter.js +0 -0
- package/src/services/pages-index.d.ts +0 -64
- package/src/services/pages-index.js +0 -73
- package/src/services/react-bundle.service.js +0 -86
- package/src/services/react-hmr-page-metadata-cache.js +0 -35
- package/src/services/react-hydration-asset.service.d.ts +0 -84
- package/src/services/react-hydration-asset.service.js +0 -217
- package/src/services/react-mdx-config-dependency.service.js +0 -122
- package/src/services/react-page-module.service.d.ts +0 -88
- package/src/services/react-page-module.service.js +0 -166
- package/src/services/react-page-payload.service.d.ts +0 -46
- package/src/services/react-page-payload.service.js +0 -67
- package/src/services/react-runtime-bundle.service.js +0 -192
- package/src/utils/client-graph-boundary-cache.js +0 -116
- package/src/utils/client-graph-boundary-plugin.js +0 -552
- package/src/utils/client-only.js +0 -19
- package/src/utils/component-config-traversal.js +0 -54
- package/src/utils/declared-modules.js +0 -47
- package/src/utils/dynamic.js +0 -12
- package/src/utils/dynamic.test.browser.js +0 -33
- package/src/utils/hmr-scripts.js +0 -31
- package/src/utils/html-boundary.js +0 -55
- package/src/utils/hydration-scripts.d.ts +0 -92
- package/src/utils/hydration-scripts.js +0 -358
- package/src/utils/hydration-scripts.test.browser.js +0 -198
- package/src/utils/reachability-analyzer.js +0 -339
- package/src/utils/react-dom-runtime-interop-plugin.js +0 -38
- package/src/utils/react-mdx-loader-plugin.d.ts +0 -3
- package/src/utils/react-mdx-loader-plugin.js +0 -45
- package/src/utils/react-runtime-alias-map.d.ts +0 -8
- package/src/utils/react-runtime-alias-map.js +0 -90
- /package/src/{utils → app}/client-only.d.ts +0 -0
- /package/src/{utils → app}/dynamic.d.ts +0 -0
- /package/src/{utils → app}/dynamic.test.browser.d.ts +0 -0
- /package/src/{utils/react-dom-runtime-interop-plugin.d.ts → bundling/runtime-interop-plugin.d.ts} +0 -0
- /package/src/{utils → client-graph}/component-config-traversal.d.ts +0 -0
- /package/src/{utils → client-graph}/declared-modules.d.ts +0 -0
- /package/src/{declarations.d.ts → contracts/declarations.d.ts} +0 -0
- /package/src/{router-adapter.d.ts → contracts/router-adapter.d.ts} +0 -0
- /package/src/{utils → hmr}/hmr-scripts.d.ts +0 -0
- /package/src/{utils → hydration}/hydration-scripts.test.browser.d.ts +0 -0
- /package/src/{react.constants.d.ts → plugin/react.constants.d.ts} +0 -0
- /package/src/{eco-embed.d.ts → render/eco-embed.d.ts} +0 -0
- /package/src/{utils → render}/html-boundary.d.ts +0 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Specifier classification and requested-export registry helpers for the client graph boundary.
|
|
3
|
+
*/
|
|
4
|
+
import { loadTsconfigPathPrefixes, matchesTsconfigPathPrefix } from '@ecopages/core/plugins/tsconfig-import-resolver';
|
|
5
|
+
import { toPackageRootSpecifier } from '@ecopages/core/plugins/package-specifier';
|
|
6
|
+
import { dirname, resolve } from 'node:path';
|
|
7
|
+
export function isBareSpecifier(specifier) {
|
|
8
|
+
if (specifier.startsWith('.'))
|
|
9
|
+
return false;
|
|
10
|
+
if (specifier.startsWith('/'))
|
|
11
|
+
return false;
|
|
12
|
+
if (specifier.includes('://'))
|
|
13
|
+
return false;
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
export function isProjectAliasSpecifier(specifier, projectRoot) {
|
|
17
|
+
if (specifier.startsWith('ecopages:')) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (projectRoot) {
|
|
21
|
+
return matchesTsconfigPathPrefix(specifier, loadTsconfigPathPrefixes(projectRoot));
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Determines whether a specifier should be treated as server-only.
|
|
27
|
+
*
|
|
28
|
+
* This covers Node built-ins as well as local module conventions such as
|
|
29
|
+
* `.server.ts` and extensionless imports that resolve to `.server.*` files.
|
|
30
|
+
*
|
|
31
|
+
* @param specifier - Raw import specifier from the module source.
|
|
32
|
+
* @returns True when the import must never become client-reachable.
|
|
33
|
+
*/
|
|
34
|
+
export function isServerOnlySpecifier(specifier) {
|
|
35
|
+
if (specifier.startsWith('node:'))
|
|
36
|
+
return true;
|
|
37
|
+
return /(?:^|[/])[^/]+\.server(?:$|\.)/.test(specifier);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Strips down a deep path module specifier to its foundational root package name.
|
|
41
|
+
*
|
|
42
|
+
* When checking against the "allowed modules" whitelist, a component might import something deeply
|
|
43
|
+
* nested like `lodash/fp/map` or `@myorg/ui/button`. However, the user configuration only whitelists
|
|
44
|
+
* the root `lodash` or `@myorg/ui` package. This normalizer ensures we are comparing apples to apples
|
|
45
|
+
* by extracting the base package scope before checking the authorization list.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* toModuleBaseSpecifier('@scope/package/deep/file') -> '@scope/package'
|
|
49
|
+
* toModuleBaseSpecifier('lodash/cloneDeep') -> 'lodash'
|
|
50
|
+
* toModuleBaseSpecifier('node:fs') -> 'node:fs'
|
|
51
|
+
*
|
|
52
|
+
* @param specifier - The raw import specifier from the code.
|
|
53
|
+
* @returns The root package name, preserving scoped npm organizations.
|
|
54
|
+
*/
|
|
55
|
+
export function toModuleBaseSpecifier(specifier) {
|
|
56
|
+
return toPackageRootSpecifier(specifier);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Parses the grammar syntax of declared modules.
|
|
60
|
+
* Handles patterns like `@pkg/name` and `@pkg/name{namedImport,anotherImport}`
|
|
61
|
+
* returning a map of base packages to their explicitly allowed specifiers.
|
|
62
|
+
*
|
|
63
|
+
* @param moduleDeclarations - A list of module declaration strings.
|
|
64
|
+
* @returns A structured map of allowed packages and their named exports.
|
|
65
|
+
*/
|
|
66
|
+
export function parseDeclaredModules(moduleDeclarations) {
|
|
67
|
+
const map = new Map();
|
|
68
|
+
for (const declaration of moduleDeclarations ?? []) {
|
|
69
|
+
const source = declaration.trim();
|
|
70
|
+
if (source.length === 0)
|
|
71
|
+
continue;
|
|
72
|
+
const openBraceIndex = source.indexOf('{');
|
|
73
|
+
if (openBraceIndex < 0) {
|
|
74
|
+
map.set(toModuleBaseSpecifier(source), '*');
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const closeBraceIndex = source.indexOf('}', openBraceIndex);
|
|
78
|
+
const rawPkg = source.slice(0, openBraceIndex).trim();
|
|
79
|
+
if (rawPkg.length === 0)
|
|
80
|
+
continue;
|
|
81
|
+
const pkg = toModuleBaseSpecifier(rawPkg);
|
|
82
|
+
const namedImportsStr = closeBraceIndex > openBraceIndex
|
|
83
|
+
? source.slice(openBraceIndex + 1, closeBraceIndex)
|
|
84
|
+
: source.slice(openBraceIndex + 1);
|
|
85
|
+
const namedImports = namedImportsStr
|
|
86
|
+
.split(',')
|
|
87
|
+
.map((s) => s.trim())
|
|
88
|
+
.filter(Boolean);
|
|
89
|
+
const existing = map.get(pkg);
|
|
90
|
+
if (existing === '*')
|
|
91
|
+
continue;
|
|
92
|
+
if (!existing) {
|
|
93
|
+
if (namedImports.length === 0) {
|
|
94
|
+
map.set(pkg, '*');
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
map.set(pkg, new Set(namedImports));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
for (const name of namedImports) {
|
|
102
|
+
existing.add(name);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return map;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Merges two declared module maps, combining their allowable specific scopes.
|
|
110
|
+
*
|
|
111
|
+
* @param a - First map of declared modules.
|
|
112
|
+
* @param b - Second map of declared modules to merge into the first.
|
|
113
|
+
* @returns A unified map of both declarations.
|
|
114
|
+
*/
|
|
115
|
+
export function mergeDeclaredModulesMap(a, b) {
|
|
116
|
+
const result = new Map(a);
|
|
117
|
+
for (const [pkg, imports] of b.entries()) {
|
|
118
|
+
const existing = result.get(pkg);
|
|
119
|
+
if (existing === '*')
|
|
120
|
+
continue;
|
|
121
|
+
if (imports === '*') {
|
|
122
|
+
result.set(pkg, '*');
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (!existing) {
|
|
126
|
+
result.set(pkg, imports);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
for (const name of imports) {
|
|
130
|
+
existing.add(name);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
export function normalizeRequestedExportsKey(pathname) {
|
|
137
|
+
let normalized = pathname.replace(/\\/g, '/');
|
|
138
|
+
normalized = normalized.replace(/\.(tsx?|jsx?)$/i, '');
|
|
139
|
+
if (normalized.endsWith('/index')) {
|
|
140
|
+
normalized = normalized.slice(0, -'/index'.length);
|
|
141
|
+
}
|
|
142
|
+
return normalized;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Resolves a local import specifier into a requested-export registry key.
|
|
146
|
+
*
|
|
147
|
+
* Bare package specifiers and project aliases are intentionally ignored because
|
|
148
|
+
* requested-export propagation is only used for cross-file local reachability.
|
|
149
|
+
*
|
|
150
|
+
* @param importer - Absolute path of the importing module.
|
|
151
|
+
* @param specifier - Raw import or re-export specifier.
|
|
152
|
+
* @returns Registry key for a local dependency, or `undefined` when not applicable.
|
|
153
|
+
*/
|
|
154
|
+
export function resolveRequestedExportsKey(importer, specifier) {
|
|
155
|
+
if (isBareSpecifier(specifier) || isProjectAliasSpecifier(specifier)) {
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
const resolved = specifier.startsWith('/') ? specifier : resolve(dirname(importer), specifier);
|
|
159
|
+
return normalizeRequestedExportsKey(resolved);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Merges newly discovered requested-export rules into the local propagation registry.
|
|
163
|
+
*
|
|
164
|
+
* Once a module is promoted to `'*'`, it stays fully reachable for the remainder
|
|
165
|
+
* of the transform pass.
|
|
166
|
+
*
|
|
167
|
+
* @param registry - Cross-module requested-export registry.
|
|
168
|
+
* @param moduleKey - Normalized local module key.
|
|
169
|
+
* @param rules - Newly observed reachable export rules for the module.
|
|
170
|
+
*/
|
|
171
|
+
export function mergeRequestedExportRules(registry, moduleKey, rules) {
|
|
172
|
+
const existing = registry.get(moduleKey);
|
|
173
|
+
if (existing === '*')
|
|
174
|
+
return;
|
|
175
|
+
if (rules === '*') {
|
|
176
|
+
registry.set(moduleKey, '*');
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (!existing) {
|
|
180
|
+
registry.set(moduleKey, new Set(rules));
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
for (const rule of rules) {
|
|
184
|
+
existing.add(rule);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function cloneRequestedExportRules(rules) {
|
|
188
|
+
return rules === '*' ? rules : new Set(rules);
|
|
189
|
+
}
|
|
190
|
+
export function snapshotRegistry(registry) {
|
|
191
|
+
const out = new Map();
|
|
192
|
+
for (const [key, rules] of registry) {
|
|
193
|
+
out.set(key, cloneRequestedExportRules(rules));
|
|
194
|
+
}
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
197
|
+
export function diffRequestedExportRules(before, after) {
|
|
198
|
+
if (!before) {
|
|
199
|
+
return cloneRequestedExportRules(after);
|
|
200
|
+
}
|
|
201
|
+
if (before === '*') {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
if (after === '*') {
|
|
205
|
+
return '*';
|
|
206
|
+
}
|
|
207
|
+
const addedRules = new Set();
|
|
208
|
+
for (const rule of after) {
|
|
209
|
+
if (!before.has(rule)) {
|
|
210
|
+
addedRules.add(rule);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return addedRules.size > 0 ? addedRules : undefined;
|
|
214
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EcoBuildPlugin } from '@ecopages/core/plugins/integration-plugin';
|
|
2
|
+
import type { DevTransformBundleContributor } from '@ecopages/core/dev/transform-server';
|
|
3
|
+
import type { ReactHmrStrategy } from '../hmr/hmr-strategy.js';
|
|
4
|
+
export type ReactDevTransformContributorOptions = {
|
|
5
|
+
strategy: ReactHmrStrategy;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Supplies React module plugins for the core dev transform bundler.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ReactDevTransformContributor implements DevTransformBundleContributor {
|
|
11
|
+
private readonly strategy;
|
|
12
|
+
constructor(options: ReactDevTransformContributorOptions);
|
|
13
|
+
ownsModule(sourcePath: string): boolean;
|
|
14
|
+
getModulePlugins(sourcePath: string): Promise<readonly EcoBuildPlugin[]>;
|
|
15
|
+
getRuntimeSpecifierMap(): ReadonlyMap<string, string>;
|
|
16
|
+
getVendorBundlePlugins(): Promise<readonly EcoBuildPlugin[]>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getBrowserRuntimeSpecifierMap } from '@ecopages/core/build/browser-runtime-manifest';
|
|
2
|
+
/**
|
|
3
|
+
* Supplies React module plugins for the core dev transform bundler.
|
|
4
|
+
*/
|
|
5
|
+
export class ReactDevTransformContributor {
|
|
6
|
+
strategy;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.strategy = options.strategy;
|
|
9
|
+
}
|
|
10
|
+
ownsModule(sourcePath) {
|
|
11
|
+
return this.strategy.ownsDevTransformEntrypoint(sourcePath);
|
|
12
|
+
}
|
|
13
|
+
async getModulePlugins(sourcePath) {
|
|
14
|
+
return this.strategy.createDevTransformPlugins(sourcePath);
|
|
15
|
+
}
|
|
16
|
+
getRuntimeSpecifierMap() {
|
|
17
|
+
return getBrowserRuntimeSpecifierMap(this.strategy.getRuntimeManifest());
|
|
18
|
+
}
|
|
19
|
+
async getVendorBundlePlugins() {
|
|
20
|
+
return this.strategy.getVendorBundlePlugins();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HMR script utilities for React components.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/** Marker comment to identify already-processed HMR code */
|
|
6
|
+
const HMR_MARKER = '/* [ecopages] react-hmr */';
|
|
7
|
+
/**
|
|
8
|
+
* Checks if code has already been processed with HMR marker.
|
|
9
|
+
* @param code - The bundled code to check
|
|
10
|
+
* @returns True if the code already contains the HMR marker
|
|
11
|
+
*/
|
|
12
|
+
export function hasHmrMarker(code) {
|
|
13
|
+
return code.includes(HMR_MARKER);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Injects HMR acceptance handler into bundled code.
|
|
17
|
+
* When a module with React exports changes, it triggers a full invalidation
|
|
18
|
+
* to ensure the parent module re-imports and re-renders with the updated component.
|
|
19
|
+
* @param code - The bundled code to wrap
|
|
20
|
+
* @returns Code with HMR handler injected
|
|
21
|
+
*/
|
|
22
|
+
export function injectHmrHandler(code) {
|
|
23
|
+
return `${HMR_MARKER}
|
|
24
|
+
${code}
|
|
25
|
+
if (import.meta.hot) {
|
|
26
|
+
import.meta.hot.accept((newModule) => {
|
|
27
|
+
if (newModule) {
|
|
28
|
+
const exports = Object.keys(newModule);
|
|
29
|
+
const hasReactExport = exports.some(key => {
|
|
30
|
+
const value = newModule[key];
|
|
31
|
+
return value && (
|
|
32
|
+
typeof value === 'function' ||
|
|
33
|
+
(typeof value === 'object' && value.$$typeof)
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (hasReactExport) {
|
|
38
|
+
import.meta.hot.invalidate();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React HMR Strategy
|
|
3
|
+
*
|
|
4
|
+
* Handles hot module replacement for React components.
|
|
5
|
+
* Triggers module invalidation on changes to ensure fresh component re-renders.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { HmrStrategy, type HmrAction } from '@ecopages/core/hmr/hmr-strategy';
|
|
10
|
+
import type { EcoBuildPlugin } from '@ecopages/core/plugins/integration-plugin';
|
|
11
|
+
import type { BrowserRuntimeManifest } from '@ecopages/core/build/browser-runtime-manifest';
|
|
12
|
+
import type { DefaultHmrContext } from '@ecopages/core';
|
|
13
|
+
import type { CompileOptions } from '@mdx-js/mdx';
|
|
14
|
+
import { ClientGraphBoundaryCache } from '../client-graph/boundary-cache.js';
|
|
15
|
+
import type { HmrPageMetadataCache } from './page-metadata-cache.js';
|
|
16
|
+
export interface ReactHmrStrategyOptions {
|
|
17
|
+
context: DefaultHmrContext;
|
|
18
|
+
pageMetadataCache: HmrPageMetadataCache;
|
|
19
|
+
runtimeManifest: BrowserRuntimeManifest;
|
|
20
|
+
mdxCompilerOptions?: CompileOptions;
|
|
21
|
+
ownedTemplateExtensions?: string[];
|
|
22
|
+
allTemplateExtensions?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Per-app cache for client-graph-boundary transform results. Owned by
|
|
25
|
+
* the React plugin for the app's lifetime. When omitted, the strategy
|
|
26
|
+
* uses a fresh in-memory cache that does not persist across HMR
|
|
27
|
+
* rebuilds.
|
|
28
|
+
*/
|
|
29
|
+
clientGraphBoundaryCache?: ClientGraphBoundaryCache;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Strategy for handling React component HMR updates.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ReactHmrStrategy extends HmrStrategy {
|
|
35
|
+
readonly type: 100;
|
|
36
|
+
private mdxCompilerOptions?;
|
|
37
|
+
private readonly ownedTemplateExtensions;
|
|
38
|
+
private readonly allTemplateExtensions;
|
|
39
|
+
private readonly context;
|
|
40
|
+
private readonly pageMetadataCache;
|
|
41
|
+
private readonly runtimeManifest;
|
|
42
|
+
private readonly clientGraphBoundaryCache;
|
|
43
|
+
private importNodePageModule;
|
|
44
|
+
private getDevTransformPluginOptions;
|
|
45
|
+
constructor(options: ReactHmrStrategyOptions);
|
|
46
|
+
private getBuildPlugins;
|
|
47
|
+
private isReactEntrypoint;
|
|
48
|
+
/**
|
|
49
|
+
* @remarks
|
|
50
|
+
* React integration owns plain `.tsx` route templates. Compound extensions in
|
|
51
|
+
* pages/layouts are integration-specific route templates and should not be
|
|
52
|
+
* claimed by React HMR strategy.
|
|
53
|
+
*/
|
|
54
|
+
private isRouteTemplate;
|
|
55
|
+
private resolveTemplateExtension;
|
|
56
|
+
private isDevTransformOutputUrl;
|
|
57
|
+
private queueDevTransformOutputUpdates;
|
|
58
|
+
private ownsWatchedEntrypoint;
|
|
59
|
+
private configContainsFile;
|
|
60
|
+
private pageModuleRequiresLayoutRefresh;
|
|
61
|
+
private hasLayoutOwnedDependencyTarget;
|
|
62
|
+
matches(filePath: string): boolean;
|
|
63
|
+
ownsDevTransformEntrypoint(sourcePath: string): boolean;
|
|
64
|
+
getRuntimeManifest(): BrowserRuntimeManifest;
|
|
65
|
+
getVendorBundlePlugins(): Promise<readonly EcoBuildPlugin[]>;
|
|
66
|
+
createDevTransformPlugins(sourcePath: string): Promise<EcoBuildPlugin[]>;
|
|
67
|
+
private isLayoutFile;
|
|
68
|
+
private isPageEntrypoint;
|
|
69
|
+
private resolveEntrypointOutputUrl;
|
|
70
|
+
private collectReactPageBuildTargets;
|
|
71
|
+
private resolveBuildTargets;
|
|
72
|
+
private partitionBuildTargets;
|
|
73
|
+
process(_filePath: string): Promise<HmrAction>;
|
|
74
|
+
}
|