Files
pnpm/pkg-manager/core/test/install/modulesCache.ts
Zoltan Kochan 5d5818e44f style: enforce node: protocol for builtin imports (#10951)
Add n/prefer-node-protocol rule and autofix all bare builtin imports
to use the node: prefix. Simplify the simple-import-sort builtins
pattern to just ^node: since all imports now use the prefix.
2026-03-13 07:59:51 +01:00

86 lines
2.6 KiB
TypeScript

import path from 'node:path'
import {
addDependenciesToPackage,
install,
mutateModulesInSingleProject,
} from '@pnpm/core'
import { readModulesManifest, writeModulesManifest } from '@pnpm/modules-yaml'
import { prepareEmpty } from '@pnpm/prepare'
import type { ProjectRootDir } from '@pnpm/types'
import { testDefaults } from '../utils/index.js'
test('the modules cache is pruned when it expires', async () => {
const project = prepareEmpty()
let { updatedManifest: manifest } = await install({
dependencies: {
'is-positive': '1.0.0',
'is-negative': '1.0.0',
},
}, testDefaults())
const modulesDir = path.resolve('node_modules')
const modulesFile = await readModulesManifest(modulesDir)!
expect(modulesFile?.prunedAt).toBeTruthy()
manifest = (await mutateModulesInSingleProject({
dependencyNames: ['is-negative'],
manifest,
mutation: 'uninstallSome',
rootDir: process.cwd() as ProjectRootDir,
}, testDefaults({}))).updatedProject.manifest
project.has('.pnpm/is-negative@1.0.0/node_modules/is-negative')
const prunedAt = new Date()
prunedAt.setMinutes(prunedAt.getMinutes() - 3)
modulesFile!.prunedAt = prunedAt.toString()
await writeModulesManifest(modulesDir, modulesFile as any) // eslint-disable-line
await addDependenciesToPackage(manifest,
['is-negative@2.0.0'],
testDefaults({ modulesCacheMaxAge: 2 })
)
project.hasNot('.pnpm/is-negative@1.0.0/node_modules/is-negative')
})
test('the modules cache is pruned when it expires and headless install is used', async () => {
const project = prepareEmpty()
let { updatedManifest: manifest } = await install({
dependencies: {
'is-positive': '1.0.0',
'is-negative': '1.0.0',
},
}, testDefaults())
const modulesDir = path.resolve('node_modules')
const modulesFile = await readModulesManifest(modulesDir)
expect(modulesFile?.prunedAt).toBeTruthy()
manifest = (await mutateModulesInSingleProject({
dependencyNames: ['is-negative'],
manifest,
mutation: 'uninstallSome',
rootDir: process.cwd() as ProjectRootDir,
}, testDefaults({ lockfileOnly: true }))).updatedProject.manifest
manifest = (await install(manifest, testDefaults({ frozenLockfile: true }))).updatedManifest
project.has('.pnpm/is-negative@1.0.0/node_modules/is-negative')
const prunedAt = new Date()
prunedAt.setMinutes(prunedAt.getMinutes() - 3)
modulesFile!.prunedAt = prunedAt.toString()
await writeModulesManifest(modulesDir, modulesFile as any) // eslint-disable-line
await install(manifest, testDefaults({ frozenLockfile: true, modulesCacheMaxAge: 2 }))
project.hasNot('.pnpm/is-negative@1.0.0/node_modules/is-negative')
})