npm

Follow live

http://slides.com/garykatsevman/npm/live

Hi

Gary Katsevman

🏛 Brightcove / video.js

🐙 @gkatsev

🐦 @gkatsev

Updating npm

$ npm install --global npm@latest
$ npm i -g npm@latest-2

binaries

$ npm i -g grunt-cli
$ npm install --global grunt-cli
$ npm i grunt-cli
$ ./node_modules/.bin/grunt
$ $(npm bin)/grunt
$ cat package.json
{
  "name": "test",
  "version": "1.0.0",
  "scripts": {
    "grunt": "grunt",
    "test": "grunt test"
  }
}
$ npm run grunt
$ npm run grunt -- test

Don't edit package.json manually

$ npm install --save global
$ npm i -S global
$ cat package.json
{
  ...
  "dependencies": {
    "global": "^4.3.0"
  }
  ...
}
$ npm install --save --save-exact global
$ npm install -S -E global
$ cat package.json
{
  ...
  "dependencies": {
    "global": "4.3.0"
  }
  ...
}
$ npm install --save-dev grunt-cli grunt
$ npm i -D grunt-cli grunt # grunt-cli is installed into $(npm bin) automatically now with RC1
$ cat package.json
{
  ...
  "devDependencies": {
    ...
    "grunt": "^0.4.4",
    "grunt-cli": ""^0.1.13",
    ...
  }
  ...
}
$ npm help 7 config

NAME
       npm-config - More than you probably want
to know about npm configuration

versioning

$ npm version major|minor|patch
$ npm version premajor|preminor|prepatch|prerelease
$ npm version patch
new version is 1.0.1
$ npm version minor
new version is 1.1.0
$ npm major
new version is 2.0.0
$ npm version premajor
new version is 3.0.0-0
$ npm version major
new version is 3.0.0

npm xmas

npm substack

Replace your configs with services

npm scripts

$ cat package.json
{
  ...
  "scripts": {
    "prebuild": "mkdirp dist/",
    "build": "browserify . -o dist/bundle.js",
    "pretest": "npm run lint",
    "test": "node tests/**/*.js",
    "lint": "vjsstandard",
    "start": "npm-run-all -p test build", 
    ...
  }
  ...
}
$ npm run test
running `pretest`:
  vjsstandard

running `test`:
  node tests/**/*.js
.
.
.
$ cat package.json
{
  ...
  "scripts": {
    "version": "npm run build && git add ."
    ...
  }
  ...
}
$ cat package.json
{
  ...
  "scripts": {
    "version": "chg release && git add CHANGELOG.md"
    ...
  }
  ...
}

npm's prepublish

$ cat package.json
{
  ...
  "scripts": {
    "build": "browserify . -o dist/bundle.js",
    "prepublish": "npm-run-all -s test build"
    ...
  }
  ...
}

$ cat package.json
{
  ...
  "scripts": {
    "build": "browserify . -o dist/bundle.js",
    "prepublish": "not-in-install && npm-run-all -s test build || in-install"
    ...
  },
  "devDepdenencies": {
    "in-publish": "^2.0.0",
    ...
  },
  ...
}

links

  • https://github.com/sindresorhus/awesome-npm/blob/master/readme.md
  • https://www.npmjs.com/package/in-publish
  • https://www.npmjs.com/package/chg
  • https://www.npmjs.com/package/npm-run-all

npm

By Gary Katsevman