Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Check for outdated, incorrect, and unused dependencies.

License

NotificationsYou must be signed in to change notification settings

dylang/npm-check

Repository files navigation

Build StatusNPM versionnpm

Check for outdated, incorrect, and unused dependencies.

npm-check -u

Features

  • Tells you what's out of date.
  • Provides a link to the package's documentation so you can decide if you want the update.
  • Kindly informs you if a dependency is not being used in your code.
  • Works on your globally installed packages too, via-g.
  • Interactive Update for less typing and fewer typos, via-u.
  • Supports public and private@scoped/packages.
  • Supports ES6-styleimport from syntax.
  • Upgrades your modules using your installed version of npm, including the newnpm@3, so dependencies go where you expect them.
  • Works with any public npm registry,private registries, and alternate registries likeSinopia.
  • Does not query registries for packages withprivate: true in their package.json.
  • Emoji in a command-line app, because command-line apps can be fun too.
  • Works withnpm@2 andnpm@3, as well as newer alternative installers likeied andpnpm.

Requirements

  • Node >= 10.9.0

On the command line

This is the easiest way to usenpm-check.

Install

npm install -g npm-check

Use

npm-check

npm-check

The result should look like the screenshot, or something nice when your packages are all up-to-date and in use.

When updates are required it will return a non-zero response code that you can use in your CI tools.

Options

Usage  $ npm-check <path> <options>Path  Where to check. Defaults to current directory. Use -g for checking global modules.Options  -u, --update          Interactive update.  -y, --update-all      Uninteractive update. Apply all updates without prompting.  -g, --global          Look at global modules.  -s, --skip-unused     Skip check for unused packages.  -p, --production      Skip devDependencies.  -d, --dev-only        Look at devDependencies only (skip dependencies).  -i, --ignore          Ignore dependencies based on succeeding 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.  --no-emoji            Remove emoji support. No emoji in default in CI environments.  --debug               Show debug output. Throw in a gist when creating issues on github.Examples  $ 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.

npm-check-u

-u, --update

Show an interactive UI for choosing which modules to update.

Automatically updates versions referenced in thepackage.json.

Based on recommendations from thenpm team,npm-check only updates usingnpm install, notnpm update.To avoid using more than one version ofnpm in one directory,npm-check will automatically install updated modulesusing the version ofnpm installed globally.

npm-check -g -u

Update usingied orpnpm

Set environment variableNPM_CHECK_INSTALLER to the name of the installer you wish to use.

NPM_CHECK_INSTALLER=pnpm npm-check -u## pnpm install --save-dev foo@version --color=always

You can also use this for dry-run testing:

NPM_CHECK_INSTALLER=echo npm-check -u

-y, --update-all

Updates your dependencies like--update, just without any prompt. This is especially useful if you want to automate your dependency updates withnpm-check.

-g, --global

Check the versions of your globally installed packages.

If the value ofprocess.env.NODE_PATH is set, it will override the default path of global node_modules returned by packageglobal-modules.

Tip: Usenpm-check -u -g to do a safe interactive update of global modules, including npm itself.

-s, --skip-unused

By defaultnpm-check will let you know if any of your modules are not being used by looking atrequire statementsin your code.

This option will skip that check.

This is enabled by default when usingglobal orupdate.

-p, --production

By defaultnpm-check will look at packages listed asdependencies anddevDependencies.

This option will let it ignore outdated and unused checks for packages listed asdevDependencies.

-d, --dev-only

Ignoredependencies and only checkdevDependencies.

This option will let it ignore outdated and unused checks for packages listed asdependencies.

-i, --ignore

Ignore dependencies that match specified glob.

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

-E, --save-exact

Install packages using--save-exact, meaning exact versions will be saved in package.json.

Applies to bothdependencies anddevDependencies.

--specials

Check special (e.g. config) files when looking for unused dependencies.

$ npm-check --specials=bin,webpack will look in thescripts section of package.json and in webpack config.

Seehttps://github.com/depcheck/depcheck#special for more information.

--color, --no-color

Enable or disable color support.

By defaultnpm-check uses colors if they are available.

--emoji, --no-emoji

Enable or disable emoji support. Useful for terminals that don't support them. Automatically disabled in CI servers.

--spinner, --no-spinner

