@ecopages/content-processor 0.5.0 → 0.6.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
@@ -4,10 +4,10 @@ Build-time content collections for Ecopages. Scans MDX (or other configured exte
4
4
 
5
5
  ## Mental model
6
6
 
7
- Build contributions use one `plugins(app)` method. Collection modules and types are generated in `setup()`, and a build that resolves a collection first waits for the same generation. The server resolver and browser resolver declare separate environments, so browser compilation cannot select the server implementation by registration order.
7
+ Build contributions use one `plugins(app)` method. Collection modules and types are generated in `setup()`, and a build that resolves a collection first waits for the same generation. `ecopages build` emits those generated collection manifests and server modules into `dist/server/` and registers them in `server-modules.json`. Production `ecopages start` restores from that map and does not call `setup()`. Development still regenerates collections when an MDX file is edited. The server resolver and browser resolver declare separate environments, so browser compilation cannot select the server implementation by registration order.
8
8
 
9
9
  1. **Declare collections** in `eco.config.ts` — content directory, frontmatter schema, and sort order.
10
- 2. **Scan at build time** — the processor validates frontmatter and writes generated modules under `.eco/cache/`.
10
+ 2. **Scan at build time** — the processor validates frontmatter and writes generated modules under `.eco/cache/`. Invalid frontmatter fails `ecopages build`, not the first request. Production emit copies the compiled collection modules into `dist/server/`.
11
11
  3. **Import the virtual module** — pages and layouts use `ecopages:content/<collection>` for `entries`, metadata, and MDX components.
12
12
  4. **Own your frontmatter** — define fields with any [Standard Schema](https://standardschema.dev)-compatible library (Zod, Valibot, ArkType, etc.). The processor adds `slug` and `segments` from the file path.
13
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/content-processor",
3
- "version": "0.5.0",
3
+ "version": "0.6.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",
@@ -20,10 +20,10 @@
20
20
  "directory": "packages/processors/content-processor"
21
21
  },
22
22
  "peerDependencies": {
23
- "@ecopages/core": "0.5.0"
23
+ "@ecopages/core": "0.6.1"
24
24
  },
25
25
  "dependencies": {
26
- "@ecopages/file-system": "0.5.0",
26
+ "@ecopages/file-system": "0.6.1",
27
27
  "@ecopages/logger": "^0.2.3",
28
28
  "remark-frontmatter": "^5.0.0",
29
29
  "unified": "^11.0.5",
@@ -18,10 +18,11 @@ export declare function resolveCollectionPath(specifier: string, collectionModul
18
18
  * Creates the server graph resolver for collection virtual modules.
19
19
  *
20
20
  * @remarks
21
- * Compiled `/server` and `/component` modules are externalized so Node can load the collection
22
- * artifact directly; both specifiers share one module instance and one component cache. Every
23
- * resolve waits for `ensureCollectionsGenerated`, so a build that runs before the Processor's
24
- * `setup()` still finds the generated modules. The Page Browser Graph uses
21
+ * Compiled `/server` and `/component` modules are externalized in development so Node can load
22
+ * the collection artifact directly; both specifiers share one module instance and one component
23
+ * cache. Production emit inlines those generated files in the unified graph and writes them to
24
+ * `dist/server/`. Every resolve waits for `ensureCollectionsGenerated`, so a build that runs
25
+ * before the Processor's `setup()` still finds the generated modules. The Page Browser Graph uses
25
26
  * `createContentPluginBundler`, where the content boundary rejects `/server` and `/component`
26
27
  * resolves to the browser-safe loader.
27
28
  */
@@ -1,4 +1,5 @@
1
1
  import path from 'node:path';
2
+ import { shouldBuildPagesUnifiedGraph } from '@ecopages/core/build';
2
3
  import { CONTENT_COMPONENT_VIRTUAL_MODULE_PATTERN, CONTENT_SERVER_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PATTERN, parseCollectionSpecifier, } from './constants.js';
3
4
  export { parseCollectionSpecifier } from './constants.js';
4
5
  export function parseCollectionName(specifier) {
@@ -51,11 +52,12 @@ function createContentResolvePlugin(collectionModules, collectionServerModules,
51
52
  const resolveServerBackedModule = async (args) => {
52
53
  await ensureCollectionsGenerated?.();
53
54
  const parsed = parseCollectionSpecifier(args.path);
54
- if (parsed) {
55
+ const inlineInUnifiedGraph = shouldBuildPagesUnifiedGraph();
56
+ if (parsed && !inlineInUnifiedGraph) {
55
57
  await ensureCollectionServerArtifact?.(parsed.collectionName);
56
58
  }
57
59
  const compiledPath = parsed ? collectionServerCompiledModules?.[parsed.collectionName] : undefined;
58
- if (compiledPath && options.externalizeCompiledServerModules) {
60
+ if (compiledPath && options.externalizeCompiledServerModules && !inlineInUnifiedGraph) {
59
61
  return { path: compiledPath, external: true };
60
62
  }
61
63
  const modulePath = resolveCollection(args.path);
@@ -83,10 +85,11 @@ function createContentResolvePlugin(collectionModules, collectionServerModules,
83
85
  * Creates the server graph resolver for collection virtual modules.
84
86
  *
85
87
  * @remarks
86
- * Compiled `/server` and `/component` modules are externalized so Node can load the collection
87
- * artifact directly; both specifiers share one module instance and one component cache. Every
88
- * resolve waits for `ensureCollectionsGenerated`, so a build that runs before the Processor's
89
- * `setup()` still finds the generated modules. The Page Browser Graph uses
88
+ * Compiled `/server` and `/component` modules are externalized in development so Node can load
89
+ * the collection artifact directly; both specifiers share one module instance and one component
90
+ * cache. Production emit inlines those generated files in the unified graph and writes them to
91
+ * `dist/server/`. Every resolve waits for `ensureCollectionsGenerated`, so a build that runs
92
+ * before the Processor's `setup()` still finds the generated modules. The Page Browser Graph uses
90
93
  * `createContentPluginBundler`, where the content boundary rejects `/server` and `/component`
91
94
  * resolves to the browser-safe loader.
92
95
  */
package/src/plugin.d.ts CHANGED
@@ -42,6 +42,16 @@ export declare class ContentProcessorPlugin extends Processor<ContentProcessorCo
42
42
  constructor(config: Omit<ProcessorConfig<ContentProcessorConfig>, 'name'>);
43
43
  private get browserPlugins();
44
44
  plugins(): EcoBuildPlugin[];
45
+ listProductionServerModuleEntries(): string[];
46
+ /**
47
+ * Points collection virtual modules at the files `ecopages build` emitted.
48
+ *
49
+ * @remarks
50
+ * Production `ecopages start` skips `setup()`, so this must not scan sources or write under `.eco/`.
51
+ */
52
+ restoreProductionRuntime(): Promise<void>;
53
+ private toSourceKey;
54
+ private resolveEmittedModule;
45
55
  private getCollectionsConfig;
46
56
  private getCollectionContentRoot;
47
57
  private writeGeneratedFile;
package/src/plugin.js CHANGED
@@ -5,6 +5,7 @@
5
5
  import path from 'node:path';
6
6
  import { fileSystem } from '@ecopages/file-system';
7
7
  import { isEcopagesEnvEnabled } from '@ecopages/core/processor';
8
+ import { loadProductionServerModules, missingProductionServerModuleError } from '@ecopages/core/build';
8
9
  import { requireAppRuntime } from '@ecopages/core/integration';
9
10
  import { mergeProcessorOptions, Processor, resolveGeneratedPath, writeGeneratedTypesPackage, } from '@ecopages/core/processor';
10
11
  import { Logger } from '@ecopages/logger';
@@ -86,6 +87,50 @@ export class ContentProcessorPlugin extends Processor {
86
87
  ...this.browserPlugins,
87
88
  ];
88
89
  }
90
+ listProductionServerModuleEntries() {
91
+ return [...Object.values(this.collectionModules), ...Object.values(this.collectionServerModules)];
92
+ }
93
+ /**
94
+ * Points collection virtual modules at the files `ecopages build` emitted.
95
+ *
96
+ * @remarks
97
+ * Production `ecopages start` skips `setup()`, so this must not scan sources or write under `.eco/`.
98
+ */
99
+ async restoreProductionRuntime() {
100
+ if (!this.context?.cache) {
101
+ return;
102
+ }
103
+ const manifest = loadProductionServerModules(this.context.config);
104
+ if (!manifest) {
105
+ return;
106
+ }
107
+ this.initializeWatchPaths();
108
+ for (const collectionName of Object.keys(this.getCollectionsConfig())) {
109
+ const entriesSource = getCollectionCachePath(this.context.cache, collectionName);
110
+ const serverSource = getCollectionServerCachePath(this.context.cache, collectionName);
111
+ const entriesKey = this.toSourceKey(entriesSource);
112
+ const serverKey = this.toSourceKey(serverSource);
113
+ const entriesOutput = this.resolveEmittedModule(manifest, entriesKey);
114
+ const serverOutput = this.resolveEmittedModule(manifest, serverKey);
115
+ if (!entriesOutput || !serverOutput) {
116
+ throw missingProductionServerModuleError(entriesOutput ? serverKey : entriesKey);
117
+ }
118
+ this.collectionModules[collectionName] = entriesOutput;
119
+ this.collectionServerModules[collectionName] = serverOutput;
120
+ this.collectionServerCompiledModules[collectionName] = serverOutput;
121
+ }
122
+ this.collectionsGeneration = Promise.resolve();
123
+ }
124
+ toSourceKey(filePath) {
125
+ if (!this.context) {
126
+ throw new Error('Content processor requires context to be set');
127
+ }
128
+ return path.relative(this.context.rootDir, filePath).split(path.sep).join('/');
129
+ }
130
+ resolveEmittedModule(manifest, sourceKey) {
131
+ const relativePath = manifest.modules[sourceKey];
132
+ return relativePath ? path.join(manifest.outdir, relativePath) : undefined;
133
+ }
89
134
  getCollectionsConfig() {
90
135
  if (!this.options?.collections) {
91
136
  throw new Error('Content processor requires `options.collections`');
@@ -344,7 +389,8 @@ export class ContentProcessorPlugin extends Processor {
344
389
  if (!this.context) {
345
390
  return;
346
391
  }
347
- if (this.collectionServerArtifacts.get(collectionName)?.invalidationVersion !== this.getServerSourceGeneration()) {
392
+ const artifact = this.collectionServerArtifacts.get(collectionName);
393
+ if (artifact && artifact.invalidationVersion !== this.getServerSourceGeneration()) {
348
394
  delete this.collectionServerCompiledModules[collectionName];
349
395
  }
350
396
  if (this.collectionServerCompiledModules[collectionName]) {