CLI: fix Windows path problems

This commit is contained in:
Fuma Nama
2024-11-25 18:21:57 +08:00
parent 1cc7196021
commit b254ec20a3
2 changed files with 25 additions and 9 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@fumadocs/cli': patch
---
Fix Windows path problems
+20 -9
View File
@@ -67,21 +67,32 @@ export async function transformReferences(
}
}
/**
* Return the import modifier for `sourceFile` to import `referenceFile`
*
* @example
* ```ts
* toReferencePath('index.ts', 'dir/hello.ts')
* // should output './dir/hello'
* ```
*/
export function toReferencePath(
sourceFile: string,
referenceFile: string,
): string {
const extname = path.extname(referenceFile);
const importPath = path.relative(
path.dirname(sourceFile),
path.join(
path.dirname(referenceFile),
path.basename(
referenceFile,
typescriptExtensions.includes(extname) ? extname : undefined,
const importPath = path
.relative(
path.dirname(sourceFile),
path.join(
path.dirname(referenceFile),
path.basename(
referenceFile,
typescriptExtensions.includes(extname) ? extname : undefined,
),
),
),
);
)
.replaceAll(path.sep, '/');
return importPath.startsWith('../') ? importPath : `./${importPath}`;
}