# find-requires

> Find all require() calls. Fast and solid implementation backed with direct scanner and esprima AST parser

Latest version **1.0.0** (published 2019-03-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install find-requires
pnpm add find-requires
yarn add find-requires
bun add find-requires
```

Provides the command `find-requires`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-03-12 |
| First published | 2012-02-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 24 |
| Author | Mariusz Nowak |
| Maintainers | medikoo |
| Keywords | analyze, dependency, detective, exports, module, modules, parser, require, resolver, scan, scanner, source, static |

## Links

- npm: https://www.npmjs.com/package/find-requires
- Repository: https://github.com/medikoo/find-requires
- Homepage: https://github.com/medikoo/find-requires#readme
- Issues: https://github.com/medikoo/find-requires/issues
- npm.io page: https://npm.io/package/find-requires

## Dependencies (2)

- [esniff](https://npm.io/package/esniff.md) ^1.1.0
- [es5-ext](https://npm.io/package/es5-ext.md) ^0.10.49

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2019-03-12
- 0.2.4 — 2018-12-28
- 0.2.3 — 2017-03-15
- 0.2.2 — 2014-08-27
- 0.2.1 — 2014-07-25
- 0.2.0 — 2014-04-28
- 0.1.6 — 2013-04-10
- 0.1.5 — 2012-12-08
- 0.1.4 — 2012-10-05
- 0.1.3 — 2012-07-25
- 0.1.2 — 2012-06-13
- 0.1.1 — 2012-03-26
- 0.1.0 — 2012-02-21

## README

[![Build status][nix-build-image]][nix-build-url]
[![Windows status][win-build-image]][win-build-url]
![Transpilation status][transpilation-image]
[![npm version][npm-image]][npm-url]

# find-requires – Find all require() calls.

Made for [modules-webmake](https://github.com/medikoo/modules-webmake). Fast [esniff](https://github.com/medikoo/esniff#esniff) based implementation of require calls parser.

## Example

foo.js:

```javascript
var one = require("one");
var two = require("two");
var slp = require("some/long" + "/path");
var wrong = require(cannotTakeThat);
```

program.js:

```javascript
var fs = require("fs");
var findRequires = require("find-requires");

var src = fs.readFileSync("foo.js", "utf-8");

console.log(findRequires(src)); // => ['one', 'two', 'some/long/path'];

// or we can get more detailed data with `raw` option:
console.log(findRequires(src, { raw: true })); /* => [
	{ value: 'one', raw: '\'one\'', point: 19, line: 1, column: 19 },
	{ value: 'two', raw: '\'two\'', point: 45, line: 2, column: 19 },
	{ value: 'some/long/path', raw: '\'some/long\' +\n\t\t\t\t\t\t\'/path\'',
		point: 71, line: 3, column: 19  },
	{ raw: 'cannotTakeThat', point: 121, line: 5, column: 21 }
] */

// We can also ensure some specific cases of dynamic requires code with some setup code injection
console.log(
	findRequires("require(__dirname + '/foo.js')", {
		setupCode: `const __dirname = ${ JSON.stringify(__dirname) }`
	})
);
```

## CLI Example

```
> npm install -g find-requires
```

Find all requires in a file:

```
> find-requires file1.js
test1.js:3:LIB + '/test2'
test1.js:4:fs
```

Find all places the fs module is required: `find-requires -m fs $(find . -name '*.js')`

## Tests

    $ npm test

[nix-build-image]: https://semaphoreci.com/api/v1/medikoo-org/find-requires/branches/master/shields_badge.svg
[nix-build-url]: https://semaphoreci.com/medikoo-org/find-requires
[win-build-image]: https://ci.appveyor.com/api/projects/status/7i22v2m9om08fklw?svg=true
[win-build-url]: https://ci.appveyor.com/project/medikoo/find-requires
[transpilation-image]: https://img.shields.io/badge/transpilation-free-brightgreen.svg
[npm-image]: https://img.shields.io/npm/v/find-requires.svg
[npm-url]: https://www.npmjs.com/package/find-requires

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