detective-typescript
Advanced tools
Comparing version 5.6.1 to 5.7.0
37
index.js
@@ -5,2 +5,3 @@ 'use strict'; | ||
const Walker = require('node-source-walk'); | ||
const types = require('ast-module-types'); | ||
@@ -23,2 +24,5 @@ /** | ||
const mixedImports = Boolean(options.mixedImports); | ||
delete walkerOptions.mixedImports; | ||
const walker = new Walker(walkerOptions); | ||
@@ -64,2 +68,19 @@ | ||
break; | ||
case 'CallExpression': | ||
if (!mixedImports || !types.isRequire(node) || | ||
!node.arguments || | ||
!node.arguments.length) { | ||
break; | ||
} | ||
if (types.isPlainRequire(node)) { | ||
const result = extractDependencyFromRequire(node); | ||
if (result) { | ||
dependencies.push(result); | ||
} | ||
} else if (types.isMainScopedRequire(node)) { | ||
dependencies.push(extractDependencyFromMainRequire(node)); | ||
} | ||
break; | ||
default: | ||
@@ -73,4 +94,16 @@ return; | ||
module.exports.tsx = function(src, options = {jsx: true}) { | ||
return module.exports(src, options); | ||
module.exports.tsx = function(src, options) { | ||
return module.exports(src, Object.assign({}, options, { jsx: true })); | ||
}; | ||
function extractDependencyFromRequire(node) { | ||
if (node.arguments[0].type === 'Literal' || node.arguments[0].type === 'StringLiteral') { | ||
return node.arguments[0].value; | ||
} else if (node.arguments[0].type === 'TemplateLiteral') { | ||
return node.arguments[0].quasis[0].value.raw; | ||
} | ||
} | ||
function extractDependencyFromMainRequire(node) { | ||
return node.arguments[0].value; | ||
} |
{ | ||
"name": "detective-typescript", | ||
"version": "5.6.1", | ||
"version": "5.7.0", | ||
"author": "Patrik Henningsson <patrik.henningsson@gmail.com>", | ||
@@ -29,2 +29,3 @@ "description": "Get the dependencies of a TypeScript module", | ||
"@typescript-eslint/typescript-estree": "^2.4.0", | ||
"ast-module-types": "^2.5.0", | ||
"node-source-walk": "^4.2.0", | ||
@@ -31,0 +32,0 @@ "typescript": "^3.6.4" |
@@ -19,4 +19,9 @@ ### detective-typescript [![Build Status](http://img.shields.io/travis/pahen/detective-typescript/master.svg?style=flat-square)](https://travis-ci.org/pahen/detective-typescript) [![npm](http://img.shields.io/npm/v/detective-typescript.svg)](https://npmjs.org/package/detective-typescript) [![npm](http://img.shields.io/npm/dm/detective-typescript.svg)](https://npmjs.org/package/detective-typescript) | ||
### Options | ||
- `skipTypeImports` (default: false) - Skips imports that only imports types | ||
- `mixedImports`: (default: false) - Include CJS imports in dependency list | ||
#### License | ||
MIT |
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
5232
89
27
4
+ Addedast-module-types@^2.5.0
+ Addedast-module-types@2.7.1(transitive)