Skip to content

Commit 72049cb

Browse files
committed
fix: resolve Windows path handling in relativePath causing incorrect Clerk imports (#324)
1 parent c139419 commit 72049cb

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/create': patch
3+
---
4+
5+
fix: resolve Windows path handling in relativePath causing incorrect Clerk imports

packages/create/src/file-helpers.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ export function relativePath(
5454
to: string,
5555
stripExtension: boolean = false,
5656
) {
57-
const fixedOnWindows = from.startsWith('.\\')
58-
? from.replace(/\\/g, '/')
59-
: from
60-
const cleanedFrom = fixedOnWindows.startsWith('./')
61-
? fixedOnWindows.slice(2)
62-
: from
57+
// Always normalize backslashes to forward slashes for Windows compatibility
58+
const normalized = from.replace(/\\/g, '/')
59+
const cleanedFrom = normalized.startsWith('./')
60+
? normalized.slice(2)
61+
: normalized
6362
const cleanedTo = to.startsWith('./') ? to.slice(2) : to
6463

6564
const fromSegments = cleanedFrom.split('/')

packages/create/tests/file-helper.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,23 @@ describe('relativePath', () => {
6969
),
7070
).toBe('../integrations/tanstack-query/layout.tsx')
7171
})
72-
it('windows', () => {
72+
it('windows with ./ prefix', () => {
7373
expect(
7474
relativePath(
7575
'.\\src\\main.tsx.ejs',
7676
'src/integrations/tanstack-query/root-provider.tsx',
7777
),
7878
).toBe('./integrations/tanstack-query/root-provider.tsx')
7979
})
80+
it('windows without ./ prefix', () => {
81+
expect(
82+
relativePath(
83+
'src\\routes\\__root.tsx.ejs',
84+
'src/integrations/clerk/provider.tsx',
85+
true,
86+
),
87+
).toBe('../integrations/clerk/provider')
88+
})
8089
})
8190

8291
describe('readFileHelper', () => {

0 commit comments

Comments
 (0)