Skip to content

Commit

Permalink
fix(compiler): exclude outDir from compiler source files
Browse files Browse the repository at this point in the history
Closes #2350
Closes #2374
  • Loading branch information
ahnpnl committed Feb 18, 2021
1 parent c427fea commit 754bdb8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/compiler/language-service.ts
Expand Up @@ -5,7 +5,7 @@ import memoize = require('lodash/memoize')
import mkdirp = require('mkdirp')
import type * as _ts 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 { CompilerInstance, SourceOutput } from '../types'
import { Errors, interpolate } from '../utils/messages'
Expand Down Expand Up @@ -75,7 +75,10 @@ export const initializeLanguageServiceInstance = (configs: ConfigSet, logger: Lo
}
// Initialize memory cache for typescript compiler
configs.parsedTsConfig.fileNames
.filter((fileName: string) => !configs.isTestFile(fileName))
.filter(
(fileName: string) =>
!configs.isTestFile(fileName) && !fileName.includes(configs.parsedTsConfig.options.outDir ?? TS_JEST_OUT_DIR),
)
.forEach((fileName: string) => {
memoryCache.files.set(fileName, {
version: 0,
Expand Down
3 changes: 1 addition & 2 deletions src/config/config-set.spec.ts
Expand Up @@ -12,7 +12,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 @@ -73,7 +73,6 @@ describe('parsedTsConfig', () => {
{
module: ts.ModuleKind.CommonJS,
inlineSources: true,
outDir: TS_JEST_OUT_DIR,
},
)
})
Expand Down
6 changes: 4 additions & 2 deletions src/config/config-set.ts
Expand Up @@ -164,8 +164,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 @@ -485,6 +483,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 754bdb8

Please sign in to comment.