EnterJS, 2016-06-16
Laurie Voss
CTO,
@seldo
Part 1
npm does not* download packages from GitHub
* not usually, and not by default
Part 2
npm install -g npm
npm install -g npm@lts
or
npm init --yes
npm init --scope=myusername npm install @myusername/mypackage var x = require('@myusername/mypackage')
> npm install --save > npm install -S > npm install --save-dev > npm install -D
> npm install --production
* mostly
npm install --cache-min 999999
npm config set cache-min 60
npm start npm stop npm restart npm test
{
"name": "@seldo/some-package",
"version": "1.0.0",
...
"scripts": {
"test": "mocha ./test/*.js",
"start": "node ./index.js"
}
}
npm publish npm publish --access=public npm publish --access=restricted
Part 3: sharing a project
Semantic Versioning
2.15.58
Breaking
major
Feature
minor
Fix
patch
npm version major npm version minor npm version patch
npm version major -m "bump to version %s"
npm install clingwrap -g
Maybe try
npm team npm access
npm team create <scope:team> npm team destroy <scope:team> npm team add <scope:team> <user> npm team rm <scope:team> <user> npm team ls <scope:team>
npm access grant read-only <scope:team> [package] npm access grant read-write <scope:team> [package] npm access revoke <scope:team> [package] npm access ls-packages [user|scope|scope:team] npm access ls-collaborators [package [user]]
npm link
Part 4: managing dependencies
npm link
In your package "@myuser/bob":
In your other package, which requires "@myuser/bob":
npm link @myuser/bob
npm publish --tag npm dist-tag
npm publish --tag <tag> npm install <pkg>@<tag>
Try it out:
npm install npm@next
to try out next week's release
npm dist-tag add <pkg>@<version> <tag> npm dist-tag rm <tag> npm dist-tag ls <package>
(you may have heard about this one recently)
npm unpublish <pkg>@<version>
npm deprecate <pkg>[@<version>] <message>
npm deprecate bob@1.0.1 "Breaks everything"
e.g.
npm outdated npm update
Package Current Wanted Latest Location domutils 1.3.0 1.3.0 1.5.1 @npm/testnpm handlebars 1.3.0 1.3.0 4.0.5 @npm/testnpm hbsfy 1.3.2 1.3.2 2.7.0 @npm/testnpm
npm run $anything
"npmcheckversion": "node ./internals/scripts/npmcheckversion.js",
"preinstall": "npm run npmcheckversion",
"prebuild": "npm run test && npm run build:clean",
"build:clean": "rimraf ./build/*",
"build": "cross-env NODE_ENV=production webpack --config internals/webpack/webpack.prod.babel.js --color -p",
"analyze": "node ./internals/scripts/analyze.js",
"start": "cross-env NODE_ENV=development node server",
"start:tunnel": "cross-env NODE_ENV=development ENABLE_TUNNEL=true node server",
"start:production": "npm run build && npm run start:prod",
"start:prod": "cross-env NODE_ENV=production node server",
"pagespeed": "node ./internals/scripts/pagespeed.js",
"presetup": "npm i chalk",
"setup": "node ./internals/scripts/setup.js",
"clean": "shjs ./internals/scripts/clean.js",
"generate": "plop --plopfile internals/generators/index.js",
"lint": "npm run lint:js && npm run lint:css",
"lint:js": "eslint . --ignore-path .gitignore --ignore-pattern internals/scripts",
"lint:css": "stylelint ./app/**/*.css",
"lint:staged": "lint-staged",
"pretest": "npm run lint",
Don't read this. Just remember "there were lots of examples".
Part 5: managing project lifecycle
npm_package_name npm_package_version npm_package_dependencies_request npm_package_dependencies_express npm_config_node_version npm_config_registry
console.log(process.env.npm_package_name)
e.g.
{
"name": "@seldo/mypackage",
"config": {
"port": "80"
}
}
console.log(npm_package_config_port) > 80 > npm config set @seldo/mypackage:port 8080 console.log(npm_package_config_port) > 8080
publish: prepublish, publish, postpublish install: preinstall, install, postinstall uninstall: preuninstall, uninstall, postuninstall version: preversion, version, postversion test: pretest, test, posttest stop: prestop, stop, poststop start: prestart, start, poststart restart: prerestart, restart, postrestart
per-project: /path/to/my/project/.npmrc
per-user: ~/.npmrc
global: $PREFIX/etc/npmrc
built-in: /path/to/npm/npmrc
//registry.npmjs.org/:_authToken=00000000-0000-0000-0000-000000000000
Looks like:
//registry.npmjs.org/:_authToken={$NPM_TOKEN}
For CI, try:
More details:
Part 6
npm install wombat -g
Fired after every:
wombat hook add @myco/package https://my.co/myhook some-secret
wombat hook add somepackage wombat hook add @myco/package wombat hook add @myco wombat hook add --type=owner @anyuser
Packages:
Scopes:
Users:
wombat hook ls wombat hook update <hook-id> https://new.co new-secret wombat hook rm <hook-id>
var makeReceiver = require('npm-hook-receiver');
var server = makeReceiver({
secret: 'my-secret',
mount: '/hook'
});
server.on('package:publish', function(package)
{
console.log(`${package.name} was updated!`);
});
Lets you build the features we're missing.
Transpile all the things!
and
greenkeeper.io
"npm outdated" as a service!
npm install nsp -g
nsp check
architecture
npm update
npm init
auto saving
.npm-init.js
devDependencies
bundledDependencies
offline installs
run scripts
publishing
SemVer
npm version
shrinkwrap
npm team
npm access
npm link
dist-tags
unpublish
deprecate
outdated
lifecycle events
.npmrc files
webhooks
...and more!
npm wants to make your life easier
Really, it's been here for some time.
Hook into your automation.
The more we know, the more we can help.
Making the registry do more for you:
For lesbian, gay, bisexual, transgender, and queer people of all kinds in tech.
(this is nothing to do with npm)
npm you
Follow me on Twitter for no reason!
@seldo
Good questions get t-shirts!