diff --git a/packages/rstack/src/fmt/discoverPaths.ts b/packages/rstack/src/fmt/discoverPaths.ts index 6eaf826..1b587bb 100644 --- a/packages/rstack/src/fmt/discoverPaths.ts +++ b/packages/rstack/src/fmt/discoverPaths.ts @@ -77,12 +77,14 @@ const findGitRoot = async (cwd: string): Promise => { class GitIgnoreMatcher { readonly #rootPath: string; + readonly #rootPrefix: string; readonly #matchers = new Map>(); readonly #loads = new Map>(); readonly #ignoredDirectories = new Map(); private constructor(rootPath: string) { this.#rootPath = rootPath; + this.#rootPrefix = rootPath.endsWith(path.sep) ? rootPath : `${rootPath}${path.sep}`; } static async create(cwd: string): Promise { @@ -120,7 +122,12 @@ class GitIgnoreMatcher { return false; } - const relativePath = path.relative(this.#rootPath, filePath); + const relativePath = + filePath === this.#rootPath + ? '' + : filePath.startsWith(this.#rootPrefix) + ? filePath.slice(this.#rootPrefix.length) + : path.relative(this.#rootPath, filePath); if (relativePath === '' || !isRelativePathInside(relativePath)) { return false; }