Giter Club home page Giter Club logo

next-update's Introduction

next-update

Tests if module's dependencies can be updated to the newer version without breaking the tests

NPM

Build status Circle CI Coverage Status semantic-release Known Vulnerabilities renovate-app badge

Note I no longer maintain Node 0.12/4 compatibility. Please switch to Node 6.

asciicast

Also check out:

  • next-updater can update all your repos
  • dont-break that checks if your code is going to break everyone who depends on it.
  • changed-log returns commit messages for the given NPM package or Github repo between two tags.

Example

Imagine your nodejs module foo has the following dependencies listed in package.json

"dependencies": {
    "lodash": "~1.2.0",
    "async": "~0.2.5"
}

You would like to update lodash and async to latest versions, to not sure if this would break anything. With next-update it is easy: run command next-update in the folder with module foo. Here is the example output:

next updates:
lodash
    1.2.1 PASS
async
    0.2.6 PASS
    0.2.7 PASS
    0.2.8 PASS

Both package.json file and node_modules folder are left unchanged, and now you know that you can safely upgrade both libraries to later versions.

It even tells you the install command ;)

Use the following command to install working versions
npm install --save [email protected]

This might not appear like a big deal for a single module that is using popular 3rd party libraries with stable apis only. next-update is most useful in the larger development context, where multiple modules are being developed side by side, often by different teams. In such situations, checking if an upgrade is possible could be part of the continuous build pipeline.

You can see if your dependencies are out of date by using david, it even has badges you can add to your README files.

next-update reports the probability of success for a given dependency update using anonymous global statistics from next-update server

available updates:
package               available  from version  average success %  successful updates  failed updates
--------------------  ---------  ------------  -----------------  ------------------  --------------
grunt-contrib-jshint  0.8.0      0.7.2         100%               34                  0
grunt-bump            0.0.13     0.0.12        100%               4                   0

Install

You can install this tool globally

npm install -g next-update  // installs module globally
next-update --help          // shows command line options

Then run inside any package folder

/git/my-awesome-module
$ next-update

Or you can use this module as a devDependency and a script command

npm install --save-dev next-update
{
    "scripts": {
        "next-update": "next-update -k true --tldr"
    }
}

This command will keep the successfuly version upgrades in the package.json file, but will not be very verbose when run.

Anonymous usage collection

After testing each module A upgrade from version X to Y, next-update sends anonymous result to next-update.herokuapp.com/. The only information transmitted is:

{
    "name": "lodash",
    "from": "1.0.0",
    "to": "2.0.0",
    "success": true
}

This information is used to answer the following questions later: what is the probability module A can be upgraded from X to Y? Thus even if you do not have tests covering this particular module, you can judge how compatible version X and Y really are over the entire internet.

You can inspect data send in stats.js.

If the dependency module has been upgraded by anyone else, its statistics will be displayed with each test.

stats: deps-ok 0.0.7 -> 0.0.8 success probability 44.44% 8 success(es) 10 failure(s)

A lot of NPM modules do not have tests, but at least you can judge if someone else has success going from verion X to version Y of a dependency.

Use

Make sure the target module has unit / integration tests, and the tests can be run using npm test command.

Run next-update from the command line in the same folder as the target module. In general this tool does the following:

  1. Reads the module's dependencies (including dev) and their versions
  2. Queries npm registry to see if there are newer versions
  3. For each dependency that has newer versions available:
    1. Installs each version
    2. Runs command npm test to determine if the new version breaks the tests
    3. Installs back the current version.
  4. Reports results

Checking specific modules

You can check one or more specific modules (whitelist) using CLI flag --module or -m

next-update --module foo,bar,baz

Ignoring or skipping some modules

note prerelease versions like 1.2.0-alpha are skipped by default. I believe next-update is meant to upgrade to stable versions.

Some modules are hard to unit test, thus the automatic upgrades are not appropriate. For example benv upgrade brings a new jsdom version, which does not work on Node 0.12 Similarly, upgrading Q from 1.x.x to 2.x.x is usually a breaking change.

You can skip a list of modules by name using config property in the package.json

"config": {
    "next-update": {
        "skip": ["benv", "q"]
    }
}

Custom test command per module

Some modules are not really tested using the default npm test command or whatever is passed via --test "..." from CLI. For example a linter module should probably be tested using npm run lint command. You can set individual test commands for each module to override the default test command. In the package.json config object set "commands" object

