From bb2ebb3e81f984e6d37dd89d2379410cd4fb2994 Mon Sep 17 00:00:00 2001 From: Ahn Date: Sat, 27 Feb 2021 23:33:37 +0100 Subject: [PATCH] fix(compiler): return original file content on emit skip --- src/compiler/language-service.ts | 4 +++- src/utils/messages.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/compiler/language-service.ts b/src/compiler/language-service.ts index 612c431a21..a64ecbaf05 100644 --- a/src/compiler/language-service.ts +++ b/src/compiler/language-service.ts @@ -263,7 +263,9 @@ export const initializeLanguageServiceInstance = (configs: ConfigSet, logger: Lo } /* istanbul ignore next (this should never happen but is kept for security) */ if (output.emitSkipped) { - throw new Error(interpolate(Errors.CannotCompile, { file: fileName })) + logger.warn(interpolate(Errors.CannotProcessFile, { file: fileName })) + + return [code, '{}'] } // Throw an error when requiring `.d.ts` files. if (!output.outputFiles.length) { diff --git a/src/utils/messages.ts b/src/utils/messages.ts index a43539a08e..fbde27f389 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -17,7 +17,7 @@ export const enum Errors { GotUnknownFileTypeWithBabel = 'Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore. If you still want Babel to process it, add another entry to the `transform` option with value `babel-jest` which key matches this type of files.', ConfigNoModuleInterop = 'If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.', MismatchNodeTargetMapping = 'There is a mismatch between your NodeJs version {{nodeJsVer}} and your TypeScript target {{compilationTarget}}. This might lead to some unexpected errors when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping', - CannotCompile = "Unable to process '{{file}}'. Please make sure that `outDir` in your tsconfig is neither `''` or `'.'`.", + CannotProcessFile = "Unable to process '{{file}}', falling back to original file content. Please make sure that `outDir` in your tsconfig is neither `''` or `'.'`. You can also configure Jest config option `transformIgnorePatterns` to ignore {{file}} from transformation", } /**