@ecopages/react 0.2.1-beta.0 → 0.3.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 +164 -28
- package/package.json +67 -30
- package/src/app/client-only.js +10 -0
- package/src/app/dynamic.js +9 -0
- package/src/app/dynamic.test.browser.js +38 -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} +29 -11
- package/src/bundling/bundle.js +130 -0
- package/src/bundling/runtime-alias-map.d.ts +12 -0
- package/src/bundling/runtime-alias-map.js +110 -0
- package/src/bundling/runtime-bundle.d.ts +70 -0
- package/src/bundling/runtime-bundle.js +233 -0
- package/src/{utils/react-dom-runtime-interop-plugin.d.ts → bundling/runtime-interop-plugin.d.ts} +1 -1
- package/src/bundling/runtime-interop-plugin.js +32 -0
- package/src/bundling/runtime-mode.d.ts +1 -0
- package/src/bundling/runtime-mode.js +10 -0
- package/src/bundling/runtime-modules.d.ts +21 -0
- package/src/bundling/runtime-modules.js +28 -0
- package/src/client-graph/ast-transform-eco-page.d.ts +10 -0
- package/src/client-graph/ast-transform-eco-page.js +71 -0
- package/src/client-graph/ast-transform-import-edits.d.ts +13 -0
- package/src/client-graph/ast-transform-import-edits.js +75 -0
- package/src/client-graph/ast-transform-walk-imports.d.ts +20 -0
- package/src/client-graph/ast-transform-walk-imports.js +105 -0
- package/src/client-graph/ast-transform.d.ts +12 -0
- package/src/client-graph/ast-transform.js +91 -0
- package/src/client-graph/ast-walk.d.ts +10 -0
- package/src/client-graph/ast-walk.js +26 -0
- package/src/client-graph/boundary-plugin-read-file-inline.d.ts +7 -0
- package/src/client-graph/boundary-plugin-read-file-inline.js +43 -0
- package/src/client-graph/boundary-plugin-transform.d.ts +16 -0
- package/src/client-graph/boundary-plugin-transform.js +31 -0
- package/src/client-graph/boundary-plugin.d.ts +23 -0
- package/src/client-graph/boundary-plugin.js +177 -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/client-graph/reachability-analyzer.d.ts +26 -0
- package/src/client-graph/reachability-analyzer.js +55 -0
- package/src/client-graph/reachability-client-roots.d.ts +8 -0
- package/src/client-graph/reachability-client-roots.js +59 -0
- package/src/client-graph/reachability-export-names.d.ts +5 -0
- package/src/client-graph/reachability-export-names.js +34 -0
- package/src/client-graph/reachability-fallback-roots.d.ts +3 -0
- package/src/client-graph/reachability-fallback-roots.js +71 -0
- package/src/client-graph/reachability-preload.d.ts +10 -0
- package/src/client-graph/reachability-preload.js +30 -0
- package/src/client-graph/reachability-top-level-index.d.ts +14 -0
- package/src/client-graph/reachability-top-level-index.js +93 -0
- package/src/client-graph/reachability-traverse.d.ts +7 -0
- package/src/client-graph/reachability-traverse.js +201 -0
- package/src/client-graph/specifier-classification.d.ts +74 -0
- package/src/client-graph/specifier-classification.js +191 -0
- package/src/content/collection-component-cache.d.ts +25 -0
- package/src/content/collection-component-cache.js +62 -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-strategy-process.d.ts +34 -0
- package/src/hmr/hmr-strategy-process.js +83 -0
- package/src/hmr/hmr-strategy.d.ts +67 -0
- package/src/hmr/hmr-strategy.js +306 -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 +22 -0
- package/src/hmr/react-hmr-dev-transform-plugins.js +19 -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/browser/island-hydration.d.ts +82 -0
- package/src/hydration/browser/island-hydration.js +251 -0
- package/src/hydration/browser/page-hydration-hmr.d.ts +11 -0
- package/src/hydration/browser/page-hydration-hmr.js +56 -0
- package/src/hydration/browser/page-hydration-module.d.ts +8 -0
- package/src/hydration/browser/page-hydration-module.js +17 -0
- package/src/hydration/browser/page-hydration.d.ts +54 -0
- package/src/hydration/browser/page-hydration.js +177 -0
- package/src/hydration/compiled-page-hydration-options.d.ts +20 -0
- package/src/hydration/hydration-asset.d.ts +127 -0
- package/src/hydration/hydration-asset.js +379 -0
- package/src/hydration/hydration-lifecycle.test.browser.d.ts +1 -0
- package/src/hydration/hydration-lifecycle.test.browser.js +461 -0
- package/src/hydration/hydration-page-entry-source.d.ts +5 -0
- package/src/hydration/hydration-page-entry-source.js +87 -0
- package/src/hydration/hydration-script-compiler.d.ts +48 -0
- package/src/hydration/hydration-script-compiler.js +213 -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 +17 -0
- package/src/hydration/page-data-reader.js +31 -0
- package/src/hydration/page-payload.d.ts +68 -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} +9 -8
- package/src/mdx/mdx-config-dependency.js +107 -0
- package/src/mdx/mdx-loader-plugin.d.ts +8 -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 +74 -0
- package/src/plugin/react.constants.js +1 -0
- package/src/{react.plugin.d.ts → plugin/react.plugin.d.ts} +21 -27
- package/src/plugin/react.plugin.js +210 -0
- package/src/plugin/react.types.d.ts +106 -0
- package/src/plugin/react.types.js +1 -0
- package/src/render/component-ownership.d.ts +49 -0
- package/src/render/component-ownership.js +47 -0
- package/src/render/component-ssr.d.ts +59 -0
- package/src/render/component-ssr.js +76 -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 +114 -0
- package/src/render/react-renderer.js +490 -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 +22 -0
- package/src/render/unified-layout-composition.js +31 -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 -205
- 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.d.ts +0 -45
- package/src/services/react-runtime-bundle.service.js +0 -186
- package/src/utils/client-graph-boundary-cache.d.ts +0 -108
- package/src/utils/client-graph-boundary-cache.js +0 -116
- package/src/utils/client-graph-boundary-plugin.d.ts +0 -51
- 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.d.ts +0 -18
- 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.d.ts +0 -66
- 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 → 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/hydration-scripts.test.browser.d.ts → hydration/compiled-page-hydration-options.js} +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,45 +0,0 @@
|
|
|
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 type { EcoBuildPlugin } from '@ecopages/core/plugins/integration-plugin';
|
|
10
|
-
import { type AssetDefinition } from '@ecopages/core/services/asset-processing-service';
|
|
11
|
-
import type { ReactRouterAdapter } from '../router-adapter.js';
|
|
12
|
-
import { type BrowserRuntimeManifest } from '@ecopages/core/build/browser-runtime-manifest';
|
|
13
|
-
export type ReactRuntimeImports = {
|
|
14
|
-
react: string;
|
|
15
|
-
reactDomClient: string;
|
|
16
|
-
reactJsxRuntime: string;
|
|
17
|
-
reactJsxDevRuntime: string;
|
|
18
|
-
reactDom: string;
|
|
19
|
-
useSyncExternalStoreWithSelector: string;
|
|
20
|
-
router?: string;
|
|
21
|
-
};
|
|
22
|
-
export interface ReactRuntimeBundleServiceConfig {
|
|
23
|
-
routerAdapter?: ReactRouterAdapter;
|
|
24
|
-
rootDir?: string;
|
|
25
|
-
}
|
|
26
|
-
type RuntimeMode = 'development' | 'production';
|
|
27
|
-
export declare class ReactRuntimeBundleService {
|
|
28
|
-
private readonly config;
|
|
29
|
-
constructor(config: ReactRuntimeBundleServiceConfig);
|
|
30
|
-
setRootDir(rootDir: string | undefined): void;
|
|
31
|
-
private get isDevelopment();
|
|
32
|
-
private getCurrentRuntimeMode;
|
|
33
|
-
private createRuntimeDefines;
|
|
34
|
-
private getReactVendorFileName;
|
|
35
|
-
private getReactDomVendorFileName;
|
|
36
|
-
private getRouterVendorFileName;
|
|
37
|
-
private getUseSyncExternalStoreWithSelectorVendorFileName;
|
|
38
|
-
private createReactVendorImportRewritePlugin;
|
|
39
|
-
getRuntimeImports(mode?: RuntimeMode): ReactRuntimeImports;
|
|
40
|
-
getRuntimeAliasMap(mode?: RuntimeMode): Record<string, string>;
|
|
41
|
-
getRuntimeManifest(mode?: RuntimeMode): BrowserRuntimeManifest;
|
|
42
|
-
getDependencies(): AssetDefinition[];
|
|
43
|
-
createRuntimeAliasPlugin(mode?: RuntimeMode): EcoBuildPlugin;
|
|
44
|
-
}
|
|
45
|
-
export {};
|
|
@@ -1,186 +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
|
-
get isDevelopment() {
|
|
22
|
-
return process.env.NODE_ENV === "development";
|
|
23
|
-
}
|
|
24
|
-
getCurrentRuntimeMode() {
|
|
25
|
-
return this.isDevelopment ? "development" : "production";
|
|
26
|
-
}
|
|
27
|
-
createRuntimeDefines(mode) {
|
|
28
|
-
const nodeEnv = JSON.stringify(mode);
|
|
29
|
-
return {
|
|
30
|
-
"process.env.NODE_ENV": nodeEnv,
|
|
31
|
-
"import.meta.env.NODE_ENV": nodeEnv
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
getReactVendorFileName(mode) {
|
|
35
|
-
return mode === "development" ? "react.development.js" : "react.js";
|
|
36
|
-
}
|
|
37
|
-
getReactDomVendorFileName(mode) {
|
|
38
|
-
return mode === "development" ? "react-dom.development.js" : "react-dom.js";
|
|
39
|
-
}
|
|
40
|
-
getRouterVendorFileName(mode) {
|
|
41
|
-
if (!this.config.routerAdapter) {
|
|
42
|
-
return "";
|
|
43
|
-
}
|
|
44
|
-
return mode === "development" ? `${this.config.routerAdapter.bundle.outputName}.development.js` : `${this.config.routerAdapter.bundle.outputName}.js`;
|
|
45
|
-
}
|
|
46
|
-
getUseSyncExternalStoreWithSelectorVendorFileName(mode) {
|
|
47
|
-
return mode === "development" ? "use-sync-external-store-with-selector.development.js" : "use-sync-external-store-with-selector.js";
|
|
48
|
-
}
|
|
49
|
-
createReactVendorImportRewritePlugin(mode) {
|
|
50
|
-
return createBrowserRuntimePlugin({
|
|
51
|
-
name: `react-plugin-vendor-runtime-import-rewrite-${mode}`,
|
|
52
|
-
manifest: createBrowserRuntimeManifest([
|
|
53
|
-
{
|
|
54
|
-
specifier: "react",
|
|
55
|
-
owner: "@ecopages/react",
|
|
56
|
-
importPath: "react",
|
|
57
|
-
publicPath: buildBrowserRuntimeAssetUrl(this.getReactVendorFileName(mode))
|
|
58
|
-
}
|
|
59
|
-
])
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
getRuntimeImports(mode = this.getCurrentRuntimeMode()) {
|
|
63
|
-
const reactVendorFileName = this.getReactVendorFileName(mode);
|
|
64
|
-
const reactDomVendorFileName = this.getReactDomVendorFileName(mode);
|
|
65
|
-
const runtimeImports = {
|
|
66
|
-
react: buildBrowserRuntimeAssetUrl(reactVendorFileName),
|
|
67
|
-
reactDomClient: buildBrowserRuntimeAssetUrl(reactDomVendorFileName),
|
|
68
|
-
reactJsxRuntime: buildBrowserRuntimeAssetUrl(reactVendorFileName),
|
|
69
|
-
reactJsxDevRuntime: buildBrowserRuntimeAssetUrl(reactVendorFileName),
|
|
70
|
-
reactDom: buildBrowserRuntimeAssetUrl(reactDomVendorFileName),
|
|
71
|
-
useSyncExternalStoreWithSelector: buildBrowserRuntimeAssetUrl(
|
|
72
|
-
this.getUseSyncExternalStoreWithSelectorVendorFileName(mode)
|
|
73
|
-
)
|
|
74
|
-
};
|
|
75
|
-
if (this.config.routerAdapter) {
|
|
76
|
-
runtimeImports.router = buildBrowserRuntimeAssetUrl(this.getRouterVendorFileName(mode));
|
|
77
|
-
}
|
|
78
|
-
return runtimeImports;
|
|
79
|
-
}
|
|
80
|
-
getRuntimeAliasMap(mode = this.getCurrentRuntimeMode()) {
|
|
81
|
-
return buildReactRuntimeAliasMap(this.getRuntimeImports(mode));
|
|
82
|
-
}
|
|
83
|
-
getRuntimeManifest(mode = this.getCurrentRuntimeMode()) {
|
|
84
|
-
return buildReactRuntimeManifest(this.getRuntimeImports(mode));
|
|
85
|
-
}
|
|
86
|
-
getDependencies() {
|
|
87
|
-
const dependencies = [];
|
|
88
|
-
for (const mode of ["production", "development"]) {
|
|
89
|
-
const reactVendorImportRewritePlugin = this.createReactVendorImportRewritePlugin(mode);
|
|
90
|
-
const reactDomRuntimeInteropPlugin = createReactDomRuntimeInteropPlugin({
|
|
91
|
-
reactSpecifier: buildBrowserRuntimeAssetUrl(this.getReactVendorFileName(mode))
|
|
92
|
-
});
|
|
93
|
-
const reactRuntimeAliasPlugin = createBrowserRuntimePlugin({
|
|
94
|
-
name: `react-plugin-runtime-specifier-alias-${mode}`,
|
|
95
|
-
manifest: createBrowserRuntimeManifest([
|
|
96
|
-
{
|
|
97
|
-
specifier: "react",
|
|
98
|
-
owner: "",
|
|
99
|
-
importPath: "react",
|
|
100
|
-
publicPath: buildBrowserRuntimeAssetUrl(this.getReactVendorFileName(mode))
|
|
101
|
-
}
|
|
102
|
-
])
|
|
103
|
-
});
|
|
104
|
-
const reactDomBundlePlugins = [reactRuntimeAliasPlugin, reactDomRuntimeInteropPlugin].filter(
|
|
105
|
-
(plugin) => plugin !== null
|
|
106
|
-
);
|
|
107
|
-
const runtimeAliasPlugin = this.createRuntimeAliasPlugin(mode);
|
|
108
|
-
const mappedSpecifiers = new Set(Object.keys(this.getRuntimeAliasMap(mode)));
|
|
109
|
-
dependencies.push(
|
|
110
|
-
createBrowserRuntimeModuleAsset({
|
|
111
|
-
modules: [
|
|
112
|
-
{ specifier: "react", defaultExport: true },
|
|
113
|
-
{ specifier: "react/jsx-runtime" },
|
|
114
|
-
{ specifier: "react/jsx-dev-runtime" }
|
|
115
|
-
],
|
|
116
|
-
name: "react",
|
|
117
|
-
fileName: this.getReactVendorFileName(mode),
|
|
118
|
-
cacheDirName: `ecopages-react-runtime-${mode}`,
|
|
119
|
-
rootDir: this.config.rootDir,
|
|
120
|
-
bundleOptions: {
|
|
121
|
-
define: this.createRuntimeDefines(mode),
|
|
122
|
-
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME]
|
|
123
|
-
}
|
|
124
|
-
}),
|
|
125
|
-
createBrowserRuntimeModuleAsset({
|
|
126
|
-
modules: [{ specifier: "react-dom", defaultExport: true }, { specifier: "react-dom/client" }],
|
|
127
|
-
name: "react-dom",
|
|
128
|
-
fileName: this.getReactDomVendorFileName(mode),
|
|
129
|
-
cacheDirName: `ecopages-react-runtime-${mode}`,
|
|
130
|
-
rootDir: this.config.rootDir,
|
|
131
|
-
bundleOptions: {
|
|
132
|
-
define: this.createRuntimeDefines(mode),
|
|
133
|
-
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
134
|
-
plugins: reactDomBundlePlugins
|
|
135
|
-
}
|
|
136
|
-
}),
|
|
137
|
-
createBrowserRuntimeScriptAsset({
|
|
138
|
-
importPath: "@ecopages/react/runtime/use-sync-external-store-with-selector",
|
|
139
|
-
name: "use-sync-external-store-with-selector",
|
|
140
|
-
fileName: this.getUseSyncExternalStoreWithSelectorVendorFileName(mode),
|
|
141
|
-
bundleOptions: {
|
|
142
|
-
define: this.createRuntimeDefines(mode),
|
|
143
|
-
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
144
|
-
plugins: [reactVendorImportRewritePlugin]
|
|
145
|
-
}
|
|
146
|
-
})
|
|
147
|
-
);
|
|
148
|
-
if (this.config.routerAdapter) {
|
|
149
|
-
const unresolvedExternals = this.config.routerAdapter.bundle.externals.filter(
|
|
150
|
-
(external) => !mappedSpecifiers.has(external)
|
|
151
|
-
);
|
|
152
|
-
dependencies.push(
|
|
153
|
-
createBrowserRuntimeScriptAsset({
|
|
154
|
-
importPath: this.config.routerAdapter.bundle.importPath,
|
|
155
|
-
name: this.config.routerAdapter.bundle.outputName,
|
|
156
|
-
fileName: this.getRouterVendorFileName(mode),
|
|
157
|
-
bundleOptions: {
|
|
158
|
-
define: this.createRuntimeDefines(mode),
|
|
159
|
-
external: unresolvedExternals,
|
|
160
|
-
plugins: [runtimeAliasPlugin]
|
|
161
|
-
}
|
|
162
|
-
})
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return dependencies;
|
|
167
|
-
}
|
|
168
|
-
createRuntimeAliasPlugin(mode = this.getCurrentRuntimeMode()) {
|
|
169
|
-
const aliasMap = this.getRuntimeAliasMap(mode);
|
|
170
|
-
const manifest = createBrowserRuntimeManifest(
|
|
171
|
-
Object.entries(aliasMap).map(([specifier, publicPath]) => ({
|
|
172
|
-
specifier,
|
|
173
|
-
owner: "",
|
|
174
|
-
importPath: specifier,
|
|
175
|
-
publicPath
|
|
176
|
-
}))
|
|
177
|
-
);
|
|
178
|
-
return createBrowserRuntimePlugin({
|
|
179
|
-
name: `react-plugin-runtime-alias-${mode}`,
|
|
180
|
-
manifest
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
export {
|
|
185
|
-
ReactRuntimeBundleService
|
|
186
|
-
};
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Per-app persistent cache for `client-graph-boundary` plugin transforms.
|
|
3
|
-
*
|
|
4
|
-
* @remarks
|
|
5
|
-
* The plugin's `transformModuleImports` function is the second most
|
|
6
|
-
* expensive operation in the React build path (after `parseSync`).
|
|
7
|
-
* It walks the AST to find reachable exports and prunes forbidden
|
|
8
|
-
* imports. On a no-op rebuild (file unchanged, no plugin signature
|
|
9
|
-
* change) the entire walk can be skipped if the inputs are identical.
|
|
10
|
-
*
|
|
11
|
-
* This cache is owned by the {@link ReactPlugin} for the app's lifetime.
|
|
12
|
-
* It persists across HMR rebuilds but is invalidated per-file when the
|
|
13
|
-
* watcher detects a source change. The `requestedExports` registry
|
|
14
|
-
* remains per-build (it's mutated during cross-file propagation and
|
|
15
|
-
* must not accumulate stale state across builds).
|
|
16
|
-
*
|
|
17
|
-
* The cache is content-hashed (via `rapidhash`) so a `touch`/`utimes`
|
|
18
|
-
* does not invalidate a still-valid entry.
|
|
19
|
-
*
|
|
20
|
-
* **`rulesAdded` semantics:** the map holds the **after-state** of
|
|
21
|
-
* every registry key this transform touched — both newly added keys
|
|
22
|
-
* and keys that were grown (Set union) or promoted to `'*'`. On
|
|
23
|
-
* replay the cache applies each entry via the same merge rules the
|
|
24
|
-
* live transform uses (`mergeRequestedExportRules`), so a key that
|
|
25
|
-
* was already in the live registry when the transform ran and grew
|
|
26
|
-
* during the transform is correctly grown on replay against a fresh
|
|
27
|
-
* registry as well.
|
|
28
|
-
*/
|
|
29
|
-
export type RequestedExportRules = Set<string> | '*';
|
|
30
|
-
export type CachedTransform = {
|
|
31
|
-
/** Hash of the source string at the time the transform was cached. */
|
|
32
|
-
sourceHash: number | bigint;
|
|
33
|
-
/** Hash of the globally-allowed modules map at the time the transform was cached. */
|
|
34
|
-
allowListHash: number | bigint;
|
|
35
|
-
/** The transformed source (or original if `modified` is false). */
|
|
36
|
-
transformed: string;
|
|
37
|
-
/** Whether the transform changed the source. */
|
|
38
|
-
modified: boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Map of `requestedExports` keys this transform touched, mapped to
|
|
41
|
-
* their **after-state**. Includes:
|
|
42
|
-
* - newly-added keys
|
|
43
|
-
* - keys whose Set grew (union of pre-existing and newly reachable exports)
|
|
44
|
-
* - keys promoted to `'*'`
|
|
45
|
-
*
|
|
46
|
-
* On cache hit, each entry is replayed via `mergeRequestedExportRules`,
|
|
47
|
-
* which handles all three cases correctly. Defensively copied at
|
|
48
|
-
* `set()` time to prevent later mutation from corrupting the cache.
|
|
49
|
-
*/
|
|
50
|
-
rulesAdded: Map<string, RequestedExportRules>;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* LRU-bounded cache for client-graph-boundary transform results.
|
|
54
|
-
*
|
|
55
|
-
* One instance is owned by the React plugin for the app's lifetime and
|
|
56
|
-
* shared across all builds. The cache key is `(filePath, source, allowList)`
|
|
57
|
-
* so a file whose source or whose global allow list changes gets a fresh
|
|
58
|
-
* entry, while everything else hits.
|
|
59
|
-
*/
|
|
60
|
-
export declare class ClientGraphBoundaryCache {
|
|
61
|
-
private readonly entries;
|
|
62
|
-
private readonly maxEntries;
|
|
63
|
-
private hits;
|
|
64
|
-
private misses;
|
|
65
|
-
constructor(maxEntries?: number);
|
|
66
|
-
/**
|
|
67
|
-
* Look up a cached transform for `filePath`.
|
|
68
|
-
*
|
|
69
|
-
* Returns `undefined` if the source or allow list has changed since
|
|
70
|
-
* the entry was stored. The caller is responsible for re-running the
|
|
71
|
-
* transform in that case and calling `set` to update the entry.
|
|
72
|
-
*/
|
|
73
|
-
get(filePath: string, source: string, globallyAllowedSpecifiers: Iterable<string>): CachedTransform | undefined;
|
|
74
|
-
/**
|
|
75
|
-
* Store a transform result.
|
|
76
|
-
*
|
|
77
|
-
* Evicts the least recently used entry if the cache exceeds its
|
|
78
|
-
* capacity. Defensively copies any `Set`-typed rules in `rulesAdded`
|
|
79
|
-
* so later mutations to the caller's sets cannot corrupt the cache.
|
|
80
|
-
*/
|
|
81
|
-
set(filePath: string, source: string, globallyAllowedSpecifiers: Iterable<string>, entry: Omit<CachedTransform, 'sourceHash' | 'allowListHash'>): void;
|
|
82
|
-
/**
|
|
83
|
-
* Invalidate a single file's entry. Call this from the file watcher
|
|
84
|
-
* when `filePath`'s content has changed.
|
|
85
|
-
*/
|
|
86
|
-
invalidate(filePath: string): void;
|
|
87
|
-
/**
|
|
88
|
-
* Invalidate every file whose key matches a prefix. Useful for
|
|
89
|
-
* "anything under `src/pages/` changed" signals.
|
|
90
|
-
*/
|
|
91
|
-
invalidateMatching(predicate: (filePath: string) => boolean): number;
|
|
92
|
-
/** Clear all entries. */
|
|
93
|
-
clear(): void;
|
|
94
|
-
/** Current cache size. */
|
|
95
|
-
get size(): number;
|
|
96
|
-
/** Hit/miss counters for observability. */
|
|
97
|
-
stats(): {
|
|
98
|
-
hits: number;
|
|
99
|
-
misses: number;
|
|
100
|
-
size: number;
|
|
101
|
-
hitRate: number;
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Default shared cache. The React plugin owns one of these; tests can
|
|
106
|
-
* create their own.
|
|
107
|
-
*/
|
|
108
|
-
export declare const clientGraphBoundaryCache: ClientGraphBoundaryCache;
|
|
@@ -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
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module ClientGraphBoundaryPlugin
|
|
3
|
-
*
|
|
4
|
-
* This module defines the primary build plugin responsible for securing the Ecopages
|
|
5
|
-
* isomorphic compilation pipeline. It ensures that backend-only code, sensitive Node.js APIs,
|
|
6
|
-
* and massive server utilities do not accidentally leak into the browser bundle.
|
|
7
|
-
*
|
|
8
|
-
* It achieves this by intercepting all client module compilation passes and applying the
|
|
9
|
-
* `analyzeReachability` AST pass. If a forbidden import (e.g. `node:fs` or `*.server.ts`)
|
|
10
|
-
* is completely unreachable from the client component's `render` function, it is surgically
|
|
11
|
-
* pruned. If a forbidden import IS reachable, the build is intentionally failed to prevent
|
|
12
|
-
* runtime hydration crashes.
|
|
13
|
-
*
|
|
14
|
-
* Additionally, this plugin provides a build-time transform that statically resolves and
|
|
15
|
-
* inlines `fs.readFileSync(path.resolve(...))` calls to prevent server/client data mismatches.
|
|
16
|
-
*/
|
|
17
|
-
import type { EcoBuildPlugin } from '@ecopages/core/plugins/integration-plugin';
|
|
18
|
-
import { ClientGraphBoundaryCache } from './client-graph-boundary-cache.js';
|
|
19
|
-
/**
|
|
20
|
-
* Configuration options for the Client Graph Boundary build plugin.
|
|
21
|
-
*
|
|
22
|
-
* This plugin serves as the primary security layer between server-only logic and the client-side JavaScript bundle.
|
|
23
|
-
* It prevents Node.js built-ins (`node:fs`, `node:path`) and backend-exclusive dependencies (e.g. `pg`, `redis`)
|
|
24
|
-
* from accidentally leaking into the browser compilation step, which would cause immediate crashes.
|
|
25
|
-
*/
|
|
26
|
-
type ClientGraphBoundaryOptions = {
|
|
27
|
-
/** Absolute path to the current working directory, used as a root fallback for resolving inline file reads. */
|
|
28
|
-
absWorkingDir?: string;
|
|
29
|
-
/**
|
|
30
|
-
* Array of module specifiers that are explicitly whitelisted to be bundled in the client code.
|
|
31
|
-
* This is typically populated by parsing `modules: ["..."]` declarations in React/Lit components.
|
|
32
|
-
*/
|
|
33
|
-
declaredModules?: readonly string[];
|
|
34
|
-
/** Array of emergency escape-hatch specifiers that always bypass the boundary checks regardless of component declarations. */
|
|
35
|
-
alwaysAllowSpecifiers?: string[];
|
|
36
|
-
/**
|
|
37
|
-
* Persistent per-app cache for transform results. Owned by the React
|
|
38
|
-
* plugin for the app's lifetime; survives across HMR rebuilds. When
|
|
39
|
-
* omitted, transforms are still memoized inside the plugin for the
|
|
40
|
-
* duration of a single build but not across builds.
|
|
41
|
-
*/
|
|
42
|
-
cache?: ClientGraphBoundaryCache;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Instantiates the client graph boundary build plugin.
|
|
46
|
-
*
|
|
47
|
-
* @param options - Configuration options for the graph boundary.
|
|
48
|
-
* @returns The resulting `EcoBuildPlugin`.
|
|
49
|
-
*/
|
|
50
|
-
export declare function createClientGraphBoundaryPlugin(options?: ClientGraphBoundaryOptions): EcoBuildPlugin;
|
|
51
|
-
export {};
|