Installing and updating dependencies in JavaScript

Installing and updating JavaScript dependencies



Hello again! In the last post, we started looking at the process of managing dependencies in JavaScript, sorted out the basics: what is an npm package, what the package manifest looks like, in which fields the dependencies are written and, in principle, what is a dependency tree, as well as the basics of semantic versioning (semver). If you missed the previous post , I recommend starting with it.



semver, , .



npm shell autocomplete



npm . , shell.



, :



  • Bash:



    npm completion >> ~/.bashrc
    source ~/.bashrc


  • Z shell:



    npm completion >> ~/.zshrc
    source ~/.zshrc




shell- . , : npm smth… [TAB], shell .





, npm ( package.json). , npm init. .



: npm init -y, . npm , .





npm init, (npm initializers). boilerplate-.



: npm init <initializer>, <initializer> β€” (: esm react-app).



β€” npm- create-, npm registry . , .



React- create-react-app: npm init react-app -- my-react-app. CLI, npm init , . React, , , , , ( : my-react-app).



registry. , β€” npm registry. .





, : dependencies, devDependencies, peerDependencies optionalDependencies. : npm install <package-name> : npm i <package-name>.



: npm i lodash.



lodash dependencies .



: npm i lodash express passport.



install :



  • -P, --save-prod

    dependencies ( )
  • -D, --save-dev

    devDependencies
  • -O, --save-optional

    optionalDependencies


peerDependencies, . . npm . , dependencies npm install, peerDependencies, ( IDE npm).



, , npm , . . : ( Git).



npm install , . . : .




- , Β«@Β»:



  • npm i lodash@3.9.2
  • npm i lodash@3


. .





, , , git clone?



npm install npm i , npm , .



:



  • --only=prod[uction]
  • --only=dev[elopment]


, , , Node.js, .





. npm : npm ls.



: npm ls [<package-name>], <package-name> , .



, ( , ):





npm ls .



, «» , : npm ls lodash.





lodash npm ls lodash.



, npm ls depth. :



npm ls --depth=0


, .



dev prod , dependencies devDependencies:



  • npm ls --dev[elopment]
  • npm ls --prod[uction]


json , npm , . ( ):



npm ls --json




npm (semver). : , 1.2.3 1.2.4 (patch update) 1.3.0 (minor update), , . . semver . 1.2.3 2.0.0 , (changelog) , , , , .



, semver , , - patch minor ( , ).



, , , , , ( ).




semver . , npm : patch, minor .



package.json :



{
  "dependencies": {
    "lodash": "^4.17.17"
  }
}


«^» (caret, hat «») semver. , lodash , 5.0.0, . . patch minor , .



, semver, npm, 99% ( npm ), . . .





, , . , . . , :



{
  "dependencies": {
    "lodash": "4.17.17"
  }
}


, lodash 4.17.17, , .



:



  • , , , β€” ,
  • , , ( ). , , .


.



, β€” ( ). , . . , .





, , , . npm outdated .





npm outdated , .



:



Package
Current
Wanted , semver
Latest , ( )
Location


npm outdated , , depth , npm , :



npm outdated --depth=10


:



npm outdated --depth=9999




npm npm update.



npm registry semver . registry ( semver), , , . , semver, . . npm update , .



: lodash: ^4.16.4. npm update , 4.17.19, : ^4.17.19.



npm outdated, npm update depth , . , :



npm update --depth=9999


( ) . , .



npm-check



npm outdated npm update npm-check.



:



npm i -g npm-check


, , . , semver, , . : - . !





npm-check : , .





npm-check, : , .



β€” npm-check , - :





npm-check , lodash .



( ) .





, . npm uninstall : rm, r un. , :



npm rm lodash express


, .



Workflow npm-



, , workflow JavaScript-. , , .



  • :

    • npm init

      ()
    • npm init -y

      ( IDE)
  • :

    • npm install <dependency>
    • npm install <dependency-1> <dependency-2>…
    • npm install -D <dev-dependency>…
  • :

    • npm outdated

      ( )
    • npm outdated --depth=9999

      ( )
    • npm update

      ( semver)
    • npm update --depth=9999

      ( semver)
    • npm-check

      ( )
    • npm-check -u

      ( )
  • :

    • npm rm <dependency>




, , . semver .



. , !



β†’




All Articles