@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.
Files changed (57) hide show
  1. package/README.md +5 -1
  2. package/package.json +4 -4
  3. package/src/app/client-only.js +13 -17
  4. package/src/app/dynamic.js +7 -10
  5. package/src/app/dynamic.test.browser.js +27 -29
  6. package/src/bundling/bootstrap-package-paths.js +5 -6
  7. package/src/bundling/bundle.js +115 -114
  8. package/src/bundling/discover-layout-runtime-modules.js +166 -155
  9. package/src/bundling/runtime-alias-map.d.ts +4 -1
  10. package/src/bundling/runtime-alias-map.js +107 -95
  11. package/src/bundling/runtime-bundle.js +250 -274
  12. package/src/bundling/runtime-interop-plugin.js +31 -35
  13. package/src/bundling/runtime-mode.js +10 -5
  14. package/src/bundling/runtime-modules.js +46 -35
  15. package/src/client-graph/ast-transform.js +415 -305
  16. package/src/client-graph/boundary-cache.js +146 -104
  17. package/src/client-graph/boundary-plugin.js +122 -104
  18. package/src/client-graph/component-config-traversal.js +70 -49
  19. package/src/client-graph/declared-modules.js +63 -41
  20. package/src/client-graph/reachability-analyzer.js +506 -313
  21. package/src/client-graph/specifier-classification.js +209 -141
  22. package/src/contracts/router-adapter.js +6 -0
  23. package/src/dev-transform/react-dev-transform-contributor.d.ts +17 -0
  24. package/src/dev-transform/react-dev-transform-contributor.js +22 -0
  25. package/src/hmr/hmr-scripts.js +22 -9
  26. package/src/hmr/hmr-strategy.d.ts +12 -181
  27. package/src/hmr/hmr-strategy.js +321 -650
  28. package/src/hmr/page-metadata-cache.js +43 -40
  29. package/src/hmr/react-hmr-dev-transform-plugins.d.ts +23 -0
  30. package/src/hmr/react-hmr-dev-transform-plugins.js +20 -0
  31. package/src/hydration/assert-no-bare-ecopages-imports.js +6 -6
  32. package/src/hydration/bootstrap-imports.js +30 -20
  33. package/src/hydration/hydration-asset.js +216 -213
  34. package/src/hydration/hydration-scripts.d.ts +4 -0
  35. package/src/hydration/hydration-scripts.js +199 -66
  36. package/src/hydration/hydration-scripts.test.browser.js +163 -168
  37. package/src/hydration/page-data-manifest.js +89 -45
  38. package/src/hydration/page-data-reader.js +45 -32
  39. package/src/hydration/page-payload.js +101 -99
  40. package/src/hydration/serialize-page-data-script.js +27 -28
  41. package/src/mdx/mdx-config-dependency.js +108 -112
  42. package/src/mdx/mdx-loader-plugin.js +7 -10
  43. package/src/page/page-module.js +72 -66
  44. package/src/plugin/react.constants.js +1 -4
  45. package/src/plugin/react.plugin.d.ts +1 -0
  46. package/src/plugin/react.plugin.js +227 -216
  47. package/src/plugin/react.types.js +1 -0
  48. package/src/render/component-ownership.js +42 -18
  49. package/src/render/component-ssr.js +168 -190
  50. package/src/render/eco-embed.js +8 -10
  51. package/src/render/errors.js +21 -16
  52. package/src/render/html-boundary.js +55 -51
  53. package/src/render/layout-compose.js +122 -94
  54. package/src/render/react-renderer.js +433 -468
  55. package/src/render/react-runtime.js +25 -20
  56. package/src/render/unified-layout-composition.js +74 -85
  57. package/src/runtime/use-sync-external-store-with-selector.js +52 -54
