mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-18 13:51:38 -04:00
fix(clean): ignore lockfile setting unless flag is passed (#11431)
Keep pnpm clean from removing pnpm-lock.yaml just because the workspace config sets lockfile: true. The lockfile cleanup now follows the command-line --lockfile option. Co-authored-by: cyphercodes <cyphercodes@users.noreply.github.com>
This commit is contained in:
5
.changeset/clean-lockfile-cli-option.md
Normal file
5
.changeset/clean-lockfile-cli-option.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Do not remove `pnpm-lock.yaml` during `pnpm clean` when `lockfile: true` is configured in `pnpm-workspace.yaml`. The lockfile is only removed when the `--lockfile` option is passed to `pnpm clean`.
|
||||
@@ -13,7 +13,7 @@ export const commandNames = ['clean', 'purge']
|
||||
|
||||
export const overridableByScript = true
|
||||
|
||||
export const rcOptionsTypes = cliOptionsTypes
|
||||
export const rcOptionsTypes = (): Record<string, unknown> => ({})
|
||||
|
||||
export function cliOptionsTypes (): Record<string, unknown> {
|
||||
return {
|
||||
@@ -58,11 +58,14 @@ export async function handler (
|
||||
virtualStoreDir?: string
|
||||
workspaceDir?: string
|
||||
workspacePackagePatterns?: string[]
|
||||
cliOptions?: {
|
||||
lockfile?: boolean
|
||||
}
|
||||
}
|
||||
): Promise<void> {
|
||||
const modulesDir = opts.modulesDir ?? 'node_modules'
|
||||
const rootDir = opts.workspaceDir ?? opts.dir
|
||||
const cleanOpts = { modulesDir, removeLockfile: opts.lockfile }
|
||||
const cleanOpts = { modulesDir, removeLockfile: opts.cliOptions?.lockfile === true }
|
||||
const dirs = await getProjectDirs(opts)
|
||||
await Promise.all(dirs.map(cleanProjectDir.bind(null, cleanOpts)))
|
||||
if (opts.virtualStoreDir) {
|
||||
|
||||
@@ -70,6 +70,20 @@ test('pnpm clean preserves lockfile by default', () => {
|
||||
expect(fs.existsSync('pnpm-lock.yaml')).toBe(true)
|
||||
})
|
||||
|
||||
test('pnpm clean preserves lockfile when pnpm-workspace.yaml sets lockfile', () => {
|
||||
tempDir()
|
||||
fs.writeFileSync('package.json', '{}', 'utf8')
|
||||
writeYamlFileSync('pnpm-workspace.yaml', { lockfile: true })
|
||||
fs.writeFileSync('pnpm-lock.yaml', 'lockfileVersion: 9')
|
||||
fs.mkdirSync('node_modules/.pnpm', { recursive: true })
|
||||
|
||||
const result = execPnpmSync(['clean'])
|
||||
expect(result.status).toBe(0)
|
||||
|
||||
expect(fs.existsSync('node_modules/.pnpm')).toBe(false)
|
||||
expect(fs.existsSync('pnpm-lock.yaml')).toBe(true)
|
||||
})
|
||||
|
||||
test('pnpm clean --lockfile removes lockfile', () => {
|
||||
tempDir()
|
||||
fs.writeFileSync('package.json', '{}', 'utf8')
|
||||
|
||||
Reference in New Issue
Block a user