@ecopages/content-processor 0.3.0 → 0.3.2

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
@@ -319,7 +319,7 @@ Do not edit generated files manually.
319
319
 
320
320
  ## Validation errors
321
321
 
322
- Invalid frontmatter throws `SchemaError` from `@standard-schema/utils` during scan/build. Fix the MDX frontmatter or relax the schema in your app.
322
+ Invalid frontmatter throws `SchemaError` from `@standard-schema/utils` during scan/build. Fix the MDX frontmatter or relax the schema in your app. In development the error appears in the browser overlay, and saving the fixed file recovers the collection without restarting the server.
323
323
 
324
324
  ## Dev / HMR
325
325
 
@@ -329,7 +329,7 @@ Watch config drives manifest regeneration only. Asset ownership (which would ski
329
329
 
330
330
  ## MDX integration
331
331
 
332
- 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.
332
+ Content files are MDX components. Ensure your JSX or React integration is configured in `eco.config.ts` with an `mdx` option so collection entries compile as components.
333
333
 
334
334
  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.
335
335
 
@@ -341,7 +341,6 @@ import remarkGfm from 'remark-gfm';
341
341
 
342
342
  ecopagesJsxPlugin({
343
343
  mdx: {
344
- enabled: true,
345
344
  ...withContentMdxPlugins({
346
345
  remarkPlugins: [remarkGfm],
347
346
  rehypePlugins: [/* app-specific rehype plugins */],
@@ -351,7 +350,6 @@ ecopagesJsxPlugin({
351
350
 
352
351
  reactPlugin({
353
352
  mdx: {
354
- enabled: true,
355
353
  ...withContentMdxPlugins(),
356
354
  },
357
355
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/content-processor",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
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.3.0"
23
+ "@ecopages/core": "0.3.2"
24
24
  },
25
25
  "dependencies": {
26
- "@ecopages/file-system": "0.3.0",
26
+ "@ecopages/file-system": "0.3.2",
27
27
  "@ecopages/logger": "^0.2.3",
28
28
  "remark-frontmatter": "^5.0.0",
29
29
  "unified": "^11.0.5",
@@ -31,6 +31,12 @@ export declare class ContentScanner<T extends Record<string, unknown> = Record<s
31
31
  clearCache(): void;
32
32
  private parseFrontmatter;
33
33
  private loadCache;
34
+ /**
35
+ * @remarks
36
+ * A rejected load is dropped so the next call re-reads the directory. Keeping it
37
+ * would replay the first schema error for every later edit, even after the
38
+ * offending file was fixed.
39
+ */
34
40
  private getCache;
35
41
  getManifest(): Promise<ContentEntry<T>[]>;
36
42
  getRawContent(slug: string): Promise<string>;
@@ -70,9 +70,21 @@ export class ContentScanner {
70
70
  filePathsBySlug,
71
71
  };
72
72
  }
73
+ /**
74
+ * @remarks
75
+ * A rejected load is dropped so the next call re-reads the directory. Keeping it
76
+ * would replay the first schema error for every later edit, even after the
77
+ * offending file was fixed.
78
+ */
73
79
  async getCache() {
74
80
  if (!this.cachePromise) {
75
- this.cachePromise = this.loadCache();
81
+ const pending = this.loadCache();
82
+ this.cachePromise = pending;
83
+ pending.catch(() => {
84
+ if (this.cachePromise === pending) {
85
+ this.cachePromise = undefined;
86
+ }
87
+ });
76
88
  }
77
89
  return this.cachePromise;
78
90
  }
package/src/plugin.d.ts CHANGED
@@ -13,8 +13,17 @@ export declare class ContentProcessorPlugin extends Processor<ContentProcessorCo
13
13
  private readonly scanners;
14
14
  private readonly collectionBuildPromises;
15
15
  private readonly collectionGenerations;
16
- private readonly collectionServerBuiltAt;
17
16
  private readonly collectionServerArtifacts;
17
+ /**
18
+ * Collections whose generated modules may not match the files on disk.
19
+ *
20
+ * @remarks
21
+ * A collection joins this set when a regeneration starts and leaves it when that
22
+ * regeneration completes. One that failed, for example on invalid frontmatter,
23
+ * stays in it so the next file change regenerates instead of diffing against a
24
+ * manifest that never reached the generated modules.
25
+ */
26
+ private readonly staleCollections;
18
27
  /**
19
28
  * Absolute paths to generated collection entry modules, keyed by collection name.
20
29
  * Virtual-module plugins close over this object so mutations stay live.
package/src/plugin.js CHANGED
@@ -33,8 +33,17 @@ export class ContentProcessorPlugin extends Processor {
33
33
  scanners = new Map();
34
34
  collectionBuildPromises = new Map();
35
35
  collectionGenerations = new Map();
36
- collectionServerBuiltAt = new Map();
37
36
  collectionServerArtifacts = new Map();
37
+ /**
38
+ * Collections whose generated modules may not match the files on disk.
39
+ *
40
+ * @remarks
41
+ * A collection joins this set when a regeneration starts and leaves it when that
42
+ * regeneration completes. One that failed, for example on invalid frontmatter,
43
+ * stays in it so the next file change regenerates instead of diffing against a
44
+ * manifest that never reached the generated modules.
45
+ */
46
+ staleCollections = new Set();
38
47
  /**
39
48
  * Absolute paths to generated collection entry modules, keyed by collection name.
40
49
  * Virtual-module plugins close over this object so mutations stay live.
@@ -123,6 +132,7 @@ export class ContentProcessorPlugin extends Processor {
123
132
  if (!definition) {
124
133
  return;
125
134
  }
135
+ this.staleCollections.add(collectionName);
126
136
  const scanner = this.getOrCreateScanner(collectionName);
127
137
  scanner.clearCache();
128
138
  const entrySources = await scanner.getEntrySources();
@@ -141,6 +151,7 @@ export class ContentProcessorPlugin extends Processor {
141
151
  this.collectionServerModules[collectionName] = serverOutputFile;
142
152
  this.collectionBrowserModules[collectionName] = browserOutputFile;
143
153
  this.invalidateCollectionServerArtifact(collectionName);
154
+ this.staleCollections.delete(collectionName);
144
155
  logger.debug('Generated content collection module', {
145
156
  collectionName,
146
157
  outputFile,
@@ -241,7 +252,7 @@ export class ContentProcessorPlugin extends Processor {
241
252
  }
242
253
  }
243
254
  async applyCollectionWatchChanges(collectionName, changes) {
244
- if (changes.regenerate) {
255
+ if (changes.regenerate || this.staleCollections.has(collectionName)) {
245
256
  await this.regenerateCollectionModule(collectionName);
246
257
  return true;
247
258
  }
@@ -260,16 +271,14 @@ export class ContentProcessorPlugin extends Processor {
260
271
  async updateChangedCollectionEntries(collectionName, changes) {
261
272
  let result = 'none';
262
273
  for (const filePath of changes.changedEntries) {
274
+ changes.invalidateServerArtifact = true;
263
275
  const updateResult = await this.getOrCreateScanner(collectionName).updateEntryForPath(filePath, 'change');
264
- if (updateResult === 'no-op') {
265
- changes.invalidateServerArtifact = true;
276
+ if (updateResult === 'structure') {
277
+ result = 'collection';
266
278
  }
267
279
  else if (updateResult === 'manifest' && result === 'none') {
268
280
  result = 'entries';
269
281
  }
270
- else if (updateResult !== 'manifest') {
271
- result = 'collection';
272
- }
273
282
  }
274
283
  return result;
275
284
  }
@@ -335,7 +344,7 @@ export class ContentProcessorPlugin extends Processor {
335
344
  if (!this.context) {
336
345
  return;
337
346
  }
338
- if (this.collectionServerBuiltAt.get(collectionName) !== this.getServerSourceGeneration()) {
347
+ if (this.collectionServerArtifacts.get(collectionName)?.invalidationVersion !== this.getServerSourceGeneration()) {
339
348
  delete this.collectionServerCompiledModules[collectionName];
340
349
  }
341
350
  if (this.collectionServerCompiledModules[collectionName]) {
@@ -363,9 +372,7 @@ export class ContentProcessorPlugin extends Processor {
363
372
  serverSourceGeneration !== this.getServerSourceGeneration();
364
373
  if (changedDuringBuild) {
365
374
  delete this.collectionServerCompiledModules[collectionName];
366
- return;
367
375
  }
368
- this.collectionServerBuiltAt.set(collectionName, serverSourceGeneration);
369
376
  })
370
377
  .finally(() => this.collectionBuildPromises.delete(collectionName));
371
378
  this.collectionBuildPromises.set(collectionName, buildPromise);