"config": {
  "next-update": {
    "commands": {
      "git-issues": "npm run issues",
      "standard": "npm run lint"
    }
  }
}

Then when git-issues module is checked by itself, it will run npm run issues command; when module standard is tested by itself, the test will use npm run lint command.

Misc

  • To see what has changed in the latest version of any module, use my companion tool changed like this changed foo (foo is package name)
  • When comparing versions, keywords latest and *** are both assumed to equal to "0.0.0".
  • A good workflow using next-update
    • see available new versions next-update --available
    • check latest version of each module using next-update --latest
    • install new versions of the desired modules using standard npm i dependency@version --save
  • You can use custom test command, for example next-update -t "grunt test"
    • npm test is used by default.
  • You can keep each working version in package.json by using --keep flag.

API

You can use next-update as a module. See file src/next-update-as-module for all options.

const nextUpdate = require('next-update')
nextUpdate({
  module: ['foo', 'bar']
}).then(results => {
  console.log(results)
})
/*
prints something like
[[
  {
    "name": "foo",
    "version": "0.2.0",
    "from": "0.2.1",
    "works": true
  },
  {
    "name": "foo",
    "version": "0.2.0",
    "from": "0.3.0",
    "works": false
  }
], [
  {
    "name": "bar",
    "version": "1.5.1",
    "from": "2.0.0",
    "works": true
  }
}}
*/

Development

Edit source, run unit tests, run end to end tests and release new version commands:

npm test
npm run e2e
grunt release
npm publish

Related

3rd party libraries

  • lazy-ass and check-more-types are used to defend against runtime errors.
  • lo-dash is used to deal with collections / iterators.
  • check-types is used to verify arguments through out the code.
  • optimist is used to process command line arguments.
  • request is used to fetch NPM registry information.
  • semver is used to compare module version numbers.
  • q library is used to handle promises. While developing this tool, I quickly ran into problems managing the asynchronous nature of fetching information, installing multiple modules, testing, etc. At first I used async, but it was still too complex. Using promises allowed to cut the program's code and the complexity to very manageable level.
  • cli-color prints colored text to the terminal.

Small print

Author: Gleb Bahmutov © 2014

License: MIT - do anything with the code, but don't blame me if it does not work.

Spread the word: tweet, star on github, etc.

Support: if you find any problems with this module, email / tweet / open issue on Github

MIT License

Copyright (c) 2014 Gleb Bahmutov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

next-update's People

Contributors

bahmutov avatar bitdeli-chef avatar iamstarkov avatar karlhorky avatar mchapman avatar xpure-sklatt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

next-update's Issues

next-update fails on GitHub dependencies

The documentation quite nicely describes the process of how modules are checked for updates. But this only targets public packages that are in the public registry.

If you use a GitHub dependency in your package.json, next-update tells you:

TypeError: Invalid comparator: myorg/mymodule#x.y.z

IMHO you can deal with Git and GitHub dependencies in a quite similar way: Simply get the latest version, and afterwards rollback to the commit ID or tag that is given in package.json.

Add option to keep working version

Add option to leave the updated version if the tests pass. At the end should not even tell the install command, just print which modules were updated.

devDependencies is not respected

Hi @bahmutov. This tool is really awesome!

I just ran it on my marky-markdown project, and noticed that the recommended npm install command doesn't take into account the fact that some deps are devDependencies. There should probably be two install commands, one with --save-dev.

next updates:
cheerio 0.18.0 -> 0.19.0
github-url-to-object 1.4.2 -> 1.5.0
html-frontmatter 1.3.2 -> 1.5.1
language-ini 1.7.0 -> 1.10.0
lodash 2.4.1 -> 3.6.0
markdown-it 3.0.4 -> 4.1.1
catjs 0.4.56 -> 0.4.84
cordova 4.2.0 -> 4.3.0
express 4.10.7 -> 4.12.3
glob 4.3.5 -> 5.0.5
johnny-five 0.8.37 -> 0.8.56
mocha 2.0.1 -> 2.2.4
payform 1.0.1 -> 1.1.0
wzrd 1.1.1 -> 1.2.1
Use the following command to install working versions
npm install --save --save-exact [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]

duplicate properties found

Is this a deliberate error, or an accidental one?

next-update - Tests if module's dependencies can be updated to latest version
  version: 0.4.5
  author: {"name":"Gleb Bahmutov","email":"[email protected]"}
checking if the current state works

