Halo lagi! Di posting terakhir, kita mulai melihat proses pengelolaan dependensi dalam JavaScript, mengurutkan dasar-dasarnya: apa itu paket npm, seperti apa bentuk manifes paket, di bidang mana dependensi ditulis dan, pada prinsipnya, apa itu pohon dependensi, serta dasar-dasar pembuatan versi semantik (semver). Jika Anda melewatkan posting sebelumnya , saya sarankan untuk memulainya.
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 .
. , !