@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.
Files changed (142) hide show
  1. package/README.md +179 -7
  2. package/package.json +53 -28
  3. package/src/app/client-only.js +15 -0
  4. package/src/app/dynamic.js +9 -0
  5. package/src/app/dynamic.test.browser.js +31 -0
  6. package/src/bundling/bootstrap-package-paths.d.ts +5 -0
  7. package/src/bundling/bootstrap-package-paths.js +5 -0
  8. package/src/{services/react-bundle.service.d.ts → bundling/bundle.d.ts} +23 -8
  9. package/src/bundling/bundle.js +120 -0
  10. package/src/bundling/discover-layout-runtime-modules.d.ts +32 -0
  11. package/src/bundling/discover-layout-runtime-modules.js +185 -0
  12. package/src/bundling/runtime-alias-map.d.ts +13 -0
  13. package/src/bundling/runtime-alias-map.js +113 -0
  14. package/src/{services/react-runtime-bundle.service.d.ts → bundling/runtime-bundle.d.ts} +25 -4
  15. package/src/bundling/runtime-bundle.js +258 -0
  16. package/src/bundling/runtime-interop-plugin.js +34 -0
  17. package/src/bundling/runtime-mode.d.ts +9 -0
  18. package/src/bundling/runtime-mode.js +11 -0
  19. package/src/bundling/runtime-modules.d.ts +29 -0
  20. package/src/bundling/runtime-modules.js +49 -0
  21. package/src/client-graph/ast-transform.d.ts +18 -0
  22. package/src/client-graph/ast-transform.js +426 -0
  23. package/src/{utils/client-graph-boundary-cache.d.ts → client-graph/boundary-cache.d.ts} +23 -13
  24. package/src/client-graph/boundary-cache.js +182 -0
  25. package/src/{utils/client-graph-boundary-plugin.d.ts → client-graph/boundary-plugin.d.ts} +4 -13
  26. package/src/client-graph/boundary-plugin.js +149 -0
  27. package/src/client-graph/component-config-traversal.js +77 -0
  28. package/src/client-graph/declared-modules.js +69 -0
  29. package/src/client-graph/module-classification.d.ts +3 -0
  30. package/src/client-graph/module-classification.js +43 -0
  31. package/src/{utils → client-graph}/reachability-analyzer.d.ts +4 -12
  32. package/src/client-graph/reachability-analyzer.js +515 -0
  33. package/src/client-graph/specifier-classification.d.ts +75 -0
  34. package/src/client-graph/specifier-classification.js +214 -0
  35. package/src/contracts/router-adapter.js +6 -0
  36. package/src/dev-transform/react-dev-transform-contributor.d.ts +17 -0
  37. package/src/dev-transform/react-dev-transform-contributor.js +22 -0
  38. package/src/hmr/hmr-scripts.js +44 -0
  39. package/src/hmr/hmr-strategy.d.ts +74 -0
  40. package/src/hmr/hmr-strategy.js +351 -0
  41. package/src/{services/react-hmr-page-metadata-cache.d.ts → hmr/page-metadata-cache.d.ts} +5 -1
  42. package/src/hmr/page-metadata-cache.js +44 -0
  43. package/src/hmr/react-hmr-dev-transform-plugins.d.ts +23 -0
  44. package/src/hmr/react-hmr-dev-transform-plugins.js +20 -0
  45. package/src/hydration/assert-no-bare-ecopages-imports.d.ts +4 -0
  46. package/src/hydration/assert-no-bare-ecopages-imports.js +7 -0
  47. package/src/hydration/bootstrap-imports.d.ts +25 -0
  48. package/src/hydration/bootstrap-imports.js +33 -0
  49. package/src/hydration/hydration-asset.d.ts +84 -0
  50. package/src/hydration/hydration-asset.js +227 -0
  51. package/src/hydration/hydration-scripts.d.ts +104 -0
  52. package/src/hydration/hydration-scripts.js +483 -0
  53. package/src/hydration/hydration-scripts.test.browser.js +199 -0
  54. package/src/hydration/page-data-manifest.d.ts +58 -0
  55. package/src/hydration/page-data-manifest.js +97 -0
  56. package/src/hydration/page-data-reader.d.ts +31 -0
  57. package/src/hydration/page-data-reader.js +77 -0
  58. package/src/hydration/page-payload.d.ts +67 -0
  59. package/src/hydration/page-payload.js +106 -0
  60. package/src/hydration/serialize-page-data-script.d.ts +27 -0
  61. package/src/hydration/serialize-page-data-script.js +30 -0
  62. package/src/{services/react-mdx-config-dependency.service.d.ts → mdx/mdx-config-dependency.d.ts} +6 -6
  63. package/src/mdx/mdx-config-dependency.js +110 -0
  64. package/src/mdx/mdx-loader-plugin.d.ts +2 -0
  65. package/src/mdx/mdx-loader-plugin.js +8 -0
  66. package/src/page/page-module.d.ts +46 -0
  67. package/src/page/page-module.js +74 -0
  68. package/src/plugin/react.constants.js +1 -0
  69. package/src/{react.plugin.d.ts → plugin/react.plugin.d.ts} +9 -3
  70. package/src/plugin/react.plugin.js +241 -0
  71. package/src/plugin/react.types.d.ts +156 -0
  72. package/src/plugin/react.types.js +1 -0
  73. package/src/render/component-ownership.d.ts +49 -0
  74. package/src/render/component-ownership.js +46 -0
  75. package/src/render/component-ssr.d.ts +113 -0
  76. package/src/render/component-ssr.js +180 -0
  77. package/src/render/eco-embed.js +9 -0
  78. package/src/render/errors.d.ts +16 -0
  79. package/src/render/errors.js +23 -0
  80. package/src/render/html-boundary.js +59 -0
  81. package/src/render/layout-compose.d.ts +66 -0
  82. package/src/render/layout-compose.js +134 -0
  83. package/src/render/react-renderer.d.ts +138 -0
  84. package/src/render/react-renderer.js +448 -0
  85. package/src/render/react-runtime.d.ts +13 -0
  86. package/src/render/react-runtime.js +26 -0
  87. package/src/render/unified-layout-composition.d.ts +53 -0
  88. package/src/render/unified-layout-composition.js +78 -0
  89. package/src/runtime/use-sync-external-store-with-selector.js +52 -54
  90. package/src/eco-embed.js +0 -11
  91. package/src/react-hmr-strategy.d.ts +0 -230
  92. package/src/react-hmr-strategy.js +0 -657
  93. package/src/react-renderer.d.ts +0 -233
  94. package/src/react-renderer.js +0 -622
  95. package/src/react.constants.js +0 -4
  96. package/src/react.plugin.js +0 -209
  97. package/src/react.types.d.ts +0 -88
  98. package/src/react.types.js +0 -0
  99. package/src/router-adapter.js +0 -0
  100. package/src/services/pages-index.d.ts +0 -64
  101. package/src/services/pages-index.js +0 -73
  102. package/src/services/react-bundle.service.js +0 -86
  103. package/src/services/react-hmr-page-metadata-cache.js +0 -35
  104. package/src/services/react-hydration-asset.service.d.ts +0 -84
  105. package/src/services/react-hydration-asset.service.js +0 -217
  106. package/src/services/react-mdx-config-dependency.service.js +0 -122
  107. package/src/services/react-page-module.service.d.ts +0 -88
  108. package/src/services/react-page-module.service.js +0 -166
  109. package/src/services/react-page-payload.service.d.ts +0 -46
  110. package/src/services/react-page-payload.service.js +0 -67
  111. package/src/services/react-runtime-bundle.service.js +0 -192
  112. package/src/utils/client-graph-boundary-cache.js +0 -116
  113. package/src/utils/client-graph-boundary-plugin.js +0 -552
  114. package/src/utils/client-only.js +0 -19
  115. package/src/utils/component-config-traversal.js +0 -54
  116. package/src/utils/declared-modules.js +0 -47
  117. package/src/utils/dynamic.js +0 -12
  118. package/src/utils/dynamic.test.browser.js +0 -33
  119. package/src/utils/hmr-scripts.js +0 -31
  120. package/src/utils/html-boundary.js +0 -55
  121. package/src/utils/hydration-scripts.d.ts +0 -92
  122. package/src/utils/hydration-scripts.js +0 -358
  123. package/src/utils/hydration-scripts.test.browser.js +0 -198
  124. package/src/utils/reachability-analyzer.js +0 -339
  125. package/src/utils/react-dom-runtime-interop-plugin.js +0 -38
  126. package/src/utils/react-mdx-loader-plugin.d.ts +0 -3
  127. package/src/utils/react-mdx-loader-plugin.js +0 -45
  128. package/src/utils/react-runtime-alias-map.d.ts +0 -8
  129. package/src/utils/react-runtime-alias-map.js +0 -90
  130. /package/src/{utils → app}/client-only.d.ts +0 -0
  131. /package/src/{utils → app}/dynamic.d.ts +0 -0
  132. /package/src/{utils → app}/dynamic.test.browser.d.ts +0 -0
  133. /package/src/{utils/react-dom-runtime-interop-plugin.d.ts → bundling/runtime-interop-plugin.d.ts} +0 -0
  134. /package/src/{utils → client-graph}/component-config-traversal.d.ts +0 -0
  135. /package/src/{utils → client-graph}/declared-modules.d.ts +0 -0
  136. /package/src/{declarations.d.ts → contracts/declarations.d.ts} +0 -0
  137. /package/src/{router-adapter.d.ts → contracts/router-adapter.d.ts} +0 -0
  138. /package/src/{utils → hmr}/hmr-scripts.d.ts +0 -0
  139. /package/src/{utils → hydration}/hydration-scripts.test.browser.d.ts +0 -0
  140. /package/src/{react.constants.d.ts → plugin/react.constants.d.ts} +0 -0
  141. /package/src/{eco-embed.d.ts → render/eco-embed.d.ts} +0 -0
  142. /package/src/{utils → render}/html-boundary.d.ts +0 -0
