@ecopages/content-processor 0.2.0-rc.6 → 0.2.0-rc.7

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 CHANGED
@@ -365,4 +365,4 @@ App-specific presentation plugins (syntax highlighting, GFM, table wrappers) sta
365
365
 
366
366
  The integration that compiles an MDX entry also owns its rendering: an entry compiled with `mdx.extensions: ['.react.mdx']` on the React integration is a React component and must be rendered through a React-owned route (for example a `[...slug].react.tsx` catch-all). Calling it from a JSX (Radiant) or Kita render tree cannot serialize its output.
367
367
 
368
- The generated `getComponent()` enforces this at render time: invoking an entry inside a render lane that is not its owning integration throws with the entry path, the owning integration, and the active one. When both integrations compile MDX for the same collection, declare disjoint `mdx.extensions` per integration — since the React MDX loader derives its filter from the declared extensions, only `.react.mdx` files compile with React. `mdx.extensions` replaces `compilerOptions.mdxExtensions` rather than merging with it.
368
+ The generated `getComponent()` preserves this ownership at render time: invoking an entry in its owning lane renders directly, while a supported foreign-child render lane queues the entry through its owning integration. If no handoff runtime is available, it throws with the entry path, owning integration, and active integration. When both integrations compile MDX for the same collection, declare disjoint `mdx.extensions` per integration — since the React MDX loader derives its filter from the declared extensions, only `.react.mdx` files compile with React. `mdx.extensions` replaces `compilerOptions.mdxExtensions` rather than merging with it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/content-processor",
3
- "version": "0.2.0-rc.6",
3
+ "version": "0.2.0-rc.7",
4
4
  "description": "Scan MDX collections at build time and expose typed ecopages:content/* virtual modules for pages and scripts",
5
5
  "keywords": [
6
6
  "content",
@@ -20,10 +20,10 @@
20
20
  "directory": "packages/processors/content-processor"
21
21
  },
22
22
  "peerDependencies": {
23
- "@ecopages/core": "0.2.0-rc.6"
23
+ "@ecopages/core": "0.2.0-rc.7"
24
24
  },