Enable or disable the spinner. Useful for terminals that don't support them. Automatically disabled in CI servers.

API

The API is here in case you want to wrap this with your CI toolset.

constnpmCheck=require('npm-check');npmCheck(options).then(currentState=>console.log(currentState.get('packages')));

update

  • Interactive update.
  • default isfalse

global

  • Check global modules.
  • default isfalse
  • cwd is automatically set with this option.

skipUnused

  • Skip checking for unused packages.
  • default isfalse

ignoreDev

  • IgnoredevDependencies.
  • This is called--production on the command line to matchnpm.
  • default isfalse

devOnly

  • Ignoredependencies and only checkdevDependencies.
  • default isfalse

ignore

  • Ignore dependencies that match specified glob.
  • default is[]

saveExact

  • Update package.json with exact versionx.y.z instead of semver range^x.y.z.
  • default isfalse

debug

  • Show debug output. Throw in a gist when creating issues on github.
  • default isfalse

cwd

  • Override wherenpm-check checks.
  • default isprocess.cwd()

specials

  • List ofdepcheck special parsers to include.
  • default is''

currentState

The result of the promise is acurrentState object, look instate.js to see how it works.

You will probably wantcurrentState.get('packages') to get an array of packages and the state of each of them.

Each item in the array will look like the following:

{moduleName:'lodash',// name of the module.homepage:'https://lodash.com/',// url to the home page.regError:undefined,// error communicating with the registrypkgError:undefined,// error reading the package.jsonlatest:'4.7.0',// latest according to the registry.installed:'4.6.1',// version installedisInstalled:true,// Is it installed?notInstalled:false,// Is it installed?packageWanted:'4.7.0',// Requested version from the package.json.packageJson:'^4.6.1',// Version or range requested in the parent package.json.devDependency:false,// Is this a devDependency?usedInScripts:undefined,// Array of `scripts` in package.json that use this module.mismatch:false,// Does the version installed not match the range in package.json?semverValid:'4.6.1',// Is the installed version valid semver?easyUpgrade:true,// Will running just `npm install` upgrade the module?bump:'minor',// What kind of bump is required to get the latest, such as patch, minor, major.unused:false// Is this module used in the code?},

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. Seedepcheck 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):

# .npmcheckrcdepcheck:  ignoreMatches: ["replace-in-file","snyk","sonarqube-scanner"]

Inspiration

  • npm outdated - awkward output, requires --depth=0 to be grokable.
  • david - does not work with private registries.
  • update-notifier - for single modules, not everything in package.json.
  • depcheck - only part of the puzzle. npm-check uses depcheck.

About the Author

Hi! Thanks for checking out this project! My name isDylan Greene. When not overwhelmed with my two young kids I enjoy contributingto the open source community. I'm also a tech lead atOpower.@dylang@dylang

Here's some of my other Node projects:

NameDescriptionnpm Downloads
grunt‑notifyAutomatic desktop notifications for Grunt errors and warnings. Supports OS X, Windows, Linux.grunt-notify
shortidAmazingly short non-sequential url-friendly unique id generator.shortid
space‑hogsDiscover surprisingly large directories from the command line.space-hogs
rssRSS feed generator. Add RSS feeds to any project. Supports enclosures and GeoRSS.rss
grunt‑promptInteractive prompt for your Grunt config using console checkboxes, text input with filtering, password fields.grunt-prompt
xmlFast and simple xml generator. Supports attributes, CDATA, etc. Includes tests and examples.xml
changelogCommand line tool (and Node module) that generates a changelog in color output, markdown, or json for modules in npmjs.org's registry as well as any public github.com repo.changelog
grunt‑attentionDisplay attention-grabbing messages in the terminalgrunt-attention
observatoryBeautiful UI for showing tasks running on the command line.observatory
anthologyModule information and stats for any @npmjs useranthology
grunt‑catEcho a file to the terminal. Works with text, figlets, ascii art, and full-color ansi.grunt-cat

This list was generated usinganthology.

License

Copyright (c) 2016 Dylan Greene, contributors.

Released under theMIT license.

Screenshots areCC BY-SA (Attribution-ShareAlike).

About

Check for outdated, incorrect, and unused dependencies.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors43


[8]ページ先頭

©2009-2025 Movatter.jp