Skip to content

Commit ec68c74

Browse files
authoredFeb 19, 2021
fix(compiler): exclude outDir from compiler source files (#2375)
Closes #2350 Closes #2374
1 parent 6b2d967 commit ec68c74

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed
 

‎src/compiler/ts-compiler.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
CustomTransformers,
1919
} from 'typescript'
2020

21-
import type { ConfigSet } from '../config/config-set'
21+
import { ConfigSet, TS_JEST_OUT_DIR } from '../config/config-set'
2222
import { LINE_FEED } from '../constants'
2323
import type { ResolvedModulesMap, StringMap, TsCompilerInstance, TsJestAstTransformer, TTypeScript } from '../types'
2424
import { rootLogger } from '../utils/logger'
@@ -75,7 +75,12 @@ export class TsCompiler implements TsCompilerInstance {
7575
}
7676
// Initialize memory cache for typescript compiler
7777
this._parsedTsConfig.fileNames
78-
.filter((fileName) => !this.configSet.isTestFile(fileName))
78+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
79+
.filter(
80+
(fileName) =>
81+
!this.configSet.isTestFile(fileName) &&
82+
!fileName.includes(this._parsedTsConfig.options.outDir ?? TS_JEST_OUT_DIR),
83+
)
7984
.forEach((fileName) => this._compilerCacheFS.set(fileName, 0))
8085
this._cachedReadFile = this._logger.wrap(serviceHostTraceCtx, 'readFile', memoize(this._ts.sys.readFile))
8186
/* istanbul ignore next */

‎src/config/config-set.spec.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { getPackageVersion } from '../utils/get-package-version'
1313
import { normalizeSlashes } from '../utils/normalize-slashes'
1414
import { mocked } from '../utils/testing'
1515

16-
import { ConfigSet, MY_DIGEST, TS_JEST_OUT_DIR } from './config-set'
16+
import { ConfigSet, MY_DIGEST } from './config-set'
1717

1818
jest.mock('../utils/backports')
1919
jest.mock('../index')
@@ -53,7 +53,6 @@ describe('parsedTsConfig', () => {
5353
it('should override some options', () => {
5454
expect(get({ tsconfig: { inlineSources: false, outDir: 'build' } }).options).toMatchObject({
5555
inlineSources: true,
56-
outDir: TS_JEST_OUT_DIR,
5756
})
5857
})
5958

‎src/config/config-set.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ export class ConfigSet {
158158
// to clear out else it's buggy
159159
out: undefined,
160160
outFile: undefined,
161-
// ensure that `LanguageService` won't pick up things from `build` folder which can lead to emit skipped error
162-
outDir: TS_JEST_OUT_DIR,
163161
composite: undefined, // see https://github.com/TypeStrong/ts-node/pull/657/files
164162
declarationDir: undefined,
165163
declarationMap: undefined,
@@ -421,6 +419,10 @@ export class ConfigSet {
421419
finalOptions.allowSyntheticDefaultImports = true
422420
}
423421
}
422+
// Make sure when allowJs is enabled, outDir is required to have when using allowJs: true
423+
if (finalOptions.allowJs && !finalOptions.outDir) {
424+
finalOptions.outDir = TS_JEST_OUT_DIR
425+
}
424426

425427
// ensure undefined are removed and other values are overridden
426428
for (const key of Object.keys(forcedOptions)) {

0 commit comments

Comments
 (0)
Please sign in to comment.