(tsm: typeof ts, forceReadConfig = false, projectDir = process.cwd())
| 30 | } |
| 31 | |
| 32 | export function patchCreateProgram(tsm: typeof ts, forceReadConfig = false, projectDir = process.cwd()) { |
| 33 | const originCreateProgram = tsm.createProgram as any; |
| 34 | |
| 35 | function createProgram(createProgramOptions: ts.CreateProgramOptions): ts.Program; |
| 36 | function createProgram( |
| 37 | rootNames: ReadonlyArray<string>, |
| 38 | options: ts.CompilerOptions, |
| 39 | host?: ts.CompilerHost, |
| 40 | oldProgram?: ts.Program, |
| 41 | configFileParsingDiagnostics?: ReadonlyArray<ts.Diagnostic> |
| 42 | ): ts.Program; |
| 43 | function createProgram( |
| 44 | rootNamesOrOptions: ReadonlyArray<string> | ts.CreateProgramOptions, |
| 45 | options?: ts.CompilerOptions, |
| 46 | host?: ts.CompilerHost, |
| 47 | oldProgram?: ts.Program, |
| 48 | configFileParsingDiagnostics?: ReadonlyArray<ts.Diagnostic> |
| 49 | ): ts.Program { |
| 50 | let rootNames; |
| 51 | let createOpts: ts.CreateProgramOptions | undefined; |
| 52 | if (!Array.isArray(rootNamesOrOptions)) { |
| 53 | createOpts = rootNamesOrOptions as ts.CreateProgramOptions; |
| 54 | } |
| 55 | if (createOpts) { |
| 56 | rootNames = createOpts.rootNames; |
| 57 | options = createOpts.options; |
| 58 | host = createOpts.host; |
| 59 | oldProgram = createOpts.oldProgram; |
| 60 | configFileParsingDiagnostics = createOpts.configFileParsingDiagnostics; |
| 61 | } else { |
| 62 | options = options!; |
| 63 | rootNames = rootNamesOrOptions as ReadonlyArray<string>; |
| 64 | } |
| 65 | |
| 66 | if (forceReadConfig) { |
| 67 | const info = getConfig(tsm, options, rootNames, projectDir); |
| 68 | options = info.compilerOptions; |
| 69 | if (createOpts) { |
| 70 | createOpts.options = options; |
| 71 | } |
| 72 | projectDir = info.projectDir; |
| 73 | } |
| 74 | const program: ts.Program = createOpts |
| 75 | ? originCreateProgram(createOpts) |
| 76 | : originCreateProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics); |
| 77 | |
| 78 | const plugins = preparePluginsFromCompilerOptions(options.plugins); |
| 79 | const pluginCreator = new PluginCreator(tsm, plugins, projectDir); |
| 80 | |
| 81 | const originEmit = program.emit; |
| 82 | |
| 83 | /** |
| 84 | * The emit method has the following declaration: |
| 85 | * https://github.com/microsoft/TypeScript/blob/bfc55b5762443c37ecdef08a3b5a4e057b4d1e85/src/compiler/builderPublic.ts#L101 |
| 86 | * The declaration specifies 5 arguments, but it's not true. Sometimes the emit method takes 6 arguments. |
| 87 | */ |
| 88 | program.emit = function newEmit( |
| 89 | targetSourceFile?: ts.SourceFile, |
no outgoing calls
no test coverage detected
searching dependent graphs…