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

@drewigg/agadoo

v3.0.0-drewigg.2

Published

Check whether a package is tree-shakeable

Downloads

11

Readme

agadoo

This package is a fork of Rich Harris's agadoo, updated to Rollup 2 and Acorn 8.

Ag-a-doo-doo-doo, push pineapple, shake the tree

What this does

Tells you whether the JavaScript library you're building is tree-shakeable.

What it doesn't do

Tell you why tree-shaking fails, if it does. Maybe in a future version.

Hold up — tree what now?

With the advent of JavaScript modules (import and export), it's possible to build libraries that are tree-shakeable. This means that a user of your library can import just the bits they need, without burdening their users with all the code you're not using.

For example, the eases-jsnext library contains a grab-bag of Robert Penner's easing equations, presented as a JavaScript module. I can use it like this in my code...

import * as eases from 'eases-jsnext';

for (let t = 0; t <= 1; t += 0.05) {
  const eased = eases.cubicInOut(t)
  const str = repeat('*', eased * 20);
  console.log(str);
}

function repeat(str, num) {
  let result = '';
  num = Math.round(num);
  while (num--) result += str;
  return result;
}

...and all the easing functions that I haven't used will get removed during bundling, if I'm using a modern bundler such as Rollup, webpack or Parcel. Here's what that bundle would look like with Rollup:

'use strict';

function cubicInOut(t) {
  return t < 0.5
    ? 4.0 * t * t * t
    : 0.5 * Math.pow(2.0 * t - 2.0, 3.0) + 1.0
}

for (let t = 0; t <= 1; t += 0.05) {
  const eased = cubicInOut(t);
  const str = repeat('*', eased * 20);
  console.log(str);
}

function repeat(str, num) {
  let result = '';
  num = Math.round(num);
  while (num--) result += str;
  return result;
}

...and here's the result of running it:


*
*
**
***
*****
*******
**********
*************
***************
*****************
******************
*******************
*******************
********************
********************
********************

But I digress. The point is that this works because eases-jsnext is a tree-shakeable library.

Using agadoo

Inside your project folder, run Agadoo like so:

npx agadoo

You can install it as a development dependency and run it each time you npm publish — if tree-shaking fails, publishing will be aborted:

npm install -D agadoo
// package.json
{
  "scripts": {
    "prepublishOnly": "agadoo"
  }
}

You can specify the module if necessary:

agadoo dist/my-library.js

Help! My library isn't tree-shakeable and I'm not sure why

Firstly, make sure you're exposing a JavaScript module using the "module" field of your package.json (aka pkg.module).

If tree-shaking still fails, it's because Rollup thinks that there are side-effects somewhere in your code. Follow these guidelines:

  • Avoid transpilers like Babel and Bublé (and if you're using TypeScript, target a modern version of JavaScript)
  • Export plain functions
  • Don't create instances of things on initial evaluation — instantiate lazily, when the functions you export are called

License

LIL.