Skip to content

Commit

Permalink
fix(prune): add --ignore-scripts arg to prune command (#7836)
Browse files Browse the repository at this point in the history
close #5030
  • Loading branch information
colincasey committed Mar 27, 2024
1 parent 670ed18 commit d4e13ca
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/plenty-tomatoes-battle.md
@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-installation": minor
---

Add `--ignore-scripts` argument to `prune` command
4 changes: 3 additions & 1 deletion pkg-manager/plugin-commands-installation/src/prune.ts
@@ -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'
Expand All @@ -12,6 +12,7 @@ export function cliOptionsTypes () {
'dev',
'optional',
'production',
'ignore-scripts',
], allTypes)
}

Expand All @@ -33,6 +34,7 @@ export function help () {
description: 'Remove the packages specified in `optionalDependencies`',
name: '--no-optional',
},
OPTIONS.ignoreScripts,
...UNIVERSAL_OPTIONS,
],
},
Expand Down
44 changes: 44 additions & 0 deletions pkg-manager/plugin-commands-installation/test/prune.ts
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
})

0 comments on commit d4e13ca

Please sign in to comment.