Skip to content

Commit

Permalink
fix: ensure generated tsconfig paths start with ./ if aliasing to `…
Browse files Browse the repository at this point in the history
…./svelte-kit` (#12220)
  • Loading branch information
eltigerchino authored May 16, 2024
1 parent 2649fd6 commit 7b72c11
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-kangaroos-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

fix: correctly handle aliases to files in the `.svelte-kit` directory
8 changes: 7 additions & 1 deletion packages/kit/src/core/sync/write_tsconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,13 @@ const value_regex = /^(.*?)((\/\*)|(\.\w+))?$/;
*/
function get_tsconfig_paths(config) {
/** @param {string} file */
const config_relative = (file) => posixify(path.relative(config.outDir, file));
const config_relative = (file) => {
let relative_path = path.relative(config.outDir, file);
if (!relative_path.startsWith('..')) {
relative_path = './' + relative_path;
}
return posixify(relative_path);
};

const alias = { ...config.alias };
if (fs.existsSync(project_relative(config.files.lib))) {
Expand Down
7 changes: 5 additions & 2 deletions packages/kit/src/core/sync/write_tsconfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ test('Creates tsconfig path aliases from kit.alias', () => {
simpleKey: 'simple/value',
key: 'value',
'key/*': 'some/other/value/*',
keyToFile: 'path/to/file.ts'
keyToFile: 'path/to/file.ts',
$routes: '.svelte-kit/types/src/routes'
}
}
});
Expand All @@ -23,7 +24,9 @@ test('Creates tsconfig path aliases from kit.alias', () => {
'simpleKey/*': ['../simple/value/*'],
key: ['../value'],
'key/*': ['../some/other/value/*'],
keyToFile: ['../path/to/file.ts']
keyToFile: ['../path/to/file.ts'],
$routes: ['./types/src/routes'],
'$routes/*': ['./types/src/routes/*']
});
});

Expand Down

0 comments on commit 7b72c11

Please sign in to comment.