@ecopages/content-processor 0.2.0-rc.5 → 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
@@ -31,6 +31,8 @@ The processor gives you a typed manifest and MDX components at build time. Wire
31
31
 
32
32
  During development, edits to an entry's MDX body invalidate its compiled server collection bundle even when its frontmatter and generated manifest are unchanged. The next request rebuilds that bundle and renders the new body.
33
33
 
34
+ Co-located non-entry files inside a collection directory (for example `survey-form.config.ts`, helper modules, or JSON data) also invalidate the compiled server collection without rewriting the generated entries manifest.
35
+
34
36
  ## Installation
35
37
 
36
38
  ```bash
@@ -363,4 +365,4 @@ App-specific presentation plugins (syntax highlighting, GFM, table wrappers) sta
363
365
 
364
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.
365
367
 
366
- 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.5",
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.5"
23
+ "@ecopages/core": "0.2.0-rc.7"
24
24
  },
25
25
  "dependencies": {
26
- "@ecopages/file-system": "0.2.0-rc.5",
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
  }
package/src/plugin.d.ts CHANGED
@@ -31,6 +31,7 @@ export declare class ContentProcessorPlugin extends Processor<ContentProcessorCo
31
31
  constructor(config: Omit<ProcessorConfig<ContentProcessorConfig>, 'name' | 'description'>);
32
32
  get buildPlugins(): EcoBuildPlugin[];
33
33
  get plugins(): EcoBuildPlugin[];
34
+ invalidateServerArtifacts(): void;
34
35
  private getCollectionsConfig;
35
36
  private getCollectionContentRoot;
36
37
  private writeGeneratedFile;
@@ -48,6 +49,7 @@ export declare class ContentProcessorPlugin extends Processor<ContentProcessorCo
48
49
  private regenerateCollectionEntriesModule;
49
50
  private regenerateCollections;
50
51
  private regenerateAllCollections;
52
+ private isCollectionEntryPath;
51
53
  private handleContentFileEvent;
52
54
  private initializeWatchPaths;
53
55
  private generateTypes;
package/src/plugin.js CHANGED
@@ -49,7 +49,7 @@ export class ContentProcessorPlugin extends Processor {
49
49
  constructor(config) {
50
50
  const defaultWatchConfig = {
51
51
  paths: [],
52
- extensions: ['mdx'],
52
+ extensions: ['.mdx', '.md', '.ts', '.tsx', '.js', '.jsx', '.json'],
53
53
  onCreate: async (ctx) => this.handleContentFileEvent(ctx.path, 'create'),
54
54
  onChange: async (ctx) => this.handleContentFileEvent(ctx.path, 'change'),
55
55
  onDelete: async (ctx) => this.handleContentFileEvent(ctx.path, 'delete'),
@@ -72,6 +72,11 @@ export class ContentProcessorPlugin extends Processor {
72
72
  createContentPlugin(this.collectionModules, this.collectionServerModules, this.collectionServerCompiledModules, this.collectionBrowserModules, (collectionName) => this.ensureCollectionServerArtifact(collectionName)),
73
73
  ];
74
74
  }
75
+ invalidateServerArtifacts() {
76
+ for (const collectionName of Object.keys(this.getCollectionsConfig())) {
77
+ this.invalidateCollectionServerArtifact(collectionName);
78
+ }
79
+ }
75
80
  getCollectionsConfig() {
76
81
  if (!this.options?.collections) {
77
82
  throw new Error('Content processor requires `options.collections`');
@@ -177,6 +182,13 @@ export class ContentProcessorPlugin extends Processor {
177
182
  async regenerateAllCollections() {
178
183
  await this.regenerateCollections(Object.keys(this.getCollectionsConfig()));
179
184
  }
185
+ isCollectionEntryPath(normalizedPath, configuredExtensions) {
186
+ const extensions = configuredExtensions ?? ['.mdx'];
187
+ return extensions.some((ext) => {
188
+ const dotted = ext.startsWith('.') ? ext : `.${ext}`;
189
+ return normalizedPath.endsWith(dotted);
190
+ });
191
+ }
180
192
  async handleContentFileEvent(filePath, event) {
181
193
  if (!this.context) {
182
194
  return;
@@ -191,6 +203,12 @@ export class ContentProcessorPlugin extends Processor {
191
203
  }
192
204
  let shouldRegenerateTypes = false;
193
205
  for (const collectionName of affectedCollections) {
206
+ const definition = this.getCollectionsConfig()[collectionName];
207
+ const isEntry = this.isCollectionEntryPath(normalizedPath, definition.extensions);
208
+ if (!isEntry) {
209
+ this.invalidateCollectionServerArtifact(collectionName);
210
+ continue;
211
+ }
194
212
  if (event === 'create' || event === 'delete') {
195
213
  await this.regenerateCollectionModule(collectionName);
196
214
  shouldRegenerateTypes = true;