/usr/lib/node_modules/next-update/node_modules/deps-ok/src/utils.js:35
      throw new Error('duplicate properties found: ' + common);
            ^
Error: duplicate properties found: jade
    at /usr/lib/node_modules/next-update/node_modules/deps-ok/src/utils.js:35:13
    at Array.forEach (native)
    at Object.getAllDependencies (/usr/lib/node_modules/next-update/node_modules/deps-ok/src/utils.js:28:14)
    at checkTopLevelNpmDependencies (/usr/lib/node_modules/next-update/node_modules/deps-ok/src/check-npm-package.js:13:20)
    at checkDependenciesInFolder (/usr/lib/node_modules/next-update/node_modules/deps-ok/src/check-folder.js:12:10)
    at /usr/lib/node_modules/next-update/src/next-update.js:31:13
    at process._tickCallback (node.js:415:13)
    at Function.Module.runMain (module.js:499:11)
    at startup (node.js:119:16)
    at node.js:902:3

i.e. do I have a double jade dependency I should be concerned about?

Shorten long version strings

When showing multiple available versions, shorten the string, for example by putting ... in the middle

instead of 0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.1.5, 0.1.6, 0.1.7
show 0.1.0, ..., 0.1.7

Fetch stats for multiple versions

If there are multiple versions available for a given module, fetch update stats for each and list separately in the rows of the available table

checking NPM registry times out

Seems to do with bad connections, but no error messages, just silently exits after a couple of seconds after "checking NPM registry" message is printed to the console

EPEERINVALID npm error causing cascading failures

next-update log pasted here: http://pastebin.com/PZJvEZD6

Everything was going fine until [email protected] failed.

npm ERR! System Linux 3.11.0-15-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "[email protected]"
npm ERR! cwd /vagrant
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code EPEERINVALID
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /vagrant/npm-debug.log
npm ERR! not ok code 0

After that, every single one failed (I presume not coincidentally).

Here's from my package.json:

  "dependencies": {
    "redis": "^0.10.3",
    "express": "^4.4.4",
    "express-session": "^1.5.1",
    "body-parser": "^1.4.2",
    "cookie-parser": "^1.3.1",
    "method-override": "^2.0.0",
    "morgan": "^1.1.0",
    "serve-favicon": "^2.0.0",
    "passport": "^0.2.0",
    "passport-google-oauth": "^0.1.5",
    "passport-facebook": "^1.0.3",
    "passport-local": "^1.0.0",
    "connect-redis": "^2.0.0",
    "nano": "^5.9.1",
    "batch": "~0.5.0",
    "superagent": "~0.16.0",
    "knex": "^0.5.8",
    "bookshelf": "^0.6.6",
    "newrelic": "^1.3.2",
    "winston": "^0.7.2",
    "winston-mail": "^0.2.7",
    "convict": "^0.4.2",
    "pg.js": "^2.11.1",
    "request": "2.36.0",
    "winston-logentries-simple": "0.0.2",
    "cssmin": "^0.4.1",
    "component-hooks": "~0.2.3"
  },
  "devDependencies": {
    "grunt": "^0.4.5",
    "time-grunt": "^0.3.1",
    "load-grunt-tasks": "^0.4.0",
    "load-grunt-config": "^0.9.2",
    "grunt-concurrent": "^0.5.0",
    "sane": "^0.5.1",
    "gaze": "^0.6.4",
    "forever-monitor": "^1.2.3",
    "should": "~3.1.0",
    "mocha": "~1.17.1",
    "supertest": "~0.9.0",
    "smash": "0.0.12",
    "d3": "^3.4.4",
    "coveralls": "^2.10.0",
    "mocha-lcov-reporter": "0.0.1",
    "istanbul": "^0.2.11"
  }

This looks relevant: npm/npm#3289

Skip error message for certain versions

Lately, npm registry returns a lot of modified, etc words for versions, need to skip them

null 'could not clean version 0.4.0rc8 for grunt'
null 'could not clean version modified for allong.es'
null 'could not clean version created for allong.es'

"Current installation is invalid, please run NPM install first" because of bower component

We put bower dependencies in a specific folder, using .bowerrc. We installed Angular as a Bower dependency, and when I run next-update I get:

next-update - Tests if module's dependencies can be updated to latest version
  version: 0.5.1
  author: {"name":"Gleb Bahmutov","email":"[email protected]"}
