@ecopages/react 0.6.0 → 0.7.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 (95) hide show
  1. package/README.md +50 -87
  2. package/package.json +32 -14
  3. package/src/bundling/bootstrap-package-paths.d.ts +13 -1
  4. package/src/bundling/bootstrap-package-paths.js +25 -3
  5. package/src/bundling/bundle.d.ts +8 -36
  6. package/src/bundling/bundle.js +42 -73
  7. package/src/client-graph/ast-transform-eco-page.d.ts +10 -6
  8. package/src/client-graph/ast-transform-eco-page.js +56 -35
  9. package/src/client-graph/ast-transform-import-edits.d.ts +10 -2
  10. package/src/client-graph/ast-transform-import-edits.js +36 -6
  11. package/src/client-graph/ast-transform-stripped-imports.d.ts +37 -0
  12. package/src/client-graph/ast-transform-stripped-imports.js +191 -0
  13. package/src/client-graph/ast-transform-walk-imports.d.ts +4 -0
  14. package/src/client-graph/ast-transform-walk-imports.js +15 -1
  15. package/src/client-graph/ast-transform.d.ts +12 -3
  16. package/src/client-graph/ast-transform.js +41 -56
  17. package/src/client-graph/boundary-plugin-read-file-inline.d.ts +3 -0
  18. package/src/client-graph/boundary-plugin-read-file-inline.js +14 -10
  19. package/src/client-graph/boundary-plugin-transform.d.ts +5 -4
  20. package/src/client-graph/boundary-plugin-transform.js +6 -13
  21. package/src/client-graph/boundary-plugin.d.ts +47 -1
  22. package/src/client-graph/boundary-plugin.js +267 -53
  23. package/src/client-graph/foreign-boundary-rewrite.d.ts +31 -0
  24. package/src/client-graph/foreign-boundary-rewrite.js +360 -0
  25. package/src/client-graph/foreign-jsx-reach.d.ts +25 -0
  26. package/src/client-graph/foreign-jsx-reach.js +68 -0
  27. package/src/client-graph/module-classification.js +3 -10
  28. package/src/client-graph/reachability-traverse.js +35 -105
  29. package/src/client-graph/requested-exports-plan.d.ts +62 -0
  30. package/src/client-graph/requested-exports-plan.js +125 -0
  31. package/src/client-graph/scope-walk.d.ts +37 -0
  32. package/src/client-graph/scope-walk.js +407 -0
  33. package/src/client-graph/specifier-classification.d.ts +2 -1
  34. package/src/client-graph/specifier-classification.js +9 -7
  35. package/src/contracts/router-adapter.d.ts +9 -24
  36. package/src/dev-transform/react-dev-transform-contributor.d.ts +4 -4
  37. package/src/dev-transform/react-dev-transform-contributor.js +6 -7
  38. package/src/hmr/hmr-strategy-process.d.ts +7 -5
  39. package/src/hmr/hmr-strategy-process.js +21 -16
  40. package/src/hmr/hmr-strategy.d.ts +11 -10
  41. package/src/hmr/hmr-strategy.js +32 -53
  42. package/src/hmr/page-metadata-cache.js +1 -1
  43. package/src/hydration/browser/foreign-boundary.d.ts +29 -0
  44. package/src/hydration/browser/foreign-boundary.js +128 -0
  45. package/src/hydration/browser/island-hydration.d.ts +3 -4
  46. package/src/hydration/browser/island-hydration.js +3 -4
  47. package/src/hydration/browser/page-hydration-hmr.d.ts +8 -7
  48. package/src/hydration/browser/page-hydration-hmr.js +53 -10
  49. package/src/hydration/browser/page-hydration.d.ts +6 -5
  50. package/src/hydration/browser/page-hydration.js +8 -6
  51. package/src/hydration/foreign-subtree.d.ts +27 -0
  52. package/src/hydration/foreign-subtree.js +69 -0
  53. package/src/hydration/hydration-asset.d.ts +37 -29
  54. package/src/hydration/hydration-asset.js +74 -138
  55. package/src/hydration/hydration-island-entry-source.d.ts +17 -0
  56. package/src/hydration/hydration-island-entry-source.js +32 -0
  57. package/src/hydration/hydration-page-entry-source.d.ts +20 -2
  58. package/src/hydration/hydration-page-entry-source.js +17 -12
  59. package/src/hydration/page-data-reader.d.ts +4 -7
  60. package/src/hydration/page-data-reader.js +5 -10
  61. package/src/mdx/mdx-config-dependency.d.ts +10 -15
  62. package/src/mdx/mdx-config-dependency.js +9 -22
  63. package/src/mdx/mdx-loader-plugin.d.ts +2 -0
  64. package/src/mdx/mdx-loader-plugin.js +1 -0
  65. package/src/page/page-module.js +1 -1
  66. package/src/plugin/react.plugin.d.ts +0 -7
  67. package/src/plugin/react.plugin.js +4 -33
  68. package/src/plugin/react.types.d.ts +0 -29
  69. package/src/render/component-ssr.d.ts +18 -0
  70. package/src/render/component-ssr.js +37 -0
  71. package/src/render/layout-compose.d.ts +4 -2
  72. package/src/render/layout-compose.js +13 -6
  73. package/src/render/layout-render-tracker.d.ts +20 -0
  74. package/src/render/layout-render-tracker.js +33 -0
  75. package/src/render/react-renderer.d.ts +28 -10
  76. package/src/render/react-renderer.js +103 -38
  77. package/src/render/react-runtime.js +2 -2
  78. package/src/bundling/runtime-alias-map.d.ts +0 -12
  79. package/src/bundling/runtime-alias-map.js +0 -110
  80. package/src/bundling/runtime-bundle.d.ts +0 -70
  81. package/src/bundling/runtime-bundle.js +0 -233
  82. package/src/bundling/runtime-interop-plugin.d.ts +0 -5
  83. package/src/bundling/runtime-interop-plugin.js +0 -32
  84. package/src/bundling/runtime-mode.d.ts +0 -1
  85. package/src/bundling/runtime-mode.js +0 -10
  86. package/src/bundling/runtime-modules.d.ts +0 -21
  87. package/src/bundling/runtime-modules.js +0 -28
  88. package/src/hydration/bootstrap-imports.d.ts +0 -25
  89. package/src/hydration/bootstrap-imports.js +0 -33
  90. package/src/hydration/compiled-page-hydration-options.d.ts +0 -19
  91. package/src/hydration/compiled-page-hydration-options.js +0 -1
  92. package/src/hydration/hydration-script-compiler.d.ts +0 -47
  93. package/src/hydration/hydration-script-compiler.js +0 -213
  94. package/src/runtime/use-sync-external-store-with-selector.d.ts +0 -3
  95. package/src/runtime/use-sync-external-store-with-selector.js +0 -54
