Home > ts-morph-structures > ImportManager
This manages import declarations and specifiers, for including in a source file.
Signature:
export default class ImportManager
importsManager.addImports({
pathToImportedModule: "ts-morph",
isPackageImport: true,
importNames: ["Structure", "StructureKind"],
isDefaultImport: false,
isTypeOnly: true
});
// ...
sourceFile.statements.unshift(...importsManager.getDeclarations());
| Constructor | Modifiers | Description |
|---|---|---|
| (constructor)(absolutePathToModule) | Constructs a new instance of the ImportManager class |
| Property | Modifiers | Type | Description |
|---|---|---|---|
| absolutePathToModule | readonly |
string | Where the file will live on the file system. |
| Method | Modifiers | Description |
|---|---|---|
| addFromDeclaration(declStructure) | Add imports from an existing import declaration. | |
| addImports(context) | ||
| fromSourceFile(absolutePathToModule, sourceFile) | static |
Build an ImportManager from a source file. |
| getAllNamesMap() | Get a map of all imported names. Each key will have its own metadata, which excludes information about other names. | |
| getDeclarations(separateTypeOnlyDeclarations) | Get the import declarations, sorted by path to file, then internally by specified import values. | |
| getNameContext(name) | Get contextual information about an existing name. | |
| removeImportName(name) | Remove a key from its import declaration. |