( fs: PathManipulation, graph: string, )
| 35 | * An import can be suffixed with ! to make it a type-only import. |
| 36 | */ |
| 37 | export function makeProgramFromGraph( |
| 38 | fs: PathManipulation, |
| 39 | graph: string, |
| 40 | ): { |
| 41 | program: ts.Program; |
| 42 | host: ts.CompilerHost; |
| 43 | options: ts.CompilerOptions; |
| 44 | } { |
| 45 | const files: TestFile[] = graph.split(';').map((fileSegment) => { |
| 46 | const [name, importList] = fileSegment.split(':'); |
| 47 | const contents = |
| 48 | (importList ? importList.split(',') : []) |
| 49 | .map((i) => { |
| 50 | if (i.startsWith('*')) { |
| 51 | const sym = i.slice(1); |
| 52 | return `export {${sym}} from './${sym}';`; |
| 53 | } else if (i.endsWith('!')) { |
| 54 | const sym = i.slice(0, -1); |
| 55 | return `import type {${sym}} from './${sym}';`; |
| 56 | } else { |
| 57 | return `import {${i}} from './${i}';`; |
| 58 | } |
| 59 | }) |
| 60 | .join('\n') + `export const ${name} = '${name}';\n`; |
| 61 | return { |
| 62 | name: fs.resolve(`/${name}.ts`), |
| 63 | contents, |
| 64 | }; |
| 65 | }); |
| 66 | return makeProgram(files); |
| 67 | } |
| 68 | |
| 69 | export function importPath(files: ts.SourceFile[]): string { |
| 70 | const fs = getFileSystem(); |
no test coverage detected
searching dependent graphs…