mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 15:48:06 -05:00
fix(prune): add --ignore-scripts arg to prune command (#7836)
close #5030
This commit is contained in:
5
.changeset/plenty-tomatoes-battle.md
Normal file
5
.changeset/plenty-tomatoes-battle.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-installation": minor
|
||||
---
|
||||
|
||||
Add `--ignore-scripts` argument to `prune` command
|
||||
@@ -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,
|
||||
],
|
||||
},
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user