Skip to content

Commit 9034677

Browse files
authored
fix(compiler): exclude files in outDir from compiler source files (#2376)
Closes #2350 Closes #2374
1 parent c427fea commit 9034677

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/compiler/language-service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import memoize = require('lodash/memoize')
55
import mkdirp = require('mkdirp')
66
import type * as _ts from 'typescript'
77

8-
import type { ConfigSet } from '../config/config-set'
8+
import { ConfigSet, TS_JEST_OUT_DIR } from '../config/config-set'
99
import { LINE_FEED } from '../constants'
1010
import type { CompilerInstance, SourceOutput } from '../types'
1111
import { Errors, interpolate } from '../utils/messages'
@@ -75,7 +75,10 @@ export const initializeLanguageServiceInstance = (configs: ConfigSet, logger: Lo
7575
}
7676
// Initialize memory cache for typescript compiler
7777
configs.parsedTsConfig.fileNames
78-
.filter((fileName: string) => !configs.isTestFile(fileName))
78+
.filter(
79+
(fileName: string) =>
80+
!configs.isTestFile(fileName) && !fileName.includes(configs.parsedTsConfig.options.outDir ?? TS_JEST_OUT_DIR),
81+
)
7982
.forEach((fileName: string) => {
8083
memoryCache.files.set(fileName, {
8184
version: 0,

src/config/config-set.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { getPackageVersion } from '../utils/get-package-version'
1212
import { normalizeSlashes } from '../utils/normalize-slashes'
1313
import { mocked } from '../utils/testing'
1414

15-
import { ConfigSet, MY_DIGEST, TS_JEST_OUT_DIR } from './config-set'
15+
import { ConfigSet, MY_DIGEST } from './config-set'
1616

1717
jest.mock('../utils/backports')
1818
jest.mock('../index')
@@ -73,7 +73,6 @@ describe('parsedTsConfig', () => {
7373
{
7474
module: ts.ModuleKind.CommonJS,
7575
inlineSources: true,
76-
outDir: TS_JEST_OUT_DIR,
7776
},
7877
)
7978
})

src/config/config-set.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ export class ConfigSet {
164164
// to clear out else it's buggy
165165
out: undefined,
166166
outFile: undefined,
167-
// ensure that `LanguageService` won't pick up things from `build` folder which can lead to emit skipped error
168-
outDir: TS_JEST_OUT_DIR,
169167
composite: undefined, // see https://github.com/TypeStrong/ts-node/pull/657/files
170168
declarationDir: undefined,
171169
declarationMap: undefined,
@@ -485,6 +483,10 @@ export class ConfigSet {
485483
finalOptions.allowSyntheticDefaultImports = true
486484
}
487485
}
486+
// Make sure when allowJs is enabled, outDir is required to have when using allowJs: true
487+
if (finalOptions.allowJs && !finalOptions.outDir) {
488+
finalOptions.outDir = TS_JEST_OUT_DIR
489+
}
488490

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

0 commit comments

Comments
 (0)