BrazilJS, 2015-08-22
He's not @isaacs, you can't fool me.
Before npm
clone this git repo: https://github.com/fs-webdev/asset-manager
run "make"
copy the file into your .node_libraries folder
make sure you name it “asset-manager.js"
make sure to pre-install
“async.js” https://github.com/caolan/async * + dependencies
“glob.js” https://github.com/isaacs/node-glob * + dependencies
“rimraf.js” https://github.com/isaacs/rimraf * + dependencies
“uglify-js.js” https://github.com/mishoo/UglifyJS2 * + dependencies
“less.js” https://github.com/less/less.js * + dependencies
Confirm that you are using the latest version from Github
Except for “glob.js”, in which case use the previous version 0.4
npm install asset-manager
With npm
* Lots of package managers support SemVer these days!
by making node.js do it
That's pretty cool.
A basic software contract that reduces overhead.
The registry is where the packages live.
GitHub is for developing,
npm is for distributing.
(Now with Portuguese support! Thanks, @benjamincoe!)
module.exports = {
name: prompt("What should we call your package?",
"bob",
function(name) { return name }
),
version: prompt("Version",
"1.0.0",
function(version) { return version }
)
}
module.exports = {
name: prompt(...),
version: prompt(...),
scripts: {
test: prompt(...),
setup: prompt(...)
}
}
and --save-deps
Because sometimes SemVer is a lie
deploy to production exactly what you ran in dev
locks every version of every package in node_modules
--save and --save-dev update shrinkwrap in npm 3
– some guy
npm pack @myuser/some-package
npm install myuser-some-package-1.0.1.tgz
npm install --cache-min 999999
We should probably call this npm --offline
makes semantic versioning quick and easy
npm version prepatch npm version patch npm version preminor npm version minor npm version premajor
npm version major
Thanks, @aredridel!
npm test npm start npm restart npm stop npm run $anything
{
"name": "@seldo/some-package",
"version": "1.0.0",
...
"scripts": {
"test": "mocha ./test/*.js",
"start": "node ./index.js"
}
}
"scripts": {
"dev": "ENVIRONMENT=development ./bin/my-app",
"setup": "// database setup goes here"
}
allows
> npm run setup
> npm run dev
...
Development server running on port 5000!
find . -name .git \
-prune -o -name node_modules \
-prune -o -name '*.min.js' \
-prune -o -name '*.js' \
-print0 | xargs -0 esformatter -i
or
npm run format
devDependencies in path
install gulp as a devDependency,
no need to tell devs to install it
2. config and package.json available as variables
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
Don't repeat yourself
"prepublish": "npm test && npm build-css && npm format"
(Only if you run npm install with no arguments in the package directory)
"postversion": "git push origin master --tags && npm publish"
Bonus tip: keep npm and git in sync automatically:
environment setup/teardown
transpilation
code cleanup
enforce best practices
automatically run tests
security checks
more!
Thanks, @boennemann
npm access
npm team
owners
, but better!manage access to multiple packages
read-only and read-write permission
permission is per-team, per-package
Orgs and Teams is a new, paid feature of npm
(user-level scopes are available for free)
@myuser/mypackage @mycompany/mypackage2
npm team create mycompany:web
npm team destroy mycompany:web
npm team add mycompany:web user1
npm team rm mycompany:web user1
npm team ls mycompany:web
npm team ls mycompany
npm access grant read-only mycompany:web mypackage
npm access grant read-write mycompany:api mypackage
npm access revoke mycompany:web mypackage
npm access ls-collaborators @mycompany/mypackage
npm access ls-packages mycompany:team
npm access ls-packages mycompany
npm access ls-packages myuser
npm install npm@beta -g
1995's technology, today!
So many race conditions!
Smarter, consistent, more reliable.
npm 2
npm 3
npm install npm@beta -g
whether or not you use node.js
As popularized by bower
parcelify
sheetify
npm.im/dr-frankenstyle
(Thanks for the question, @codepo8!)
It is surprisingly tricky to come up with the definition of a "good" package
Because not everybody likes the command line.
What problem does this solve?
A Slack group for gay, lesbian, bisexual, transgender and queer people in tech
laurie@npmjs.com