Skip to content

Latest commit

 

History

History
62 lines (45 loc) · 3.84 KB

package.md

File metadata and controls

62 lines (45 loc) · 3.84 KB

Javascript / Package development

What to include

Packages only include production source code and a few mandatory files (included by default). The safe way to handle it is via package.json's files key which looks something like this:

{
  "files": [
    "/lib/**/*.js",
    "!/lib/**/*.test.js",
    "/lib/**/*.json",
    "/lib/**/*.svg"
  ],
}

ESM?

Update 2020-01-13: Mocha released experimental support in mocha@7.0.0-esm1

Update 2019-10-22: this 2ality post explains the possibilities of publishing hybrid NPM packages. Library support will have to be tested.

TLDR; no ESM.

There are many ways to interpret ES Modules, e.g. esm, Node's native experimental support (1, 2, 3) or webpack (1, 2). The common convention for declaring them is to use the .mjs extension for ESM files and .js (or .cjs) for CommonJS files.

Shipping backward compatible ESM packages could happen as:

The question "Is it safe to release ESM packages?" boils down to:

  • Can interpreters handle ESM files?
  • Can interpreters fall back to CommonJS files when needed?

TLDR; sadly no and no.

Can interpreters handle ESM files?

Can interpreters fall back to CommonJS files when needed?

Further reading