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

feat: remove scoped package / when pattern without / #1168

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion src/lib/filterAndReject.ts
Expand Up @@ -31,7 +31,14 @@ function composeFilter(filterPattern: FilterRejectPattern): (name: string, versi
// glob string
else {
const patterns = filterPattern.split(/[\s,]+/)
predicate = (dependencyName: string) => patterns.some(pattern => minimatch(dependencyName, pattern))
predicate = (dependencyName: string) =>
patterns.some(
pattern =>
minimatch(dependencyName, pattern) ||
(!pattern.includes('/') &&
dependencyName.includes('/') &&
minimatch(dependencyName.replace(/\//g, '_'), pattern)),
)
}
}
// array
Expand Down
50 changes: 50 additions & 0 deletions test/filter.test.ts
Expand Up @@ -41,6 +41,56 @@ describe('filter', () => {
upgraded.should.have.property('lodash.filter')
})

it('filter with wildcard for scoped package', async () => {
// eslint-disable-next-line jsdoc/require-jsdoc
const withFilter = (filter: string[]) =>
ncu({
packageData: {
dependencies: {
vite: '1.0.0',
'@vitejs/plugin-react': '1.0.0',
'@vitejs/plugin-vue': '1.0.0',
},
},
filter,
}) as Promise<Index<string>>

{
const upgraded = await withFilter(['vite'])
upgraded.should.have.property('vite')
upgraded.should.not.have.property('@vitejs/plugin-react')
upgraded.should.not.have.property('@vitejs/plugin-vue')
}

{
const upgraded = await withFilter(['@vite*'])
upgraded.should.not.have.property('vite')
upgraded.should.have.property('@vitejs/plugin-react')
upgraded.should.have.property('@vitejs/plugin-vue')
}

{
const upgraded = await withFilter(['*vite*'])
upgraded.should.have.property('vite')
upgraded.should.have.property('@vitejs/plugin-react')
upgraded.should.have.property('@vitejs/plugin-vue')
}

{
const upgraded = await withFilter(['*vite*/*react*'])
upgraded.should.not.have.property('vite')
upgraded.should.have.property('@vitejs/plugin-react')
upgraded.should.not.have.property('@vitejs/plugin-vue')
}

{
const upgraded = await withFilter(['*vite*vue*'])
upgraded.should.not.have.property('vite')
upgraded.should.not.have.property('@vitejs/plugin-react')
upgraded.should.have.property('@vitejs/plugin-vue')
}
})

it('filter with negated wildcard', async () => {
const upgraded = (await ncu({
packageData: {
Expand Down