@ecopages/react 0.2.0-beta.4 → 0.2.0-beta.41
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 +175 -7
- package/package.json +54 -29
- 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 +191 -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} +30 -5
- 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 +223 -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 +152 -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 -205
- 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 -186
- 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
package/src/react.plugin.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IntegrationPlugin
|
|
3
|
-
} from "@ecopages/core/plugins/integration-plugin";
|
|
4
|
-
import { Logger } from "@ecopages/logger";
|
|
5
|
-
import { REACT_PLUGIN_NAME } from "./react.constants.js";
|
|
6
|
-
import { ReactRenderer } from "./react-renderer.js";
|
|
7
|
-
import { ReactHmrStrategy } from "./react-hmr-strategy.js";
|
|
8
|
-
import { ReactRuntimeBundleService } from "./services/react-runtime-bundle.service.js";
|
|
9
|
-
import { ReactHmrPageMetadataCache } from "./services/react-hmr-page-metadata-cache.js";
|
|
10
|
-
import { createReactMdxLoaderPlugin } from "./utils/react-mdx-loader-plugin.js";
|
|
11
|
-
import { ClientGraphBoundaryCache } from "./utils/client-graph-boundary-cache.js";
|
|
12
|
-
const appLogger = new Logger("[ReactPlugin]");
|
|
13
|
-
const PLUGIN_NAME = REACT_PLUGIN_NAME;
|
|
14
|
-
const mergePluginLists = (...lists) => {
|
|
15
|
-
const merged = lists.flatMap((list) => list ? [...list] : []);
|
|
16
|
-
return merged.length > 0 ? merged : void 0;
|
|
17
|
-
};
|
|
18
|
-
const appendMdxExtensions = (target, mdxExtensions) => {
|
|
19
|
-
for (const extension of mdxExtensions) {
|
|
20
|
-
if (!target.includes(extension)) {
|
|
21
|
-
target.push(extension);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const resolveReactMdxCompilerOptions = (mdxOptions) => {
|
|
26
|
-
const { compilerOptions, remarkPlugins, rehypePlugins, recmaPlugins } = mdxOptions;
|
|
27
|
-
const resolved = {
|
|
28
|
-
...compilerOptions,
|
|
29
|
-
jsxImportSource: "react",
|
|
30
|
-
jsxRuntime: "automatic",
|
|
31
|
-
development: process.env.NODE_ENV === "development"
|
|
32
|
-
};
|
|
33
|
-
const mergedRemark = mergePluginLists(compilerOptions?.remarkPlugins, remarkPlugins);
|
|
34
|
-
const mergedRehype = mergePluginLists(compilerOptions?.rehypePlugins, rehypePlugins);
|
|
35
|
-
const mergedRecma = mergePluginLists(compilerOptions?.recmaPlugins, recmaPlugins);
|
|
36
|
-
if (mergedRemark) resolved.remarkPlugins = mergedRemark;
|
|
37
|
-
if (mergedRehype) resolved.rehypePlugins = mergedRehype;
|
|
38
|
-
if (mergedRecma) resolved.recmaPlugins = mergedRecma;
|
|
39
|
-
return resolved;
|
|
40
|
-
};
|
|
41
|
-
const resolveReactPluginOptions = (options) => {
|
|
42
|
-
const { extensions: userExtensions, router, mdx, explicitGraph, dependencies, ...baseConfig } = options ?? {};
|
|
43
|
-
const extensions = [...userExtensions ?? [".tsx"]];
|
|
44
|
-
const mdxEnabled = mdx?.enabled ?? false;
|
|
45
|
-
const mdxExtensions = mdx?.extensions ?? [".mdx"];
|
|
46
|
-
if (mdxEnabled) {
|
|
47
|
-
appendMdxExtensions(extensions, mdxExtensions);
|
|
48
|
-
} else if (mdx?.extensions?.length) {
|
|
49
|
-
appLogger.warn(
|
|
50
|
-
"MDX extensions provided but MDX is disabled. MDX files will not be processed. Set mdx.enabled to true to enable MDX support."
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
const rendererConfig = {
|
|
54
|
-
routerAdapter: router,
|
|
55
|
-
mdxCompilerOptions: mdxEnabled && mdx ? resolveReactMdxCompilerOptions(mdx) : void 0,
|
|
56
|
-
mdxExtensions,
|
|
57
|
-
hmrPageMetadataCache: new ReactHmrPageMetadataCache(),
|
|
58
|
-
explicitGraphEnabled: explicitGraph ?? false
|
|
59
|
-
};
|
|
60
|
-
return {
|
|
61
|
-
...baseConfig,
|
|
62
|
-
extensions,
|
|
63
|
-
integrationDependencies: dependencies,
|
|
64
|
-
rendererConfig
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
class ReactPlugin extends IntegrationPlugin {
|
|
68
|
-
renderer = ReactRenderer;
|
|
69
|
-
routerAdapter;
|
|
70
|
-
mdxEnabled;
|
|
71
|
-
mdxCompilerOptions;
|
|
72
|
-
mdxExtensions;
|
|
73
|
-
mdxLoaderPlugin;
|
|
74
|
-
runtimeBundleService;
|
|
75
|
-
hmrPageMetadataCache;
|
|
76
|
-
clientGraphBoundaryCache;
|
|
77
|
-
runtimeDependenciesInitialized = false;
|
|
78
|
-
/**
|
|
79
|
-
* Indicates whether React explicit graph mode is enabled for renderer/HMR behavior.
|
|
80
|
-
*/
|
|
81
|
-
explicitGraphEnabled;
|
|
82
|
-
rendererConfig;
|
|
83
|
-
constructor(options) {
|
|
84
|
-
const config = resolveReactPluginOptions(options);
|
|
85
|
-
const { extensions, rendererConfig, integrationDependencies, ...baseConfig } = config;
|
|
86
|
-
super({
|
|
87
|
-
name: PLUGIN_NAME,
|
|
88
|
-
extensions,
|
|
89
|
-
jsxImportSource: "react",
|
|
90
|
-
integrationDependencies,
|
|
91
|
-
...baseConfig
|
|
92
|
-
});
|
|
93
|
-
this.routerAdapter = rendererConfig.routerAdapter;
|
|
94
|
-
this.mdxCompilerOptions = rendererConfig.mdxCompilerOptions;
|
|
95
|
-
this.mdxEnabled = Boolean(rendererConfig.mdxCompilerOptions);
|
|
96
|
-
this.mdxExtensions = rendererConfig.mdxExtensions ?? [".mdx"];
|
|
97
|
-
this.hmrPageMetadataCache = rendererConfig.hmrPageMetadataCache ?? new ReactHmrPageMetadataCache();
|
|
98
|
-
this.clientGraphBoundaryCache = new ClientGraphBoundaryCache();
|
|
99
|
-
this.explicitGraphEnabled = rendererConfig.explicitGraphEnabled ?? false;
|
|
100
|
-
this.rendererConfig = {
|
|
101
|
-
...rendererConfig,
|
|
102
|
-
mdxExtensions: this.mdxExtensions,
|
|
103
|
-
hmrPageMetadataCache: this.hmrPageMetadataCache,
|
|
104
|
-
explicitGraphEnabled: this.explicitGraphEnabled
|
|
105
|
-
};
|
|
106
|
-
if (this.mdxEnabled) {
|
|
107
|
-
appLogger.debug("MDX mode enabled with React jsx runtime");
|
|
108
|
-
}
|
|
109
|
-
this.runtimeBundleService = new ReactRuntimeBundleService({
|
|
110
|
-
routerAdapter: this.routerAdapter
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Creates a React renderer with instance-owned runtime configuration.
|
|
115
|
-
*
|
|
116
|
-
* React renderers depend on plugin-owned router, MDX, and HMR metadata state.
|
|
117
|
-
* Keeping that state on the instance avoids cross-plugin static mutation while
|
|
118
|
-
* preserving the same runtime services the base initializer wires up.
|
|
119
|
-
*/
|
|
120
|
-
initializeRenderer(options) {
|
|
121
|
-
const renderer = new this.renderer({
|
|
122
|
-
...this.createRendererOptions(options),
|
|
123
|
-
reactConfig: this.rendererConfig
|
|
124
|
-
});
|
|
125
|
-
return this.attachRendererRuntimeServices(renderer);
|
|
126
|
-
}
|
|
127
|
-
ensureRuntimeDependencies() {
|
|
128
|
-
if (this.runtimeDependenciesInitialized) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
this.runtimeBundleService.setRootDir(this.appConfig?.rootDir);
|
|
132
|
-
this.integrationDependencies.unshift(...this.runtimeBundleService.getDependencies());
|
|
133
|
-
this.runtimeDependenciesInitialized = true;
|
|
134
|
-
}
|
|
135
|
-
get plugins() {
|
|
136
|
-
if (this.mdxLoaderPlugin) {
|
|
137
|
-
return [this.mdxLoaderPlugin];
|
|
138
|
-
}
|
|
139
|
-
return [];
|
|
140
|
-
}
|
|
141
|
-
get browserRuntimeManifest() {
|
|
142
|
-
this.ensureRuntimeDependencies();
|
|
143
|
-
return this.runtimeBundleService.getRuntimeManifest();
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Ensures the optional React MDX loader exists before either config-time
|
|
147
|
-
* manifest sealing or runtime setup needs it.
|
|
148
|
-
*/
|
|
149
|
-
async ensureMdxLoaderPlugin() {
|
|
150
|
-
if (!this.mdxEnabled || !this.mdxCompilerOptions || this.mdxLoaderPlugin) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
this.mdxLoaderPlugin = createReactMdxLoaderPlugin(this.mdxCompilerOptions);
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Prepares React's build-facing loader contributions before config build seals
|
|
157
|
-
* the app manifest.
|
|
158
|
-
*/
|
|
159
|
-
async prepareBuildContributions() {
|
|
160
|
-
this.ensureRuntimeDependencies();
|
|
161
|
-
await this.ensureMdxLoaderPlugin();
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Performs runtime-only React setup after build contributions are already
|
|
165
|
-
* materialized.
|
|
166
|
-
*/
|
|
167
|
-
async setup() {
|
|
168
|
-
this.ensureRuntimeDependencies();
|
|
169
|
-
await this.ensureMdxLoaderPlugin();
|
|
170
|
-
await super.setup();
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Provides React-specific HMR strategy with Fast Refresh support.
|
|
174
|
-
*
|
|
175
|
-
* The strategy shares a React-only page metadata cache with the renderer so
|
|
176
|
-
* save-time rebuilds can reuse declared-module analysis without expanding the
|
|
177
|
-
* core HMR interfaces.
|
|
178
|
-
*
|
|
179
|
-
* @returns ReactHmrStrategy instance for handling React component updates
|
|
180
|
-
*/
|
|
181
|
-
getHmrStrategy() {
|
|
182
|
-
if (!this.hmrManager || !this.appConfig) {
|
|
183
|
-
return void 0;
|
|
184
|
-
}
|
|
185
|
-
const context = this.hmrManager.getDefaultContext();
|
|
186
|
-
return new ReactHmrStrategy({
|
|
187
|
-
context,
|
|
188
|
-
pageMetadataCache: this.hmrPageMetadataCache,
|
|
189
|
-
runtimeManifest: this.runtimeBundleService.getRuntimeManifest("development"),
|
|
190
|
-
mdxCompilerOptions: this.mdxCompilerOptions,
|
|
191
|
-
ownedTemplateExtensions: this.extensions,
|
|
192
|
-
allTemplateExtensions: this.appConfig.templatesExt,
|
|
193
|
-
explicitGraphEnabled: this.explicitGraphEnabled,
|
|
194
|
-
clientGraphBoundaryCache: this.clientGraphBoundaryCache
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
function reactPlugin(options) {
|
|
199
|
-
return new ReactPlugin(options);
|
|
200
|
-
}
|
|
201
|
-
export {
|
|
202
|
-
PLUGIN_NAME,
|
|
203
|
-
ReactPlugin,
|
|
204
|
-
reactPlugin
|
|
205
|
-
};
|
package/src/react.types.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { AssetDefinition } from '@ecopages/core/services/asset-processing-service';
|
|
2
|
-
import type { CompileOptions } from '@mdx-js/mdx';
|
|
3
|
-
import type { ReactRouterAdapter } from './router-adapter.js';
|
|
4
|
-
import type { ReactHmrPageMetadataCache } from './services/react-hmr-page-metadata-cache.js';
|
|
5
|
-
/**
|
|
6
|
-
* MDX configuration options for the React plugin.
|
|
7
|
-
*/
|
|
8
|
-
export type ReactMdxOptions = {
|
|
9
|
-
/**
|
|
10
|
-
* Whether to enable MDX support.
|
|
11
|
-
* @default false
|
|
12
|
-
*/
|
|
13
|
-
enabled: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Compiler options for MDX.
|
|
16
|
-
* @default undefined
|
|
17
|
-
*/
|
|
18
|
-
compilerOptions?: Omit<CompileOptions, 'jsxImportSource' | 'jsxRuntime'>;
|
|
19
|
-
/**
|
|
20
|
-
* Remark plugins.
|
|
21
|
-
* @default undefined
|
|
22
|
-
*/
|
|
23
|
-
remarkPlugins?: CompileOptions['remarkPlugins'];
|
|
24
|
-
/**
|
|
25
|
-
* Rehype plugins.
|
|
26
|
-
* @default undefined
|
|
27
|
-
*/
|
|
28
|
-
rehypePlugins?: CompileOptions['rehypePlugins'];
|
|
29
|
-
/**
|
|
30
|
-
* Recma plugins.
|
|
31
|
-
* @default undefined
|
|
32
|
-
*/
|
|
33
|
-
recmaPlugins?: CompileOptions['recmaPlugins'];
|
|
34
|
-
/**
|
|
35
|
-
* Custom extensions to be treated as MDX files.
|
|
36
|
-
* @default ['.mdx']
|
|
37
|
-
*/
|
|
38
|
-
extensions?: string[];
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Options for the React plugin.
|
|
42
|
-
*/
|
|
43
|
-
export type ReactPluginOptions = {
|
|
44
|
-
extensions?: string[];
|
|
45
|
-
dependencies?: AssetDefinition[];
|
|
46
|
-
/**
|
|
47
|
-
* Enables explicit client graph mode for React page entries.
|
|
48
|
-
*
|
|
49
|
-
* When enabled, React page-entry bundling relies on explicit dependency declarations
|
|
50
|
-
* and skips AST-based `middleware`/`requires` stripping in the React path.
|
|
51
|
-
* @default false
|
|
52
|
-
*/
|
|
53
|
-
explicitGraph?: boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Router adapter for SPA navigation.
|
|
56
|
-
* When provided, pages with layouts will be wrapped in the router for client-side navigation.
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* import { ecoRouter } from '@ecopages/react-router';
|
|
60
|
-
* reactPlugin({ router: ecoRouter() })
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
router?: ReactRouterAdapter;
|
|
64
|
-
/**
|
|
65
|
-
* MDX configuration for handling .mdx files within the React plugin.
|
|
66
|
-
* When enabled, MDX files are treated as React pages with full router support.
|
|
67
|
-
* @example
|
|
68
|
-
* ```ts
|
|
69
|
-
* reactPlugin({
|
|
70
|
-
* router: ecoRouter(),
|
|
71
|
-
* mdx: {
|
|
72
|
-
* enabled: true,
|
|
73
|
-
* extensions: ['.mdx', '.md'],
|
|
74
|
-
* remarkPlugins: [remarkGfm],
|
|
75
|
-
* rehypePlugins: [[rehypePrettyCode, { theme: '...' }]],
|
|
76
|
-
* }
|
|
77
|
-
* })
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
mdx?: ReactMdxOptions;
|
|
81
|
-
};
|
|
82
|
-
export type ReactRendererConfig = {
|
|
83
|
-
routerAdapter?: ReactRouterAdapter;
|
|
84
|
-
mdxCompilerOptions?: CompileOptions;
|
|
85
|
-
mdxExtensions?: string[];
|
|
86
|
-
hmrPageMetadataCache?: ReactHmrPageMetadataCache;
|
|
87
|
-
explicitGraphEnabled?: boolean;
|
|
88
|
-
};
|
package/src/react.types.js
DELETED
|
File without changes
|
package/src/router-adapter.js
DELETED
|
File without changes
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Per-app index of React-owned page entrypoints.
|
|
3
|
-
*
|
|
4
|
-
* @remarks
|
|
5
|
-
* The HMR strategy previously called `fileSystem.glob` on every
|
|
6
|
-
* layout change. For apps with many pages this is wasteful: O(pages)
|
|
7
|
-
* on every HMR event, and the result rarely changes between HMR
|
|
8
|
-
* rebuilds.
|
|
9
|
-
*
|
|
10
|
-
* `PagesIndex` maintains a `Set` of owned page entrypoint paths. The
|
|
11
|
-
* initial population is a single glob; subsequent mutations go through
|
|
12
|
-
* `add` / `remove` (called by the HMR strategy when it observes a
|
|
13
|
-
* file create/delete under `pagesDir`). The strategy reads via
|
|
14
|
-
* `list()` for an O(1) snapshot of the current set.
|
|
15
|
-
*
|
|
16
|
-
* Phase 1 ships the class and the `list()` consumer. Watcher-driven
|
|
17
|
-
* `add` / `remove` integration lands in a follow-up — for now the
|
|
18
|
-
* strategy calls `refresh()` lazily, which is equivalent to the old
|
|
19
|
-
* glob behavior but with a stable API for the future incremental
|
|
20
|
-
* path.
|
|
21
|
-
*/
|
|
22
|
-
export type PagesIndexOptions = {
|
|
23
|
-
pagesDir: string;
|
|
24
|
-
extensions?: string[];
|
|
25
|
-
/**
|
|
26
|
-
* Optional predicate to filter out non-page entrypoints (e.g.
|
|
27
|
-
* test fixtures, generated files). Defaults to including every
|
|
28
|
-
* file matching an extension.
|
|
29
|
-
*/
|
|
30
|
-
isPageEntrypoint?: (absolutePath: string) => boolean;
|
|
31
|
-
};
|
|
32
|
-
export declare class PagesIndex {
|
|
33
|
-
private readonly pagesDir;
|
|
34
|
-
private readonly extensions;
|
|
35
|
-
private readonly isPageEntrypoint;
|
|
36
|
-
private readonly pages;
|
|
37
|
-
private lastRefreshAt;
|
|
38
|
-
constructor(options: PagesIndexOptions);
|
|
39
|
-
/**
|
|
40
|
-
* Rescan the pages directory and rebuild the index.
|
|
41
|
-
*
|
|
42
|
-
* Cheap to call multiple times in sequence (just a glob). The
|
|
43
|
-
* real value of `PagesIndex` is the `add` / `remove` path that
|
|
44
|
-
* callers can wire to the file watcher; for now this is the
|
|
45
|
-
* fallback used on layout changes.
|
|
46
|
-
*/
|
|
47
|
-
refresh(): Promise<void>;
|
|
48
|
-
/**
|
|
49
|
-
* Add a single entrypoint. Idempotent.
|
|
50
|
-
*/
|
|
51
|
-
add(absolutePath: string): void;
|
|
52
|
-
/**
|
|
53
|
-
* Remove a single entrypoint. Idempotent.
|
|
54
|
-
*/
|
|
55
|
-
remove(absolutePath: string): void;
|
|
56
|
-
/** True if the index contains `absolutePath`. */
|
|
57
|
-
has(absolutePath: string): boolean;
|
|
58
|
-
/** Snapshot of the current set, sorted by absolute path. */
|
|
59
|
-
list(): string[];
|
|
60
|
-
/** Number of indexed entrypoints. */
|
|
61
|
-
get size(): number;
|
|
62
|
-
/** Last refresh timestamp (ms since epoch). */
|
|
63
|
-
get refreshedAt(): number;
|
|
64
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { fileSystem } from "@ecopages/file-system";
|
|
3
|
-
const DEFAULT_EXTENSIONS = [".tsx", ".kita.tsx", ".lit.tsx", ".eco.tsx", ".mdx", ".react.tsx"];
|
|
4
|
-
class PagesIndex {
|
|
5
|
-
pagesDir;
|
|
6
|
-
extensions;
|
|
7
|
-
isPageEntrypoint;
|
|
8
|
-
pages = /* @__PURE__ */ new Set();
|
|
9
|
-
lastRefreshAt = 0;
|
|
10
|
-
constructor(options) {
|
|
11
|
-
this.pagesDir = options.pagesDir;
|
|
12
|
-
this.extensions = options.extensions ?? DEFAULT_EXTENSIONS;
|
|
13
|
-
this.isPageEntrypoint = options.isPageEntrypoint ?? (() => true);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Rescan the pages directory and rebuild the index.
|
|
17
|
-
*
|
|
18
|
-
* Cheap to call multiple times in sequence (just a glob). The
|
|
19
|
-
* real value of `PagesIndex` is the `add` / `remove` path that
|
|
20
|
-
* callers can wire to the file watcher; for now this is the
|
|
21
|
-
* fallback used on layout changes.
|
|
22
|
-
*/
|
|
23
|
-
async refresh() {
|
|
24
|
-
const files = await fileSystem.glob(
|
|
25
|
-
this.extensions.map((ext) => `**/*${ext}`),
|
|
26
|
-
{
|
|
27
|
-
cwd: this.pagesDir
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
const next = /* @__PURE__ */ new Set();
|
|
31
|
-
for (const file of files) {
|
|
32
|
-
const absolutePath = path.join(this.pagesDir, file);
|
|
33
|
-
if (!this.isPageEntrypoint(absolutePath)) continue;
|
|
34
|
-
if (file.includes(".ecopages-node.")) continue;
|
|
35
|
-
next.add(absolutePath);
|
|
36
|
-
}
|
|
37
|
-
this.pages.clear();
|
|
38
|
-
for (const p of next) this.pages.add(p);
|
|
39
|
-
this.lastRefreshAt = Date.now();
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Add a single entrypoint. Idempotent.
|
|
43
|
-
*/
|
|
44
|
-
add(absolutePath) {
|
|
45
|
-
if (!this.isPageEntrypoint(absolutePath)) return;
|
|
46
|
-
this.pages.add(absolutePath);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Remove a single entrypoint. Idempotent.
|
|
50
|
-
*/
|
|
51
|
-
remove(absolutePath) {
|
|
52
|
-
this.pages.delete(absolutePath);
|
|
53
|
-
}
|
|
54
|
-
/** True if the index contains `absolutePath`. */
|
|
55
|
-
has(absolutePath) {
|
|
56
|
-
return this.pages.has(absolutePath);
|
|
57
|
-
}
|
|
58
|
-
/** Snapshot of the current set, sorted by absolute path. */
|
|
59
|
-
list() {
|
|
60
|
-
return Array.from(this.pages).sort();
|
|
61
|
-
}
|
|
62
|
-
/** Number of indexed entrypoints. */
|
|
63
|
-
get size() {
|
|
64
|
-
return this.pages.size;
|
|
65
|
-
}
|
|
66
|
-
/** Last refresh timestamp (ms since epoch). */
|
|
67
|
-
get refreshedAt() {
|
|
68
|
-
return this.lastRefreshAt;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
export {
|
|
72
|
-
PagesIndex
|
|
73
|
-
};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { createClientGraphBoundaryPlugin } from "../utils/client-graph-boundary-plugin.js";
|
|
2
|
-
import {
|
|
3
|
-
getReactClientGraphAllowSpecifiers,
|
|
4
|
-
getReactRuntimeExternalSpecifiers
|
|
5
|
-
} from "../utils/react-runtime-alias-map.js";
|
|
6
|
-
import { createBrowserRuntimePlugin } from "@ecopages/core/build/browser-runtime-plugin";
|
|
7
|
-
import { createForeignJsxOverridePlugin } from "@ecopages/core/plugins/foreign-jsx-override-plugin";
|
|
8
|
-
import { ReactRuntimeBundleService } from "./react-runtime-bundle.service.js";
|
|
9
|
-
import { createReactMdxLoaderPlugin } from "../utils/react-mdx-loader-plugin.js";
|
|
10
|
-
class ReactBundleService {
|
|
11
|
-
runtimeBundleService;
|
|
12
|
-
config;
|
|
13
|
-
constructor(config) {
|
|
14
|
-
this.config = config;
|
|
15
|
-
this.runtimeBundleService = new ReactRuntimeBundleService({
|
|
16
|
-
rootDir: config.rootDir,
|
|
17
|
-
routerAdapter: config.routerAdapter
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Returns resolved runtime import paths for the React runtime.
|
|
22
|
-
*/
|
|
23
|
-
getRuntimeImports() {
|
|
24
|
-
return this.runtimeBundleService.getRuntimeImports();
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Creates bundle options for a page or component entry.
|
|
28
|
-
*
|
|
29
|
-
* @remarks
|
|
30
|
-
* React derives runtime specifier mappings from the core browser runtime manifest
|
|
31
|
-
* so ESM imports resolve to concrete runtime asset URLs during module loading.
|
|
32
|
-
*
|
|
33
|
-
* @param componentName - Generated unique component name for output naming
|
|
34
|
-
* @param isMdx - Whether the source file is an MDX file
|
|
35
|
-
* @param declaredModules - Explicitly declared browser module specifiers
|
|
36
|
-
* @returns Bundle options object for the build adapter
|
|
37
|
-
*/
|
|
38
|
-
async createBundleOptions(componentName, isMdx, declaredModules, bundleOptions = {}) {
|
|
39
|
-
const runtimeImports = this.getRuntimeImports();
|
|
40
|
-
const options = {
|
|
41
|
-
mainFields: ["module", "browser", "main"],
|
|
42
|
-
naming: `${componentName}.[ext]`,
|
|
43
|
-
...import.meta.env?.NODE_ENV === "production" && {
|
|
44
|
-
minify: true,
|
|
45
|
-
treeshaking: true
|
|
46
|
-
},
|
|
47
|
-
...bundleOptions.splitting === void 0 ? {} : { splitting: bundleOptions.splitting }
|
|
48
|
-
};
|
|
49
|
-
if (!bundleOptions.includeRuntime) {
|
|
50
|
-
const reactRuntimeSpecifiers = new Set(getReactRuntimeExternalSpecifiers());
|
|
51
|
-
options.external = [
|
|
52
|
-
...Object.values(runtimeImports).filter(
|
|
53
|
-
(specifier) => Boolean(specifier) && !reactRuntimeSpecifiers.has(
|
|
54
|
-
specifier
|
|
55
|
-
)
|
|
56
|
-
)
|
|
57
|
-
];
|
|
58
|
-
}
|
|
59
|
-
const graphBoundaryPlugin = createClientGraphBoundaryPlugin({
|
|
60
|
-
absWorkingDir: this.config.rootDir,
|
|
61
|
-
declaredModules,
|
|
62
|
-
alwaysAllowSpecifiers: getReactClientGraphAllowSpecifiers([], this.config.routerAdapter)
|
|
63
|
-
});
|
|
64
|
-
const foreignJsxOverridePlugin = createForeignJsxOverridePlugin({
|
|
65
|
-
name: "react-renderer-foreign-jsx-override",
|
|
66
|
-
hostJsxImportSource: this.config.jsxImportSource ?? "react",
|
|
67
|
-
foreignExtensions: this.config.nonReactExtensions ?? []
|
|
68
|
-
});
|
|
69
|
-
const runtimeManifest = this.runtimeBundleService.getRuntimeManifest();
|
|
70
|
-
const runtimeRewritePlugin = createBrowserRuntimePlugin({
|
|
71
|
-
name: "react-renderer-runtime-import-rewrite",
|
|
72
|
-
manifest: runtimeManifest
|
|
73
|
-
});
|
|
74
|
-
const runtimePlugins = bundleOptions.includeRuntime ? [] : [runtimeRewritePlugin].filter((plugin) => plugin !== null);
|
|
75
|
-
if (isMdx && this.config.mdxCompilerOptions) {
|
|
76
|
-
const mdxPlugin = createReactMdxLoaderPlugin(this.config.mdxCompilerOptions);
|
|
77
|
-
options.plugins = [foreignJsxOverridePlugin, graphBoundaryPlugin, ...runtimePlugins, mdxPlugin];
|
|
78
|
-
} else {
|
|
79
|
-
options.plugins = [foreignJsxOverridePlugin, graphBoundaryPlugin, ...runtimePlugins];
|
|
80
|
-
}
|
|
81
|
-
return options;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
export {
|
|
85
|
-
ReactBundleService
|
|
86
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
class ReactHmrPageMetadataCache {
|
|
3
|
-
declaredModulesByEntrypoint = /* @__PURE__ */ new Map();
|
|
4
|
-
ownedEntrypoints = /* @__PURE__ */ new Set();
|
|
5
|
-
/**
|
|
6
|
-
* Marks an HMR entrypoint as React-owned.
|
|
7
|
-
*/
|
|
8
|
-
markOwnedEntrypoint(entrypointPath) {
|
|
9
|
-
this.ownedEntrypoints.add(path.resolve(entrypointPath));
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Stores the declared browser modules for a page entrypoint.
|
|
13
|
-
*/
|
|
14
|
-
setDeclaredModules(entrypointPath, declaredModules) {
|
|
15
|
-
const resolvedEntrypointPath = path.resolve(entrypointPath);
|
|
16
|
-
this.markOwnedEntrypoint(resolvedEntrypointPath);
|
|
17
|
-
this.declaredModulesByEntrypoint.set(resolvedEntrypointPath, [...declaredModules]);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Returns the last known declared browser modules for a page entrypoint.
|
|
21
|
-
*/
|
|
22
|
-
getDeclaredModules(entrypointPath) {
|
|
23
|
-
const declaredModules = this.declaredModulesByEntrypoint.get(path.resolve(entrypointPath));
|
|
24
|
-
return declaredModules ? [...declaredModules] : void 0;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Returns true when the watched entrypoint is owned by the React integration.
|
|
28
|
-
*/
|
|
29
|
-
ownsEntrypoint(entrypointPath) {
|
|
30
|
-
return this.ownedEntrypoints.has(path.resolve(entrypointPath));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export {
|
|
34
|
-
ReactHmrPageMetadataCache
|
|
35
|
-
};
|
|
@@ -1,84 +0,0 @@
|
|
|
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 AssetDefinition, type ProcessedAsset } from '@ecopages/core/services/asset-processing-service';
|
|
11
|
-
import type { AssetProcessingService } from '@ecopages/core/services/asset-processing-service';
|
|
12
|
-
import type { ReactBundleService } from './react-bundle.service.js';
|
|
13
|
-
import type { ReactHmrPageMetadataCache } from './react-hmr-page-metadata-cache.js';
|
|
14
|
-
import type { ReactRouterAdapter } from '../router-adapter.js';
|
|
15
|
-
/**
|
|
16
|
-
* Configuration for the ReactHydrationAssetService.
|
|
17
|
-
*/
|
|
18
|
-
export interface ReactHydrationAssetServiceConfig {
|
|
19
|
-
srcDir: string;
|
|
20
|
-
routerAdapter?: ReactRouterAdapter;
|
|
21
|
-
assetProcessingService: AssetProcessingService;
|
|
22
|
-
bundleService: ReactBundleService;
|
|
23
|
-
hmrPageMetadataCache?: ReactHmrPageMetadataCache;
|
|
24
|
-
}
|
|
25
|
-
export declare function getReactIslandComponentKey(componentFile: string, config?: EcoComponentConfig): string;
|
|
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
|
-
private static readonly ROUTER_PAGE_GROUPED_BUNDLE_ID;
|
|
32
|
-
constructor(config: ReactHydrationAssetServiceConfig);
|
|
33
|
-
private getIslandBundleName;
|
|
34
|
-
private getIslandHydrationName;
|
|
35
|
-
private getRouterPageGroupedEntryName;
|
|
36
|
-
/**
|
|
37
|
-
* Resolves the browser import path used for a React-owned page or island module.
|
|
38
|
-
* Uses HMR manager for development or constructs static path for production.
|
|
39
|
-
*
|
|
40
|
-
* @param pagePath - Absolute path to the page source file
|
|
41
|
-
* @param assetName - Generated asset name
|
|
42
|
-
* @returns The resolved browser import path for the module
|
|
43
|
-
*/
|
|
44
|
-
resolveAssetImportPath(pagePath: string, assetName: string): Promise<string>;
|
|
45
|
-
/**
|
|
46
|
-
* Creates the page-owned route entry asset for hydration and client navigation.
|
|
47
|
-
*
|
|
48
|
-
* @param pagePath - Absolute path to the page source file
|
|
49
|
-
* @param componentName - Generated unique component name
|
|
50
|
-
* @param importPath - Resolved browser import path used by development HMR
|
|
51
|
-
* @param bundleOptions - Bundle configuration options
|
|
52
|
-
* @param isDevelopment - Whether running in development mode with HMR
|
|
53
|
-
* @param isMdx - Whether the source file is an MDX file
|
|
54
|
-
* @returns One page-owned asset definition for processing
|
|
55
|
-
*/
|
|
56
|
-
createPageDependencies(pagePath: string, componentName: string, importPath: string, pageModuleUrlExpression: string, bundleOptions: Record<string, unknown>, isDevelopment: boolean, useBrowserRuntimeImports: boolean, isMdx: boolean): AssetDefinition[];
|
|
57
|
-
/**
|
|
58
|
-
* Builds client-side assets for a React component island.
|
|
59
|
-
*
|
|
60
|
-
* Includes the bundled component entry and a shared hydration bootstrap script.
|
|
61
|
-
*
|
|
62
|
-
* @param componentFile - Absolute path to the component source file
|
|
63
|
-
* @param config - Optional component config with `__eco` metadata
|
|
64
|
-
* @returns Processed assets ready for injection
|
|
65
|
-
*/
|
|
66
|
-
buildComponentRenderAssets(componentFile: string, config?: EcoComponentConfig): Promise<ProcessedAsset[]>;
|
|
67
|
-
/**
|
|
68
|
-
* Creates the Page Browser Graph dependency declarations for a React page.
|
|
69
|
-
*
|
|
70
|
-
* @param pagePath - Absolute file path of the page
|
|
71
|
-
* @param isMdx - Whether the page is an MDX file
|
|
72
|
-
* @param declaredModules - Explicitly declared browser module specifiers
|
|
73
|
-
* @returns Declarative assets for core-owned processing
|
|
74
|
-
*/
|
|
75
|
-
createPageBrowserGraphDependencies(pagePath: string, isMdx: boolean, declaredModules: string[]): Promise<AssetDefinition[]>;
|
|
76
|
-
/**
|
|
77
|
-
* Builds the Page Browser Graph assets for a React page.
|
|
78
|
-
*
|
|
79
|
-
* @remarks
|
|
80
|
-
* Kept as a compatibility wrapper while callers migrate to core-owned page
|
|
81
|
-
* graph assembly.
|
|
82
|
-
*/
|
|
83
|
-
buildPageBrowserGraphAssets(pagePath: string, isMdx: boolean, declaredModules: string[]): Promise<ProcessedAsset[]>;
|
|
84
|
-
}
|