My Recent npm Package Toolset

I’ve published a few Node modules to npm in the last week, and I wanted to share the tools I’ve been using to make this process easy and enjoyable.

:rocket: Publishing

semantic-release is a game changer. Not only does this tool automate publishing to npm from Travis CI, it takes care of semantic versioning based on the commits since the last deployment to npm. In order to do this, semantic-release requires a commit message convention (I stick with the default defined by the AngularJS team).

All I need to do is push code to master (usually through GitHub pull requests), and semantic-release takes care of publishing the new version of my Node module to npm. This makes shipping code super simple! :relieved:

:white_check_mark: Code Quality

husky is a git hook manager, making it really easy to format source code, lint staged files, and run tests all before code is committed and/or pushed to GitHub.

Here is a snippet from danger-plugin-jira-issue’s package.json.

{
  "scripts": {
    "precommit": "lint-staged",
    "commit": "git-cz",
    "commitmsg": "validate-commit-msg"
  },
  "lint-staged": {
    "*.js": [
      "prettier --single-quote --trailing-comma=all --no-semi --write",
      "git add"
    ]
  },
  "config": {
    "commitizen": {
      "path": "cz-conventional-changelog"
    }
  },
  "devDependencies": {
    "commitizen": "^2.9.6",
    "cz-conventional-changelog": "^2.0.0",
    "husky": "^0.13.3",
    "lint-staged": "^3.4.1",
    "prettier": "^1.3.1",
    "validate-commit-msg": "^2.12.1"
  }
}

Assuming I use the npm commit script (or git cz per commitizen’s README) in order to create a conventional commit message for semantic-release, these git hooks will:

  • before committing, auto-format all staged .js files using prettier
  • after committing, validate that the commit message adheres to semantic-release’s convention

This way, I am always committing code that adheres to the same style, and each commit can be used by semantic-release to determine the next Node module version to publish.

:book: Documentation

Clear, clean code documentation is important, and ESDoc has been my tool of choice when writing ES2015 code compiled with Babel. ESDoc will even host your documentation, which makes it really easy to annotate your codebase and let ESDoc take care of the rest. Check out a recent example here.


What’s your workflow for creating an npm package? What tools make development and deployment easier and more enjoyable? I’d love to hear on twitter - @macklinu. :heart: