Skip to content

Commit

Permalink
adding ability to filter
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Jan 7, 2019
1 parent bda767d commit cf1b327
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Options
-p, --production Skip devDependencies.
-d, --dev-only Look at devDependencies only (skip dependencies).
-i, --ignore Ignore dependencies based on succeeding glob.
-f, --filter Filter dependencies based on glob.
-E, --save-exact Save exact version (x.y.z) instead of caret (^x.y.z) in package.json.
--specials List of depcheck specials to include in check for unused dependencies.
--no-color Force or disable color output.
Expand Down Expand Up @@ -144,6 +145,12 @@ Ignore dependencies that match specified glob.

`$ npm-check -i babel-*` will ignore all dependencies starting with 'babel-'.

#### `-f, --filter`

Ignore dependencies that match specified glob.

`$ npm-check -f babel-*` will only include dependencies starting with 'babel-'.

#### `-E, --save-exact`

Install packages using `--save-exact`, meaning exact versions will be saved in package.json.
Expand Down
10 changes: 7 additions & 3 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const cli = meow({
-p, --production Skip devDependencies.
-d, --dev-only Look at devDependencies only (skip dependencies).
-i, --ignore Ignore dependencies based on succeeding glob.
-f, --filter Include dependencies based on glob.
-E, --save-exact Save exact version (x.y.z) instead of caret (^x.y.z) in package.json.
--specials List of depcheck specials to include in check for unused dependencies.
--no-color Force or disable color output.
Expand All @@ -52,7 +53,8 @@ const cli = meow({
p: 'production',
d: 'dev-only',
E: 'save-exact',
i: 'ignore'
i: 'ignore',
f: 'filter'
},
default: {
dir: pkgDir.sync() || process.cwd(),
Expand All @@ -73,7 +75,8 @@ const cli = meow({
],
string: [
'ignore',
'specials'
'specials',
'filter'
]
});

Expand All @@ -91,7 +94,8 @@ const options = {
installer: process.env.NPM_CHECK_INSTALLER || 'auto',
debug: cli.flags.debug,
spinner: cli.flags.spinner,
ignore: cli.flags.ignore
ignore: cli.flags.ignore,
filter: cli.flags.filter
};

if (options.debug) {
Expand Down
10 changes: 10 additions & 0 deletions lib/in/create-package-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ function createPackageSummary(moduleName, currentState) {
}
}

// If --filter is defined, only include specified package globs
const filter = currentState.get('filter');
if (filter) {
const filterMatch = Array.isArray(filter) ? filter.some(filteredModule => minimatch(moduleName, filteredModule)) : minimatch(moduleName, filter);

if (!filterMatch) {
return false;
}
}

const unusedDependencies = currentState.get('unusedDependencies');
const missingFromPackageJson = currentState.get('missingFromPackageJson');

Expand Down
1 change: 1 addition & 0 deletions lib/state/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const defaultOptions = {
spinner: false,
installer: 'npm',
ignore: [],
filter: [],

globalPackages: {},
cwdPackageJson: {devDependencies: {}, dependencies: {}},
Expand Down

0 comments on commit cf1b327

Please sign in to comment.