@ecopages/react 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +178 -35
- package/package.json +80 -32
- package/src/app/client-only.js +10 -0
- package/src/app/dynamic.js +9 -0
- package/src/app/dynamic.test.browser.d.ts +1 -0
- package/src/app/dynamic.test.browser.js +38 -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/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/browser/island-hydration.d.ts +82 -0
- package/src/hydration/browser/island-hydration.js +251 -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 +127 -0
- package/src/hydration/hydration-asset.js +379 -0
- package/src/hydration/hydration-lifecycle.test.browser.d.ts +1 -0
- package/src/hydration/hydration-lifecycle.test.browser.js +461 -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 +48 -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
package/src/react.plugin.d.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module contains the react plugin for Ecopages
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
import { IntegrationPlugin } from '@ecopages/core/plugins/integration-plugin';
|
|
6
|
-
import type { EcoBuildPlugin } from '@ecopages/core/build/build-types';
|
|
7
|
-
import type { HmrStrategy } from '@ecopages/core/hmr/hmr-strategy';
|
|
8
|
-
import type { AssetDefinition } from '@ecopages/core/services/asset-processing-service';
|
|
9
|
-
import type { CompileOptions } from '@mdx-js/mdx';
|
|
10
|
-
import type React from 'react';
|
|
11
|
-
import { ReactRenderer } from './react-renderer.js';
|
|
12
|
-
import type { ReactRouterAdapter } from './router-adapter.js';
|
|
13
|
-
/**
|
|
14
|
-
* MDX configuration options for the React plugin
|
|
15
|
-
*/
|
|
16
|
-
export type ReactMdxOptions = {
|
|
17
|
-
/**
|
|
18
|
-
* Whether to enable MDX support.
|
|
19
|
-
* @default false
|
|
20
|
-
*/
|
|
21
|
-
enabled: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Compiler options for MDX.
|
|
24
|
-
* @default undefined
|
|
25
|
-
*/
|
|
26
|
-
compilerOptions?: Omit<CompileOptions, 'jsxImportSource' | 'jsxRuntime'>;
|
|
27
|
-
/**
|
|
28
|
-
* Remark plugins.
|
|
29
|
-
* @default undefined
|
|
30
|
-
*/
|
|
31
|
-
remarkPlugins?: CompileOptions['remarkPlugins'];
|
|
32
|
-
/**
|
|
33
|
-
* Rehype plugins.
|
|
34
|
-
* @default undefined
|
|
35
|
-
*/
|
|
36
|
-
rehypePlugins?: CompileOptions['rehypePlugins'];
|
|
37
|
-
/**
|
|
38
|
-
* Recma plugins.
|
|
39
|
-
* @default undefined
|
|
40
|
-
*/
|
|
41
|
-
recmaPlugins?: CompileOptions['recmaPlugins'];
|
|
42
|
-
/**
|
|
43
|
-
* Custom extensions to be treated as MDX files.
|
|
44
|
-
* @default ['.mdx']
|
|
45
|
-
*/
|
|
46
|
-
extensions?: string[];
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Options for the React plugin
|
|
50
|
-
*/
|
|
51
|
-
export type ReactPluginOptions = {
|
|
52
|
-
extensions?: string[];
|
|
53
|
-
dependencies?: AssetDefinition[];
|
|
54
|
-
/**
|
|
55
|
-
* Enables explicit client graph mode for React page entries.
|
|
56
|
-
*
|
|
57
|
-
* When enabled, React page-entry bundling relies on explicit dependency declarations
|
|
58
|
-
* and skips AST-based `middleware`/`requires` stripping in the React path.
|
|
59
|
-
* @default false
|
|
60
|
-
*/
|
|
61
|
-
explicitGraph?: boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Router adapter for SPA navigation.
|
|
64
|
-
* When provided, pages with layouts will be wrapped in the router for client-side navigation.
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* import { ecoRouter } from '@ecopages/react-router';
|
|
68
|
-
* reactPlugin({ router: ecoRouter() })
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
router?: ReactRouterAdapter;
|
|
72
|
-
/**
|
|
73
|
-
* MDX configuration for handling .mdx files within the React plugin.
|
|
74
|
-
* When enabled, MDX files are treated as React pages with full router support.
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* reactPlugin({
|
|
78
|
-
* router: ecoRouter(),
|
|
79
|
-
* mdx: {
|
|
80
|
-
* enabled: true,
|
|
81
|
-
* extensions: ['.mdx', '.md'],
|
|
82
|
-
* remarkPlugins: [remarkGfm],
|
|
83
|
-
* rehypePlugins: [[rehypePrettyCode, { theme: '...' }]],
|
|
84
|
-
* }
|
|
85
|
-
* })
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
mdx?: ReactMdxOptions;
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* The name of the React plugin
|
|
92
|
-
*/
|
|
93
|
-
export declare const PLUGIN_NAME = "react";
|
|
94
|
-
/**
|
|
95
|
-
* The React plugin class
|
|
96
|
-
* This plugin provides support for React components in Ecopages
|
|
97
|
-
*/
|
|
98
|
-
export declare class ReactPlugin extends IntegrationPlugin<React.JSX.Element> {
|
|
99
|
-
renderer: typeof ReactRenderer;
|
|
100
|
-
routerAdapter: ReactRouterAdapter | undefined;
|
|
101
|
-
private mdxEnabled;
|
|
102
|
-
private mdxCompilerOptions?;
|
|
103
|
-
private mdxExtensions;
|
|
104
|
-
private mdxLoaderPlugin;
|
|
105
|
-
private runtimeBundleService;
|
|
106
|
-
private readonly hmrPageMetadataCache;
|
|
107
|
-
private runtimeDependenciesInitialized;
|
|
108
|
-
/**
|
|
109
|
-
* Indicates whether React explicit graph mode is enabled for renderer/HMR behavior.
|
|
110
|
-
*/
|
|
111
|
-
private explicitGraphEnabled;
|
|
112
|
-
constructor(options?: Omit<ReactPluginOptions, 'name'>);
|
|
113
|
-
private ensureRuntimeDependencies;
|
|
114
|
-
get plugins(): EcoBuildPlugin[];
|
|
115
|
-
/**
|
|
116
|
-
* Ensures the optional React MDX loader exists before either config-time
|
|
117
|
-
* manifest sealing or runtime setup needs it.
|
|
118
|
-
*/
|
|
119
|
-
private ensureMdxLoaderPlugin;
|
|
120
|
-
/**
|
|
121
|
-
* Prepares React's build-facing loader contributions before config build seals
|
|
122
|
-
* the app manifest.
|
|
123
|
-
*/
|
|
124
|
-
prepareBuildContributions(): Promise<void>;
|
|
125
|
-
/**
|
|
126
|
-
* Performs runtime-only React setup after build contributions are already
|
|
127
|
-
* materialized.
|
|
128
|
-
*/
|
|
129
|
-
setup(): Promise<void>;
|
|
130
|
-
/**
|
|
131
|
-
* Provides React-specific HMR strategy with Fast Refresh support.
|
|
132
|
-
*
|
|
133
|
-
* The strategy shares a React-only page metadata cache with the renderer so
|
|
134
|
-
* save-time rebuilds can reuse declared-module analysis without expanding the
|
|
135
|
-
* core HMR interfaces.
|
|
136
|
-
*
|
|
137
|
-
* @returns ReactHmrStrategy instance for handling React component updates
|
|
138
|
-
*/
|
|
139
|
-
getHmrStrategy(): HmrStrategy | undefined;
|
|
140
|
-
getRuntimeSpecifierMap(): Record<string, string>;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Factory function to create a React plugin instance
|
|
144
|
-
* @param options Configuration options for the React plugin
|
|
145
|
-
* @returns A new ReactPlugin instance
|
|
146
|
-
*/
|
|
147
|
-
export declare function reactPlugin(options?: ReactPluginOptions): ReactPlugin;
|
package/src/react.plugin.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { IntegrationPlugin } from "@ecopages/core/plugins/integration-plugin";
|
|
2
|
-
import { Logger } from "@ecopages/logger";
|
|
3
|
-
import { ReactRenderer } from "./react-renderer.js";
|
|
4
|
-
import { ReactHmrStrategy } from "./react-hmr-strategy.js";
|
|
5
|
-
import { ReactRuntimeBundleService } from "./services/react-runtime-bundle.service.js";
|
|
6
|
-
import { ReactHmrPageMetadataCache } from "./services/react-hmr-page-metadata-cache.js";
|
|
7
|
-
const appLogger = new Logger("[ReactPlugin]");
|
|
8
|
-
const PLUGIN_NAME = "react";
|
|
9
|
-
class ReactPlugin extends IntegrationPlugin {
|
|
10
|
-
renderer = ReactRenderer;
|
|
11
|
-
routerAdapter;
|
|
12
|
-
mdxEnabled;
|
|
13
|
-
mdxCompilerOptions;
|
|
14
|
-
mdxExtensions;
|
|
15
|
-
mdxLoaderPlugin;
|
|
16
|
-
runtimeBundleService;
|
|
17
|
-
hmrPageMetadataCache = new ReactHmrPageMetadataCache();
|
|
18
|
-
runtimeDependenciesInitialized = false;
|
|
19
|
-
/**
|
|
20
|
-
* Indicates whether React explicit graph mode is enabled for renderer/HMR behavior.
|
|
21
|
-
*/
|
|
22
|
-
explicitGraphEnabled;
|
|
23
|
-
constructor(options) {
|
|
24
|
-
const { extensions: _ignoredExtensions, ...restOptions } = options ?? {};
|
|
25
|
-
const extensions = [...options?.extensions ?? [".tsx"]];
|
|
26
|
-
const mdxExtensions = options?.mdx?.extensions ?? [".mdx"];
|
|
27
|
-
if (options?.mdx?.enabled) {
|
|
28
|
-
for (const extension of mdxExtensions) {
|
|
29
|
-
if (!extensions.includes(extension)) {
|
|
30
|
-
extensions.push(extension);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
} else if (options?.mdx?.extensions?.length) {
|
|
34
|
-
appLogger.warn(
|
|
35
|
-
"MDX extensions provided but MDX is disabled. MDX files will not be processed. Set mdx.enabled to true to enable MDX support."
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
super({
|
|
39
|
-
name: PLUGIN_NAME,
|
|
40
|
-
extensions,
|
|
41
|
-
jsxImportSource: "react",
|
|
42
|
-
...restOptions
|
|
43
|
-
});
|
|
44
|
-
this.mdxEnabled = options?.mdx?.enabled ?? false;
|
|
45
|
-
this.mdxExtensions = mdxExtensions;
|
|
46
|
-
if (this.mdxEnabled) {
|
|
47
|
-
const { compilerOptions, remarkPlugins, rehypePlugins, recmaPlugins } = options?.mdx || {};
|
|
48
|
-
this.mdxCompilerOptions = {
|
|
49
|
-
...compilerOptions,
|
|
50
|
-
remarkPlugins: [...compilerOptions?.remarkPlugins || [], ...remarkPlugins || []],
|
|
51
|
-
rehypePlugins: [...compilerOptions?.rehypePlugins || [], ...rehypePlugins || []],
|
|
52
|
-
recmaPlugins: [...compilerOptions?.recmaPlugins || [], ...recmaPlugins || []],
|
|
53
|
-
jsxImportSource: "react",
|
|
54
|
-
jsxRuntime: "automatic",
|
|
55
|
-
development: process.env.NODE_ENV === "development"
|
|
56
|
-
};
|
|
57
|
-
appLogger.debug("MDX mode enabled with React jsx runtime");
|
|
58
|
-
}
|
|
59
|
-
this.routerAdapter = options?.router;
|
|
60
|
-
this.runtimeBundleService = new ReactRuntimeBundleService({
|
|
61
|
-
routerAdapter: this.routerAdapter
|
|
62
|
-
});
|
|
63
|
-
this.explicitGraphEnabled = options?.explicitGraph ?? false;
|
|
64
|
-
ReactRenderer.routerAdapter = this.routerAdapter;
|
|
65
|
-
ReactRenderer.mdxCompilerOptions = this.mdxCompilerOptions;
|
|
66
|
-
ReactRenderer.mdxExtensions = this.mdxExtensions;
|
|
67
|
-
ReactRenderer.explicitGraphEnabled = this.explicitGraphEnabled;
|
|
68
|
-
ReactRenderer.hmrPageMetadataCache = this.hmrPageMetadataCache;
|
|
69
|
-
}
|
|
70
|
-
ensureRuntimeDependencies() {
|
|
71
|
-
if (this.runtimeDependenciesInitialized) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
this.runtimeBundleService.setRootDir(this.appConfig?.rootDir);
|
|
75
|
-
this.integrationDependencies.unshift(...this.runtimeBundleService.getDependencies());
|
|
76
|
-
this.runtimeDependenciesInitialized = true;
|
|
77
|
-
}
|
|
78
|
-
get plugins() {
|
|
79
|
-
if (this.mdxLoaderPlugin) {
|
|
80
|
-
return [this.mdxLoaderPlugin];
|
|
81
|
-
}
|
|
82
|
-
return [];
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Ensures the optional React MDX loader exists before either config-time
|
|
86
|
-
* manifest sealing or runtime setup needs it.
|
|
87
|
-
*/
|
|
88
|
-
async ensureMdxLoaderPlugin() {
|
|
89
|
-
if (!this.mdxEnabled || !this.mdxCompilerOptions || this.mdxLoaderPlugin) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const { createReactMdxLoaderPlugin } = await import("./utils/react-mdx-loader-plugin.js");
|
|
93
|
-
this.mdxLoaderPlugin = createReactMdxLoaderPlugin(this.mdxCompilerOptions);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Prepares React's build-facing loader contributions before config build seals
|
|
97
|
-
* the app manifest.
|
|
98
|
-
*/
|
|
99
|
-
async prepareBuildContributions() {
|
|
100
|
-
this.ensureRuntimeDependencies();
|
|
101
|
-
await this.ensureMdxLoaderPlugin();
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Performs runtime-only React setup after build contributions are already
|
|
105
|
-
* materialized.
|
|
106
|
-
*/
|
|
107
|
-
async setup() {
|
|
108
|
-
this.ensureRuntimeDependencies();
|
|
109
|
-
await this.ensureMdxLoaderPlugin();
|
|
110
|
-
await super.setup();
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Provides React-specific HMR strategy with Fast Refresh support.
|
|
114
|
-
*
|
|
115
|
-
* The strategy shares a React-only page metadata cache with the renderer so
|
|
116
|
-
* save-time rebuilds can reuse declared-module analysis without expanding the
|
|
117
|
-
* core HMR interfaces.
|
|
118
|
-
*
|
|
119
|
-
* @returns ReactHmrStrategy instance for handling React component updates
|
|
120
|
-
*/
|
|
121
|
-
getHmrStrategy() {
|
|
122
|
-
if (!this.hmrManager || !this.appConfig) {
|
|
123
|
-
return void 0;
|
|
124
|
-
}
|
|
125
|
-
const context = this.hmrManager.getDefaultContext();
|
|
126
|
-
return new ReactHmrStrategy(
|
|
127
|
-
context,
|
|
128
|
-
this.hmrPageMetadataCache,
|
|
129
|
-
this.mdxCompilerOptions,
|
|
130
|
-
this.extensions,
|
|
131
|
-
this.appConfig.templatesExt,
|
|
132
|
-
this.explicitGraphEnabled
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
getRuntimeSpecifierMap() {
|
|
136
|
-
return this.runtimeBundleService.getSpecifierMap();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
function reactPlugin(options) {
|
|
140
|
-
return new ReactPlugin(options);
|
|
141
|
-
}
|
|
142
|
-
export {
|
|
143
|
-
PLUGIN_NAME,
|
|
144
|
-
ReactPlugin,
|
|
145
|
-
reactPlugin
|
|
146
|
-
};
|
package/src/router-adapter.js
DELETED
|
File without changes
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
nonReactExtensions?: string[];
|
|
20
|
-
jsxImportSource?: string;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Manages esbuild bundle configuration and plugin creation for React page/component builds.
|
|
24
|
-
*/
|
|
25
|
-
export declare class ReactBundleService {
|
|
26
|
-
private readonly runtimeBundleService;
|
|
27
|
-
private readonly config;
|
|
28
|
-
constructor(config: ReactBundleServiceConfig);
|
|
29
|
-
/**
|
|
30
|
-
* Returns resolved runtime import paths for the React runtime.
|
|
31
|
-
*/
|
|
32
|
-
getRuntimeImports(): ReactRuntimeImports;
|
|
33
|
-
/**
|
|
34
|
-
* Creates esbuild bundle options for a page or component entry.
|
|
35
|
-
*
|
|
36
|
-
* @param componentName - Generated unique component name for output naming
|
|
37
|
-
* @param isMdx - Whether the source file is an MDX file
|
|
38
|
-
* @param declaredModules - Explicitly declared browser module specifiers
|
|
39
|
-
* @returns Bundle options object for the build adapter
|
|
40
|
-
*/
|
|
41
|
-
createBundleOptions(componentName: string, isMdx: boolean, declaredModules: string[]): Promise<Record<string, unknown>>;
|
|
42
|
-
/**
|
|
43
|
-
* Creates the esbuild plugin that rewrites bare React specifiers
|
|
44
|
-
* to their runtime asset URLs.
|
|
45
|
-
*/
|
|
46
|
-
createRuntimeAliasPlugin(runtimeSpecifierMap: Record<string, string>): import("@ecopages/core/build/build-types").EcoBuildPlugin | null;
|
|
47
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { createClientGraphBoundaryPlugin } from "../utils/client-graph-boundary-plugin.js";
|
|
2
|
-
import {
|
|
3
|
-
buildReactRuntimeSpecifierMap,
|
|
4
|
-
getReactClientGraphAllowSpecifiers,
|
|
5
|
-
getReactRuntimeExternalSpecifiers
|
|
6
|
-
} from "../utils/react-runtime-specifier-map.js";
|
|
7
|
-
import { createUseSyncExternalStoreShimPlugin } from "../utils/use-sync-external-store-shim-plugin.js";
|
|
8
|
-
import { createRuntimeSpecifierAliasPlugin } from "@ecopages/core/build/runtime-specifier-alias-plugin";
|
|
9
|
-
import { createForeignJsxOverridePlugin } from "@ecopages/core/plugins/foreign-jsx-override-plugin";
|
|
10
|
-
import { ReactRuntimeBundleService } from "./react-runtime-bundle.service.js";
|
|
11
|
-
class ReactBundleService {
|
|
12
|
-
runtimeBundleService;
|
|
13
|
-
config;
|
|
14
|
-
constructor(config) {
|
|
15
|
-
this.config = config;
|
|
16
|
-
this.runtimeBundleService = new ReactRuntimeBundleService({
|
|
17
|
-
rootDir: config.rootDir,
|
|
18
|
-
routerAdapter: config.routerAdapter
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Returns resolved runtime import paths for the React runtime.
|
|
23
|
-
*/
|
|
24
|
-
getRuntimeImports() {
|
|
25
|
-
return this.runtimeBundleService.getRuntimeImports();
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Creates esbuild bundle options for a page or component entry.
|
|
29
|
-
*
|
|
30
|
-
* @param componentName - Generated unique component name for output naming
|
|
31
|
-
* @param isMdx - Whether the source file is an MDX file
|
|
32
|
-
* @param declaredModules - Explicitly declared browser module specifiers
|
|
33
|
-
* @returns Bundle options object for the build adapter
|
|
34
|
-
*/
|
|
35
|
-
async createBundleOptions(componentName, isMdx, declaredModules) {
|
|
36
|
-
const runtimeImports = this.getRuntimeImports();
|
|
37
|
-
const runtimeSpecifierMap = buildReactRuntimeSpecifierMap(runtimeImports, this.config.routerAdapter);
|
|
38
|
-
const options = {
|
|
39
|
-
external: getReactRuntimeExternalSpecifiers(),
|
|
40
|
-
mainFields: ["module", "browser", "main"],
|
|
41
|
-
naming: `${componentName}.[ext]`,
|
|
42
|
-
...import.meta.env?.NODE_ENV === "production" && {
|
|
43
|
-
minify: true,
|
|
44
|
-
splitting: false,
|
|
45
|
-
treeshaking: true
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const graphBoundaryPlugin = createClientGraphBoundaryPlugin({
|
|
49
|
-
absWorkingDir: this.config.rootDir,
|
|
50
|
-
declaredModules,
|
|
51
|
-
alwaysAllowSpecifiers: getReactClientGraphAllowSpecifiers([], this.config.routerAdapter)
|
|
52
|
-
});
|
|
53
|
-
const foreignJsxOverridePlugin = createForeignJsxOverridePlugin({
|
|
54
|
-
name: "react-renderer-foreign-jsx-override",
|
|
55
|
-
hostJsxImportSource: this.config.jsxImportSource ?? "react",
|
|
56
|
-
foreignExtensions: this.config.nonReactExtensions ?? []
|
|
57
|
-
});
|
|
58
|
-
const runtimeAliasPlugin = this.createRuntimeAliasPlugin(runtimeSpecifierMap);
|
|
59
|
-
const useSyncExternalStoreShimPlugin = createUseSyncExternalStoreShimPlugin({
|
|
60
|
-
name: "react-renderer-use-sync-external-store-shim",
|
|
61
|
-
namespace: "ecopages-react-renderer-shim"
|
|
62
|
-
});
|
|
63
|
-
if (isMdx && this.config.mdxCompilerOptions) {
|
|
64
|
-
const { createReactMdxLoaderPlugin } = await import("../utils/react-mdx-loader-plugin.js");
|
|
65
|
-
const mdxPlugin = createReactMdxLoaderPlugin(this.config.mdxCompilerOptions);
|
|
66
|
-
options.plugins = [
|
|
67
|
-
foreignJsxOverridePlugin,
|
|
68
|
-
graphBoundaryPlugin,
|
|
69
|
-
runtimeAliasPlugin,
|
|
70
|
-
mdxPlugin,
|
|
71
|
-
useSyncExternalStoreShimPlugin
|
|
72
|
-
];
|
|
73
|
-
} else {
|
|
74
|
-
options.plugins = [
|
|
75
|
-
foreignJsxOverridePlugin,
|
|
76
|
-
graphBoundaryPlugin,
|
|
77
|
-
runtimeAliasPlugin,
|
|
78
|
-
useSyncExternalStoreShimPlugin
|
|
79
|
-
];
|
|
80
|
-
}
|
|
81
|
-
return options;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Creates the esbuild plugin that rewrites bare React specifiers
|
|
85
|
-
* to their runtime asset URLs.
|
|
86
|
-
*/
|
|
87
|
-
createRuntimeAliasPlugin(runtimeSpecifierMap) {
|
|
88
|
-
return createRuntimeSpecifierAliasPlugin(runtimeSpecifierMap, { name: "react-runtime-import-alias" });
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
export {
|
|
92
|
-
ReactBundleService
|
|
93
|
-
};
|
|
@@ -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,76 +0,0 @@
|
|
|
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
|
-
export declare function getReactIslandComponentKey(componentFile: string, config?: EcoComponentConfig): string;
|
|
27
|
-
/**
|
|
28
|
-
* Manages the creation of client-side hydration assets for React pages and component islands.
|
|
29
|
-
*/
|
|
30
|
-
export declare class ReactHydrationAssetService {
|
|
31
|
-
private readonly config;
|
|
32
|
-
constructor(config: ReactHydrationAssetServiceConfig);
|
|
33
|
-
private getIslandBundleName;
|
|
34
|
-
private getIslandHydrationName;
|
|
35
|
-
/**
|
|
36
|
-
* Resolves the import path for the bundled page component.
|
|
37
|
-
* Uses HMR manager for development or constructs static path for production.
|
|
38
|
-
*
|
|
39
|
-
* @param pagePath - Absolute path to the page source file
|
|
40
|
-
* @param assetName - Generated asset name
|
|
41
|
-
* @returns The resolved import path for the bundled component
|
|
42
|
-
*/
|
|
43
|
-
resolveAssetImportPath(pagePath: string, assetName: string): Promise<string>;
|
|
44
|
-
/**
|
|
45
|
-
* Creates the asset dependencies for a page: the bundled component and hydration script.
|
|
46
|
-
*
|
|
47
|
-
* @param pagePath - Absolute path to the page source file
|
|
48
|
-
* @param componentName - Generated unique component name
|
|
49
|
-
* @param importPath - Resolved import path for the bundled component
|
|
50
|
-
* @param bundleOptions - Bundle configuration options
|
|
51
|
-
* @param isDevelopment - Whether running in development mode with HMR
|
|
52
|
-
* @param isMdx - Whether the source file is an MDX file
|
|
53
|
-
* @param props - Optional page props for client serialization
|
|
54
|
-
* @returns Array of asset definitions for processing
|
|
55
|
-
*/
|
|
56
|
-
createPageDependencies(pagePath: string, componentName: string, importPath: string, bundleOptions: Record<string, unknown>, isDevelopment: boolean, isMdx: boolean, props?: Record<string, unknown>): 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
|
-
* Builds all client-side route assets for a 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 Processed assets for the route
|
|
74
|
-
*/
|
|
75
|
-
buildRouteRenderAssets(pagePath: string, isMdx: boolean, declaredModules: string[]): Promise<ProcessedAsset[]>;
|
|
76
|
-
}
|