Skip to content

Commit b091d70

Browse files
committed
fix: set customConditions to undefined in TsCompiler
`customConditions` is only available to `Node16`/`NodeNext`/`Bundler` module option, see https://www.typescriptlang.org/tsconfig/#customConditions Fixes #4620
1 parent 9d89856 commit b091d70

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

src/legacy/compiler/__snapshots__/ts-compiler.spec.ts.snap

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code with config {"babelConfig": false, "supportsStaticESM": false, "useESM": true} 1`] = `
44
{
55
"allowSyntheticDefaultImports": undefined,
6+
"customConditions": undefined,
67
"esModuleInterop": true,
78
"module": 1,
89
}
@@ -11,6 +12,7 @@ exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code
1112
exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code with config {"babelConfig": false, "supportsStaticESM": true, "useESM": false} 1`] = `
1213
{
1314
"allowSyntheticDefaultImports": undefined,
15+
"customConditions": undefined,
1416
"esModuleInterop": true,
1517
"module": 1,
1618
}
@@ -19,6 +21,7 @@ exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code
1921
exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code with config {"babelConfig": false, "supportsStaticESM": true, "useESM": true} 1`] = `
2022
{
2123
"allowSyntheticDefaultImports": undefined,
24+
"customConditions": undefined,
2225
"esModuleInterop": true,
2326
"module": 99,
2427
}
@@ -27,6 +30,7 @@ exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code
2730
exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code with config {"babelConfig": true, "supportsStaticESM": false, "useESM": true} 1`] = `
2831
{
2932
"allowSyntheticDefaultImports": undefined,
33+
"customConditions": undefined,
3034
"esModuleInterop": true,
3135
"module": 1,
3236
}

src/legacy/compiler/ts-compiler.spec.ts

+35-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ describe('TsCompiler', () => {
4141
const compiler = makeCompiler({
4242
tsJestConfig: {
4343
...baseTsJestConfig,
44-
isolatedModules: true,
44+
tsconfig: {
45+
isolatedModules: true,
46+
},
4547
},
4648
})
4749

@@ -111,7 +113,15 @@ describe('TsCompiler', () => {
111113
},
112114
])('should transpile code with config %p', ({ useESM, babelConfig, supportsStaticESM }) => {
113115
const compiler = makeCompiler({
114-
tsJestConfig: { ...baseTsJestConfig, isolatedModules: true, useESM, babelConfig },
116+
tsJestConfig: {
117+
...baseTsJestConfig,
118+
useESM,
119+
babelConfig,
120+
tsconfig: {
121+
isolatedModules: true,
122+
customConditions: ['my-condition'],
123+
},
124+
},
115125
})
116126
const transformersStub = {
117127
before: [],
@@ -138,12 +148,19 @@ describe('TsCompiler', () => {
138148
module: usedCompilerOptions.module,
139149
esModuleInterop: usedCompilerOptions.esModuleInterop,
140150
allowSyntheticDefaultImports: usedCompilerOptions.allowSyntheticDefaultImports,
151+
customConditions: usedCompilerOptions.customConditions,
141152
}).toMatchSnapshot()
142153
})
143154

144155
test.each([true, false])('should report diagnostics if shouldReportDiagnostics is %p', (shouldReport) => {
145156
const compiler = makeCompiler({
146-
tsJestConfig: { ...baseTsJestConfig, isolatedModules: true, useESM: false },
157+
tsJestConfig: {
158+
...baseTsJestConfig,
159+
useESM: false,
160+
tsconfig: {
161+
isolatedModules: true,
162+
},
163+
},
147164
})
148165
compiler.configSet.raiseDiagnostics = jest.fn()
149166
compiler.configSet.shouldReportDiagnostics = jest.fn().mockReturnValue(shouldReport)
@@ -227,6 +244,7 @@ describe('TsCompiler', () => {
227244
tsconfig: {
228245
module: moduleValue as unknown as RawCompilerOptions['module'],
229246
esModuleInterop: false,
247+
customConditions: ['my-condition'],
230248
},
231249
},
232250
})
@@ -253,6 +271,7 @@ describe('TsCompiler', () => {
253271
expect(usedCompilerOptions.module).toBe(expectedModule)
254272
expect(usedCompilerOptions.esModuleInterop).toBe(expectedEsModuleInterop)
255273
expect(usedCompilerOptions.moduleResolution).toBe(ts.ModuleResolutionKind.Node10)
274+
expect(usedCompilerOptions.customConditions).toBeUndefined()
256275
expect(output).toEqual({
257276
code: updateOutput(jsOutput, fileName, sourceMap),
258277
diagnostics: [],
@@ -355,7 +374,13 @@ describe('TsCompiler', () => {
355374
describe('_makeTransformers', () => {
356375
test('should return the transformers object which contains before, after and afterDeclarations transformers', () => {
357376
const compiler = makeCompiler({
358-
tsJestConfig: { ...baseTsJestConfig, isolatedModules: true, useESM: false },
377+
tsJestConfig: {
378+
...baseTsJestConfig,
379+
useESM: false,
380+
tsconfig: {
381+
isolatedModules: true,
382+
},
383+
},
359384
})
360385
const transformerStub = join(mockFolder, 'dummy-transformer.js')
361386
console.log = jest.fn()
@@ -395,7 +420,12 @@ describe('TsCompiler', () => {
395420
const fileName = join(mockFolder, 'thing.ts')
396421
const fileContent = 'const bar = 1'
397422
const compiler = makeCompiler({
398-
tsJestConfig: { ...baseTsJestConfig, isolatedModules: true },
423+
tsJestConfig: {
424+
...baseTsJestConfig,
425+
tsconfig: {
426+
isolatedModules: true,
427+
},
428+
},
399429
})
400430
const fileContentCache = new Map<string, string>()
401431
const fileVersionCache = new Map<string, number>()

src/legacy/compiler/ts-compiler.ts

+8
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ export class TsCompiler implements TsCompilerInstance {
153153
...compilerOptions,
154154
module: this._ts.ModuleKind.CommonJS,
155155
moduleResolution,
156+
/**
157+
* This option is only supported in `Node16`/`NodeNext` and `Bundler` module, see https://www.typescriptlang.org/tsconfig/#customConditions
158+
*/
159+
customConditions: undefined,
156160
}
157161
}
158162

@@ -168,6 +172,10 @@ export class TsCompiler implements TsCompilerInstance {
168172
module: moduleKind,
169173
esModuleInterop,
170174
moduleResolution,
175+
/**
176+
* This option is only supported in `Node16`/`NodeNext` and `Bundler` module, see https://www.typescriptlang.org/tsconfig/#customConditions
177+
*/
178+
customConditions: undefined,
171179
}
172180
}
173181

0 commit comments

Comments
 (0)