Skip to content

Commit 67f96ad

Browse files
authored
fix: Clear outDir if set in tsconfig (#406)
* Clear outDir if set in tsconfig If outDir is set, Typescript sets directories in the source maps relative to it which causes problems in `concatSourceMaps` when the paths in the source point to nonexistent files instead of the virtual modules set up by the transformer. Fixes #405 * Unconditionally clear `outDir`
1 parent 1f82c44 commit 67f96ad

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

Diff for: src/transformers/typescript.ts

+2
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ function getCompilerOptions({
270270
...(convertedCompilerOptions as CompilerOptions),
271271
importsNotUsedAsValues: ts.ImportsNotUsedAsValues.Error,
272272
allowNonTsExtensions: true,
273+
// Clear outDir since it causes source map issues when the files aren't actually written to disk.
274+
outDir: undefined,
273275
};
274276

275277
if (

Diff for: test/fixtures/tsconfig.outdir.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"module": "es2015",
4+
"skipLibCheck": true,
5+
"outDir": "dist"
6+
}
7+
}

Diff for: test/transformers/typescript.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,20 @@ describe('transformer - typescript', () => {
177177
expect(map).toHaveProperty('sources', ['App.svelte']);
178178
});
179179

180+
it('should work when tsconfig contains outDir', async () => {
181+
const opts = sveltePreprocess({
182+
typescript: {
183+
tsconfigFile: './test/fixtures/tsconfig.outdir.json',
184+
handleMixedImports: true,
185+
},
186+
sourceMap: true,
187+
});
188+
189+
const preprocessed = await preprocess(template, opts);
190+
191+
expect(preprocessed.toString?.()).toContain(EXPECTED_SCRIPT);
192+
});
193+
180194
it('supports extends field', () => {
181195
const { options } = loadTsconfig({}, getTestAppFilename(), {
182196
tsconfigFile: './test/fixtures/tsconfig.extends1.json',

0 commit comments

Comments
 (0)