UNPKG

vuoto

Version:

Modern whitespace normalizer CLI with enhanced output and developer experience - cut the noise, clean the void

34 lines (33 loc) 991 B
import path from 'node:path'; import fg from 'fast-glob'; import { readGitignoreFile } from './read-gitignore-file.js'; /** * Collect .gitignore patterns recursively from cwd and all subfolders. * @param cwd The current working directory. * * @returns The collected .gitignore patterns. * * @example * * ```ts * const patterns = await collectGitignores(process.cwd()); * ``` */ export async function collectGitignores(cwd) { const gitignoreFiles = await fg('**/.gitignore', { cwd, absolute: true, dot: true, }); const patterns = []; for (const file of gitignoreFiles) { const dir = path.dirname(file); const localPatterns = await readGitignoreFile(dir); // prefix patterns with relative path of that .gitignore dir const relDir = path.relative(cwd, dir) || '.'; for (const p of localPatterns) { patterns.push(relDir === '.' ? p : `${relDir}/${p}`); } } return patterns; }