@ecopages/react 0.2.0-beta.3 → 0.2.0-beta.31
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 +168 -6
- package/package.json +51 -26
- package/src/bundling/bootstrap-package-paths.d.ts +5 -0
- package/src/bundling/bootstrap-package-paths.js +6 -0
- package/src/{services/react-bundle.service.d.ts → bundling/bundle.d.ts} +21 -8
- package/src/{services/react-bundle.service.js → bundling/bundle.js} +53 -21
- package/src/bundling/discover-layout-runtime-modules.d.ts +32 -0
- package/src/bundling/discover-layout-runtime-modules.js +180 -0
- package/src/bundling/runtime-alias-map.d.ts +10 -0
- package/src/{utils/react-runtime-alias-map.js → bundling/runtime-alias-map.js} +13 -2
- package/src/{services/react-runtime-bundle.service.d.ts → bundling/runtime-bundle.d.ts} +30 -5
- package/src/{services/react-runtime-bundle.service.js → bundling/runtime-bundle.js} +104 -8
- package/src/bundling/runtime-mode.d.ts +9 -0
- package/src/bundling/runtime-mode.js +6 -0
- package/src/bundling/runtime-modules.d.ts +29 -0
- package/src/bundling/runtime-modules.js +38 -0
- package/src/client-graph/ast-transform.d.ts +18 -0
- package/src/{utils/client-graph-boundary-plugin.js → client-graph/ast-transform.js} +15 -232
- package/src/{utils/client-graph-boundary-cache.d.ts → client-graph/boundary-cache.d.ts} +0 -5
- package/src/{utils/client-graph-boundary-cache.js → client-graph/boundary-cache.js} +1 -3
- package/src/{utils/client-graph-boundary-plugin.d.ts → client-graph/boundary-plugin.d.ts} +4 -13
- package/src/client-graph/boundary-plugin.js +107 -0
- package/src/{utils → client-graph}/component-config-traversal.js +4 -2
- package/src/{utils → client-graph}/reachability-analyzer.d.ts +2 -2
- package/src/{utils → client-graph}/reachability-analyzer.js +4 -1
- package/src/client-graph/specifier-classification.d.ts +75 -0
- package/src/client-graph/specifier-classification.js +155 -0
- package/src/{react-hmr-strategy.d.ts → hmr/hmr-strategy.d.ts} +19 -6
- package/src/{react-hmr-strategy.js → hmr/hmr-strategy.js} +154 -133
- package/src/{services/react-hmr-page-metadata-cache.d.ts → hmr/page-metadata-cache.d.ts} +5 -1
- package/src/{services/react-hmr-page-metadata-cache.js → hmr/page-metadata-cache.js} +8 -2
- 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 +23 -0
- package/src/{services/react-hydration-asset.service.d.ts → hydration/hydration-asset.d.ts} +33 -33
- package/src/{services/react-hydration-asset.service.js → hydration/hydration-asset.js} +63 -56
- package/src/hydration/hydration-scripts.d.ts +100 -0
- package/src/hydration/hydration-scripts.js +350 -0
- package/src/{utils → hydration}/hydration-scripts.test.browser.js +11 -5
- package/src/hydration/page-data-manifest.d.ts +58 -0
- package/src/hydration/page-data-manifest.js +53 -0
- package/src/hydration/page-data-reader.d.ts +31 -0
- package/src/hydration/page-data-reader.js +64 -0
- package/src/hydration/page-payload.d.ts +67 -0
- package/src/hydration/page-payload.js +104 -0
- package/src/hydration/serialize-page-data-script.d.ts +27 -0
- package/src/hydration/serialize-page-data-script.js +31 -0
- package/src/{services/react-mdx-config-dependency.service.d.ts → mdx/mdx-config-dependency.d.ts} +5 -5
- package/src/{services/react-mdx-config-dependency.service.js → mdx/mdx-config-dependency.js} +8 -10
- package/src/mdx/mdx-loader-plugin.d.ts +2 -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 +72 -0
- package/src/{react.plugin.d.ts → plugin/react.plugin.d.ts} +8 -3
- package/src/{react.plugin.js → plugin/react.plugin.js} +78 -54
- package/src/plugin/react.types.d.ts +149 -0
- package/src/render/component-ownership.d.ts +50 -0
- package/src/render/component-ownership.js +23 -0
- package/src/render/component-ssr.d.ts +113 -0
- package/src/render/component-ssr.js +202 -0
- package/src/render/errors.d.ts +16 -0
- package/src/render/errors.js +18 -0
- package/src/render/layout-compose.d.ts +66 -0
- package/src/render/layout-compose.js +106 -0
- package/src/render/react-renderer.d.ts +138 -0
- package/src/render/react-renderer.js +481 -0
- package/src/render/react-runtime.d.ts +13 -0
- package/src/render/react-runtime.js +21 -0
- package/src/render/unified-layout-composition.d.ts +53 -0
- package/src/render/unified-layout-composition.js +89 -0
- package/src/react-renderer.d.ts +0 -233
- package/src/react-renderer.js +0 -622
- package/src/react.types.d.ts +0 -88
- package/src/services/pages-index.d.ts +0 -64
- package/src/services/pages-index.js +0 -73
- package/src/services/react-page-module.service.d.ts +0 -88
- package/src/services/react-page-module.service.js +0 -166
- package/src/services/react-page-payload.service.d.ts +0 -46
- package/src/services/react-page-payload.service.js +0 -67
- package/src/utils/hydration-scripts.d.ts +0 -92
- package/src/utils/hydration-scripts.js +0 -358
- package/src/utils/react-mdx-loader-plugin.d.ts +0 -3
- package/src/utils/react-mdx-loader-plugin.js +0 -45
- package/src/utils/react-runtime-alias-map.d.ts +0 -8
- /package/src/{utils → app}/client-only.d.ts +0 -0
- /package/src/{utils → app}/client-only.js +0 -0
- /package/src/{utils → app}/dynamic.d.ts +0 -0
- /package/src/{utils → app}/dynamic.js +0 -0
- /package/src/{utils → app}/dynamic.test.browser.d.ts +0 -0
- /package/src/{utils → app}/dynamic.test.browser.js +0 -0
- /package/src/{utils/react-dom-runtime-interop-plugin.d.ts → bundling/runtime-interop-plugin.d.ts} +0 -0
- /package/src/{utils/react-dom-runtime-interop-plugin.js → bundling/runtime-interop-plugin.js} +0 -0
- /package/src/{utils → client-graph}/component-config-traversal.d.ts +0 -0
- /package/src/{utils → client-graph}/declared-modules.d.ts +0 -0
- /package/src/{utils → client-graph}/declared-modules.js +0 -0
- /package/src/{declarations.d.ts → contracts/declarations.d.ts} +0 -0
- /package/src/{router-adapter.d.ts → contracts/router-adapter.d.ts} +0 -0
- /package/src/{router-adapter.js → contracts/router-adapter.js} +0 -0
- /package/src/{utils → hmr}/hmr-scripts.d.ts +0 -0
- /package/src/{utils → hmr}/hmr-scripts.js +0 -0
- /package/src/{utils → hydration}/hydration-scripts.test.browser.d.ts +0 -0
- /package/src/{react.constants.d.ts → plugin/react.constants.d.ts} +0 -0
- /package/src/{react.constants.js → plugin/react.constants.js} +0 -0
- /package/src/{react.types.js → plugin/react.types.js} +0 -0
- /package/src/{eco-embed.d.ts → render/eco-embed.d.ts} +0 -0
- /package/src/{eco-embed.js → render/eco-embed.js} +0 -0
- /package/src/{utils → render}/html-boundary.d.ts +0 -0
- /package/src/{utils → render}/html-boundary.js +0 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
isBarePackageImportSpecifier,
|
|
5
|
+
resolveProjectModulePath
|
|
6
|
+
} from "@ecopages/core/plugins/tsconfig-import-resolver";
|
|
7
|
+
import { analyzeReachability } from "../client-graph/reachability-analyzer.js";
|
|
8
|
+
import { REACT_RUNTIME_SPECIFIERS } from "./runtime-alias-map.js";
|
|
9
|
+
const MODULE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
|
|
10
|
+
const AUTO_RUNTIME_EXCLUDED_SPECIFIERS = /* @__PURE__ */ new Set([
|
|
11
|
+
...REACT_RUNTIME_SPECIFIERS,
|
|
12
|
+
"react-dom/client",
|
|
13
|
+
"use-sync-external-store/shim",
|
|
14
|
+
"use-sync-external-store/shim/index.js",
|
|
15
|
+
"use-sync-external-store/shim/with-selector",
|
|
16
|
+
"use-sync-external-store/shim/with-selector.js"
|
|
17
|
+
]);
|
|
18
|
+
const AUTO_RUNTIME_EXCLUDED_PACKAGE_PREFIXES = ["@ecopages/", "@techn.es/"];
|
|
19
|
+
const PROVIDER_MODULE_PATH_PATTERN = /(?:^|[/\\])(?:[^/\\]*provider[^/\\]*|[^/\\]*context[^/\\]*)\.(?:tsx?|jsx?|mts?|mjs)$/i;
|
|
20
|
+
const PROVIDER_MODULE_SOURCE_PATTERN = /\b(?:QueryClientProvider|(?:\w+Provider)|createContext|Context\.Provider)\b/;
|
|
21
|
+
function isServerModulePath(filePath) {
|
|
22
|
+
return /\.server\.(?:tsx?|jsx?|mts?|mjs|cjs)$/.test(filePath);
|
|
23
|
+
}
|
|
24
|
+
function isEcoLayoutSource(source) {
|
|
25
|
+
return /\beco\.layout(?:<[^>]*>)?\s*\(/.test(source);
|
|
26
|
+
}
|
|
27
|
+
function isRuntimeProviderLayoutSource(source) {
|
|
28
|
+
return isEcoLayoutSource(source) && /\bruntimeProvider\s*:\s*true\b/.test(source);
|
|
29
|
+
}
|
|
30
|
+
function isProviderRuntimeModulePath(filePath, source) {
|
|
31
|
+
if (PROVIDER_MODULE_PATH_PATTERN.test(filePath)) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return PROVIDER_MODULE_SOURCE_PATTERN.test(source);
|
|
35
|
+
}
|
|
36
|
+
function normalizeRuntimePackageSpecifier(specifier) {
|
|
37
|
+
if (specifier.startsWith("@")) {
|
|
38
|
+
const parts = specifier.split("/");
|
|
39
|
+
if (parts.length >= 2) {
|
|
40
|
+
return `${parts[0]}/${parts[1]}`;
|
|
41
|
+
}
|
|
42
|
+
return specifier;
|
|
43
|
+
}
|
|
44
|
+
return specifier.split("/")[0] ?? specifier;
|
|
45
|
+
}
|
|
46
|
+
function isAutoRuntimeExcludedPackage(packageRoot) {
|
|
47
|
+
if (AUTO_RUNTIME_EXCLUDED_PACKAGE_PREFIXES.some((prefix) => packageRoot.startsWith(prefix))) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return packageRoot.endsWith("-devtools");
|
|
51
|
+
}
|
|
52
|
+
function shouldExcludeAutoRuntimeSpecifier(specifier, options) {
|
|
53
|
+
if (AUTO_RUNTIME_EXCLUDED_SPECIFIERS.has(specifier)) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
if (options.routerImportPath && specifier === options.routerImportPath) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return isAutoRuntimeExcludedPackage(normalizeRuntimePackageSpecifier(specifier));
|
|
60
|
+
}
|
|
61
|
+
function collectLayoutEntryFiles(searchDir, extensions, files) {
|
|
62
|
+
if (!existsSync(searchDir)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
for (const entry of readdirSync(searchDir, { withFileTypes: true })) {
|
|
66
|
+
const entryPath = path.join(searchDir, entry.name);
|
|
67
|
+
if (entry.isDirectory()) {
|
|
68
|
+
collectLayoutEntryFiles(entryPath, extensions, files);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (!entry.isFile()) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (!extensions.some((extension) => entry.name.endsWith(extension))) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const source = readFileSync(entryPath, "utf8");
|
|
79
|
+
if (!isEcoLayoutSource(source)) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
files.all.push(entryPath);
|
|
83
|
+
if (isRuntimeProviderLayoutSource(source)) {
|
|
84
|
+
files.runtimeProvider.push(entryPath);
|
|
85
|
+
}
|
|
86
|
+
} catch {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function resolveLayoutDiscoveryPlan(layoutEntries) {
|
|
92
|
+
if (layoutEntries.runtimeProvider.length > 0) {
|
|
93
|
+
return {
|
|
94
|
+
entryFiles: layoutEntries.runtimeProvider,
|
|
95
|
+
mode: "runtime-provider-layouts",
|
|
96
|
+
collectAllReachableNpm: true
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
entryFiles: layoutEntries.all,
|
|
101
|
+
mode: "provider-scoped-fallback",
|
|
102
|
+
collectAllReachableNpm: false
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function collectReachableNpmSpecifiersFromFile(filePath, options) {
|
|
106
|
+
if (isServerModulePath(filePath)) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (options.visitedFiles.has(filePath)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
options.visitedFiles.add(filePath);
|
|
113
|
+
let source;
|
|
114
|
+
try {
|
|
115
|
+
source = readFileSync(filePath, "utf8");
|
|
116
|
+
} catch {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const reachability = analyzeReachability(source, filePath);
|
|
120
|
+
if (!reachability.analyzed) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const collectNpmFromModule = options.collectAllReachableNpm || isProviderRuntimeModulePath(filePath, source);
|
|
124
|
+
for (const specifier of reachability.reachableImports.keys()) {
|
|
125
|
+
if (options.projectRoot) {
|
|
126
|
+
const resolvedLocalModule = resolveProjectModulePath(options.projectRoot, filePath, specifier);
|
|
127
|
+
if (resolvedLocalModule) {
|
|
128
|
+
options.queue.push(resolvedLocalModule);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (!collectNpmFromModule) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (!isBarePackageImportSpecifier(specifier, options.projectRoot)) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (shouldExcludeAutoRuntimeSpecifier(specifier, options)) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
options.discovered.add(normalizeRuntimePackageSpecifier(specifier));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function discoverLayoutRuntimeModuleSpecifiers(options) {
|
|
145
|
+
const extensions = options.extensions ?? MODULE_EXTENSIONS;
|
|
146
|
+
const layoutEntries = { all: [], runtimeProvider: [] };
|
|
147
|
+
for (const searchDir of options.searchDirs) {
|
|
148
|
+
collectLayoutEntryFiles(searchDir, extensions, layoutEntries);
|
|
149
|
+
}
|
|
150
|
+
const plan = resolveLayoutDiscoveryPlan(layoutEntries);
|
|
151
|
+
const discovered = /* @__PURE__ */ new Set();
|
|
152
|
+
for (const entryFile of plan.entryFiles) {
|
|
153
|
+
const visitedFiles = /* @__PURE__ */ new Set();
|
|
154
|
+
const queue = [entryFile];
|
|
155
|
+
while (queue.length > 0) {
|
|
156
|
+
const filePath = queue.shift();
|
|
157
|
+
if (!filePath) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
collectReachableNpmSpecifiersFromFile(filePath, {
|
|
161
|
+
projectRoot: options.projectRoot,
|
|
162
|
+
routerImportPath: options.routerImportPath,
|
|
163
|
+
collectAllReachableNpm: plan.collectAllReachableNpm,
|
|
164
|
+
visitedFiles,
|
|
165
|
+
queue,
|
|
166
|
+
discovered
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
specifiers: [...discovered].sort(),
|
|
172
|
+
mode: plan.mode
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
export {
|
|
176
|
+
discoverLayoutRuntimeModuleSpecifiers,
|
|
177
|
+
isProviderRuntimeModulePath,
|
|
178
|
+
isRuntimeProviderLayoutSource,
|
|
179
|
+
normalizeRuntimePackageSpecifier
|
|
180
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
|
|
2
|
+
import type { ReactRuntimeImports } from './runtime-bundle.js';
|
|
3
|
+
import type { ResolvedReactPluginRuntimeModule } from './runtime-modules.js';
|
|
4
|
+
import { type BrowserRuntimeAssetDeclaration, type BrowserRuntimeManifest } from '@ecopages/core/build/browser-runtime-manifest';
|
|
5
|
+
export declare const REACT_RUNTIME_SPECIFIERS: readonly ["react", "react-dom", "react/jsx-runtime", "react/jsx-dev-runtime", "react-dom/client"];
|
|
6
|
+
export declare function buildReactRuntimeAliasMap(runtimeImports: ReactRuntimeImports): Record<string, string>;
|
|
7
|
+
export declare function buildConfiguredRuntimeModuleManifestEntries(modules: readonly ResolvedReactPluginRuntimeModule[], getPublicPath: (outputName: string) => string): BrowserRuntimeAssetDeclaration[];
|
|
8
|
+
export declare function buildReactRuntimeManifest(runtimeImports: ReactRuntimeImports, configuredRuntimeModules?: readonly ResolvedReactPluginRuntimeModule[], getConfiguredRuntimeModulePublicPath?: (outputName: string) => string): BrowserRuntimeManifest;
|
|
9
|
+
export declare function getReactRuntimeExternalSpecifiers(): string[];
|
|
10
|
+
export declare function getReactClientGraphAllowSpecifiers(runtimeSpecifiers: Iterable<string>, routerAdapter?: ReactRouterAdapter): string[];
|
|
@@ -12,7 +12,16 @@ const REACT_RUNTIME_SPECIFIERS = [
|
|
|
12
12
|
function buildReactRuntimeAliasMap(runtimeImports) {
|
|
13
13
|
return Object.fromEntries(getBrowserRuntimeSpecifierMap(buildReactRuntimeManifest(runtimeImports)));
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function buildConfiguredRuntimeModuleManifestEntries(modules, getPublicPath) {
|
|
16
|
+
return modules.map((module) => ({
|
|
17
|
+
specifier: module.specifier,
|
|
18
|
+
owner: "@ecopages/react",
|
|
19
|
+
importPath: module.specifier,
|
|
20
|
+
publicPath: getPublicPath(module.outputName),
|
|
21
|
+
externals: [...getReactRuntimeExternalSpecifiers(), ...module.externals]
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
function buildReactRuntimeManifest(runtimeImports, configuredRuntimeModules = [], getConfiguredRuntimeModulePublicPath = () => "") {
|
|
16
25
|
return createBrowserRuntimeManifest([
|
|
17
26
|
{
|
|
18
27
|
specifier: "react",
|
|
@@ -67,7 +76,8 @@ function buildReactRuntimeManifest(runtimeImports) {
|
|
|
67
76
|
owner: "@ecopages/react",
|
|
68
77
|
importPath: "use-sync-external-store/shim/with-selector.js",
|
|
69
78
|
publicPath: runtimeImports.useSyncExternalStoreWithSelector
|
|
70
|
-
}
|
|
79
|
+
},
|
|
80
|
+
...buildConfiguredRuntimeModuleManifestEntries(configuredRuntimeModules, getConfiguredRuntimeModulePublicPath)
|
|
71
81
|
]);
|
|
72
82
|
}
|
|
73
83
|
function getReactRuntimeExternalSpecifiers() {
|
|
@@ -83,6 +93,7 @@ function getReactClientGraphAllowSpecifiers(runtimeSpecifiers, routerAdapter) {
|
|
|
83
93
|
}
|
|
84
94
|
export {
|
|
85
95
|
REACT_RUNTIME_SPECIFIERS,
|
|
96
|
+
buildConfiguredRuntimeModuleManifestEntries,
|
|
86
97
|
buildReactRuntimeAliasMap,
|
|
87
98
|
buildReactRuntimeManifest,
|
|
88
99
|
getReactClientGraphAllowSpecifiers,
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { EcoBuildPlugin } from '@ecopages/core/plugins/integration-plugin';
|
|
10
10
|
import { type AssetDefinition } from '@ecopages/core/services/asset-processing-service';
|
|
11
|
-
import type { ReactRouterAdapter } from '../router-adapter.js';
|
|
11
|
+
import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
|
|
12
|
+
import type { ResolvedReactPluginRuntimeModule } from './runtime-modules.js';
|
|
12
13
|
import { type BrowserRuntimeManifest } from '@ecopages/core/build/browser-runtime-manifest';
|
|
13
14
|
export type ReactRuntimeImports = {
|
|
14
15
|
react: string;
|
|
@@ -17,29 +18,53 @@ export type ReactRuntimeImports = {
|
|
|
17
18
|
reactJsxDevRuntime: string;
|
|
18
19
|
reactDom: string;
|
|
19
20
|
useSyncExternalStoreWithSelector: string;
|
|
21
|
+
pageLayoutNormalization: string;
|
|
22
|
+
layoutCompose: string;
|
|
20
23
|
router?: string;
|
|
21
24
|
};
|
|
22
|
-
export interface
|
|
25
|
+
export interface RuntimeBundleServiceConfig {
|
|
23
26
|
routerAdapter?: ReactRouterAdapter;
|
|
27
|
+
runtimeModules?: ResolvedReactPluginRuntimeModule[];
|
|
24
28
|
rootDir?: string;
|
|
29
|
+
workDir?: string;
|
|
25
30
|
}
|
|
26
31
|
type RuntimeMode = 'development' | 'production';
|
|
27
|
-
export declare class
|
|
32
|
+
export declare class RuntimeBundleService {
|
|
28
33
|
private readonly config;
|
|
29
|
-
constructor(config:
|
|
34
|
+
constructor(config: RuntimeBundleServiceConfig);
|
|
30
35
|
setRootDir(rootDir: string | undefined): void;
|
|
36
|
+
setWorkDir(workDir: string | undefined): void;
|
|
37
|
+
setRuntimeModules(runtimeModules: ResolvedReactPluginRuntimeModule[]): void;
|
|
31
38
|
private get isDevelopment();
|
|
32
39
|
private getCurrentRuntimeMode;
|
|
33
40
|
private createRuntimeDefines;
|
|
34
41
|
private getReactVendorFileName;
|
|
35
42
|
private getReactDomVendorFileName;
|
|
36
43
|
private getRouterVendorFileName;
|
|
44
|
+
private getConfiguredRuntimeModuleFileName;
|
|
45
|
+
private getConfiguredRuntimeModules;
|
|
46
|
+
getConfiguredRuntimeModuleSpecifiers(): string[];
|
|
47
|
+
private getRuntimeModuleBundleExternals;
|
|
37
48
|
private getUseSyncExternalStoreWithSelectorVendorFileName;
|
|
49
|
+
private getPageLayoutNormalizationVendorFileName;
|
|
50
|
+
private getLayoutComposeVendorFileName;
|
|
38
51
|
private createReactVendorImportRewritePlugin;
|
|
39
52
|
getRuntimeImports(mode?: RuntimeMode): ReactRuntimeImports;
|
|
40
53
|
getRuntimeAliasMap(mode?: RuntimeMode): Record<string, string>;
|
|
41
54
|
getRuntimeManifest(mode?: RuntimeMode): BrowserRuntimeManifest;
|
|
42
|
-
getDependencies(
|
|
55
|
+
getDependencies(options?: {
|
|
56
|
+
modes?: RuntimeMode[];
|
|
57
|
+
}): AssetDefinition[];
|
|
58
|
+
/**
|
|
59
|
+
* Declares the MDX-only page-layout-normalization vendor for the current runtime mode.
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* Kept out of {@link getDependencies} so non-MDX pages do not pay for this vendor during
|
|
63
|
+
* integration setup. Callers process these assets once when an MDX page graph is prepared.
|
|
64
|
+
*/
|
|
65
|
+
getPageLayoutNormalizationDependencies(options?: {
|
|
66
|
+
modes?: RuntimeMode[];
|
|
67
|
+
}): AssetDefinition[];
|
|
43
68
|
createRuntimeAliasPlugin(mode?: RuntimeMode): EcoBuildPlugin;
|
|
44
69
|
}
|
|
45
70
|
export {};
|
|
@@ -5,12 +5,17 @@ import {
|
|
|
5
5
|
createBrowserRuntimeModuleAsset,
|
|
6
6
|
createBrowserRuntimeScriptAsset
|
|
7
7
|
} from "@ecopages/core/services/asset-processing-service";
|
|
8
|
-
import { createReactDomRuntimeInteropPlugin } from "
|
|
9
|
-
import {
|
|
8
|
+
import { createReactDomRuntimeInteropPlugin } from "./runtime-interop-plugin.js";
|
|
9
|
+
import {
|
|
10
|
+
buildReactRuntimeAliasMap,
|
|
11
|
+
buildReactRuntimeManifest,
|
|
12
|
+
getReactRuntimeExternalSpecifiers
|
|
13
|
+
} from "./runtime-alias-map.js";
|
|
10
14
|
import {
|
|
11
15
|
createBrowserRuntimeManifest
|
|
12
16
|
} from "@ecopages/core/build/browser-runtime-manifest";
|
|
13
|
-
|
|
17
|
+
import { LAYOUT_COMPOSE_PACKAGE, PAGE_LAYOUT_NORMALIZATION_PACKAGE } from "./bootstrap-package-paths.js";
|
|
18
|
+
class RuntimeBundleService {
|
|
14
19
|
config;
|
|
15
20
|
constructor(config) {
|
|
16
21
|
this.config = config;
|
|
@@ -18,6 +23,12 @@ class ReactRuntimeBundleService {
|
|
|
18
23
|
setRootDir(rootDir) {
|
|
19
24
|
this.config.rootDir = rootDir;
|
|
20
25
|
}
|
|
26
|
+
setWorkDir(workDir) {
|
|
27
|
+
this.config.workDir = workDir;
|
|
28
|
+
}
|
|
29
|
+
setRuntimeModules(runtimeModules) {
|
|
30
|
+
this.config.runtimeModules = runtimeModules;
|
|
31
|
+
}
|
|
21
32
|
get isDevelopment() {
|
|
22
33
|
return process.env.NODE_ENV === "development";
|
|
23
34
|
}
|
|
@@ -43,9 +54,32 @@ class ReactRuntimeBundleService {
|
|
|
43
54
|
}
|
|
44
55
|
return mode === "development" ? `${this.config.routerAdapter.bundle.outputName}.development.js` : `${this.config.routerAdapter.bundle.outputName}.js`;
|
|
45
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
|
+
}
|
|
46
74
|
getUseSyncExternalStoreWithSelectorVendorFileName(mode) {
|
|
47
75
|
return mode === "development" ? "use-sync-external-store-with-selector.development.js" : "use-sync-external-store-with-selector.js";
|
|
48
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
|
+
}
|
|
49
83
|
createReactVendorImportRewritePlugin(mode) {
|
|
50
84
|
return createBrowserRuntimePlugin({
|
|
51
85
|
name: `react-plugin-vendor-runtime-import-rewrite-${mode}`,
|
|
@@ -70,7 +104,9 @@ class ReactRuntimeBundleService {
|
|
|
70
104
|
reactDom: buildBrowserRuntimeAssetUrl(reactDomVendorFileName),
|
|
71
105
|
useSyncExternalStoreWithSelector: buildBrowserRuntimeAssetUrl(
|
|
72
106
|
this.getUseSyncExternalStoreWithSelectorVendorFileName(mode)
|
|
73
|
-
)
|
|
107
|
+
),
|
|
108
|
+
pageLayoutNormalization: buildBrowserRuntimeAssetUrl(this.getPageLayoutNormalizationVendorFileName(mode)),
|
|
109
|
+
layoutCompose: buildBrowserRuntimeAssetUrl(this.getLayoutComposeVendorFileName(mode))
|
|
74
110
|
};
|
|
75
111
|
if (this.config.routerAdapter) {
|
|
76
112
|
runtimeImports.router = buildBrowserRuntimeAssetUrl(this.getRouterVendorFileName(mode));
|
|
@@ -81,11 +117,16 @@ class ReactRuntimeBundleService {
|
|
|
81
117
|
return buildReactRuntimeAliasMap(this.getRuntimeImports(mode));
|
|
82
118
|
}
|
|
83
119
|
getRuntimeManifest(mode = this.getCurrentRuntimeMode()) {
|
|
84
|
-
return buildReactRuntimeManifest(
|
|
120
|
+
return buildReactRuntimeManifest(
|
|
121
|
+
this.getRuntimeImports(mode),
|
|
122
|
+
this.getConfiguredRuntimeModules(),
|
|
123
|
+
(outputName) => buildBrowserRuntimeAssetUrl(this.getConfiguredRuntimeModuleFileName(outputName, mode))
|
|
124
|
+
);
|
|
85
125
|
}
|
|
86
|
-
getDependencies() {
|
|
126
|
+
getDependencies(options) {
|
|
87
127
|
const dependencies = [];
|
|
88
|
-
|
|
128
|
+
const modes = options?.modes ?? [this.getCurrentRuntimeMode()];
|
|
129
|
+
for (const mode of modes) {
|
|
89
130
|
const reactVendorImportRewritePlugin = this.createReactVendorImportRewritePlugin(mode);
|
|
90
131
|
const reactDomRuntimeInteropPlugin = createReactDomRuntimeInteropPlugin({
|
|
91
132
|
reactSpecifier: buildBrowserRuntimeAssetUrl(this.getReactVendorFileName(mode))
|
|
@@ -117,6 +158,7 @@ class ReactRuntimeBundleService {
|
|
|
117
158
|
fileName: this.getReactVendorFileName(mode),
|
|
118
159
|
cacheDirName: `ecopages-react-runtime-${mode}`,
|
|
119
160
|
rootDir: this.config.rootDir,
|
|
161
|
+
workDir: this.config.workDir,
|
|
120
162
|
bundleOptions: {
|
|
121
163
|
define: this.createRuntimeDefines(mode),
|
|
122
164
|
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME]
|
|
@@ -128,6 +170,7 @@ class ReactRuntimeBundleService {
|
|
|
128
170
|
fileName: this.getReactDomVendorFileName(mode),
|
|
129
171
|
cacheDirName: `ecopages-react-runtime-${mode}`,
|
|
130
172
|
rootDir: this.config.rootDir,
|
|
173
|
+
workDir: this.config.workDir,
|
|
131
174
|
bundleOptions: {
|
|
132
175
|
define: this.createRuntimeDefines(mode),
|
|
133
176
|
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
@@ -143,6 +186,16 @@ class ReactRuntimeBundleService {
|
|
|
143
186
|
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
144
187
|
plugins: [reactVendorImportRewritePlugin]
|
|
145
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
|
+
}
|
|
146
199
|
})
|
|
147
200
|
);
|
|
148
201
|
if (this.config.routerAdapter) {
|
|
@@ -162,6 +215,49 @@ class ReactRuntimeBundleService {
|
|
|
162
215
|
})
|
|
163
216
|
);
|
|
164
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]
|
|
232
|
+
}
|
|
233
|
+
})
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
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
|
+
);
|
|
165
261
|
}
|
|
166
262
|
return dependencies;
|
|
167
263
|
}
|
|
@@ -182,5 +278,5 @@ class ReactRuntimeBundleService {
|
|
|
182
278
|
}
|
|
183
279
|
}
|
|
184
280
|
export {
|
|
185
|
-
|
|
281
|
+
RuntimeBundleService
|
|
186
282
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
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 declare function isReactProductionRuntime(): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes `reactPlugin({ runtimeModules })` entries for vendor bundling.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
export type ReactPluginRuntimeModule = string | {
|
|
7
|
+
specifier: string;
|
|
8
|
+
outputName?: string;
|
|
9
|
+
externals?: string[];
|
|
10
|
+
};
|
|
11
|
+
export type ResolvedReactPluginRuntimeModule = {
|
|
12
|
+
specifier: string;
|
|
13
|
+
outputName: string;
|
|
14
|
+
externals: string[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Builds a stable vendor filename stem from a package specifier.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveReactPluginRuntimeModuleSlug(specifier: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Resolves user-facing runtime module declarations into vendor bundle config.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveReactPluginRuntimeModules(modules: ReactPluginRuntimeModule[] | undefined): ResolvedReactPluginRuntimeModule[];
|
|
24
|
+
/**
|
|
25
|
+
* Merges auto-discovered layout npm imports with explicit `runtimeModules` entries.
|
|
26
|
+
*
|
|
27
|
+
* @remarks Manual entries win when both sources declare the same specifier.
|
|
28
|
+
*/
|
|
29
|
+
export declare function mergeReactPluginRuntimeModules(manualModules: ResolvedReactPluginRuntimeModule[], autoSpecifiers: string[]): ResolvedReactPluginRuntimeModule[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
function resolveReactPluginRuntimeModuleSlug(specifier) {
|
|
2
|
+
return specifier.replace(/^@/, "").replace(/\//g, "-");
|
|
3
|
+
}
|
|
4
|
+
function resolveReactPluginRuntimeModules(modules) {
|
|
5
|
+
return (modules ?? []).map((entry) => {
|
|
6
|
+
if (typeof entry === "string") {
|
|
7
|
+
return {
|
|
8
|
+
specifier: entry,
|
|
9
|
+
outputName: resolveReactPluginRuntimeModuleSlug(entry),
|
|
10
|
+
externals: []
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
specifier: entry.specifier,
|
|
15
|
+
outputName: entry.outputName ?? resolveReactPluginRuntimeModuleSlug(entry.specifier),
|
|
16
|
+
externals: entry.externals ?? []
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function mergeReactPluginRuntimeModules(manualModules, autoSpecifiers) {
|
|
21
|
+
const merged = /* @__PURE__ */ new Map();
|
|
22
|
+
for (const specifier of autoSpecifiers) {
|
|
23
|
+
merged.set(specifier, {
|
|
24
|
+
specifier,
|
|
25
|
+
outputName: resolveReactPluginRuntimeModuleSlug(specifier),
|
|
26
|
+
externals: []
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
for (const entry of manualModules) {
|
|
30
|
+
merged.set(entry.specifier, entry);
|
|
31
|
+
}
|
|
32
|
+
return [...merged.values()];
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
mergeReactPluginRuntimeModules,
|
|
36
|
+
resolveReactPluginRuntimeModuleSlug,
|
|
37
|
+
resolveReactPluginRuntimeModules
|
|
38
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AST transforms for the client graph boundary plugin.
|
|
3
|
+
*/
|
|
4
|
+
import type { RequestedExportRules } from './boundary-cache.js';
|
|
5
|
+
/**
|
|
6
|
+
* Parses a module using Oxc AST and surgically removes forbidden imports.
|
|
7
|
+
* Filters down to the exact specifiers requested via `{namedImport}` syntax.
|
|
8
|
+
*
|
|
9
|
+
* @param source - The raw string source content of the module.
|
|
10
|
+
* @param filename - The absolute path of the module.
|
|
11
|
+
* @param globallyAllowed - A map of modules declared globally allowable by the build configuration.
|
|
12
|
+
* @param requestedExports - Local requested-export registry used to propagate named reachability across files.
|
|
13
|
+
* @returns An object containing the transformed string and a boolean indicating if changes occurred.
|
|
14
|
+
*/
|
|
15
|
+
export declare function transformModuleImports(source: string, filename: string, globallyAllowed: Map<string, Set<string> | '*'>, requestedExports: Map<string, RequestedExportRules>, projectRoot?: string): {
|
|
16
|
+
transformed: string;
|
|
17
|
+
modified: boolean;
|
|
18
|
+
};
|