@ecopages/react 0.2.0-alpha.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/LICENSE +21 -0
  3. package/README.md +65 -0
  4. package/package.json +76 -0
  5. package/src/declarations.d.ts +6 -0
  6. package/src/react-hmr-strategy.d.ts +143 -0
  7. package/src/react-hmr-strategy.js +332 -0
  8. package/src/react-hmr-strategy.ts +444 -0
  9. package/src/react-renderer.d.ts +106 -0
  10. package/src/react-renderer.js +302 -0
  11. package/src/react-renderer.ts +403 -0
  12. package/src/react.plugin.d.ts +147 -0
  13. package/src/react.plugin.js +126 -0
  14. package/src/react.plugin.ts +241 -0
  15. package/src/router-adapter.d.ts +87 -0
  16. package/src/router-adapter.js +0 -0
  17. package/src/router-adapter.ts +95 -0
  18. package/src/services/react-bundle.service.d.ts +68 -0
  19. package/src/services/react-bundle.service.js +145 -0
  20. package/src/services/react-bundle.service.ts +212 -0
  21. package/src/services/react-hmr-page-metadata-cache.d.ts +17 -0
  22. package/src/services/react-hmr-page-metadata-cache.js +19 -0
  23. package/src/services/react-hmr-page-metadata-cache.ts +24 -0
  24. package/src/services/react-hydration-asset.service.d.ts +75 -0
  25. package/src/services/react-hydration-asset.service.js +198 -0
  26. package/src/services/react-hydration-asset.service.ts +260 -0
  27. package/src/services/react-page-module.service.d.ts +80 -0
  28. package/src/services/react-page-module.service.js +155 -0
  29. package/src/services/react-page-module.service.ts +214 -0
  30. package/src/services/react-runtime-bundle.service.d.ts +38 -0
  31. package/src/services/react-runtime-bundle.service.js +207 -0
  32. package/src/services/react-runtime-bundle.service.ts +271 -0
  33. package/src/utils/client-graph-boundary-plugin.d.ts +43 -0
  34. package/src/utils/client-graph-boundary-plugin.js +356 -0
  35. package/src/utils/client-graph-boundary-plugin.ts +590 -0
  36. package/src/utils/client-only.d.ts +8 -0
  37. package/src/utils/client-only.js +19 -0
  38. package/src/utils/client-only.ts +27 -0
  39. package/src/utils/declared-modules.d.ts +42 -0
  40. package/src/utils/declared-modules.js +56 -0
  41. package/src/utils/declared-modules.ts +99 -0
  42. package/src/utils/dynamic.d.ts +15 -0
  43. package/src/utils/dynamic.js +12 -0
  44. package/src/utils/dynamic.ts +27 -0
  45. package/src/utils/hmr-scripts.d.ts +18 -0
  46. package/src/utils/hmr-scripts.js +31 -0
  47. package/src/utils/hmr-scripts.ts +47 -0
  48. package/src/utils/html-boundary.d.ts +7 -0
  49. package/src/utils/html-boundary.js +55 -0
  50. package/src/utils/html-boundary.ts +66 -0
  51. package/src/utils/hydration-scripts.d.ts +71 -0
  52. package/src/utils/hydration-scripts.js +222 -0
  53. package/src/utils/hydration-scripts.ts +338 -0
  54. package/src/utils/reachability-analyzer.d.ts +55 -0
  55. package/src/utils/reachability-analyzer.js +243 -0
  56. package/src/utils/reachability-analyzer.ts +440 -0
  57. package/src/utils/react-mdx-loader-plugin.d.ts +3 -0
  58. package/src/utils/react-mdx-loader-plugin.js +37 -0
  59. package/src/utils/react-mdx-loader-plugin.ts +40 -0
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Bundle configuration service for React integration.
3
+ *
4
+ * Encapsulates all esbuild plugin creation and bundle options
5
+ * for client-side React component builds.
6
+ *
7
+ * @module
8
+ */
9
+ import type { ReactRouterAdapter } from '../router-adapter.js';
10
+ import type { CompileOptions } from '@mdx-js/mdx';
11
+ import { type ReactRuntimeImports } from './react-runtime-bundle.service.js';
12
+ /**
13
+ * Configuration for the ReactBundleService.
14
+ */
15
+ export interface ReactBundleServiceConfig {
16
+ rootDir: string;
17
+ routerAdapter?: ReactRouterAdapter;
18
+ mdxCompilerOptions?: CompileOptions;
19
+ }
20
+ /**
21
+ * Manages esbuild bundle configuration and plugin creation for React page/component builds.
22
+ */
23
+ export declare class ReactBundleService {
24
+ private readonly config;
25
+ private readonly runtimeBundleService;
26
+ constructor(config: ReactBundleServiceConfig);
27
+ /**
28
+ * Returns resolved runtime import paths for the React runtime.
29
+ */
30
+ getRuntimeImports(): ReactRuntimeImports;
31
+ /**
32
+ * Creates esbuild bundle options for a page or component entry.
33
+ *
34
+ * @param componentName - Generated unique component name for output naming
35
+ * @param isMdx - Whether the source file is an MDX file
36
+ * @param declaredModules - Explicitly declared browser module specifiers
37
+ * @returns Bundle options object for the build adapter
38
+ */
39
+ createBundleOptions(componentName: string, isMdx: boolean, declaredModules: string[]): Promise<Record<string, unknown>>;
40
+ /**
41
+ * Creates the esbuild plugin that rewrites bare React specifiers
42
+ * to their runtime asset URLs.
43
+ */
44
+ createRuntimeAliasPlugin(runtimeImports: ReactRuntimeImports): {
45
+ name: string;
46
+ setup(build: {
47
+ onResolve: (options: {
48
+ filter: RegExp;
49
+ namespace?: string;
50
+ }, callback: (args: {
51
+ path: string;
52
+ importer: string;
53
+ namespace: string;
54
+ }) => {
55
+ path?: string;
56
+ namespace?: string;
57
+ external?: boolean;
58
+ } | undefined) => void;
59
+ }): void;
60
+ };
61
+ /**
62
+ * Creates the esbuild plugin that shims `use-sync-external-store/shim`
63
+ * to re-export from React's built-in `useSyncExternalStore`.
64
+ * This is needed because some packages use `use-sync-external-store/shim`
65
+ * but React 18+ has built-in `useSyncExternalStore`.
66
+ */
67
+ private createSyncExternalStorePlugin;
68
+ }
@@ -0,0 +1,145 @@
1
+ import { createClientGraphBoundaryPlugin } from "../utils/client-graph-boundary-plugin.js";
2
+ import { ReactRuntimeBundleService } from "./react-runtime-bundle.service.js";
3
+ class ReactBundleService {
4
+ constructor(config) {
5
+ this.config = config;
6
+ this.runtimeBundleService = new ReactRuntimeBundleService({
7
+ routerAdapter: config.routerAdapter
8
+ });
9
+ }
10
+ runtimeBundleService;
11
+ /**
12
+ * Returns resolved runtime import paths for the React runtime.
13
+ */
14
+ getRuntimeImports() {
15
+ return this.runtimeBundleService.getRuntimeImports();
16
+ }
17
+ /**
18
+ * Creates esbuild bundle options for a page or component entry.
19
+ *
20
+ * @param componentName - Generated unique component name for output naming
21
+ * @param isMdx - Whether the source file is an MDX file
22
+ * @param declaredModules - Explicitly declared browser module specifiers
23
+ * @returns Bundle options object for the build adapter
24
+ */
25
+ async createBundleOptions(componentName, isMdx, declaredModules) {
26
+ const runtimeImports = this.getRuntimeImports();
27
+ const options = {
28
+ external: ["react", "react-dom", "react/jsx-runtime", "react/jsx-dev-runtime", "react-dom/client"],
29
+ mainFields: ["module", "browser", "main"],
30
+ naming: `${componentName}.[ext]`,
31
+ ...import.meta.env?.NODE_ENV === "production" && {
32
+ minify: true,
33
+ splitting: false,
34
+ treeshaking: true
35
+ }
36
+ };
37
+ const graphBoundaryPlugin = createClientGraphBoundaryPlugin({
38
+ absWorkingDir: this.config.rootDir,
39
+ declaredModules,
40
+ alwaysAllowSpecifiers: [
41
+ "@ecopages/core",
42
+ "react",
43
+ "react-dom",
44
+ "react/jsx-runtime",
45
+ "react/jsx-dev-runtime",
46
+ "react-dom/client",
47
+ ...this.config.routerAdapter ? [this.config.routerAdapter.importMapKey] : []
48
+ ]
49
+ });
50
+ const runtimeAliasPlugin = this.createRuntimeAliasPlugin(runtimeImports);
51
+ const useSyncExternalStoreShimPlugin = this.createSyncExternalStorePlugin();
52
+ if (isMdx && this.config.mdxCompilerOptions) {
53
+ const { createReactMdxLoaderPlugin } = await import("../utils/react-mdx-loader-plugin.js");
54
+ const mdxPlugin = createReactMdxLoaderPlugin(this.config.mdxCompilerOptions);
55
+ options.plugins = [runtimeAliasPlugin, mdxPlugin, useSyncExternalStoreShimPlugin, graphBoundaryPlugin];
56
+ } else {
57
+ options.plugins = [runtimeAliasPlugin, useSyncExternalStoreShimPlugin, graphBoundaryPlugin];
58
+ }
59
+ return options;
60
+ }
61
+ /**
62
+ * Creates the esbuild plugin that rewrites bare React specifiers
63
+ * to their runtime asset URLs.
64
+ */
65
+ createRuntimeAliasPlugin(runtimeImports) {
66
+ const aliases = /* @__PURE__ */ new Map([
67
+ ["react", runtimeImports.react],
68
+ ["react-dom/client", runtimeImports.reactDomClient],
69
+ ["react/jsx-runtime", runtimeImports.reactJsxRuntime],
70
+ ["react/jsx-dev-runtime", runtimeImports.reactJsxDevRuntime],
71
+ ["react-dom", runtimeImports.reactDom]
72
+ ]);
73
+ if (this.config.routerAdapter && runtimeImports.router) {
74
+ aliases.set(this.config.routerAdapter.importMapKey, runtimeImports.router);
75
+ }
76
+ const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
77
+ const pattern = new RegExp(
78
+ `^(${Array.from(aliases.keys()).map((key) => escapeRegExp(key)).join("|")})$`
79
+ );
80
+ return {
81
+ name: "react-runtime-import-alias",
82
+ setup(build) {
83
+ build.onResolve({ filter: pattern }, (args) => {
84
+ const mappedPath = aliases.get(args.path);
85
+ if (!mappedPath) {
86
+ return void 0;
87
+ }
88
+ return {
89
+ path: mappedPath,
90
+ external: true
91
+ };
92
+ });
93
+ }
94
+ };
95
+ }
96
+ /**
97
+ * Creates the esbuild plugin that shims `use-sync-external-store/shim`
98
+ * to re-export from React's built-in `useSyncExternalStore`.
99
+ * This is needed because some packages use `use-sync-external-store/shim`
100
+ * but React 18+ has built-in `useSyncExternalStore`.
101
+ */
102
+ createSyncExternalStorePlugin() {
103
+ return {
104
+ name: "react-renderer-use-sync-external-store-shim",
105
+ setup(build) {
106
+ build.onResolve({ filter: /^use-sync-external-store\/shim(?:\/index\.js)?$/ }, () => ({
107
+ path: "use-sync-external-store/shim",
108
+ namespace: "ecopages-react-renderer-shim"
109
+ }));
110
+ build.onLoad(
111
+ { filter: /^use-sync-external-store\/shim$/, namespace: "ecopages-react-renderer-shim" },
112
+ () => ({
113
+ contents: "export { useSyncExternalStore } from 'react';",
114
+ loader: "js"
115
+ })
116
+ );
117
+ build.onLoad({ filter: /[\\/]use-sync-external-store[\\/]shim[\\/]index\.js$/ }, () => ({
118
+ contents: "export { useSyncExternalStore } from 'react';",
119
+ loader: "js"
120
+ }));
121
+ build.onLoad(
122
+ {
123
+ filter: /[\\/]use-sync-external-store[\\/]cjs[\\/]use-sync-external-store-shim\.development\.js$/
124
+ },
125
+ () => ({
126
+ contents: "export { useSyncExternalStore } from 'react';",
127
+ loader: "js"
128
+ })
129
+ );
130
+ build.onLoad(
131
+ {
132
+ filter: /[\\/]use-sync-external-store[\\/]cjs[\\/]use-sync-external-store-shim\.production\.js$/
133
+ },
134
+ () => ({
135
+ contents: "export { useSyncExternalStore } from 'react';",
136
+ loader: "js"
137
+ })
138
+ );
139
+ }
140
+ };
141
+ }
142
+ }
143
+ export {
144
+ ReactBundleService
145
+ };
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Bundle configuration service for React integration.
3
+ *
4
+ * Encapsulates all esbuild plugin creation and bundle options
5
+ * for client-side React component builds.
6
+ *
7
+ * @module
8
+ */
9
+
10
+ import { createClientGraphBoundaryPlugin } from '../utils/client-graph-boundary-plugin.ts';
11
+ import type { ReactRouterAdapter } from '../router-adapter.ts';
12
+ import type { CompileOptions } from '@mdx-js/mdx';
13
+ import { ReactRuntimeBundleService, type ReactRuntimeImports } from './react-runtime-bundle.service.ts';
14
+
15
+ /**
16
+ * Configuration for the ReactBundleService.
17
+ */
18
+ export interface ReactBundleServiceConfig {
19
+ rootDir: string;
20
+ routerAdapter?: ReactRouterAdapter;
21
+ mdxCompilerOptions?: CompileOptions;
22
+ }
23
+
24
+ /**
25
+ * Manages esbuild bundle configuration and plugin creation for React page/component builds.
26
+ */
27
+ export class ReactBundleService {
28
+ private readonly runtimeBundleService: ReactRuntimeBundleService;
29
+
30
+ constructor(private readonly config: ReactBundleServiceConfig) {
31
+ this.runtimeBundleService = new ReactRuntimeBundleService({
32
+ routerAdapter: config.routerAdapter,
33
+ });
34
+ }
35
+
36
+ /**
37
+ * Returns resolved runtime import paths for the React runtime.
38
+ */
39
+ getRuntimeImports(): ReactRuntimeImports {
40
+ return this.runtimeBundleService.getRuntimeImports();
41
+ }
42
+
43
+ /**
44
+ * Creates esbuild bundle options for a page or component entry.
45
+ *
46
+ * @param componentName - Generated unique component name for output naming
47
+ * @param isMdx - Whether the source file is an MDX file
48
+ * @param declaredModules - Explicitly declared browser module specifiers
49
+ * @returns Bundle options object for the build adapter
50
+ */
51
+ async createBundleOptions(
52
+ componentName: string,
53
+ isMdx: boolean,
54
+ declaredModules: string[],
55
+ ): Promise<Record<string, unknown>> {
56
+ const runtimeImports = this.getRuntimeImports();
57
+ const options: Record<string, unknown> = {
58
+ external: ['react', 'react-dom', 'react/jsx-runtime', 'react/jsx-dev-runtime', 'react-dom/client'],
59
+ mainFields: ['module', 'browser', 'main'],
60
+ naming: `${componentName}.[ext]`,
61
+ ...(import.meta.env?.NODE_ENV === 'production' && {
62
+ minify: true,
63
+ splitting: false,
64
+ treeshaking: true,
65
+ }),
66
+ };
67
+
68
+ const graphBoundaryPlugin = createClientGraphBoundaryPlugin({
69
+ absWorkingDir: this.config.rootDir,
70
+ declaredModules,
71
+ alwaysAllowSpecifiers: [
72
+ '@ecopages/core',
73
+ 'react',
74
+ 'react-dom',
75
+ 'react/jsx-runtime',
76
+ 'react/jsx-dev-runtime',
77
+ 'react-dom/client',
78
+ ...(this.config.routerAdapter ? [this.config.routerAdapter.importMapKey] : []),
79
+ ],
80
+ });
81
+
82
+ const runtimeAliasPlugin = this.createRuntimeAliasPlugin(runtimeImports);
83
+ const useSyncExternalStoreShimPlugin = this.createSyncExternalStorePlugin();
84
+
85
+ if (isMdx && this.config.mdxCompilerOptions) {
86
+ const { createReactMdxLoaderPlugin } = await import('../utils/react-mdx-loader-plugin.ts');
87
+ const mdxPlugin = createReactMdxLoaderPlugin(this.config.mdxCompilerOptions);
88
+ options.plugins = [runtimeAliasPlugin, mdxPlugin, useSyncExternalStoreShimPlugin, graphBoundaryPlugin];
89
+ } else {
90
+ options.plugins = [runtimeAliasPlugin, useSyncExternalStoreShimPlugin, graphBoundaryPlugin];
91
+ }
92
+
93
+ return options;
94
+ }
95
+
96
+ /**
97
+ * Creates the esbuild plugin that rewrites bare React specifiers
98
+ * to their runtime asset URLs.
99
+ */
100
+ createRuntimeAliasPlugin(runtimeImports: ReactRuntimeImports) {
101
+ const aliases = new Map<string, string>([
102
+ ['react', runtimeImports.react],
103
+ ['react-dom/client', runtimeImports.reactDomClient],
104
+ ['react/jsx-runtime', runtimeImports.reactJsxRuntime],
105
+ ['react/jsx-dev-runtime', runtimeImports.reactJsxDevRuntime],
106
+ ['react-dom', runtimeImports.reactDom],
107
+ ]);
108
+
109
+ if (this.config.routerAdapter && runtimeImports.router) {
110
+ aliases.set(this.config.routerAdapter.importMapKey, runtimeImports.router);
111
+ }
112
+
113
+ const escapeRegExp = (value: string): string => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
114
+ const pattern = new RegExp(
115
+ `^(${Array.from(aliases.keys())
116
+ .map((key) => escapeRegExp(key))
117
+ .join('|')})$`,
118
+ );
119
+
120
+ return {
121
+ name: 'react-runtime-import-alias',
122
+ setup(build: {
123
+ onResolve: (
124
+ options: { filter: RegExp; namespace?: string },
125
+ callback: (args: {
126
+ path: string;
127
+ importer: string;
128
+ namespace: string;
129
+ }) => { path?: string; namespace?: string; external?: boolean } | undefined,
130
+ ) => void;
131
+ }) {
132
+ build.onResolve({ filter: pattern }, (args) => {
133
+ const mappedPath = aliases.get(args.path);
134
+ if (!mappedPath) {
135
+ return undefined;
136
+ }
137
+ return {
138
+ path: mappedPath,
139
+ external: true,
140
+ };
141
+ });
142
+ },
143
+ };
144
+ }
145
+
146
+ /**
147
+ * Creates the esbuild plugin that shims `use-sync-external-store/shim`
148
+ * to re-export from React's built-in `useSyncExternalStore`.
149
+ * This is needed because some packages use `use-sync-external-store/shim`
150
+ * but React 18+ has built-in `useSyncExternalStore`.
151
+ */
152
+ private createSyncExternalStorePlugin() {
153
+ return {
154
+ name: 'react-renderer-use-sync-external-store-shim',
155
+ setup(build: {
156
+ onResolve: (
157
+ options: { filter: RegExp; namespace?: string },
158
+ callback: (args: {
159
+ path: string;
160
+ importer: string;
161
+ namespace: string;
162
+ }) => { path?: string; namespace?: string } | undefined,
163
+ ) => void;
164
+ onLoad: (
165
+ options: { filter: RegExp; namespace?: string },
166
+ callback: (args: {
167
+ path: string;
168
+ namespace: string;
169
+ }) => { contents?: string; loader?: 'js' } | undefined,
170
+ ) => void;
171
+ }) {
172
+ build.onResolve({ filter: /^use-sync-external-store\/shim(?:\/index\.js)?$/ }, () => ({
173
+ path: 'use-sync-external-store/shim',
174
+ namespace: 'ecopages-react-renderer-shim',
175
+ }));
176
+
177
+ build.onLoad(
178
+ { filter: /^use-sync-external-store\/shim$/, namespace: 'ecopages-react-renderer-shim' },
179
+ () => ({
180
+ contents: "export { useSyncExternalStore } from 'react';",
181
+ loader: 'js',
182
+ }),
183
+ );
184
+
185
+ build.onLoad({ filter: /[\\/]use-sync-external-store[\\/]shim[\\/]index\.js$/ }, () => ({
186
+ contents: "export { useSyncExternalStore } from 'react';",
187
+ loader: 'js',
188
+ }));
189
+
190
+ build.onLoad(
191
+ {
192
+ filter: /[\\/]use-sync-external-store[\\/]cjs[\\/]use-sync-external-store-shim\.development\.js$/,
193
+ },
194
+ () => ({
195
+ contents: "export { useSyncExternalStore } from 'react';",
196
+ loader: 'js',
197
+ }),
198
+ );
199
+
200
+ build.onLoad(
201
+ {
202
+ filter: /[\\/]use-sync-external-store[\\/]cjs[\\/]use-sync-external-store-shim\.production\.js$/,
203
+ },
204
+ () => ({
205
+ contents: "export { useSyncExternalStore } from 'react';",
206
+ loader: 'js',
207
+ }),
208
+ );
209
+ },
210
+ };
211
+ }
212
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * React-only cache for page metadata that HMR rebuilds need during development.
3
+ *
4
+ * This keeps React Fast Refresh optimizations local to the React integration so
5
+ * core HMR interfaces do not need React-specific metadata hooks.
6
+ */
7
+ export declare class ReactHmrPageMetadataCache {
8
+ private readonly declaredModulesByEntrypoint;
9
+ /**
10
+ * Stores the declared browser modules for a page entrypoint.
11
+ */
12
+ setDeclaredModules(entrypointPath: string, declaredModules: string[]): void;
13
+ /**
14
+ * Returns the last known declared browser modules for a page entrypoint.
15
+ */
16
+ getDeclaredModules(entrypointPath: string): string[] | undefined;
17
+ }
@@ -0,0 +1,19 @@
1
+ class ReactHmrPageMetadataCache {
2
+ declaredModulesByEntrypoint = /* @__PURE__ */ new Map();
3
+ /**
4
+ * Stores the declared browser modules for a page entrypoint.
5
+ */
6
+ setDeclaredModules(entrypointPath, declaredModules) {
7
+ this.declaredModulesByEntrypoint.set(entrypointPath, [...declaredModules]);
8
+ }
9
+ /**
10
+ * Returns the last known declared browser modules for a page entrypoint.
11
+ */
12
+ getDeclaredModules(entrypointPath) {
13
+ const declaredModules = this.declaredModulesByEntrypoint.get(entrypointPath);
14
+ return declaredModules ? [...declaredModules] : void 0;
15
+ }
16
+ }
17
+ export {
18
+ ReactHmrPageMetadataCache
19
+ };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * React-only cache for page metadata that HMR rebuilds need during development.
3
+ *
4
+ * This keeps React Fast Refresh optimizations local to the React integration so
5
+ * core HMR interfaces do not need React-specific metadata hooks.
6
+ */
7
+ export class ReactHmrPageMetadataCache {
8
+ private readonly declaredModulesByEntrypoint = new Map<string, string[]>();
9
+
10
+ /**
11
+ * Stores the declared browser modules for a page entrypoint.
12
+ */
13
+ setDeclaredModules(entrypointPath: string, declaredModules: string[]): void {
14
+ this.declaredModulesByEntrypoint.set(entrypointPath, [...declaredModules]);
15
+ }
16
+
17
+ /**
18
+ * Returns the last known declared browser modules for a page entrypoint.
19
+ */
20
+ getDeclaredModules(entrypointPath: string): string[] | undefined {
21
+ const declaredModules = this.declaredModulesByEntrypoint.get(entrypointPath);
22
+ return declaredModules ? [...declaredModules] : undefined;
23
+ }
24
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Hydration asset creation service for React integration.
3
+ *
4
+ * Builds the asset definitions (bundled component scripts + hydration bootstrap scripts)
5
+ * required for client-side React rendering — both at the page level and the component
6
+ * island level.
7
+ *
8
+ * @module
9
+ */
10
+ import type { EcoComponentConfig } from '@ecopages/core';
11
+ import { type AssetDefinition, type ProcessedAsset } from '@ecopages/core/services/asset-processing-service';
12
+ import type { AssetProcessingService } from '@ecopages/core/services/asset-processing-service';
13
+ import type { ReactBundleService } from './react-bundle.service.js';
14
+ import type { ReactHmrPageMetadataCache } from './react-hmr-page-metadata-cache.js';
15
+ import type { ReactRouterAdapter } from '../router-adapter.js';
16
+ /**
17
+ * Configuration for the ReactHydrationAssetService.
18
+ */
19
+ export interface ReactHydrationAssetServiceConfig {
20
+ srcDir: string;
21
+ routerAdapter?: ReactRouterAdapter;
22
+ assetProcessingService: AssetProcessingService;
23
+ bundleService: ReactBundleService;
24
+ hmrPageMetadataCache?: ReactHmrPageMetadataCache;
25
+ }
26
+ /**
27
+ * Manages the creation of client-side hydration assets for React pages and component islands.
28
+ */
29
+ export declare class ReactHydrationAssetService {
30
+ private readonly config;
31
+ constructor(config: ReactHydrationAssetServiceConfig);
32
+ /**
33
+ * Resolves the import path for the bundled page component.
34
+ * Uses HMR manager for development or constructs static path for production.
35
+ *
36
+ * @param pagePath - Absolute path to the page source file
37
+ * @param componentName - Generated unique component name
38
+ * @returns The resolved import path for the bundled component
39
+ */
40
+ resolveAssetImportPath(pagePath: string, componentName: string): Promise<string>;
41
+ /**
42
+ * Creates the asset dependencies for a page: the bundled component and hydration script.
43
+ *
44
+ * @param pagePath - Absolute path to the page source file
45
+ * @param componentName - Generated unique component name
46
+ * @param importPath - Resolved import path for the bundled component
47
+ * @param bundleOptions - Bundle configuration options
48
+ * @param isDevelopment - Whether running in development mode with HMR
49
+ * @param isMdx - Whether the source file is an MDX file
50
+ * @param props - Optional page props for client serialization
51
+ * @returns Array of asset definitions for processing
52
+ */
53
+ createPageDependencies(pagePath: string, componentName: string, importPath: string, bundleOptions: Record<string, unknown>, isDevelopment: boolean, isMdx: boolean, props?: Record<string, unknown>): AssetDefinition[];
54
+ /**
55
+ * Builds client-side assets for a React component island.
56
+ *
57
+ * Includes the bundled component entry and an inline hydration bootstrap script.
58
+ *
59
+ * @param componentFile - Absolute path to the component source file
60
+ * @param componentInstanceId - Unique instance ID for DOM targeting
61
+ * @param props - Serialized props for client-side hydration
62
+ * @param config - Optional component config with `__eco` metadata
63
+ * @returns Processed assets ready for injection
64
+ */
65
+ buildComponentRenderAssets(componentFile: string, componentInstanceId: string, props: Record<string, unknown>, config?: EcoComponentConfig): Promise<ProcessedAsset[]>;
66
+ /**
67
+ * Builds all client-side route assets for a page.
68
+ *
69
+ * @param pagePath - Absolute file path of the page
70
+ * @param isMdx - Whether the page is an MDX file
71
+ * @param declaredModules - Explicitly declared browser module specifiers
72
+ * @returns Processed assets for the route
73
+ */
74
+ buildRouteRenderAssets(pagePath: string, isMdx: boolean, declaredModules: string[]): Promise<ProcessedAsset[]>;
75
+ }