Skip to content

Commit afb80ae

Browse files
authoredJul 8, 2024··
fix: remove customConditions tsconfig option (#648)
...in order to prevent invalid config errors which could arise from us forcing a module resolution. fixes #646
1 parent 9918cb6 commit afb80ae

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed
 

‎src/transformers/typescript.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,17 @@ function getCompilerOptions({
6060

6161
const compilerOptions: CompilerOptions = {
6262
target: ts.ScriptTarget.ES2015,
63-
...(convertedCompilerOptions as CompilerOptions),
63+
...convertedCompilerOptions,
6464
// force module(resolution) to esnext and a compatible moduleResolution. Reason:
6565
// transpileModule treats NodeNext as CommonJS because it doesn't read the package.json.
6666
// Also see https://github.com/microsoft/TypeScript/issues/53022 (the filename workaround doesn't work).
6767
module: ts.ModuleKind.ESNext,
68-
moduleResolution: ts.ModuleResolutionKind.Node10,
68+
moduleResolution:
69+
convertedCompilerOptions.moduleResolution ===
70+
ts.ModuleResolutionKind.Bundler
71+
? ts.ModuleResolutionKind.Bundler
72+
: ts.ModuleResolutionKind.Node10,
73+
customConditions: undefined, // fails when using an invalid moduleResolution combination which could happen when we force moduleResolution to Node10
6974
allowNonTsExtensions: true,
7075
// Clear outDir since it causes source map issues when the files aren't actually written to disk.
7176
outDir: undefined,
@@ -141,7 +146,10 @@ export function loadTsconfig(
141146
compilerOptionsJSON: any,
142147
filename: string,
143148
tsOptions: Options.Typescript,
144-
) {
149+
): {
150+
options: ts.CompilerOptions;
151+
errors: ts.Diagnostic[];
152+
} {
145153
if (typeof tsOptions.tsconfigFile === 'boolean') {
146154
return { errors: [], options: compilerOptionsJSON };
147155
}

‎test/transformers/typescript.test.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import type { Processed } from '../../src/types';
1313
import type { Diagnostic } from 'typescript';
1414

15-
spyConsole({ silent: true });
15+
spyConsole({ silent: false });
1616

1717
const EXPECTED_SCRIPT = getFixtureContent('script.js');
1818

@@ -203,5 +203,22 @@ describe('transformer - typescript', () => {
203203
expect(code).not.toContain('&&=');
204204
expect(code).not.toContain('||=');
205205
});
206+
207+
it('should remove customConditions option if necessary to prevent config error', async () => {
208+
const opts = sveltePreprocess({
209+
typescript: {
210+
tsconfigFile: false,
211+
compilerOptions: {
212+
// we force a different module resolution in our transformer which
213+
// would fail if we wouldn't also remove the customConditions
214+
moduleResolution: 'NodeNext',
215+
customConditions: ['development'],
216+
},
217+
},
218+
});
219+
const preprocessed = await preprocess(template, opts);
220+
221+
expect(preprocessed.toString?.()).toContain('export var hello');
222+
});
206223
});
207224
});

0 commit comments

Comments
 (0)
Please sign in to comment.