checking if the current state works
ERROR: cannot find folder /home/nchambrier/Projects/LMTM/ooz/bower_components/angular
ERROR testing next working updates
Error: Current installation is invalid, please run NPM install first
    at /home/nchambrier/.nvm/v0.10.32/lib/node_modules/next-update/src/next-update.js:35:26
    at node.js:906:3
From previous event:
    at checkDependenciesInstalled (/home/nchambrier/.nvm/v0.10.32/lib/node_modules/next-update/src/next-update.js:29:19)
    at Object.checkCurrentInstall (/home/nchambrier/.nvm/v0.10.32/lib/node_modules/next-update/src/next-update.js:43:12)
    at Object.<anonymous> (/home/nchambrier/.nvm/v0.10.32/lib/node_modules/next-update/index.js:129:38)

Obviously, if it looks for Angular in ./bower_components it won't be found as there is no such folder.

next-update should either

  • ignore bower dependencies (I thought it only checked npm dependencies)
  • read .bowerrc

Use $NODE_PATH

I think this error I'm getting is because next-update only looks locally, not to the node path?

(develop) thomas:/vagrant $ env | grep NODE_PATH
NODE_PATH=/home/vagrant/.npm-packages/lib/node_modules:/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript

(develop) thomas:/vagrant $ ls /home/vagrant/.npm-packages/lib/node_modules/redis/
benches  changelog.md  diff_multi_bench_output.js  examples  generate_commands.js  index.js  lib  multi_bench.js  package.json  README.md  test.js  test-unref.js

(develop) thomas:/vagrant $ next-update
next-update - Tests if module's dependencies can be updated to latest version
  version: 0.4.4
  author: {"name":"Gleb Bahmutov","email":"[email protected]"}
checking if the current state works
cannot find file /vagrant/node_modules/redis/package.json
ERROR: cannot find module redis
ERROR testing next working updates
Error: Current installation is invalid, please run NPM install first
    at /usr/lib/node_modules/next-update/src/next-update.js:35:26
    at node.js:902:3
From previous event:
    at checkDependenciesInstalled (/usr/lib/node_modules/next-update/src/next-update.js:29:19)
    at Object.checkCurrentInstall (/usr/lib/node_modules/next-update/src/next-update.js:43:12)
    at Object.<anonymous> (/usr/lib/node_modules/next-update/index.js:122:38)
(develop) thomas:/vagrant $

Use $NODE_PATH

I think this error I'm getting is because next-update only looks locally, not to the node path?

(develop) thomas:/vagrant $ env | grep NODE_PATH
NODE_PATH=/home/vagrant/.npm-packages/lib/node_modules:/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript

(develop) thomas:/vagrant $ ls /home/vagrant/.npm-packages/lib/node_modules/redis/
benches  changelog.md  diff_multi_bench_output.js  examples  generate_commands.js  index.js  lib  multi_bench.js  package.json  README.md  test.js  test-unref.js

(develop) thomas:/vagrant $ next-update
next-update - Tests if module's dependencies can be updated to latest version
  version: 0.4.4
  author: {"name":"Gleb Bahmutov","email":"[email protected]"}
checking if the current state works
cannot find file /vagrant/node_modules/redis/package.json
ERROR: cannot find module redis
ERROR testing next working updates
Error: Current installation is invalid, please run NPM install first
    at /usr/lib/node_modules/next-update/src/next-update.js:35:26
    at node.js:902:3
From previous event:
    at checkDependenciesInstalled (/usr/lib/node_modules/next-update/src/next-update.js:29:19)
    at Object.checkCurrentInstall (/usr/lib/node_modules/next-update/src/next-update.js:43:12)
    at Object.<anonymous> (/usr/lib/node_modules/next-update/index.js:122:38)
(develop) thomas:/vagrant $

Hardcoded URL to npm.registry.org

Hi.

I'm using your wonderful lib to make sure we don't break anything in our build environment and to make sure we're not 1:1 dependent on registry.npm.org being up since we use CI, we have our own registry mirrored to registry.npm.org. Our mirror takes a while to update sometimes and since next-update always uses npm.registry.org to look up the dependencies, it fails when trying to install them (which is using the correct, local registry).

Would be great if next-update used the registry defined in .npmrc and defaults to registry.npm.org instead. :)

If npm doesn't expose the registry easily, it could perhaps execute npm config get registry which will output which registry that is defined in the .npmrc file.

Thanks again for the useful project!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.