Skip to content

Commit

Permalink
Merge branch 'main' into feat/bun
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine authored Sep 12, 2023
2 parents b8c6569 + 79fc218 commit b1716a9
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 42 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "npm-check-updates",
"version": "16.13.3",
"version": "16.13.4",
"author": "Tomas Junnonen <[email protected]>",
"license": "Apache-2.0",
"contributors": [
Expand Down
8 changes: 4 additions & 4 deletions src/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ const cliOptions: CLIOption[] = [
arg: 'p',
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',
type: 'string | RegExp | (string | RegExp)[] | FilterFunction',
parse: (value, accum) => [...(accum || []), value],
},
{
Expand All @@ -519,7 +519,7 @@ const cliOptions: CLIOption[] = [
long: 'filterVersion',
arg: 'p',
description: 'Filter on package version using comma-or-space-delimited list, /regex/, or predicate function.',
type: 'string | string[] | RegExp | RegExp[] | FilterFunction',
type: 'string | RegExp | (string | RegExp)[] | FilterFunction',
parse: (value, accum) => [...(accum || []), value],
},
{
Expand Down Expand Up @@ -660,14 +660,14 @@ const cliOptions: CLIOption[] = [
arg: 'p',
description:
'Exclude packages matching the given string, wildcard, glob, comma-or-space-delimited list, /regex/, or predicate function.',
type: 'string | string[] | RegExp | RegExp[] | FilterFunction',
type: 'string | RegExp | (string | RegExp)[] | FilterFunction',
parse: (value, accum) => [...(accum || []), value],
},
{
long: 'rejectVersion',
arg: 'p',
description: 'Exclude package.json versions using comma-or-space-delimited list, /regex/, or predicate function.',
type: 'string | string[] | RegExp | RegExp[] | FilterFunction',
type: 'string | RegExp | (string | RegExp)[] | FilterFunction',
parse: (value, accum) => [...(accum || []), value],
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/filterAndReject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function composeFilter(filterPattern: FilterPattern): (name: string, versionSpec
// array
else if (Array.isArray(filterPattern)) {
predicate = (dependencyName: string, versionSpec: string) =>
filterPattern.some((subpattern: string | RegExp) => composeFilter(subpattern)(dependencyName, versionSpec))
filterPattern.some(subpattern => composeFilter(subpattern)(dependencyName, versionSpec))
}
// raw RegExp
else if (filterPattern instanceof RegExp) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/initOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function parseFilterExpression(filterExpression: FilterPattern | undefined): Fil
Array.isArray(filterExpression) &&
(filterExpression.length === 0 || typeof filterExpression[0] === 'string')
) {
const filtered = (filterExpression as string[]).map(s => s.trim()).filter(x => x)
const filtered = filterExpression.map(s => (typeof s === 'string' ? s.trim() : s)).filter(x => x)
return filtered.length > 0 ? filtered : undefined
} else {
return filterExpression
Expand Down
2 changes: 1 addition & 1 deletion src/types/FilterPattern.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FilterFunction } from './FilterFunction'

/** Supported patterns for the --filter and --reject options. */
export type FilterPattern = string | string[] | RegExp | RegExp[] | FilterFunction
export type FilterPattern = string | RegExp | (string | RegExp)[] | FilterFunction
60 changes: 32 additions & 28 deletions src/types/RunOptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,20 @@
{
"$ref": "#/definitions/RegExp"
},
{
"items": {
"type": "string"
},
"type": "array"
},
{
"description": "Supported function for the --filter and --reject options.",
"type": "object"
},
{
"items": {
"$ref": "#/definitions/RegExp"
"anyOf": [
{
"$ref": "#/definitions/RegExp"
},
{
"type": "string"
}
]
},
"type": "array"
},
Expand All @@ -262,19 +263,20 @@
{
"$ref": "#/definitions/RegExp"
},
{
"items": {
"type": "string"
},
"type": "array"
},
{
"description": "Supported function for the --filter and --reject options.",
"type": "object"
},
{
"items": {
"$ref": "#/definitions/RegExp"
"anyOf": [
{
"$ref": "#/definitions/RegExp"
},
{
"type": "string"
}
]
},
"type": "array"
},
Expand Down Expand Up @@ -380,19 +382,20 @@
{
"$ref": "#/definitions/RegExp"
},
{
"items": {
"type": "string"
},
"type": "array"
},
{
"description": "Supported function for the --filter and --reject options.",
"type": "object"
},
{
"items": {
"$ref": "#/definitions/RegExp"
"anyOf": [
{
"$ref": "#/definitions/RegExp"
},
{
"type": "string"
}
]
},
"type": "array"
},
Expand All @@ -407,19 +410,20 @@
{
"$ref": "#/definitions/RegExp"
},
{
"items": {
"type": "string"
},
"type": "array"
},
{
"description": "Supported function for the --filter and --reject options.",
"type": "object"
},
{
"items": {
"$ref": "#/definitions/RegExp"
"anyOf": [
{
"$ref": "#/definitions/RegExp"
},
{
"type": "string"
}
]
},
"type": "array"
},
Expand Down
8 changes: 4 additions & 4 deletions src/types/RunOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ export interface RunOptions {
errorLevel?: number

/** Include only package names matching the given string, wildcard, glob, comma-or-space-delimited list, /regex/, or predicate function. */
filter?: string | string[] | RegExp | RegExp[] | FilterFunction
filter?: string | RegExp | (string | RegExp)[] | FilterFunction

/** Filters out upgrades based on a user provided function. Run "ncu --help --filterResults" for details. */
filterResults?: FilterResultsFunction

/** Filter on package version using comma-or-space-delimited list, /regex/, or predicate function. */
filterVersion?: string | string[] | RegExp | RegExp[] | FilterFunction
filterVersion?: string | RegExp | (string | RegExp)[] | FilterFunction

/** Modify the output formatting or show additional information. Specify one or more comma-delimited values: group, ownerChanged, repo, time, lines. Run "ncu --help --format" for details. */
format?: string[]
Expand Down Expand Up @@ -146,10 +146,10 @@ export interface RunOptions {
registryType?: 'npm' | 'json'

/** Exclude packages matching the given string, wildcard, glob, comma-or-space-delimited list, /regex/, or predicate function. */
reject?: string | string[] | RegExp | RegExp[] | FilterFunction
reject?: string | RegExp | (string | RegExp)[] | FilterFunction

/** Exclude package.json versions using comma-or-space-delimited list, /regex/, or predicate function. */
rejectVersion?: string | string[] | RegExp | RegExp[] | FilterFunction
rejectVersion?: string | RegExp | (string | RegExp)[] | FilterFunction

/** Remove version ranges from the final package version. */
removeRange?: boolean
Expand Down
19 changes: 19 additions & 0 deletions test/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,25 @@ describe('filter', () => {
upgraded.should.have.property('fp-and-or')
})

it('filter with array of mixed strings and regex', async () => {
const upgraded = (await ncu({
packageData: {
dependencies: {
'fp-and-or': '0.1.0',
lodash: '2.0.0',
'lodash.map': '2.0.0',
'lodash.filter': '2.0.0',
},
},
filter: ['fp-and-or', /lodash\..*/],
})) as Index<string>
upgraded.should.deep.equal({
'fp-and-or': '99.9.9',
'lodash.map': '99.9.9',
'lodash.filter': '99.9.9',
})
})

it('filter with array of regex strings', async () => {
const upgraded = (await ncu({
packageData: {
Expand Down

0 comments on commit b1716a9

Please sign in to comment.