From f80bcb198117a8f6eb33e131de2bba8167b52a14 Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 5 Aug 2026 10:40:35 +0800 Subject: [PATCH] perf(fmt): avoid relative path resolution under root --- packages/rstack/src/fmt/ignore.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/rstack/src/fmt/ignore.ts b/packages/rstack/src/fmt/ignore.ts index b27ce88..c313ce3 100644 --- a/packages/rstack/src/fmt/ignore.ts +++ b/packages/rstack/src/fmt/ignore.ts @@ -22,9 +22,12 @@ interface CreateIgnoreMatcherOptions { const createPatternMatcher = (rootPath: string, patterns: string): IgnoreMatcher => { const matcher = createIgnore({ allowRelativePaths: true }).add(patterns); + const rootPrefix = rootPath.endsWith(path.sep) ? rootPath : `${rootPath}${path.sep}`; return (filePath, isDirectory = false) => { - const relativePath = path.relative(rootPath, filePath); + const relativePath = filePath.startsWith(rootPrefix) + ? filePath.slice(rootPrefix.length) + : path.relative(rootPath, filePath); if (relativePath === '') { return false; }