diff --git a/.changeset/plenty-tomatoes-battle.md b/.changeset/plenty-tomatoes-battle.md new file mode 100644 index 00000000000..b986f227b4f --- /dev/null +++ b/.changeset/plenty-tomatoes-battle.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-installation": minor +--- + +Add `--ignore-scripts` argument to `prune` command diff --git a/pkg-manager/plugin-commands-installation/src/prune.ts b/pkg-manager/plugin-commands-installation/src/prune.ts index cb2bb5eb949..621969daa5a 100644 --- a/pkg-manager/plugin-commands-installation/src/prune.ts +++ b/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' @@ -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, ], }, diff --git a/pkg-manager/plugin-commands-installation/test/prune.ts b/pkg-manager/plugin-commands-installation/test/prune.ts index 019cf0557e7..511f55de407 100644 --- a/pkg-manager/plugin-commands-installation/test/prune.ts +++ b/pkg-manager/plugin-commands-installation/test/prune.ts @@ -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') +})