Skip to content

Commit

Permalink
Support multiple --filter and --reject options (#1125).
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Feb 22, 2023
1 parent 9636fdb commit fa33af3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ const cliOptions: CLIOption[] = [
description:
'Include only package names matching the given string, wildcard, glob, comma-or-space-delimited list, /regex/, or predicate function.',
type: 'string | string[] | RegExp | RegExp[] | FilterFunction',
parse: (value, accum) => [...(accum || []), value],
},
{
long: 'filterVersion',
Expand Down Expand Up @@ -558,6 +559,7 @@ When --packageManager staticRegistry is set, --registry must specify a path to a
description:
'Exclude packages matching the given string, wildcard, glob, comma-or-space-delimited list, /regex/, or predicate function.',
type: 'string | string[] | RegExp | RegExp[] | FilterFunction',
parse: (value, accum) => [...(accum || []), value],
},
{
long: 'rejectVersion',
Expand Down
36 changes: 36 additions & 0 deletions test/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,24 @@ describe('filter', () => {
upgraded.should.have.property('lodash.map')
upgraded.should.have.property('lodash.filter')
})

it('allow multiple --filter options', async () => {
const pkgData = {
dependencies: {
'ncu-test-v2': '^1.0.0',
'ncu-test-tag': '^1.0.0',
},
}

const output = await spawn(
'node',
[bin, '--jsonUpgraded', '--stdin', '--filter', 'ncu-test-v2', '--filter', 'ncu-test-tag'],
JSON.stringify(pkgData),
)
const upgraded = JSON.parse(output)
upgraded.should.have.property('ncu-test-v2')
upgraded.should.have.property('ncu-test-tag')
})
})
})

Expand Down Expand Up @@ -309,5 +327,23 @@ describe('reject', () => {
pkgData.should.have.property('ncu-test-v2')
pkgData.should.have.property('ncu-test-tag')
})

it('allow multiple --reject options', async () => {
const pkgData = {
dependencies: {
'ncu-test-v2': '^1.0.0',
'ncu-test-tag': '^1.0.0',
},
}

const output = await spawn(
'node',
[bin, '--jsonUpgraded', '--stdin', '--reject', 'ncu-test-v2', '--reject', 'ncu-test-tag'],
JSON.stringify(pkgData),
)
const upgraded = JSON.parse(output)
upgraded.should.not.have.property('ncu-test-v2')
upgraded.should.not.have.property('ncu-test-tag')
})
})
})

0 comments on commit fa33af3

Please sign in to comment.