Skip to content

Commit

Permalink
chore: fix win
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonIter committed Aug 13, 2024
1 parent 132941f commit ef426b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
9 changes: 7 additions & 2 deletions packages/core/src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ async function calcLongestCommonPath(
return null;
}

const splitPaths = absPaths.map((p) => p.split(path.posix.sep));
// we support two cases
// 1. /packages-a/src/index.ts
// 2. D:/packages-a/src/index.ts
const sep = path.posix.sep as '/';

const splitPaths = absPaths.map((p) => p.split(sep));
let lcaFragments = splitPaths[0]!;
for (let i = 1; i < splitPaths.length; i++) {
const currentPath = splitPaths[i]!;
Expand All @@ -92,7 +97,7 @@ async function calcLongestCommonPath(
lcaFragments = lcaFragments.slice(0, j);
}

let lca = lcaFragments.length > 0 ? lcaFragments.join(path.sep) : '/';
let lca = lcaFragments.length > 0 ? lcaFragments.join(sep) : sep;

const stats = await fsP.stat(lca);
if (stats?.isFile()) {
Expand Down
20 changes: 10 additions & 10 deletions packages/core/tests/lcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ describe('LCP calculate correctly', () => {
expect(result).toEqual('/Users/Someone/project-a/src');
} else {
const result = await calcLongestCommonPath([
'D:\\Users\\Someone\\project-a\\src\\helpers',
'D:\\Users\\Someone\\project-a\\src',
'D:\\Users\\Someone\\project-a\\src\\utils',
'D:/Users/Someone/project-a/src/helpers',
'D:/Users/Someone/project-a/src',
'D:/Users/Someone/project-a/src/utils',
]);
expect(result).toEqual('D:\\Users\\Someone\\project-a\\src');
expect(result).toEqual('D:/Users/Someone/project-a/src');
}
});

Expand All @@ -49,11 +49,11 @@ describe('LCP calculate correctly', () => {
expect(result).toEqual('/Users/Someone/project-monorepo');
} else {
const result = await calcLongestCommonPath([
'D:\\Users\\Someone\\project-monorepo\\packages-a\\src\\index.ts',
'D:\\Users\\Someone\\project-monorepo\\packages-util\\src\\index.js',
'D:\\Users\\Someone\\project-monorepo\\script.js',
'D:/Users/Someone/project-monorepo/packages-a/src/index.ts',
'D:/Users/Someone/project-monorepo/packages-util/src/index.js',
'D:/Users/Someone/project-monorepo/script.js',
]);
expect(result).toEqual('D:\\Users\\Someone\\project-monorepo');
expect(result).toEqual('D:/Users/Someone/project-monorepo');
}
});

Expand All @@ -68,9 +68,9 @@ describe('LCP calculate correctly', () => {
expect(result).toEqual('/Users/Someone/project/src');
} else {
const result = await calcLongestCommonPath([
'D:\\Users\\Someone\\project\\src\\index.js',
'D:/Users/Someone/project/src/index.js',
]);
expect(result).toEqual('D:\\Users\\Someone\\project\\src');
expect(result).toEqual('D:/Users/Someone/project/src');
}
});
});

0 comments on commit ef426b5

Please sign in to comment.