Skip to content

Commit b254ec2

Browse files
committedNov 25, 2024·
CLI: fix Windows path problems
1 parent 1cc7196 commit b254ec2

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed
 

‎.changeset/clever-dryers-act.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fumadocs/cli': patch
3+
---
4+
5+
Fix Windows path problems

‎packages/cli/src/utils/transform-references.ts

+20-9
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,32 @@ export async function transformReferences(
6767
}
6868
}
6969

70+
/**
71+
* Return the import modifier for `sourceFile` to import `referenceFile`
72+
*
73+
* @example
74+
* ```ts
75+
* toReferencePath('index.ts', 'dir/hello.ts')
76+
* // should output './dir/hello'
77+
* ```
78+
*/
7079
export function toReferencePath(
7180
sourceFile: string,
7281
referenceFile: string,
7382
): string {
7483
const extname = path.extname(referenceFile);
75-
const importPath = path.relative(
76-
path.dirname(sourceFile),
77-
path.join(
78-
path.dirname(referenceFile),
79-
path.basename(
80-
referenceFile,
81-
typescriptExtensions.includes(extname) ? extname : undefined,
84+
const importPath = path
85+
.relative(
86+
path.dirname(sourceFile),
87+
path.join(
88+
path.dirname(referenceFile),
89+
path.basename(
90+
referenceFile,
91+
typescriptExtensions.includes(extname) ? extname : undefined,
92+
),
8293
),
83-
),
84-
);
94+
)
95+
.replaceAll(path.sep, '/');
8596

8697
return importPath.startsWith('../') ? importPath : `./${importPath}`;
8798
}

0 commit comments

Comments
 (0)
Please sign in to comment.