detective-typescript
Advanced tools
Comparing version 11.0.2 to 11.1.0
14
index.js
@@ -32,2 +32,10 @@ 'use strict'; | ||
// Pre-parse the source to get the AST to pass to `onFile`, | ||
// then reuse that AST below in our walker walk. | ||
const ast = typeof src === 'string' ? walker.parse(src) : src; | ||
if (options.onFile) { | ||
options.onFile({ options, src, ast, walker }); | ||
} | ||
walker.walk(src, node => { | ||
@@ -104,2 +112,6 @@ switch (node.type) { | ||
if (options.onAfterFile) { | ||
options.onAfterFile({ options, src, ast, walker, dependencies }); | ||
} | ||
return dependencies; | ||
@@ -113,3 +125,3 @@ }; | ||
function extractDependencyFromRequire(node) { | ||
if (node.arguments[0].type === 'Literal' || node.arguments[0].type === 'StringLiteral') { | ||
if (['Literal', 'StringLiteral'].includes(node.arguments[0].type)) { | ||
return node.arguments[0].value; | ||
@@ -116,0 +128,0 @@ } |
{ | ||
"name": "detective-typescript", | ||
"version": "11.0.2", | ||
"version": "11.1.0", | ||
"author": "Patrik Henningsson <patrik.henningsson@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Get the dependencies of a TypeScript module", |
@@ -31,2 +31,4 @@ # detective-typescript | ||
- `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. | ||
@@ -33,0 +35,0 @@ ## License |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7333
105
37