Upload
pieter-herroelen
View
218
Download
2
Embed Size (px)
NPMBeyond npm i
Pieter Herroelen
NPM?
NPM 2 vs NPM 3
NPM scripts
"scripts": { "postinstall": "echo \"Thanks for installing my package \""},
● prepublish: Run BEFORE the package is published. (Also run on local npm install without any arguments.)● publish, postpublish: Run AFTER the package is published.● preinstall: Run BEFORE the package is installed● install, postinstall: Run AFTER the package is installed.● preuninstall, uninstall: Run BEFORE the package is uninstalled.● postuninstall: Run AFTER the package is uninstalled.● preversion, version: Run BEFORE bump the package version.● postversion: Run AFTER bump the package version.● pretest, test, posttest: Run by the npm test command.● prestop, stop, poststop: Run by the npm stop command.● prestart, start, poststart: Run by the npm start command.● prerestart, restart, postrestart: Run by the npm restart command. Note: npm restart will run the stop and
start scripts if no restart script is provided.
(https://docs.npmjs.com/misc/scripts)
Predefined script names
"scripts": { "grunt-version": "grunt --version"},
$ grunt --versiongrunt-cli v0.1.13grunt v1.0.0$ npm run grunt-version
> npm-test@1.0.0 grunt /Users/pieter/projects/npm-test> grunt --version
grunt-cli v1.2.0grunt v1.0.1
Custom script names
How to use NPM as a build toolhttp://blog.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/
NPM version syntax
MAJOR.MINOR.PATCH
MAJOR.MINOR.PATCH
= Semantic versioning aka semver
1.2.3 - 2.3.4
Minimum version
Comparator( < or <= )
Maximum version
1.2.3 - 2.3.4
1.2.3 <= 2.3.4
= Hyphen range
1.x
Minimum version
Comparator( < or <= )
Maximum version
1.x
1.0.0 < 2.0.0
= Hyphen range
~1.2.3
Minimum version
Comparator( < or <= )
Maximum version
~1.2.3
1.2.3 < 1.3.0
= tilde range
^1.2.3
Minimum version
Comparator( < or <= )
Maximum version
^1.2.3
1.2.3 < 2.0.0
= caret range (default)
^0.2.3
Minimum version
Comparator( < or <= )
Maximum version
^0.2.3
0.2.3 < 0.3.0
NPM repositories
Module
Module author:npm publish
Your app
You:npm install
March 23rd, 2016
babel leftpad
Module
Module author:npm unpublish
Your app
You:npm install babel
http://back-grounds.com/file/792/1680x1050/crop/atomic-blast.jpg
You cannot publish over the previously published version.
babel leftpad^0.0.3
^0.0.3
Minimum version
Comparator( < or <= )
Maximum version
^0.0.3
0.0.3 < 0.0.4
Module
Module author:npm publish
Your app
You:npm install
Private NPMrepository
Module
Module author:npm unpublish
Your app
You:npm install
Private NPMrepository
NPM shrinkwrap
B(external)
C(external)
A
B(1.0.0)
C(1.0.0)
1.0.0 1.0.0
B(external)
C(external)
A
B(1.0.0)
C(1.0.0)
C(1.0.1)
1.0.0 1.0.1
$ npm shrinkwrapwrote npm-shrinkwrap.json
B(external)
C(external)
A
B(1.0.0)
C(1.0.0)
C(1.0.1)
1.0.0 1.0.0
Your own NPM repo + shrinkwrap = reproducible builds :)
Scoped packages
Module@neoscores/some-
module
Your colleague:npm publish
Your app
You:npm loginnpm install @neoscores/some-module