Skip to content

Commit 88c216f

Browse files
committed
fix: windows relative path fix
1 parent 6c04707 commit 88c216f

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

packages/cta-engine/src/file-helpers.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,26 @@ export function getBinaryFile(content: string): string | null {
3737
}
3838

3939
export function relativePath(from: string, to: string) {
40-
const cleanedFrom = from.startsWith('./') ? from.slice(2) : from
40+
const fixedOnWindows = from.startsWith('.\\')
41+
? from.replace(/\\/g, '/')
42+
: from
43+
const cleanedFrom = fixedOnWindows.startsWith('./')
44+
? fixedOnWindows.slice(2)
45+
: from
4146
const cleanedTo = to.startsWith('./') ? to.slice(2) : to
4247

48+
const fromSegments = cleanedFrom.split('/')
49+
const toSegments = cleanedTo.split('/')
50+
4351
if (process.env.CTA_DEBUG) {
52+
console.log('process.platform', process.platform)
53+
console.log('fixedOnWindows', fixedOnWindows)
4454
console.log('from', from)
4555
console.log('to', to)
4656
console.log('cleanedFrom', cleanedFrom)
4757
console.log('cleanedTo', cleanedTo)
4858
}
4959

50-
const fromSegments = cleanedFrom.split('/')
51-
const toSegments = cleanedTo.split('/')
52-
5360
fromSegments.pop()
5461
toSegments.pop()
5562

packages/cta-engine/tests/file-helper.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ describe('relativePath', () => {
4747
),
4848
).toBe('../integrations/tanstack-query/layout.tsx')
4949
})
50-
// it('windows', () => {
51-
// expect(
52-
// relativePath(
53-
// 'c:\\test-app\\src\\main.tsx',
54-
// 'src/integrations/tanstack-query/root-provider.tsx',
55-
// ),
56-
// ).toBe('./integrations/tanstack-query/root-provider.tsx')
57-
// })
50+
it('windows', () => {
51+
expect(
52+
relativePath(
53+
'.\\src\\main.tsx.ejs',
54+
'src/integrations/tanstack-query/root-provider.tsx',
55+
),
56+
).toBe('./integrations/tanstack-query/root-provider.tsx')
57+
})
5858
})
5959

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

0 commit comments

Comments
 (0)