@@ -1,9 +1,21 @@
1
+ /**
2
+ * React IntegrationRenderer orchestrator.
3
+ *
4
+ * @remarks
5
+ * Wires services and delegates SSR / layout composition / ownership details to
6
+ * focused modules under `render/`. Prefer changing those modules for
7
+ * implementation work; keep this file as the IntegrationRenderer seam.
8
+ *
9
+ * @module
10
+ */
11
+ import { AsyncLocalStorage } from 'node:async_hooks';
1
12
  import { buildIslandHostAttributes, getComponentIdentity } from '@ecopages/core';
2
13
  import { createIntegrationRenderer, selectHydrationIslandEntries, } from '@ecopages/core/integration';
3
14
  import { ECO_DOCUMENT_OWNER_ATTRIBUTE } from '@ecopages/core/client';
4
15
  import { resolveQueuedTokens } from '@ecopages/core/integration';
5
- import { ensurePageConfigLayouts } from '@ecopages/core/integration';
16
+ import { ensurePageConfigLayouts, moveMdxMetadataOntoPage } from '@ecopages/core/integration';
6
17
  import { hasSingleRootElement } from './html-boundary.js';
18
+ import { toRootRelativePath } from '@ecopages/core/build';
7
19
  import { getIslandComponentKey } from '../hydration/hydration-asset.js';
