Skip to content

(fix) Clear outDir if set in tsconfig #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/transformers/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ function getCompilerOptions({
const compilerOptionsJSON = {
moduleResolution: 'node',
target: 'es6',
// Clear outDir since it causes source map issues when the files aren't actually written to disk.
outDir: undefined,
};

Object.assign(compilerOptionsJSON, options.compilerOptions);
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