Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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')
})