Skip to content

Commit 4c4fb24

Browse files
committed
fix: normalize file paths in convertDirectory for consistent processing
- Updated `convertDirectory` to normalize slashes in file paths, ensuring consistent handling across different operating systems. - Adjusted the calculation of relative paths to use the normalized absolute source directory.
1 parent 76dc715 commit 4c4fb24

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,13 @@ export async function convertDirectory(
250250
return [];
251251
}
252252

253-
for (const sourceFilePath of potentialFiles) {
254-
// sourceFilePath is now absolute, ensure relativePath calculation is correct
255-
const relativePath = relative(absoluteSourceDir, sourceFilePath);
256-
const parsedSourcePath = parse(sourceFilePath);
253+
const normalizedAbsoluteSourceDir = absoluteSourceDir.replace(/\\/g, '/'); // Normalize for relative path base
254+
255+
for (const rawSourceFilePath of potentialFiles) {
256+
const sourceFilePath = rawSourceFilePath.replace(/\\/g, '/'); // Normalize slashes for consistency
257+
// sourceFilePath is now absolute with normalized slashes, ensure relativePath calculation is correct
258+
const relativePath = relative(normalizedAbsoluteSourceDir, sourceFilePath);
259+
const parsedSourcePath = parse(sourceFilePath); // parse handles '/' fine
257260

258261
let fileSpecificDirection: ConversionDirection | undefined =
259262
options?.direction;
@@ -262,6 +265,7 @@ export async function convertDirectory(
262265
if (!fileSpecificDirection && !options?.forceFormat) {
263266
// Only detect if no overall direction and not forcing format
264267
try {
268+
// Use the potentially normalized sourceFilePath for reading
265269
const fileContentForDetect = await readFile(sourceFilePath, 'utf-8');
266270
const detectedFormat = detectFormat(fileContentForDetect);
267271
if (detectedFormat === 'cursor') {

0 commit comments

Comments
 (0)