Skip to content

Commit

Permalink
fix: Clear outDir if set in tsconfig (#406)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
dimfeld authored Sep 20, 2021
1 parent 1f82c44 commit 67f96ad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/transformers/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ function getCompilerOptions({
...(convertedCompilerOptions as CompilerOptions),
importsNotUsedAsValues: ts.ImportsNotUsedAsValues.Error,
allowNonTsExtensions: true,
// Clear outDir since it causes source map issues when the files aren't actually written to disk.
outDir: undefined,
};

if (
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/tsconfig.outdir.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"module": "es2015",
"skipLibCheck": true,
"outDir": "dist"
}
}
14 changes: 14 additions & 0 deletions test/transformers/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ describe('transformer - typescript', () => {
expect(map).toHaveProperty('sources', ['App.svelte']);
});

it('should work when tsconfig contains outDir', async () => {
const opts = sveltePreprocess({
typescript: {
tsconfigFile: './test/fixtures/tsconfig.outdir.json',
handleMixedImports: true,
},
sourceMap: true,
});

const preprocessed = await preprocess(template, opts);

expect(preprocessed.toString?.()).toContain(EXPECTED_SCRIPT);
});

it('supports extends field', () => {
const { options } = loadTsconfig({}, getTestAppFilename(), {
tsconfigFile: './test/fixtures/tsconfig.extends1.json',
Expand Down

0 comments on commit 67f96ad

Please sign in to comment.