@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,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hydration asset creation service for React integration.
|
|
3
|
+
*
|
|
4
|
+
* Builds the asset definitions required for client-side React rendering — both at
|
|
5
|
+
* the page level and the component island level.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { rapidhash } from '@ecopages/core/hash';
|
|
11
|
+
import { RESOLVED_ASSETS_DIR } from '@ecopages/core/constants';
|
|
12
|
+
import { isReactProductionRuntime } from '../bundling/runtime-mode.js';
|
|
13
|
+
import { AssetFactory, } from '@ecopages/core/services/asset-processing-service';
|
|
14
|
+
import { createHydrationScript, createIslandHydrationScript } from './hydration-scripts.js';
|
|
15
|
+
import { resolveHydrationBootstrapImports } from './bootstrap-imports.js';
|
|
16
|
+
import { collectDeclaredModulesInConfig } from '../client-graph/declared-modules.js';
|
|
17
|
+
export function getIslandComponentKey(componentFile, config) {
|
|
18
|
+
return rapidhash(`${componentFile}:${config?.identity?.id ?? ''}`).toString();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Manages the creation of client-side hydration assets for React pages and component islands.
|
|
22
|
+
*/
|
|
23
|
+
export class HydrationAssetService {
|
|
24
|
+
config;
|
|
25
|
+
static ROUTER_PAGE_GROUPED_BUNDLE_ID = 'ecopages-react-router-pages';
|
|
26
|
+
constructor(config) {
|
|
27
|
+
this.config = config;
|
|
28
|
+
}
|
|
29
|
+
getIslandBundleName(componentFile) {
|
|
30
|
+
return `ecopages-react-island-${rapidhash(componentFile)}`;
|
|
31
|
+
}
|
|
32
|
+
getIslandHydrationName(bundleName, componentKey) {
|
|
33
|
+
return `${bundleName}-hydration-${componentKey}`;
|
|
34
|
+
}
|
|
35
|
+
getRouterPageGroupedEntryName(pagePath) {
|
|
36
|
+
const relativePath = path.relative(this.config.srcDir, pagePath);
|
|
37
|
+
return relativePath
|
|
38
|
+
.replace(/\.(tsx?|jsx?|mdx?)$/, '')
|
|
39
|
+
.replace(/[\\/]+/g, '__')
|
|
40
|
+
.replace(/\[([^\]]+)\]/g, '_$1_');
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolves the browser import path used for a React-owned page or island module.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* When HMR is enabled, registers the source file as an HMR entrypoint and returns
|
|
47
|
+
* that URL. Otherwise returns the static resolved-assets path for the generated
|
|
48
|
+
* asset name.
|
|
49
|
+
*/
|
|
50
|
+
async resolveAssetImportPath(pagePath, assetName) {
|
|
51
|
+
const hmrManager = this.config.assetProcessingService?.getHmrManager();
|
|
52
|
+
if (hmrManager?.isEnabled()) {
|
|
53
|
+
return hmrManager.registerEntrypoint(pagePath);
|
|
54
|
+
}
|
|
55
|
+
return `/${path
|
|
56
|
+
.join(RESOLVED_ASSETS_DIR, path.relative(this.config.srcDir, pagePath))
|
|
57
|
+
.replace(path.basename(pagePath), `${assetName}.js`)
|
|
58
|
+
.replace(/\\/g, '/')}`;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates the page-owned route entry asset for hydration and client navigation.
|
|
62
|
+
*/
|
|
63
|
+
createPageDependencies(options) {
|
|
64
|
+
const { pagePath, componentName, importPath, pageModuleUrlExpression, bundleOptions, hmrEnabled, useBrowserRuntimeImports, isMdx, } = options;
|
|
65
|
+
const runtimeImports = this.config.bundleService.getRuntimeImports();
|
|
66
|
+
/**
|
|
67
|
+
* @remarks
|
|
68
|
+
* Production router pages share a grouped bundle. Development HMR keeps each
|
|
69
|
+
* page bootstrap independent and unbundled; shared helpers resolve via vendor URLs.
|
|
70
|
+
*/
|
|
71
|
+
const groupedBundle = !hmrEnabled && this.config.routerAdapter
|
|
72
|
+
? {
|
|
73
|
+
id: HydrationAssetService.ROUTER_PAGE_GROUPED_BUNDLE_ID,
|
|
74
|
+
entryName: this.getRouterPageGroupedEntryName(pagePath),
|
|
75
|
+
}
|
|
76
|
+
: undefined;
|
|
77
|
+
const bootstrapImports = resolveHydrationBootstrapImports({
|
|
78
|
+
useBrowserRuntimeImports,
|
|
79
|
+
runtimeImports,
|
|
80
|
+
routerAdapterImportPath: this.config.routerAdapter?.bundle.importPath,
|
|
81
|
+
});
|
|
82
|
+
return [
|
|
83
|
+
AssetFactory.createContentScript({
|
|
84
|
+
position: 'head',
|
|
85
|
+
content: createHydrationScript({
|
|
86
|
+
importPath: hmrEnabled ? importPath : pagePath,
|
|
87
|
+
pageModuleUrlExpression,
|
|
88
|
+
reactImportPath: bootstrapImports.reactImportPath,
|
|
89
|
+
reactDomClientImportPath: bootstrapImports.reactDomClientImportPath,
|
|
90
|
+
routerImportPath: bootstrapImports.routerImportPath,
|
|
91
|
+
layoutComposeImportPath: bootstrapImports.layoutComposeImportPath,
|
|
92
|
+
pageLayoutNormalizationImportPath: bootstrapImports.pageLayoutNormalizationImportPath,
|
|
93
|
+
hmrEnabled,
|
|
94
|
+
isMdx,
|
|
95
|
+
router: this.config.routerAdapter,
|
|
96
|
+
scriptId: componentName,
|
|
97
|
+
}),
|
|
98
|
+
name: componentName,
|
|
99
|
+
packageRole: 'page-script',
|
|
100
|
+
/**
|
|
101
|
+
* @remarks
|
|
102
|
+
* HMR bootstraps stay unbundled write-through ESM. Helper imports must
|
|
103
|
+
* already be browser-resolvable vendor URLs from
|
|
104
|
+
* {@link resolveHydrationBootstrapImports}.
|
|
105
|
+
*/
|
|
106
|
+
bundle: !hmrEnabled,
|
|
107
|
+
groupedBundle,
|
|
108
|
+
bundleOptions,
|
|
109
|
+
attributes: {
|
|
110
|
+
type: 'module',
|
|
111
|
+
defer: '',
|
|
112
|
+
'data-eco-rerun': 'true',
|
|
113
|
+
'data-eco-script-id': componentName,
|
|
114
|
+
...(this.config.routerAdapter ? { 'data-eco-page-bootstrap': 'react-router' } : {}),
|
|
115
|
+
'data-eco-persist': 'true',
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Builds client-side assets for a React component island.
|
|
122
|
+
*
|
|
123
|
+
* Includes the bundled component entry and a shared hydration bootstrap script.
|
|
124
|
+
*
|
|
125
|
+
* @param componentFile - Absolute path to the component source file
|
|
126
|
+
* @param config - Optional component config with identity attribution
|
|
127
|
+
* @returns Processed assets ready for injection
|
|
128
|
+
*/
|
|
129
|
+
async buildComponentRenderAssets(componentFile, config) {
|
|
130
|
+
const componentName = this.getIslandBundleName(componentFile);
|
|
131
|
+
const componentKey = getIslandComponentKey(componentFile, config);
|
|
132
|
+
const hydrationName = this.getIslandHydrationName(componentName, componentKey);
|
|
133
|
+
const hmrManager = this.config.assetProcessingService?.getHmrManager();
|
|
134
|
+
const hmrEnabled = hmrManager?.isEnabled() ?? false;
|
|
135
|
+
if (hmrEnabled) {
|
|
136
|
+
this.config.hmrPageMetadataCache?.markOwnedEntrypoint(componentFile);
|
|
137
|
+
}
|
|
138
|
+
const importPath = await this.resolveAssetImportPath(componentFile, componentName);
|
|
139
|
+
const runtimeImports = this.config.bundleService.getRuntimeImports();
|
|
140
|
+
const islandHydrationScript = createIslandHydrationScript({
|
|
141
|
+
importPath,
|
|
142
|
+
scriptId: hydrationName,
|
|
143
|
+
reactImportPath: runtimeImports.react,
|
|
144
|
+
reactDomClientImportPath: runtimeImports.reactDomClient,
|
|
145
|
+
targetSelector: `[data-eco-component-key="${componentKey}"]`,
|
|
146
|
+
componentRef: config?.identity?.id,
|
|
147
|
+
componentFile,
|
|
148
|
+
minify: !hmrEnabled,
|
|
149
|
+
hmrEnabled,
|
|
150
|
+
});
|
|
151
|
+
const hydrationScript = AssetFactory.createContentScript({
|
|
152
|
+
position: 'head',
|
|
153
|
+
content: islandHydrationScript,
|
|
154
|
+
name: hydrationName,
|
|
155
|
+
packageRole: 'keep-separate',
|
|
156
|
+
bundle: false,
|
|
157
|
+
attributes: {
|
|
158
|
+
type: 'module',
|
|
159
|
+
defer: '',
|
|
160
|
+
'data-eco-rerun': 'true',
|
|
161
|
+
'data-eco-script-id': hydrationName,
|
|
162
|
+
'data-eco-persist': 'true',
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
const dependencies = [hydrationScript];
|
|
166
|
+
if (!hmrEnabled) {
|
|
167
|
+
const declaredModules = collectDeclaredModulesInConfig(config);
|
|
168
|
+
const bundleOptions = await this.config.bundleService.createBundleOptions(componentName, false, declaredModules);
|
|
169
|
+
dependencies.unshift(AssetFactory.createFileScript({
|
|
170
|
+
position: 'head',
|
|
171
|
+
filepath: componentFile,
|
|
172
|
+
name: componentName,
|
|
173
|
+
packageRole: 'dynamic-chunk',
|
|
174
|
+
excludeFromHtml: true,
|
|
175
|
+
bundle: true,
|
|
176
|
+
bundleOptions,
|
|
177
|
+
attributes: {
|
|
178
|
+
type: 'module',
|
|
179
|
+
defer: '',
|
|
180
|
+
'data-eco-persist': 'true',
|
|
181
|
+
},
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
if (!this.config.assetProcessingService) {
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
return this.config.assetProcessingService.processDependencies(dependencies, componentName);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Creates the page browser graph dependency declarations for a React page.
|
|
191
|
+
*
|
|
192
|
+
* @remarks
|
|
193
|
+
* Chooses shared vendor import URLs when HMR is on, when running a non-production
|
|
194
|
+
* hosted runtime with HMR off, or when a router adapter is configured (router
|
|
195
|
+
* pages always externalize to shared runtimes). Production non-router pages
|
|
196
|
+
* may inline React into the page bundle instead.
|
|
197
|
+
*
|
|
198
|
+
* @param pagePath - Absolute file path of the page
|
|
199
|
+
* @param isMdx - Whether the page is an MDX file
|
|
200
|
+
* @param declaredModules - Explicitly declared browser module specifiers
|
|
201
|
+
*/
|
|
202
|
+
async createPageBrowserGraphDependencies(pagePath, isMdx, declaredModules) {
|
|
203
|
+
const componentName = `ecopages-react-${rapidhash(pagePath)}`;
|
|
204
|
+
const hmrManager = this.config.assetProcessingService?.getHmrManager();
|
|
205
|
+
const hmrEnabled = hmrManager?.isEnabled() ?? false;
|
|
206
|
+
const productionRuntime = isReactProductionRuntime();
|
|
207
|
+
const usesRouterRuntime = Boolean(this.config.routerAdapter);
|
|
208
|
+
const useBrowserRuntimeImports = hmrEnabled || !productionRuntime || usesRouterRuntime;
|
|
209
|
+
if (hmrEnabled) {
|
|
210
|
+
this.config.hmrPageMetadataCache?.setDeclaredModules(pagePath, declaredModules);
|
|
211
|
+
}
|
|
212
|
+
const importPath = await this.resolveAssetImportPath(pagePath, componentName);
|
|
213
|
+
const pageModuleUrlExpression = hmrEnabled ? JSON.stringify(importPath) : 'import.meta.url';
|
|
214
|
+
const bundleOptions = await this.config.bundleService.createBundleOptions(componentName, isMdx, declaredModules, { includeRuntime: !useBrowserRuntimeImports, splitting: usesRouterRuntime });
|
|
215
|
+
const dependencies = this.createPageDependencies({
|
|
216
|
+
pagePath,
|
|
217
|
+
componentName,
|
|
218
|
+
importPath,
|
|
219
|
+
pageModuleUrlExpression,
|
|
220
|
+
bundleOptions,
|
|
221
|
+
hmrEnabled,
|
|
222
|
+
useBrowserRuntimeImports,
|
|
223
|
+
isMdx,
|
|
224
|
+
});
|
|
225
|
+
return dependencies;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hydration script generators for React pages.
|
|
3
|
+
* These functions create the page entry modules that hydrate React routes.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
|
|
7
|
+
/**
|
|
8
|
+
* Options for generating a hydration script.
|
|
9
|
+
*/
|
|
10
|
+
export type HydrationScriptOptions = {
|
|
11
|
+
/** The module path imported by the page entry module. */
|
|
12
|
+
importPath: string;
|
|
13
|
+
/** Browser expression that resolves to the page module URL the router should import. */
|
|
14
|
+
pageModuleUrlExpression?: string;
|
|
15
|
+
/** Stable id of the page entry script tag in the document. */
|
|
16
|
+
scriptId: string;
|
|
17
|
+
/** Direct import path for React runtime module */
|
|
18
|
+
reactImportPath: string;
|
|
19
|
+
/** Direct import path for react-dom/client runtime module */
|
|
20
|
+
reactDomClientImportPath: string;
|
|
21
|
+
/** Direct import path for router runtime module */
|
|
22
|
+
routerImportPath?: string;
|
|
23
|
+
/**
|
|
24
|
+
* When true, emit HMR registration and hot-reload handlers.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* HMR page bootstraps stay unbundled and evaluate as native browser ESM.
|
|
28
|
+
* Callers must supply browser-resolvable import paths (shared vendor URLs)
|
|
29
|
+
* so generated source does not emit bare `@ecopages/*` imports. When false,
|
|
30
|
+
* this generator emits the same readable bootstrap without HMR hooks.
|
|
31
|
+
*/
|
|
32
|
+
hmrEnabled: boolean;
|
|
33
|
+
/** Whether the source file is an MDX file */
|
|
34
|
+
isMdx: boolean;
|
|
35
|
+
/** Optional router adapter for SPA navigation */
|
|
36
|
+
router?: ReactRouterAdapter;
|
|
37
|
+
/**
|
|
38
|
+
* Import path for shared layout composition helper.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* Required so callers (not this generator) decide vendor URL vs bare package.
|
|
42
|
+
*/
|
|
43
|
+
layoutComposeImportPath: string;
|
|
44
|
+
/**
|
|
45
|
+
* Import path for MDX page layout normalization helper.
|
|
46
|
+
*
|
|
47
|
+
* @remarks
|
|
48
|
+
* Required so callers (not this generator) decide vendor URL vs bare package.
|
|
49
|
+
*/
|
|
50
|
+
pageLayoutNormalizationImportPath: string;
|
|
51
|
+
/**
|
|
52
|
+
* Optional import path for the page-data reader.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* When omitted, hydration scripts inline the reader so native browser ESM /
|
|
56
|
+
* HMR entry evaluation does not depend on bare `@ecopages/react/*` imports.
|
|
57
|
+
* Browser unit tests that execute `data:` scripts may still pass a resolvable URL.
|
|
58
|
+
*/
|
|
59
|
+
pageDataReaderImportPath?: string;
|
|
60
|
+
};
|
|
61
|
+
export type IslandHydrationScriptOptions = {
|
|
62
|
+
/** Bundled browser module path for the island component. */
|
|
63
|
+
importPath: string;
|
|
64
|
+
/** Stable id of the island bootstrap script tag in the document. */
|
|
65
|
+
scriptId: string;
|
|
66
|
+
/** Browser import path for React runtime. */
|
|
67
|
+
reactImportPath: string;
|
|
68
|
+
/** Browser import path for react-dom/client runtime. */
|
|
69
|
+
reactDomClientImportPath: string;
|
|
70
|
+
/** Selector that resolves to all SSR root elements for this island component. */
|
|
71
|
+
targetSelector: string;
|
|
72
|
+
/** Optional stable component id used to resolve named exports reliably. */
|
|
73
|
+
componentRef?: string;
|
|
74
|
+
/** Optional source file hint used as fallback for component resolution. */
|
|
75
|
+
componentFile?: string;
|
|
76
|
+
/**
|
|
77
|
+
* When true, emit a compact source string.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* Island bootstraps use `bundle: false`, so compact output must be generated
|
|
81
|
+
* here rather than delegated to the bundler.
|
|
82
|
+
*/
|
|
83
|
+
minify: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* When true, register an HMR handler that hot-imports the dev transform module.
|
|
86
|
+
*/
|
|
87
|
+
hmrEnabled?: boolean;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Creates a page hydration entry module.
|
|
91
|
+
*
|
|
92
|
+
* @remarks
|
|
93
|
+
* Always emits readable source. Production page assets set `bundle: true` so
|
|
94
|
+
* core's content-script processor minifies the result. Do not hand-minify here.
|
|
95
|
+
*/
|
|
96
|
+
export declare function createHydrationScript(options: HydrationScriptOptions): string;
|
|
97
|
+
/**
|
|
98
|
+
* Creates the client bootstrap for component-level React islands.
|
|
99
|
+
*
|
|
100
|
+
* @remarks
|
|
101
|
+
* Island scripts use `bundle: false`, so compact output still needs a
|
|
102
|
+
* handwritten string.
|
|
103
|
+
*/
|
|
104
|
+
export declare function createIslandHydrationScript(options: IslandHydrationScriptOptions): string;
|