From 107e0625a249ef9797e8563cc111fb9f6a8a24a9 Mon Sep 17 00:00:00 2001 From: Ahn Date: Thu, 26 Mar 2020 16:49:46 +0100 Subject: [PATCH] fix: always do type check for all files provided to ts-jest transformer (#1450) --- .../__snapshots__/logger.test.ts.snap | 40 +++++++++---------- .../__snapshots__/program.spec.ts.snap | 6 +-- src/compiler/instance.ts | 27 +++++++------ src/compiler/language-service.spec.ts | 8 ++-- src/compiler/language-service.ts | 32 +++++++++------ src/compiler/program.spec.ts | 30 +++++++++----- src/compiler/program.ts | 30 +++++++------- src/compiler/transpile-module.ts | 18 ++++----- src/ts-jest-transformer.spec.ts | 37 +++++++++++++++-- src/ts-jest-transformer.ts | 3 ++ src/types.ts | 5 ++- 11 files changed, 144 insertions(+), 92 deletions(-) diff --git a/e2e/__tests__/__snapshots__/logger.test.ts.snap b/e2e/__tests__/__snapshots__/logger.test.ts.snap index 31f504d5ca..09a401f290 100644 --- a/e2e/__tests__/__snapshots__/logger.test.ts.snap +++ b/e2e/__tests__/__snapshots__/logger.test.ts.snap @@ -12,28 +12,28 @@ Array [ "[level:20] backporting config", "[level:20] normalized jest config", "[level:20] normalized ts-jest config", - "[level:20] babel is disabled", "[level:20] loaded module typescript", "[level:20] patching typescript", "[level:20] checking version of typescript: OK", "[level:20] readTsConfig(): reading /tsconfig.json", "[level:20] normalized typescript config", - "[level:20] processing /Hello.spec.ts", "[level:20] file caching disabled", "[level:20] compileUsingLanguageService(): create typescript compiler", "[level:20] compileUsingLanguageService(): creating language service", + "[level:20] compileFn(): computing diagnostics for language service", + "[level:20] babel is disabled", + "[level:20] processing /Hello.spec.ts", "[level:20] readThrough(): no cache", "[level:20] compileFn(): compiling using language service", "[level:20] updateMemoryCache(): update memory cache for language service", "[level:20] visitSourceFileNode(): hoisting", - "[level:20] compileFn(): computing diagnostics for language service", "[level:20] computing cache key for /Hello.ts", + "[level:20] compileFn(): computing diagnostics for language service", "[level:20] processing /Hello.ts", "[level:20] readThrough(): no cache", "[level:20] compileFn(): compiling using language service", "[level:20] updateMemoryCache(): update memory cache for language service", "[level:20] visitSourceFileNode(): hoisting", - "[level:20] compileFn(): computing diagnostics for language service", ] `; @@ -49,33 +49,33 @@ Array [ "[level:20] backporting config", "[level:20] normalized jest config", "[level:20] normalized ts-jest config", - "[level:20] normalized babel config via ts-jest option", "[level:20] loaded module typescript", "[level:20] patching typescript", "[level:20] checking version of typescript: OK", "[level:20] readTsConfig(): reading /tsconfig.json", "[level:20] normalized typescript config", + "[level:20] file caching disabled", + "[level:20] compileUsingLanguageService(): create typescript compiler", + "[level:20] compileUsingLanguageService(): creating language service", + "[level:20] compileFn(): computing diagnostics for language service", + "[level:20] normalized babel config via ts-jest option", "[level:20] processing /Hello.spec.ts", "[level:20] creating babel-jest transformer", "[level:20] loaded module babel-jest", "[level:20] patching babel-jest", "[level:20] checking version of babel-jest: OK", - "[level:20] file caching disabled", - "[level:20] compileUsingLanguageService(): create typescript compiler", - "[level:20] compileUsingLanguageService(): creating language service", "[level:20] readThrough(): no cache", "[level:20] compileFn(): compiling using language service", "[level:20] updateMemoryCache(): update memory cache for language service", "[level:20] visitSourceFileNode(): hoisting", - "[level:20] compileFn(): computing diagnostics for language service", "[level:20] calling babel-jest processor", "[level:20] computing cache key for /Hello.ts", + "[level:20] compileFn(): computing diagnostics for language service", "[level:20] processing /Hello.ts", "[level:20] readThrough(): no cache", "[level:20] compileFn(): compiling using language service", "[level:20] updateMemoryCache(): update memory cache for language service", "[level:20] visitSourceFileNode(): hoisting", - "[level:20] compileFn(): computing diagnostics for language service", "[level:20] calling babel-jest processor", ] `; @@ -93,33 +93,33 @@ Array [ "[level:20] normalized jest config", "[level:20] resolved path from babel.config.js to /babel.config.js", "[level:20] normalized ts-jest config", - "[level:20] normalized babel config via ts-jest option", "[level:20] loaded module typescript", "[level:20] patching typescript", "[level:20] checking version of typescript: OK", "[level:20] readTsConfig(): reading /tsconfig.json", "[level:20] normalized typescript config", + "[level:20] file caching disabled", + "[level:20] compileUsingLanguageService(): create typescript compiler", + "[level:20] compileUsingLanguageService(): creating language service", + "[level:20] compileFn(): computing diagnostics for language service", + "[level:20] normalized babel config via ts-jest option", "[level:20] processing /Hello.spec.ts", "[level:20] creating babel-jest transformer", "[level:20] loaded module babel-jest", "[level:20] patching babel-jest", "[level:20] checking version of babel-jest: OK", - "[level:20] file caching disabled", - "[level:20] compileUsingLanguageService(): create typescript compiler", - "[level:20] compileUsingLanguageService(): creating language service", "[level:20] readThrough(): no cache", "[level:20] compileFn(): compiling using language service", "[level:20] updateMemoryCache(): update memory cache for language service", "[level:20] visitSourceFileNode(): hoisting", - "[level:20] compileFn(): computing diagnostics for language service", "[level:20] calling babel-jest processor", "[level:20] computing cache key for /Hello.ts", + "[level:20] compileFn(): computing diagnostics for language service", "[level:20] processing /Hello.ts", "[level:20] readThrough(): no cache", "[level:20] compileFn(): compiling using language service", "[level:20] updateMemoryCache(): update memory cache for language service", "[level:20] visitSourceFileNode(): hoisting", - "[level:20] compileFn(): computing diagnostics for language service", "[level:20] calling babel-jest processor", ] `; @@ -136,28 +136,28 @@ Array [ "[level:20] backporting config", "[level:20] normalized jest config", "[level:20] normalized ts-jest config", - "[level:20] babel is disabled", "[level:20] loaded module typescript", "[level:20] patching typescript", "[level:20] checking version of typescript: OK", "[level:20] readTsConfig(): reading /tsconfig.json", "[level:20] normalized typescript config", - "[level:20] processing /Hello.spec.ts", "[level:20] file caching disabled", "[level:20] compileUsingLanguageService(): create typescript compiler", "[level:20] compileUsingLanguageService(): creating language service", + "[level:20] compileFn(): computing diagnostics for language service", + "[level:20] babel is disabled", + "[level:20] processing /Hello.spec.ts", "[level:20] readThrough(): no cache", "[level:20] compileFn(): compiling using language service", "[level:20] updateMemoryCache(): update memory cache for language service", "[level:20] visitSourceFileNode(): hoisting", - "[level:20] compileFn(): computing diagnostics for language service", "[level:20] computing cache key for /Hello.ts", + "[level:20] compileFn(): computing diagnostics for language service", "[level:20] processing /Hello.ts", "[level:20] readThrough(): no cache", "[level:20] compileFn(): compiling using language service", "[level:20] updateMemoryCache(): update memory cache for language service", "[level:20] visitSourceFileNode(): hoisting", - "[level:20] compileFn(): computing diagnostics for language service", ] `; diff --git a/src/compiler/__snapshots__/program.spec.ts.snap b/src/compiler/__snapshots__/program.spec.ts.snap index 30ee6b0fef..ff4913cad6 100644 --- a/src/compiler/__snapshots__/program.spec.ts.snap +++ b/src/compiler/__snapshots__/program.spec.ts.snap @@ -146,10 +146,6 @@ exports[`other jsx options should compile tsx file for with program 1`] = ` ================================================================================ `; -exports[`typings incremental program should not report diagnostics with pathRegex config does not match file name 1`] = `"test-typings.ts: Emit skipped"`; - -exports[`typings incremental program should report diagnostics with pathRegex config matches file name 1`] = `"test-typings.ts: Emit skipped"`; - -exports[`typings normal program should not report diagnostics with pathRegex config matches file name 1`] = `"test-typings.ts: Emit skipped"`; +exports[`typings incremental program should report diagnostics with pathRegex config matches file name 1`] = `"test-typings.ts(3,7): error TS2322: Type 'number' is not assignable to type 'string'."`; exports[`typings normal program should report diagnostics with pathRegex config matches file name 1`] = `"test-typings.ts(3,7): error TS2322: Type 'number' is not assignable to type 'string'."`; diff --git a/src/compiler/instance.ts b/src/compiler/instance.ts index d92f5b83c1..20cf839946 100644 --- a/src/compiler/instance.ts +++ b/src/compiler/instance.ts @@ -35,7 +35,7 @@ import mkdirp = require('mkdirp') import { basename, extname, join, normalize } from 'path' import { ConfigSet } from '../config/config-set' -import { CompileFn, CompileResult, MemoryCache, TsCompiler } from '../types' +import { CompileFn, CompilerInstance, MemoryCache, TsCompiler } from '../types' import { sha1 } from '../util/sha1' import { compileUsingLanguageService } from './language-service' @@ -113,11 +113,10 @@ const readThrough = ( mkdirp.sync(cachedir) return (code: string, fileName: string, lineOffset?: number) => { - const normalizedFileName = normalize(fileName) - const cachePath = join(cachedir, getCacheName(code, normalizedFileName)) - const extension = getExtension(normalizedFileName) - const outputPath = `${cachePath}${extension}` - + const normalizedFileName = normalize(fileName), + cachePath = join(cachedir, getCacheName(code, normalizedFileName)), + extension = getExtension(normalizedFileName), + outputPath = `${cachePath}${extension}` try { const output = readFileSync(outputPath, 'utf8') if (isValidCacheContent(output)) { @@ -129,10 +128,12 @@ const readThrough = ( } catch (err) {} logger.debug({ fileName }, 'readThrough(): cache miss') - const [value, sourceMap] = compileFn(code, normalizedFileName, lineOffset) - const output = updateOutput(value, normalizedFileName, sourceMap, getExtension) + + const [value, sourceMap] = compileFn(code, normalizedFileName, lineOffset), + output = updateOutput(value, normalizedFileName, sourceMap, getExtension) logger.debug({ normalizedFileName, outputPath }, 'readThrough(): writing caches') + memoryCache.outputs[normalizedFileName] = output writeFileSync(outputPath, output) @@ -172,16 +173,16 @@ export const createCompiler = (configs: ConfigSet): TsCompiler => { compilerOptions.jsx === ts.JsxEmit.Preserve ? (path: string) => (/\.[tj]sx$/.test(path) ? '.jsx' : '.js') : (_: string) => '.js' - let compileResult: CompileResult + let compilerInstance: CompilerInstance if (!tsJest.isolatedModules) { // Use language services by default - compileResult = !tsJest.compilerHost + compilerInstance = !tsJest.compilerHost ? compileUsingLanguageService(configs, logger, memoryCache) : compileUsingProgram(configs, logger, memoryCache) } else { - compileResult = compileUsingTranspileModule(configs, logger) + compilerInstance = compileUsingTranspileModule(configs, logger) } - const compile = readThrough(cachedir, memoryCache, compileResult.compileFn, getExtension, logger) + const compile = readThrough(cachedir, memoryCache, compilerInstance.compileFn, getExtension, logger) - return { cwd: configs.cwd, compile, program: compileResult.program } + return { cwd: configs.cwd, compile, program: compilerInstance.program, diagnose: compilerInstance.diagnoseFn } } diff --git a/src/compiler/language-service.spec.ts b/src/compiler/language-service.spec.ts index fb8d81c1af..bd6c261d2c 100644 --- a/src/compiler/language-service.spec.ts +++ b/src/compiler/language-service.spec.ts @@ -36,8 +36,6 @@ describe('language service', () => { "[level:20] updateMemoryCache(): update memory cache for language service ", "[level:20] visitSourceFileNode(): hoisting - ", - "[level:20] compileFn(): computing diagnostics for language service ", "[level:20] readThrough(): writing caches ", @@ -146,8 +144,9 @@ const x: string = g(5) tsJestConfig: { tsConfig: false, diagnostics: { pathRegex: fileName } }, }) writeFileSync(fileName, source, 'utf8') + compiler.compile(source, fileName) - expect(() => compiler.compile(source, fileName)).toThrowErrorMatchingSnapshot() + expect(() => compiler.diagnose!(fileName)).toThrowErrorMatchingSnapshot() removeSync(fileName) }) @@ -162,8 +161,9 @@ const t: string = f(5) tsJestConfig: { tsConfig: false, diagnostics: { pathRegex: 'bar.ts' } }, }) writeFileSync(fileName, source, 'utf8') + compiler.compile(source, fileName) - expect(() => compiler.compile(source, fileName)).not.toThrowError() + expect(() => compiler.diagnose!(fileName)).not.toThrowError() removeSync(fileName) }) diff --git a/src/compiler/language-service.ts b/src/compiler/language-service.ts index 15c4075d8d..d9ff964fff 100644 --- a/src/compiler/language-service.ts +++ b/src/compiler/language-service.ts @@ -4,7 +4,7 @@ import { basename, normalize, relative } from 'path' import * as _ts from 'typescript' import { ConfigSet } from '../config/config-set' -import { CompileResult, MemoryCache, SourceOutput } from '../types' +import { CompilerInstance, MemoryCache, SourceOutput } from '../types' import { Errors, interpolate } from '../util/messages' const hasOwn = Object.prototype.hasOwnProperty @@ -16,7 +16,7 @@ export const compileUsingLanguageService = ( configs: ConfigSet, logger: Logger, memoryCache: MemoryCache, -): CompileResult => { +): CompilerInstance => { logger.debug('compileUsingLanguageService(): create typescript compiler') const ts = configs.compilerModule, @@ -95,17 +95,6 @@ export const compileUsingLanguageService = ( // Must set memory cache before attempting to read file. updateMemoryCache(code, normalizedFileName) const output: _ts.EmitOutput = service.getEmitOutput(normalizedFileName) - if (configs.shouldReportDiagnostic(normalizedFileName)) { - logger.debug({ normalizedFileName }, 'compileFn(): computing diagnostics for language service') - - // Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`. - const diagnostics = service - .getCompilerOptionsDiagnostics() - .concat(service.getSyntacticDiagnostics(normalizedFileName)) - .concat(service.getSemanticDiagnostics(normalizedFileName)) - // will raise or just warn diagnostics depending on config - configs.raiseDiagnostics(diagnostics, normalizedFileName, logger) - } /* istanbul ignore next (this should never happen but is kept for security) */ if (output.emitSkipped) { @@ -123,6 +112,23 @@ export const compileUsingLanguageService = ( return [output.outputFiles[1].text, output.outputFiles[0].text] }, + diagnoseFn: (filePath: string) => { + const normalizedFileName = normalize(filePath) + if (configs.shouldReportDiagnostic(normalizedFileName)) { + logger.debug({ normalizedFileName }, 'compileFn(): computing diagnostics for language service') + + // Not sure why e2e tests not working without this if. In reality, this if is not needed + if (service.getProgram()!.getSourceFile(filePath)) { + // Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`. + const diagnostics = service + .getCompilerOptionsDiagnostics() + .concat(service.getSyntacticDiagnostics(normalizedFileName)) + .concat(service.getSemanticDiagnostics(normalizedFileName)) + // will raise or just warn diagnostics depending on config + configs.raiseDiagnostics(diagnostics, normalizedFileName, logger) + } + } + }, program: service.getProgram(), } } diff --git a/src/compiler/program.spec.ts b/src/compiler/program.spec.ts index 6a658de2aa..580a17b62d 100644 --- a/src/compiler/program.spec.ts +++ b/src/compiler/program.spec.ts @@ -38,7 +38,11 @@ const t: string = f(5) }, }) - expect(() => compiler.compile(source, fileName)).toThrowErrorMatchingSnapshot() + try { + compiler.compile(source, fileName) + } catch (e) {} + + expect(() => compiler.diagnose!(fileName)).toThrowErrorMatchingSnapshot() }) it('should not report diagnostics with pathRegex config matches file name', () => { @@ -50,7 +54,11 @@ const t: string = f(5) }, }) - expect(() => compiler.compile(source, fileName)).toThrowErrorMatchingSnapshot() + try { + compiler.compile(source, fileName) + } catch (e) {} + + expect(() => compiler.diagnose!(fileName)).not.toThrowError() }) }) @@ -60,11 +68,15 @@ const t: string = f(5) tsJestConfig: { ...baseTsJestConfig, incremental: true, - diagnostics: { pathRegex: 'typings-error.ts' }, + diagnostics: { pathRegex: fileName }, }, }) - expect(() => compiler.compile(source, fileName)).toThrowErrorMatchingSnapshot() + try { + compiler.compile(source, fileName) + } catch (e) {} + + expect(() => compiler.diagnose!(fileName)).toThrowErrorMatchingSnapshot() }) it('should not report diagnostics with pathRegex config does not match file name', () => { @@ -76,7 +88,11 @@ const t: string = f(5) }, }) - expect(() => compiler.compile(source, fileName)).toThrowErrorMatchingSnapshot() + try { + compiler.compile(source, fileName) + } catch (e) {} + + expect(() => compiler.diagnose!(fileName)).not.toThrowError() }) }) }) @@ -161,8 +177,6 @@ describe('cache', () => { "[level:20] updateMemoryCache(): update memory cache for program ", "[level:20] visitSourceFileNode(): hoisting - ", - "[level:20] compileFn(): computing diagnostics for program ", "[level:20] readThrough(): writing caches ", @@ -202,8 +216,6 @@ Array [ "[level:20] updateMemoryCache(): update memory cache for incremental program ", "[level:20] visitSourceFileNode(): hoisting -", - "[level:20] compileFn(): computing diagnostics for incremental program ", "[level:20] readThrough(): writing caches ", diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c028cc27dc..732c107d39 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -4,7 +4,7 @@ import { basename, normalize, relative } from 'path' import * as _ts from 'typescript' import { ConfigSet } from '../config/config-set' -import { CompileResult, MemoryCache, SourceOutput } from '../types' +import { CompilerInstance, MemoryCache, SourceOutput } from '../types' import { Errors, interpolate } from '../util/messages' const hasOwn = Object.prototype.hasOwnProperty @@ -12,7 +12,7 @@ const hasOwn = Object.prototype.hasOwnProperty /** * @internal */ -export const compileUsingProgram = (configs: ConfigSet, logger: Logger, memoryCache: MemoryCache): CompileResult => { +export const compileUsingProgram = (configs: ConfigSet, logger: Logger, memoryCache: MemoryCache): CompilerInstance => { logger.debug('compileUsingProgram(): create typescript compiler') const ts = configs.compilerModule, @@ -144,18 +144,6 @@ export const compileUsingProgram = (configs: ConfigSet, logger: Logger, memoryCa undefined, customTransformers, ) - if (configs.shouldReportDiagnostic(normalizedFileName)) { - logger.debug( - { normalizedFileName }, - `compileFn(): computing diagnostics for ${incremental ? 'incremental program' : 'program'}`, - ) - - const diagnostics = program - .getSemanticDiagnostics(sourceFile) - .concat(program.getSyntacticDiagnostics(sourceFile)) - // will raise or just warn diagnostics depending on config - configs.raiseDiagnostics(diagnostics, normalizedFileName, logger) - } if (result.emitSkipped) { throw new TypeError(`${relative(cwd, fileName)}: Emit skipped`) @@ -172,6 +160,20 @@ export const compileUsingProgram = (configs: ConfigSet, logger: Logger, memoryCa return output }, + diagnoseFn: (filePath: string) => { + const normalizedFileName = normalize(filePath) + if (configs.shouldReportDiagnostic(normalizedFileName)) { + logger.debug( + { normalizedFileName }, + `compileFn(): computing diagnostics for ${incremental ? 'incremental program' : 'program'}`, + ) + + const sourceFile = program.getSourceFile(normalizedFileName), + diagnostics = program.getSemanticDiagnostics(sourceFile).concat(program.getSyntacticDiagnostics(sourceFile)) + // will raise or just warn diagnostics depending on config + configs.raiseDiagnostics(diagnostics, normalizedFileName, logger) + } + }, program, } } diff --git a/src/compiler/transpile-module.ts b/src/compiler/transpile-module.ts index 47a50b310a..8d04ad94e9 100644 --- a/src/compiler/transpile-module.ts +++ b/src/compiler/transpile-module.ts @@ -2,25 +2,25 @@ import { Logger } from 'bs-logger' import { normalize } from 'path' import { ConfigSet } from '../config/config-set' -import { CompileResult, SourceOutput } from '../types' +import { CompilerInstance, SourceOutput } from '../types' /** * @internal */ -export const compileUsingTranspileModule = (configs: ConfigSet, logger: Logger): CompileResult => { +export const compileUsingTranspileModule = (configs: ConfigSet, logger: Logger): CompilerInstance => { logger.debug('compileUsingTranspileModule(): create typescript compiler') return { compileFn: (code: string, fileName: string): SourceOutput => { logger.debug({ fileName }, 'getOutput(): compiling as isolated module') - const normalizedFileName = normalize(fileName) - const result = configs.compilerModule.transpileModule(code, { - fileName: normalizedFileName, - transformers: configs.tsCustomTransformers, - compilerOptions: configs.typescript.options, - reportDiagnostics: configs.shouldReportDiagnostic(normalizedFileName), - }) + const normalizedFileName = normalize(fileName), + result = configs.compilerModule.transpileModule(code, { + fileName: normalizedFileName, + transformers: configs.tsCustomTransformers, + compilerOptions: configs.typescript.options, + reportDiagnostics: configs.shouldReportDiagnostic(normalizedFileName), + }) if (result.diagnostics && configs.shouldReportDiagnostic(normalizedFileName)) { configs.raiseDiagnostics(result.diagnostics, normalizedFileName, logger) diff --git a/src/ts-jest-transformer.spec.ts b/src/ts-jest-transformer.spec.ts index 1e9aef0f06..35af758791 100644 --- a/src/ts-jest-transformer.spec.ts +++ b/src/ts-jest-transformer.spec.ts @@ -249,11 +249,20 @@ Array [ }) describe('getCacheKey', () => { + let tr: TsJestTransformer + + beforeEach(() => { + tr = new TsJestTransformer() + }) + it('should be different for each argument value', () => { - const tr = new TsJestTransformer() - jest - .spyOn(tr, 'configsFor') - .mockImplementation(jestConfigStr => (({ cacheKey: jestConfigStr } as unknown) as ConfigSet)) + jest.spyOn(tr, 'configsFor').mockImplementation( + jestConfigStr => + (({ + cacheKey: jestConfigStr, + tsCompiler: {}, + } as unknown) as ConfigSet), + ) const input = { fileContent: 'export default "foo"', fileName: 'foo.ts', @@ -274,4 +283,24 @@ describe('getCacheKey', () => { // unique array should have same length expect(keys.filter((k, i, all) => all.indexOf(k) === i)).toHaveLength(keys.length) }) + + it('should call diagnosticsFn to do type checking for test file', () => { + const tsCompilerStub = { diagnose: jest.fn() } + jest.spyOn(tr, 'configsFor').mockImplementation( + jestConfigStr => + (({ + cacheKey: jestConfigStr, + tsCompiler: tsCompilerStub, + } as unknown) as ConfigSet), + ) + const input = { + fileContent: 'export default "foo"', + fileName: 'foo.ts', + jestConfigStr: '{"foo": "bar"}', + options: { instrument: false, rootDir: '/foo' }, + } + tr.getCacheKey(input.fileContent, input.fileName, input.jestConfigStr, input.options) + + expect(tsCompilerStub.diagnose).toHaveBeenCalledWith(input.fileName) + }) }) diff --git a/src/ts-jest-transformer.ts b/src/ts-jest-transformer.ts index 69796476fd..8362639712 100644 --- a/src/ts-jest-transformer.ts +++ b/src/ts-jest-transformer.ts @@ -179,6 +179,9 @@ export class TsJestTransformer implements Transformer { const configs = this.configsFor(jestConfigStr) // we do not instrument, ensure it is false all the time const { instrument = false, rootDir = configs.rootDir } = transformOptions + if (configs.tsCompiler.diagnose) { + configs.tsCompiler.diagnose(filePath) + } return sha1( configs.cacheKey, diff --git a/src/types.ts b/src/types.ts index c36cf6a8f1..535420c024 100644 --- a/src/types.ts +++ b/src/types.ts @@ -162,6 +162,7 @@ export type ModulePatcher = (module: T) => T export interface TsCompiler { cwd: string compile(code: string, fileName: string, lineOffset?: number): string + diagnose: DiagnoseFn | undefined program: _ts.Program | undefined } @@ -181,9 +182,11 @@ export interface MemoryCache { } export type CompileFn = (code: string, fileName: string, lineOffset?: number) => SourceOutput +export type DiagnoseFn = (filePath: string) => void -export interface CompileResult { +export interface CompilerInstance { compileFn: CompileFn + diagnoseFn?: DiagnoseFn program?: _ts.Program }