@ecopages/content-processor 0.2.0-beta.43 → 0.2.0-rc.1

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
@@ -121,32 +121,14 @@ Point `entryType` at the **frontmatter type** (`DocsFrontmatter`), not a hand-ro
121
121
 
122
122
  ## TypeScript setup
123
123
 
124
- Virtual-module types are generated at build/dev time into:
125
-
126
- ```text
127
- node_modules/@types/ecopages-content-processor/virtual-module.d.ts
128
- ```
129
-
130
- Add a root `modules.d.ts` (same pattern as `@ecopages/image-processor`):
124
+ Add one import to the app `modules.d.ts`:
131
125
 
132
126
  ```typescript
133
- /// <reference types="ecopages-content-processor" />
134
-
135
- import '@ecopages/core/declarations';
136
127
  import '@ecopages/content-processor/types';
137
128
  ```
138
129
 
139
- Recommended `tsconfig.json` additions:
140
-
141
- ```json
142
- {
143
- "compilerOptions": {
144
- "baseUrl": ".",
145
- "types": ["bun", "ecopages-content-processor"]
146
- },
147
- "include": ["src", "eco.config.ts", "modules.d.ts", "node_modules/@types/ecopages-content-processor"]
148
- }
149
- ```
130
+ That declares `ecopages:content/*`. Collection modules are generated at dev/build time into
131
+ `node_modules/@types/ecopages-content-processor`, which TypeScript loads automatically.
150
132
 
151
133
  Run `ecopages dev` or `ecopages build` before expecting IDE types. Restart the TypeScript server if types look stale after changing schema or collection config.
152
134
 
@@ -160,14 +142,14 @@ import { getComponent, getEntryDependencies } from 'ecopages:content/docs/server
160
142
  import type { Entry } from 'ecopages:content/docs';
161
143
  ```
162
144
 
163
- | Export | Module | Description |
164
- | :----------------------------- | :------ | :---------------------------------------------------------------------------------------------- |
165
- | `entries` | entries | Readonly manifest of all entries, sorted by `orderBy`. |
166
- | `getEntry(slug)` | entries | Lookup by joined slug, e.g. `'getting-started/intro'`. |
167
- | `getEntryBySegments(segments)` | entries | Lookup by segment array, e.g. `['getting-started', 'intro']`. |
168
- | `getComponent(slug)` | server | `Promise` of the MDX component for the entry (lazy-loaded per slug). |
169
- | `getEntryDependencies(slug)` | server | `Promise` of the browser dependency bag for the entry, with MDX source ownership. |
170
- | `Entry` | entries | **Type only.** `ContentEntry<YourFrontmatter>` — frontmatter fields plus `slug` and `segments`. |
145
+ | Export | Module | Description |
146
+ | :----------------------------- | :------ | :-------------------------------------------------------------------------------------------------------------------------- |
147
+ | `entries` | entries | Readonly manifest of all entries, sorted by `orderBy`. |
148
+ | `getEntry(slug)` | entries | Lookup by joined slug, e.g. `'getting-started/intro'`. Throws `HttpError.NotFound` when missing. |
149
+ | `getEntryBySegments(segments)` | entries | Lookup by segment array, e.g. `['getting-started', 'intro']`. Throws `HttpError.NotFound` when missing. |
150
+ | `getComponent(slug)` | server | `Promise` of the MDX component for the entry (lazy-loaded per slug). Throws `HttpError.NotFound` when missing. |
151
+ | `getEntryDependencies(slug)` | server | `Promise` of the browser dependency bag for the entry, with MDX source ownership. Throws `HttpError.NotFound` when missing. |
152
+ | `Entry` | entries | **Type only.** `ContentEntry<YourFrontmatter>` — frontmatter fields plus `slug` and `segments`. |
171
153
 
172
154
  **Important:** `Entry` exists only in generated `.d.ts` files, not in the runtime cache module. Keep type imports on a separate `import type` line in page files that get bundled. Mixed imports like `import { entries, type Entry }` can cause the bundler to treat `Entry` as a runtime export and fail with `MISSING_EXPORT`.
173
155
 
@@ -208,6 +190,8 @@ export default eco.page<{ entry: Entry }>({
208
190
  });
209
191
  ```
210
192
 
193
+ Unknown slugs throw `HttpError.NotFound`, so a catch-all that matches `/docs/[...slug]` still serves the app 404 page instead of a 500.
194
+
211
195
  Content MDX entries may declare interactive demo dependencies without polluting the catch-all page shell:
