diff --git a/.changeset/fresh-crabs-beam.md b/.changeset/fresh-crabs-beam.md new file mode 100644 index 000000000..307893ccf --- /dev/null +++ b/.changeset/fresh-crabs-beam.md @@ -0,0 +1,5 @@ +--- +'fumadocs-mdx': patch +--- + +Change cache path of manifest files diff --git a/packages/mdx/src/loader-mdx.ts b/packages/mdx/src/loader-mdx.ts index 5eafcbc7c..c42cfbe7f 100644 --- a/packages/mdx/src/loader-mdx.ts +++ b/packages/mdx/src/loader-mdx.ts @@ -8,7 +8,7 @@ import { findCollectionId } from '@/utils/find-collection'; import { getConfigHash, loadConfigCached } from '@/config/cached'; import { buildMDX } from '@/utils/build-mdx'; import { getDefaultMDXOptions, type TransformContext } from '@/config'; -import { getKey } from '@/map/manifest'; +import { getManifestEntryPath } from '@/map/manifest'; import { formatError } from '@/utils/format-error'; import { getGitTimestamp } from './utils/git-timestamp'; @@ -154,7 +154,7 @@ export default async function loader( if (config.global?.generateManifest) { await fs.mkdir('.next/cache/fumadocs', { recursive: true }); await fs.writeFile( - path.resolve('.next/cache/fumadocs', `${getKey(filePath)}.json`), + getManifestEntryPath(filePath), JSON.stringify({ path: filePath, data: file.data, diff --git a/packages/mdx/src/map/manifest.ts b/packages/mdx/src/map/manifest.ts index ac481b8a7..b3747bd53 100644 --- a/packages/mdx/src/map/manifest.ts +++ b/packages/mdx/src/map/manifest.ts @@ -1,5 +1,4 @@ import fs from 'node:fs'; -import { createHash } from 'node:crypto'; import path from 'node:path'; import { type LoadedConfig } from '@/config/load'; import type { MetaFile } from '@/loader-mdx'; @@ -11,8 +10,13 @@ export interface Manifest { })[]; } -export function getKey(key: string): string { - return createHash('sha256').update(key).digest('hex'); +export function getManifestEntryPath(originalPath: string): string { + const toName = path + .relative(process.cwd(), originalPath) + .replaceAll(`..${path.sep}`, '-') + .replaceAll(path.sep, '_'); + + return path.resolve('.next/cache/fumadocs', `${toName}.json`); } export function writeManifest(to: string, config: LoadedConfig): void { @@ -24,9 +28,7 @@ export function writeManifest(to: string, config: LoadedConfig): void { if (type === 'meta') continue; try { - const content = fs.readFileSync( - path.resolve('.next/cache/fumadocs', `${getKey(file)}.json`), - ); + const content = fs.readFileSync(getManifestEntryPath(file)); const meta = JSON.parse(content.toString()) as MetaFile; output.files.push({