mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-29 04:21:39 -04:00
* feat: use JSON for npm registry metadata cache instead of msgpack Switch the on-disk package metadata cache from msgpack (.mpk) to JSON (.json). When metadata is not filtered, the raw JSON response from the registry is written directly to disk with cachedAt injected, avoiding a parse-then-serialize round-trip. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: update lockfileOnly test to use .json metadata extension Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Update resolving/npm-resolver/src/pickPackage.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
83 lines
2.3 KiB
TypeScript
83 lines
2.3 KiB
TypeScript
import path from 'path'
|
|
import { prepare } from '@pnpm/prepare'
|
|
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
|
|
import execa from 'execa'
|
|
import { cache } from '@pnpm/cache.commands'
|
|
import { sync as rimraf } from '@zkochan/rimraf'
|
|
|
|
const pnpmBin = path.join(import.meta.dirname, '../../../pnpm/bin/pnpm.mjs')
|
|
const REGISTRY = `http://localhost:${REGISTRY_MOCK_PORT}/`
|
|
|
|
describe('cache', () => {
|
|
let cacheDir: string
|
|
let storeDir: string
|
|
beforeAll(async () => {
|
|
prepare()
|
|
cacheDir = path.resolve('cache')
|
|
storeDir = path.resolve('store')
|
|
|
|
await execa('node', [
|
|
pnpmBin,
|
|
'add',
|
|
'is-negative@2.1.0',
|
|
`--store-dir=${storeDir}`,
|
|
`--cache-dir=${cacheDir}`,
|
|
'--config.resolution-mode=highest',
|
|
`--registry=${REGISTRY}`,
|
|
])
|
|
rimraf('node_modules')
|
|
rimraf('pnpm-lock.yaml')
|
|
await execa('node', [
|
|
pnpmBin,
|
|
'add',
|
|
'is-negative@2.1.0',
|
|
'is-positive@1.0.0',
|
|
`--store-dir=${storeDir}`,
|
|
`--cache-dir=${cacheDir}`,
|
|
'--config.resolution-mode=highest',
|
|
])
|
|
})
|
|
test('list all metadata from the cache', async () => {
|
|
const result = await cache.handler({
|
|
cacheDir,
|
|
cliOptions: {},
|
|
pnpmHomeDir: storeDir,
|
|
}, ['list'])
|
|
|
|
expect(result).toBe(`localhost+${REGISTRY_MOCK_PORT}/is-negative.json
|
|
registry.npmjs.org/is-negative.json
|
|
registry.npmjs.org/is-positive.json`)
|
|
})
|
|
test('list all metadata from the cache related to the specified registry', async () => {
|
|
const result = await cache.handler({
|
|
cacheDir,
|
|
cliOptions: {
|
|
registry: 'https://registry.npmjs.org/',
|
|
},
|
|
pnpmHomeDir: storeDir,
|
|
}, ['list'])
|
|
|
|
expect(result).toBe(`registry.npmjs.org/is-negative.json
|
|
registry.npmjs.org/is-positive.json`)
|
|
})
|
|
test('list all metadata from the cache that matches a pattern', async () => {
|
|
const result = await cache.handler({
|
|
cacheDir,
|
|
cliOptions: {},
|
|
pnpmHomeDir: storeDir,
|
|
}, ['list', '*-positive'])
|
|
|
|
expect(result).toBe('registry.npmjs.org/is-positive.json')
|
|
})
|
|
test('list registries', async () => {
|
|
const result = await cache.handler({
|
|
cacheDir,
|
|
cliOptions: {},
|
|
pnpmHomeDir: storeDir,
|
|
}, ['list-registries'])
|
|
|
|
expect(result).toBe(`localhost+${REGISTRY_MOCK_PORT}
|
|
registry.npmjs.org`)
|
|
})
|
|
})
|