Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): exclude files in outDir from compiler source files #2375

Merged
merged 1 commit into from Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/compiler/ts-compiler.ts
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
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
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