npm.io
15.0.1 • Published yesterday

detective-typescript

Licence
MIT
Version
15.0.1
Deps
3
Size
7 kB
Vulns
0
Weekly
0
Stars
64

detective-typescript

CI npm version npm downloads

Get the dependencies of TypeScript module

npm install detective-typescript typescript

Usage

ESM

import fs from 'node:fs';
import detective from 'detective-typescript';

const mySourceCode = fs.readFileSync('myfile.ts', 'utf8');

// Pass in a file's content or an AST
const dependencies = detective(mySourceCode);

// For TSX/JSX files
const tsxDependencies = detective.tsx(mySourceCode);
CommonJS
const { default: detective } = require('detective-typescript');

Options

Option Type Default Description
skipTypeImports boolean false Skip imports that only import types
mixedImports boolean false Include CJS require() calls in the dependency list
skipAsyncImports boolean false Omit dynamic import('foo') expressions
jsx boolean false Enable parsing of JSX/TSX syntax
onFile Function - Callback invoked before a file is processed. Receives { options, src, ast, walker }. Intended for use with dependency-tree and precinct.
onAfterFile Function - Like onFile, but also receives dependencies (string array of extracted dependencies).

License

MIT

Keywords