mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-30 11:38:41 -04:00
The metadata cache files now use a two-line NDJSON format: - Line 1: cache headers (etag, modified, cachedAt) ~100 bytes - Line 2: raw registry metadata JSON (unchanged) This allows loadMetaHeaders to read only the first 1 KB of the file to extract conditional-request headers (etag, modified), avoiding the cost of reading and parsing multi-MB metadata files when the registry returns 200 and the old metadata would be discarded. Also moves cache directories to v11/ namespace (v11/metadata, v11/metadata-full, v11/metadata-full-filtered) since the format is not backwards compatible.
24 lines
966 B
TypeScript
24 lines
966 B
TypeScript
import fs from 'node:fs'
|
|
|
|
import getRegistryName from 'encode-registry'
|
|
import { glob } from 'tinyglobby'
|
|
|
|
export async function cacheListRegistries (opts: { cacheDir: string, registry?: string, registries?: boolean }): Promise<string> {
|
|
return fs.readdirSync(opts.cacheDir).sort().join('\n')
|
|
}
|
|
|
|
export async function cacheList (opts: { cacheDir: string, registry?: string, registries?: boolean }, filter: string[]): Promise<string> {
|
|
const metaFiles = await findMetadataFiles(opts, filter)
|
|
return metaFiles.sort().join('\n')
|
|
}
|
|
|
|
export async function findMetadataFiles (opts: { cacheDir: string, registry?: string }, filter: string[]): Promise<string[]> {
|
|
const prefix = opts.registry ? `${getRegistryName(opts.registry)}` : '*'
|
|
const patterns = filter.length ? filter.map((filter) => `${prefix}/${filter}.jsonl`) : [`${prefix}/**`]
|
|
const metaFiles = await glob(patterns, {
|
|
cwd: opts.cacheDir,
|
|
expandDirectories: false,
|
|
})
|
|
return metaFiles
|
|
}
|