25
25
  "dependencies": {
26
- "@ecopages/file-system": "0.2.0-rc.6",
26
+ "@ecopages/file-system": "0.2.0-rc.7",
27
27
  "@ecopages/logger": "^0.2.3",
28
28
  "remark-frontmatter": "^5.0.0",
29
29
  "unified": "^11.0.5",
package/src/codegen.js CHANGED
@@ -57,28 +57,32 @@ export function getEntryBySegments(segments: string[]) {
57
57
  * route renderer. It does not re-bind or snapshot `config`.
58
58
  */
59
59
  function renderAttachMdxExportsHelper(options) {
60
- const ownershipGuard = options?.ownershipCheck
60
+ const ownershipImport = options?.ownershipCheck
61
61
  ? `
62
- import { assertContentEntryOwnerLane } from '@ecopages/content-processor/ownership';
62
+ import { invokeContentEntry } from '@ecopages/content-processor/ownership';
63
63
  `
64
64
  : '';
65
65
  const guardBody = options?.ownershipCheck
66
66
  ? `
67
67
  const component = Object.assign(
68
- (props: Record<string, unknown>) => {
69
- assertContentEntryOwnerLane(sourceFile, module.config?.identity?.integration);
70
- return Page(props);
71
- },
68
+ (props: Record<string, unknown> = {}) =>
69
+ invokeContentEntry(
70
+ sourceFile,
71
+ module.config?.identity?.integration,
72
+ component,
73
+ Page,
74
+ props,
75
+ ),
72
76
  Page,
73
77
  ) as EcoComponent<Record<string, unknown>>;
74
78
  `
75
79
  : `
76
80
  const component = Object.assign(
77
- (props: Record<string, unknown>) => Page(props),
81
+ (props: Record<string, unknown> = {}) => Page(props),
78
82
  Page,
79
83
  ) as EcoComponent<Record<string, unknown>>;
80
84
  `;
81
- return `${ownershipGuard}type ContentMdxModule = {
85
+ return `${ownershipImport}type ContentMdxModule = {
82
86
  default: EcoComponent<Record<string, unknown>>;
83
87
  config?: EcoComponent<Record<string, unknown>>['config'];
84
88
  getMetadata?: EcoComponent<Record<string, unknown>>['metadata'];
@@ -1,3 +1,4 @@
1
+ import type { EcoComponent } from '@ecopages/core';
1
2
  /**
2
3
  * Throws when an MDX content entry is invoked under a different integration
3
4
  * than the one that compiled it.
@@ -9,3 +10,18 @@
9
10
  * outside a render lane.
10
11
  */
11
12
  export declare function assertContentEntryOwnerLane(sourceFile: string, integration: string | undefined): void;
13
+ type OwnedContentEntryComponent = EcoComponent & ((props: Record<string, unknown>) => unknown);
14
+ /**
15
+ * Invokes an MDX content entry under its owning integration's lane.
16
+ *
17
+ * @remarks
18
+ * When a foreign render lane is active but exposes a foreign-child runtime,
19
+ * the entry is handed off to its owning renderer through the Foreign Subtree
20
+ * queue instead of failing: the owning renderer renders and hydrates the
21
+ * subtree, and the lane receives resolved HTML. The strict ownership guard
22
+ * applies only when no handoff is available, so loaders and tests can invoke
23
+ * the component outside a render lane and foreign lanes without a runtime
24
+ * fail fast with an actionable message.
25
+ */
26
+ export declare function invokeContentEntry(sourceFile: string, integration: string | undefined, component: OwnedContentEntryComponent, page: (props: Record<string, unknown>) => unknown, props?: Record<string, unknown>): unknown;
27
+ export {};
package/src/ownership.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getComponentRenderContext } from '@ecopages/core/route-renderer/orchestration/foreign-child/component-render-context';
1
+ import { getComponentRenderContext, } from '@ecopages/core/route-renderer/orchestration/foreign-child/component-render-context';
2
2
  /**
3
3
  * Throws when an MDX content entry is invoked under a different integration
4
4
  * than the one that compiled it.
@@ -17,5 +17,49 @@ export function assertContentEntryOwnerLane(sourceFile, integration) {
17
17
  if (!context || context.currentIntegration === integration) {
18
18
  return;
19
19
  }
20
- throw new Error(`[ecopages] MDX content entry "${sourceFile}" is owned by the "${integration}" integration but was rendered inside a ${context.currentIntegration} render tree. MDX entries compiled by "${integration}" can only be rendered through routes owned by "${integration}" (for example a [...slug].${integration}.tsx catch-all). Either render this entry from an owning route or compile it with the host integration's MDX loader.`);
20
+ throw ownershipError(sourceFile, integration, context.currentIntegration);
21
+ }
22
+ function ownershipError(sourceFile, integration, currentIntegration) {
23
+ return new Error(`[ecopages] MDX content entry "${sourceFile}" is owned by the "${integration}" integration and cannot be rendered inside a ${currentIntegration} render tree. Embed it through its owning renderer (for example eco.embed() / EcoEmbed) or render it from a route owned by "${integration}".`);
24
+ }
25
+ function isPromiseLike(value) {
26
+ return typeof value === 'object' && value !== null && 'then' in value && typeof value.then === 'function';
27
+ }
28
+ /**
29
+ * Invokes an MDX content entry under its owning integration's lane.
30
+ *
31
+ * @remarks
32
+ * When a foreign render lane is active but exposes a foreign-child runtime,
33
+ * the entry is handed off to its owning renderer through the Foreign Subtree
34
+ * queue instead of failing: the owning renderer renders and hydrates the
35
+ * subtree, and the lane receives resolved HTML. The strict ownership guard
36
+ * applies only when no handoff is available, so loaders and tests can invoke
37
+ * the component outside a render lane and foreign lanes without a runtime
38
+ * fail fast with an actionable message.
39
+ */
40
+ export function invokeContentEntry(sourceFile, integration, component, page, props = {}) {
41
+ if (!integration) {
42
+ return page(props);
43
+ }
44
+ const context = getComponentRenderContext();
45
+ if (!context || context.currentIntegration === integration) {
46
+ return page(props);
47
+ }
48
+ const resolveInterception = (interception) => {
49
+ if (interception?.kind === 'resolved') {
50
+ return interception.value;
51
+ }
52
+ if (interception?.kind === 'inline') {
53
+ return page(interception.props ?? props);
54
+ }
55
+ throw ownershipError(sourceFile, integration, context.currentIntegration);
56
+ };
57
+ const interception = context.interceptForeignChild({
58
+ component,
59
+ props,
60
+ targetIntegration: integration,
61
+ });
62
+ return isPromiseLike(interception)
63
+ ? interception.then(resolveInterception)
64
+ : resolveInterception(interception);
21
65
  }