Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/babel-utils/babel-collect-imports
Recursively collect all the internal and external dependencies from an entry point
https://github.com/babel-utils/babel-collect-imports
babel babylon dependencies external imports internal parse
Last synced: about 2 months ago
JSON representation
Recursively collect all the internal and external dependencies from an entry point
- Host: GitHub
- URL: https://github.com/babel-utils/babel-collect-imports
- Owner: babel-utils
- License: mit
- Created: 2018-01-03T05:10:21.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-07T09:38:26.000Z (almost 6 years ago)
- Last Synced: 2024-03-25T20:18:56.301Z (9 months ago)
- Topics: babel, babylon, dependencies, external, imports, internal, parse
- Language: JavaScript
- Size: 32.2 KB
- Stars: 35
- Watchers: 3
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# babel-collect-imports
> Recursively collect all the internal and external dependencies from an entry point
## Install
```sh
yarn add babel-collect-imports
```## Usage
```js
const { collectImportsSync } = require('babel-collect-imports');let { internal, external } = collectImportsSync('path/to/entry.js');
// { internal: ['path/to/entry.js', 'path/to/import.js', 'path/to/other/import.js'],
// external: ['lodash', 'react'] }
```When it discovers an "internal" dependency (one that is not a node package), it
will follow the import and continue collecting dependencies.## API
### `collectImportsSync(entry, parserOpts?, resolveOpts?)`
- `entry` should be a full file path
- `parserOpts` is [Babylon's](https://github.com/babel/babel/tree/master/packages/babylon) options
- `resolveOpts` is [resolve's](https://github.com/browserify/resolve) options## FAQ
#### How are "internal" vs "external" imports determined?
It's all about the starting dot:
```js
import internal from './internal-because-it-starts-with-a-dot';
import external from 'external-because-it-does-not-start-with-a-dot';
```#### What about my special aliasing system?
Your custom aliasing is bad and you should feel bad. Try playing with
`resolveOpts`.