@@ -1,282 +1,258 @@
1
- import { createBrowserRuntimePlugin } from "@ecopages/core/build/browser-runtime-plugin";
2
- import { DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME } from "@ecopages/core/build/browser-runtime-plugin";
3
- import {
4
- buildBrowserRuntimeAssetUrl,
5
- createBrowserRuntimeModuleAsset,
6
- createBrowserRuntimeScriptAsset
7
- } from "@ecopages/core/services/asset-processing-service";
8
- import { createReactDomRuntimeInteropPlugin } from "./runtime-interop-plugin.js";
9
- import {
10
- buildReactRuntimeAliasMap,
11
- buildReactRuntimeManifest,
12
- getReactRuntimeExternalSpecifiers
13
- } from "./runtime-alias-map.js";
14
- import {
15
- createBrowserRuntimeManifest
16
- } from "@ecopages/core/build/browser-runtime-manifest";
17
- import { LAYOUT_COMPOSE_PACKAGE, PAGE_LAYOUT_NORMALIZATION_PACKAGE } from "./bootstrap-package-paths.js";
18
- class RuntimeBundleService {
19
- config;
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
- return mode === "development" ? `${this.config.routerAdapter.bundle.outputName}.development.js` : `${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));
73
- }
74
- getUseSyncExternalStoreWithSelectorVendorFileName(mode) {
75
- return mode === "development" ? "use-sync-external-store-with-selector.development.js" : "use-sync-external-store-with-selector.js";
76
- }
77
- getPageLayoutNormalizationVendorFileName(mode) {
78
- return mode === "development" ? "page-layout-normalization.development.js" : "page-layout-normalization.js";
79
- }
80
- getLayoutComposeVendorFileName(mode) {
81
- return mode === "development" ? "layout-compose.development.js" : "layout-compose.js";
82
- }
83
- createReactVendorImportRewritePlugin(mode) {
84
- return createBrowserRuntimePlugin({
85
- name: `react-plugin-vendor-runtime-import-rewrite-${mode}`,
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
- getRuntimeImports(mode = this.getCurrentRuntimeMode()) {
97
- const reactVendorFileName = this.getReactVendorFileName(mode);
98
- const reactDomVendorFileName = this.getReactDomVendorFileName(mode);
99
- const runtimeImports = {
100
- react: buildBrowserRuntimeAssetUrl(reactVendorFileName),
101
- reactDomClient: buildBrowserRuntimeAssetUrl(reactDomVendorFileName),
102
- reactJsxRuntime: buildBrowserRuntimeAssetUrl(reactVendorFileName),
103
- reactJsxDevRuntime: buildBrowserRuntimeAssetUrl(reactVendorFileName),
104
- reactDom: buildBrowserRuntimeAssetUrl(reactDomVendorFileName),
105
- useSyncExternalStoreWithSelector: buildBrowserRuntimeAssetUrl(
106
- this.getUseSyncExternalStoreWithSelectorVendorFileName(mode)
107
- ),
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));
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
- return runtimeImports;
115
- }
116
- getRuntimeAliasMap(mode = this.getCurrentRuntimeMode()) {
117
- return buildReactRuntimeAliasMap(this.getRuntimeImports(mode));
118
- }
119
- getRuntimeManifest(mode = this.getCurrentRuntimeMode()) {
120
- return buildReactRuntimeManifest(
121
- this.getRuntimeImports(mode),
122
- this.getConfiguredRuntimeModules(),
123
- (outputName) => buildBrowserRuntimeAssetUrl(this.getConfiguredRuntimeModuleFileName(outputName, mode))
124
- );
125
- }
126
- getDependencies(options) {
127
- const dependencies = [];
128
- const modes = options?.modes ?? [this.getCurrentRuntimeMode()];
129
- for (const mode of modes) {
130
- const reactVendorImportRewritePlugin = this.createReactVendorImportRewritePlugin(mode);
131
- const reactDomRuntimeInteropPlugin = createReactDomRuntimeInteropPlugin({
132
- reactSpecifier: buildBrowserRuntimeAssetUrl(this.getReactVendorFileName(mode))
133
- });
134
- const reactRuntimeAliasPlugin = createBrowserRuntimePlugin({
135
- name: `react-plugin-runtime-specifier-alias-${mode}`,
136
- manifest: createBrowserRuntimeManifest([
137
- {
138
- specifier: "react",
139
- owner: "",
140
- importPath: "react",
141
- publicPath: buildBrowserRuntimeAssetUrl(this.getReactVendorFileName(mode))
142
- }
143
- ])
144
- });
145
- const reactDomBundlePlugins = [reactRuntimeAliasPlugin, reactDomRuntimeInteropPlugin].filter(
146
- (plugin) => plugin !== null
147
- );
148
- const runtimeAliasPlugin = this.createRuntimeAliasPlugin(mode);
149
- const mappedSpecifiers = new Set(Object.keys(this.getRuntimeAliasMap(mode)));
150
- dependencies.push(
151
- createBrowserRuntimeModuleAsset({
152
- modules: [
153
- { specifier: "react", defaultExport: true },
154
- { specifier: "react/jsx-runtime" },
155
- { specifier: "react/jsx-dev-runtime" }
156
- ],
157
- name: "react",
158
- fileName: this.getReactVendorFileName(mode),
159
- cacheDirName: `ecopages-react-runtime-${mode}`,
160
- rootDir: this.config.rootDir,
161
- workDir: this.config.workDir,
162
- bundleOptions: {
163
- define: this.createRuntimeDefines(mode),
164
- excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME]
165
- }
166
- }),
167
- createBrowserRuntimeModuleAsset({
168
- modules: [{ specifier: "react-dom", defaultExport: true }, { specifier: "react-dom/client" }],
169
- name: "react-dom",
170
- fileName: this.getReactDomVendorFileName(mode),
171
- cacheDirName: `ecopages-react-runtime-${mode}`,
172
- rootDir: this.config.rootDir,
173
- workDir: this.config.workDir,
174
- bundleOptions: {
175
- define: this.createRuntimeDefines(mode),
176
- excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
177
- plugins: reactDomBundlePlugins
178
- }
179
- }),
180
- createBrowserRuntimeScriptAsset({
181
- importPath: "@ecopages/react/runtime/use-sync-external-store-with-selector",
182
- name: "use-sync-external-store-with-selector",
183
- fileName: this.getUseSyncExternalStoreWithSelectorVendorFileName(mode),
184
- bundleOptions: {
185
- define: this.createRuntimeDefines(mode),
186
- excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
187
- plugins: [reactVendorImportRewritePlugin]
188
- }
189
- }),
190
- createBrowserRuntimeScriptAsset({
191
- importPath: LAYOUT_COMPOSE_PACKAGE,
192
- name: "layout-compose",
193
- fileName: this.getLayoutComposeVendorFileName(mode),
194
- bundleOptions: {
195
- define: this.createRuntimeDefines(mode),
196
- excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
197
- plugins: [reactVendorImportRewritePlugin]
198
- }
199
- })
200
- );
201
- if (this.config.routerAdapter) {
202
- const unresolvedExternals = this.config.routerAdapter.bundle.externals.filter(
203
- (external) => !mappedSpecifiers.has(external)
204
- );
205
- dependencies.push(
206
- createBrowserRuntimeScriptAsset({
207
- importPath: this.config.routerAdapter.bundle.importPath,
208
- name: this.config.routerAdapter.bundle.outputName,
209
- fileName: this.getRouterVendorFileName(mode),
210
- bundleOptions: {
211
- define: this.createRuntimeDefines(mode),
212
- external: unresolvedExternals,
213
- plugins: [runtimeAliasPlugin]
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
- for (const runtimeModule of this.getConfiguredRuntimeModules()) {
219
- dependencies.push(
220
- createBrowserRuntimeModuleAsset({
221
- modules: [{ specifier: runtimeModule.specifier, defaultExport: true }],
222
- name: runtimeModule.outputName,
223
- fileName: this.getConfiguredRuntimeModuleFileName(runtimeModule.outputName, mode),
224
- cacheDirName: `ecopages-react-runtime-module-${runtimeModule.outputName}-${mode}`,
225
- rootDir: this.config.rootDir,
226
- workDir: this.config.workDir,
227
- bundleOptions: {
228
- define: this.createRuntimeDefines(mode),
229
- external: this.getRuntimeModuleBundleExternals(runtimeModule, mappedSpecifiers),
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
- return dependencies;
238
- }
239
- /**
240
- * Declares the MDX-only page-layout-normalization vendor for the current runtime mode.
241
- *
242
- * @remarks
243
- * Kept out of {@link getDependencies} so non-MDX pages do not pay for this vendor during
244
- * integration setup. Callers process these assets once when an MDX page graph is prepared.
245
- */
246
- getPageLayoutNormalizationDependencies(options) {
247
- const dependencies = [];
248
- const modes = options?.modes ?? [this.getCurrentRuntimeMode()];
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 "node:fs";
2
- import path from "node:path";
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
3
  function escapeRegExp(value) {
4
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
5
5
  }
6
- 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 void 0;
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}';
28
- ${rewritten}`,
29
- loader: "js",
30
- resolveDir: path.dirname(args.path)
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
- function isReactProductionRuntime() {
2
- return process.env.NODE_ENV === "production";
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
- };