Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 635 Vote(s) - 3.58 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to update each dependency in package.json to the latest version?

#1
I copied `package.json` from another project and now want to bump all of the dependencies to their latest versions since this is a fresh project and I don't mind fixing something if it breaks.

What's the easiest way to do this?

The best way I know is to run `npm info express version` then update each dependency in `package.json` manually. There must be a better way.

{
"name": "myproject",
"description": "my node project",
"version": "1.0.0",
"dependencies": {
"express": "^3.0.3", // how do I get these bumped to latest?
"mongodb": "^1.2.5",
"underscore": "^1.4.2"
}
}

---

For **Yarn** specific solutions refer to [this Stack Overflow][1] thread.


[1]:

[To see links please register here]

Reply

#2
This works as of npm 1.3.15.

"dependencies": {
"foo": "latest"
}
Reply

#3
Alternative is

"dependencies":{
"foo" : ">=1.4.5"
}

everytime you use npm update , it automatically update to the latest version.
For more version syntax, you may check here:

[To see links please register here]

Reply

#4
I recently had to update several projects that were using npm and package.json for their gruntfile.js magic. The following bash command (multiline command) worked well for me:

npm outdated --json --depth=0 | \
jq --ascii-output --monochrome-output '. | keys | .[]' | \
xargs npm install $1 --save-dev

The idea here:
To pipe the `npm outdated` output as json, to `jq`
(jq is a json command line parser/query tool)
(notice the use of `--depth` argument for `npm outdated`)
jq will strip the output down to just the top level package name only.
finally xargs puts each LIBRARYNAME one at a time into a `npm install LIBRARYNAME --save-dev` command

The above is what worked for me on a machine runnning:
node=v0.11.10 osx=10.9.2 npm=1.3.24

this required:
xargs

[To see links please register here]

(native to my machine I believe)
and
jq

[To see links please register here]

(I installed it with `brew install jq`)

Note: I only save the updated libraries to package.json inside of the json key `devDependancies` by using `--save-dev`, that was a requirement of my projects, quite possible not yours.

Afterward I check that everything is gravy with a simple

npm outdated --depth=0

Also, you can check the current toplevel installed library versions with

npm list --depth=0
Reply

#5
The above commands are unsafe because you might break your module when switching versions.
Instead I recommend the following

* Set actual current node modules version into package.json using `npm shrinkwrap` command.
* Update each dependency to the latest version IF IT DOES NOT BREAK YOUR TESTS using

[To see links please register here]

command line tool

<pre>
npm install -g next-update
// from your package
next-update
</pre>

Reply

#6
The only caveat I have found with the best answer above is that it updates the modules to the latest version. This means it could update to an unstable alpha build.

I would use that npm-check-updates utility.
My group used this tool and it worked effectively by installing the stable updates.

As Etienne stated above: install and run with this:

$ npm install -g npm-check-updates
$ npm-check-updates -u
$ npm install
Reply

#7
1. Use `*` as the version for the latest releases, including unstable
2. Use `latest` as version definition for the latest stable version
3. Modify the package.json with exactly the latest stable version number using [`LatestStablePackages`][1]

[1]:

[To see links please register here]


Here is an example:

"dependencies": {
"express": "latest" // using the latest STABLE version
, "node-gyp": "latest"
, "jade": "latest"
, "mongoose": "*" // using the newest version, may involve the unstable releases
, "cookie-parser": "latest"
, "express-session": "latest"
, "body-parser": "latest"
, "nodemailer":"latest"
, "validator": "latest"
, "bcrypt": "latest"
, "formidable": "latest"
, "path": "latest"
, "fs-extra": "latest"
, "moment": "latest"
, "express-device": "latest"
},
Reply

#8
Here is a basic regex to match semantic version numbers so you can quickly replace them all with an asterisk.

### Semantic Version Regex

([>|<|=|~|^|\s])*?(\d+\.)?(\d+\.)?(\*|\d+)

### How to use

Select the package versions you want to replace in the JSON file.

[![screenshot:select the text you want to replace][1]][1]

Input the regex above and verify it's matching the correct text.

[![screenshot:input the semver regex above][2]][2]

Replace all matches with an asterisk.

[![screenshot:replace package versions with an asterisk][3]][3]

Run `npm update --save`

[1]:

[2]:

[3]:
Reply

#9
**Solution without additional packages**

Change every dependency's version to `*`:

"dependencies": {
"react": "*",
"react-google-maps": "*"
}

Then run `npm update --save`.

Some of your packages were updated, but some not?

"dependencies": {
"react": "^15.0.1",
"react-google-maps": "*"
}

This is the tricky part, it means your local version of "react" was lower than the newest one. In this case npm downloaded and updated "react" package. However your local version of "react-google-maps" is the same as the newest one.

If you still want to "update" unchanged `*`, you have to delete these modules from `node_modules` folder.

e.g. delete `node_modules/react-google-maps`.

Finally run again `npm update --save`.


"dependencies": {
"react": "^15.0.1",
"react-google-maps": "^4.10.1"
}

Do not forget to run `npm update --save-dev` if you want to update development dependencies.
Reply

#10
Updtr!

> Based on npm outdated, updtr installs the latest version and runs npm test for each dependency. If the test succeeds, updtr saves the new version number to your package.json. If the test fails, however, updtr rolls back its changes.

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through