Node philosophy = Unix philosophy
- many small modules
- each module does one thing and does it well
- think lego bricks
- why is this good for open source?
- smaller surface area
- easier to test
- easier to understand
- easier to contribute
Difference b/w a package and a module
- A package is essentially just a directory (or tarball) with some metadata
- You publish and install packages
- A module is some code you
require()
orimport
- You code and export modules
I want to create a module that I will publish as a package - how do I start?
- come up with a name and mkdir it
- create a GH repo
git init
andgit push
git clone
- create
package.json
- pick a license (SPDX compatible)
- write some code
- main export, typically defined in
index.js
- submodules in
lib
orsrc
- CLI program? how about a bin file?
- main export, typically defined in
- write some tests
- add CI
- write docs
- test, push, test
npm publish
How to create a package.json
file?
- As simple as
npm init
- name
- version
- description
- repo
- keywords
- author
- license
- scripts
- lifecycle
- custom
- dependencies and devDependencies
npm install --save
npm install --save-dev
How does CI work?
- Add
.travis.yml
file to your GH repo- defines runtime (multiple versions) and services (external resources)
- Define
test
(and maybepretest
orposttest
) scripts in yourpackage.json
file- Travis automatically runs
npm install
andnpm test
against configured versions of Node
- Travis automatically runs
- Enable Travis service in GH repo
- build on push and PR
- Done!
Releasing changes
Let's talk about the Open Source Workflow
- idea or problem
- create an issue
- open for discussion
- make some changes
- fork, clone
- create a new branch
- write code, write tests (or vice versa)
- commit and push
- open PR
- review => commit, maybe rebase, push
- merge and delete branch
- rinse, repeat
- see why tests and CI are important?
- time to release
npm version
git push --follow-tags
- wait for CI build
npm publish
Let's talk about semver
- What the heck is it?
- Semantic Versioning
- Standard format with specific meaning
- major.minor.patch = breaking.feature.bugfix
- What does that mean?
- breaking
- API or functional change that could break someone else's code
- examples?
- feature
- an addition, preserves existing API/functionality
- examples?
- bugfix
- a change to unintended or broken existing functionality
- examples?
- when in doubt, just increment major version
- breaking
Let's talk about tests
- You need a test runner, an API for tests, and assertions
- all test frameworks come with first 2, some come with all 3
- sometimes you need mocking too
- Test runner + API
- mocha
- lab
- tape
- Assertions
- chai
- should
- code
- Node's assert
- All-in-one
- ava
- tap
- jasmine
- Mocking
- nock
- sinon
Let's talk about code coverage
- nyc
- coveralls
Let's talk about docs
- README
- CONTRIBUTING and CoC
Other things we probably won't get to
- Greenkeeper
- InnerSource
- People to follow
- YourFirstPR
- Module requests
- Code style and linters