https://github.com/egoist/konan
find all require/import calls by walking the AST
https://github.com/egoist/konan
ast babylon detective import require
Last synced: 8 months ago
JSON representation
find all require/import calls by walking the AST
- Host: GitHub
- URL: https://github.com/egoist/konan
- Owner: egoist
- License: mit
- Created: 2017-02-05T11:30:51.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-12-25T14:42:00.000Z (over 4 years ago)
- Last Synced: 2025-08-25T23:36:07.754Z (8 months ago)
- Topics: ast, babylon, detective, import, require
- Language: JavaScript
- Homepage:
- Size: 79.1 KB
- Stars: 53
- Watchers: 3
- Forks: 5
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# konan
[](https://npmjs.com/package/konan) [](https://npmjs.com/package/konan)  [](https://github.com/egoist/donate)
> Like [detective](https://github.com/substack/node-detective) but also supports ES6 `import` and more.
## Install
```bash
yarn add konan
# or hey old school
npm install --save konan
```
## Supported syntax
- `require` call
- `import/export` ES6 modules
- `import()` [Dynamic import](https://github.com/tc39/proposal-dynamic-import)
- You can use all language features supported by [babel parser](https://github.com/babel/babel/tree/master/packages/babel-parser), including `jsx` syntax by default
## Usage
```js
const konan = require('konan')
konan(`
import React, {Component} from 'react'
const vue = require('vue/dist/vue')
import('./my-async-module').then()
require(path.resolve('./'))
`)
/*
result =>
{
strings: ['react', 'vue/dist/vue', './my-async-module'],
expressions: ['path.resolve(\'./\')']
}
*/
```
## API
### konan(input, [options])
#### input
Type: `string` `object`
Required: `true`
Source content as string or AST tree.
#### options
##### dynamicImport
Type: `boolean`
Default: `true`
You can disable detecting dynamic `import()`-ed modules.
##### parse
Type: `object`
Default: `{sourceType: 'module', plugins: ['jsx', 'typescript', 'dynamicImport']}`
[babel parser](https://github.com/babel/babel/tree/master/packages/babel-parser) parse [options](https://babeljs.io/docs/en/next/babel-parser.html#options).
## FAQ
### What does konan stand for?
It stands for `Meitantei Konan` (名探偵コナン), the main character in [Detective Conan](https://en.wikipedia.org/wiki/Case_Closed).
## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D
## Author
**konan** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.
Authored and maintained by egoist with help from contributors ([list](https://github.com/egoist/konan/contributors)).
> [egoistian.com](https://egoistian.com) · GitHub [@egoist](https://github.com/egoist) · Twitter [@_egoistlily](https://twitter.com/_egoistlily)