212
196
 
213
197
  ```mdx
@@ -239,7 +223,7 @@ export const docsNav = entries.map((entry) => ({
239
223
  }));
240
224
  ```
241
225
 
242
- Group or sort in your app — for example by a `group` frontmatter field and an `order` number. See `apps/docs` (`src/lib/content-nav.ts`) and `examples/docs-starter` (`src/content-nav.ts`) for full layouts with sections and sidebars.
226
+ Group or sort in your app — for example by a `group` frontmatter field and an `order` number. See `apps/docs` (`src/lib/content-nav.ts`) and `templates/docs-starter` (`src/content-nav.ts`) for full layouts with sections and sidebars.
243
227
 
244
228
  ## Build scripts
245
229
 
@@ -291,11 +275,11 @@ Watch config drives manifest regeneration only. Asset ownership (which would ski
291
275
 
292
276
  ## MDX integration
293
277
 
294
- Content files are MDX components. Ensure your JSX/MDX integration (for example, `@ecopages/ecopages-jsx`) is configured in `eco.config.ts` so `getComponent()` returns a renderable component.
278
+ Content files are MDX components. Ensure your JSX or React integration is configured in `eco.config.ts` with MDX enabled so collection entries compile as components.
295
279
 
296
280
  Content collections with YAML frontmatter need `remark-frontmatter` in the **MDX compile pipeline**. The processor validates frontmatter at scan time (`vfile-matter`); MDX render time needs the remark plugin so `---` blocks are not emitted as content.
297
281
 
298
- Use `@ecopages/content-processor/mdx`:
282
+ Use `@ecopages/content-processor/mdx` on whichever integration compiles the MDX:
299
283
 
300
284
  ```typescript
301
285
  import { withContentMdxPlugins } from '@ecopages/content-processor/mdx';
@@ -310,6 +294,13 @@ ecopagesJsxPlugin({
310
294
  }),
311
295
  },
312
296
  });
297
+
298
+ reactPlugin({
299
+ mdx: {
300
+ enabled: true,
301
+ ...withContentMdxPlugins(),
302
+ },
303
+ });
313
304
  ```
314
305
 
315
306
  `withContentMdxPlugins()` prepends `remarkFrontmatter`. Import it directly when you need finer control:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/content-processor",
3
- "version": "0.2.0-beta.43",
3
+ "version": "0.2.0-rc.1",
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",
@@ -17,10 +17,10 @@
17
17
  "directory": "packages/processors/content-processor"
18
18
  },
19
19
  "peerDependencies": {
20
- "@ecopages/core": "0.2.0-beta.43"
20
+ "@ecopages/core": "0.2.0-rc.1"
21
21
  },
22
22
  "dependencies": {
23
- "@ecopages/file-system": "0.2.0-beta.43",
23
+ "@ecopages/file-system": "0.2.0-rc.1",
24
24
  "@ecopages/logger": "^0.2.3",
25
25
  "remark-frontmatter": "^5.0.0",
26
26
  "unified": "^11.0.5",
@@ -37,7 +37,7 @@
37
37
  "types": "./src/plugin.d.ts"
38
38
  },
39
39
  "./types": {
40
- "types": "./src/types.d.ts"
40
+ "types": "./src/content-types.d.ts"
41
41
  },
42
42
  "./mdx": {
43
43
  "default": "./src/mdx.js",
@@ -48,19 +48,12 @@
48
48
  "types": "./src/plugin.d.ts"
49
49
  },
50
50
  "./types.ts": {
51
- "types": "./src/types.d.ts"
51
+ "types": "./src/content-types.d.ts"
52
52
  },
53
53
  "./mdx.ts": {
54
54
  "default": "./src/mdx.js",
55
55
  "types": "./src/mdx.d.ts"
56
56
  }
57
57
  },
58
- "typesVersions": {
59
- "*": {
60
- "ecopages:content/*": [
61
- "./virtual-module.d.ts"
62
- ]
63
- }
64
- },
65
58
  "types": "./src/index.d.ts"
66
59
  }
package/src/codegen.d.ts CHANGED
@@ -1,13 +1,33 @@
1
1
  import type { ContentEntry } from './types.js';
