@ecopages/content-processor 0.2.0-beta.42 → 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.
package/README.md CHANGED
@@ -160,14 +160,14 @@ import { getComponent, getEntryDependencies } from 'ecopages:content/docs/server
160
160
  import type { Entry } from 'ecopages:content/docs';
161
161
  ```
162
162
 
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`. |
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'`. Throws `HttpError.NotFound` when missing. |
167
+ | `getEntryBySegments(segments)` | entries | Lookup by segment array, e.g. `['getting-started', 'intro']`. Throws `HttpError.NotFound` when missing. |
168
+ | `getComponent(slug)` | server | `Promise` of the MDX component for the entry (lazy-loaded per slug). Throws `HttpError.NotFound` when missing. |
169
+ | `getEntryDependencies(slug)` | server | `Promise` of the browser dependency bag for the entry, with MDX source ownership. Throws `HttpError.NotFound` when missing. |
170
+ | `Entry` | entries | **Type only.** `ContentEntry<YourFrontmatter>` — frontmatter fields plus `slug` and `segments`. |
171
171
 
172
172
  **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
173
 
@@ -208,6 +208,8 @@ export default eco.page<{ entry: Entry }>({
208
208
  });
209
209
  ```
210
210
 
211
+ Unknown slugs throw `HttpError.NotFound`, so a catch-all that matches `/docs/[...slug]` still serves the app 404 page instead of a 500.
212
+
211
213
  Content MDX entries may declare interactive demo dependencies without polluting the catch-all page shell:
212
214
 
213
215
  ```mdx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/content-processor",
3
- "version": "0.2.0-beta.42",
3
+ "version": "0.2.0-rc.0",
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.42"
20
+ "@ecopages/core": "0.2.0-rc.0"
21
21
  },
22
22
  "dependencies": {
23
- "@ecopages/file-system": "0.2.0-beta.42",
23
+ "@ecopages/file-system": "0.2.0-rc.0",
24
24
  "@ecopages/logger": "^0.2.3",
25
25
  "remark-frontmatter": "^5.0.0",
26
26
  "unified": "^11.0.5",
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.
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. */