@ecopages/react 0.6.1 → 0.7.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 +50 -87
- package/package.json +32 -14
- package/src/bundling/bootstrap-package-paths.d.ts +13 -1
- package/src/bundling/bootstrap-package-paths.js +25 -3
- package/src/bundling/bundle.d.ts +8 -36
- package/src/bundling/bundle.js +42 -73
- package/src/client-graph/ast-transform-eco-page.d.ts +10 -6
- package/src/client-graph/ast-transform-eco-page.js +56 -35
- package/src/client-graph/ast-transform-import-edits.d.ts +10 -2
- package/src/client-graph/ast-transform-import-edits.js +36 -6
- package/src/client-graph/ast-transform-stripped-imports.d.ts +37 -0
- package/src/client-graph/ast-transform-stripped-imports.js +191 -0
- package/src/client-graph/ast-transform-walk-imports.d.ts +4 -0
- package/src/client-graph/ast-transform-walk-imports.js +15 -1
- package/src/client-graph/ast-transform.d.ts +12 -3
- package/src/client-graph/ast-transform.js +41 -56
- package/src/client-graph/boundary-plugin-read-file-inline.d.ts +3 -0
- package/src/client-graph/boundary-plugin-read-file-inline.js +14 -10
- package/src/client-graph/boundary-plugin-transform.d.ts +5 -4
- package/src/client-graph/boundary-plugin-transform.js +6 -13
- package/src/client-graph/boundary-plugin.d.ts +47 -1
- package/src/client-graph/boundary-plugin.js +267 -53
- package/src/client-graph/foreign-boundary-rewrite.d.ts +31 -0
- package/src/client-graph/foreign-boundary-rewrite.js +360 -0
- package/src/client-graph/foreign-jsx-reach.d.ts +25 -0
- package/src/client-graph/foreign-jsx-reach.js +68 -0
- package/src/client-graph/module-classification.js +3 -10
- package/src/client-graph/reachability-traverse.js +35 -105
- package/src/client-graph/requested-exports-plan.d.ts +62 -0
- package/src/client-graph/requested-exports-plan.js +125 -0
- package/src/client-graph/scope-walk.d.ts +37 -0
- package/src/client-graph/scope-walk.js +407 -0
- package/src/client-graph/specifier-classification.d.ts +2 -1
- package/src/client-graph/specifier-classification.js +9 -7
- package/src/contracts/router-adapter.d.ts +9 -24
- package/src/dev-transform/react-dev-transform-contributor.d.ts +4 -4
- package/src/dev-transform/react-dev-transform-contributor.js +6 -7
- package/src/hmr/hmr-strategy-process.d.ts +7 -5
- package/src/hmr/hmr-strategy-process.js +21 -16
- package/src/hmr/hmr-strategy.d.ts +11 -10
- package/src/hmr/hmr-strategy.js +32 -53
- package/src/hmr/page-metadata-cache.js +1 -1
- package/src/hydration/browser/foreign-boundary.d.ts +29 -0
- package/src/hydration/browser/foreign-boundary.js +128 -0
- package/src/hydration/browser/island-hydration.d.ts +3 -4
- package/src/hydration/browser/island-hydration.js +3 -4
- package/src/hydration/browser/page-hydration-hmr.d.ts +8 -7
- package/src/hydration/browser/page-hydration-hmr.js +53 -10
- package/src/hydration/browser/page-hydration.d.ts +6 -5
- package/src/hydration/browser/page-hydration.js +8 -6
- package/src/hydration/foreign-subtree.d.ts +27 -0
- package/src/hydration/foreign-subtree.js +69 -0
- package/src/hydration/hydration-asset.d.ts +37 -29
- package/src/hydration/hydration-asset.js +74 -138
- package/src/hydration/hydration-island-entry-source.d.ts +17 -0
- package/src/hydration/hydration-island-entry-source.js +32 -0
- package/src/hydration/hydration-page-entry-source.d.ts +20 -2
- package/src/hydration/hydration-page-entry-source.js +17 -12
- package/src/hydration/page-data-reader.d.ts +4 -7
- package/src/hydration/page-data-reader.js +5 -10
- package/src/mdx/mdx-config-dependency.d.ts +10 -15
- package/src/mdx/mdx-config-dependency.js +9 -22
- package/src/mdx/mdx-loader-plugin.d.ts +2 -0
- package/src/mdx/mdx-loader-plugin.js +1 -0
- package/src/page/page-module.js +1 -1
- package/src/plugin/react.plugin.d.ts +0 -7
- package/src/plugin/react.plugin.js +4 -33
- package/src/plugin/react.types.d.ts +0 -29
- package/src/render/component-ssr.d.ts +18 -0
- package/src/render/component-ssr.js +37 -0
- package/src/render/layout-compose.d.ts +4 -2
- package/src/render/layout-compose.js +13 -6
- package/src/render/layout-render-tracker.d.ts +20 -0
- package/src/render/layout-render-tracker.js +33 -0
- package/src/render/react-renderer.d.ts +28 -10
- package/src/render/react-renderer.js +103 -38
- package/src/render/react-runtime.js +2 -2
- package/src/bundling/runtime-alias-map.d.ts +0 -12
- package/src/bundling/runtime-alias-map.js +0 -110
- package/src/bundling/runtime-bundle.d.ts +0 -70
- package/src/bundling/runtime-bundle.js +0 -233
- package/src/bundling/runtime-interop-plugin.d.ts +0 -5
- package/src/bundling/runtime-interop-plugin.js +0 -32
- package/src/bundling/runtime-mode.d.ts +0 -1
- package/src/bundling/runtime-mode.js +0 -10
- package/src/bundling/runtime-modules.d.ts +0 -21
- package/src/bundling/runtime-modules.js +0 -28
- package/src/hydration/bootstrap-imports.d.ts +0 -25
- package/src/hydration/bootstrap-imports.js +0 -33
- package/src/hydration/compiled-page-hydration-options.d.ts +0 -19
- package/src/hydration/compiled-page-hydration-options.js +0 -1
- package/src/hydration/hydration-script-compiler.d.ts +0 -47
- package/src/hydration/hydration-script-compiler.js +0 -213
- package/src/runtime/use-sync-external-store-with-selector.d.ts +0 -3
- package/src/runtime/use-sync-external-store-with-selector.js +0 -54
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from 'node:url';
|
|
2
|
-
import { fileSystem } from '@ecopages/file-system';
|
|
3
|
-
import { rolldown } from 'rolldown';
|
|
4
|
-
const ISLAND_BOOTSTRAP_ID = '\0ecopages-react-island-bootstrap';
|
|
5
|
-
const PAGE_BOOTSTRAP_ID = '\0ecopages-react-page-bootstrap';
|
|
6
|
-
const PAGE_HYDRATION_MODULE_ID = '\0ecopages-react-page-hydration-module';
|
|
7
|
-
const PAGE_HYDRATION_HMR_ID = '\0ecopages-react-page-hydration-hmr';
|
|
8
|
-
const PAGE_DATA_READER_ID = '\0ecopages-react-page-data-reader';
|
|
9
|
-
const PAGE_DATA_MANIFEST_ID = '\0ecopages-react-page-data-manifest';
|
|
10
|
-
import { createPageEntrySource } from './hydration-page-entry-source.js';
|
|
11
|
-
/** Serializes every compilation input so source/config changes cannot reuse stale output. */
|
|
12
|
-
function getCacheKey(options) {
|
|
13
|
-
return JSON.stringify(options);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Creates the small Island Host entry that imports application modules and
|
|
17
|
-
* delegates lifecycle behavior to the typed browser bootstrap.
|
|
18
|
-
*/
|
|
19
|
-
function createEntrySource(options) {
|
|
20
|
-
const hmrSource = options.hmrEnabled
|
|
21
|
-
? `registerIslandHmr(configuration, (url) => import(url), ${JSON.stringify(options.importPath)});`
|
|
22
|
-
: '';
|
|
23
|
-
return `
|
|
24
|
-
import { hydrateRoot } from ${JSON.stringify(options.reactDomClientImportPath)};
|
|
25
|
-
import { createElement, useEffect } from ${JSON.stringify(options.reactImportPath)};
|
|
26
|
-
import * as ComponentModule from ${JSON.stringify(options.importPath)};
|
|
27
|
-
import { getIslandHydrationRuntime, mountIslands, registerIslandHmr } from ${JSON.stringify(ISLAND_BOOTSTRAP_ID)};
|
|
28
|
-
|
|
29
|
-
const configuration = {
|
|
30
|
-
targetSelector: ${JSON.stringify(options.targetSelector)},
|
|
31
|
-
componentModule: ComponentModule,
|
|
32
|
-
componentRef: ${JSON.stringify(options.componentRef ?? '')},
|
|
33
|
-
scriptId: ${JSON.stringify(options.scriptId)},
|
|
34
|
-
runtime: { hydrateRoot, createElement, useEffect },
|
|
35
|
-
runtimeState: getIslandHydrationRuntime()
|
|
36
|
-
};
|
|
37
|
-
const mount = () => mountIslands(configuration);
|
|
38
|
-
${hmrSource}
|
|
39
|
-
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", mount, { once: true }) : mount();
|
|
40
|
-
`;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Resolves framework browser sources from repository TypeScript or published
|
|
44
|
-
* JavaScript files while keeping application and vendor modules external.
|
|
45
|
-
*/
|
|
46
|
-
function createBootstrapPlugin() {
|
|
47
|
-
const sourcePaths = new Map([
|
|
48
|
-
[ISLAND_BOOTSTRAP_ID, ['island-hydration.ts', 'island-hydration.js']],
|
|
49
|
-
[PAGE_BOOTSTRAP_ID, ['page-hydration.ts', 'page-hydration.js']],
|
|
50
|
-
[PAGE_HYDRATION_MODULE_ID, ['page-hydration-module.ts', 'page-hydration-module.js']],
|
|
51
|
-
[PAGE_HYDRATION_HMR_ID, ['page-hydration-hmr.ts', 'page-hydration-hmr.js']],
|
|
52
|
-
[PAGE_DATA_READER_ID, ['../page-data-reader.js', '../page-data-reader.js']],
|
|
53
|
-
]);
|
|
54
|
-
const readBootstrapSource = (id) => {
|
|
55
|
-
const candidates = sourcePaths.get(id);
|
|
56
|
-
if (!candidates)
|
|
57
|
-
throw new Error(`Unknown hydration bootstrap module: ${id}`);
|
|
58
|
-
for (const relativePath of candidates) {
|
|
59
|
-
try {
|
|
60
|
-
return fileSystem.readFileSync(fileURLToPath(new URL(`./browser/${relativePath}`, import.meta.url)));
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
throw new Error(`Unable to locate hydration bootstrap source for ${id}`);
|
|
67
|
-
};
|
|
68
|
-
const pageBootstrapRelativeImports = new Map([
|
|
69
|
-
['./page-hydration-module.js', PAGE_HYDRATION_MODULE_ID],
|
|
70
|
-
['./page-hydration-hmr.js', PAGE_HYDRATION_HMR_ID],
|
|
71
|
-
]);
|
|
72
|
-
return {
|
|
73
|
-
name: 'ecopages-react-hydration-bootstrap',
|
|
74
|
-
resolveId(source, importer) {
|
|
75
|
-
if (sourcePaths.has(source))
|
|
76
|
-
return source;
|
|
77
|
-
if (importer === PAGE_DATA_READER_ID && source === './page-data-manifest.js') {
|
|
78
|
-
return PAGE_DATA_MANIFEST_ID;
|
|
79
|
-
}
|
|
80
|
-
if (importer && pageBootstrapRelativeImports.has(source)) {
|
|
81
|
-
if (importer === PAGE_BOOTSTRAP_ID || importer === PAGE_HYDRATION_HMR_ID) {
|
|
82
|
-
return pageBootstrapRelativeImports.get(source);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return undefined;
|
|
86
|
-
},
|
|
87
|
-
load(id) {
|
|
88
|
-
if (id === PAGE_DATA_MANIFEST_ID) {
|
|
89
|
-
return {
|
|
90
|
-
code: fileSystem.readFileSync(fileURLToPath(new URL('./page-data-manifest.js', import.meta.url))),
|
|
91
|
-
moduleType: 'ts',
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
if (!sourcePaths.has(id))
|
|
95
|
-
return undefined;
|
|
96
|
-
return { code: readBootstrapSource(id), moduleType: 'ts' };
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
/** Bundles one virtual entry and closes the Rolldown bundle after generation. */
|
|
101
|
-
async function compileEntry(options) {
|
|
102
|
-
const bundle = await rolldown({
|
|
103
|
-
input: options.entryId,
|
|
104
|
-
plugins: [
|
|
105
|
-
{
|
|
106
|
-
name: 'ecopages-react-entry',
|
|
107
|
-
resolveId(source) {
|
|
108
|
-
return source === options.entryId ? source : undefined;
|
|
109
|
-
},
|
|
110
|
-
load(id) {
|
|
111
|
-
return id === options.entryId ? { code: options.entrySource, moduleType: 'js' } : undefined;
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
createBootstrapPlugin(),
|
|
115
|
-
],
|
|
116
|
-
external: options.external,
|
|
117
|
-
transform: { target: 'es2021' },
|
|
118
|
-
});
|
|
119
|
-
try {
|
|
120
|
-
const generated = await bundle.generate({ format: 'esm', minify: options.minify });
|
|
121
|
-
const chunk = generated.output.find((output) => output.type === 'chunk');
|
|
122
|
-
if (!chunk || !('code' in chunk))
|
|
123
|
-
throw new Error(options.errorMessage);
|
|
124
|
-
return chunk.code ?? '';
|
|
125
|
-
}
|
|
126
|
-
finally {
|
|
127
|
-
await bundle.close();
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/** Compiles an Island Host entry using the shared virtual-entry pipeline. */
|
|
131
|
-
function compileIsland(options) {
|
|
132
|
-
return compileEntry({
|
|
133
|
-
entryId: 'virtual:ecopages-react-island-entry',
|
|
134
|
-
entrySource: createEntrySource(options),
|
|
135
|
-
external: [options.importPath, options.reactImportPath, options.reactDomClientImportPath],
|
|
136
|
-
minify: options.minify,
|
|
137
|
-
errorMessage: 'React hydration compiler emitted no JavaScript chunk',
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
/** Compiles a Page entry using the shared virtual-entry pipeline. */
|
|
141
|
-
function compilePage(options) {
|
|
142
|
-
return compileEntry({
|
|
143
|
-
entryId: 'virtual:ecopages-react-page-entry',
|
|
144
|
-
entrySource: createPageEntrySource(options),
|
|
145
|
-
external: [
|
|
146
|
-
options.importPath,
|
|
147
|
-
options.reactImportPath,
|
|
148
|
-
options.reactDomClientImportPath,
|
|
149
|
-
options.routerImportPath,
|
|
150
|
-
options.layoutComposeImportPath,
|
|
151
|
-
options.pageLayoutNormalizationImportPath,
|
|
152
|
-
].filter((value) => Boolean(value)),
|
|
153
|
-
minify: options.minify,
|
|
154
|
-
errorMessage: 'React page hydration compiler emitted no JavaScript chunk',
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
/** Caches in-flight and completed compilations while evicting rejected work. */
|
|
158
|
-
class CompilationCache {
|
|
159
|
-
entries = new Map();
|
|
160
|
-
/** Returns a cached compilation or starts exactly one compilation for the key. */
|
|
161
|
-
getOrCompile(key, factory) {
|
|
162
|
-
const cached = this.entries.get(key);
|
|
163
|
-
if (cached)
|
|
164
|
-
return cached;
|
|
165
|
-
const pending = factory();
|
|
166
|
-
this.entries.set(key, pending);
|
|
167
|
-
pending.then(() => undefined, () => {
|
|
168
|
-
if (this.entries.get(key) === pending)
|
|
169
|
-
this.entries.delete(key);
|
|
170
|
-
});
|
|
171
|
-
return pending;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Compiles the editable React Island Host lifecycle into a browser ESM string.
|
|
176
|
-
*
|
|
177
|
-
* @remarks
|
|
178
|
-
* Compilation is cached by the complete entry configuration. Rejected promises
|
|
179
|
-
* are removed so a transient filesystem or bundler error can recover.
|
|
180
|
-
*/
|
|
181
|
-
export class IslandHydrationScriptCompiler {
|
|
182
|
-
compilationCache = new CompilationCache();
|
|
183
|
-
/**
|
|
184
|
-
* Compiles and caches one readable or minified Island Host entry.
|
|
185
|
-
*
|
|
186
|
-
* @param options - Complete entry imports, selector, identity, and output mode.
|
|
187
|
-
* @returns A browser ESM source string.
|
|
188
|
-
*/
|
|
189
|
-
compile(options) {
|
|
190
|
-
const key = getCacheKey(options);
|
|
191
|
-
return this.compilationCache.getOrCompile(key, () => compileIsland(options));
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Compiles editable Page lifecycle modules into browser ESM strings.
|
|
196
|
-
*
|
|
197
|
-
* @remarks
|
|
198
|
-
* The cache belongs to the service instance, allowing development restarts to
|
|
199
|
-
* discard framework-source changes without sharing stale output globally.
|
|
200
|
-
*/
|
|
201
|
-
export class PageHydrationScriptCompiler {
|
|
202
|
-
compilationCache = new CompilationCache();
|
|
203
|
-
/**
|
|
204
|
-
* Compiles and caches one readable or minified Page entry.
|
|
205
|
-
*
|
|
206
|
-
* @param options - Complete page imports, router contract, and output mode.
|
|
207
|
-
* @returns A browser ESM source string.
|
|
208
|
-
*/
|
|
209
|
-
compile(options) {
|
|
210
|
-
const key = getCacheKey(options);
|
|
211
|
-
return this.compilationCache.getOrCompile(key, () => compilePage(options));
|
|
212
|
-
}
|
|
213
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
type Subscribe = (onStoreChange: () => void) => () => void;
|
|
2
|
-
export declare function useSyncExternalStoreWithSelector<Snapshot, Selection>(subscribe: Subscribe, getSnapshot: () => Snapshot, getServerSnapshot: (() => Snapshot) | undefined, selector: (snapshot: Snapshot) => Selection, isEqual?: (left: Selection, right: Selection) => boolean): Selection;
|
|
3
|
-
export {};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react-hooks/exhaustive-deps -- shim mirrors upstream ref-based hook semantics */
|
|
2
|
-
import { useDebugValue, useEffect, useMemo, useRef, useSyncExternalStore } from 'react';
|
|
3
|
-
const objectIs = Object.is;
|
|
4
|
-
export function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
5
|
-
const instRef = useRef({ hasValue: false, value: undefined });
|
|
6
|
-
const memoizedSelectionRef = useMemo(() => {
|
|
7
|
-
let hasMemo = false;
|
|
8
|
-
let memoizedSnapshot;
|
|
9
|
-
let memoizedSelection;
|
|
10
|
-
const maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;
|
|
11
|
-
const memoizedSelector = (nextSnapshot) => {
|
|
12
|
-
if (!hasMemo) {
|
|
13
|
-
hasMemo = true;
|
|
14
|
-
memoizedSnapshot = nextSnapshot;
|
|
15
|
-
const nextSelection = selector(nextSnapshot);
|
|
16
|
-
const inst = instRef.current;
|
|
17
|
-
if (isEqual !== undefined && inst.hasValue) {
|
|
18
|
-
const currentSelection = inst.value;
|
|
19
|
-
if (isEqual(currentSelection, nextSelection)) {
|
|
20
|
-
memoizedSelection = currentSelection;
|
|
21
|
-
return currentSelection;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
memoizedSelection = nextSelection;
|
|
25
|
-
return nextSelection;
|
|
26
|
-
}
|
|
27
|
-
const currentSelection = memoizedSelection;
|
|
28
|
-
if (objectIs(memoizedSnapshot, nextSnapshot)) {
|
|
29
|
-
return currentSelection;
|
|
30
|
-
}
|
|
31
|
-
const nextSelection = selector(nextSnapshot);
|
|
32
|
-
if (isEqual !== undefined && isEqual(currentSelection, nextSelection)) {
|
|
33
|
-
memoizedSnapshot = nextSnapshot;
|
|
34
|
-
return currentSelection;
|
|
35
|
-
}
|
|
36
|
-
memoizedSnapshot = nextSnapshot;
|
|
37
|
-
memoizedSelection = nextSelection;
|
|
38
|
-
return nextSelection;
|
|
39
|
-
};
|
|
40
|
-
return [
|
|
41
|
-
() => memoizedSelector(getSnapshot()),
|
|
42
|
-
maybeGetServerSnapshot === null ? undefined : () => memoizedSelector(maybeGetServerSnapshot()),
|
|
43
|
-
];
|
|
44
|
-
}, [getSnapshot, getServerSnapshot, selector, isEqual]);
|
|
45
|
-
const value = useSyncExternalStore(subscribe, memoizedSelectionRef[0], memoizedSelectionRef[1]);
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
instRef.current = {
|
|
48
|
-
hasValue: true,
|
|
49
|
-
value,
|
|
50
|
-
};
|
|
51
|
-
}, [value]);
|
|
52
|
-
useDebugValue(value);
|
|
53
|
-
return value;
|
|
54
|
-
}
|