Skip to content

Commit 1024d5c

Browse files
authored
perf(fmt): avoid relative path resolution under root (#183)
1 parent f5901d7 commit 1024d5c

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

packages/rstack/src/fmt/ignore.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ interface CreateIgnoreMatcherOptions {
2222

2323
const createPatternMatcher = (rootPath: string, patterns: string): IgnoreMatcher => {
2424
const matcher = createIgnore({ allowRelativePaths: true }).add(patterns);
25+
const rootPrefix = rootPath.endsWith(path.sep) ? rootPath : `${rootPath}${path.sep}`;
2526

2627
return (filePath, isDirectory = false) => {
27-
const relativePath = path.relative(rootPath, filePath);
28+
const relativePath = filePath.startsWith(rootPrefix)
29+
? filePath.slice(rootPrefix.length)
30+
: path.relative(rootPath, filePath);
2831
if (relativePath === '') {
2932
return false;
3033
}

0 commit comments

Comments
 (0)