diff --git a/.changeset/wicked-kangaroos-swim.md b/.changeset/wicked-kangaroos-swim.md new file mode 100644 index 000000000000..b67f05c405ce --- /dev/null +++ b/.changeset/wicked-kangaroos-swim.md @@ -0,0 +1,5 @@ +--- +"@sveltejs/kit": patch +--- + +fix: correctly handle aliases to files in the `.svelte-kit` directory diff --git a/packages/kit/src/core/sync/write_tsconfig.js b/packages/kit/src/core/sync/write_tsconfig.js index 0bf360ab77d1..de7214b98b3e 100644 --- a/packages/kit/src/core/sync/write_tsconfig.js +++ b/packages/kit/src/core/sync/write_tsconfig.js @@ -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))) { diff --git a/packages/kit/src/core/sync/write_tsconfig.spec.js b/packages/kit/src/core/sync/write_tsconfig.spec.js index fbfa18cc97b9..65a6d09f1499 100644 --- a/packages/kit/src/core/sync/write_tsconfig.spec.js +++ b/packages/kit/src/core/sync/write_tsconfig.spec.js @@ -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' } } }); @@ -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/*'] }); });