Skip to content

Commit

Permalink
fix: tsconfig includes being a level higher than they should be (#8880)
Browse files Browse the repository at this point in the history
closes #8872
closes #8898

---------

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
  • Loading branch information
3 people committed Feb 7, 2023
1 parent 1beb19c commit b915dfe
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-boats-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: deduplicate paths in tsconfig
30 changes: 20 additions & 10 deletions packages/kit/src/core/sync/write_tsconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,29 @@ export function get_tsconfig(kit, include_base_url) {
/** @param {string} file */
const config_relative = (file) => posixify(path.relative(kit.outDir, file));

const include = ['ambient.d.ts', './types/**/$types.d.ts', config_relative('vite.config.ts')];
for (const dir of [kit.files.routes, kit.files.lib]) {
const relative = project_relative(path.dirname(dir));
include.push(config_relative(`${relative}/**/*.js`));
include.push(config_relative(`${relative}/**/*.ts`));
include.push(config_relative(`${relative}/**/*.svelte`));
const include = new Set([
'ambient.d.ts',
'./types/**/$types.d.ts',
config_relative('vite.config.ts')
]);
// TODO(v2): find a better way to include all src files. We can't just use routes/lib only because
// people might have other folders/files in src that they want included.
const src_includes = [kit.files.routes, kit.files.lib, path.resolve('src')].filter((dir) => {
const relative = path.relative(path.resolve('src'), dir);
return !relative || relative.startsWith('..');
});
for (const dir of src_includes) {
include.add(config_relative(`${dir}/**/*.js`));
include.add(config_relative(`${dir}/**/*.ts`));
include.add(config_relative(`${dir}/**/*.svelte`));
}

// Test folder is a special case - we advocate putting tests in a top-level test folder
// and it's not configurable (should we make it?)
const test_folder = project_relative('tests');
include.push(config_relative(`${test_folder}/**/*.js`));
include.push(config_relative(`${test_folder}/**/*.ts`));
include.push(config_relative(`${test_folder}/**/*.svelte`));
include.add(config_relative(`${test_folder}/**/*.js`));
include.add(config_relative(`${test_folder}/**/*.ts`));
include.add(config_relative(`${test_folder}/**/*.svelte`));

const exclude = [config_relative('node_modules/**'), './[!ambient.d.ts]**'];
if (path.extname(kit.files.serviceWorker)) {
Expand Down Expand Up @@ -135,7 +145,7 @@ export function get_tsconfig(kit, include_base_url) {
// TODO(v2): use the new flag verbatimModuleSyntax instead (requires support by Vite/Esbuild)
ignoreDeprecations: ts && Number(ts.version.split('.')[0]) >= 5 ? '5.0' : undefined
},
include,
include: [...include],
exclude
};

Expand Down
27 changes: 27 additions & 0 deletions packages/kit/src/core/sync/write_tsconfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,31 @@ test('Allows generated tsconfig to be replaced', () => {
assert.equal(config.extends, 'some/other/tsconfig.json');
});

test('Creates tsconfig include from kit.files', () => {
const { kit } = validate_config({
kit: {
files: {
lib: 'app'
}
}
});

const { include } = get_tsconfig(kit, false);

assert.equal(include, [
'ambient.d.ts',
'./types/**/$types.d.ts',
'../vite.config.ts',
'../app/**/*.js',
'../app/**/*.ts',
'../app/**/*.svelte',
'../src/**/*.js',
'../src/**/*.ts',
'../src/**/*.svelte',
'../tests/**/*.js',
'../tests/**/*.ts',
'../tests/**/*.svelte'
]);
});

test.run();

0 comments on commit b915dfe

Please sign in to comment.