From 40019c272508a5daec7f6e042ff29f583689e36e Mon Sep 17 00:00:00 2001 From: Ahn Date: Thu, 18 Feb 2021 17:21:33 +0100 Subject: [PATCH] fix(compiler): exclude `outDir` from compiler source files Closes #2350 Closes #2374 --- src/compiler/ts-compiler.ts | 9 +++++++-- src/config/config-set.spec.ts | 3 +-- src/config/config-set.ts | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/compiler/ts-compiler.ts b/src/compiler/ts-compiler.ts index 6b4f6227f0..282f4b79ad 100644 --- a/src/compiler/ts-compiler.ts +++ b/src/compiler/ts-compiler.ts @@ -18,7 +18,7 @@ import type { CustomTransformers, } from 'typescript' -import type { ConfigSet } from '../config/config-set' +import { ConfigSet, TS_JEST_OUT_DIR } from '../config/config-set' import { LINE_FEED } from '../constants' import type { ResolvedModulesMap, StringMap, TsCompilerInstance, TsJestAstTransformer, TTypeScript } from '../types' import { rootLogger } from '../utils/logger' @@ -75,7 +75,12 @@ export class TsCompiler implements TsCompilerInstance { } // Initialize memory cache for typescript compiler this._parsedTsConfig.fileNames - .filter((fileName) => !this.configSet.isTestFile(fileName)) + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + .filter( + (fileName) => + !this.configSet.isTestFile(fileName) && + !fileName.includes(this._parsedTsConfig.options.outDir ?? TS_JEST_OUT_DIR), + ) .forEach((fileName) => this._compilerCacheFS.set(fileName, 0)) this._cachedReadFile = this._logger.wrap(serviceHostTraceCtx, 'readFile', memoize(this._ts.sys.readFile)) /* istanbul ignore next */ diff --git a/src/config/config-set.spec.ts b/src/config/config-set.spec.ts index ee151465e4..686eb64aa3 100644 --- a/src/config/config-set.spec.ts +++ b/src/config/config-set.spec.ts @@ -13,7 +13,7 @@ import { getPackageVersion } from '../utils/get-package-version' import { normalizeSlashes } from '../utils/normalize-slashes' import { mocked } from '../utils/testing' -import { ConfigSet, MY_DIGEST, TS_JEST_OUT_DIR } from './config-set' +import { ConfigSet, MY_DIGEST } from './config-set' jest.mock('../utils/backports') jest.mock('../index') @@ -53,7 +53,6 @@ describe('parsedTsConfig', () => { it('should override some options', () => { expect(get({ tsconfig: { inlineSources: false, outDir: 'build' } }).options).toMatchObject({ inlineSources: true, - outDir: TS_JEST_OUT_DIR, }) }) diff --git a/src/config/config-set.ts b/src/config/config-set.ts index ba217026d6..2753035a04 100644 --- a/src/config/config-set.ts +++ b/src/config/config-set.ts @@ -158,8 +158,6 @@ export class ConfigSet { // to clear out else it's buggy out: undefined, outFile: undefined, - // ensure that `LanguageService` won't pick up things from `build` folder which can lead to emit skipped error - outDir: TS_JEST_OUT_DIR, composite: undefined, // see https://github.com/TypeStrong/ts-node/pull/657/files declarationDir: undefined, declarationMap: undefined, @@ -421,6 +419,10 @@ export class ConfigSet { finalOptions.allowSyntheticDefaultImports = true } } + // Make sure when allowJs is enabled, outDir is required to have when using allowJs: true + if (finalOptions.allowJs && !finalOptions.outDir) { + finalOptions.outDir = TS_JEST_OUT_DIR + } // ensure undefined are removed and other values are overridden for (const key of Object.keys(forcedOptions)) {