Skip to content

Commit

Permalink
updated to latest package versions (node 10+);
Browse files Browse the repository at this point in the history
added support for rcfile;
added babel support for spread operator;
added yarn support;
  • Loading branch information
dkhunt27 committed Feb 15, 2021
1 parent f8ce810 commit fe9e89c
Show file tree
Hide file tree
Showing 15 changed files with 6,473 additions and 3,481 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"es2015"
],
"plugins": [
"transform-runtime"
"transform-runtime",
"transform-object-rest-spread"
]
}
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ os:
node_js:
- 12
- 10
- 8
- 6
- 4
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "cli",
"program": "${workspaceFolder}/lib/cli.js",
"args": ["--debug"]
}
]
}
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ npm-check
* Works with `npm@2` and `npm@3`, as well as newer alternative installers like `ied` and `pnpm`.

### Requirements
* Node >= 0.11.
* Node >= 10.

### On the command line

Expand Down Expand Up @@ -267,6 +267,18 @@ Each item in the array will look like the following:

You will also see this if you use `--debug` on the command line.

### RC File Support
Additional options can be sent to the depcheck process. See [depcheck API](https://github.com/depcheck/depcheck#api). Create a .npmcheckrc{.json,.yml,.js} file and set the depcheck options under depcheck property.

For example, to skip packages for unused check, but still want them in the outdated check (so can't use the --ignore option):
```
# .npmcheckrc
depcheck:
ignoreMatches: ["replace-in-file","snyk","sonarqube-scanner"]
```

### Inspiration

* [npm outdated](https://www.npmjs.com/doc/cli/npm-outdated.html) - awkward output, requires --depth=0 to be grokable.
Expand Down
6 changes: 2 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
environment:
matrix:
- nodejs_version: 7
- nodejs_version: 6
- nodejs_version: 4
- nodejs_version: 12
- nodejs_version: 10

install:
- ps: Install-Product node $env:nodejs_version
- npm i -g npm@3
- npm install
- set CI=true

Expand Down
31 changes: 31 additions & 0 deletions latest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
dependencies
callsite-record v3 -> v4; didn't see any breaking changes identified in doc
chalk v1 -> v4; fixed stripColor; node >= 10; other breaking changes didn't seem to apply
depcheck v0 -> v1; didn't see any breaking changes identified in doc
execa v0 -> v5; node >= 10; other breaking changes didn't seem to apply
global-modules v1 -> v2; didn't see any breaking changes identified in doc
globby v4 -> v11; node >= 10; other breaking changes didn't seem to apply
inquirer v0 - v7; fixed inquirer.prompt call
is-ci v1 -> v2; didn't see any breaking changes identified in doc
lodash v4 -> v4
meow v3 -> v9; fixed options; node >= 10; other breaking changes didn't seem to apply
node-emoji v1 -> v1
ora v0 -> v5; node >= 10; other breaking changes didn't seem to apply
package-json v4 -> v6; node >= 8; other breaking changes didn't seem to apply
path-exists v2 -> v4; node >= 8; other breaking changes didn't seem to apply
pkg-dir v1 -> v5; node >= 10; other breaking changes didn't seem to apply
preferred-pm v1 -> v3; no release/tags found
rc-config-loader *new*
semver v5 -> v7; didn't see any breaking changes identified in doc
semver-diff v2 -> v3; node >= 8; other breaking changes didn't seem to apply
strip-ansi *new*
throat v2 -> v6; node > 10; other breaking changes didn't seem to apply
update-notifier v2 -> v5; node > 10; other breaking changes didn't seem to apply
xtend v4 -> v4

devDependencies
babel-cli v6 -> v6
babel-plugin-transform-object-rest-spread *new*
babel-plugin-transform-runtime v6 -> v6
babel-preset-es2015 v6 -> v6
xo v0 -> v0
113 changes: 68 additions & 45 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const detectPreferredPM = require('preferred-pm');

updateNotifier({pkg}).notify();

const cli = meow({
help: `
/* eslint-disable indent */
const cli = meow(`
Usage
$ npm-check <path> <options>
Expand All @@ -42,43 +42,65 @@ const cli = meow({
$ npm-check # See what can be updated, what isn't being used.
$ npm-check ../foo # Check another path.
$ npm-check -gu # Update globally installed modules by picking which ones to upgrade.
`},
`,
{
alias: {
u: 'update',
y: 'update-all',
g: 'global',
s: 'skip-unused',
p: 'production',
d: 'dev-only',
E: 'save-exact',
i: 'ignore'
},
default: {
dir: pkgDir.sync() || process.cwd(),
emoji: !isCI,
spinner: !isCI
},
boolean: [
'update',
'update-all',
'global',
'skip-unused',
'production',
'dev-only',
'save-exact',
'color',
'emoji',
'spinner'
],
string: [
'ignore',
'specials'
]
flags: {
update: {
type: 'boolean',
alias: 'u'
},
updateAll: {
type: 'boolean',
alias: 'y'
},
global: {
type: 'boolean',
alias: 'g'
},
skipUnused: {
type: 'boolean',
alias: 's'
},
production: {
type: 'boolean',
alias: 'p'
},
devOnly: {
type: 'boolean',
alias: 'd'
},
saveExact: {
type: 'boolean',
alias: 'E'
},
ignore: {
type: 'string',
alias: 'i'
},
specials: {
type: 'string'
},
color: {
type: 'boolean'
},
emoji: {
type: 'boolean',
default: !isCI
},
debug: {
type: 'boolean'
},
spinner: {
type: 'boolean',
default: !isCI
}
}
});

/* eslint-enable indent */

const options = {
cwd: cli.input[0] || cli.flags.dir,
cwd: cli.input[0] || pkgDir.sync() || process.cwd(),
update: cli.flags.update,
updateAll: cli.flags.updateAll,
global: cli.flags.global,
Expand Down Expand Up @@ -115,28 +137,29 @@ Promise.resolve()
if (options.updateAll) {
return updateAll(currentState);
}

if (options.update) {
return interactiveUpdate(currentState);
}

return staticOutput(currentState);
})
.catch(err => {
console.log(err.message);
.catch(error => {
console.log(error.message);

if (options.debug) {
console.log(createCallsiteRecord(err).renderSync());
console.log(createCallsiteRecord(error).renderSync());
} else {
console.log('For more detail, add `--debug` to the command');
}

process.exit(1);
});

const SUPPORTED_INSTALLERS = ['npm', 'pnpm', 'ied'];
// eslint-disable-next-line unicorn/prefer-set-has
const SUPPORTED_INSTALLERS = ['npm', 'pnpm', 'ied', 'yarn'];

function detectPreferredInstaller(cwd) {
return detectPreferredPM(cwd)
.then(preferredPM => {
return preferredPM && SUPPORTED_INSTALLERS.indexOf(preferredPM.name) !== -1 ?
preferredPM.name : 'npm';
});
async function detectPreferredInstaller(cwd) {
const preferredPM = await detectPreferredPM(cwd);
return preferredPM && SUPPORTED_INSTALLERS.includes(preferredPM.name) ? preferredPM.name : 'npm';
}
26 changes: 24 additions & 2 deletions lib/in/get-unused-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const depcheck = require('depcheck');
const ora = require('ora');
const _ = require('lodash');
const { rcFile } = require('rc-config-loader');

function skipUnused(currentState) {
return currentState.get('skipUnused') || // manual option to ignore this
Expand All @@ -11,6 +12,20 @@ function skipUnused(currentState) {
!currentState.get('cwdPackageJson').name; // there's no package.json
}

function loadRcFile(rcFileName) {
try {
const results = rcFile(rcFileName);
// Not Found
if (!results) {
return {};
}
return results.config;
} catch (error) {
console.error(`Error parsing rc file; skipping it; error: ${error.message}`);
return {}; // default value
}
}

function getSpecialParsers(currentState) {
const specialsInput = currentState.get('specials');
if (!specialsInput) return;
Expand All @@ -31,7 +46,7 @@ function checkUnused(currentState) {
return;
}

const depCheckOptions = {
const depcheckDefaults = {
ignoreDirs: [
'sandbox',
'dist',
Expand All @@ -57,7 +72,14 @@ function checkUnused(currentState) {
specials: getSpecialParsers(currentState)
};

depcheck(currentState.get('cwd'), depCheckOptions, resolve);
let npmCheckRc = loadRcFile('npmcheck');

let depcheckOptions = {
...depcheckDefaults,
...npmCheckRc.depcheck
};

depcheck(currentState.get('cwd'), depcheckOptions, resolve);
}).then(depCheckResults => {
spinner.stop();
const unusedDependencies = [].concat(depCheckResults.dependencies, depCheckResults.devDependencies);
Expand Down
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
const npmCheck = require('./in');
const createState = require('./state/state');

function init(userOptions) {
return createState(userOptions)
.then(currentState => npmCheck(currentState));
async function init(userOptions) {
const currentState = await createState(userOptions);
return npmCheck(currentState);
}

module.exports = init;
11 changes: 8 additions & 3 deletions lib/out/install-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ function install(packages, currentState) {
}

const installer = currentState.get('installer');
const installGlobal = currentState.get('global') ? '--global' : null;
const saveExact = currentState.get('saveExact') ? '--save-exact' : null;
const color = chalk.supportsColor ? '--color=always' : null;

const npmArgs = ['install']
const isYarn = installer === 'yarn';

const installGlobal = currentState.get('global') ? (isYarn ? 'global' : '--global'): null;
const saveExact = currentState.get('saveExact') ? (isYarn ? '--exact' : '--save-exact') : null;

const installCmd = isYarn ? 'add' : 'install';

const npmArgs = [installCmd]
.concat(installGlobal)
.concat(saveExact)
.concat(packages)
Expand Down
Loading

0 comments on commit fe9e89c

Please sign in to comment.