# @goto-bus-stop/common-shake

> CommonJS Tree Shake (fork)

Latest version **2.4.1** (published 2024-01-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @goto-bus-stop/common-shake
pnpm add @goto-bus-stop/common-shake
yarn add @goto-bus-stop/common-shake
bun add @goto-bus-stop/common-shake
```

## Health

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

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.4.1 |
| Published | 2024-01-04 |
| First published | 2018-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 29 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Fedor Indutny |
| Maintainers | goto-bus-stop |
| Keywords | commonjs, tree, shake |

## Links

- npm: https://www.npmjs.com/package/@goto-bus-stop/common-shake
- Repository: https://github.com/goto-bus-stop/common-shake
- Homepage: https://github.com/goto-bus-stop/common-shake#readme
- Issues: https://github.com/goto-bus-stop/common-shake/issues
- npm.io page: https://npm.io/package/@goto-bus-stop/common-shake

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) ^3.2.6
- [escope](https://npm.io/package/escope.md) ^3.6.0
- [acorn-walk](https://npm.io/package/acorn-walk.md) ^7.0.0

## Recent versions

- 2.4.1 (latest) — 2024-01-04
- 2.4.0 — 2020-03-09
- 2.3.0 — 2019-06-29
- 2.2.0 — 2018-04-11

## README

# @goto-bus-stop/common-shake
[![NPM version](https://badge.fury.io/js/%40goto-bus-stop%2Fcommon-shake.svg)](http://badge.fury.io/js/%40goto-bus-stop%2Fcommon-shake)
[![Build Status](https://secure.travis-ci.org/goto-bus-stop/common-shake.svg)](http://travis-ci.org/goto-bus-stop/common-shake)

> This is a fork of [indutny/common-shake](https://github.com/indutny/common-shake),
> pending [#3](https://github.com/indutny/common-shake/pull/3).

---

See [webpack-common-shake][0] for [webpack][1] plugin.
See [common-shakeify][3] for a [browserify][4] plugin.

## Usage

```js
const acorn = require('acorn');
const Analyzer = require('@goto-bus-stop/common-shake').Analyzer;

const a = new Analyzer();

a.run(acorn.parse(`
  'use strict';
  const lib = require('./a.js');
  exports.a = lib.a;
`, { locations: true }), 'index.js');

a.run(acorn.parse(`
  'use strict';
  exports.a = 42;
`, { locations: true }), 'a.js');

a.resolve('index.js', './a.js', 'a.js');
console.log(a.isSuccess(), a.bailouts);
// true false

console.log(a.getModule('index.js').getInfo());
// { bailouts: false, declarations: [ 'a' ], uses: [] }

console.log(a.getModule('a.js').getInfo());
// { bailouts: false, declarations: [ 'a' ], uses: [ 'a' ] }

const module = a.getModule('a.js');
a.getDeclarations().forEach((decl) => {
  console.log(module.isUsed(decl.name) ? 'used' : 'not used');
  console.log(decl.name, decl.ast);
});

// If you want to mark all exported values of module as used:
a.getModule('root').forceExport();
```

## Graphviz

For debugging and inspection purposes a graph in [dot][2] format may be
generated from the modules hierarchy using following API:

```js
const Graph = require('@goto-bus-stop/common-shake').Graph;
const graph = new Graph('/path/to/working/dir');

console.log(graph.generate(analyzer.getModules()));
```

## LICENSE

This software is licensed under the MIT License.

Copyright Fedor Indutny, 2017.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.

[0]: https://github.com/indutny/webpack-common-shake
[1]: https://webpack.github.io/
[2]: http://www.graphviz.org/content/dot-language
[3]: https://github.com/browserify/common-shakeify
[4]: https://browserify.org

---
_Source: https://npm.io/package/@goto-bus-stop/common-shake · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
