# agadoo

> Check whether a package is tree-shakeable

Latest version **3.0.0** (published 2022-11-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install agadoo
pnpm add agadoo
yarn add agadoo
bun add agadoo
```

Provides the command `agadoo`.

## Health

**Score 28/100 (F)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2022-11-29 |
| First published | 2018-08-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/agadoo) |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 547 |
| Author | Rich Harris |
| Maintainers | rich_harris |
| Keywords | modules, bundlers, rollup, webpack, parcel, tree-shaking |

## Links

- npm: https://www.npmjs.com/package/agadoo
- Repository: https://github.com/Rich-Harris/agadoo
- Homepage: https://github.com/Rich-Harris/agadoo#readme
- Issues: https://github.com/Rich-Harris/agadoo/issues
- npm.io page: https://npm.io/package/agadoo

## Dependencies (3)

- [acorn](https://npm.io/package/acorn.md) ^8.8.1
- [rollup](https://npm.io/package/rollup.md) ^3.5.0
- [@rollup/plugin-virtual](https://npm.io/package/@rollup/plugin-virtual.md) ^3.0.1

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2022-11-29
- 2.0.0 — 2020-01-02
- 1.1.0 — 2019-09-16
- 1.0.1 — 2018-09-26
- 1.0.0 — 2018-08-20

## README

# agadoo

*[Ag-a-doo-doo-doo, push pineapple, shake the tree](https://www.youtube.com/watch?v=POv-3yIPSWc)*


## 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](https://github.com/Rich-Harris/eases-jsnext) library contains a grab-bag of [Robert Penner's easing equations](http://robertpenner.com/easing/), presented as a JavaScript module. I can use it like this in my code...

```js
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:

```js
'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:

```bash
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:

```bash
npm install -D agadoo
```

```js
// package.json
{
  "scripts": {
    "prepublishOnly": "agadoo"
  }
}
```

You can specify the module if necessary:

```bash
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](https://github.com/rollup/rollup/wiki/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](LICENSE).

---
_Source: https://npm.io/package/agadoo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
