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 all commits
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
16 changes: 14 additions & 2 deletions src/lib/filterAndReject.ts
@@ -1,4 +1,4 @@
import { and } from 'fp-and-or'
import { and, or } from 'fp-and-or'
import identity from 'lodash/identity'
import negate from 'lodash/negate'
import minimatch from 'minimatch'
Expand Down Expand Up @@ -31,7 +31,19 @@ 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) => {
/** Returns true if the pattern matches an unscoped dependency name. */
const matchUnscoped = (pattern: string) => minimatch(dependencyName, pattern)

/** Returns true if the pattern matches a scoped dependency name. */
const matchScoped = (pattern: string) =>
!pattern.includes('/') &&
dependencyName.includes('/') &&
minimatch(dependencyName.replace(/\//g, '_'), pattern)

// return true if any of the provided patterns match the dependency name
return patterns.some(or(matchUnscoped, matchScoped))
}
}
}
// array
Expand Down
45 changes: 45 additions & 0 deletions test/filter.test.ts
Expand Up @@ -41,6 +41,51 @@ describe('filter', () => {
upgraded.should.have.property('lodash.filter')
})

it('filter with wildcard for scoped package', async () => {
const pkg = {
dependencies: {
vite: '1.0.0',
'@vitejs/plugin-react': '1.0.0',
'@vitejs/plugin-vue': '1.0.0',
},
}

{
const upgraded = await ncu({ packageData: pkg, filter: ['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 ncu({ packageData: pkg, filter: ['@vite*'] })
upgraded!.should.not.have.property('vite')
upgraded!.should.have.property('@vitejs/plugin-react')
upgraded!.should.have.property('@vitejs/plugin-vue')
}

{
const upgraded = await ncu({ packageData: pkg, filter: ['*vite*'] })
upgraded!.should.have.property('vite')
upgraded!.should.have.property('@vitejs/plugin-react')
upgraded!.should.have.property('@vitejs/plugin-vue')
}

{
const upgraded = await ncu({ packageData: pkg, filter: ['*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 ncu({ packageData: pkg, filter: ['*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