@ecopages/react 0.2.0-beta.9 → 0.2.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +179 -7
- package/package.json +53 -28
- package/src/app/client-only.js +15 -0
- package/src/app/dynamic.js +9 -0
- package/src/app/dynamic.test.browser.js +31 -0
- package/src/bundling/bootstrap-package-paths.d.ts +5 -0
- package/src/bundling/bootstrap-package-paths.js +5 -0
- package/src/{services/react-bundle.service.d.ts → bundling/bundle.d.ts} +23 -8
- package/src/bundling/bundle.js +120 -0
- package/src/bundling/discover-layout-runtime-modules.d.ts +32 -0
- package/src/bundling/discover-layout-runtime-modules.js +185 -0
- package/src/bundling/runtime-alias-map.d.ts +13 -0
- package/src/bundling/runtime-alias-map.js +113 -0
- package/src/{services/react-runtime-bundle.service.d.ts → bundling/runtime-bundle.d.ts} +25 -4
- package/src/bundling/runtime-bundle.js +258 -0
- package/src/bundling/runtime-interop-plugin.js +34 -0
- package/src/bundling/runtime-mode.d.ts +9 -0
- package/src/bundling/runtime-mode.js +11 -0
- package/src/bundling/runtime-modules.d.ts +29 -0
- package/src/bundling/runtime-modules.js +49 -0
- package/src/client-graph/ast-transform.d.ts +18 -0
- package/src/client-graph/ast-transform.js +426 -0
- package/src/{utils/client-graph-boundary-cache.d.ts → client-graph/boundary-cache.d.ts} +23 -13
- package/src/client-graph/boundary-cache.js +182 -0
- package/src/{utils/client-graph-boundary-plugin.d.ts → client-graph/boundary-plugin.d.ts} +4 -13
- package/src/client-graph/boundary-plugin.js +149 -0
- package/src/client-graph/component-config-traversal.js +77 -0
- package/src/client-graph/declared-modules.js +69 -0
- package/src/client-graph/module-classification.d.ts +3 -0
- package/src/client-graph/module-classification.js +43 -0
- package/src/{utils → client-graph}/reachability-analyzer.d.ts +4 -12
- package/src/client-graph/reachability-analyzer.js +515 -0
- package/src/client-graph/specifier-classification.d.ts +75 -0
- package/src/client-graph/specifier-classification.js +214 -0
- 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 +44 -0
- package/src/hmr/hmr-strategy.d.ts +74 -0
- package/src/hmr/hmr-strategy.js +351 -0
- package/src/{services/react-hmr-page-metadata-cache.d.ts → hmr/page-metadata-cache.d.ts} +5 -1
- package/src/hmr/page-metadata-cache.js +44 -0
- 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.d.ts +4 -0
- package/src/hydration/assert-no-bare-ecopages-imports.js +7 -0
- package/src/hydration/bootstrap-imports.d.ts +25 -0
- package/src/hydration/bootstrap-imports.js +33 -0
- package/src/hydration/hydration-asset.d.ts +84 -0
- package/src/hydration/hydration-asset.js +227 -0
- package/src/hydration/hydration-scripts.d.ts +104 -0
- package/src/hydration/hydration-scripts.js +483 -0
- package/src/hydration/hydration-scripts.test.browser.js +199 -0
- package/src/hydration/page-data-manifest.d.ts +58 -0
- package/src/hydration/page-data-manifest.js +97 -0
- package/src/hydration/page-data-reader.d.ts +31 -0
- package/src/hydration/page-data-reader.js +77 -0
- package/src/hydration/page-payload.d.ts +67 -0
- package/src/hydration/page-payload.js +106 -0
- package/src/hydration/serialize-page-data-script.d.ts +27 -0
- package/src/hydration/serialize-page-data-script.js +30 -0
- package/src/{services/react-mdx-config-dependency.service.d.ts → mdx/mdx-config-dependency.d.ts} +6 -6
- package/src/mdx/mdx-config-dependency.js +110 -0
- package/src/mdx/mdx-loader-plugin.d.ts +2 -0
- package/src/mdx/mdx-loader-plugin.js +8 -0
- package/src/page/page-module.d.ts +46 -0
- package/src/page/page-module.js +74 -0
- package/src/plugin/react.constants.js +1 -0
- package/src/{react.plugin.d.ts → plugin/react.plugin.d.ts} +9 -3
- package/src/plugin/react.plugin.js +241 -0
- package/src/plugin/react.types.d.ts +156 -0
- package/src/plugin/react.types.js +1 -0
- package/src/render/component-ownership.d.ts +49 -0
- package/src/render/component-ownership.js +46 -0
- package/src/render/component-ssr.d.ts +113 -0
- package/src/render/component-ssr.js +180 -0
- package/src/render/eco-embed.js +9 -0
- package/src/render/errors.d.ts +16 -0
- package/src/render/errors.js +23 -0
- package/src/render/html-boundary.js +59 -0
- package/src/render/layout-compose.d.ts +66 -0
- package/src/render/layout-compose.js +134 -0
- package/src/render/react-renderer.d.ts +138 -0
- package/src/render/react-renderer.js +448 -0
- package/src/render/react-runtime.d.ts +13 -0
- package/src/render/react-runtime.js +26 -0
- package/src/render/unified-layout-composition.d.ts +53 -0
- package/src/render/unified-layout-composition.js +78 -0
- package/src/runtime/use-sync-external-store-with-selector.js +52 -54
- package/src/eco-embed.js +0 -11
- package/src/react-hmr-strategy.d.ts +0 -230
- package/src/react-hmr-strategy.js +0 -657
- package/src/react-renderer.d.ts +0 -233
- package/src/react-renderer.js +0 -622
- package/src/react.constants.js +0 -4
- package/src/react.plugin.js +0 -209
- package/src/react.types.d.ts +0 -88
- package/src/react.types.js +0 -0
- package/src/router-adapter.js +0 -0
- package/src/services/pages-index.d.ts +0 -64
- package/src/services/pages-index.js +0 -73
- package/src/services/react-bundle.service.js +0 -86
- package/src/services/react-hmr-page-metadata-cache.js +0 -35
- package/src/services/react-hydration-asset.service.d.ts +0 -84
- package/src/services/react-hydration-asset.service.js +0 -217
- package/src/services/react-mdx-config-dependency.service.js +0 -122
- 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/services/react-runtime-bundle.service.js +0 -192
- package/src/utils/client-graph-boundary-cache.js +0 -116
- package/src/utils/client-graph-boundary-plugin.js +0 -552
- package/src/utils/client-only.js +0 -19
- package/src/utils/component-config-traversal.js +0 -54
- package/src/utils/declared-modules.js +0 -47
- package/src/utils/dynamic.js +0 -12
- package/src/utils/dynamic.test.browser.js +0 -33
- package/src/utils/hmr-scripts.js +0 -31
- package/src/utils/html-boundary.js +0 -55
- package/src/utils/hydration-scripts.d.ts +0 -92
- package/src/utils/hydration-scripts.js +0 -358
- package/src/utils/hydration-scripts.test.browser.js +0 -198
- package/src/utils/reachability-analyzer.js +0 -339
- package/src/utils/react-dom-runtime-interop-plugin.js +0 -38
- 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/react-runtime-alias-map.js +0 -90
- /package/src/{utils → app}/client-only.d.ts +0 -0
- /package/src/{utils → app}/dynamic.d.ts +0 -0
- /package/src/{utils → app}/dynamic.test.browser.d.ts +0 -0
- /package/src/{utils/react-dom-runtime-interop-plugin.d.ts → bundling/runtime-interop-plugin.d.ts} +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/{declarations.d.ts → contracts/declarations.d.ts} +0 -0
- /package/src/{router-adapter.d.ts → contracts/router-adapter.d.ts} +0 -0
- /package/src/{utils → hmr}/hmr-scripts.d.ts +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/{eco-embed.d.ts → render/eco-embed.d.ts} +0 -0
- /package/src/{utils → render}/html-boundary.d.ts +0 -0
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { LocalsAccessError } from "@ecopages/core/errors";
|
|
2
|
-
class ReactPagePayloadService {
|
|
3
|
-
/**
|
|
4
|
-
* Creates the canonical page-props payload used by router hydration.
|
|
5
|
-
*
|
|
6
|
-
* React pages embedded in a non-React HTML shell still need to expose the same
|
|
7
|
-
* page-data contract as fully React-owned documents so navigation and hydration
|
|
8
|
-
* can read one shared document payload consistently.
|
|
9
|
-
*/
|
|
10
|
-
buildRouterPageDataScript(pageProps) {
|
|
11
|
-
const safeJson = JSON.stringify(pageProps || {}).replace(/</g, "\\u003c");
|
|
12
|
-
return `<script id="__ECO_PAGE_DATA__" type="application/json">${safeJson}<\/script>`;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Builds the serialized page-props payload embedded into the final HTML.
|
|
16
|
-
*
|
|
17
|
-
* The document payload is intentionally narrower than the full server render
|
|
18
|
-
* input: only routing data, public page props, and explicitly allowed locals are
|
|
19
|
-
* exposed to the browser.
|
|
20
|
-
*/
|
|
21
|
-
buildSerializedPageProps(options) {
|
|
22
|
-
return {
|
|
23
|
-
...options.pageProps,
|
|
24
|
-
params: options.params,
|
|
25
|
-
query: options.query,
|
|
26
|
-
...options.safeLocals && { locals: options.safeLocals }
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Safely extracts the declared subset of locals for client-side hydration.
|
|
31
|
-
*
|
|
32
|
-
* On dynamic pages with `cache: 'dynamic'`, middleware populates `locals` with
|
|
33
|
-
* request-scoped data (e.g., session). Only keys explicitly declared via
|
|
34
|
-
* `Page.requires` are serialized to the client so sensitive request-only data
|
|
35
|
-
* is not leaked into hydration payloads by default.
|
|
36
|
-
*
|
|
37
|
-
* On static pages, `locals` is a Proxy that throws `LocalsAccessError` on access
|
|
38
|
-
* to prevent accidental use. This method safely detects that case and returns
|
|
39
|
-
* `undefined` instead of throwing.
|
|
40
|
-
*/
|
|
41
|
-
getSerializableLocals(locals, requiredLocals) {
|
|
42
|
-
try {
|
|
43
|
-
if (!locals) {
|
|
44
|
-
return void 0;
|
|
45
|
-
}
|
|
46
|
-
const requiredKeys = requiredLocals ? Array.isArray(requiredLocals) ? requiredLocals : [requiredLocals] : [];
|
|
47
|
-
if (requiredKeys.length === 0) {
|
|
48
|
-
return void 0;
|
|
49
|
-
}
|
|
50
|
-
const serializedLocals = Object.fromEntries(
|
|
51
|
-
requiredKeys.filter((key) => Object.prototype.hasOwnProperty.call(locals, key)).map((key) => [key, locals[key]])
|
|
52
|
-
);
|
|
53
|
-
if (Object.keys(serializedLocals).length > 0) {
|
|
54
|
-
return serializedLocals;
|
|
55
|
-
}
|
|
56
|
-
return void 0;
|
|
57
|
-
} catch (error) {
|
|
58
|
-
if (error instanceof LocalsAccessError) {
|
|
59
|
-
return void 0;
|
|
60
|
-
}
|
|
61
|
-
throw error;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export {
|
|
66
|
-
ReactPagePayloadService
|
|
67
|
-
};
|
|
@@ -1,192 +0,0 @@
|
|
|
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 "../utils/react-dom-runtime-interop-plugin.js";
|
|
9
|
-
import { buildReactRuntimeAliasMap, buildReactRuntimeManifest } from "../utils/react-runtime-alias-map.js";
|
|
10
|
-
import {
|
|
11
|
-
createBrowserRuntimeManifest
|
|
12
|
-
} from "@ecopages/core/build/browser-runtime-manifest";
|
|
13
|
-
class ReactRuntimeBundleService {
|
|
14
|
-
config;
|
|
15
|
-
constructor(config) {
|
|
16
|
-
this.config = config;
|
|
17
|
-
}
|
|
18
|
-
setRootDir(rootDir) {
|
|
19
|
-
this.config.rootDir = rootDir;
|
|
20
|
-
}
|
|
21
|
-
setWorkDir(workDir) {
|
|
22
|
-
this.config.workDir = workDir;
|
|
23
|
-
}
|
|
24
|
-
get isDevelopment() {
|
|
25
|
-
return process.env.NODE_ENV === "development";
|
|
26
|
-
}
|
|
27
|
-
getCurrentRuntimeMode() {
|
|
28
|
-
return this.isDevelopment ? "development" : "production";
|
|
29
|
-
}
|
|
30
|
-
createRuntimeDefines(mode) {
|
|
31
|
-
const nodeEnv = JSON.stringify(mode);
|
|
32
|
-
return {
|
|
33
|
-
"process.env.NODE_ENV": nodeEnv,
|
|
34
|
-
"import.meta.env.NODE_ENV": nodeEnv
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
getReactVendorFileName(mode) {
|
|
38
|
-
return mode === "development" ? "react.development.js" : "react.js";
|
|
39
|
-
}
|
|
40
|
-
getReactDomVendorFileName(mode) {
|
|
41
|
-
return mode === "development" ? "react-dom.development.js" : "react-dom.js";
|
|
42
|
-
}
|
|
43
|
-
getRouterVendorFileName(mode) {
|
|
44
|
-
if (!this.config.routerAdapter) {
|
|
45
|
-
return "";
|
|
46
|
-
}
|
|
47
|
-
return mode === "development" ? `${this.config.routerAdapter.bundle.outputName}.development.js` : `${this.config.routerAdapter.bundle.outputName}.js`;
|
|
48
|
-
}
|
|
49
|
-
getUseSyncExternalStoreWithSelectorVendorFileName(mode) {
|
|
50
|
-
return mode === "development" ? "use-sync-external-store-with-selector.development.js" : "use-sync-external-store-with-selector.js";
|
|
51
|
-
}
|
|
52
|
-
createReactVendorImportRewritePlugin(mode) {
|
|
53
|
-
return createBrowserRuntimePlugin({
|
|
54
|
-
name: `react-plugin-vendor-runtime-import-rewrite-${mode}`,
|
|
55
|
-
manifest: createBrowserRuntimeManifest([
|
|
56
|
-
{
|
|
57
|
-
specifier: "react",
|
|
58
|
-
owner: "@ecopages/react",
|
|
59
|
-
importPath: "react",
|
|
60
|
-
publicPath: buildBrowserRuntimeAssetUrl(this.getReactVendorFileName(mode))
|
|
61
|
-
}
|
|
62
|
-
])
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
getRuntimeImports(mode = this.getCurrentRuntimeMode()) {
|
|
66
|
-
const reactVendorFileName = this.getReactVendorFileName(mode);
|
|
67
|
-
const reactDomVendorFileName = this.getReactDomVendorFileName(mode);
|
|
68
|
-
const runtimeImports = {
|
|
69
|
-
react: buildBrowserRuntimeAssetUrl(reactVendorFileName),
|
|
70
|
-
reactDomClient: buildBrowserRuntimeAssetUrl(reactDomVendorFileName),
|
|
71
|
-
reactJsxRuntime: buildBrowserRuntimeAssetUrl(reactVendorFileName),
|
|
72
|
-
reactJsxDevRuntime: buildBrowserRuntimeAssetUrl(reactVendorFileName),
|
|
73
|
-
reactDom: buildBrowserRuntimeAssetUrl(reactDomVendorFileName),
|
|
74
|
-
useSyncExternalStoreWithSelector: buildBrowserRuntimeAssetUrl(
|
|
75
|
-
this.getUseSyncExternalStoreWithSelectorVendorFileName(mode)
|
|
76
|
-
)
|
|
77
|
-
};
|
|
78
|
-
if (this.config.routerAdapter) {
|
|
79
|
-
runtimeImports.router = buildBrowserRuntimeAssetUrl(this.getRouterVendorFileName(mode));
|
|
80
|
-
}
|
|
81
|
-
return runtimeImports;
|
|
82
|
-
}
|
|
83
|
-
getRuntimeAliasMap(mode = this.getCurrentRuntimeMode()) {
|
|
84
|
-
return buildReactRuntimeAliasMap(this.getRuntimeImports(mode));
|
|
85
|
-
}
|
|
86
|
-
getRuntimeManifest(mode = this.getCurrentRuntimeMode()) {
|
|
87
|
-
return buildReactRuntimeManifest(this.getRuntimeImports(mode));
|
|
88
|
-
}
|
|
89
|
-
getDependencies(options) {
|
|
90
|
-
const dependencies = [];
|
|
91
|
-
const modes = options?.modes ?? [this.getCurrentRuntimeMode()];
|
|
92
|
-
for (const mode of modes) {
|
|
93
|
-
const reactVendorImportRewritePlugin = this.createReactVendorImportRewritePlugin(mode);
|
|
94
|
-
const reactDomRuntimeInteropPlugin = createReactDomRuntimeInteropPlugin({
|
|
95
|
-
reactSpecifier: buildBrowserRuntimeAssetUrl(this.getReactVendorFileName(mode))
|
|
96
|
-
});
|
|
97
|
-
const reactRuntimeAliasPlugin = createBrowserRuntimePlugin({
|
|
98
|
-
name: `react-plugin-runtime-specifier-alias-${mode}`,
|
|
99
|
-
manifest: createBrowserRuntimeManifest([
|
|
100
|
-
{
|
|
101
|
-
specifier: "react",
|
|
102
|
-
owner: "",
|
|
103
|
-
importPath: "react",
|
|
104
|
-
publicPath: buildBrowserRuntimeAssetUrl(this.getReactVendorFileName(mode))
|
|
105
|
-
}
|
|
106
|
-
])
|
|
107
|
-
});
|
|
108
|
-
const reactDomBundlePlugins = [reactRuntimeAliasPlugin, reactDomRuntimeInteropPlugin].filter(
|
|
109
|
-
(plugin) => plugin !== null
|
|
110
|
-
);
|
|
111
|
-
const runtimeAliasPlugin = this.createRuntimeAliasPlugin(mode);
|
|
112
|
-
const mappedSpecifiers = new Set(Object.keys(this.getRuntimeAliasMap(mode)));
|
|
113
|
-
dependencies.push(
|
|
114
|
-
createBrowserRuntimeModuleAsset({
|
|
115
|
-
modules: [
|
|
116
|
-
{ specifier: "react", defaultExport: true },
|
|
117
|
-
{ specifier: "react/jsx-runtime" },
|
|
118
|
-
{ specifier: "react/jsx-dev-runtime" }
|
|
119
|
-
],
|
|
120
|
-
name: "react",
|
|
121
|
-
fileName: this.getReactVendorFileName(mode),
|
|
122
|
-
cacheDirName: `ecopages-react-runtime-${mode}`,
|
|
123
|
-
rootDir: this.config.rootDir,
|
|
124
|
-
workDir: this.config.workDir,
|
|
125
|
-
bundleOptions: {
|
|
126
|
-
define: this.createRuntimeDefines(mode),
|
|
127
|
-
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME]
|
|
128
|
-
}
|
|
129
|
-
}),
|
|
130
|
-
createBrowserRuntimeModuleAsset({
|
|
131
|
-
modules: [{ specifier: "react-dom", defaultExport: true }, { specifier: "react-dom/client" }],
|
|
132
|
-
name: "react-dom",
|
|
133
|
-
fileName: this.getReactDomVendorFileName(mode),
|
|
134
|
-
cacheDirName: `ecopages-react-runtime-${mode}`,
|
|
135
|
-
rootDir: this.config.rootDir,
|
|
136
|
-
workDir: this.config.workDir,
|
|
137
|
-
bundleOptions: {
|
|
138
|
-
define: this.createRuntimeDefines(mode),
|
|
139
|
-
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
140
|
-
plugins: reactDomBundlePlugins
|
|
141
|
-
}
|
|
142
|
-
}),
|
|
143
|
-
createBrowserRuntimeScriptAsset({
|
|
144
|
-
importPath: "@ecopages/react/runtime/use-sync-external-store-with-selector",
|
|
145
|
-
name: "use-sync-external-store-with-selector",
|
|
146
|
-
fileName: this.getUseSyncExternalStoreWithSelectorVendorFileName(mode),
|
|
147
|
-
bundleOptions: {
|
|
148
|
-
define: this.createRuntimeDefines(mode),
|
|
149
|
-
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
150
|
-
plugins: [reactVendorImportRewritePlugin]
|
|
151
|
-
}
|
|
152
|
-
})
|
|
153
|
-
);
|
|
154
|
-
if (this.config.routerAdapter) {
|
|
155
|
-
const unresolvedExternals = this.config.routerAdapter.bundle.externals.filter(
|
|
156
|
-
(external) => !mappedSpecifiers.has(external)
|
|
157
|
-
);
|
|
158
|
-
dependencies.push(
|
|
159
|
-
createBrowserRuntimeScriptAsset({
|
|
160
|
-
importPath: this.config.routerAdapter.bundle.importPath,
|
|
161
|
-
name: this.config.routerAdapter.bundle.outputName,
|
|
162
|
-
fileName: this.getRouterVendorFileName(mode),
|
|
163
|
-
bundleOptions: {
|
|
164
|
-
define: this.createRuntimeDefines(mode),
|
|
165
|
-
external: unresolvedExternals,
|
|
166
|
-
plugins: [runtimeAliasPlugin]
|
|
167
|
-
}
|
|
168
|
-
})
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return dependencies;
|
|
173
|
-
}
|
|
174
|
-
createRuntimeAliasPlugin(mode = this.getCurrentRuntimeMode()) {
|
|
175
|
-
const aliasMap = this.getRuntimeAliasMap(mode);
|
|
176
|
-
const manifest = createBrowserRuntimeManifest(
|
|
177
|
-
Object.entries(aliasMap).map(([specifier, publicPath]) => ({
|
|
178
|
-
specifier,
|
|
179
|
-
owner: "",
|
|
180
|
-
importPath: specifier,
|
|
181
|
-
publicPath
|
|
182
|
-
}))
|
|
183
|
-
);
|
|
184
|
-
return createBrowserRuntimePlugin({
|
|
185
|
-
name: `react-plugin-runtime-alias-${mode}`,
|
|
186
|
-
manifest
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
export {
|
|
191
|
-
ReactRuntimeBundleService
|
|
192
|
-
};
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { rapidhash } from "@ecopages/core/utils/hash";
|
|
2
|
-
const DEFAULT_MAX_ENTRIES = 5e3;
|
|
3
|
-
function cloneRules(rules) {
|
|
4
|
-
return rules instanceof Set ? new Set(rules) : rules;
|
|
5
|
-
}
|
|
6
|
-
class ClientGraphBoundaryCache {
|
|
7
|
-
entries = /* @__PURE__ */ new Map();
|
|
8
|
-
maxEntries;
|
|
9
|
-
hits = 0;
|
|
10
|
-
misses = 0;
|
|
11
|
-
constructor(maxEntries = DEFAULT_MAX_ENTRIES) {
|
|
12
|
-
if (maxEntries <= 0) {
|
|
13
|
-
throw new Error(`ClientGraphBoundaryCache: maxEntries must be > 0, got ${maxEntries}`);
|
|
14
|
-
}
|
|
15
|
-
this.maxEntries = maxEntries;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Look up a cached transform for `filePath`.
|
|
19
|
-
*
|
|
20
|
-
* Returns `undefined` if the source or allow list has changed since
|
|
21
|
-
* the entry was stored. The caller is responsible for re-running the
|
|
22
|
-
* transform in that case and calling `set` to update the entry.
|
|
23
|
-
*/
|
|
24
|
-
get(filePath, source, globallyAllowedSpecifiers) {
|
|
25
|
-
const sourceHash = rapidhash(source);
|
|
26
|
-
const allowListHash = hashAllowList(globallyAllowedSpecifiers);
|
|
27
|
-
const existing = this.entries.get(filePath);
|
|
28
|
-
if (existing && existing.sourceHash === sourceHash && existing.allowListHash === allowListHash) {
|
|
29
|
-
this.hits += 1;
|
|
30
|
-
this.entries.delete(filePath);
|
|
31
|
-
this.entries.set(filePath, existing);
|
|
32
|
-
return existing;
|
|
33
|
-
}
|
|
34
|
-
this.misses += 1;
|
|
35
|
-
return void 0;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Store a transform result.
|
|
39
|
-
*
|
|
40
|
-
* Evicts the least recently used entry if the cache exceeds its
|
|
41
|
-
* capacity. Defensively copies any `Set`-typed rules in `rulesAdded`
|
|
42
|
-
* so later mutations to the caller's sets cannot corrupt the cache.
|
|
43
|
-
*/
|
|
44
|
-
set(filePath, source, globallyAllowedSpecifiers, entry) {
|
|
45
|
-
const sourceHash = rapidhash(source);
|
|
46
|
-
const allowListHash = hashAllowList(globallyAllowedSpecifiers);
|
|
47
|
-
const rulesAddedCopy = /* @__PURE__ */ new Map();
|
|
48
|
-
for (const [key, rules] of entry.rulesAdded) {
|
|
49
|
-
rulesAddedCopy.set(key, cloneRules(rules));
|
|
50
|
-
}
|
|
51
|
-
const full = {
|
|
52
|
-
sourceHash,
|
|
53
|
-
allowListHash,
|
|
54
|
-
transformed: entry.transformed,
|
|
55
|
-
modified: entry.modified,
|
|
56
|
-
rulesAdded: rulesAddedCopy
|
|
57
|
-
};
|
|
58
|
-
this.entries.set(filePath, full);
|
|
59
|
-
if (this.entries.size > this.maxEntries) {
|
|
60
|
-
const oldestKey = this.entries.keys().next().value;
|
|
61
|
-
if (oldestKey !== void 0) {
|
|
62
|
-
this.entries.delete(oldestKey);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Invalidate a single file's entry. Call this from the file watcher
|
|
68
|
-
* when `filePath`'s content has changed.
|
|
69
|
-
*/
|
|
70
|
-
invalidate(filePath) {
|
|
71
|
-
this.entries.delete(filePath);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Invalidate every file whose key matches a prefix. Useful for
|
|
75
|
-
* "anything under `src/pages/` changed" signals.
|
|
76
|
-
*/
|
|
77
|
-
invalidateMatching(predicate) {
|
|
78
|
-
let removed = 0;
|
|
79
|
-
for (const key of this.entries.keys()) {
|
|
80
|
-
if (predicate(key)) {
|
|
81
|
-
this.entries.delete(key);
|
|
82
|
-
removed += 1;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return removed;
|
|
86
|
-
}
|
|
87
|
-
/** Clear all entries. */
|
|
88
|
-
clear() {
|
|
89
|
-
this.entries.clear();
|
|
90
|
-
this.hits = 0;
|
|
91
|
-
this.misses = 0;
|
|
92
|
-
}
|
|
93
|
-
/** Current cache size. */
|
|
94
|
-
get size() {
|
|
95
|
-
return this.entries.size;
|
|
96
|
-
}
|
|
97
|
-
/** Hit/miss counters for observability. */
|
|
98
|
-
stats() {
|
|
99
|
-
const total = this.hits + this.misses;
|
|
100
|
-
return {
|
|
101
|
-
hits: this.hits,
|
|
102
|
-
misses: this.misses,
|
|
103
|
-
size: this.entries.size,
|
|
104
|
-
hitRate: total === 0 ? 0 : this.hits / total
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
const clientGraphBoundaryCache = new ClientGraphBoundaryCache();
|
|
109
|
-
function hashAllowList(specifiers) {
|
|
110
|
-
const sorted = Array.from(specifiers).sort();
|
|
111
|
-
return rapidhash(sorted.join("\n"));
|
|
112
|
-
}
|
|
113
|
-
export {
|
|
114
|
-
ClientGraphBoundaryCache,
|
|
115
|
-
clientGraphBoundaryCache
|
|
116
|
-
};
|