2
+ /**
3
+ * Generates the metadata-only virtual module for one content collection.
4
+ *
5
+ * @remarks
6
+ * The emitted module intentionally contains no MDX imports. Pages can use its
7
+ * manifest during route preparation without loading entry components.
8
+ */
2
9
  export declare function renderCollectionEntriesModule(collectionName: string, manifest: ContentEntry[]): string;
10
+ /**
11
+ * Generates the server-only virtual module that lazy-loads MDX entries.
12
+ *
13
+ * @remarks
14
+ * The emitted module caches completed components and coalesces concurrent
15
+ * loads for the same slug. Keeping MDX imports here leaves the metadata
16
+ * virtual module cheap to load during route preparation.
17
+ */
3
18
  export declare function renderCollectionComponentsModule(_collectionName: string, outputDir: string, entrySources: Array<{
4
19
  entry: ContentEntry;
5
20
  filePath: string;
6
21
  }>): string;
22
+ /** Generates both ambient virtual-module declarations for one collection. */
7
23
  export declare function renderCollectionTypesModule(collectionName: string, entryType?: string, typeResolution?: {
8
24
  rootDir: string;
9
25
  typesOutputFile: string;
10
26
  }): string;
27
+ /**
28
+ * Generates the declaration file that gives TypeScript types for every
29
+ * configured `ecopages:content/*` virtual module.
30
+ */
11
31
  export declare function renderVirtualModuleTypes(collections: Record<string, {
12
32
  entryType?: string;
13
33
  }>, typeResolution?: {
package/src/codegen.js CHANGED
@@ -9,6 +9,17 @@ function parseEntryTypeImport(entryType) {
9
9
  }
10
10
  return { module, name };
11
11
  }
12
+ /** Emits the shared missing-entry failure used by both generated runtime modules. */
13
+ function renderUnknownContentEntryThrow() {
14
+ return 'throw HttpError.NotFound(`Unknown content entry: ${slug}`)';
15
+ }
16
+ /**
17
+ * Generates the metadata-only virtual module for one content collection.
18
+ *
19
+ * @remarks
20
+ * The emitted module intentionally contains no MDX imports. Pages can use its
21
+ * manifest during route preparation without loading entry components.
22
+ */
12
23
  export function renderCollectionEntriesModule(collectionName, manifest) {
13
24
  const entriesBySlugLines = [];
14
25
  for (const [index, entry] of manifest.entries()) {
@@ -16,6 +27,8 @@ export function renderCollectionEntriesModule(collectionName, manifest) {
16
27
  }
17
28
  return `// This file is auto-generated by @ecopages/content-processor. Do not edit.
18
29
 
30
+ import { HttpError } from '@ecopages/core/errors';
31
+
19
32
  export const entries = [
20
33
  ${manifest.map((entry) => `\t${serializeEntry(entry)},`).join('\n')}
21
34
  ] as const;
@@ -26,7 +39,7 @@ ${entriesBySlugLines.join('\n')}
26
39
 
27
40
  export function getEntry(slug: string) {
28
41
  const entry = entriesBySlug[slug];
29
- if (!entry) throw new Error(\`Unknown content entry: \${slug}\`);
42
+ if (!entry) ${renderUnknownContentEntryThrow()};
30
43
  return entry;
31
44
  }
32
45
 
@@ -35,6 +48,14 @@ export function getEntryBySegments(segments: string[]) {
35
48
  }
36
49
  `;
37
50
  }
51
+ /**
52
+ * Generates the adapter that retains an MDX module's Ecopages component contract.
53
+ *
54
+ * @remarks
55
+ * MDX compilers expose component metadata as module exports. The generated
56
+ * server module moves that metadata onto the component returned to the route
57
+ * renderer, while assigning the content file as its canonical identity.
58
+ */
38
59
  function renderAttachMdxExportsHelper() {
39
60
  return `type ContentMdxModule = {
40
61
  default: EcoComponent<Record<string, unknown>>;
@@ -70,6 +91,14 @@ function attachMdxExports(module: ContentMdxModule, sourceFile: string): EcoComp
70
91
  }
71
92
  `;
72
93
  }
94
+ /**
95
+ * Generates the server-only virtual module that lazy-loads MDX entries.
96
+ *
97
+ * @remarks
98
+ * The emitted module caches completed components and coalesces concurrent
99
+ * loads for the same slug. Keeping MDX imports here leaves the metadata
100
+ * virtual module cheap to load during route preparation.
101
+ */
73
102
  export function renderCollectionComponentsModule(_collectionName, outputDir, entrySources) {
74
103
  const loaderLines = [];
75
104
  const entrySourceFilesBySlugLines = [];
@@ -84,6 +113,7 @@ export function renderCollectionComponentsModule(_collectionName, outputDir, ent
84
113
  return `// This file is auto-generated by @ecopages/content-processor. Do not edit.
85
114
 
86
115
  import { bindComponentIdentity, getComponentIdentity, type EcoComponent, type PageDependenciesResult } from '@ecopages/core';
116
+ import { HttpError } from '@ecopages/core/errors';
87
117
 
88
118
  ${renderAttachMdxExportsHelper()}
89
119
 
@@ -111,7 +141,7 @@ export async function getComponent(slug: string): Promise<EcoComponent<Record<st
111
141
 
112
142
  const load = loadersBySlug[slug];
113
143
  if (!load) {
114
- throw new Error(\`Unknown content entry: \${slug}\`);
144
+ ${renderUnknownContentEntryThrow()};
115
145
  }
116
146
 
117
147
  const loadPromise = (async () => {
@@ -141,6 +171,15 @@ export async function getEntryDependencies(slug: string): Promise<PageDependenci
141
171
  }
142
172
  `;
143
173
  }
174
+ /**
175
+ * Resolves an app-owned frontmatter type to the specifier used in generated
176
+ * virtual-module declarations.
177
+ *
178
+ * @remarks
179
+ * Types inside `src` use the app's `@/` alias. Types outside it use a relative
180
+ * path from the generated declaration file so TypeScript can resolve both
181
+ * forms without depending on the processor's own location.
182
+ */
144
183
  function resolveEntryTypeImport(entryType, rootDir, typesOutputFile) {
145
184
  const { module, name } = parseEntryTypeImport(entryType);
146
185
  const absoluteModule = resolve(rootDir, module);
@@ -168,7 +207,9 @@ function renderCollectionEntriesTypesModule(collectionName, entryType, typeResol
168
207
  ${entryDeclaration}
169
208
 
170
209
  export const entries: readonly Entry[];
210
+ /** @throws HttpError 404 when the slug is not in the collection. */
171
211
  export function getEntry(slug: string): Entry;
212
+ /** @throws HttpError 404 when no entry matches the segments. */
172
213
  export function getEntryBySegments(segments: string[]): Entry;
173
214
  }`;
174
215
  }
@@ -176,13 +217,20 @@ function renderCollectionComponentsTypesModule(collectionName) {
176
217
  return `declare module "ecopages:content/${collectionName}/server" {
177
218
  import type { EcoComponent, PageDependenciesResult } from '@ecopages/core';
178
219
 
220
+ /** @throws HttpError 404 when the slug is not in the collection. */
179
221
  export function getComponent(slug: string): Promise<EcoComponent<Record<string, unknown>>>;
222
+ /** @throws HttpError 404 when the slug is not in the collection. */
180
223
  export function getEntryDependencies(slug: string): Promise<PageDependenciesResult | undefined>;
181
224
  }`;
182
225
  }
226
+ /** Generates both ambient virtual-module declarations for one collection. */
183
227
  export function renderCollectionTypesModule(collectionName, entryType, typeResolution) {
184
228
  return `${renderCollectionEntriesTypesModule(collectionName, entryType, typeResolution)}\n\n${renderCollectionComponentsTypesModule(collectionName)}`;
185
229
  }
230
+ /**
231
+ * Generates the declaration file that gives TypeScript types for every
232
+ * configured `ecopages:content/*` virtual module.
233
+ */
186
234
  export function renderVirtualModuleTypes(collections, typeResolution) {
187
235
  return `/**
188
236
  * Do not edit manually. This file is auto-generated.
@@ -0,0 +1,11 @@
1
+ export type {
2
+ ContentCollectionComponentsModule,
3
+ ContentCollectionEntriesModule,
4
+ ContentCollectionModule,
5
+ ContentEntry,
6
+ EntryComparator,
7
+ OrderBy,
8
+ } from './types.js';
9
+
10
+ declare module 'ecopages:content/*' {}
11
+ declare module 'ecopages:content/*/server' {}
package/src/mdx.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import remarkFrontmatter from 'remark-frontmatter';
2
1
  import type { PluggableList } from 'unified';
3
2
  export { default as remarkFrontmatter } from 'remark-frontmatter';
4
3
  export type ContentMdxPluginsOptions = {
@@ -7,6 +6,10 @@ export type ContentMdxPluginsOptions = {
7
6
  /** Rehype plugins for the MDX pipeline. */
8
7
  rehypePlugins?: PluggableList;
9
8
  };
9
+ export type ContentMdxPlugins = {
10
+ remarkPlugins: PluggableList;
11
+ rehypePlugins: PluggableList;
12
+ };
10
13
  /**
11
14
  * Builds MDX plugin options for content collections that use YAML frontmatter.
12
15
  *
@@ -15,7 +18,4 @@ export type ContentMdxPluginsOptions = {
15
18
  * `contentProcessorPlugin()` — the processor validates frontmatter at scan time;
16
19
  * this helper wires the matching MDX remark plugin for render time.
17
20
  */
18
- export declare function withContentMdxPlugins(options?: ContentMdxPluginsOptions): {
19
- remarkPlugins: (typeof remarkFrontmatter | import("unified").Pluggable)[];
20
- rehypePlugins: PluggableList;
21
- };
21
+ export declare function withContentMdxPlugins(options?: ContentMdxPluginsOptions): ContentMdxPlugins;
package/src/plugin.js CHANGED
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import path from 'node:path';
6
6
  import { fileSystem } from '@ecopages/file-system';
7
- import { mergeProcessorOptions, Processor, resolveGeneratedPath, } from '@ecopages/core/plugins/processor';
7
+ import { mergeProcessorOptions, Processor, resolveGeneratedPath, writeGeneratedTypesPackage, } from '@ecopages/core/plugins/processor';
8
8
  import { Logger } from '@ecopages/logger';
9
9
  import { renderCollectionComponentsModule, renderCollectionEntriesModule, renderVirtualModuleTypes, } from './codegen.js';
10
10
  import { compareEntriesBySlug } from './sort.js';
@@ -237,6 +237,12 @@ export class ContentProcessorPlugin extends Processor {
237
237
  subPath: 'index.d.ts',
238
238
  });
239
239
  this.writeGeneratedFile(indexTypesDir, 'import "./virtual-module.d.js";\n');
240
+ writeGeneratedTypesPackage({
241
+ root: this.context.rootDir,
242
+ module: this.name,
243
+ packageName: '@types/ecopages-content-processor',
244
+ writeFile: (filePath, content) => this.writeGeneratedFile(filePath, content),
245
+ });
240
246
  }
241
247
  async buildCollectionServerArtifact(collectionName, serverOutputFile, ownedSourcePaths) {
242
248
  if (!this.context?.config.runtime?.buildRuntime) {
package/src/types.d.ts CHANGED
@@ -16,12 +16,28 @@ export type OrderBy<T extends Record<string, unknown> = Record<string, unknown>>
16
16
  /** Runtime shape of a generated `ecopages:content/<collection>` entries module. */
17
17
  export type ContentCollectionEntriesModule<TEntry extends Record<string, unknown> = Record<string, unknown>> = {
18
18
  readonly entries: readonly ContentEntry<TEntry>[];
19
+ /**
20
+ * Lookup by joined slug.
21
+ * @throws HttpError 404 when the slug is not in the collection.
22
+ */
19
23
  getEntry(slug: string): ContentEntry<TEntry>;
24
+ /**
25
+ * Lookup by path segments.
26
+ * @throws HttpError 404 when no entry matches the segments.
27
+ */
20
28
  getEntryBySegments(segments: string[]): ContentEntry<TEntry>;
21
29
  };
22
30
  /** Runtime shape of a generated `ecopages:content/<collection>/server` module. */
23
31
  export type ContentCollectionComponentsModule = {
32
+ /**
33
+ * Lazy-loads the MDX component for one slug.
34
+ * @throws HttpError 404 when the slug is not in the collection.
35
+ */
24
36
  getComponent(slug: string): Promise<EcoComponent<Record<string, unknown>>>;
37
+ /**
38
+ * Browser dependency bag for one slug, with MDX source ownership.
39
+ * @throws HttpError 404 when the slug is not in the collection.
40
+ */
25
41
  getEntryDependencies(slug: string): Promise<PageDependenciesResult | undefined>;
26
42
  };
27
43
  /** @deprecated Import entries and server modules separately. */