Reputation: 888
I am relatively new to grunt and am not really familiar with node yet.
I have a boilerplate Gruntfile and package.json file that I use in all my projects and modify it as needed.
When I start each project I want to update all the Grunt plugins in devDependencies and the package.json, but I don't know of a quick and easy way to do this.
Is it possible to update all modules with one command or do I have to do them individually?
Thanks.
Upvotes: 11
Views: 12433
Reputation: 2823
grunt-dev-update plugin — is my choice.
This answer is relevant for February 2018. In the future, the data from this answer may be obsolete.
Author of this answer personally used this plugin at February 2018.
See plugin description:
Why not use
npm update
ornpm install
?first —
npm update
doesn't work on dev dependencies,
second —npm update
stays inside your semver matching in yourpackage.json
,
thirdly — npm isn't automated like your grunt tasks.
Installation, usage instructions and options are described in official plugin description.
Strange option name; I did not understand at first, what is options.semver
.
Example configuration:
Package name : autoprefixer
Package type : devDependencies
Current version : 6.7.7
Wanted version : 6.7.7
Latest version : 8.0.0
Package name : browser-sync
Package type : devDependencies
Current version : 2.23.5
Wanted version : 2.23.6
Latest version : 2.23.6
You run grunt devUpdate
in console:
If semver: true
:
autoprefixer not update, browser-sync update.
elif semver: false
:
autoprefixer and browser-sync update both.
Upvotes: 0
Reputation: 13762
In your package.json
you can tag each dependency with a range of versions to install then type npm install
to install all the listed dependencies at the given versions:
Only install 0.6.0
:
{
"devDependencies": {
"grunt-contrib-watch": "0.6.0"
}
}
Prefix with ~
to install the latest patch version 0.6.x
:
As 0.6.1
, 0.6.2
, 0.6.3
, etc versions are released, npm install
will install the latest version of those. If 0.7.0
is release, it will not install that version (generally a good strategy as it may contain breaking changes).
{
"devDependencies": {
"grunt-contrib-watch": "~0.6.0"
}
}
Explicitly set the range:
You can use >
, <
, <=
, >=
to explicitly set the version range. Another good option for custom ranges or if you would like to be explicit with your version ranges. The follow will install every version greater or equal than 0.6.0
but less than 1.0.0
:
{
"devDependencies": {
"grunt-contrib-watch": ">= 0.6.0 < 1.0.0"
}
}
Always install the latest with *
Or if you just always want the latest version use *
:
{
"devDependencies": {
"grunt-contrib-watch": "*"
}
}
See more about version ranges in the npm docs: https://www.npmjs.org/doc/misc/semver.html
npm outdated
If you would like to see which of your dependencies are out of date, use npm outdated
: https://www.npmjs.org/doc/cli/npm-outdated.html
npm update
Use npm update
to update all your dependencies to the latest versions. Or npm update packagename anotherpackage
to update specific packages to the latest version.
Upvotes: 22