@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
|
@@ -1,282 +1,258 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
constructor(config) {
|
|
21
|
-
this.config = config;
|
|
22
|
-
}
|
|
23
|
-
setRootDir(rootDir) {
|
|
24
|
-
this.config.rootDir = rootDir;
|
|
25
|
-
}
|
|
26
|
-
setWorkDir(workDir) {
|
|
27
|
-
this.config.workDir = workDir;
|
|
28
|
-
}
|
|
29
|
-
setRuntimeModules(runtimeModules) {
|
|
30
|
-
this.config.runtimeModules = runtimeModules;
|
|
31
|
-
}
|
|
32
|
-
get isDevelopment() {
|
|
33
|
-
return process.env.NODE_ENV === "development";
|
|
34
|
-
}
|
|
35
|
-
getCurrentRuntimeMode() {
|
|
36
|
-
return this.isDevelopment ? "development" : "production";
|
|
37
|
-
}
|
|
38
|
-
createRuntimeDefines(mode) {
|
|
39
|
-
const nodeEnv = JSON.stringify(mode);
|
|
40
|
-
return {
|
|
41
|
-
"process.env.NODE_ENV": nodeEnv,
|
|
42
|
-
"import.meta.env.NODE_ENV": nodeEnv
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
getReactVendorFileName(mode) {
|
|
46
|
-
return mode === "development" ? "react.development.js" : "react.js";
|
|
47
|
-
}
|
|
48
|
-
getReactDomVendorFileName(mode) {
|
|
49
|
-
return mode === "development" ? "react-dom.development.js" : "react-dom.js";
|
|
50
|
-
}
|
|
51
|
-
getRouterVendorFileName(mode) {
|
|
52
|
-
if (!this.config.routerAdapter) {
|
|
53
|
-
return "";
|
|
1
|
+
/**
|
|
2
|
+
* Runtime bundle service for React integration.
|
|
3
|
+
*
|
|
4
|
+
* Owns creation of the browser runtime assets for React and React DOM,
|
|
5
|
+
* including shared runtime entry generation and specifier mapping.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { createBrowserRuntimePlugin } from '@ecopages/core/build/browser-runtime-plugin';
|
|
10
|
+
import { DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME } from '@ecopages/core/build/browser-runtime-plugin';
|
|
11
|
+
import { buildBrowserRuntimeAssetUrl, createBrowserRuntimeModuleAsset, createBrowserRuntimeScriptAsset, } from '@ecopages/core/services/asset-processing-service';
|
|
12
|
+
import { createReactDomRuntimeInteropPlugin } from './runtime-interop-plugin.js';
|
|
13
|
+
import { buildReactRuntimeAliasMap, buildReactRuntimeManifest, getReactRuntimeExternalSpecifiers, } from './runtime-alias-map.js';
|
|
14
|
+
import { createBrowserRuntimeManifest, } from '@ecopages/core/build/browser-runtime-manifest';
|
|
15
|
+
import { LAYOUT_COMPOSE_PACKAGE, PAGE_LAYOUT_NORMALIZATION_PACKAGE } from './bootstrap-package-paths.js';
|
|
16
|
+
export class RuntimeBundleService {
|
|
17
|
+
config;
|
|
18
|
+
constructor(config) {
|
|
19
|
+
this.config = config;
|
|
54
20
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
manifest: createBrowserRuntimeManifest([
|
|
87
|
-
{
|
|
88
|
-
specifier: "react",
|
|
89
|
-
owner: "@ecopages/react",
|
|
90
|
-
importPath: "react",
|
|
91
|
-
publicPath: buildBrowserRuntimeAssetUrl(this.getReactVendorFileName(mode))
|
|
21
|
+
setRootDir(rootDir) {
|
|
22
|
+
this.config.rootDir = rootDir;
|
|
23
|
+
}
|
|
24
|
+
setWorkDir(workDir) {
|
|
25
|
+
this.config.workDir = workDir;
|
|
26
|
+
}
|
|
27
|
+
setRuntimeModules(runtimeModules) {
|
|
28
|
+
this.config.runtimeModules = runtimeModules;
|
|
29
|
+
}
|
|
30
|
+
get isDevelopment() {
|
|
31
|
+
return process.env.NODE_ENV === 'development';
|
|
32
|
+
}
|
|
33
|
+
getCurrentRuntimeMode() {
|
|
34
|
+
return this.isDevelopment ? 'development' : 'production';
|
|
35
|
+
}
|
|
36
|
+
createRuntimeDefines(mode) {
|
|
37
|
+
const nodeEnv = JSON.stringify(mode);
|
|
38
|
+
return {
|
|
39
|
+
'process.env.NODE_ENV': nodeEnv,
|
|
40
|
+
'import.meta.env.NODE_ENV': nodeEnv,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
getReactVendorFileName(mode) {
|
|
44
|
+
return mode === 'development' ? 'react.development.js' : 'react.js';
|
|
45
|
+
}
|
|
46
|
+
getReactDomVendorFileName(mode) {
|
|
47
|
+
return mode === 'development' ? 'react-dom.development.js' : 'react-dom.js';
|
|
48
|
+
}
|
|
49
|
+
getRouterVendorFileName(mode) {
|
|
50
|
+
if (!this.config.routerAdapter) {
|
|
51
|
+
return '';
|
|
92
52
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
53
|
+
return mode === 'development'
|
|
54
|
+
? `${this.config.routerAdapter.bundle.outputName}.development.js`
|
|
55
|
+
: `${this.config.routerAdapter.bundle.outputName}.js`;
|
|
56
|
+
}
|
|
57
|
+
getConfiguredRuntimeModuleFileName(outputName, mode) {
|
|
58
|
+
return mode === 'development' ? `${outputName}.development.js` : `${outputName}.js`;
|
|
59
|
+
}
|
|
60
|
+
getConfiguredRuntimeModules() {
|
|
61
|
+
return this.config.runtimeModules ?? [];
|
|
62
|
+
}
|
|
63
|
+
getConfiguredRuntimeModuleSpecifiers() {
|
|
64
|
+
return this.getConfiguredRuntimeModules().map((module) => module.specifier);
|
|
65
|
+
}
|
|
66
|
+
getRuntimeModuleBundleExternals(module, mappedSpecifiers) {
|
|
67
|
+
return [
|
|
68
|
+
...getReactRuntimeExternalSpecifiers(),
|
|
69
|
+
...(this.config.routerAdapter?.bundle.externals ?? []),
|
|
70
|
+
...(this.config.routerAdapter ? [this.config.routerAdapter.bundle.importPath] : []),
|
|
71
|
+
...module.externals,
|
|
72
|
+
].filter((external) => !mappedSpecifiers.has(external));
|
|
113
73
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
74
|
+
getUseSyncExternalStoreWithSelectorVendorFileName(mode) {
|
|
75
|
+
return mode === 'development'
|
|
76
|
+
? 'use-sync-external-store-with-selector.development.js'
|
|
77
|
+
: 'use-sync-external-store-with-selector.js';
|
|
78
|
+
}
|
|
79
|
+
getPageLayoutNormalizationVendorFileName(mode) {
|
|
80
|
+
return mode === 'development' ? 'page-layout-normalization.development.js' : 'page-layout-normalization.js';
|
|
81
|
+
}
|
|
82
|
+
getLayoutComposeVendorFileName(mode) {
|
|
83
|
+
return mode === 'development' ? 'layout-compose.development.js' : 'layout-compose.js';
|
|
84
|
+
}
|
|
85
|
+
createReactVendorImportRewritePlugin(mode) {
|
|
86
|
+
return createBrowserRuntimePlugin({
|
|
87
|
+
name: `react-plugin-vendor-runtime-import-rewrite-${mode}`,
|
|
88
|
+
manifest: createBrowserRuntimeManifest([
|
|
89
|
+
{
|
|
90
|
+
specifier: 'react',
|
|
91
|
+
owner: '@ecopages/react',
|
|
92
|
+
importPath: 'react',
|
|
93
|
+
publicPath: buildBrowserRuntimeAssetUrl(this.getReactVendorFileName(mode)),
|
|
94
|
+
},
|
|
95
|
+
]),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
getRuntimeImports(mode = this.getCurrentRuntimeMode()) {
|
|
99
|
+
const reactVendorFileName = this.getReactVendorFileName(mode);
|
|
100
|
+
const reactDomVendorFileName = this.getReactDomVendorFileName(mode);
|
|
101
|
+
const runtimeImports = {
|
|
102
|
+
react: buildBrowserRuntimeAssetUrl(reactVendorFileName),
|
|
103
|
+
reactDomClient: buildBrowserRuntimeAssetUrl(reactDomVendorFileName),
|
|
104
|
+
reactJsxRuntime: buildBrowserRuntimeAssetUrl(reactVendorFileName),
|
|
105
|
+
reactJsxDevRuntime: buildBrowserRuntimeAssetUrl(reactVendorFileName),
|
|
106
|
+
reactDom: buildBrowserRuntimeAssetUrl(reactDomVendorFileName),
|
|
107
|
+
useSyncExternalStoreWithSelector: buildBrowserRuntimeAssetUrl(this.getUseSyncExternalStoreWithSelectorVendorFileName(mode)),
|
|
108
|
+
pageLayoutNormalization: buildBrowserRuntimeAssetUrl(this.getPageLayoutNormalizationVendorFileName(mode)),
|
|
109
|
+
layoutCompose: buildBrowserRuntimeAssetUrl(this.getLayoutComposeVendorFileName(mode)),
|
|
110
|
+
};
|
|
111
|
+
if (this.config.routerAdapter) {
|
|
112
|
+
runtimeImports.router = buildBrowserRuntimeAssetUrl(this.getRouterVendorFileName(mode));
|
|
113
|
+
}
|
|
114
|
+
return runtimeImports;
|
|
115
|
+
}
|
|
116
|
+
getRuntimeAliasMap(mode = this.getCurrentRuntimeMode()) {
|
|
117
|
+
return buildReactRuntimeAliasMap(this.getRuntimeImports(mode));
|
|
118
|
+
}
|
|
119
|
+
getRuntimeManifest(mode = this.getCurrentRuntimeMode()) {
|
|
120
|
+
return buildReactRuntimeManifest(this.getRuntimeImports(mode), this.getConfiguredRuntimeModules(), (outputName) => buildBrowserRuntimeAssetUrl(this.getConfiguredRuntimeModuleFileName(outputName, mode)), { routerImportPath: this.config.routerAdapter?.bundle.importPath });
|
|
121
|
+
}
|
|
122
|
+
getDependencies(options) {
|
|
123
|
+
const dependencies = [];
|
|
124
|
+
const modes = options?.modes ?? [this.getCurrentRuntimeMode()];
|
|
125
|
+
for (const mode of modes) {
|
|
126
|
+
const reactVendorImportRewritePlugin = this.createReactVendorImportRewritePlugin(mode);
|
|
127
|
+
const reactDomRuntimeInteropPlugin = createReactDomRuntimeInteropPlugin({
|
|
128
|
+
reactSpecifier: buildBrowserRuntimeAssetUrl(this.getReactVendorFileName(mode)),
|
|
129
|
+
});
|
|
130
|
+
const reactRuntimeAliasPlugin = createBrowserRuntimePlugin({
|
|
131
|
+
name: `react-plugin-runtime-specifier-alias-${mode}`,
|
|
132
|
+
manifest: createBrowserRuntimeManifest([
|
|
133
|
+
{
|
|
134
|
+
specifier: 'react',
|
|
135
|
+
owner: '',
|
|
136
|
+
importPath: 'react',
|
|
137
|
+
publicPath: buildBrowserRuntimeAssetUrl(this.getReactVendorFileName(mode)),
|
|
138
|
+
},
|
|
139
|
+
]),
|
|
140
|
+
});
|
|
141
|
+
const reactDomBundlePlugins = [reactRuntimeAliasPlugin, reactDomRuntimeInteropPlugin].filter((plugin) => plugin !== null);
|
|
142
|
+
const runtimeAliasPlugin = this.createRuntimeAliasPlugin(mode);
|
|
143
|
+
const mappedSpecifiers = new Set(Object.keys(this.getRuntimeAliasMap(mode)));
|
|
144
|
+
dependencies.push(createBrowserRuntimeModuleAsset({
|
|
145
|
+
modules: [
|
|
146
|
+
{ specifier: 'react', defaultExport: true },
|
|
147
|
+
{ specifier: 'react/jsx-runtime' },
|
|
148
|
+
{ specifier: 'react/jsx-dev-runtime' },
|
|
149
|
+
],
|
|
150
|
+
name: 'react',
|
|
151
|
+
fileName: this.getReactVendorFileName(mode),
|
|
152
|
+
cacheDirName: `ecopages-react-runtime-${mode}`,
|
|
153
|
+
rootDir: this.config.rootDir,
|
|
154
|
+
workDir: this.config.workDir,
|
|
155
|
+
bundleOptions: {
|
|
156
|
+
define: this.createRuntimeDefines(mode),
|
|
157
|
+
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
158
|
+
},
|
|
159
|
+
}), createBrowserRuntimeModuleAsset({
|
|
160
|
+
modules: [{ specifier: 'react-dom', defaultExport: true }, { specifier: 'react-dom/client' }],
|
|
161
|
+
name: 'react-dom',
|
|
162
|
+
fileName: this.getReactDomVendorFileName(mode),
|
|
163
|
+
cacheDirName: `ecopages-react-runtime-${mode}`,
|
|
164
|
+
rootDir: this.config.rootDir,
|
|
165
|
+
workDir: this.config.workDir,
|
|
166
|
+
bundleOptions: {
|
|
167
|
+
define: this.createRuntimeDefines(mode),
|
|
168
|
+
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
169
|
+
plugins: reactDomBundlePlugins,
|
|
170
|
+
},
|
|
171
|
+
}), createBrowserRuntimeScriptAsset({
|
|
172
|
+
importPath: '@ecopages/react/runtime/use-sync-external-store-with-selector',
|
|
173
|
+
name: 'use-sync-external-store-with-selector',
|
|
174
|
+
fileName: this.getUseSyncExternalStoreWithSelectorVendorFileName(mode),
|
|
175
|
+
bundleOptions: {
|
|
176
|
+
define: this.createRuntimeDefines(mode),
|
|
177
|
+
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
178
|
+
plugins: [reactVendorImportRewritePlugin],
|
|
179
|
+
},
|
|
180
|
+
}), createBrowserRuntimeScriptAsset({
|
|
181
|
+
importPath: LAYOUT_COMPOSE_PACKAGE,
|
|
182
|
+
name: 'layout-compose',
|
|
183
|
+
fileName: this.getLayoutComposeVendorFileName(mode),
|
|
184
|
+
bundleOptions: {
|
|
185
|
+
define: this.createRuntimeDefines(mode),
|
|
186
|
+
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
187
|
+
plugins: [reactVendorImportRewritePlugin],
|
|
188
|
+
},
|
|
189
|
+
}));
|
|
190
|
+
if (this.config.routerAdapter) {
|
|
191
|
+
const unresolvedExternals = this.config.routerAdapter.bundle.externals.filter((external) => !mappedSpecifiers.has(external));
|
|
192
|
+
dependencies.push(createBrowserRuntimeScriptAsset({
|
|
193
|
+
importPath: this.config.routerAdapter.bundle.importPath,
|
|
194
|
+
name: this.config.routerAdapter.bundle.outputName,
|
|
195
|
+
fileName: this.getRouterVendorFileName(mode),
|
|
196
|
+
bundleOptions: {
|
|
197
|
+
define: this.createRuntimeDefines(mode),
|
|
198
|
+
external: unresolvedExternals,
|
|
199
|
+
plugins: [runtimeAliasPlugin],
|
|
200
|
+
},
|
|
201
|
+
}));
|
|
214
202
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
231
|
-
plugins: [runtimeAliasPlugin]
|
|
203
|
+
for (const runtimeModule of this.getConfiguredRuntimeModules()) {
|
|
204
|
+
dependencies.push(createBrowserRuntimeModuleAsset({
|
|
205
|
+
modules: [{ specifier: runtimeModule.specifier, defaultExport: true }],
|
|
206
|
+
name: runtimeModule.outputName,
|
|
207
|
+
fileName: this.getConfiguredRuntimeModuleFileName(runtimeModule.outputName, mode),
|
|
208
|
+
cacheDirName: `ecopages-react-runtime-module-${runtimeModule.outputName}-${mode}`,
|
|
209
|
+
rootDir: this.config.rootDir,
|
|
210
|
+
workDir: this.config.workDir,
|
|
211
|
+
bundleOptions: {
|
|
212
|
+
define: this.createRuntimeDefines(mode),
|
|
213
|
+
external: this.getRuntimeModuleBundleExternals(runtimeModule, mappedSpecifiers),
|
|
214
|
+
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
215
|
+
plugins: [runtimeAliasPlugin],
|
|
216
|
+
},
|
|
217
|
+
}));
|
|
232
218
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
219
|
+
}
|
|
220
|
+
return dependencies;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Declares the MDX-only page-layout-normalization vendor for the current runtime mode.
|
|
224
|
+
*
|
|
225
|
+
* @remarks
|
|
226
|
+
* Kept out of {@link getDependencies} so non-MDX pages do not pay for this vendor during
|
|
227
|
+
* integration setup. Callers process these assets once when an MDX page graph is prepared.
|
|
228
|
+
*/
|
|
229
|
+
getPageLayoutNormalizationDependencies(options) {
|
|
230
|
+
const dependencies = [];
|
|
231
|
+
const modes = options?.modes ?? [this.getCurrentRuntimeMode()];
|
|
232
|
+
for (const mode of modes) {
|
|
233
|
+
dependencies.push(createBrowserRuntimeScriptAsset({
|
|
234
|
+
importPath: PAGE_LAYOUT_NORMALIZATION_PACKAGE,
|
|
235
|
+
name: 'page-layout-normalization',
|
|
236
|
+
fileName: this.getPageLayoutNormalizationVendorFileName(mode),
|
|
237
|
+
bundleOptions: {
|
|
238
|
+
define: this.createRuntimeDefines(mode),
|
|
239
|
+
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
240
|
+
},
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
return dependencies;
|
|
236
244
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
for (const mode of modes) {
|
|
250
|
-
dependencies.push(
|
|
251
|
-
createBrowserRuntimeScriptAsset({
|
|
252
|
-
importPath: PAGE_LAYOUT_NORMALIZATION_PACKAGE,
|
|
253
|
-
name: "page-layout-normalization",
|
|
254
|
-
fileName: this.getPageLayoutNormalizationVendorFileName(mode),
|
|
255
|
-
bundleOptions: {
|
|
256
|
-
define: this.createRuntimeDefines(mode),
|
|
257
|
-
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME]
|
|
258
|
-
}
|
|
259
|
-
})
|
|
260
|
-
);
|
|
245
|
+
createRuntimeAliasPlugin(mode = this.getCurrentRuntimeMode()) {
|
|
246
|
+
const aliasMap = this.getRuntimeAliasMap(mode);
|
|
247
|
+
const manifest = createBrowserRuntimeManifest(Object.entries(aliasMap).map(([specifier, publicPath]) => ({
|
|
248
|
+
specifier,
|
|
249
|
+
owner: '',
|
|
250
|
+
importPath: specifier,
|
|
251
|
+
publicPath,
|
|
252
|
+
})));
|
|
253
|
+
return createBrowserRuntimePlugin({
|
|
254
|
+
name: `react-plugin-runtime-alias-${mode}`,
|
|
255
|
+
manifest,
|
|
256
|
+
});
|
|
261
257
|
}
|
|
262
|
-
return dependencies;
|
|
263
|
-
}
|
|
264
|
-
createRuntimeAliasPlugin(mode = this.getCurrentRuntimeMode()) {
|
|
265
|
-
const aliasMap = this.getRuntimeAliasMap(mode);
|
|
266
|
-
const manifest = createBrowserRuntimeManifest(
|
|
267
|
-
Object.entries(aliasMap).map(([specifier, publicPath]) => ({
|
|
268
|
-
specifier,
|
|
269
|
-
owner: "",
|
|
270
|
-
importPath: specifier,
|
|
271
|
-
publicPath
|
|
272
|
-
}))
|
|
273
|
-
);
|
|
274
|
-
return createBrowserRuntimePlugin({
|
|
275
|
-
name: `react-plugin-runtime-alias-${mode}`,
|
|
276
|
-
manifest
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
258
|
}
|
|
280
|
-
export {
|
|
281
|
-
RuntimeBundleService
|
|
282
|
-
};
|
|
@@ -1,38 +1,34 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import path from
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
3
|
function escapeRegExp(value) {
|
|
4
|
-
|
|
4
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
5
5
|
}
|
|
6
|
-
function createReactDomRuntimeInteropPlugin(options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
};
|
|
6
|
+
export function createReactDomRuntimeInteropPlugin(options) {
|
|
7
|
+
const reactDomFileFilter = /[\\/]react-dom[\\/].*\.js$/;
|
|
8
|
+
const reactRequirePattern = /\brequire\((['"])react\1\)/g;
|
|
9
|
+
const reactSpecifier = options?.reactSpecifier ?? 'react';
|
|
10
|
+
return {
|
|
11
|
+
name: options?.name ?? 'react-dom-runtime-interop',
|
|
12
|
+
setup(build) {
|
|
13
|
+
if (reactSpecifier.startsWith('/')) {
|
|
14
|
+
build.onResolve({ filter: new RegExp(`^${escapeRegExp(reactSpecifier)}$`) }, (args) => ({
|
|
15
|
+
path: args.path,
|
|
16
|
+
external: true,
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
build.onLoad({ filter: reactDomFileFilter }, (args) => {
|
|
20
|
+
const content = fs.readFileSync(args.path, 'utf-8');
|
|
21
|
+
if (!reactRequirePattern.test(content)) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
reactRequirePattern.lastIndex = 0;
|
|
25
|
+
const rewritten = content.replace(reactRequirePattern, '__ecopages_react_runtime');
|
|
26
|
+
return {
|
|
27
|
+
contents: `import * as __ecopages_react_runtime from '${reactSpecifier}';\n${rewritten}`,
|
|
28
|
+
loader: 'js',
|
|
29
|
+
resolveDir: path.dirname(args.path),
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
};
|
|
35
34
|
}
|
|
36
|
-
export {
|
|
37
|
-
createReactDomRuntimeInteropPlugin
|
|
38
|
-
};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Production runtime check for React bundle and hydration policy.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Matches core `isProductionRuntime` (`NODE_ENV === 'production'`) without a new
|
|
6
|
+
* `@ecopages/core` export. Keeping this boundary shared ensures hosted-development
|
|
7
|
+
* runtime imports and production bundle optimizations use the same definition.
|
|
8
|
+
*/
|
|
9
|
+
export function isReactProductionRuntime() {
|
|
10
|
+
return process.env.NODE_ENV === 'production';
|
|
3
11
|
}
|
|
4
|
-
export {
|
|
5
|
-
isReactProductionRuntime
|
|
6
|
-
};
|