@ecopages/react 0.2.1 → 0.3.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 +179 -35
- package/package.json +78 -33
- package/src/app/client-only.js +10 -0
- package/src/app/dynamic.js +9 -0
- package/src/bundling/bootstrap-package-paths.d.ts +5 -0
- package/src/bundling/bootstrap-package-paths.js +5 -0
- package/src/bundling/bundle.d.ts +78 -0
- package/src/bundling/bundle.js +130 -0
- package/src/bundling/runtime-alias-map.d.ts +12 -0
- package/src/bundling/runtime-alias-map.js +110 -0
- package/src/bundling/runtime-bundle.d.ts +70 -0
- package/src/bundling/runtime-bundle.js +233 -0
- package/src/{utils/react-dom-runtime-interop-plugin.d.ts → bundling/runtime-interop-plugin.d.ts} +1 -1
- package/src/bundling/runtime-interop-plugin.js +32 -0
- package/src/bundling/runtime-mode.d.ts +1 -0
- package/src/bundling/runtime-mode.js +10 -0
- package/src/bundling/runtime-modules.d.ts +21 -0
- package/src/bundling/runtime-modules.js +28 -0
- 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 +20 -0
- package/src/client-graph/ast-transform-walk-imports.js +105 -0
- package/src/client-graph/ast-transform.d.ts +12 -0
- package/src/client-graph/ast-transform.js +91 -0
- 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 +7 -0
- package/src/client-graph/boundary-plugin-read-file-inline.js +43 -0
- package/src/client-graph/boundary-plugin-transform.d.ts +16 -0
- package/src/client-graph/boundary-plugin-transform.js +31 -0
- package/src/client-graph/boundary-plugin.d.ts +23 -0
- package/src/client-graph/boundary-plugin.js +177 -0
- package/src/client-graph/component-config-traversal.d.ts +36 -0
- package/src/client-graph/component-config-traversal.js +77 -0
- package/src/{utils → client-graph}/declared-modules.d.ts +1 -1
- 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/client-graph/reachability-analyzer.d.ts +26 -0
- package/src/client-graph/reachability-analyzer.js +55 -0
- 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/client-graph/specifier-classification.d.ts +74 -0
- package/src/client-graph/specifier-classification.js +191 -0
- package/src/content/collection-component-cache.d.ts +25 -0
- package/src/content/collection-component-cache.js +62 -0
- package/src/{router-adapter.d.ts → contracts/router-adapter.d.ts} +7 -14
- 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-strategy-process.d.ts +34 -0
- package/src/hmr/hmr-strategy-process.js +83 -0
- package/src/hmr/hmr-strategy.d.ts +67 -0
- package/src/hmr/hmr-strategy.js +306 -0
- package/src/{services/react-hmr-page-metadata-cache.d.ts → hmr/page-metadata-cache.d.ts} +6 -2
- package/src/hmr/page-metadata-cache.js +44 -0
- package/src/hmr/react-hmr-dev-transform-plugins.d.ts +22 -0
- package/src/hmr/react-hmr-dev-transform-plugins.js +19 -0
- package/src/hydration/bootstrap-imports.d.ts +25 -0
- package/src/hydration/bootstrap-imports.js +33 -0
- package/src/hydration/browser/island-hydration.d.ts +81 -0
- package/src/hydration/browser/island-hydration.js +247 -0
- 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 +54 -0
- package/src/hydration/browser/page-hydration.js +177 -0
- 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-asset.d.ts +128 -0
- package/src/hydration/hydration-asset.js +388 -0
- 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 +47 -0
- package/src/hydration/hydration-script-compiler.js +213 -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 +17 -0
- package/src/hydration/page-data-reader.js +31 -0
- package/src/hydration/page-payload.d.ts +68 -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/mdx/mdx-config-dependency.d.ts +37 -0
- package/src/mdx/mdx-config-dependency.js +107 -0
- package/src/mdx/mdx-loader-plugin.d.ts +8 -0
- package/src/mdx/mdx-loader-plugin.js +11 -0
- package/src/page/page-module.d.ts +46 -0
- package/src/page/page-module.js +74 -0
- package/src/plugin/react.constants.d.ts +1 -0
- package/src/plugin/react.constants.js +1 -0
- package/src/plugin/react.plugin.d.ts +71 -0
- package/src/plugin/react.plugin.js +210 -0
- package/src/plugin/react.types.d.ts +106 -0
- package/src/plugin/react.types.js +1 -0
- package/src/render/component-ownership.d.ts +49 -0
- package/src/render/component-ownership.js +47 -0
- package/src/render/component-ssr.d.ts +59 -0
- package/src/render/component-ssr.js +76 -0
- package/src/render/eco-embed.d.ts +11 -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 +114 -0
- package/src/render/react-renderer.js +490 -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 +22 -0
- package/src/render/unified-layout-composition.js +31 -0
- package/src/runtime/use-sync-external-store-with-selector.d.ts +3 -0
- package/src/runtime/use-sync-external-store-with-selector.js +54 -0
- package/CHANGELOG.md +0 -29
- package/src/react-hmr-strategy.d.ts +0 -148
- package/src/react-hmr-strategy.js +0 -313
- package/src/react-renderer.d.ts +0 -213
- package/src/react-renderer.js +0 -654
- package/src/react.plugin.d.ts +0 -147
- package/src/react.plugin.js +0 -146
- package/src/router-adapter.js +0 -0
- package/src/services/react-bundle.service.d.ts +0 -47
- package/src/services/react-bundle.service.js +0 -93
- package/src/services/react-hmr-page-metadata-cache.js +0 -35
- package/src/services/react-hydration-asset.service.d.ts +0 -76
- package/src/services/react-hydration-asset.service.js +0 -210
- package/src/services/react-page-module.service.d.ts +0 -83
- package/src/services/react-page-module.service.js +0 -162
- package/src/services/react-runtime-bundle.service.d.ts +0 -40
- package/src/services/react-runtime-bundle.service.js +0 -130
- package/src/utils/client-graph-boundary-plugin.d.ts +0 -43
- package/src/utils/client-graph-boundary-plugin.js +0 -494
- package/src/utils/client-only.js +0 -19
- package/src/utils/declared-modules.js +0 -59
- package/src/utils/dynamic.js +0 -12
- package/src/utils/hmr-scripts.d.ts +0 -18
- package/src/utils/hmr-scripts.js +0 -31
- package/src/utils/html-boundary.js +0 -55
- package/src/utils/hydration-scripts.d.ts +0 -86
- package/src/utils/hydration-scripts.js +0 -285
- package/src/utils/reachability-analyzer.d.ts +0 -66
- package/src/utils/reachability-analyzer.js +0 -339
- package/src/utils/react-dom-runtime-interop-plugin.js +0 -29
- 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-specifier-map.d.ts +0 -6
- package/src/utils/react-runtime-specifier-map.js +0 -37
- package/src/utils/use-sync-external-store-shim-plugin.d.ts +0 -5
- package/src/utils/use-sync-external-store-shim-plugin.js +0 -41
- /package/src/{utils → app}/client-only.d.ts +0 -0
- /package/src/{utils → app}/dynamic.d.ts +0 -0
- /package/src/{declarations.d.ts → contracts/declarations.d.ts} +0 -0
- /package/src/{utils → render}/html-boundary.d.ts +0 -0
|
@@ -0,0 +1,128 @@
|
|
|
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 type { EcoComponentConfig } from '@ecopages/core';
|
|
10
|
+
import type { PageClientBuildEntry } from '@ecopages/core/integration';
|
|
11
|
+
import { type AssetDefinition, type ProcessedAsset } from '@ecopages/core/integration';
|
|
12
|
+
import type { AssetProcessingIntegration, AssetProcessingService } from '@ecopages/core/integration';
|
|
13
|
+
import type { BundleService } from '../bundling/bundle.js';
|
|
14
|
+
import type { HmrPageMetadataCache } from '../hmr/page-metadata-cache.js';
|
|
15
|
+
import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for the HydrationAssetService.
|
|
18
|
+
*/
|
|
19
|
+
export interface HydrationAssetServiceConfig {
|
|
20
|
+
srcDir: string;
|
|
21
|
+
routerAdapter?: ReactRouterAdapter;
|
|
22
|
+
assetProcessingService: AssetProcessingService;
|
|
23
|
+
assetProcessingIntegration?: AssetProcessingIntegration;
|
|
24
|
+
bundleService: BundleService;
|
|
25
|
+
hmrPageMetadataCache?: HmrPageMetadataCache;
|
|
26
|
+
}
|
|
27
|
+
type PageDependencyOptions = {
|
|
28
|
+
pagePath: string;
|
|
29
|
+
componentName: string;
|
|
30
|
+
importPath: string;
|
|
31
|
+
pageModuleUrlExpression: string;
|
|
32
|
+
bundleOptions: Record<string, unknown>;
|
|
33
|
+
hmrEnabled: boolean;
|
|
34
|
+
useBrowserRuntimeImports: boolean;
|
|
35
|
+
isMdx: boolean;
|
|
36
|
+
hasPagePreload?: boolean;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Derives the stable component key used by asset grouping and host selectors.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* The key identifies the component entry. Individual SSR instances receive a
|
|
43
|
+
* separate component ID, so repeated uses share browser assets without sharing
|
|
44
|
+
* a React root.
|
|
45
|
+
*
|
|
46
|
+
* @param componentFile - Absolute source path of the React component.
|
|
47
|
+
* @param config - Optional component identity used to distinguish entries.
|
|
48
|
+
* @returns Stable key used in selectors and asset names.
|
|
49
|
+
*/
|
|
50
|
+
export declare function getIslandComponentKey(componentFile: string, config?: EcoComponentConfig): string;
|
|
51
|
+
/**
|
|
52
|
+
* Manages the creation of client-side hydration assets for React pages and component islands.
|
|
53
|
+
*/
|
|
54
|
+
export declare class HydrationAssetService {
|
|
55
|
+
private readonly config;
|
|
56
|
+
private readonly islandScriptCompiler;
|
|
57
|
+
private readonly pageScriptCompiler;
|
|
58
|
+
private static readonly ROUTER_PAGE_GROUPED_BUNDLE_ID;
|
|
59
|
+
constructor(config: HydrationAssetServiceConfig);
|
|
60
|
+
private getIslandBundleName;
|
|
61
|
+
private getIslandHydrationName;
|
|
62
|
+
private getRouterPageGroupedEntryName;
|
|
63
|
+
/**
|
|
64
|
+
* Resolves the browser import path used for a React-owned page or island module.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* When HMR is enabled, registers the source file as an HMR entrypoint and returns
|
|
68
|
+
* that URL. Otherwise returns the static resolved-assets path for the generated
|
|
69
|
+
* asset name.
|
|
70
|
+
*/
|
|
71
|
+
resolveAssetImportPath(pagePath: string, assetName: string): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Creates the page-owned route entry asset for hydration and client navigation.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* The entry is compiled asynchronously from the editable browser lifecycle.
|
|
77
|
+
* Production router pages may be grouped into the Page Browser Graph, while
|
|
78
|
+
* HMR entries remain separate ESM scripts with browser-resolvable imports.
|
|
79
|
+
*/
|
|
80
|
+
createPageDependencies(options: PageDependencyOptions): Promise<AssetDefinition[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Builds island and lazy-entry browser assets in one grouped multi-entry build.
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* Production reads island module URLs from processed grouped-build outputs.
|
|
86
|
+
* HMR keeps per-file transform URLs and does not start a disk bundle.
|
|
87
|
+
*/
|
|
88
|
+
buildPageClientRenderAssets(input: {
|
|
89
|
+
islands: Array<{
|
|
90
|
+
file: string;
|
|
91
|
+
config?: EcoComponentConfig;
|
|
92
|
+
}>;
|
|
93
|
+
lazyEntries?: AssetDefinition[];
|
|
94
|
+
}): Promise<{
|
|
95
|
+
assetsByFile: Map<string, ProcessedAsset[]>;
|
|
96
|
+
processedAssets: ProcessedAsset[];
|
|
97
|
+
}>;
|
|
98
|
+
/** Collects React island hydration entries for the production app browser build. */
|
|
99
|
+
collectAppBrowserClientBuildEntries(islands: Array<{
|
|
100
|
+
file: string;
|
|
101
|
+
config?: EcoComponentConfig;
|
|
102
|
+
}>): Promise<PageClientBuildEntry[]>;
|
|
103
|
+
/** Keeps one entry per component; a file that declares several island components keeps each of them. */
|
|
104
|
+
private uniqueIslands;
|
|
105
|
+
private buildHmrPageClientRenderAssets;
|
|
106
|
+
private buildGroupedPageClientRenderAssets;
|
|
107
|
+
private createGroupedIslandEntries;
|
|
108
|
+
private indexSrcUrlsByEntryName;
|
|
109
|
+
private createGroupedHydrationScripts;
|
|
110
|
+
private collectIslandAssetsByFile;
|
|
111
|
+
private buildHmrIslandRenderAssets;
|
|
112
|
+
private createIslandHydrationScript;
|
|
113
|
+
/**
|
|
114
|
+
* Creates the page browser graph dependency declarations for a React page.
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* Chooses shared vendor import URLs when HMR is on, when running a non-production
|
|
118
|
+
* hosted runtime with HMR off, or when a router adapter is configured (router
|
|
119
|
+
* pages always externalize to shared runtimes). Production non-router pages
|
|
120
|
+
* may inline React into the page bundle instead.
|
|
121
|
+
*
|
|
122
|
+
* @param pagePath - Absolute file path of the page
|
|
123
|
+
* @param isMdx - Whether the page is an MDX file
|
|
124
|
+
* @param declaredModules - Explicitly declared browser module specifiers
|
|
125
|
+
*/
|
|
126
|
+
createPageBrowserGraphDependencies(pagePath: string, isMdx: boolean, declaredModules: string[]): Promise<AssetDefinition[]>;
|
|
127
|
+
}
|
|
128
|
+
export {};
|
|
@@ -0,0 +1,388 @@
|
|
|
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 { contentHash } from '@ecopages/core/build';
|
|
11
|
+
import { RESOLVED_ASSETS_DIR } from '@ecopages/core/build';
|
|
12
|
+
import { isReactProductionRuntime } from '../bundling/runtime-mode.js';
|
|
13
|
+
import { APP_BROWSER_CLIENT_BUNDLE_ID, AssetFactory, createAppBrowserClientEntry, } from '@ecopages/core/integration';
|
|
14
|
+
import { IslandHydrationScriptCompiler, PageHydrationScriptCompiler } from './hydration-script-compiler.js';
|
|
15
|
+
import { resolveHydrationBootstrapImports } from './bootstrap-imports.js';
|
|
16
|
+
import { collectDeclaredModulesInConfig } from '../client-graph/declared-modules.js';
|
|
17
|
+
import { hasPagePreloadExport } from '../client-graph/reachability-analyzer.js';
|
|
18
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
19
|
+
/**
|
|
20
|
+
* Derives the stable component key used by asset grouping and host selectors.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* The key identifies the component entry. Individual SSR instances receive a
|
|
24
|
+
* separate component ID, so repeated uses share browser assets without sharing
|
|
25
|
+
* a React root.
|
|
26
|
+
*
|
|
27
|
+
* @param componentFile - Absolute source path of the React component.
|
|
28
|
+
* @param config - Optional component identity used to distinguish entries.
|
|
29
|
+
* @returns Stable key used in selectors and asset names.
|
|
30
|
+
*/
|
|
31
|
+
export function getIslandComponentKey(componentFile, config) {
|
|
32
|
+
return BigInt(`0x${contentHash(`${componentFile}:${config?.identity?.id ?? ''}`, 16)}`).toString(10);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Manages the creation of client-side hydration assets for React pages and component islands.
|
|
36
|
+
*/
|
|
37
|
+
export class HydrationAssetService {
|
|
38
|
+
config;
|
|
39
|
+
islandScriptCompiler = new IslandHydrationScriptCompiler();
|
|
40
|
+
pageScriptCompiler = new PageHydrationScriptCompiler();
|
|
41
|
+
static ROUTER_PAGE_GROUPED_BUNDLE_ID = APP_BROWSER_CLIENT_BUNDLE_ID;
|
|
42
|
+
constructor(config) {
|
|
43
|
+
this.config = config;
|
|
44
|
+
}
|
|
45
|
+
getIslandBundleName(componentFile) {
|
|
46
|
+
return `ecopages-react-island-${BigInt(`0x${contentHash(componentFile, 16)}`).toString()}`;
|
|
47
|
+
}
|
|
48
|
+
getIslandHydrationName(bundleName, componentKey) {
|
|
49
|
+
return `${bundleName}-hydration-${componentKey}`;
|
|
50
|
+
}
|
|
51
|
+
getRouterPageGroupedEntryName(pagePath) {
|
|
52
|
+
const relativePath = path.relative(this.config.srcDir, pagePath);
|
|
53
|
+
return relativePath
|
|
54
|
+
.replace(/\.(tsx?|jsx?|mdx?)$/, '')
|
|
55
|
+
.replace(/[\\/]+/g, '__')
|
|
56
|
+
.replace(/\[([^\]]+)\]/g, '_$1_');
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Resolves the browser import path used for a React-owned page or island module.
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* When HMR is enabled, registers the source file as an HMR entrypoint and returns
|
|
63
|
+
* that URL. Otherwise returns the static resolved-assets path for the generated
|
|
64
|
+
* asset name.
|
|
65
|
+
*/
|
|
66
|
+
async resolveAssetImportPath(pagePath, assetName) {
|
|
67
|
+
const hmrManager = this.config.assetProcessingService?.getHmrManager();
|
|
68
|
+
if (hmrManager?.isEnabled()) {
|
|
69
|
+
return hmrManager.registerEntrypoint(pagePath);
|
|
70
|
+
}
|
|
71
|
+
return `/${path
|
|
72
|
+
.join(RESOLVED_ASSETS_DIR, path.relative(this.config.srcDir, pagePath))
|
|
73
|
+
.replace(path.basename(pagePath), `${assetName}.js`)
|
|
74
|
+
.replace(/\\/g, '/')}`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Creates the page-owned route entry asset for hydration and client navigation.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* The entry is compiled asynchronously from the editable browser lifecycle.
|
|
81
|
+
* Production router pages may be grouped into the Page Browser Graph, while
|
|
82
|
+
* HMR entries remain separate ESM scripts with browser-resolvable imports.
|
|
83
|
+
*/
|
|
84
|
+
async createPageDependencies(options) {
|
|
85
|
+
const { pagePath, componentName, importPath, pageModuleUrlExpression, bundleOptions, hmrEnabled, useBrowserRuntimeImports, isMdx, hasPagePreload, } = options;
|
|
86
|
+
const runtimeImports = this.config.bundleService.getRuntimeImports();
|
|
87
|
+
const groupedBundle = !hmrEnabled && this.config.routerAdapter
|
|
88
|
+
? {
|
|
89
|
+
id: HydrationAssetService.ROUTER_PAGE_GROUPED_BUNDLE_ID,
|
|
90
|
+
entryName: this.getRouterPageGroupedEntryName(pagePath),
|
|
91
|
+
}
|
|
92
|
+
: undefined;
|
|
93
|
+
const bootstrapImports = resolveHydrationBootstrapImports({
|
|
94
|
+
useBrowserRuntimeImports,
|
|
95
|
+
runtimeImports,
|
|
96
|
+
routerAdapterImportPath: this.config.routerAdapter?.bundle.importPath,
|
|
97
|
+
});
|
|
98
|
+
const pageHydrationScript = await this.pageScriptCompiler.compile({
|
|
99
|
+
importPath: hmrEnabled ? importPath : pagePath,
|
|
100
|
+
pageModuleUrlExpression,
|
|
101
|
+
scriptId: componentName,
|
|
102
|
+
reactImportPath: bootstrapImports.reactImportPath,
|
|
103
|
+
reactDomClientImportPath: bootstrapImports.reactDomClientImportPath,
|
|
104
|
+
routerImportPath: bootstrapImports.routerImportPath,
|
|
105
|
+
layoutComposeImportPath: bootstrapImports.layoutComposeImportPath,
|
|
106
|
+
pageLayoutNormalizationImportPath: bootstrapImports.pageLayoutNormalizationImportPath,
|
|
107
|
+
routerComponents: this.config.routerAdapter?.components,
|
|
108
|
+
routerPropsExpression: this.config.routerAdapter?.getRouterProps('Page', 'props'),
|
|
109
|
+
hmrEnabled,
|
|
110
|
+
isMdx,
|
|
111
|
+
hasPagePreload: hasPagePreload === true,
|
|
112
|
+
minify: !hmrEnabled && isReactProductionRuntime(),
|
|
113
|
+
});
|
|
114
|
+
return [
|
|
115
|
+
AssetFactory.createContentScript({
|
|
116
|
+
position: 'head',
|
|
117
|
+
content: pageHydrationScript,
|
|
118
|
+
name: componentName,
|
|
119
|
+
packageRole: 'page-script',
|
|
120
|
+
/**
|
|
121
|
+
* @remarks
|
|
122
|
+
* HMR bootstraps stay unbundled write-through ESM. Helper imports must
|
|
123
|
+
* already be browser-resolvable vendor URLs from
|
|
124
|
+
* {@link resolveHydrationBootstrapImports}.
|
|
125
|
+
*/
|
|
126
|
+
bundle: !hmrEnabled,
|
|
127
|
+
groupedBundle,
|
|
128
|
+
bundleOptions,
|
|
129
|
+
attributes: {
|
|
130
|
+
type: 'module',
|
|
131
|
+
defer: '',
|
|
132
|
+
'data-eco-rerun': 'true',
|
|
133
|
+
'data-eco-script-id': componentName,
|
|
134
|
+
...(this.config.routerAdapter ? { 'data-eco-page-bootstrap': 'react-router' } : {}),
|
|
135
|
+
'data-eco-persist': 'true',
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Builds island and lazy-entry browser assets in one grouped multi-entry build.
|
|
142
|
+
*
|
|
143
|
+
* @remarks
|
|
144
|
+
* Production reads island module URLs from processed grouped-build outputs.
|
|
145
|
+
* HMR keeps per-file transform URLs and does not start a disk bundle.
|
|
146
|
+
*/
|
|
147
|
+
async buildPageClientRenderAssets(input) {
|
|
148
|
+
if (!this.config.assetProcessingService) {
|
|
149
|
+
return { assetsByFile: new Map(), processedAssets: [] };
|
|
150
|
+
}
|
|
151
|
+
const uniqueIslands = this.uniqueIslands(input.islands);
|
|
152
|
+
const hmrEnabled = this.config.assetProcessingService.getHmrManager()?.isEnabled() ?? false;
|
|
153
|
+
if (hmrEnabled) {
|
|
154
|
+
return this.buildHmrPageClientRenderAssets(uniqueIslands, input.lazyEntries);
|
|
155
|
+
}
|
|
156
|
+
return this.buildGroupedPageClientRenderAssets(uniqueIslands, input.lazyEntries);
|
|
157
|
+
}
|
|
158
|
+
/** Collects React island hydration entries for the production app browser build. */
|
|
159
|
+
async collectAppBrowserClientBuildEntries(islands) {
|
|
160
|
+
const uniqueIslands = this.uniqueIslands(islands);
|
|
161
|
+
const groupedEntrypointFiles = [...new Set(uniqueIslands.map(({ file }) => file))];
|
|
162
|
+
const groupedDeclaredModules = [
|
|
163
|
+
...new Set(uniqueIslands.flatMap(({ config }) => collectDeclaredModulesInConfig(config))),
|
|
164
|
+
];
|
|
165
|
+
const entries = [];
|
|
166
|
+
for (const island of uniqueIslands) {
|
|
167
|
+
const componentName = this.getIslandBundleName(island.file);
|
|
168
|
+
const declaredModules = collectDeclaredModulesInConfig(island.config);
|
|
169
|
+
const bundleOptions = await this.config.bundleService.createBundleOptions(componentName, false, declaredModules, {}, island.file, groupedEntrypointFiles, groupedDeclaredModules);
|
|
170
|
+
const componentKey = getIslandComponentKey(island.file, island.config);
|
|
171
|
+
const hydrationName = this.getIslandHydrationName(componentName, componentKey);
|
|
172
|
+
const hydrationScript = await this.createIslandHydrationScript(island.file, island.config, island.file, false);
|
|
173
|
+
entries.push({
|
|
174
|
+
dependency: {
|
|
175
|
+
...hydrationScript,
|
|
176
|
+
bundle: true,
|
|
177
|
+
groupedBundle: {
|
|
178
|
+
id: APP_BROWSER_CLIENT_BUNDLE_ID,
|
|
179
|
+
entryName: hydrationName,
|
|
180
|
+
},
|
|
181
|
+
bundleOptions,
|
|
182
|
+
},
|
|
183
|
+
islandFile: island.file,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return entries;
|
|
187
|
+
}
|
|
188
|
+
/** Keeps one entry per component; a file that declares several island components keeps each of them. */
|
|
189
|
+
uniqueIslands(islands) {
|
|
190
|
+
const uniqueIslands = [];
|
|
191
|
+
const seenKeys = new Set();
|
|
192
|
+
for (const island of islands) {
|
|
193
|
+
const key = getIslandComponentKey(island.file, island.config);
|
|
194
|
+
if (seenKeys.has(key)) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
seenKeys.add(key);
|
|
198
|
+
uniqueIslands.push(island);
|
|
199
|
+
}
|
|
200
|
+
return uniqueIslands;
|
|
201
|
+
}
|
|
202
|
+
async buildHmrPageClientRenderAssets(uniqueIslands, lazyEntries) {
|
|
203
|
+
const assetsByFile = new Map();
|
|
204
|
+
const processedAssets = [];
|
|
205
|
+
for (const island of uniqueIslands) {
|
|
206
|
+
this.config.hmrPageMetadataCache?.markOwnedEntrypoint(island.file);
|
|
207
|
+
const assets = await this.buildHmrIslandRenderAssets(island.file, island.config);
|
|
208
|
+
assetsByFile.set(island.file, [...(assetsByFile.get(island.file) ?? []), ...assets]);
|
|
209
|
+
processedAssets.push(...assets);
|
|
210
|
+
}
|
|
211
|
+
if (lazyEntries?.length) {
|
|
212
|
+
processedAssets.push(...(await this.config.assetProcessingService.processDependencies(lazyEntries, this.config.assetProcessingIntegration)));
|
|
213
|
+
}
|
|
214
|
+
return { assetsByFile, processedAssets };
|
|
215
|
+
}
|
|
216
|
+
async buildGroupedPageClientRenderAssets(uniqueIslands, lazyEntries) {
|
|
217
|
+
const islandEntries = await this.createGroupedIslandEntries(uniqueIslands);
|
|
218
|
+
const clientEntries = [...islandEntries, ...(lazyEntries ?? [])];
|
|
219
|
+
const processedClientEntries = clientEntries.length > 0
|
|
220
|
+
? await this.config.assetProcessingService.processDependencies(clientEntries, this.config.assetProcessingIntegration)
|
|
221
|
+
: [];
|
|
222
|
+
const srcUrlByEntryName = this.indexSrcUrlsByEntryName(processedClientEntries);
|
|
223
|
+
const hydrationScripts = await this.createGroupedHydrationScripts(uniqueIslands, srcUrlByEntryName);
|
|
224
|
+
const processedHydration = hydrationScripts.length > 0
|
|
225
|
+
? await this.config.assetProcessingService.processDependencies(hydrationScripts, this.config.assetProcessingIntegration)
|
|
226
|
+
: [];
|
|
227
|
+
return {
|
|
228
|
+
assetsByFile: this.collectIslandAssetsByFile(uniqueIslands, processedClientEntries, processedHydration),
|
|
229
|
+
processedAssets: [...processedClientEntries, ...processedHydration],
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
async createGroupedIslandEntries(uniqueIslands) {
|
|
233
|
+
const islandEntries = [];
|
|
234
|
+
const declaredModulesByFile = new Map();
|
|
235
|
+
for (const { file, config } of uniqueIslands) {
|
|
236
|
+
const declaredModules = declaredModulesByFile.get(file) ?? new Set();
|
|
237
|
+
for (const module of collectDeclaredModulesInConfig(config))
|
|
238
|
+
declaredModules.add(module);
|
|
239
|
+
declaredModulesByFile.set(file, declaredModules);
|
|
240
|
+
}
|
|
241
|
+
const groupedEntrypointFiles = [...declaredModulesByFile.keys()];
|
|
242
|
+
const groupedDeclaredModules = [
|
|
243
|
+
...new Set(uniqueIslands.flatMap(({ config }) => collectDeclaredModulesInConfig(config))),
|
|
244
|
+
];
|
|
245
|
+
for (const [file, declaredModules] of declaredModulesByFile) {
|
|
246
|
+
const componentName = this.getIslandBundleName(file);
|
|
247
|
+
const bundleOptions = await this.config.bundleService.createBundleOptions(componentName, false, [...declaredModules], {}, file, groupedEntrypointFiles, groupedDeclaredModules);
|
|
248
|
+
islandEntries.push(createAppBrowserClientEntry({
|
|
249
|
+
entryName: componentName,
|
|
250
|
+
importPath: file,
|
|
251
|
+
reexport: true,
|
|
252
|
+
packageRole: 'dynamic-chunk',
|
|
253
|
+
bundleOptions,
|
|
254
|
+
attributes: {
|
|
255
|
+
'data-eco-persist': 'true',
|
|
256
|
+
},
|
|
257
|
+
}));
|
|
258
|
+
}
|
|
259
|
+
return islandEntries;
|
|
260
|
+
}
|
|
261
|
+
indexSrcUrlsByEntryName(processedClientEntries) {
|
|
262
|
+
const srcUrlByEntryName = new Map();
|
|
263
|
+
for (const processed of processedClientEntries) {
|
|
264
|
+
const entryName = processed.groupedBundle?.entryName;
|
|
265
|
+
if (entryName && processed.srcUrl) {
|
|
266
|
+
srcUrlByEntryName.set(entryName, processed.srcUrl);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return srcUrlByEntryName;
|
|
270
|
+
}
|
|
271
|
+
async createGroupedHydrationScripts(uniqueIslands, srcUrlByEntryName) {
|
|
272
|
+
const hydrationScripts = [];
|
|
273
|
+
for (const island of uniqueIslands) {
|
|
274
|
+
const importPath = srcUrlByEntryName.get(this.getIslandBundleName(island.file));
|
|
275
|
+
if (!importPath) {
|
|
276
|
+
throw new Error(`Missing grouped browser output for island ${island.file}`);
|
|
277
|
+
}
|
|
278
|
+
hydrationScripts.push(await this.createIslandHydrationScript(island.file, island.config, importPath, false));
|
|
279
|
+
}
|
|
280
|
+
return hydrationScripts;
|
|
281
|
+
}
|
|
282
|
+
collectIslandAssetsByFile(uniqueIslands, processedClientEntries, processedHydration) {
|
|
283
|
+
const assetsByFile = new Map();
|
|
284
|
+
const hydrationByName = new Map();
|
|
285
|
+
for (const processed of processedHydration) {
|
|
286
|
+
const name = processed.attributes?.['data-eco-script-id'];
|
|
287
|
+
if (!name) {
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
const existing = hydrationByName.get(name) ?? [];
|
|
291
|
+
existing.push(processed);
|
|
292
|
+
hydrationByName.set(name, existing);
|
|
293
|
+
}
|
|
294
|
+
for (const island of uniqueIslands) {
|
|
295
|
+
const componentName = this.getIslandBundleName(island.file);
|
|
296
|
+
const hydrationName = this.getIslandHydrationName(componentName, getIslandComponentKey(island.file, island.config));
|
|
297
|
+
const islandAsset = processedClientEntries.find((processed) => processed.groupedBundle?.entryName === componentName);
|
|
298
|
+
const fileAssets = assetsByFile.get(island.file);
|
|
299
|
+
assetsByFile.set(island.file, [
|
|
300
|
+
...(fileAssets ?? (islandAsset ? [islandAsset] : [])),
|
|
301
|
+
...(hydrationByName.get(hydrationName) ?? []),
|
|
302
|
+
]);
|
|
303
|
+
}
|
|
304
|
+
return assetsByFile;
|
|
305
|
+
}
|
|
306
|
+
async buildHmrIslandRenderAssets(componentFile, config) {
|
|
307
|
+
const importPath = await this.resolveAssetImportPath(componentFile, this.getIslandBundleName(componentFile));
|
|
308
|
+
const hydrationScript = await this.createIslandHydrationScript(componentFile, config, importPath, true);
|
|
309
|
+
return this.config.assetProcessingService.processDependencies([hydrationScript], this.config.assetProcessingIntegration);
|
|
310
|
+
}
|
|
311
|
+
async createIslandHydrationScript(componentFile, config, importPath, hmrEnabled) {
|
|
312
|
+
const componentName = this.getIslandBundleName(componentFile);
|
|
313
|
+
const componentKey = getIslandComponentKey(componentFile, config);
|
|
314
|
+
const hydrationName = this.getIslandHydrationName(componentName, componentKey);
|
|
315
|
+
const runtimeImports = this.config.bundleService.getRuntimeImports();
|
|
316
|
+
const islandHydrationScript = await this.islandScriptCompiler.compile({
|
|
317
|
+
importPath,
|
|
318
|
+
scriptId: hydrationName,
|
|
319
|
+
reactImportPath: runtimeImports.react,
|
|
320
|
+
reactDomClientImportPath: runtimeImports.reactDomClient,
|
|
321
|
+
targetSelector: `[data-eco-component-key="${componentKey}"]`,
|
|
322
|
+
componentRef: config?.identity?.id,
|
|
323
|
+
minify: !hmrEnabled,
|
|
324
|
+
hmrEnabled,
|
|
325
|
+
});
|
|
326
|
+
return AssetFactory.createContentScript({
|
|
327
|
+
position: 'head',
|
|
328
|
+
content: islandHydrationScript,
|
|
329
|
+
name: hydrationName,
|
|
330
|
+
packageRole: 'keep-separate',
|
|
331
|
+
bundle: false,
|
|
332
|
+
attributes: {
|
|
333
|
+
type: 'module',
|
|
334
|
+
defer: '',
|
|
335
|
+
'data-eco-rerun': 'true',
|
|
336
|
+
'data-eco-script-id': hydrationName,
|
|
337
|
+
'data-eco-persist': 'true',
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Creates the page browser graph dependency declarations for a React page.
|
|
343
|
+
*
|
|
344
|
+
* @remarks
|
|
345
|
+
* Chooses shared vendor import URLs when HMR is on, when running a non-production
|
|
346
|
+
* hosted runtime with HMR off, or when a router adapter is configured (router
|
|
347
|
+
* pages always externalize to shared runtimes). Production non-router pages
|
|
348
|
+
* may inline React into the page bundle instead.
|
|
349
|
+
*
|
|
350
|
+
* @param pagePath - Absolute file path of the page
|
|
351
|
+
* @param isMdx - Whether the page is an MDX file
|
|
352
|
+
* @param declaredModules - Explicitly declared browser module specifiers
|
|
353
|
+
*/
|
|
354
|
+
async createPageBrowserGraphDependencies(pagePath, isMdx, declaredModules) {
|
|
355
|
+
const componentName = `ecopages-react-${BigInt(`0x${contentHash(pagePath, 16)}`).toString()}`;
|
|
356
|
+
const hmrManager = this.config.assetProcessingService?.getHmrManager();
|
|
357
|
+
const hmrEnabled = hmrManager?.isEnabled() ?? false;
|
|
358
|
+
const productionRuntime = isReactProductionRuntime();
|
|
359
|
+
const usesRouterRuntime = Boolean(this.config.routerAdapter);
|
|
360
|
+
const useBrowserRuntimeImports = hmrEnabled || !productionRuntime || usesRouterRuntime;
|
|
361
|
+
if (hmrEnabled) {
|
|
362
|
+
this.config.hmrPageMetadataCache?.setDeclaredModules(pagePath, declaredModules);
|
|
363
|
+
}
|
|
364
|
+
const importPath = await this.resolveAssetImportPath(pagePath, componentName);
|
|
365
|
+
const pageModuleUrlExpression = hmrEnabled ? JSON.stringify(importPath) : 'import.meta.url';
|
|
366
|
+
let hasPagePreload = false;
|
|
367
|
+
try {
|
|
368
|
+
const source = await fileSystem.readFile(pagePath);
|
|
369
|
+
hasPagePreload = hasPagePreloadExport(source, pagePath);
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
hasPagePreload = false;
|
|
373
|
+
}
|
|
374
|
+
const bundleOptions = await this.config.bundleService.createBundleOptions(componentName, isMdx, declaredModules, { includeRuntime: !useBrowserRuntimeImports, splitting: usesRouterRuntime }, pagePath);
|
|
375
|
+
const dependencies = await this.createPageDependencies({
|
|
376
|
+
pagePath,
|
|
377
|
+
componentName,
|
|
378
|
+
importPath,
|
|
379
|
+
pageModuleUrlExpression,
|
|
380
|
+
bundleOptions,
|
|
381
|
+
hmrEnabled,
|
|
382
|
+
useBrowserRuntimeImports,
|
|
383
|
+
isMdx,
|
|
384
|
+
hasPagePreload,
|
|
385
|
+
});
|
|
386
|
+
return dependencies;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
function assertRouterConfiguration(options) {
|
|
2
|
+
if (options.routerComponents && !options.routerImportPath) {
|
|
3
|
+
throw new Error('routerImportPath is required when router components are configured');
|
|
4
|
+
}
|
|
5
|
+
if (options.routerComponents && !options.routerPropsExpression) {
|
|
6
|
+
throw new Error('routerPropsExpression is required when router components are configured');
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function buildPageImport(options) {
|
|
10
|
+
if (options.isMdx || options.hasPagePreload) {
|
|
11
|
+
return `import * as PageModule from ${JSON.stringify(options.importPath)};`;
|
|
12
|
+
}
|
|
13
|
+
return `import Page from ${JSON.stringify(options.importPath)};`;
|
|
14
|
+
}
|
|
15
|
+
function buildInitialPageBinding(options) {
|
|
16
|
+
if (options.isMdx || options.hasPagePreload) {
|
|
17
|
+
return `const initialPage = resolvePageModule(PageModule, ${options.isMdx}, ${options.isMdx ? 'ensurePageConfigLayouts' : 'undefined'});`;
|
|
18
|
+
}
|
|
19
|
+
return `const initialPage = resolvePageModule({ default: Page }, false);`;
|
|
20
|
+
}
|
|
21
|
+
function buildRouterImports(options) {
|
|
22
|
+
if (!options.routerComponents)
|
|
23
|
+
return '';
|
|
24
|
+
return `import { ${options.routerComponents.router}, ${options.routerComponents.pageContent} } from ${JSON.stringify(options.routerImportPath)};`;
|
|
25
|
+
}
|
|
26
|
+
function buildRouterTree(options) {
|
|
27
|
+
if (!options.routerComponents) {
|
|
28
|
+
return 'const createTree = (Page, props) => composeLayoutPageTree(Page, props);';
|
|
29
|
+
}
|
|
30
|
+
return `const createTree = (Page, props) => {
|
|
31
|
+
const pageContent = createElement(${options.routerComponents.pageContent});
|
|
32
|
+
return createElement(${options.routerComponents.router}, ${options.routerPropsExpression}, pageContent);
|
|
33
|
+
};`;
|
|
34
|
+
}
|
|
35
|
+
function buildNormalizationImport(options) {
|
|
36
|
+
if (!options.isMdx)
|
|
37
|
+
return '';
|
|
38
|
+
return `import { ensurePageConfigLayouts } from ${JSON.stringify(options.pageLayoutNormalizationImportPath)};`;
|
|
39
|
+
}
|
|
40
|
+
function buildHmrOptions(options) {
|
|
41
|
+
if (!options.hmrEnabled)
|
|
42
|
+
return '';
|
|
43
|
+
const layoutStack = options.routerComponents
|
|
44
|
+
? 'getLayoutStack: (Page) => (Page.config?.layouts ?? []).map((layout) => layout?.config?.identity?.id ?? "").join("|"),'
|
|
45
|
+
: '';
|
|
46
|
+
return `hmr: {
|
|
47
|
+
importPath: ${JSON.stringify(options.importPath)},
|
|
48
|
+
${layoutStack}
|
|
49
|
+
},`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates the Page entry contract consumed by the browser lifecycle.
|
|
53
|
+
*/
|
|
54
|
+
export function createPageEntrySource(options) {
|
|
55
|
+
assertRouterConfiguration(options);
|
|
56
|
+
const pageBootstrapId = '\0ecopages-react-page-bootstrap';
|
|
57
|
+
const pageDataReaderId = '\0ecopages-react-page-data-reader';
|
|
58
|
+
return `
|
|
59
|
+
import { hydrateRoot } from ${JSON.stringify(options.reactDomClientImportPath)};
|
|
60
|
+
import { createElement } from ${JSON.stringify(options.reactImportPath)};
|
|
61
|
+
import { resolvePageModule, startPageHydration } from ${JSON.stringify(pageBootstrapId)};
|
|
62
|
+
import { readPageDataDocument, getPageDataFromDocument } from ${JSON.stringify(pageDataReaderId)};
|
|
63
|
+
${options.routerComponents ? '' : `import { composeLayoutPageTree } from ${JSON.stringify(options.layoutComposeImportPath)};`}
|
|
64
|
+
${buildRouterImports(options)}
|
|
65
|
+
${buildNormalizationImport(options)}
|
|
66
|
+
${buildPageImport(options)}
|
|
67
|
+
const pageModuleUrl = ${options.pageModuleUrlExpression};
|
|
68
|
+
${buildInitialPageBinding(options)}
|
|
69
|
+
${buildRouterTree(options)}
|
|
70
|
+
export default initialPage.Page;
|
|
71
|
+
${options.hasPagePreload ? 'export const preload = initialPage.preload;' : ''}
|
|
72
|
+
export const config = initialPage.Page.config;
|
|
73
|
+
startPageHydration({
|
|
74
|
+
scriptId: ${JSON.stringify(options.scriptId)},
|
|
75
|
+
pageModuleUrl,
|
|
76
|
+
Page: initialPage.Page,
|
|
77
|
+
pageDataReader: { readPageDataDocument, getPageDataFromDocument },
|
|
78
|
+
runtime: { hydrateRoot, createElement },
|
|
79
|
+
createTree,
|
|
80
|
+
hasRouter: ${Boolean(options.routerComponents)},
|
|
81
|
+
isMdx: ${options.isMdx},
|
|
82
|
+
${options.isMdx ? 'normalizePageConfig: ensurePageConfigLayouts,' : ''}
|
|
83
|
+
${options.hasPagePreload ? 'preload: initialPage.preload,' : ''}
|
|
84
|
+
${buildHmrOptions(options)}
|
|
85
|
+
});
|
|
86
|
+
`.trim();
|
|
87
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Complete inputs that affect an Island Host script's generated source. */
|
|
2
|
+
export type CompiledIslandHydrationOptions = {
|
|
3
|
+
importPath: string;
|
|
4
|
+
scriptId: string;
|
|
5
|
+
reactImportPath: string;
|
|
6
|
+
reactDomClientImportPath: string;
|
|
7
|
+
targetSelector: string;
|
|
8
|
+
componentRef?: string;
|
|
9
|
+
minify: boolean;
|
|
10
|
+
hmrEnabled?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type { CompiledPageHydrationOptions } from './compiled-page-hydration-options.js';
|
|
13
|
+
import type { CompiledPageHydrationOptions } from './compiled-page-hydration-options.js';
|
|
14
|
+
/**
|
|
15
|
+
* Compiles the editable React Island Host lifecycle into a browser ESM string.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Compilation is cached by the complete entry configuration. Rejected promises
|
|
19
|
+
* are removed so a transient filesystem or bundler error can recover.
|
|
20
|
+
*/
|
|
21
|
+
export declare class IslandHydrationScriptCompiler {
|
|
22
|
+
private readonly compilationCache;
|
|
23
|
+
/**
|
|
24
|
+
* Compiles and caches one readable or minified Island Host entry.
|
|
25
|
+
*
|
|
26
|
+
* @param options - Complete entry imports, selector, identity, and output mode.
|
|
27
|
+
* @returns A browser ESM source string.
|
|
28
|
+
*/
|
|
29
|
+
compile(options: CompiledIslandHydrationOptions): Promise<string>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Compiles editable Page lifecycle modules into browser ESM strings.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* The cache belongs to the service instance, allowing development restarts to
|
|
36
|
+
* discard framework-source changes without sharing stale output globally.
|
|
37
|
+
*/
|
|
38
|
+
export declare class PageHydrationScriptCompiler {
|
|
39
|
+
private readonly compilationCache;
|
|
40
|
+
/**
|
|
41
|
+
* Compiles and caches one readable or minified Page entry.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Complete page imports, router contract, and output mode.
|
|
44
|
+
* @returns A browser ESM source string.
|
|
45
|
+
*/
|
|
46
|
+
compile(options: CompiledPageHydrationOptions): Promise<string>;
|
|
47
|
+
}
|