Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, maybe it'd be more accurate or comprehensive to say:

Suggested change
fix: correctly handle aliases to files in the `.svelte-kit` directory
fix: correctly handle aliases to files in hidden directories

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that's right. The only issue was that aliases to files in .svelte-kit did not start with a leading ./ so tsconfig considered them to be non-relative paths and complained e.g. "types/routes/src/*"

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