Skip to content

Commit 7b72c11

Browse files
authored
fix: ensure generated tsconfig paths start with ./ if aliasing to ./svelte-kit (#12220)
1 parent 2649fd6 commit 7b72c11

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

.changeset/wicked-kangaroos-swim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sveltejs/kit": patch
3+
---
4+
5+
fix: correctly handle aliases to files in the `.svelte-kit` directory

packages/kit/src/core/sync/write_tsconfig.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,13 @@ const value_regex = /^(.*?)((\/\*)|(\.\w+))?$/;
192192
*/
193193
function get_tsconfig_paths(config) {
194194
/** @param {string} file */
195-
const config_relative = (file) => posixify(path.relative(config.outDir, file));
195+
const config_relative = (file) => {
196+
let relative_path = path.relative(config.outDir, file);
197+
if (!relative_path.startsWith('..')) {
198+
relative_path = './' + relative_path;
199+
}
200+
return posixify(relative_path);
201+
};
196202

197203
const alias = { ...config.alias };
198204
if (fs.existsSync(project_relative(config.files.lib))) {

packages/kit/src/core/sync/write_tsconfig.spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ test('Creates tsconfig path aliases from kit.alias', () => {
99
simpleKey: 'simple/value',
1010
key: 'value',
1111
'key/*': 'some/other/value/*',
12-
keyToFile: 'path/to/file.ts'
12+
keyToFile: 'path/to/file.ts',
13+
$routes: '.svelte-kit/types/src/routes'
1314
}
1415
}
1516
});
@@ -23,7 +24,9 @@ test('Creates tsconfig path aliases from kit.alias', () => {
2324
'simpleKey/*': ['../simple/value/*'],
2425
key: ['../value'],
2526
'key/*': ['../some/other/value/*'],
26-
keyToFile: ['../path/to/file.ts']
27+
keyToFile: ['../path/to/file.ts'],
28+
$routes: ['./types/src/routes'],
29+
'$routes/*': ['./types/src/routes/*']
2730
});
2831
});
2932

0 commit comments

Comments
 (0)