Publishing npm Packages

Photo by Engin Akyurt via Pexels.

Introduction

In the node.js package maintenance working group, one of the topics we’ve been discussing is about what files to include or exclude when publishing npm packages.

  • coverage, .nyc_output - coverage output for istanbul and nyc
  • .idea, .vscode - configs for IDE or editors
  • .github, .travis.yml - github and travis config directory
  • .npmignore - npm publish ignore list file
  • .DS_Store - Mac OS filesystem meta data
  1. how packages should exclude these files when publishing
  2. whether other files like tests and sources should be published (but would be a non-issue once npm tink project is released)

Publish without Meta Files

When publishing, npm allows you to either exclude certain files or include only the files you want. They work opposite of each other so you have to decide on the approach you want to take.

Excluding Files

By default, npm uses exclusion to skip publishing files, and it actually comes with reasonable defaults to exclude some of the most common files like .gitignore. It automatically uses .gitignore to exclude more files, but if another file .npmignore is present, then it will be used and .gitignore is ignored.

Including Files

npm supports another way to skip publishing files through an include list in package.json. You can set a field files with an array of files and/or directories that npm should only include in your published packages.

Exclude or Include

Since the two approaches are completely opposite of each other, there are different reasons to pick one over the other.

Tests and Sources

If you look at the packages installed in your node_modules, you would see that most of them have their tests and rc files with them also.

Closing

We established a baseline and a recommendation guide for publishing packages without meta files, using either the exclude or include support from npm.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Node.js

Node.js

Node.js is a collaborative open source project dedicated to building and supporting the Node.js platform. https://nodejs.org/en/