Parse all the import
ed modules inside the file(Only ES Modules supported)
To install:
npm install dependit -S
import getDependency from 'dependit'
const filepath = '/path/to/your/file'
const result = getDependency(filepath)
filepath
absolute path to your file
The return value is an object with all the dependencies information. The object's structure is listed below using TypeScript.
interface Result {
path: string,
dependencies: Array<Dependency>
}
interface Dependency {
source: string,
imported: Array<ImportedItem>
}
interface ImportedItem {
value: string,
local: string,
type: ImportType
}
enum ImportType {
default = 'ImportDefault',
import = 'Import',
namespace = 'ImportNamespace'
}
Currently only 4 types are supported:
.js
.jsx
.ts
.vue