Skip to content

Instantly share code, notes, and snippets.

@nexdrew
Last active January 21, 2016 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nexdrew/2e5284ecf74f45f352a4 to your computer and use it in GitHub Desktop.
Save nexdrew/2e5284ecf74f45f352a4 to your computer and use it in GitHub Desktop.

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() or import
    • 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 and git push
    • git clone
  • create package.json
  • pick a license (SPDX compatible)
  • write some code
    • main export, typically defined in index.js
    • submodules in lib or src
    • CLI program? how about a bin file?
  • 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 maybe pretest or posttest) scripts in your package.json file
    • Travis automatically runs npm install and npm test against configured versions of Node
  • 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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment