Update npm package with fixed dependency from command line

I have a npm package with a fixed version that has an update.
Example package.json extract:

devDependencies: {
   "someFixedVersionPackage": "1.0.0", //1.1.0 is latest
   "anotherFixedVersionPackage": "2.3.2", //2.3.4 is latest
}

Is there an npm command that installs the latest version of this package and updates package.json, preferably all packages at the same time?

To be clear, I want the above package.json snippet to be updated before this, in addition to updatable packages:

devDependencies: {
   "someFixedVersionPackage": "1.1.0", //latest
   "anotherFixedVersionPackage": "2.3.4", //latest
}

Thank.

+3
source share
3 answers

Why doesn't it work here npm update?

In accordance with the documentation for npm update:

This command will update all packages listed in the latest version (specified in the tag configuration), observing semver.

. , , -dev devDependencies.

, , . , . , npm ; , , .

, package.json?

, . , .

, , , , . , npm : .

5 npm "npm-shrinkwrap.json" shrinkwrap:

npm shrinkwrap

, , , .

npm 5, "package-lock.json" , npm "node_modules" "package.json".

, package.json, npm install, , , . , .

. :

  • npm install , .
  • , .
  • npm shrinkwrap, npm-shrinkwrap.json git .

.json(, , ), npm update:

"devDependencies": {
   "someFixedVersionPackage": "^1.0.0",
   "anotherFixedVersionPackage": "^2.3.2",
}

package-lock.json . .

, ?

npm update : . :

  • npm install , .
  • . npm install --save package.json, ( "package-lock.json" "npm-shrinkwrap.json" ). , : running npm install .
  • , .
  • .

, :

  • , , (~) (^). npm update ( 0 - , . ). , "^ 1.0.0" "^ 1.1.0", "~ 2.3.2" "~ 2.3.4". --save --save-dev "package.json" ( ).

  • npm outdated, , . npm update. .

  • (, npm install browserify@11.2.0 --save-dev). , , . , , .

, ?

, , - , SemVer. . , , . , React 15, React react@15.x.x. . npm: SemVer?

. ?

:

npm 5?

5, npm "package-lock.json" , , . . , npm-shrinkwrap.json , package-lock.json . "package-lock.json" .

?

Yarn, npm- , , npm. yarn upgrade ยซpackageยป latest , package.json . yarn upgrade-interactive , npm-check.

$ yarn outdated
yarn outdated v0.16.1
Package      Current Wanted Latest
babel-eslint 7.0.0   7.0.0  7.1.0 
chai         3.0.0   3.0.0  3.5.0 
Done in 0.84s.
$ yarn upgrade babel-eslint chai
yarn upgrade v0.16.1
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 2 new dependencies.
โ”œโ”€ babel-eslint@7.1.0
โ””โ”€ chai@3.5.0
+14
+1

Running the following command will do what you want:

npm install someFixedVersionPackage@latest anotherFixedVersionPackage@latest --save-dev --save-exact

Structure:

  • npm install someFixedVersionPackage@latest install the latest package
  • The flag --save-devwill force it to update the version inpackage.json devDependencies
  • The flag --save-exactwill force it to keep the fixed version instead of the semver range operator

Link to npm install docs

0
source

Source: https://habr.com/ru/post/1674183/


All Articles