https://github.com/thepassle/find-dependencies
https://github.com/thepassle/find-dependencies
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/thepassle/find-dependencies
- Owner: thepassle
- Created: 2021-10-17T07:43:44.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-10-18T08:52:47.000Z (over 3 years ago)
- Last Synced: 2024-11-12T21:45:41.033Z (3 months ago)
- Language: JavaScript
- Size: 83 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# find-dependencies
Given an array of paths, scans all modules and returns all depending paths.
Intended to be used on post-build, frontend facing, ESM based code.
## Usage
```js
const inputPaths = ['my-package/index.js'];
```Where `my-package/index.js` contains:
```js
import '@scoped/package';
import {b} from '@scoped/package/baz/index.js';
import c from 'export-map';
import d from 'nested';
import e from 'regular';
import g from './bla.js';
import('dynamic-import');
``````js
const inputPaths = ['my-package/index.js'];
const dependencies = await findDependencies(inputPaths);
```Will output:
```js
[
'/users/blank/my-package/node_modules/@scoped/package/index.js',
'/users/blank/my-package/node_modules/@scoped/package/baz/index.js',
'/users/blank/my-package/node_modules/export-map/long/path/index.js',
'/users/blank/my-package/node_modules/nested/index.js',
'/users/blank/my-package/node_modules/regular/index.js',
'/users/blank/my-package/node_modules/dynamic-import/index.js',
'/users/blank/my-package/node_modules/nested/node_modules/regular/index.js'
]
```## Configuration
```js
export interface Options {
/**
* In case `node_modules` is higher up in the file tree, for example in a monorepo
* Defaults to 3
*/
nodeModulesDepth?: number,
/** Defaults to `process.cwd()` */
basePath?: string
}
``````js
findDependencies(inputPaths, {
basePath: 'foo/bar',
nodeModulesDepth: 5,
});
```