Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/loaders/markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,26 @@ function emit(this: any, opts: IMdLoaderOptions, ret: IMdTransformerResult) {
}
}

const fileHashCache = new Map<string, { signature: string; hash: string }>();

function getCachedFileHash(file: string) {
const stat = fs.statSync(file, { bigint: true });
const signature = `${stat.mtimeNs}:${stat.size}`;
const cached = fileHashCache.get(file);

if (cached?.signature === signature) {
return cached.hash;
}

const hash = getContentHash(fs.readFileSync(file, 'utf-8'));
fileHashCache.set(file, { signature, hash });

return hash;
}

function getDepsCacheKey(deps: (typeof depsMapping)['0'] = []) {
return JSON.stringify(
deps.map(
(file) => `${file}:${getContentHash(fs.readFileSync(file, 'utf-8'))}`,
),
deps.map((file) => `${file}:${getCachedFileHash(file)}`),
);
}

Expand Down
Loading