@ecopages/content-processor 0.6.0 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/content-processor",
3
- "version": "0.6.0",
3
+ "version": "0.7.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",
@@ -9,6 +9,9 @@
9
9
  "collections"
10
10
  ],
11
11
  "license": "MIT",
12
+ "engines": {
13
+ "node": "^24.22.0 || >=26.0.0"
14
+ },
12
15
  "main": "./src/index.js",
13
16
  "type": "module",
14
17
  "publishConfig": {
@@ -20,10 +23,10 @@
20
23
  "directory": "packages/processors/content-processor"
21
24
  },
22
25
  "peerDependencies": {
23
- "@ecopages/core": "0.6.0"
26
+ "@ecopages/core": "0.7.0"
24
27
  },
25
28
  "dependencies": {
26
- "@ecopages/file-system": "0.6.0",
29
+ "@ecopages/file-system": "0.7.0",
27
30
  "@ecopages/logger": "^0.2.3",
28
31
  "remark-frontmatter": "^5.0.0",
29
32
  "unified": "^11.0.5",
package/src/codegen.d.ts CHANGED
@@ -19,7 +19,7 @@ export declare function renderCollectionEntriesModule(collectionName: string, ma
19
19
  * resolves `ecopages:content/<collection>/component` to this module so both
20
20
  * specifiers share one cache and one wrapped component per slug.
21
21
  */
22
- export declare function renderCollectionComponentsModule(collectionName: string, outputDir: string, entrySources: Array<{
22
+ export declare function renderCollectionComponentsModule(collectionName: string, outputDir: string, rootDir: string, entrySources: Array<{
23
23
  entry: ContentEntry;
24
24
  filePath: string;
25
25
  }>): string;
@@ -32,7 +32,7 @@ export declare function renderCollectionComponentsModule(collectionName: string,
32
32
  * loads one browser-compiled MDX entry on demand and coalesces concurrent
33
33
  * requests; it is not a server renderer.
34
34
  */
35
- export declare function renderCollectionBrowserModule(collectionName: string, outputDir: string, entrySources: Array<{
35
+ export declare function renderCollectionBrowserModule(collectionName: string, outputDir: string, rootDir: string, entrySources: Array<{
36
36
  entry: ContentEntry;
37
37
  filePath: string;
38
38
  }>): string;
package/src/codegen.js CHANGED
@@ -1,4 +1,4 @@
1
- import { relative, resolve, dirname, join } from 'node:path';
1
+ import { path } from '@ecopages/file-system/path';
2
2
  function serializeEntry(entry) {
3
3
  return JSON.stringify(entry);
4
4
  }
@@ -107,14 +107,20 @@ ${guardBody}
107
107
  }
108
108
  `;
109
109
  }
110
- /** Renders the per-slug MDX import and source-file maps shared by both loaders. */
111
- function renderMdxLoaderMaps(outputDir, entrySources) {
110
+ /**
111
+ * Renders the per-slug MDX import and source-file maps shared by both loaders.
112
+ *
113
+ * @remarks
114
+ * Source files, which only name an entry in errors, are written relative to `rootDir`, so the emitted module
115
+ * names no path of the machine that built it.
116
+ */
117
+ function renderMdxLoaderMaps(outputDir, rootDir, entrySources) {
112
118
  const loaderLines = [];
113
119
  const entrySourceFilesBySlugLines = [];
114
120
  for (const { entry, filePath } of entrySources) {
115
- const importPath = relative(outputDir, filePath).split('\\').join('/');
121
+ const importPath = path.relative(outputDir, filePath);
116
122
  const escapedImportPath = importPath.replace(/'/g, "\\'");
117
- const sourceFile = filePath.split('\\').join('/');
123
+ const sourceFile = path.relative(rootDir, filePath);
118
124
  const escapedSourceFile = sourceFile.replace(/'/g, "\\'");
119
125
  loaderLines.push(`\t'${entry.slug}': () => import('${escapedImportPath}'),`);
120
126
  entrySourceFilesBySlugLines.push(`\t'${entry.slug}': '${escapedSourceFile}',`);
@@ -139,7 +145,7 @@ ${entrySourceFilesBySlugLines.join('\n')}
139
145
  * resolves `ecopages:content/<collection>/component` to this module so both
140
146
  * specifiers share one cache and one wrapped component per slug.
141
147
  */
142
- export function renderCollectionComponentsModule(collectionName, outputDir, entrySources) {
148
+ export function renderCollectionComponentsModule(collectionName, outputDir, rootDir, entrySources) {
143
149
  return `// This file is auto-generated by @ecopages/content-processor. Do not edit.
144
150
 
145
151
  import type { EcoComponent, PageDependenciesResult } from '@ecopages/core';
@@ -147,7 +153,7 @@ import { HttpError } from '@ecopages/core/errors';
147
153
 
148
154
  ${renderAttachMdxExportsHelper({ ownershipCheck: true })}
149
155
 
150
- ${renderMdxLoaderMaps(outputDir, entrySources)}
156
+ ${renderMdxLoaderMaps(outputDir, rootDir, entrySources)}
151
157
 
152
158
  const componentCache = new Map<string, EcoComponent<Record<string, unknown>>>();
153
159
  const componentLoadPromises = new Map<string, Promise<EcoComponent<Record<string, unknown>>>>();
@@ -202,7 +208,7 @@ export const loadComponent = Object.assign((slug: string) => getComponent(slug),
202
208
  * loads one browser-compiled MDX entry on demand and coalesces concurrent
203
209
  * requests; it is not a server renderer.
204
210
  */
205
- export function renderCollectionBrowserModule(collectionName, outputDir, entrySources) {
211
+ export function renderCollectionBrowserModule(collectionName, outputDir, rootDir, entrySources) {
206
212
  return `// This file is auto-generated by @ecopages/content-processor. Do not edit.
207
213
 
208
214
  import type { EcoComponent } from '@ecopages/core';
@@ -210,7 +216,7 @@ import { HttpError } from '@ecopages/core/errors';
210
216
 
211
217
  ${renderAttachMdxExportsHelper()}
212
218
 
213
- ${renderMdxLoaderMaps(outputDir, entrySources)}
219
+ ${renderMdxLoaderMaps(outputDir, rootDir, entrySources)}
214
220
 
215
221
  const componentLoadPromises = new Map<string, Promise<EcoComponent<Record<string, unknown>>>>();
216
222
 
@@ -246,13 +252,13 @@ export const loadComponent = Object.assign(loadEntry, { collection: ${JSON.strin
246
252
  */
247
253
  function resolveEntryTypeImport(entryType, rootDir, typesOutputFile) {
248
254
  const { module, name } = parseEntryTypeImport(entryType);
249
- const absoluteModule = resolve(rootDir, module);
250
- const srcDir = join(rootDir, 'src');
251
- const relativeToSrc = relative(srcDir, absoluteModule).split('\\').join('/');
255
+ const absoluteModule = path.resolve(rootDir, module);
256
+ const srcDir = path.join(rootDir, 'src');
257
+ const relativeToSrc = path.relative(srcDir, absoluteModule);
252
258
  if (!relativeToSrc.startsWith('..') && !relativeToSrc.startsWith('/')) {
253
259
  return { module: `@/${relativeToSrc}`, name };
254
260
  }
255
- let relativeModule = relative(dirname(typesOutputFile), absoluteModule).split('\\').join('/');
261
+ let relativeModule = path.relative(path.dirname(typesOutputFile), absoluteModule);
256
262
  if (!relativeModule.startsWith('.')) {
257
263
  relativeModule = `./${relativeModule}`;
258
264
  }
@@ -1,5 +1,4 @@
1
- import path from 'node:path';
2
- import { pathToFileURL } from 'node:url';
1
+ import { path } from '@ecopages/file-system/path';
3
2
  import { fileSystem } from '@ecopages/file-system';
4
3
  import { buildServerModule, contentHash, recordCollectionBuild } from '@ecopages/core/build';
5
4
  import { requireAppRuntime } from '@ecopages/core/integration';
@@ -32,7 +31,7 @@ export async function buildCollectionServerModule(input) {
32
31
  const artifact = {
33
32
  collectionName,
34
33
  outputPath,
35
- outputUrl: pathToFileURL(outputPath).href,
34
+ outputUrl: path.toFileUrl(outputPath).href,
36
35
  sourcePaths: [...ownedSourcePaths, sourceFilePath],
37
36
  buildIdentity,
38
37
  invalidationVersion,
@@ -33,8 +33,8 @@ export declare function createContentPlugin(collectionModules: Record<string, st
33
33
  * @remarks
34
34
  * It resolves entries and `/component` modules to generated files on disk so
35
35
  * relative MDX imports inside those files resolve as filesystem paths. A
36
- * virtual namespace would keep those imports inside `ecopages-content:` and
37
- * Rolldown would report them as missing. `/server` resolution is omitted so
36
+ * `\0` virtual module would leave those imports without a directory to resolve
37
+ * from. `/server` resolution is omitted so
38
38
  * the content server-boundary plugin can reject any server artifact that
39
39
  * remains browser-reachable.
40
40
  */
@@ -1,4 +1,4 @@
1
- import path from 'node:path';
1
+ import { path } from '@ecopages/file-system/path';
2
2
  import { shouldBuildPagesUnifiedGraph } from '@ecopages/core/build';
3
3
  import { CONTENT_COMPONENT_VIRTUAL_MODULE_PATTERN, CONTENT_SERVER_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PATTERN, parseCollectionSpecifier, } from './constants.js';
4
4
  export { parseCollectionSpecifier } from './constants.js';
@@ -36,16 +36,7 @@ function createContentResolvePlugin(collectionModules, collectionServerModules,
36
36
  const resolveGeneratedModule = async (args) => {
37
37
  await ensureCollectionsGenerated?.();
38
38
  const modulePath = resolveCollection(args.path);
39
- if (!modulePath) {
40
- return undefined;
41
- }
42
- if (options.namespace) {
43
- return {
44
- namespace: options.namespace,
45
- path: modulePath,
46
- };
47
- }
48
- return { path: modulePath };
39
+ return modulePath ? { path: modulePath } : undefined;
49
40
  };
50
41
  build.onResolve({ filter: CONTENT_VIRTUAL_MODULE_PATTERN }, resolveGeneratedModule);
51
42
  if (options.graph === 'server') {
@@ -61,16 +52,7 @@ function createContentResolvePlugin(collectionModules, collectionServerModules,
61
52
  return { path: compiledPath, external: true };
62
53
  }
63
54
  const modulePath = resolveCollection(args.path);
64
- if (!modulePath) {
65
- return undefined;
66
- }
67
- if (options.namespace) {
68
- return {
69
- namespace: options.namespace,
70
- path: modulePath,
71
- };
72
- }
73
- return { path: modulePath };
55
+ return modulePath ? { path: modulePath } : undefined;
74
56
  };
75
57
  build.onResolve({ filter: CONTENT_SERVER_VIRTUAL_MODULE_PATTERN }, resolveServerBackedModule);
76
58
  build.onResolve({ filter: CONTENT_COMPONENT_VIRTUAL_MODULE_PATTERN }, resolveServerBackedModule);
@@ -102,8 +84,8 @@ export function createContentPlugin(collectionModules, collectionServerModules,
102
84
  * @remarks
103
85
  * It resolves entries and `/component` modules to generated files on disk so
104
86
  * relative MDX imports inside those files resolve as filesystem paths. A
105
- * virtual namespace would keep those imports inside `ecopages-content:` and
106
- * Rolldown would report them as missing. `/server` resolution is omitted so
87
+ * `\0` virtual module would leave those imports without a directory to resolve
88
+ * from. `/server` resolution is omitted so
107
89
  * the content server-boundary plugin can reject any server artifact that
108
90
  * remains browser-reachable.
109
91
  */
@@ -1,4 +1,4 @@
1
- import { join, relative, resolve, sep } from 'node:path';
1
+ import { path } from '@ecopages/file-system/path';
2
2
  import { validateStandardSchema } from '@ecopages/core';
3
3
  import { VFile } from 'vfile';
4
4
  import { matter } from 'vfile-matter';
@@ -14,10 +14,10 @@ import { compareEntriesBySlug } from './sort.js';
14
14
  function slugFromRelativePath(relativePath, extensions) {
15
15
  for (const ext of extensions) {
16
16
  if (relativePath.endsWith(ext)) {
17
- return relativePath.slice(0, -ext.length).split(sep).join('/');
17
+ return relativePath.slice(0, -ext.length);
18
18
  }
19
19
  }
20
- return relativePath.split(sep).join('/');
20
+ return relativePath;
21
21
  }
22
22
  /**
23
23
  * Scans a content directory and exposes manifest metadata plus source file paths.
@@ -47,7 +47,7 @@ export class ContentScanner {
47
47
  const patterns = this.extensions.map((ext) => `**/*${ext}`);
48
48
  const relativePaths = await fileSystem.glob(patterns, { cwd: this.contentRoot });
49
49
  const files = await Promise.all(relativePaths.map(async (relativePath) => {
50
- const filePath = join(this.contentRoot, relativePath);
50
+ const filePath = path.join(this.contentRoot, relativePath);
51
51
  const slug = slugFromRelativePath(relativePath, this.extensions);
52
52
  const raw = await fileSystem.readFile(filePath);
53
53
  const entry = {
@@ -114,19 +114,19 @@ export class ContentScanner {
114
114
  * rewriting generated collection modules during dev HMR.
115
115
  */
116
116
  async updateEntryForPath(filePath, event) {
117
- const resolvedPath = resolve(filePath);
117
+ const resolvedPath = path.resolve(filePath);
118
118
  const cache = await this.getCache();
119
119
  if (event === 'delete') {
120
120
  return this.removeEntryAtPath(cache, resolvedPath);
121
121
  }
122
- const relativePath = relative(this.contentRoot, resolvedPath);
122
+ const relativePath = path.relative(this.contentRoot, resolvedPath);
123
123
  const nextSlug = slugFromRelativePath(relativePath, this.extensions);
124
124
  const previousSlug = this.findSlugForFilePath(cache, resolvedPath);
125
125
  return this.upsertEntryAtPath(cache, resolvedPath, nextSlug, previousSlug);
126
126
  }
127
127
  findSlugForFilePath(cache, filePath) {
128
128
  for (const [slug, currentPath] of cache.filePathsBySlug) {
129
- if (resolve(currentPath) === filePath) {
129
+ if (path.resolve(currentPath) === filePath) {
130
130
  return slug;
131
131
  }
132
132
  }
package/src/plugin.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * ContentProcessorPlugin
3
3
  * @module @ecopages/content-processor
4
4
  */
5
- import path from 'node:path';
5
+ import { path } from '@ecopages/file-system/path';
6
6
  import { fileSystem } from '@ecopages/file-system';
7
7
  import { isEcopagesEnvEnabled } from '@ecopages/core/processor';
8
8
  import { loadProductionServerModules, missingProductionServerModuleError } from '@ecopages/core/build';
@@ -125,7 +125,7 @@ export class ContentProcessorPlugin extends Processor {
125
125
  if (!this.context) {
126
126
  throw new Error('Content processor requires context to be set');
127
127
  }
128
- return path.relative(this.context.rootDir, filePath).split(path.sep).join('/');
128
+ return path.relative(this.context.rootDir, filePath);
129
129
  }
130
130
  resolveEmittedModule(manifest, sourceKey) {
131
131
  const relativePath = manifest.modules[sourceKey];
@@ -187,8 +187,8 @@ export class ContentProcessorPlugin extends Processor {
187
187
  const browserOutputFile = getCollectionBrowserCachePath(this.context.cache, collectionName);
188
188
  const outputDir = path.dirname(outputFile);
189
189
  const entriesOutput = renderCollectionEntriesModule(collectionName, manifest);
190
- const componentsOutput = renderCollectionComponentsModule(collectionName, outputDir, entrySources);
191
- const browserOutput = renderCollectionBrowserModule(collectionName, outputDir, entrySources);
190
+ const componentsOutput = renderCollectionComponentsModule(collectionName, outputDir, this.context.rootDir, entrySources);
191
+ const browserOutput = renderCollectionBrowserModule(collectionName, outputDir, this.context.rootDir, entrySources);
192
192
  this.writeGeneratedFile(outputFile, entriesOutput);
193
193
  this.writeGeneratedFile(serverOutputFile, componentsOutput);
194
194
  this.writeGeneratedFile(browserOutputFile, browserOutput);
@@ -271,7 +271,7 @@ export class ContentProcessorPlugin extends Processor {
271
271
  const normalizedPath = path.normalize(filePath);
272
272
  for (const [collectionName, definition] of Object.entries(this.getCollectionsConfig())) {
273
273
  const contentRoot = this.getCollectionContentRoot(definition.contentDir);
274
- if (normalizedPath.startsWith(contentRoot + path.sep) || normalizedPath === contentRoot) {
274
+ if (normalizedPath.startsWith(contentRoot + '/') || normalizedPath === contentRoot) {
275
275
  const changes = collectionChanges.get(collectionName) ?? {
276
276
  regenerate: false,
277
277
  changedEntries: [],