8
20
  import { REACT_PLUGIN_NAME, REACT_SSR_RENDER_TIMEOUT_MS } from '../plugin/react.constants.js';
9
21
  import { BundleService } from '../bundling/bundle.js';
@@ -14,13 +26,16 @@ import { PagePayloadService } from '../hydration/page-payload.js';
14
26
  import { HydrationAssetService } from '../hydration/hydration-asset.js';
15
27
  import {} from '@ecopages/core/integration';
16
28
  import { asNonReactShellComponent, getComponentRequires, isReactManagedComponent } from './component-ownership.js';
17
- import { buildHydrationProps, renderComponentHtml, renderNonReactShellComponent, restoreRuntimeChildHtml, toReactNode, } from './component-ssr.js';
29
+ import { buildHydrationProps, renderComponentHtml, renderNonReactShellComponent, restoreRuntimeChildHtml, replaceForeignSubtreeTokens, toReactNode, wrapForeignSubtreeTokens, } from './component-ssr.js';
18
30
  import { BundleError, ReactRenderError } from './errors.js';
19
31
  import { renderReactHtml, resolveReactRuntimeModules, runWithRenderBudget, } from './react-runtime.js';
20
32
  import { composeReactLayoutPageTree, shouldUseUnifiedReactLayoutComposition } from './unified-layout-composition.js';
21
33
  import { assertComposablePage, resolveLayoutContextFromShell } from './layout-compose.js';
34
+ import { LayoutRenderTracker } from './layout-render-tracker.js';
22
35
  export { BundleError, ReactRenderError } from './errors.js';
23
36
  const ReactIntegrationRenderer = createIntegrationRenderer(REACT_PLUGIN_NAME);
37
+ /** Whether the Page being rendered hydrates, for the Components rendered as part of its tree. */
38
+ const pageTreeHydration = new AsyncLocalStorage();
24
39
  /** Renderer adapter that contributes React-specific behavior through core hooks. */
