




















@@ -6,10 +6,11 @@
66import { createHash } from "node:crypto";
77import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
88import { homedir, tmpdir } from "node:os";
9-import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
9+import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
1010import { globSync } from "glob";
1111import ignore from "ignore";
1212import { minimatch } from "minimatch";
13+import { addIgnoreRules, toPosixPath, type IgnoreMatcher } from "../../shared/ignore-rules.js";
1314import { CONFIG_DIR_NAME } from "../config.js";
1415import { type GitSource, parseGitUrl } from "../utils/git.js";
1516import { canonicalizePath, isLocalPath } from "../utils/paths.js";
@@ -119,67 +120,10 @@ const FILE_PATTERNS: Record<ResourceType, RegExp> = {
119120themes: /\.json$/,
120121};
121122122-const IGNORE_FILE_NAMES = [".gitignore", ".ignore", ".fdignore"];
123-124-type IgnoreMatcher = ReturnType<typeof ignore>;
125-126-function toPosixPath(p: string): string {
127-return p.split(sep).join("/");
128-}
129-130123function getHomeDir(): string {
131124return process.env.HOME || homedir();
132125}
133126134-function prefixIgnorePattern(line: string, prefix: string): string | null {
135-const trimmed = line.trim();
136-if (!trimmed) {
137-return null;
138-}
139-if (trimmed.startsWith("#") && !trimmed.startsWith("\\#")) {
140-return null;
141-}
142-143-let pattern = line;
144-let negated = false;
145-146-if (pattern.startsWith("!")) {
147-negated = true;
148-pattern = pattern.slice(1);
149-} else if (pattern.startsWith("\\!")) {
150-pattern = pattern.slice(1);
151-}
152-153-if (pattern.startsWith("/")) {
154-pattern = pattern.slice(1);
155-}
156-157-const prefixed = prefix ? `${prefix}${pattern}` : pattern;
158-return negated ? `!${prefixed}` : prefixed;
159-}
160-161-function addIgnoreRules(ig: IgnoreMatcher, dir: string, rootDir: string): void {
162-const relativeDir = relative(rootDir, dir);
163-const prefix = relativeDir ? `${toPosixPath(relativeDir)}/` : "";
164-165-for (const filename of IGNORE_FILE_NAMES) {
166-const ignorePath = join(dir, filename);
167-if (!existsSync(ignorePath)) {
168-continue;
169-}
170-try {
171-const content = readFileSync(ignorePath, "utf-8");
172-const patterns = content
173-.split(/\r?\n/)
174-.map((line) => prefixIgnorePattern(line, prefix))
175-.filter((line): line is string => Boolean(line));
176-if (patterns.length > 0) {
177-ig.add(patterns);
178-}
179-} catch {}
180-}
181-}
182-183127function isPattern(s: string): boolean {
184128return (
185129s.startsWith("!") ||
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。