mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 07:38:12 -05:00
feat: new parameter --fail-if-no-match supported (#7409)
close #7403 --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
8
.changeset/lazy-pans-perform.md
Normal file
8
.changeset/lazy-pans-perform.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"@pnpm/common-cli-options-help": minor
|
||||
"@pnpm/config": minor
|
||||
"pnpm": minor
|
||||
---
|
||||
|
||||
Use `--fail-if-no-match` if you want the CLI fail if no packages were matched by the command [#7403](https://github.com/pnpm/pnpm/issues/7403).
|
||||
|
||||
@@ -116,6 +116,10 @@ export const FILTERING = {
|
||||
description: 'Restricts the scope to package names matching the given pattern similar to --filter, but it ignores devDependencies when searching for dependencies and dependents.',
|
||||
name: '--filter-prod <pattern>',
|
||||
},
|
||||
{
|
||||
description: 'If no projects are matched by the command, exit with exit code 1 (fail)',
|
||||
name: '--fail-if-no-match',
|
||||
},
|
||||
],
|
||||
title: 'Filtering options (run the command only on packages that satisfy at least one of the selectors)',
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ export interface Config {
|
||||
excludeLinksFromLockfile: boolean
|
||||
extraBinPaths: string[]
|
||||
extraEnv: Record<string, string>
|
||||
failIfNoMatch: boolean
|
||||
filter: string[]
|
||||
filterProd: string[]
|
||||
rawLocalConfig: Record<string, any>, // eslint-disable-line
|
||||
|
||||
@@ -145,7 +145,8 @@ export const types = Object.assign({
|
||||
'embed-readme': Boolean,
|
||||
'update-notifier': Boolean,
|
||||
'registry-supports-time-field': Boolean,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
'fail-if-no-match': Boolean,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as Partial<Record<keyof KebabCaseConfig, any>>, npmTypes.types)
|
||||
|
||||
export type CliOptions = Record<string, unknown> & { dir?: string }
|
||||
@@ -210,6 +211,7 @@ export async function getConfig (
|
||||
'enable-modules-dir': true,
|
||||
'exclude-links-from-lockfile': false,
|
||||
'extend-node-path': true,
|
||||
'fail-if-no-match': false,
|
||||
'fetch-retries': 2,
|
||||
'fetch-retry-factor': 10,
|
||||
'fetch-retry-maxtimeout': 60000,
|
||||
|
||||
@@ -53,6 +53,7 @@ export const GLOBAL_OPTIONS = pick([
|
||||
'workspace-packages',
|
||||
'workspace-root',
|
||||
'include-workspace-root',
|
||||
'fail-if-no-match',
|
||||
], allTypes)
|
||||
|
||||
export type CommandResponse = string | { output?: string, exitCode: number }
|
||||
|
||||
@@ -214,7 +214,7 @@ export async function main (inputArgv: string[]) {
|
||||
if (printLogs) {
|
||||
console.log(`No projects found in "${wsDir}"`)
|
||||
}
|
||||
process.exitCode = 0
|
||||
process.exitCode = config.failIfNoMatch ? 1 : 0
|
||||
return
|
||||
}
|
||||
config.allProjectsGraph = filterResults.allProjectsGraph
|
||||
@@ -223,7 +223,7 @@ export async function main (inputArgv: string[]) {
|
||||
if (printLogs) {
|
||||
console.log(`No projects matched the filters in "${wsDir}"`)
|
||||
}
|
||||
process.exitCode = 0
|
||||
process.exitCode = config.failIfNoMatch ? 1 : 0
|
||||
return
|
||||
}
|
||||
if (filterResults.unmatchedFilters.length !== 0 && printLogs) {
|
||||
|
||||
@@ -37,6 +37,11 @@ test('no projects matched the filters', async () => {
|
||||
const { stdout } = execPnpmSync(['list', '--filter=not-exists'])
|
||||
expect(stdout.toString()).toMatch(/^No projects matched the filters in/)
|
||||
}
|
||||
{
|
||||
const { stdout, status } = execPnpmSync(['list', '--filter=not-exists', '--fail-if-no-match'])
|
||||
expect(stdout.toString()).toMatch(/^No projects matched the filters in/)
|
||||
expect(status).toBe(1)
|
||||
}
|
||||
{
|
||||
const { stdout } = execPnpmSync(['list', '--filter=not-exists', '--parseable'])
|
||||
expect(stdout.toString()).toBe('') // don't print anything if --parseable is used
|
||||
|
||||
Reference in New Issue
Block a user