@@ -1,209 +0,0 @@
1
- import {
2
- IntegrationPlugin
3
- } from "@ecopages/core/plugins/integration-plugin";
4
- import { Logger } from "@ecopages/logger";
5
- import path from "node:path";
6
- import { REACT_PLUGIN_NAME } from "./react.constants.js";
7
- import { ReactRenderer } from "./react-renderer.js";
8
- import { ReactHmrStrategy } from "./react-hmr-strategy.js";
9
- import { ReactRuntimeBundleService } from "./services/react-runtime-bundle.service.js";
10
- import { ReactHmrPageMetadataCache } from "./services/react-hmr-page-metadata-cache.js";
11
- import { createReactMdxLoaderPlugin } from "./utils/react-mdx-loader-plugin.js";
12
- import { ClientGraphBoundaryCache } from "./utils/client-graph-boundary-cache.js";
13
- const appLogger = new Logger("[ReactPlugin]");
14
- const PLUGIN_NAME = REACT_PLUGIN_NAME;
15
- const mergePluginLists = (...lists) => {
16
- const merged = lists.flatMap((list) => list ? [...list] : []);
17
- return merged.length > 0 ? merged : void 0;
18
- };
19
- const appendMdxExtensions = (target, mdxExtensions) => {
20
- for (const extension of mdxExtensions) {
21
- if (!target.includes(extension)) {
22
- target.push(extension);
23
- }
24
- }
25
- };
26
- const resolveReactMdxCompilerOptions = (mdxOptions) => {
27
- const { compilerOptions, remarkPlugins, rehypePlugins, recmaPlugins } = mdxOptions;
28
- const resolved = {
29
- ...compilerOptions,
30
- jsxImportSource: "react",
31
- jsxRuntime: "automatic",
32
- development: process.env.NODE_ENV === "development"
33
- };
34
- const mergedRemark = mergePluginLists(compilerOptions?.remarkPlugins, remarkPlugins);
35
- const mergedRehype = mergePluginLists(compilerOptions?.rehypePlugins, rehypePlugins);
36
- const mergedRecma = mergePluginLists(compilerOptions?.recmaPlugins, recmaPlugins);
37
- if (mergedRemark) resolved.remarkPlugins = mergedRemark;
38
- if (mergedRehype) resolved.rehypePlugins = mergedRehype;
39
- if (mergedRecma) resolved.recmaPlugins = mergedRecma;
40
- return resolved;
41
- };
42
- const resolveReactPluginOptions = (options) => {
43
- const { extensions: userExtensions, router, mdx, explicitGraph, dependencies, ...baseConfig } = options ?? {};
44
- const extensions = [...userExtensions ?? [".tsx"]];
45
- const mdxEnabled = mdx?.enabled ?? false;
46
- const mdxExtensions = mdx?.extensions ?? [".mdx"];
47
- if (mdxEnabled) {
48
- appendMdxExtensions(extensions, mdxExtensions);
49
- } else if (mdx?.extensions?.length) {
50
- appLogger.warn(
51
- "MDX extensions provided but MDX is disabled. MDX files will not be processed. Set mdx.enabled to true to enable MDX support."
52
- );
53
- }
54
- const rendererConfig = {
55
- routerAdapter: router,
56
- mdxCompilerOptions: mdxEnabled && mdx ? resolveReactMdxCompilerOptions(mdx) : void 0,
57
- mdxExtensions,
58
- hmrPageMetadataCache: new ReactHmrPageMetadataCache(),
59
- explicitGraphEnabled: explicitGraph ?? false
60
- };
61
- return {
62
- ...baseConfig,
63
- extensions,
64
- integrationDependencies: dependencies,
65
- rendererConfig
66
- };
67
- };
68
- class ReactPlugin extends IntegrationPlugin {
69
- renderer = ReactRenderer;
70
- routerAdapter;
71
- mdxEnabled;
72
- mdxCompilerOptions;
73
- mdxExtensions;
74
- mdxLoaderPlugin;
75
- runtimeBundleService;
76
- hmrPageMetadataCache;
77
- clientGraphBoundaryCache;
78
- runtimeDependenciesInitialized = false;
79
- /**
80
- * Indicates whether React explicit graph mode is enabled for renderer/HMR behavior.
81
- */
82
- explicitGraphEnabled;
83
- rendererConfig;
84
- constructor(options) {
85
- const config = resolveReactPluginOptions(options);
86
- const { extensions, rendererConfig, integrationDependencies, ...baseConfig } = config;
87
- super({
88
- name: PLUGIN_NAME,
89
- extensions,
90
- jsxImportSource: "react",
91
- integrationDependencies,
92
- ...baseConfig
93
- });
94
- this.routerAdapter = rendererConfig.routerAdapter;
95
- this.mdxCompilerOptions = rendererConfig.mdxCompilerOptions;
96
- this.mdxEnabled = Boolean(rendererConfig.mdxCompilerOptions);
97
- this.mdxExtensions = rendererConfig.mdxExtensions ?? [".mdx"];
98
- this.hmrPageMetadataCache = rendererConfig.hmrPageMetadataCache ?? new ReactHmrPageMetadataCache();
99
- this.clientGraphBoundaryCache = new ClientGraphBoundaryCache();
100
- this.explicitGraphEnabled = rendererConfig.explicitGraphEnabled ?? false;
101
- this.rendererConfig = {
102
- ...rendererConfig,
103
- mdxExtensions: this.mdxExtensions,
104
- hmrPageMetadataCache: this.hmrPageMetadataCache,
105
- explicitGraphEnabled: this.explicitGraphEnabled
106
- };
107
- if (this.mdxEnabled) {
108
- appLogger.debug("MDX mode enabled with React jsx runtime");
109
- }
110
- this.runtimeBundleService = new ReactRuntimeBundleService({
111
- routerAdapter: this.routerAdapter
112
- });
113
- }
114
- /**
115
- * Creates a React renderer with instance-owned runtime configuration.
116
- *
117
- * React renderers depend on plugin-owned router, MDX, and HMR metadata state.
118
- * Keeping that state on the instance avoids cross-plugin static mutation while
119
- * preserving the same runtime services the base initializer wires up.
120
- */
121
- initializeRenderer(options) {
122
- const renderer = new this.renderer({
123
- ...this.createRendererOptions(options),
124
- reactConfig: this.rendererConfig
125
- });
126
- return this.attachRendererRuntimeServices(renderer);
127
- }
128
- ensureRuntimeDependencies() {
129
- if (this.runtimeDependenciesInitialized) {
130
- return;
131
- }
132
- this.runtimeBundleService.setRootDir(this.appConfig?.rootDir);
133
- this.runtimeBundleService.setWorkDir(
134
- this.appConfig?.absolutePaths?.workDir ?? (this.appConfig?.rootDir ? path.join(this.appConfig.rootDir, this.appConfig.workDir ?? ".eco") : void 0)
135
- );
136
- this.integrationDependencies.unshift(...this.runtimeBundleService.getDependencies());
137
- this.runtimeDependenciesInitialized = true;
138
- }
139
- get plugins() {
140
- if (this.mdxLoaderPlugin) {
141
- return [this.mdxLoaderPlugin];
142
- }
143
- return [];
144
- }
145
- get browserRuntimeManifest() {
146
- this.ensureRuntimeDependencies();
147
- return this.runtimeBundleService.getRuntimeManifest();
148
- }
149
- /**
150
- * Ensures the optional React MDX loader exists before either config-time
151
- * manifest sealing or runtime setup needs it.
152
- */
153
- async ensureMdxLoaderPlugin() {
154
- if (!this.mdxEnabled || !this.mdxCompilerOptions || this.mdxLoaderPlugin) {
155
- return;
156
- }
157
- this.mdxLoaderPlugin = createReactMdxLoaderPlugin(this.mdxCompilerOptions);
158
- }
159
- /**
160
- * Prepares React's build-facing loader contributions before config build seals
161
- * the app manifest.
162
- */
163
- async prepareBuildContributions() {
164
- this.ensureRuntimeDependencies();
165
- await this.ensureMdxLoaderPlugin();
166
- }
167
- /**
168
- * Performs runtime-only React setup after build contributions are already
169
- * materialized.
170
- */
171
- async setup() {
172
- this.ensureRuntimeDependencies();
173
- await this.ensureMdxLoaderPlugin();
174
- await super.setup();
175
- }
176
- /**
177
- * Provides React-specific HMR strategy with Fast Refresh support.
178
- *
179
- * The strategy shares a React-only page metadata cache with the renderer so
180
- * save-time rebuilds can reuse declared-module analysis without expanding the
181
- * core HMR interfaces.
182
- *
183
- * @returns ReactHmrStrategy instance for handling React component updates
184
- */
185
- getHmrStrategy() {
186
- if (!this.hmrManager || !this.appConfig) {
187
- return void 0;
188
- }
189
- const context = this.hmrManager.getDefaultContext();
190
- return new ReactHmrStrategy({
191
- context,
192
- pageMetadataCache: this.hmrPageMetadataCache,
193
- runtimeManifest: this.runtimeBundleService.getRuntimeManifest("development"),
194
- mdxCompilerOptions: this.mdxCompilerOptions,
195
- ownedTemplateExtensions: this.extensions,
196
- allTemplateExtensions: this.appConfig.templatesExt,
197
- explicitGraphEnabled: this.explicitGraphEnabled,
198
- clientGraphBoundaryCache: this.clientGraphBoundaryCache
199
- });
200
- }
201
- }
202
- function reactPlugin(options) {
203
- return new ReactPlugin(options);
204
- }
205
- export {
206
- PLUGIN_NAME,
207
- ReactPlugin,
208
- reactPlugin
209
- };
@@ -1,88 +0,0 @@
1
- import type { AssetDefinition } from '@ecopages/core/services/asset-processing-service';
2
- import type { CompileOptions } from '@mdx-js/mdx';
3
- import type { ReactRouterAdapter } from './router-adapter.js';
4
- import type { ReactHmrPageMetadataCache } from './services/react-hmr-page-metadata-cache.js';
5
- /**
6
- * MDX configuration options for the React plugin.
7
- */
8
- export type ReactMdxOptions = {
9
- /**
10
- * Whether to enable MDX support.
11
- * @default false
12
- */
13
- enabled: boolean;
14
- /**
15
- * Compiler options for MDX.
16
- * @default undefined
17
- */
18
- compilerOptions?: Omit<CompileOptions, 'jsxImportSource' | 'jsxRuntime'>;
19
- /**
20
- * Remark plugins.
21
- * @default undefined
22
- */
23
- remarkPlugins?: CompileOptions['remarkPlugins'];
24
- /**
25
- * Rehype plugins.
26
- * @default undefined
27
- */
28
- rehypePlugins?: CompileOptions['rehypePlugins'];
29
- /**
30
- * Recma plugins.
31
- * @default undefined
32
- */
33
- recmaPlugins?: CompileOptions['recmaPlugins'];
34
- /**
35
- * Custom extensions to be treated as MDX files.
36
- * @default ['.mdx']
37
- */
38
- extensions?: string[];
39
- };
40
- /**
41
- * Options for the React plugin.
42
- */
43
- export type ReactPluginOptions = {
44
- extensions?: string[];
45
- dependencies?: AssetDefinition[];
46
- /**
47
- * Enables explicit client graph mode for React page entries.
48
- *
49
- * When enabled, React page-entry bundling relies on explicit dependency declarations
50
- * and skips AST-based `middleware`/`requires` stripping in the React path.
51
- * @default false
52
- */
53
- explicitGraph?: boolean;
54
- /**
55
- * Router adapter for SPA navigation.
56
- * When provided, pages with layouts will be wrapped in the router for client-side navigation.
57
- * @example
58
- * ```ts
59
- * import { ecoRouter } from '@ecopages/react-router';
60
- * reactPlugin({ router: ecoRouter() })
61
- * ```
62
- */
63
- router?: ReactRouterAdapter;
64
- /**
65
- * MDX configuration for handling .mdx files within the React plugin.
66
- * When enabled, MDX files are treated as React pages with full router support.
67
- * @example
68
- * ```ts
69
- * reactPlugin({
70
- * router: ecoRouter(),
71
- * mdx: {
72
- * enabled: true,
73
- * extensions: ['.mdx', '.md'],
74
- * remarkPlugins: [remarkGfm],
75
- * rehypePlugins: [[rehypePrettyCode, { theme: '...' }]],
76
- * }
77
- * })
78
- * ```
79
- */
80
- mdx?: ReactMdxOptions;
81
- };
82
- export type ReactRendererConfig = {
83
- routerAdapter?: ReactRouterAdapter;
84
- mdxCompilerOptions?: CompileOptions;
85
- mdxExtensions?: string[];
86
- hmrPageMetadataCache?: ReactHmrPageMetadataCache;
87
- explicitGraphEnabled?: boolean;
88
- };
File without changes
File without changes
@@ -1,64 +0,0 @@
1
- /**
2
- * Per-app index of React-owned page entrypoints.
3
- *
4
- * @remarks
5
- * The HMR strategy previously called `fileSystem.glob` on every
6
- * layout change. For apps with many pages this is wasteful: O(pages)
7
- * on every HMR event, and the result rarely changes between HMR
8
- * rebuilds.
9
- *
10
- * `PagesIndex` maintains a `Set` of owned page entrypoint paths. The
11
- * initial population is a single glob; subsequent mutations go through
12
- * `add` / `remove` (called by the HMR strategy when it observes a
13
- * file create/delete under `pagesDir`). The strategy reads via
14
- * `list()` for an O(1) snapshot of the current set.
15
- *
16
- * Phase 1 ships the class and the `list()` consumer. Watcher-driven
17
- * `add` / `remove` integration lands in a follow-up — for now the
18
- * strategy calls `refresh()` lazily, which is equivalent to the old
19
- * glob behavior but with a stable API for the future incremental
20
- * path.
21
- */
22
- export type PagesIndexOptions = {
23
- pagesDir: string;
24
- extensions?: string[];
25
- /**
26
- * Optional predicate to filter out non-page entrypoints (e.g.
27
- * test fixtures, generated files). Defaults to including every
28
- * file matching an extension.
29
- */
30
- isPageEntrypoint?: (absolutePath: string) => boolean;
31
- };
32
- export declare class PagesIndex {
33
- private readonly pagesDir;
34
- private readonly extensions;
35
- private readonly isPageEntrypoint;
36
- private readonly pages;
37
- private lastRefreshAt;
38
- constructor(options: PagesIndexOptions);
39
- /**
40
- * Rescan the pages directory and rebuild the index.
41
- *
42
- * Cheap to call multiple times in sequence (just a glob). The
43
- * real value of `PagesIndex` is the `add` / `remove` path that
44
- * callers can wire to the file watcher; for now this is the
45
- * fallback used on layout changes.
46
- */
47
- refresh(): Promise<void>;
48
- /**
49
- * Add a single entrypoint. Idempotent.
50
- */
51
- add(absolutePath: string): void;
52
- /**
53
- * Remove a single entrypoint. Idempotent.
54
- */
55
- remove(absolutePath: string): void;
56
- /** True if the index contains `absolutePath`. */
57
- has(absolutePath: string): boolean;
58
- /** Snapshot of the current set, sorted by absolute path. */
59
- list(): string[];
60
- /** Number of indexed entrypoints. */
61
- get size(): number;
62
- /** Last refresh timestamp (ms since epoch). */
63
- get refreshedAt(): number;
64
- }
@@ -1,73 +0,0 @@
1
- import path from "node:path";
2
- import { fileSystem } from "@ecopages/file-system";
3
- const DEFAULT_EXTENSIONS = [".tsx", ".kita.tsx", ".lit.tsx", ".eco.tsx", ".mdx", ".react.tsx"];
4
- class PagesIndex {
5
- pagesDir;
6
- extensions;
7
- isPageEntrypoint;
8
- pages = /* @__PURE__ */ new Set();
9
- lastRefreshAt = 0;
10
- constructor(options) {
11
- this.pagesDir = options.pagesDir;
12
- this.extensions = options.extensions ?? DEFAULT_EXTENSIONS;
13
- this.isPageEntrypoint = options.isPageEntrypoint ?? (() => true);
14
- }
15
- /**
16
- * Rescan the pages directory and rebuild the index.
17
- *
18
- * Cheap to call multiple times in sequence (just a glob). The
19
- * real value of `PagesIndex` is the `add` / `remove` path that
20
- * callers can wire to the file watcher; for now this is the
21
- * fallback used on layout changes.
22
- */
23
- async refresh() {
24
- const files = await fileSystem.glob(
25
- this.extensions.map((ext) => `**/*${ext}`),
26
- {
27
- cwd: this.pagesDir
28
- }
29
- );
30
- const next = /* @__PURE__ */ new Set();
31
- for (const file of files) {
32
- const absolutePath = path.join(this.pagesDir, file);
33
- if (!this.isPageEntrypoint(absolutePath)) continue;
34
- if (file.includes(".ecopages-node.")) continue;
35
- next.add(absolutePath);
36
- }
37
- this.pages.clear();
38
- for (const p of next) this.pages.add(p);
39
- this.lastRefreshAt = Date.now();
40
- }
41
- /**
42
- * Add a single entrypoint. Idempotent.
43
- */
44
- add(absolutePath) {
45
- if (!this.isPageEntrypoint(absolutePath)) return;
46
- this.pages.add(absolutePath);
47
- }
48
- /**
49
- * Remove a single entrypoint. Idempotent.
50
- */
51
- remove(absolutePath) {
52
- this.pages.delete(absolutePath);
53
- }
54
- /** True if the index contains `absolutePath`. */
55
- has(absolutePath) {
56
- return this.pages.has(absolutePath);
57
- }
58
- /** Snapshot of the current set, sorted by absolute path. */
59
- list() {
60
- return Array.from(this.pages).sort();
61
- }
62
- /** Number of indexed entrypoints. */
63
- get size() {
64
- return this.pages.size;
65
- }
66
- /** Last refresh timestamp (ms since epoch). */
67
- get refreshedAt() {
68
- return this.lastRefreshAt;
69
- }
70
- }
71
- export {
72
- PagesIndex
73
- };
@@ -1,86 +0,0 @@
1
- import { createClientGraphBoundaryPlugin } from "../utils/client-graph-boundary-plugin.js";
2
- import {
3
- getReactClientGraphAllowSpecifiers,
4
- getReactRuntimeExternalSpecifiers
5
- } from "../utils/react-runtime-alias-map.js";
6
- import { createBrowserRuntimePlugin } from "@ecopages/core/build/browser-runtime-plugin";
7
- import { createForeignJsxOverridePlugin } from "@ecopages/core/plugins/foreign-jsx-override-plugin";
8
- import { ReactRuntimeBundleService } from "./react-runtime-bundle.service.js";
9
- import { createReactMdxLoaderPlugin } from "../utils/react-mdx-loader-plugin.js";
10
- class ReactBundleService {
11
- runtimeBundleService;
12
- config;
13
- constructor(config) {
14
- this.config = config;
15
- this.runtimeBundleService = new ReactRuntimeBundleService({
16
- rootDir: config.rootDir,
17
- routerAdapter: config.routerAdapter
18
- });
19
- }
20
- /**
21
- * Returns resolved runtime import paths for the React runtime.
22
- */
23
- getRuntimeImports() {
24
- return this.runtimeBundleService.getRuntimeImports();
25
- }
26
- /**
27
- * Creates bundle options for a page or component entry.
28
- *
29
- * @remarks
30
- * React derives runtime specifier mappings from the core browser runtime manifest
31
- * so ESM imports resolve to concrete runtime asset URLs during module loading.
32
- *
33
- * @param componentName - Generated unique component name for output naming
34
- * @param isMdx - Whether the source file is an MDX file
35
- * @param declaredModules - Explicitly declared browser module specifiers
36
- * @returns Bundle options object for the build adapter
37
- */
38
- async createBundleOptions(componentName, isMdx, declaredModules, bundleOptions = {}) {
39
- const runtimeImports = this.getRuntimeImports();
40
- const options = {
41
- mainFields: ["module", "browser", "main"],
42
- naming: `${componentName}.[ext]`,
43
- ...import.meta.env?.NODE_ENV === "production" && {
44
- minify: true,
45
- treeshaking: true
46
- },
47
- ...bundleOptions.splitting === void 0 ? {} : { splitting: bundleOptions.splitting }
48
- };
49
- if (!bundleOptions.includeRuntime) {
50
- const reactRuntimeSpecifiers = new Set(getReactRuntimeExternalSpecifiers());
51
- options.external = [
52
- ...Object.values(runtimeImports).filter(
53
- (specifier) => Boolean(specifier) && !reactRuntimeSpecifiers.has(
54
- specifier
55
- )
56
- )
57
- ];
58
- }
59
- const graphBoundaryPlugin = createClientGraphBoundaryPlugin({
60
- absWorkingDir: this.config.rootDir,
61
- declaredModules,
62
- alwaysAllowSpecifiers: getReactClientGraphAllowSpecifiers([], this.config.routerAdapter)
63
- });
64
- const foreignJsxOverridePlugin = createForeignJsxOverridePlugin({
65
- name: "react-renderer-foreign-jsx-override",
66
- hostJsxImportSource: this.config.jsxImportSource ?? "react",
67
- foreignExtensions: this.config.nonReactExtensions ?? []
68
- });
69
- const runtimeManifest = this.runtimeBundleService.getRuntimeManifest();
70
- const runtimeRewritePlugin = createBrowserRuntimePlugin({
71
- name: "react-renderer-runtime-import-rewrite",
72
- manifest: runtimeManifest
73
- });
74
- const runtimePlugins = bundleOptions.includeRuntime ? [] : [runtimeRewritePlugin].filter((plugin) => plugin !== null);
75
- if (isMdx && this.config.mdxCompilerOptions) {
76
- const mdxPlugin = createReactMdxLoaderPlugin(this.config.mdxCompilerOptions);
77
- options.plugins = [foreignJsxOverridePlugin, graphBoundaryPlugin, ...runtimePlugins, mdxPlugin];
78
- } else {
79
- options.plugins = [foreignJsxOverridePlugin, graphBoundaryPlugin, ...runtimePlugins];
80
- }
81
- return options;
82
- }
83
- }
84
- export {
85
- ReactBundleService
86
- };
@@ -1,35 +0,0 @@
1
- import path from "node:path";
2
- class ReactHmrPageMetadataCache {
3
- declaredModulesByEntrypoint = /* @__PURE__ */ new Map();
4
- ownedEntrypoints = /* @__PURE__ */ new Set();
5
- /**
6
- * Marks an HMR entrypoint as React-owned.
7
- */
8
- markOwnedEntrypoint(entrypointPath) {
9
- this.ownedEntrypoints.add(path.resolve(entrypointPath));
10
- }
11
- /**
12
- * Stores the declared browser modules for a page entrypoint.
13
- */
14
- setDeclaredModules(entrypointPath, declaredModules) {
15
- const resolvedEntrypointPath = path.resolve(entrypointPath);
16
- this.markOwnedEntrypoint(resolvedEntrypointPath);
17
- this.declaredModulesByEntrypoint.set(resolvedEntrypointPath, [...declaredModules]);
18
- }
19
- /**
20
- * Returns the last known declared browser modules for a page entrypoint.
21
- */
22
- getDeclaredModules(entrypointPath) {
23
- const declaredModules = this.declaredModulesByEntrypoint.get(path.resolve(entrypointPath));
24
- return declaredModules ? [...declaredModules] : void 0;
25
- }
26
- /**
27
- * Returns true when the watched entrypoint is owned by the React integration.
28
- */
29
- ownsEntrypoint(entrypointPath) {
30
- return this.ownedEntrypoints.has(path.resolve(entrypointPath));
31
- }
32
- }
33
- export {
34
- ReactHmrPageMetadataCache
35
- };
@@ -1,84 +0,0 @@
1
- /**
2
- * Hydration asset creation service for React integration.
3
- *
4
- * Builds the asset definitions required for client-side React rendering — both at
5
- * the page level and the component island level.
6
- *
7
- * @module
8
- */
9
- import type { EcoComponentConfig } from '@ecopages/core';
10
- import { type AssetDefinition, type ProcessedAsset } from '@ecopages/core/services/asset-processing-service';
11
- import type { AssetProcessingService } from '@ecopages/core/services/asset-processing-service';
12
- import type { ReactBundleService } from './react-bundle.service.js';
13
- import type { ReactHmrPageMetadataCache } from './react-hmr-page-metadata-cache.js';
14
- import type { ReactRouterAdapter } from '../router-adapter.js';
15
- /**
16
- * Configuration for the ReactHydrationAssetService.
17
- */
18
- export interface ReactHydrationAssetServiceConfig {
19
- srcDir: string;
20
- routerAdapter?: ReactRouterAdapter;
21
- assetProcessingService: AssetProcessingService;
22
- bundleService: ReactBundleService;
23
- hmrPageMetadataCache?: ReactHmrPageMetadataCache;
24
- }
25
- export declare function getReactIslandComponentKey(componentFile: string, config?: EcoComponentConfig): string;
26
- /**
27
- * Manages the creation of client-side hydration assets for React pages and component islands.
28
- */
29
- export declare class ReactHydrationAssetService {
30
- private readonly config;
31
- private static readonly ROUTER_PAGE_GROUPED_BUNDLE_ID;
32
- constructor(config: ReactHydrationAssetServiceConfig);
33
- private getIslandBundleName;
34
- private getIslandHydrationName;
35
- private getRouterPageGroupedEntryName;
36
- /**
37
- * Resolves the browser import path used for a React-owned page or island module.
38
- * Uses HMR manager for development or constructs static path for production.
39
- *
40
- * @param pagePath - Absolute path to the page source file
41
- * @param assetName - Generated asset name
42
- * @returns The resolved browser import path for the module
43
- */
44
- resolveAssetImportPath(pagePath: string, assetName: string): Promise<string>;
45
- /**
46
- * Creates the page-owned route entry asset for hydration and client navigation.
47
- *
48
- * @param pagePath - Absolute path to the page source file
49
- * @param componentName - Generated unique component name
50
- * @param importPath - Resolved browser import path used by development HMR
51
- * @param bundleOptions - Bundle configuration options
52
- * @param isDevelopment - Whether running in development mode with HMR
53
- * @param isMdx - Whether the source file is an MDX file
54
- * @returns One page-owned asset definition for processing
55
- */
56
- createPageDependencies(pagePath: string, componentName: string, importPath: string, pageModuleUrlExpression: string, bundleOptions: Record<string, unknown>, isDevelopment: boolean, useBrowserRuntimeImports: boolean, isMdx: boolean): AssetDefinition[];
57
- /**
58
- * Builds client-side assets for a React component island.
59
- *
60
- * Includes the bundled component entry and a shared hydration bootstrap script.
61
- *
62
- * @param componentFile - Absolute path to the component source file
63
- * @param config - Optional component config with `__eco` metadata
64
- * @returns Processed assets ready for injection
65
- */
66
- buildComponentRenderAssets(componentFile: string, config?: EcoComponentConfig): Promise<ProcessedAsset[]>;
67
- /**
68
- * Creates the Page Browser Graph dependency declarations for a React page.
69
- *
70
- * @param pagePath - Absolute file path of the page
71
- * @param isMdx - Whether the page is an MDX file
72
- * @param declaredModules - Explicitly declared browser module specifiers
73
- * @returns Declarative assets for core-owned processing
74
- */
75
- createPageBrowserGraphDependencies(pagePath: string, isMdx: boolean, declaredModules: string[]): Promise<AssetDefinition[]>;
76
- /**
77
- * Builds the Page Browser Graph assets for a React page.
78
- *
79
- * @remarks
80
- * Kept as a compatibility wrapper while callers migrate to core-owned page
81
- * graph assembly.
82
- */
83
- buildPageBrowserGraphAssets(pagePath: string, isMdx: boolean, declaredModules: string[]): Promise<ProcessedAsset[]>;
84
- }