25
40
  export class ReactRenderer extends ReactIntegrationRenderer {
26
41
  reactRuntimeModules;
@@ -123,14 +138,36 @@ export class ReactRenderer extends ReactIntegrationRenderer {
123
138
  this.reactRuntimeModules ??= this.resolveReactRuntimeModules();
124
139
  return this.reactRuntimeModules;
125
140
  }
141
+ /**
142
+ * Renders the route with the Page's hydration decision available to every Layout and document it composes.
143
+ *
144
+ * @remarks
145
+ * A Layout or document is rendered on its own when the Page has Foreign Children, and its config does not say
146
+ * whether the Page hydrates; only the Page's does.
147
+ */
148
+ render(options) {
149
+ return pageTreeHydration.run(this.hydratesPageTree(options.Page), () => super.render(options));
150
+ }
126
151
  renderReactTree(element, label) {
127
152
  return renderReactHtml(this.getReactRuntimeModules(), element, {
128
153
  timeoutMs: this.getRuntimeState().renderTimeoutMs,
129
154
  label,
130
155
  });
131
156
  }
132
- resolveReactQueuedForeignSubtreeHtml(html, runtimeContext) {
133
- return this.resolveQueuedForeignSubtrees(html, runtimeContext, async (children, currentRuntimeContext, queuedResolutionsByToken, resolveToken) => ({
157
+ /**
158
+ * Whether the browser hydrates the tree of the Page `component`.
159
+ *
160
+ * @remarks
161
+ * It reads the Page's own config, which holds the modules of its Layouts and nested Components.
162
+ */
163
+ hydratesPageTree(component) {
164
+ return this.forceBrowserGraph || this.pageModuleService.shouldHydratePage({ default: component });
165
+ }
166
+ /**
167
+ * Resolves the Foreign Subtree tokens in `html`, wrapping them in the hydration boundary only when `hydrates`.
168
+ */
169
+ resolveReactQueuedForeignSubtreeHtml(html, runtimeContext, hydrates) {
170
+ return this.resolveQueuedForeignSubtrees(hydrates ? wrapForeignSubtreeTokens(html, runtimeContext) : html, runtimeContext, async (children, currentRuntimeContext, queuedResolutionsByToken, resolveToken) => ({
134
171
  html: await this.renderQueuedChildrenToHtml({
135
172
  children,
136
173
  runtimeContext: currentRuntimeContext,
@@ -220,15 +257,19 @@ export class ReactRenderer extends ReactIntegrationRenderer {
220
257
  timeoutMs: this.getRuntimeState().renderTimeoutMs,
221
258
  label: getComponentIdentity(input.component)?.file ?? 'component',
222
259
  }));
223
- html = await this.resolveReactQueuedForeignSubtreeHtml(html, runtimeContext);
224
- const canAttachAttributes = hasSingleRootElement(html);
225
260
  const componentFile = getComponentIdentity(componentConfig)?.file;
261
+ const isIslandRoot = Boolean(componentFile && context.componentInstanceId && !hasResolvedChildHtml) &&
262
+ hasSingleRootElement(replaceForeignSubtreeTokens(html, runtimeContext, '<x></x>'));
263
+ html = await this.resolveReactQueuedForeignSubtreeHtml(html, runtimeContext, isIslandRoot ||
264
+ (!context.componentInstanceId &&
265
+ (pageTreeHydration.getStore() ?? this.hydratesPageTree(input.component))));
266
+ const canAttachAttributes = hasSingleRootElement(html);
226
267
  let rootAttributes;
227
- if (canAttachAttributes && componentFile && context.componentInstanceId && !hasResolvedChildHtml) {
268
+ if (canAttachAttributes && isIslandRoot && componentFile && context.componentInstanceId) {
228
269
  rootAttributes = buildIslandHostAttributes({
229
270
  integrationName: this.name,
230
271
  componentInstanceId: context.componentInstanceId,
231
- componentKey: getIslandComponentKey(componentFile, componentConfig),
272
+ componentKey: getIslandComponentKey(toRootRelativePath(this.appConfig.rootDir, componentFile), componentConfig),
232
273
  props: buildHydrationProps(input.props),
233
274
  });
234
275
  html = `<eco-island style="display:contents">${html}</eco-island>`;
@@ -262,39 +303,32 @@ export class ReactRenderer extends ReactIntegrationRenderer {
262
303
  }
263
304
  normalizeImportedPageFileHook(file, pageModule) {
264
305
  const reactModule = pageModule;
265
- const { default: Page, getMetadata, config } = reactModule;
266
- if (this.pageModuleService.isMdxFile(file) && config) {
306
+ const { default: Page, config } = reactModule;
307
+ if (!this.pageModuleService.isMdxFile(file)) {
308
+ return pageModule;
309
+ }
310
+ if (config) {
267
311
  ensurePageConfigLayouts(config);
268
312
  Page.config = config;
269
313
  }
270
- return {
271
- ...pageModule,
272
- default: Page,
273
- getMetadata,
274
- config,
275
- };
314
+ return { ...moveMdxMetadataOntoPage(reactModule), default: Page, config };
276
315
  }
277
316
  async collectPageBrowserGraphContributionHook(context) {
278
317
  try {
279
318
  const { file: pagePath, pageModule } = context;
280
319
  const shouldHydrate = this.forceBrowserGraph ? true : this.pageModuleService.shouldHydratePage(pageModule);
281
320
  if (!shouldHydrate) {
282
- return { assets: [] };
321
+ return {};
283
322
  }
284
323
  const isMdx = this.pageModuleService.isMdxFile(pagePath);
285
324
  const declaredModules = this.pageModuleService.collectPageDeclaredModules(pageModule);
286
- if (isMdx) {
287
- await this.bundleService.ensurePageLayoutNormalizationVendorProcessed(this.assetProcessingService);
288
- }
289
325
  const dependencies = await this.hydrationAssetService.createPageBrowserGraphDependencies(pagePath, isMdx, declaredModules);
290
- const assets = isMdx
291
- ? await this.mdxConfigDependencyService.processMdxConfigDependencies({
292
- pagePath,
293
- config: pageModule.config,
294
- processComponentDependencies: async (components) => await this.processComponentDependencies(components),
295
- })
296
- : [];
297
- return { dependencies, assets };
326
+ if (!isMdx)
327
+ return { dependencies };
328
+ return {
329
+ dependencies,
330
+ ...this.mdxConfigDependencyService.collectMdxConfigContribution(pagePath, pageModule.config),
331
+ };
298
332
  }
299
333
  catch (error) {
300
334
  if (error instanceof BundleError) {
@@ -310,9 +344,11 @@ export class ReactRenderer extends ReactIntegrationRenderer {
310
344
  props: layout.props,
311
345
  }));
312
346
  const runtime = this.getReactRuntimeModules();
347
+ const renderTracker = new LayoutRenderTracker();
313
348
  const tree = composeReactLayoutPageTree(pageComponent, page.props, shellEntries, {
314
349
  context: resolveLayoutContextFromShell(page.props, shellEntries),
315
350
  react: runtime.react,
351
+ renderTracker,
316
352
  });
317
353
  const runtimeInput = {
318
354
  component: page.component,
@@ -323,7 +359,12 @@ export class ReactRenderer extends ReactIntegrationRenderer {
323
359
  };
324
360
  const runtimeContext = this.getQueuedForeignSubtreeContext(runtimeInput);
325
361
  const html = this.normalizeUnresolvedMarkerArtifactHtml(await this.renderReactTree(tree, getComponentIdentity(page.component)?.file ?? 'page'));
326
- return { children: await this.resolveReactQueuedForeignSubtreeHtml(html, runtimeContext) };
362
+ const layoutWithoutChildren = renderTracker.findLayoutWithoutChildren(page.component);
363
+ if (layoutWithoutChildren)
364
+ this.onLayoutChildrenNotRendered(layoutWithoutChildren);
365
+ return {
366
+ children: await this.resolveReactQueuedForeignSubtreeHtml(html, runtimeContext, this.hydratesPageTree(page.component)),
367
+ };
327
368
  }
328
369
  resolveComposeChildren(options) {
329
370
  const { page, shellLayouts, foreignChildRoots } = options;
@@ -356,12 +397,12 @@ export class ReactRenderer extends ReactIntegrationRenderer {
356
397
  }
357
398
  getHtmlDocumentContributionsHook(options) {
358
399
  const renderOptions = options.renderOptions;
359
- if (options.partial ||
360
- !renderOptions ||
361
- !this.routerAdapter ||
362
- isReactManagedComponent(renderOptions.HtmlTemplate, this.name)) {
400
+ if (options.partial || !renderOptions)
401
+ return undefined;
402
+ if (!this.routerAdapter)
403
+ return this.buildRouterlessPageDataContributions(renderOptions);
404
+ if (isReactManagedComponent(renderOptions.HtmlTemplate, this.name))
363
405
  return undefined;
364
- }
365
406
  const pagePayload = this.buildPagePayload({
366
407
  Page: renderOptions.Page,
367
408
  pageProps: renderOptions.pageProps,
@@ -378,6 +419,32 @@ export class ReactRenderer extends ReactIntegrationRenderer {
378
419
  routerEnabled: true,
379
420
  });
380
421
  }
422
+ /**
423
+ * Publishes the props of a hydrating Page that has no router.
424
+ *
425
+ * @remarks
426
+ * A router's Html shell emits `__ECO_PAGE_DATA__` itself (`EcoPropsScript`). Without a router nothing does, so the
427
+ * hydration entry and a direct HMR update would read empty props. The script is a head contribution, whatever
428
+ * Integration owns the Html template, and only a Page the browser hydrates gets it.
429
+ */
430
+ buildRouterlessPageDataContributions(renderOptions) {
431
+ if (!this.hydratesPageTree(renderOptions.Page))
432
+ return undefined;
433
+ const pagePayload = this.buildPagePayload({
434
+ Page: renderOptions.Page,
435
+ pageProps: renderOptions.pageProps,
436
+ params: renderOptions.params,
437
+ query: renderOptions.query,
438
+ locals: renderOptions.locals,
439
+ pagePackage: renderOptions.pagePackage,
440
+ });
441
+ return [
442
+ {
443
+ placement: 'head-append',
444
+ html: this.pagePayloadService.buildRouterPageDataScript(pagePayload.pageProps),
445
+ },
446
+ ];
447
+ }
381
448
  getDocumentAttributesHook(_renderOptions) {
382
449
  return this.getRouterDocumentAttributes();
383
450
  }
@@ -392,10 +459,8 @@ function createReactRendererHookFactory(reactConfig, runtimeStateRef, hookTarget
392
459
  const bundleService = new BundleService({
393
460
  rootDir: appConfig.rootDir,
394
461
  appConfig,
395
- assetProcessingIntegration,
396
462
  hostIntegrationName: REACT_PLUGIN_NAME,
397
463
  routerAdapter,
398
- runtimeModules: reactConfig?.runtimeModules,
399
464
  getMdxLoaderPlugin: reactConfig?.getMdxLoaderPlugin,
400
465
  });
401
466
  const pageModuleService = new PageModuleService({
@@ -406,6 +471,7 @@ function createReactRendererHookFactory(reactConfig, runtimeStateRef, hookTarget
406
471
  hasRouterAdapter: Boolean(routerAdapter),
407
472
  });
408
473
  const hydrationAssetService = new HydrationAssetService({
474
+ rootDir: appConfig.rootDir,
409
475
  srcDir: appConfig.srcDir,
410
476
  routerAdapter,
411
477
  assetProcessingService,
@@ -425,9 +491,8 @@ function createReactRendererHookFactory(reactConfig, runtimeStateRef, hookTarget
425
491
  pagePayloadService: new PagePayloadService(),
426
492
  mdxConfigDependencyService: new MdxConfigDependencyService({
427
493
  integrationName: REACT_PLUGIN_NAME,
494
+ rootDir: appConfig.rootDir,
428
495
  pageModuleService,
429
- assetProcessingService,
430
- assetProcessingIntegration,
431
496
  }),
432
497
  applyPendingLazyTriggers,
433
498
  };
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { AsyncLocalStorage } from 'node:async_hooks';
9
9
  import { createRequire } from 'node:module';
10
- import path from 'node:path';
10
+ import { path } from '@ecopages/file-system/path';
11
11
  import { text } from 'node:stream/consumers';
12
12
  import { Logger } from '@ecopages/logger';
13
13
  import { ReactRenderError } from './errors.js';
@@ -25,7 +25,7 @@ export function runWithRenderBudget(options, render) {
25
25
  return renderBudgetStorage.run({ deadline: Date.now() + options.timeoutMs, timeoutMs: options.timeoutMs, label: options.label, warned: false }, render);
26
26
  }
27
27
  export function resolveReactRuntimeModules(rootDir) {
28
- const appPackageJsonPath = path.resolve(rootDir || process.cwd(), 'package.json');
28
+ const appPackageJsonPath = path.resolve(rootDir || path.cwd(), 'package.json');
29
29
  try {
30
30
  const requireFromApp = createRequire(appPackageJsonPath);
31
31
  return {
@@ -1,12 +0,0 @@
1
- import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
2
- import type { ReactRuntimeImports } from './runtime-bundle.js';
3
- import type { ResolvedReactPluginRuntimeModule } from './runtime-modules.js';
4
- import { type BrowserRuntimeAssetDeclaration, type BrowserRuntimeManifest } from '@ecopages/core/build';
5
- export type BuildReactRuntimeManifestOptions = {
6
- routerImportPath?: string;
7
- };
8
- export declare const REACT_RUNTIME_SPECIFIERS: readonly ["react", "react-dom", "react/jsx-runtime", "react/jsx-dev-runtime", "react-dom/client"];
9
- export declare function buildConfiguredRuntimeModuleManifestEntries(modules: readonly ResolvedReactPluginRuntimeModule[], getPublicPath: (outputName: string) => string): BrowserRuntimeAssetDeclaration[];
10
- export declare function buildReactRuntimeManifest(runtimeImports: ReactRuntimeImports, configuredRuntimeModules?: readonly ResolvedReactPluginRuntimeModule[], getConfiguredRuntimeModulePublicPath?: (outputName: string) => string, options?: BuildReactRuntimeManifestOptions): BrowserRuntimeManifest;
11
- export declare function getReactRuntimeExternalSpecifiers(): string[];
12
- export declare function getReactClientGraphAllowSpecifiers(runtimeSpecifiers: Iterable<string>, routerAdapter?: ReactRouterAdapter): string[];
@@ -1,110 +0,0 @@
1
- import { createBrowserRuntimeManifest, } from '@ecopages/core/build';
2
- import { LAYOUT_COMPOSE_PACKAGE } from './bootstrap-package-paths.js';
3
- export const REACT_RUNTIME_SPECIFIERS = [
4
- 'react',
5
- 'react-dom',
6
- 'react/jsx-runtime',
7
- 'react/jsx-dev-runtime',
8
- 'react-dom/client',
9
- ];
10
- export function buildConfiguredRuntimeModuleManifestEntries(modules, getPublicPath) {
11
- return modules.map((module) => ({
12
- specifier: module.specifier,
13
- owner: '@ecopages/react',
14
- importPath: module.specifier,
15
- publicPath: getPublicPath(module.outputName),
16
- externals: getReactRuntimeExternalSpecifiers(),
17
- }));
18
- }
19
- export function buildReactRuntimeManifest(runtimeImports, configuredRuntimeModules = [], getConfiguredRuntimeModulePublicPath = () => '', options) {
20
- const frameworkDeclarations = [
21
- {
22
- specifier: LAYOUT_COMPOSE_PACKAGE,
23
- owner: '@ecopages/react',
24
- importPath: LAYOUT_COMPOSE_PACKAGE,
25
- publicPath: runtimeImports.layoutCompose,
26
- },
27
- ];
28
- if (options?.routerImportPath && runtimeImports.router) {
29
- frameworkDeclarations.push({
30
- specifier: options.routerImportPath,
31
- owner: '@ecopages/react-router',
32
- importPath: options.routerImportPath,
33
- publicPath: runtimeImports.router,
34
- }, {
35
- specifier: '@ecopages/react-router',
36
- owner: '@ecopages/react-router',
37
- importPath: options.routerImportPath,
38
- publicPath: runtimeImports.router,
39
- });
40
- }
41
- return createBrowserRuntimeManifest([
42
- {
43
- specifier: 'react',
44
- owner: '@ecopages/react',
45
- importPath: 'react',
46
- publicPath: runtimeImports.react,
47
- },
48
- {
49
- specifier: 'react/jsx-runtime',
50
- owner: '@ecopages/react',
51
- importPath: 'react/jsx-runtime',
52
- publicPath: runtimeImports.reactJsxRuntime,
53
- },
54
- {
55
- specifier: 'react/jsx-dev-runtime',
56
- owner: '@ecopages/react',
57
- importPath: 'react/jsx-dev-runtime',
58
- publicPath: runtimeImports.reactJsxDevRuntime,
59
- },
60
- {
61
- specifier: 'react-dom',
62
- owner: '@ecopages/react',
63
- importPath: 'react-dom',
64
- publicPath: runtimeImports.reactDom,
65
- },
66
- {
67
- specifier: 'react-dom/client',
68
- owner: '@ecopages/react',
69
- importPath: 'react-dom/client',
70
- publicPath: runtimeImports.reactDomClient,
71
- },
72
- {
73
- specifier: 'use-sync-external-store/shim',
74
- owner: '@ecopages/react',
75
- importPath: 'use-sync-external-store/shim',
76
- publicPath: runtimeImports.react,
77
- },
78
- {
79
- specifier: 'use-sync-external-store/shim/index.js',
80
- owner: '@ecopages/react',
81
- importPath: 'use-sync-external-store/shim/index.js',
82
- publicPath: runtimeImports.react,
83
- },
84
- {
85
- specifier: 'use-sync-external-store/shim/with-selector',
86
- owner: '@ecopages/react',
87
- importPath: 'use-sync-external-store/shim/with-selector',
88
- publicPath: runtimeImports.useSyncExternalStoreWithSelector,
89
- },
90
- {
91
- specifier: 'use-sync-external-store/shim/with-selector.js',
92
- owner: '@ecopages/react',
93
- importPath: 'use-sync-external-store/shim/with-selector.js',
94
- publicPath: runtimeImports.useSyncExternalStoreWithSelector,
95
- },
96
- ...frameworkDeclarations,
97
- ...buildConfiguredRuntimeModuleManifestEntries(configuredRuntimeModules, getConfiguredRuntimeModulePublicPath),
98
- ]);
99
- }
100
- export function getReactRuntimeExternalSpecifiers() {
101
- return [...REACT_RUNTIME_SPECIFIERS];
102
- }
103
- export function getReactClientGraphAllowSpecifiers(runtimeSpecifiers, routerAdapter) {
104
- return [
105
- '@ecopages/core',
106
- ...REACT_RUNTIME_SPECIFIERS,
107
- ...(routerAdapter ? [routerAdapter.bundle.importPath] : []),
108
- ...Array.from(runtimeSpecifiers),
109
- ];
110
- }
@@ -1,70 +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/integration';
10
- import { type AssetDefinition } from '@ecopages/core/integration';
11
- import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
12
- import type { ResolvedReactPluginRuntimeModule } from './runtime-modules.js';
13
- import { type BrowserRuntimeManifest } from '@ecopages/core/build';
14
- export type ReactRuntimeImports = {
15
- react: string;
16
- reactDomClient: string;
17
- reactJsxRuntime: string;
18
- reactJsxDevRuntime: string;
19
- reactDom: string;
20
- useSyncExternalStoreWithSelector: string;
21
- pageLayoutNormalization: string;
22
- layoutCompose: string;
23
- router?: string;
24
- };
25
- export interface RuntimeBundleServiceConfig {
26
- routerAdapter?: ReactRouterAdapter;
27
- runtimeModules?: ResolvedReactPluginRuntimeModule[];
28
- rootDir?: string;
29
- workDir?: string;
30
- }
31
- type RuntimeMode = 'development' | 'production';
32
- export declare class RuntimeBundleService {
33
- private readonly config;
34
- constructor(config: RuntimeBundleServiceConfig);
35
- setRootDir(rootDir: string | undefined): void;
36
- setWorkDir(workDir: string | undefined): void;
37
- setRuntimeModules(runtimeModules: ResolvedReactPluginRuntimeModule[]): void;
38
- private get isDevelopment();
39
- private getCurrentRuntimeMode;
40
- private createRuntimeDefines;
41
- private getVendorFileName;
42
- private getConfiguredRuntimeModules;
43
- getConfiguredRuntimeModuleSpecifiers(): string[];
44
- private createReactVendorImportRewritePlugin;
45
- getRuntimeImports(mode?: RuntimeMode): ReactRuntimeImports;
46
- getRuntimeAliasMap(mode?: RuntimeMode): Record<string, string>;
47
- getRuntimeManifest(mode?: RuntimeMode): BrowserRuntimeManifest;
48
- getDependencies(options?: {
49
- modes?: RuntimeMode[];
50
- }): AssetDefinition[];
51
- /**
52
- * Declares the MDX-only page-layout-normalization vendor for the current runtime mode.
53
- *
54
- * @remarks
55
- * Kept out of {@link getDependencies} so non-MDX pages do not pay for this vendor during
56
- * integration setup. Callers process these assets once when an MDX page graph is prepared.
57
- */
58
- getPageLayoutNormalizationDependencies(options?: {
59
- modes?: RuntimeMode[];
60
- }): AssetDefinition[];
61
- /**
62
- * Builds the vendor import-rewrite plugin for one runtime asset.
63
- *
64
- * @remarks
65
- * `omitSpecifiers` drops the module being bundled so a self-import cannot
66
- * rewrite to the file currently being emitted.
67
- */
68
- createRuntimeAliasPlugin(mode?: RuntimeMode, omitSpecifiers?: readonly string[]): EcoBuildPlugin;
69
- }
70
- export {};