npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

es6-npm-boilerplate

v0.0.3

Published

Boilerplate for authoring in ES6 and publishing in ES5.

Downloads

5

Readme

es6-npm-boilerplate

Boilerplate for authoring in ES6 and publishing in ES5. Includes unit tests with Jest which are themselves authored in ES6.

Why Publish in ES5?

The benefits of authoring in ES6 are self-evident. But as explained by Brian LeRoux in ES6 Modules: The End of Civilization As We Know It?, when publishing JavaScript code, there's no guarantee that your consumer will be using an ES6-supported environment. If you don't publish ES5 source, then, you're putting the onus on them to run your build step--and odds are, they won't be up for it.

To quote Brian:

The only realistic assumption is the target runtime will be ES5 compatible.

Functionality

Transpilation is handled by the 6to5 module. Specifically, the entire src directory is compiled into the dist directory, as outlined in the package.json's prepublish script:

6to5 --modules common src --out-dir dist"

As the prepublish script is run by default whenever you publish to npm, you (as the author) never have to worry about transpiling.

In addition, we point the package.json to dist/index.js (to make sure that require('es6-npm-boilerplate') loads the ES5 source) with this line:

{
  ...
  "main": "dist/index.js",
  ...
}

Unit Tests

Unit tests are configured to pass all source through __tests__/jest.conf.js, which again runs 6to5. The configuration file is kept in the __tests__ directory to reduce clutter. This preprocessing step is handled with this portion of the package.json:

{
  ...
  "jest": {
    "scriptPreprocessor": "__tests__/jest.conf.js",
    "testPathIgnorePatterns": [
      "/node_modules/",
      "./__tests__/jest.conf.js"
    ]
  },
  ...
}

The ability to author your tests in ES6 and run them without an additional build step makes for a pretty remarkable experience.

What Gets Published?

Only the dist directory, package.json, and README are published to npm, as these are the only relevant parts of the codebase in the eyes of a consumer. This behavior is enforced by the .npmignore file, which reads as follows:

__tests__
src

Even if you choose to include these directories, you should still add an empty .npmignore to your repository. Otherwise, npm will default to a .npmignore that includes dist and thus the compiled ES5 code won't be published.

Acknowledgements

Thanks to Brian LeRoux for his helpful article and talking over some of this with me.

License

CC0.