https://github.com/dependents/detective-typescript
Get the dependencies of a TypeScript module
https://github.com/dependents/detective-typescript
detective typescript
Last synced: 3 months ago
JSON representation
Get the dependencies of a TypeScript module
- Host: GitHub
- URL: https://github.com/dependents/detective-typescript
- Owner: dependents
- Created: 2017-01-23T04:24:38.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2025-02-05T15:27:04.000Z (over 1 year ago)
- Last Synced: 2025-04-07T03:15:59.089Z (about 1 year ago)
- Topics: detective, typescript
- Language: JavaScript
- Size: 569 KB
- Stars: 58
- Watchers: 2
- Forks: 28
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# detective-typescript
[](https://github.com/dependents/detective-typescript/actions/workflows/ci.yml?query=branch%3Amain)
[](https://www.npmjs.com/package/detective-typescript)
[](https://www.npmjs.com/package/detective-typescript)
> Get the dependencies of TypeScript module
```sh
npm install detective-typescript typescript
```
## Usage
```js
const fs = require('fs');
const detective = require('detective-typescript');
const mySourceCode = fs.readFileSync('myfile.ts', 'utf8');
// Pass in a file's content or an AST
const dependencies = detective(mySourceCode);
```
## Options
- `skipTypeImports` (default: `false`) Skips imports that only imports types
- `mixedImports`: (default: `false`) Include CJS imports in dependency list
- `skipAsyncImports`: (default: `false`) Whether or not to omit async imports (import('foo'))
- `jsx`: (default: `false`) Enable parsing of JSX
- `onFile`: A callback that will be called before the file is processed. Intended for use with [`dependency-tree`](https://github.com/dependents/node-dependency-tree). Passed an object argument with properties `options` (echoing any options passed in, e.g., by [`precinct`](https://github.com/dependents/node-precinct)), `src` (source code for file as string), `ast` (parsed AST object for the file source), and `walker` (a `Walker` instance from [`node-source-walk`](https://github.com/dependents/node-source-walk) configured for TypeScript to which you can pass the `ast` or `src`).
- `onAfterFile`: Similar to `onFile`, but the callback is also passed an object property `dependencies`, a string array with the extracted dependencies.
## License
MIT