( host: Tree, modulePath: string, moduleName: string, src: string, )
| 44 | * @param src src location to import |
| 45 | */ |
| 46 | export function addModuleImportToModule( |
| 47 | host: Tree, |
| 48 | modulePath: string, |
| 49 | moduleName: string, |
| 50 | src: string, |
| 51 | ) { |
| 52 | const moduleSource = parseSourceFile(host, modulePath); |
| 53 | |
| 54 | if (!moduleSource) { |
| 55 | throw new SchematicsException(`Module not found: ${modulePath}`); |
| 56 | } |
| 57 | |
| 58 | const changes = addImportToModule(moduleSource, modulePath, moduleName, src); |
| 59 | const recorder = host.beginUpdate(modulePath); |
| 60 | |
| 61 | changes.forEach(change => { |
| 62 | if (change instanceof InsertChange) { |
| 63 | recorder.insertLeft(change.pos, change.toAdd); |
| 64 | } |
| 65 | }); |
| 66 | |
| 67 | host.commitUpdate(recorder); |
| 68 | } |
| 69 | |
| 70 | /** Wraps the internal find module from options with undefined path handling */ |
| 71 | export async function findModuleFromOptions( |
no test coverage detected