Skip to content

Commit

Permalink
fix(compiler): exclude outDir from compiler source files (#2375)
Browse files Browse the repository at this point in the history
Closes #2350
Closes #2374
  • Loading branch information
ahnpnl authored Feb 19, 2021
1 parent 6b2d967 commit ec68c74
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/compiler/ts-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 */
Expand Down
3 changes: 1 addition & 2 deletions src/config/config-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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,
})
})

Expand Down
6 changes: 4 additions & 2 deletions src/config/config-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit ec68c74

Please sign in to comment.