Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/rstack/src/fmt/discoverPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ const findGitRoot = async (cwd: string): Promise<string> => {

class GitIgnoreMatcher {
readonly #rootPath: string;
readonly #rootPrefix: string;
readonly #matchers = new Map<string, ReturnType<typeof ignore>>();
readonly #loads = new Map<string, Promise<void>>();
readonly #ignoredDirectories = new Map<string, boolean>();

private constructor(rootPath: string) {
this.#rootPath = rootPath;
this.#rootPrefix = rootPath.endsWith(path.sep) ? rootPath : `${rootPath}${path.sep}`;
}

static async create(cwd: string): Promise<GitIgnoreMatcher> {
Expand Down Expand Up @@ -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;
}
Expand Down