@ecopages/react 0.2.0-beta.31 → 0.2.0-beta.32
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 +5 -1
- package/package.json +4 -4
- package/src/app/client-only.js +13 -17
- package/src/app/dynamic.js +7 -10
- package/src/app/dynamic.test.browser.js +27 -29
- package/src/bundling/bootstrap-package-paths.js +5 -6
- package/src/bundling/bundle.js +115 -114
- package/src/bundling/discover-layout-runtime-modules.js +166 -155
- package/src/bundling/runtime-alias-map.d.ts +4 -1
- package/src/bundling/runtime-alias-map.js +107 -95
- package/src/bundling/runtime-bundle.js +250 -274
- package/src/bundling/runtime-interop-plugin.js +31 -35
- package/src/bundling/runtime-mode.js +10 -5
- package/src/bundling/runtime-modules.js +46 -35
- package/src/client-graph/ast-transform.js +415 -305
- package/src/client-graph/boundary-cache.js +146 -104
- package/src/client-graph/boundary-plugin.js +122 -104
- package/src/client-graph/component-config-traversal.js +70 -49
- package/src/client-graph/declared-modules.js +63 -41
- package/src/client-graph/reachability-analyzer.js +506 -313
- package/src/client-graph/specifier-classification.js +209 -141
- 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 +22 -9
- package/src/hmr/hmr-strategy.d.ts +12 -181
- package/src/hmr/hmr-strategy.js +321 -650
- package/src/hmr/page-metadata-cache.js +43 -40
- 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.js +6 -6
- package/src/hydration/bootstrap-imports.js +30 -20
- package/src/hydration/hydration-asset.js +216 -213
- package/src/hydration/hydration-scripts.d.ts +4 -0
- package/src/hydration/hydration-scripts.js +199 -66
- package/src/hydration/hydration-scripts.test.browser.js +163 -168
- package/src/hydration/page-data-manifest.js +89 -45
- package/src/hydration/page-data-reader.js +45 -32
- package/src/hydration/page-payload.js +101 -99
- package/src/hydration/serialize-page-data-script.js +27 -28
- package/src/mdx/mdx-config-dependency.js +108 -112
- package/src/mdx/mdx-loader-plugin.js +7 -10
- package/src/page/page-module.js +72 -66
- package/src/plugin/react.constants.js +1 -4
- package/src/plugin/react.plugin.d.ts +1 -0
- package/src/plugin/react.plugin.js +227 -216
- package/src/plugin/react.types.js +1 -0
- package/src/render/component-ownership.js +42 -18
- package/src/render/component-ssr.js +168 -190
- package/src/render/eco-embed.js +8 -10
- package/src/render/errors.js +21 -16
- package/src/render/html-boundary.js +55 -51
- package/src/render/layout-compose.js +122 -94
- package/src/render/react-renderer.js +433 -468
- package/src/render/react-runtime.js +25 -20
- package/src/render/unified-layout-composition.js +74 -85
- package/src/runtime/use-sync-external-store-with-selector.js +52 -54
package/src/page/page-module.js
CHANGED
|
@@ -1,72 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return config;
|
|
1
|
+
/**
|
|
2
|
+
* Page module loading and configuration resolution service for React integration.
|
|
3
|
+
*
|
|
4
|
+
* Handles component config metadata resolution and module hydration analysis.
|
|
5
|
+
* MDX page modules load through the core {@link PageModuleImportService} path
|
|
6
|
+
* using the React plugin's server build contributions.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { rapidhash } from '@ecopages/core/hash';
|
|
12
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
13
|
+
import { someInConfigTree } from '../client-graph/component-config-traversal.js';
|
|
14
|
+
import { collectPageDeclaredModulesFromModule } from '../client-graph/declared-modules.js';
|
|
15
|
+
/**
|
|
16
|
+
* Manages page module metadata resolution and hydration analysis for React pages.
|
|
17
|
+
*/
|
|
18
|
+
export class PageModuleService {
|
|
19
|
+
config;
|
|
20
|
+
constructor(config) {
|
|
21
|
+
this.config = config;
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the given file path corresponds to an MDX file based on configured extensions.
|
|
25
|
+
*/
|
|
26
|
+
isMdxFile(filePath) {
|
|
27
|
+
return this.config.mdxExtensions.some((ext) => filePath.endsWith(ext));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Ensures that an EcoComponentConfig has proper `__eco` metadata attached.
|
|
31
|
+
*/
|
|
32
|
+
ensureConfigFileMetadata(config, pagePath) {
|
|
33
|
+
if (config.__eco?.file) {
|
|
34
|
+
return config;
|
|
35
|
+
}
|
|
36
|
+
const buildEcoMeta = (file) => ({
|
|
37
|
+
id: config.__eco?.id ?? rapidhash(file).toString(36),
|
|
38
|
+
integration: config.__eco?.integration ?? this.config.integrationName,
|
|
39
|
+
file,
|
|
40
|
+
});
|
|
41
|
+
const resolveDependencyValue = (value) => typeof value === 'string' ? value : value.src;
|
|
42
|
+
const dependencyPaths = [
|
|
43
|
+
...(config.dependencies?.stylesheets ?? []).map(resolveDependencyValue),
|
|
44
|
+
...(config.dependencies?.scripts ?? []).map(resolveDependencyValue),
|
|
45
|
+
]
|
|
46
|
+
.filter((value) => Boolean(value))
|
|
47
|
+
.filter((value) => value.startsWith('./') || value.startsWith('../'));
|
|
48
|
+
const candidateDirs = [this.config.layoutsDir, this.config.componentsDir, path.dirname(pagePath)].filter((value) => typeof value === 'string' && value.length > 0);
|
|
49
|
+
for (const dependencyPath of dependencyPaths) {
|
|
50
|
+
for (const candidateDir of candidateDirs) {
|
|
51
|
+
const resolvedDependency = path.resolve(candidateDir, dependencyPath);
|
|
52
|
+
if (fileSystem.exists(resolvedDependency)) {
|
|
53
|
+
return {
|
|
54
|
+
...config,
|
|
55
|
+
__eco: buildEcoMeta(path.join(candidateDir, path.basename(pagePath))),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
42
61
|
...config,
|
|
43
|
-
__eco: buildEcoMeta(
|
|
44
|
-
|
|
62
|
+
__eco: buildEcoMeta(pagePath),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
hasModulesInConfig(config) {
|
|
66
|
+
return someInConfigTree(config, (node) => node.dependencies?.modules?.some((entry) => entry.trim().length > 0) ?? false);
|
|
67
|
+
}
|
|
68
|
+
shouldHydratePage(pageModule) {
|
|
69
|
+
if (this.config.hasRouterAdapter) {
|
|
70
|
+
return true;
|
|
45
71
|
}
|
|
46
|
-
|
|
72
|
+
const pageConfig = pageModule.default?.config;
|
|
73
|
+
return this.hasModulesInConfig(pageConfig) || this.hasModulesInConfig(pageModule.config);
|
|
47
74
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
__eco: buildEcoMeta(pagePath)
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
hasModulesInConfig(config) {
|
|
54
|
-
return someInConfigTree(
|
|
55
|
-
config,
|
|
56
|
-
(node) => node.dependencies?.modules?.some((entry) => entry.trim().length > 0) ?? false
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
shouldHydratePage(pageModule) {
|
|
60
|
-
if (this.config.hasRouterAdapter) {
|
|
61
|
-
return true;
|
|
75
|
+
collectPageDeclaredModules(pageModule) {
|
|
76
|
+
return collectPageDeclaredModulesFromModule(pageModule);
|
|
62
77
|
}
|
|
63
|
-
const pageConfig = pageModule.default?.config;
|
|
64
|
-
return this.hasModulesInConfig(pageConfig) || this.hasModulesInConfig(pageModule.config);
|
|
65
|
-
}
|
|
66
|
-
collectPageDeclaredModules(pageModule) {
|
|
67
|
-
return collectPageDeclaredModulesFromModule(pageModule);
|
|
68
|
-
}
|
|
69
78
|
}
|
|
70
|
-
export {
|
|
71
|
-
PageModuleService
|
|
72
|
-
};
|
|
@@ -72,6 +72,7 @@ export declare class ReactPlugin extends IntegrationPlugin<React.ReactNode> {
|
|
|
72
72
|
*
|
|
73
73
|
* @returns ReactHmrStrategy instance for handling React component updates
|
|
74
74
|
*/
|
|
75
|
+
setHmrManager(hmrManager: NonNullable<IntegrationPlugin['hmrManager']>): void;
|
|
75
76
|
getHmrStrategy(): HmrStrategy | undefined;
|
|
76
77
|
}
|
|
77
78
|
/**
|
|
@@ -1,229 +1,240 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { IntegrationPlugin, } from '@ecopages/core/plugins/integration-plugin';
|
|
2
|
+
import { Logger } from '@ecopages/logger';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { REACT_PLUGIN_NAME } from './react.constants.js';
|
|
5
|
+
import { ReactRenderer } from '../render/react-renderer.js';
|
|
6
|
+
import { ReactHmrStrategy } from '../hmr/hmr-strategy.js';
|
|
7
|
+
import { ReactDevTransformContributor } from '../dev-transform/react-dev-transform-contributor.js';
|
|
8
|
+
import { RuntimeBundleService } from '../bundling/runtime-bundle.js';
|
|
9
|
+
import { HmrPageMetadataCache } from '../hmr/page-metadata-cache.js';
|
|
10
|
+
import { createReactMdxLoaderPlugin } from '../mdx/mdx-loader-plugin.js';
|
|
11
|
+
import { appendMdxExtensions, resolveMdxCompilerOptions } from '@ecopages/mdx/core';
|
|
12
|
+
import { ClientGraphBoundaryCache } from '../client-graph/boundary-cache.js';
|
|
13
|
+
import { discoverLayoutRuntimeModuleSpecifiers } from '../bundling/discover-layout-runtime-modules.js';
|
|
14
|
+
import { mergeReactPluginRuntimeModules, resolveReactPluginRuntimeModules } from '../bundling/runtime-modules.js';
|
|
15
|
+
const appLogger = new Logger('[ReactPlugin]');
|
|
16
|
+
/**
|
|
17
|
+
* The name of the React plugin
|
|
18
|
+
*/
|
|
19
|
+
export const PLUGIN_NAME = REACT_PLUGIN_NAME;
|
|
20
|
+
const resolveReactMdxCompilerOptions = (mdxOptions) => resolveMdxCompilerOptions(mdxOptions, { jsxImportSource: 'react' });
|
|
21
|
+
/**
|
|
22
|
+
* Resolves user-facing React plugin options into the internal plugin config.
|
|
23
|
+
*
|
|
24
|
+
* Defaults:
|
|
25
|
+
* - `extensions`: `['.tsx']`
|
|
26
|
+
* - `explicitGraph`: `false`
|
|
27
|
+
* - `mdx.enabled`: `false`
|
|
28
|
+
* - `mdx.extensions`: `['.mdx']`
|
|
29
|
+
*/
|
|
19
30
|
const resolveReactPluginOptions = (options) => {
|
|
20
|
-
|
|
21
|
-
extensions
|
|
22
|
-
|
|
23
|
-
mdx
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
mdxExtensions,
|
|
45
|
-
hmrPageMetadataCache: new HmrPageMetadataCache(),
|
|
46
|
-
forceBrowserGraph: explicitGraph ?? false
|
|
47
|
-
};
|
|
48
|
-
return {
|
|
49
|
-
...baseConfig,
|
|
50
|
-
extensions,
|
|
51
|
-
integrationDependencies: dependencies,
|
|
52
|
-
rendererConfig
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
class ReactPlugin extends IntegrationPlugin {
|
|
56
|
-
renderer = ReactRenderer;
|
|
57
|
-
routerAdapter;
|
|
58
|
-
mdxEnabled;
|
|
59
|
-
mdxCompilerOptions;
|
|
60
|
-
mdxExtensions;
|
|
61
|
-
mdxLoaderPlugin;
|
|
62
|
-
runtimeBundleService;
|
|
63
|
-
hmrPageMetadataCache;
|
|
64
|
-
clientGraphBoundaryCache;
|
|
65
|
-
hmrStrategy;
|
|
66
|
-
runtimeDependenciesInitialized = false;
|
|
67
|
-
/**
|
|
68
|
-
* When true, always emit page browser graph / hydration assets.
|
|
69
|
-
*
|
|
70
|
-
* @remarks
|
|
71
|
-
* Mapped from public `explicitGraph`. Does not skip client-graph AST stripping.
|
|
72
|
-
*/
|
|
73
|
-
forceBrowserGraph;
|
|
74
|
-
rendererConfig;
|
|
75
|
-
constructor(options) {
|
|
76
|
-
const config = resolveReactPluginOptions(options);
|
|
77
|
-
const { extensions, rendererConfig, integrationDependencies, ...baseConfig } = config;
|
|
78
|
-
super({
|
|
79
|
-
name: PLUGIN_NAME,
|
|
80
|
-
extensions,
|
|
81
|
-
jsxImportSource: "react",
|
|
82
|
-
integrationDependencies,
|
|
83
|
-
...baseConfig
|
|
84
|
-
});
|
|
85
|
-
this.routerAdapter = rendererConfig.routerAdapter;
|
|
86
|
-
this.mdxCompilerOptions = rendererConfig.mdxCompilerOptions;
|
|
87
|
-
this.mdxEnabled = Boolean(rendererConfig.mdxCompilerOptions);
|
|
88
|
-
this.mdxExtensions = rendererConfig.mdxExtensions ?? [".mdx"];
|
|
89
|
-
this.hmrPageMetadataCache = rendererConfig.hmrPageMetadataCache ?? new HmrPageMetadataCache();
|
|
90
|
-
this.clientGraphBoundaryCache = new ClientGraphBoundaryCache();
|
|
91
|
-
this.forceBrowserGraph = rendererConfig.forceBrowserGraph ?? false;
|
|
92
|
-
this.rendererConfig = {
|
|
93
|
-
...rendererConfig,
|
|
94
|
-
mdxExtensions: this.mdxExtensions,
|
|
95
|
-
hmrPageMetadataCache: this.hmrPageMetadataCache,
|
|
96
|
-
forceBrowserGraph: this.forceBrowserGraph
|
|
31
|
+
const { extensions: userExtensions, router, mdx, explicitGraph, dependencies, runtimeModules, ...baseConfig } = options ?? {};
|
|
32
|
+
const extensions = [...(userExtensions ?? ['.tsx'])];
|
|
33
|
+
const mdxEnabled = mdx?.enabled ?? false;
|
|
34
|
+
const mdxExtensions = mdx?.extensions ?? ['.mdx'];
|
|
35
|
+
const resolvedRuntimeModules = resolveReactPluginRuntimeModules(runtimeModules);
|
|
36
|
+
if (mdxEnabled) {
|
|
37
|
+
appendMdxExtensions(extensions, mdxExtensions);
|
|
38
|
+
}
|
|
39
|
+
else if (mdx?.extensions?.length) {
|
|
40
|
+
appLogger.warn('MDX extensions provided but MDX is disabled. MDX files will not be processed. Set mdx.enabled to true to enable MDX support.');
|
|
41
|
+
}
|
|
42
|
+
const rendererConfig = {
|
|
43
|
+
routerAdapter: router,
|
|
44
|
+
runtimeModules: resolvedRuntimeModules,
|
|
45
|
+
mdxCompilerOptions: mdxEnabled && mdx ? resolveReactMdxCompilerOptions(mdx) : undefined,
|
|
46
|
+
mdxExtensions,
|
|
47
|
+
hmrPageMetadataCache: new HmrPageMetadataCache(),
|
|
48
|
+
forceBrowserGraph: explicitGraph ?? false,
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
...baseConfig,
|
|
52
|
+
extensions,
|
|
53
|
+
integrationDependencies: dependencies,
|
|
54
|
+
rendererConfig,
|
|
97
55
|
};
|
|
98
|
-
|
|
99
|
-
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* The React plugin class
|
|
59
|
+
* This plugin provides support for React components in Ecopages
|
|
60
|
+
*/
|
|
61
|
+
export class ReactPlugin extends IntegrationPlugin {
|
|
62
|
+
renderer = ReactRenderer;
|
|
63
|
+
routerAdapter;
|
|
64
|
+
mdxEnabled;
|
|
65
|
+
mdxCompilerOptions;
|
|
66
|
+
mdxExtensions;
|
|
67
|
+
mdxLoaderPlugin;
|
|
68
|
+
runtimeBundleService;
|
|
69
|
+
hmrPageMetadataCache;
|
|
70
|
+
clientGraphBoundaryCache;
|
|
71
|
+
hmrStrategy;
|
|
72
|
+
runtimeDependenciesInitialized = false;
|
|
73
|
+
/**
|
|
74
|
+
* When true, always emit page browser graph / hydration assets.
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* Mapped from public `explicitGraph`. Does not skip client-graph AST stripping.
|
|
78
|
+
*/
|
|
79
|
+
forceBrowserGraph;
|
|
80
|
+
rendererConfig;
|
|
81
|
+
constructor(options) {
|
|
82
|
+
const config = resolveReactPluginOptions(options);
|
|
83
|
+
const { extensions, rendererConfig, integrationDependencies, ...baseConfig } = config;
|
|
84
|
+
super({
|
|
85
|
+
name: PLUGIN_NAME,
|
|
86
|
+
extensions,
|
|
87
|
+
jsxImportSource: 'react',
|
|
88
|
+
integrationDependencies,
|
|
89
|
+
...baseConfig,
|
|
90
|
+
});
|
|
91
|
+
this.routerAdapter = rendererConfig.routerAdapter;
|
|
92
|
+
this.mdxCompilerOptions = rendererConfig.mdxCompilerOptions;
|
|
93
|
+
this.mdxEnabled = Boolean(rendererConfig.mdxCompilerOptions);
|
|
94
|
+
this.mdxExtensions = rendererConfig.mdxExtensions ?? ['.mdx'];
|
|
95
|
+
this.hmrPageMetadataCache = rendererConfig.hmrPageMetadataCache ?? new HmrPageMetadataCache();
|
|
96
|
+
this.clientGraphBoundaryCache = new ClientGraphBoundaryCache();
|
|
97
|
+
this.forceBrowserGraph = rendererConfig.forceBrowserGraph ?? false;
|
|
98
|
+
this.rendererConfig = {
|
|
99
|
+
...rendererConfig,
|
|
100
|
+
mdxExtensions: this.mdxExtensions,
|
|
101
|
+
hmrPageMetadataCache: this.hmrPageMetadataCache,
|
|
102
|
+
forceBrowserGraph: this.forceBrowserGraph,
|
|
103
|
+
};
|
|
104
|
+
if (this.mdxEnabled) {
|
|
105
|
+
appLogger.debug('MDX mode enabled with React jsx runtime');
|
|
106
|
+
}
|
|
107
|
+
this.runtimeBundleService = new RuntimeBundleService({
|
|
108
|
+
routerAdapter: this.routerAdapter,
|
|
109
|
+
runtimeModules: this.rendererConfig.runtimeModules,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Creates a React renderer with instance-owned runtime configuration.
|
|
114
|
+
*
|
|
115
|
+
* React renderers depend on plugin-owned router, MDX, and HMR metadata state.
|
|
116
|
+
* Keeping that state on the instance avoids cross-plugin static mutation while
|
|
117
|
+
* preserving the same runtime services the base initializer wires up.
|
|
118
|
+
*/
|
|
119
|
+
initializeRenderer(options) {
|
|
120
|
+
const renderer = new this.renderer({
|
|
121
|
+
...this.createRendererOptions(options),
|
|
122
|
+
reactConfig: this.rendererConfig,
|
|
123
|
+
});
|
|
124
|
+
return this.attachRendererRuntimeServices(renderer);
|
|
100
125
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
initializeRenderer(options) {
|
|
114
|
-
const renderer = new this.renderer({
|
|
115
|
-
...this.createRendererOptions(options),
|
|
116
|
-
reactConfig: this.rendererConfig
|
|
117
|
-
});
|
|
118
|
-
return this.attachRendererRuntimeServices(renderer);
|
|
119
|
-
}
|
|
120
|
-
ensureRuntimeDependencies() {
|
|
121
|
-
if (this.runtimeDependenciesInitialized) {
|
|
122
|
-
return;
|
|
126
|
+
ensureRuntimeDependencies() {
|
|
127
|
+
if (this.runtimeDependenciesInitialized) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.runtimeBundleService.setRootDir(this.appConfig?.rootDir);
|
|
131
|
+
this.runtimeBundleService.setWorkDir(this.appConfig?.absolutePaths?.workDir ??
|
|
132
|
+
(this.appConfig?.rootDir
|
|
133
|
+
? path.join(this.appConfig.rootDir, this.appConfig.workDir ?? '.eco')
|
|
134
|
+
: undefined));
|
|
135
|
+
this.runtimeBundleService.setRuntimeModules(this.resolveEffectiveRuntimeModules());
|
|
136
|
+
this.integrationDependencies.unshift(...this.runtimeBundleService.getDependencies());
|
|
137
|
+
this.runtimeDependenciesInitialized = true;
|
|
123
138
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
resolveEffectiveRuntimeModules() {
|
|
140
|
+
const manualModules = this.rendererConfig.runtimeModules ?? [];
|
|
141
|
+
if (!this.routerAdapter || !this.appConfig) {
|
|
142
|
+
return manualModules;
|
|
143
|
+
}
|
|
144
|
+
const discovery = discoverLayoutRuntimeModuleSpecifiers({
|
|
145
|
+
searchDirs: [this.appConfig.absolutePaths.layoutsDir, this.appConfig.absolutePaths.componentsDir].filter(Boolean),
|
|
146
|
+
projectRoot: this.appConfig.absolutePaths.projectDir,
|
|
147
|
+
routerImportPath: this.routerAdapter.bundle.importPath,
|
|
148
|
+
});
|
|
149
|
+
const merged = mergeReactPluginRuntimeModules(manualModules, discovery.specifiers);
|
|
150
|
+
this.rendererConfig.runtimeModules = merged;
|
|
151
|
+
if (discovery.mode === 'provider-scoped-fallback') {
|
|
152
|
+
appLogger.debug('Layout runtime auto-vendoring is using provider-scoped fallback discovery. Set runtimeProvider: true on provider root layouts to scope discovery explicitly.');
|
|
153
|
+
}
|
|
154
|
+
if (discovery.specifiers.length > 0) {
|
|
155
|
+
appLogger.debug(`Auto-vendoring layout runtime modules for persisted SPA layouts: ${discovery.specifiers.join(', ')}`);
|
|
156
|
+
}
|
|
157
|
+
return merged;
|
|
136
158
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
routerImportPath: this.routerAdapter.bundle.importPath
|
|
143
|
-
});
|
|
144
|
-
const merged = mergeReactPluginRuntimeModules(manualModules, discovery.specifiers);
|
|
145
|
-
this.rendererConfig.runtimeModules = merged;
|
|
146
|
-
if (discovery.mode === "provider-scoped-fallback") {
|
|
147
|
-
appLogger.debug(
|
|
148
|
-
"Layout runtime auto-vendoring is using provider-scoped fallback discovery. Set runtimeProvider: true on provider root layouts to scope discovery explicitly."
|
|
149
|
-
);
|
|
159
|
+
get plugins() {
|
|
160
|
+
if (this.mdxLoaderPlugin) {
|
|
161
|
+
return [this.mdxLoaderPlugin];
|
|
162
|
+
}
|
|
163
|
+
return [];
|
|
150
164
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
);
|
|
165
|
+
get browserRuntimeManifest() {
|
|
166
|
+
this.ensureRuntimeDependencies();
|
|
167
|
+
return this.runtimeBundleService.getRuntimeManifest();
|
|
155
168
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Ensures the optional React MDX loader exists before either config-time
|
|
171
|
+
* manifest sealing or runtime setup needs it.
|
|
172
|
+
*/
|
|
173
|
+
async ensureMdxLoaderPlugin() {
|
|
174
|
+
if (!this.mdxEnabled || !this.mdxCompilerOptions || this.mdxLoaderPlugin) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
this.mdxLoaderPlugin = createReactMdxLoaderPlugin(this.mdxCompilerOptions);
|
|
161
178
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
* Ensures the optional React MDX loader exists before either config-time
|
|
170
|
-
* manifest sealing or runtime setup needs it.
|
|
171
|
-
*/
|
|
172
|
-
async ensureMdxLoaderPlugin() {
|
|
173
|
-
if (!this.mdxEnabled || !this.mdxCompilerOptions || this.mdxLoaderPlugin) {
|
|
174
|
-
return;
|
|
179
|
+
/**
|
|
180
|
+
* Prepares React's build-facing loader contributions before config build seals
|
|
181
|
+
* the app manifest.
|
|
182
|
+
*/
|
|
183
|
+
async prepareBuildContributions() {
|
|
184
|
+
this.ensureRuntimeDependencies();
|
|
185
|
+
await this.ensureMdxLoaderPlugin();
|
|
175
186
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
await this.ensureMdxLoaderPlugin();
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Performs runtime-only React setup after build contributions are already
|
|
188
|
-
* materialized.
|
|
189
|
-
*/
|
|
190
|
-
async setup() {
|
|
191
|
-
this.ensureRuntimeDependencies();
|
|
192
|
-
await this.ensureMdxLoaderPlugin();
|
|
193
|
-
await super.setup();
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Provides React-specific HMR strategy with Fast Refresh support.
|
|
197
|
-
*
|
|
198
|
-
* The strategy shares a React-only page metadata cache with the renderer so
|
|
199
|
-
* save-time rebuilds can reuse declared-module analysis without expanding the
|
|
200
|
-
* core HMR interfaces.
|
|
201
|
-
*
|
|
202
|
-
* @returns ReactHmrStrategy instance for handling React component updates
|
|
203
|
-
*/
|
|
204
|
-
getHmrStrategy() {
|
|
205
|
-
if (!this.hmrManager || !this.appConfig) {
|
|
206
|
-
return void 0;
|
|
187
|
+
/**
|
|
188
|
+
* Performs runtime-only React setup after build contributions are already
|
|
189
|
+
* materialized.
|
|
190
|
+
*/
|
|
191
|
+
async setup() {
|
|
192
|
+
this.ensureRuntimeDependencies();
|
|
193
|
+
await this.ensureMdxLoaderPlugin();
|
|
194
|
+
await super.setup();
|
|
207
195
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
196
|
+
/**
|
|
197
|
+
* Provides React-specific HMR strategy with Fast Refresh support.
|
|
198
|
+
*
|
|
199
|
+
* The strategy shares a React-only page metadata cache with the renderer so
|
|
200
|
+
* save-time rebuilds can reuse declared-module analysis without expanding the
|
|
201
|
+
* core HMR interfaces.
|
|
202
|
+
*
|
|
203
|
+
* @returns ReactHmrStrategy instance for handling React component updates
|
|
204
|
+
*/
|
|
205
|
+
setHmrManager(hmrManager) {
|
|
206
|
+
super.setHmrManager(hmrManager);
|
|
207
|
+
const strategy = this.getHmrStrategy();
|
|
208
|
+
if (!strategy || !this.appConfig) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
hmrManager.registerDevTransformContributor(new ReactDevTransformContributor({
|
|
212
|
+
strategy: strategy,
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
getHmrStrategy() {
|
|
216
|
+
if (!this.hmrManager || !this.appConfig) {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
if (!this.hmrStrategy) {
|
|
220
|
+
this.hmrStrategy = new ReactHmrStrategy({
|
|
221
|
+
context: this.hmrManager.getDefaultContext(),
|
|
222
|
+
pageMetadataCache: this.hmrPageMetadataCache,
|
|
223
|
+
runtimeManifest: this.runtimeBundleService.getRuntimeManifest('development'),
|
|
224
|
+
mdxCompilerOptions: this.mdxCompilerOptions,
|
|
225
|
+
ownedTemplateExtensions: this.extensions,
|
|
226
|
+
allTemplateExtensions: this.appConfig.templatesExt,
|
|
227
|
+
clientGraphBoundaryCache: this.clientGraphBoundaryCache,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return this.hmrStrategy;
|
|
218
231
|
}
|
|
219
|
-
return this.hmrStrategy;
|
|
220
|
-
}
|
|
221
232
|
}
|
|
222
|
-
|
|
223
|
-
|
|
233
|
+
/**
|
|
234
|
+
* Factory function to create a React plugin instance
|
|
235
|
+
* @param options Configuration options for the React plugin
|
|
236
|
+
* @returns A new ReactPlugin instance
|
|
237
|
+
*/
|
|
238
|
+
export function reactPlugin(options) {
|
|
239
|
+
return new ReactPlugin(options);
|
|
224
240
|
}
|
|
225
|
-
export {
|
|
226
|
-
PLUGIN_NAME,
|
|
227
|
-
ReactPlugin,
|
|
228
|
-
reactPlugin
|
|
229
|
-
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|