fix(prune): add --ignore-scripts arg to prune command (#7836)

close #5030
This commit is contained in:
Colin Casey
2024-03-27 20:05:07 -03:00
committed by GitHub
parent 670ed188df
commit d4e13ca969
3 changed files with 52 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-installation": minor
---
Add `--ignore-scripts` argument to `prune` command

View File

@@ -1,5 +1,5 @@
import { docsUrl } from '@pnpm/cli-utils'
import { UNIVERSAL_OPTIONS } from '@pnpm/common-cli-options-help'
import { UNIVERSAL_OPTIONS, OPTIONS } from '@pnpm/common-cli-options-help'
import { types as allTypes } from '@pnpm/config'
import pick from 'ramda/src/pick'
import renderHelp from 'render-help'
@@ -12,6 +12,7 @@ export function cliOptionsTypes () {
'dev',
'optional',
'production',
'ignore-scripts',
], allTypes)
}
@@ -33,6 +34,7 @@ export function help () {
description: 'Remove the packages specified in `optionalDependencies`',
name: '--no-optional',
},
OPTIONS.ignoreScripts,
...UNIVERSAL_OPTIONS,
],
},

View File

@@ -3,6 +3,8 @@ import { add, install, link, prune } from '@pnpm/plugin-commands-installation'
import { prepare } from '@pnpm/prepare'
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
import { fixtures } from '@pnpm/test-fixtures'
import { createTestIpcServer } from '@pnpm/test-ipc-server'
import fs from 'fs'
const REGISTRY_URL = `http://localhost:${REGISTRY_MOCK_PORT}`
const f = fixtures(__dirname)
@@ -110,3 +112,45 @@ test('prune removes dev dependencies', async () => {
project.hasNot('is-negative')
project.hasNot('.pnpm/is-negative@1.0.0')
})
test('prune: ignores all the lifecycle scripts when --ignore-scripts is used', async () => {
await using server = await createTestIpcServer()
prepare({
name: 'test-prune-with-ignore-scripts',
version: '0.0.0',
scripts: {
// eslint-disable:object-literal-sort-keys
preinstall: server.sendLineScript('preinstall'),
prepare: server.sendLineScript('prepare'),
postinstall: server.sendLineScript('postinstall'),
// eslint-enable:object-literal-sort-keys
},
})
const storeDir = path.resolve('store')
const opts = {
...DEFAULT_OPTIONS,
ignoreScripts: true,
cacheDir: path.resolve('cache'),
dir: process.cwd(),
linkWorkspacePackages: true,
storeDir,
}
await install.handler(opts)
await prune.handler(opts)
expect(fs.existsSync('package.json')).toBeTruthy()
expect(server.getLines()).toStrictEqual([])
})
test('cliOptionsTypes', () => {
expect(prune.cliOptionsTypes()).toHaveProperty('production')
expect(prune.cliOptionsTypes()).toHaveProperty('dev')
expect(prune.cliOptionsTypes()).toHaveProperty('ignore-scripts')
expect(prune.cliOptionsTypes()).toHaveProperty('optional')
})