@w5s/eslint-config-ignore 1.33.0 → 1.34.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -6
- package/dist/index.js +11 -19
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/internal/ignoreFileFind.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/eslintIgnores.d.ts
|
|
2
1
|
export interface ESLintIgnoreConfig {
|
|
3
2
|
/**
|
|
4
3
|
* The file globs to ignore
|
|
@@ -57,13 +56,9 @@ export interface ESLintIgnoreOptions {
|
|
|
57
56
|
* @param options
|
|
58
57
|
*/
|
|
59
58
|
export declare function eslintIgnores(options?: ESLintIgnoreOptions): Promise<ESLintIgnoreConfig>;
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/meta.d.ts
|
|
62
59
|
export declare const meta: Readonly<{
|
|
63
60
|
buildNumber: number;
|
|
64
61
|
name: string;
|
|
65
62
|
version: string;
|
|
66
63
|
}>;
|
|
67
|
-
|
|
68
|
-
export { type ESLintIgnoreOptions as Options, eslintIgnores as default };
|
|
69
|
-
//# sourceMappingURL=index.d.ts.map
|
|
64
|
+
export { type ESLintIgnoreOptions as Options, eslintIgnores as default };
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import process from "node:process";
|
|
|
4
4
|
import { minimatch } from "minimatch";
|
|
5
5
|
import fs$1 from "node:fs/promises";
|
|
6
6
|
import parseGitignore from "parse-gitignore";
|
|
7
|
-
|
|
7
|
+
// src/defaultIgnores.ts
|
|
8
8
|
const defaultIgnores = [
|
|
9
9
|
"**/package-lock.json",
|
|
10
10
|
"**/yarn.lock",
|
|
@@ -40,8 +40,7 @@ const defaultIgnores = [
|
|
|
40
40
|
"**/.agents",
|
|
41
41
|
"**/.*/skills"
|
|
42
42
|
];
|
|
43
|
-
|
|
44
|
-
//#region src/internal/gitModulesIgnore.ts
|
|
43
|
+
// src/internal/gitModulesIgnore.ts
|
|
45
44
|
const SUBMODULE_PATH_RE = /path\s*=\s*(.+)/g;
|
|
46
45
|
/**
|
|
47
46
|
* Read `cwd/.gitmodules` and return ESLint ignore glob patterns for every
|
|
@@ -90,13 +89,11 @@ function gitModulesParse(content) {
|
|
|
90
89
|
}
|
|
91
90
|
return paths;
|
|
92
91
|
}
|
|
93
|
-
|
|
94
|
-
//#region src/internal/ignoreFileParse.ts
|
|
92
|
+
// src/internal/ignoreFileParse.ts
|
|
95
93
|
function ignoreFileParse(input) {
|
|
96
94
|
return parseGitignore.parse(input).patterns;
|
|
97
95
|
}
|
|
98
|
-
|
|
99
|
-
//#region src/internal/convertIgnorePatternToMinimatch.ts
|
|
96
|
+
// src/internal/convertIgnorePatternToMinimatch.ts
|
|
100
97
|
/**
|
|
101
98
|
* Converts a gitignore-style pattern to an ESLint-compatible minimatch pattern.
|
|
102
99
|
*
|
|
@@ -129,8 +126,7 @@ function convertIgnorePatternToMinimatch(pattern) {
|
|
|
129
126
|
const matchInsideSuffix = patternToTest.endsWith("/**") ? "/*" : "";
|
|
130
127
|
return `${negatedPrefix}${matchEverywherePrefix}${escapedPatternWithoutLeadingSlash}${matchInsideSuffix}`;
|
|
131
128
|
}
|
|
132
|
-
|
|
133
|
-
//#region src/internal/ignoreRuleResolve.ts
|
|
129
|
+
// src/internal/ignoreRuleResolve.ts
|
|
134
130
|
const ROOT_PREFIX_PATTERN = /^\.\/?/;
|
|
135
131
|
const normalizePath = (p) => p.replaceAll("\\", "/").replace(ROOT_PREFIX_PATTERN, "");
|
|
136
132
|
/**
|
|
@@ -162,8 +158,7 @@ function ignoreRuleResolve(prefix, rule) {
|
|
|
162
158
|
else converted = (normalizedPrefix ? `${normalizedPrefix}/` : "") + convertIgnorePatternToMinimatch(raw);
|
|
163
159
|
return negated ? `!${converted}` : converted;
|
|
164
160
|
}
|
|
165
|
-
|
|
166
|
-
//#region src/internal/ignoreFileFind.ts
|
|
161
|
+
// src/internal/ignoreFileFind.ts
|
|
167
162
|
const GITIGNORE_FILE = ".gitignore";
|
|
168
163
|
/**
|
|
169
164
|
* Find `.gitignore` files relevant to `rootDir`.
|
|
@@ -206,7 +201,7 @@ async function ignoreFileFind(rootDir, options) {
|
|
|
206
201
|
}
|
|
207
202
|
function isIgnored(patterns, candidateRel) {
|
|
208
203
|
const m = lastMatchWins(patterns, candidateRel);
|
|
209
|
-
return m
|
|
204
|
+
return m !== null && !m.startsWith("!");
|
|
210
205
|
}
|
|
211
206
|
async function collectAncestorGitignores(startDir) {
|
|
212
207
|
const files = [];
|
|
@@ -272,8 +267,7 @@ async function ignoreFileFind(rootDir, options) {
|
|
|
272
267
|
}
|
|
273
268
|
return [...found].map((p) => nodePath.relative(rootDir, p));
|
|
274
269
|
}
|
|
275
|
-
|
|
276
|
-
//#region src/eslintIgnores.ts
|
|
270
|
+
// src/eslintIgnores.ts
|
|
277
271
|
/**
|
|
278
272
|
* Create a new eslint configuration object
|
|
279
273
|
*
|
|
@@ -310,14 +304,12 @@ async function eslintIgnores(options = {}) {
|
|
|
310
304
|
name: `${namespace}/eslint-ignore`
|
|
311
305
|
};
|
|
312
306
|
}
|
|
313
|
-
|
|
314
|
-
//#region src/meta.ts
|
|
307
|
+
// src/meta.ts
|
|
315
308
|
const meta = Object.freeze({
|
|
316
|
-
buildNumber:
|
|
309
|
+
buildNumber: 0x6b04cca5,
|
|
317
310
|
name: "@w5s/eslint-config-ignore",
|
|
318
|
-
version: "1.
|
|
311
|
+
version: "1.34.1"
|
|
319
312
|
});
|
|
320
|
-
//#endregion
|
|
321
313
|
export { eslintIgnores as default, eslintIgnores, meta };
|
|
322
314
|
|
|
323
315
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fs"],"sources":["../src/defaultIgnores.ts","../src/internal/gitModulesIgnore.ts","../src/internal/ignoreFileParse.ts","../src/internal/convertIgnorePatternToMinimatch.ts","../src/internal/ignoreRuleResolve.ts","../src/internal/ignoreFileFind.ts","../src/eslintIgnores.ts","../src/meta.ts"],"sourcesContent":["export const defaultIgnores = [\n // Lock files\n '**/package-lock.json',\n '**/yarn.lock',\n '**/pnpm-lock.yaml',\n '**/bun.lockb',\n\n // Commonly ignored\n '**/output',\n '**/.output',\n '**/coverage',\n '**/temp',\n '**/.temp',\n '**/tmp',\n '**/.tmp',\n '**/.cache',\n\n // Well known extensions to ignore\n '**/*.min.*',\n '**/*.timestamp-*.mjs',\n\n // Framework specific temporary folder\n '.go/',\n '.pnpm-store/',\n '**/.vitepress/cache',\n '**/.vite-inspect',\n '**/.history',\n '**/.nuxt',\n '**/.next',\n '**/next-env.d.ts',\n '**/.svelte-kit',\n '**/.vercel',\n '**/.idea',\n '**/.yarn',\n '**/__snapshots__/**',\n\n // Generated markdown\n '**/CHANGELOG.md',\n\n // git submodules (makefile-core / makefile-ci)\n '.modules/',\n\n // AI related\n '**/.context',\n '**/.claude',\n '**/.agents',\n '**/.*/skills',\n];\n","import fs from 'node:fs';\nimport nodePath from 'node:path';\n\nconst SUBMODULE_PATH_RE = /path\\s*=\\s*(.+)/g;\n\n/**\n * Read `cwd/.gitmodules` and return ESLint ignore glob patterns for every\n * listed submodule. Returns an empty array when no `.gitmodules` file exists.\n *\n * @param cwd\n * @example\n * ```ts\n * await gitModulesIgnore('/path/to/project');\n * // ['**\\/packages/foo\\/**', '**\\/packages/bar\\/**']\n * ```\n */\nexport async function gitModulesIgnore(cwd: string): Promise<Array<string>> {\n const gmPath = nodePath.join(cwd, '.gitmodules');\n try {\n let stat = null;\n try {\n stat = await fs.promises.stat(gmPath);\n } catch {\n stat = null;\n }\n if (!stat?.isFile()) return [];\n\n const content = (await fs.promises.readFile(gmPath, 'utf8'));\n const paths = gitModulesParse(content);\n return paths.map((p) => `${p.replaceAll('\\\\', '/')}/**`);\n } catch {\n return [];\n }\n}\n\n/**\n * Parse the content of a `.gitmodules` file and return the list of submodule paths.\n *\n * @param content\n * @example\n * ```ts\n * gitModulesParse('[submodule \"foo\"]\\n\\tpath = packages/foo\\n');\n * // ['packages/foo']\n * ```\n */\nexport function gitModulesParse(content: string): Array<string> {\n const paths: Array<string> = [];\n SUBMODULE_PATH_RE.lastIndex = 0;\n for (;;) {\n const matches = SUBMODULE_PATH_RE.exec(content);\n if (!matches) break;\n const captured = matches[1];\n if (captured) paths.push(captured.trim());\n }\n return paths;\n}\n","import parseGitignore from 'parse-gitignore';\n\nexport function ignoreFileParse(input: string): Array<string> {\n return parseGitignore.parse(input).patterns;\n};\n","/**\n * Converts a gitignore-style pattern to an ESLint-compatible minimatch pattern.\n *\n * Ported from `@eslint/config-helpers` (eslint/rewrite).\n *\n * @see https://github.com/eslint/rewrite/blob/main/packages/config-helpers/src/ignore-file.js\n * @param pattern The .eslintignore or .gitignore pattern to convert.\n * @returns The converted minimatch pattern.\n */\nexport function convertIgnorePatternToMinimatch(pattern: string): string {\n const isNegated = pattern.startsWith('!');\n const negatedPrefix = isNegated ? '!' : '';\n const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd();\n\n // special cases\n if (['', '**', '**/', '/**'].includes(patternToTest)) {\n return `${negatedPrefix}${patternToTest}`;\n }\n\n const firstIndexOfSlash = patternToTest.indexOf('/');\n\n const matchEverywherePrefix = firstIndexOfSlash === -1 || firstIndexOfSlash === patternToTest.length - 1 ? '**/' : '';\n\n const patternWithoutLeadingSlash = firstIndexOfSlash === 0 ? patternToTest.slice(1) : patternToTest;\n\n /*\n * Escape `{` and `(` because in gitignore patterns they are just\n * literal characters without any specific syntactic meaning,\n * while in minimatch patterns they can form brace expansion or ext glob syntax.\n */\n let escapedPatternWithoutLeadingSlash = '';\n let isEscaped = false;\n\n for (const char of patternWithoutLeadingSlash) {\n if (!isEscaped && (char === '{' || char === '(')) {\n escapedPatternWithoutLeadingSlash += '\\\\';\n }\n\n escapedPatternWithoutLeadingSlash += char;\n\n isEscaped = char === '\\\\' && !isEscaped;\n }\n\n const matchInsideSuffix = patternToTest.endsWith('/**') ? '/*' : '';\n\n return `${negatedPrefix}${matchEverywherePrefix}${escapedPatternWithoutLeadingSlash}${matchInsideSuffix}`;\n}\n","import { convertIgnorePatternToMinimatch } from './convertIgnorePatternToMinimatch.js';\n\nconst ROOT_PREFIX_PATTERN = /^\\.\\/?/;\n\nconst normalizePath = (p: string) => p.replaceAll('\\\\', '/').replace(ROOT_PREFIX_PATTERN, '');\n\n/**\n * Resolve a raw ignore rule from a `.gitignore` file into a flat ESLint\n * minimatch glob relative to the configured working directory.\n *\n * @example\n * ```ts\n * import { ignoreRuleResolve } from './internal/ignoreRuleResolve.js';\n *\n * ignoreRuleResolve('.', 'out'); // '**\\/out'\n * ignoreRuleResolve('.', '/dist'); // 'dist'\n * ignoreRuleResolve('android', 'build'); // 'android/**\\/build'\n * ignoreRuleResolve('android', '/build'); // 'android/build'\n * ignoreRuleResolve('android', '!build'); // '!android/**\\/build'\n * ```\n *\n * @internal\n * @param prefix A path prefix that points to the directory containing the `.gitignore` file.\n * @param rule The raw ignore rule parsed from `.gitignore`.\n * @returns A normalized ignore pattern relative to the root `cwd`.\n */\nexport function ignoreRuleResolve(prefix: string, rule: string): string {\n const negated = rule.startsWith('!');\n const raw = negated ? rule.slice(1) : rule;\n const normalizedPrefix = prefix === '.' || prefix === '' ? '' : normalizePath(prefix);\n\n let converted: string;\n if (raw.startsWith('/')) {\n const joined = normalizedPrefix\n ? `${normalizedPrefix}/${raw.slice(1)}`\n : raw.slice(1);\n converted = convertIgnorePatternToMinimatch(`/${joined}`);\n } else {\n const dirPrefix = normalizedPrefix ? `${normalizedPrefix}/` : '';\n converted = dirPrefix + convertIgnorePatternToMinimatch(raw);\n }\n\n return negated ? `!${converted}` : converted;\n}\n","/* eslint-disable unicorn/prefer-await */\nimport { minimatch } from 'minimatch';\nimport fs from 'node:fs/promises';\nimport nodePath from 'node:path';\n\nimport { ignoreFileParse } from './ignoreFileParse.js';\nimport { ignoreRuleResolve } from './ignoreRuleResolve.js';\n\nconst GITIGNORE_FILE = '.gitignore';\n\nexport interface IgnoreFileFindOptions {\n /** Directory names to skip when searching downward from `rootDir`. */\n excludeDirs?: Array<string>;\n /** Maximum recursion depth when searching downward. Defaults to 8. */\n maxDepth?: number;\n /** When true (default), stop ancestor traversal when a `.git` directory is found. */\n stopAtGitRoot?: boolean;\n}\n\n/**\n * Find `.gitignore` files relevant to `rootDir`.\n *\n * Behavior:\n * - Searches downwards from `rootDir` (BFS) for `.gitignore` files, skipping `excludeDirs`.\n * - Walks ancestors from `rootDir` up to the filesystem root (and stops at a `.git` folder when `stopAtGitRoot` is true).\n * - Returns relative paths to `rootDir`.\n *\n * @param rootDir\n * @param options\n */\nexport async function ignoreFileFind(\n rootDir: string,\n options?: IgnoreFileFindOptions,\n): Promise<Array<string>> {\n const excludeDirs = new Set(options?.excludeDirs ?? ['node_modules', '.git']);\n const maxDepth = options?.maxDepth ?? 8;\n const stopAtGitRoot = options?.stopAtGitRoot ?? true;\n\n const absoluteRootDir = nodePath.resolve(rootDir);\n const found = new Set<string>();\n\n // --- Helpers (internal, not exported) ---------------------------------\n const normalize = (p: string) => p.replaceAll('\\\\', '/');\n\n function patternMatchesPath(pattern: string, candidateRel: string): boolean {\n const normCandidate = normalize(candidateRel);\n const normPattern = normalize(pattern);\n\n if (minimatch(normCandidate, normPattern, { dot: true })) {\n return true;\n }\n\n if (minimatch(normCandidate, `${normPattern}/**`, { dot: true })) {\n return true;\n }\n\n if (normPattern.endsWith('/')) {\n const withoutTrailing = normPattern.slice(0, -1);\n if (minimatch(normCandidate, withoutTrailing, { dot: true })) {\n return true;\n }\n if (minimatch(normCandidate, `${withoutTrailing}/**`, { dot: true })) {\n return true;\n }\n }\n\n return false;\n }\n\n function lastMatchWins(patterns: Array<string>, candidateRel: string): null | string {\n let lastMatch: null | string = null;\n for (const p of patterns) {\n const pat = p.startsWith('!') ? p.slice(1) : p;\n if (!pat) continue;\n\n if (patternMatchesPath(pat, candidateRel)) {\n lastMatch = p;\n }\n }\n return lastMatch;\n }\n\n function isIgnored(patterns: Array<string>, candidateRel: string): boolean {\n const m = lastMatchWins(patterns, candidateRel);\n return m ? !m.startsWith('!') : false;\n }\n\n async function collectAncestorGitignores(startDir: string): Promise<Array<string>> {\n const files: Array<string> = [];\n let dir = startDir;\n while (true) {\n const gi = nodePath.join(dir, GITIGNORE_FILE);\n try {\n const stat = await fs.stat(gi).catch(() => null);\n if (stat?.isFile()) files.push(gi);\n } catch {\n // ignore\n }\n\n if (stopAtGitRoot) {\n try {\n const gitStat = await fs.stat(nodePath.join(dir, '.git')).catch(() => null);\n if (gitStat?.isDirectory()) break;\n } catch {\n // ignore\n }\n }\n\n const parent = nodePath.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n // eslint-disable-next-line unicorn/no-array-reverse\n return files.reverse();\n }\n\n async function parseAndResolve(giPath: string): Promise<Array<string>> {\n try {\n const content = (await fs.readFile(giPath, 'utf8'));\n const parsed = ignoreFileParse(content);\n const prefixRel = nodePath.relative(rootDir, nodePath.dirname(giPath));\n return parsed.map((p) => ignoreRuleResolve(prefixRel, p));\n } catch {\n return [];\n }\n }\n\n // --- Build initial patterns from ancestor .gitignore files -------------\n const ancestorFiles = await collectAncestorGitignores(absoluteRootDir);\n const initialPatterns: Array<string> = [];\n for (const gi of ancestorFiles) {\n const parsed = await parseAndResolve(gi);\n if (parsed.length > 0) initialPatterns.push(...parsed);\n found.add(gi);\n }\n\n // --- BFS downward carrying accumulated patterns -----------------------\n const queue: Array<{ depth: number; dir: string; patterns: Array<string> }> = [\n { depth: 0, dir: absoluteRootDir, patterns: [...initialPatterns] },\n ];\n\n while (queue.length > 0) {\n // eslint-disable-next-line ts/no-non-null-assertion\n const { depth, dir: currentDir, patterns } = queue.shift()!;\n if (depth > maxDepth) continue;\n\n let entries;\n try {\n entries = await fs.readdir(currentDir, { withFileTypes: true });\n } catch {\n continue; // unreadable\n }\n\n // If local .gitignore exists, parse and extend patterns\n\n // eslint-disable-next-line unicorn/prefer-array-some\n const local = entries.find((e) => e.isFile() && e.name === GITIGNORE_FILE);\n const combinedPatterns = local ? [...patterns, ...(await parseAndResolve(nodePath.join(currentDir, GITIGNORE_FILE)))] : patterns;\n if (local) found.add(nodePath.join(currentDir, GITIGNORE_FILE));\n\n for (const ent of entries) {\n if (!ent.isDirectory()) continue;\n if (excludeDirs.has(ent.name)) continue;\n const subdir = nodePath.join(currentDir, ent.name);\n const rel = nodePath.relative(rootDir, subdir);\n if (isIgnored(combinedPatterns, rel)) continue;\n queue.push({ depth: depth + 1, dir: subdir, patterns: combinedPatterns });\n }\n }\n\n return [...found].map((p) => nodePath.relative(rootDir, p));\n}\n","import fs from 'node:fs';\nimport nodePath from 'node:path';\nimport process from 'node:process';\n\nimport { defaultIgnores } from './defaultIgnores.js';\nimport { gitModulesIgnore } from './internal/gitModulesIgnore.js';\nimport { ignoreFileFind } from './internal/ignoreFileFind.js';\nimport { ignoreFileParse } from './internal/ignoreFileParse.js';\nimport { ignoreRuleResolve } from './internal/ignoreRuleResolve.js';\n\nexport interface ESLintIgnoreConfig {\n /**\n * The file globs to ignore\n */\n ignores: Array<string>;\n\n /**\n * The configuration name\n */\n name: string;\n}\n\nexport interface ESLintIgnoreOptions {\n /**\n * Override current working directory\n */\n cwd?: string;\n\n /**\n * Whether to ignore git submodules (default: true)\n */\n ignoreGitModules?: boolean;\n\n /**\n * Override or customize ignore patterns.\n * - If passed an array, it appends patterns to the merged ignore list.\n * - If passed a function, it receives the merged list and returns the final array.\n */\n ignores?: ((ignores: ESLintIgnoreConfig['ignores']) => ESLintIgnoreConfig['ignores']) | ESLintIgnoreConfig['ignores'];\n\n /**\n * Override the namespace used in the configuration name (default: 'w5s')\n *\n * @example\n * ```ts\n * await eslintIgnores({ namespace: 'custom-name' });// { name: 'custom-name/eslint-ignore', ignores: [...] }\n * ```\n */\n namespace?: string | undefined;\n\n /**\n * Include recommended settings and default ignored files\n */\n recommended?: boolean | undefined;\n}\n\n/**\n * Create a new eslint configuration object\n *\n * @example\n * ```ts\n * // eslint.config.js\n * export default [\n * await eslintIgnores({\n * ignores: [\n * // Add custom paths here\n * ],\n * // namespace: 'custom-name', // Optional namespace override\n * })\n * ];\n * ```\n *\n * @param options\n */\nexport async function eslintIgnores(options: ESLintIgnoreOptions = {}): Promise<ESLintIgnoreConfig> {\n const cwd = options.cwd ?? process.cwd();\n const namespace = options.namespace ?? 'w5s';\n const recommended = options.recommended ?? true;\n const ignoreFilePaths = await ignoreFileFind(cwd);\n const ignoreGlobs = (await Promise.all(ignoreFilePaths.map(async (ignoreFilePathRelative) => {\n const ignoreFilePath = nodePath.join(cwd, ignoreFilePathRelative);\n const ignoreFileContent = String(await fs.promises.readFile(ignoreFilePath));\n const patterns = ignoreFileParse(ignoreFileContent);\n const ignoreDirectoryRelative = nodePath.dirname(ignoreFilePathRelative);\n\n return patterns.map((pattern) => ignoreRuleResolve(ignoreDirectoryRelative, pattern));\n })));\n\n const mergedIgnores = [\n ...(recommended ? defaultIgnores : []),\n ...ignoreGlobs.flat(),\n ];\n\n // Optionally include .gitmodules entries as ignores (each submodule path -> `${path}/**`)\n if (options.ignoreGitModules ?? true) {\n mergedIgnores.push(...await gitModulesIgnore(cwd));\n }\n\n const ignores = typeof options.ignores === 'function'\n ? options.ignores(mergedIgnores)\n : options.ignores\n ? [...mergedIgnores, ...options.ignores]\n : mergedIgnores;\n\n return {\n ignores,\n name: `${namespace}/eslint-ignore`,\n };\n}\n","export const meta = Object.freeze({\n // @ts-ignore - these variables are injected at build time\n buildNumber: (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\n // @ts-ignore - these variables are injected at build time\n name: (typeof __PACKAGE_NAME__ === 'undefined' ? '' : __PACKAGE_NAME__) as string,\n // @ts-ignore - these variables are injected at build time\n version: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,\n});\n"],"mappings":";;;;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,aACvC,QAAQ,QAAQ,aAAa,IAC7B,QAAQ,UACN,CAAC,GAAG,eAAe,GAAG,QAAQ,OAAO,IACrC;EAIJ,MAAM,GAAG,UAAU;CACrB;AACF;;;AC5GA,MAAa,OAAO,OAAO,OAAO;CAEhC,aAAA;CAEA,MAAA;CAEA,SAAA;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["fs"],"sources":["../src/defaultIgnores.ts","../src/internal/gitModulesIgnore.ts","../src/internal/ignoreFileParse.ts","../src/internal/convertIgnorePatternToMinimatch.ts","../src/internal/ignoreRuleResolve.ts","../src/internal/ignoreFileFind.ts","../src/eslintIgnores.ts","../src/meta.ts"],"sourcesContent":["export const defaultIgnores = [\n // Lock files\n '**/package-lock.json',\n '**/yarn.lock',\n '**/pnpm-lock.yaml',\n '**/bun.lockb',\n\n // Commonly ignored\n '**/output',\n '**/.output',\n '**/coverage',\n '**/temp',\n '**/.temp',\n '**/tmp',\n '**/.tmp',\n '**/.cache',\n\n // Well known extensions to ignore\n '**/*.min.*',\n '**/*.timestamp-*.mjs',\n\n // Framework specific temporary folder\n '.go/',\n '.pnpm-store/',\n '**/.vitepress/cache',\n '**/.vite-inspect',\n '**/.history',\n '**/.nuxt',\n '**/.next',\n '**/next-env.d.ts',\n '**/.svelte-kit',\n '**/.vercel',\n '**/.idea',\n '**/.yarn',\n '**/__snapshots__/**',\n\n // Generated markdown\n '**/CHANGELOG.md',\n\n // git submodules (makefile-core / makefile-ci)\n '.modules/',\n\n // AI related\n '**/.context',\n '**/.claude',\n '**/.agents',\n '**/.*/skills',\n];\n","import fs from 'node:fs';\nimport nodePath from 'node:path';\n\nconst SUBMODULE_PATH_RE = /path\\s*=\\s*(.+)/g;\n\n/**\n * Read `cwd/.gitmodules` and return ESLint ignore glob patterns for every\n * listed submodule. Returns an empty array when no `.gitmodules` file exists.\n *\n * @param cwd\n * @example\n * ```ts\n * await gitModulesIgnore('/path/to/project');\n * // ['**\\/packages/foo\\/**', '**\\/packages/bar\\/**']\n * ```\n */\nexport async function gitModulesIgnore(cwd: string): Promise<Array<string>> {\n const gmPath = nodePath.join(cwd, '.gitmodules');\n try {\n let stat = null;\n try {\n stat = await fs.promises.stat(gmPath);\n } catch {\n stat = null;\n }\n if (!stat?.isFile()) return [];\n\n const content = (await fs.promises.readFile(gmPath, 'utf8'));\n const paths = gitModulesParse(content);\n return paths.map((p) => `${p.replaceAll('\\\\', '/')}/**`);\n } catch {\n return [];\n }\n}\n\n/**\n * Parse the content of a `.gitmodules` file and return the list of submodule paths.\n *\n * @param content\n * @example\n * ```ts\n * gitModulesParse('[submodule \"foo\"]\\n\\tpath = packages/foo\\n');\n * // ['packages/foo']\n * ```\n */\nexport function gitModulesParse(content: string): Array<string> {\n const paths: Array<string> = [];\n SUBMODULE_PATH_RE.lastIndex = 0;\n for (;;) {\n const matches = SUBMODULE_PATH_RE.exec(content);\n if (!matches) break;\n const captured = matches[1];\n if (captured) paths.push(captured.trim());\n }\n return paths;\n}\n","import parseGitignore from 'parse-gitignore';\n\nexport function ignoreFileParse(input: string): Array<string> {\n return parseGitignore.parse(input).patterns;\n};\n","/**\n * Converts a gitignore-style pattern to an ESLint-compatible minimatch pattern.\n *\n * Ported from `@eslint/config-helpers` (eslint/rewrite).\n *\n * @see https://github.com/eslint/rewrite/blob/main/packages/config-helpers/src/ignore-file.js\n * @param pattern The .eslintignore or .gitignore pattern to convert.\n * @returns The converted minimatch pattern.\n */\nexport function convertIgnorePatternToMinimatch(pattern: string): string {\n const isNegated = pattern.startsWith('!');\n const negatedPrefix = isNegated ? '!' : '';\n const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd();\n\n // special cases\n if (['', '**', '**/', '/**'].includes(patternToTest)) {\n return `${negatedPrefix}${patternToTest}`;\n }\n\n const firstIndexOfSlash = patternToTest.indexOf('/');\n\n const matchEverywherePrefix = firstIndexOfSlash === -1 || firstIndexOfSlash === patternToTest.length - 1 ? '**/' : '';\n\n const patternWithoutLeadingSlash = firstIndexOfSlash === 0 ? patternToTest.slice(1) : patternToTest;\n\n /*\n * Escape `{` and `(` because in gitignore patterns they are just\n * literal characters without any specific syntactic meaning,\n * while in minimatch patterns they can form brace expansion or ext glob syntax.\n */\n let escapedPatternWithoutLeadingSlash = '';\n let isEscaped = false;\n\n for (const char of patternWithoutLeadingSlash) {\n if (!isEscaped && (char === '{' || char === '(')) {\n escapedPatternWithoutLeadingSlash += '\\\\';\n }\n\n escapedPatternWithoutLeadingSlash += char;\n\n isEscaped = char === '\\\\' && !isEscaped;\n }\n\n const matchInsideSuffix = patternToTest.endsWith('/**') ? '/*' : '';\n\n return `${negatedPrefix}${matchEverywherePrefix}${escapedPatternWithoutLeadingSlash}${matchInsideSuffix}`;\n}\n","import { convertIgnorePatternToMinimatch } from './convertIgnorePatternToMinimatch.js';\n\nconst ROOT_PREFIX_PATTERN = /^\\.\\/?/;\n\nconst normalizePath = (p: string) => p.replaceAll('\\\\', '/').replace(ROOT_PREFIX_PATTERN, '');\n\n/**\n * Resolve a raw ignore rule from a `.gitignore` file into a flat ESLint\n * minimatch glob relative to the configured working directory.\n *\n * @example\n * ```ts\n * import { ignoreRuleResolve } from './internal/ignoreRuleResolve.js';\n *\n * ignoreRuleResolve('.', 'out'); // '**\\/out'\n * ignoreRuleResolve('.', '/dist'); // 'dist'\n * ignoreRuleResolve('android', 'build'); // 'android/**\\/build'\n * ignoreRuleResolve('android', '/build'); // 'android/build'\n * ignoreRuleResolve('android', '!build'); // '!android/**\\/build'\n * ```\n *\n * @internal\n * @param prefix A path prefix that points to the directory containing the `.gitignore` file.\n * @param rule The raw ignore rule parsed from `.gitignore`.\n * @returns A normalized ignore pattern relative to the root `cwd`.\n */\nexport function ignoreRuleResolve(prefix: string, rule: string): string {\n const negated = rule.startsWith('!');\n const raw = negated ? rule.slice(1) : rule;\n const normalizedPrefix = prefix === '.' || prefix === '' ? '' : normalizePath(prefix);\n\n let converted: string;\n if (raw.startsWith('/')) {\n const joined = normalizedPrefix\n ? `${normalizedPrefix}/${raw.slice(1)}`\n : raw.slice(1);\n converted = convertIgnorePatternToMinimatch(`/${joined}`);\n } else {\n const dirPrefix = normalizedPrefix ? `${normalizedPrefix}/` : '';\n converted = dirPrefix + convertIgnorePatternToMinimatch(raw);\n }\n\n return negated ? `!${converted}` : converted;\n}\n","/* eslint-disable unicorn/prefer-await */\nimport { minimatch } from 'minimatch';\nimport fs from 'node:fs/promises';\nimport nodePath from 'node:path';\n\nimport { ignoreFileParse } from './ignoreFileParse.js';\nimport { ignoreRuleResolve } from './ignoreRuleResolve.js';\n\nconst GITIGNORE_FILE = '.gitignore';\n\nexport interface IgnoreFileFindOptions {\n /** Directory names to skip when searching downward from `rootDir`. */\n excludeDirs?: Array<string>;\n /** Maximum recursion depth when searching downward. Defaults to 8. */\n maxDepth?: number;\n /** When true (default), stop ancestor traversal when a `.git` directory is found. */\n stopAtGitRoot?: boolean;\n}\n\n/**\n * Find `.gitignore` files relevant to `rootDir`.\n *\n * Behavior:\n * - Searches downwards from `rootDir` (BFS) for `.gitignore` files, skipping `excludeDirs`.\n * - Walks ancestors from `rootDir` up to the filesystem root (and stops at a `.git` folder when `stopAtGitRoot` is true).\n * - Returns relative paths to `rootDir`.\n *\n * @param rootDir\n * @param options\n */\nexport async function ignoreFileFind(\n rootDir: string,\n options?: IgnoreFileFindOptions,\n): Promise<Array<string>> {\n const excludeDirs = new Set(options?.excludeDirs ?? ['node_modules', '.git']);\n const maxDepth = options?.maxDepth ?? 8;\n const stopAtGitRoot = options?.stopAtGitRoot ?? true;\n\n const absoluteRootDir = nodePath.resolve(rootDir);\n const found = new Set<string>();\n\n // --- Helpers (internal, not exported) ---------------------------------\n const normalize = (p: string) => p.replaceAll('\\\\', '/');\n\n function patternMatchesPath(pattern: string, candidateRel: string): boolean {\n const normCandidate = normalize(candidateRel);\n const normPattern = normalize(pattern);\n\n if (minimatch(normCandidate, normPattern, { dot: true })) {\n return true;\n }\n\n if (minimatch(normCandidate, `${normPattern}/**`, { dot: true })) {\n return true;\n }\n\n if (normPattern.endsWith('/')) {\n const withoutTrailing = normPattern.slice(0, -1);\n if (minimatch(normCandidate, withoutTrailing, { dot: true })) {\n return true;\n }\n if (minimatch(normCandidate, `${withoutTrailing}/**`, { dot: true })) {\n return true;\n }\n }\n\n return false;\n }\n\n function lastMatchWins(patterns: Array<string>, candidateRel: string): null | string {\n let lastMatch: null | string = null;\n for (const p of patterns) {\n const pat = p.startsWith('!') ? p.slice(1) : p;\n if (!pat) continue;\n\n if (patternMatchesPath(pat, candidateRel)) {\n lastMatch = p;\n }\n }\n return lastMatch;\n }\n\n function isIgnored(patterns: Array<string>, candidateRel: string): boolean {\n const m = lastMatchWins(patterns, candidateRel);\n return m !== null && !m.startsWith('!');\n }\n\n async function collectAncestorGitignores(startDir: string): Promise<Array<string>> {\n const files: Array<string> = [];\n let dir = startDir;\n while (true) {\n const gi = nodePath.join(dir, GITIGNORE_FILE);\n try {\n const stat = await fs.stat(gi).catch(() => null);\n if (stat?.isFile()) files.push(gi);\n } catch {\n // ignore\n }\n\n if (stopAtGitRoot) {\n try {\n const gitStat = await fs.stat(nodePath.join(dir, '.git')).catch(() => null);\n if (gitStat?.isDirectory()) break;\n } catch {\n // ignore\n }\n }\n\n const parent = nodePath.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n // eslint-disable-next-line unicorn/no-array-reverse\n return files.reverse();\n }\n\n async function parseAndResolve(giPath: string): Promise<Array<string>> {\n try {\n const content = (await fs.readFile(giPath, 'utf8'));\n const parsed = ignoreFileParse(content);\n const prefixRel = nodePath.relative(rootDir, nodePath.dirname(giPath));\n return parsed.map((p) => ignoreRuleResolve(prefixRel, p));\n } catch {\n return [];\n }\n }\n\n // --- Build initial patterns from ancestor .gitignore files -------------\n const ancestorFiles = await collectAncestorGitignores(absoluteRootDir);\n const initialPatterns: Array<string> = [];\n for (const gi of ancestorFiles) {\n const parsed = await parseAndResolve(gi);\n if (parsed.length > 0) initialPatterns.push(...parsed);\n found.add(gi);\n }\n\n // --- BFS downward carrying accumulated patterns -----------------------\n const queue: Array<{ depth: number; dir: string; patterns: Array<string> }> = [\n { depth: 0, dir: absoluteRootDir, patterns: [...initialPatterns] },\n ];\n\n while (queue.length > 0) {\n // eslint-disable-next-line ts/no-non-null-assertion\n const { depth, dir: currentDir, patterns } = queue.shift()!;\n if (depth > maxDepth) continue;\n\n let entries;\n try {\n entries = await fs.readdir(currentDir, { withFileTypes: true });\n } catch {\n continue; // unreadable\n }\n\n // If local .gitignore exists, parse and extend patterns\n\n // eslint-disable-next-line unicorn/prefer-array-some\n const local = entries.find((e) => e.isFile() && e.name === GITIGNORE_FILE);\n const combinedPatterns = local ? [...patterns, ...(await parseAndResolve(nodePath.join(currentDir, GITIGNORE_FILE)))] : patterns;\n if (local) found.add(nodePath.join(currentDir, GITIGNORE_FILE));\n\n for (const ent of entries) {\n if (!ent.isDirectory()) continue;\n if (excludeDirs.has(ent.name)) continue;\n const subdir = nodePath.join(currentDir, ent.name);\n const rel = nodePath.relative(rootDir, subdir);\n if (isIgnored(combinedPatterns, rel)) continue;\n queue.push({ depth: depth + 1, dir: subdir, patterns: combinedPatterns });\n }\n }\n\n return [...found].map((p) => nodePath.relative(rootDir, p));\n}\n","import fs from 'node:fs';\nimport nodePath from 'node:path';\nimport process from 'node:process';\n\nimport { defaultIgnores } from './defaultIgnores.js';\nimport { gitModulesIgnore } from './internal/gitModulesIgnore.js';\nimport { ignoreFileFind } from './internal/ignoreFileFind.js';\nimport { ignoreFileParse } from './internal/ignoreFileParse.js';\nimport { ignoreRuleResolve } from './internal/ignoreRuleResolve.js';\n\nexport interface ESLintIgnoreConfig {\n /**\n * The file globs to ignore\n */\n ignores: Array<string>;\n\n /**\n * The configuration name\n */\n name: string;\n}\n\nexport interface ESLintIgnoreOptions {\n /**\n * Override current working directory\n */\n cwd?: string;\n\n /**\n * Whether to ignore git submodules (default: true)\n */\n ignoreGitModules?: boolean;\n\n /**\n * Override or customize ignore patterns.\n * - If passed an array, it appends patterns to the merged ignore list.\n * - If passed a function, it receives the merged list and returns the final array.\n */\n ignores?: ((ignores: ESLintIgnoreConfig['ignores']) => ESLintIgnoreConfig['ignores']) | ESLintIgnoreConfig['ignores'];\n\n /**\n * Override the namespace used in the configuration name (default: 'w5s')\n *\n * @example\n * ```ts\n * await eslintIgnores({ namespace: 'custom-name' });// { name: 'custom-name/eslint-ignore', ignores: [...] }\n * ```\n */\n namespace?: string | undefined;\n\n /**\n * Include recommended settings and default ignored files\n */\n recommended?: boolean | undefined;\n}\n\n/**\n * Create a new eslint configuration object\n *\n * @example\n * ```ts\n * // eslint.config.js\n * export default [\n * await eslintIgnores({\n * ignores: [\n * // Add custom paths here\n * ],\n * // namespace: 'custom-name', // Optional namespace override\n * })\n * ];\n * ```\n *\n * @param options\n */\nexport async function eslintIgnores(options: ESLintIgnoreOptions = {}): Promise<ESLintIgnoreConfig> {\n const cwd = options.cwd ?? process.cwd();\n const namespace = options.namespace ?? 'w5s';\n const recommended = options.recommended ?? true;\n const ignoreFilePaths = await ignoreFileFind(cwd);\n const ignoreGlobs = (await Promise.all(ignoreFilePaths.map(async (ignoreFilePathRelative) => {\n const ignoreFilePath = nodePath.join(cwd, ignoreFilePathRelative);\n const ignoreFileContent = String(await fs.promises.readFile(ignoreFilePath));\n const patterns = ignoreFileParse(ignoreFileContent);\n const ignoreDirectoryRelative = nodePath.dirname(ignoreFilePathRelative);\n\n return patterns.map((pattern) => ignoreRuleResolve(ignoreDirectoryRelative, pattern));\n })));\n\n const mergedIgnores = [\n ...(recommended ? defaultIgnores : []),\n ...ignoreGlobs.flat(),\n ];\n\n // Optionally include .gitmodules entries as ignores (each submodule path -> `${path}/**`)\n if (options.ignoreGitModules ?? true) {\n mergedIgnores.push(...await gitModulesIgnore(cwd));\n }\n\n const ignores = typeof options.ignores === 'function'\n ? options.ignores(mergedIgnores)\n : options.ignores\n ? [...mergedIgnores, ...options.ignores]\n : mergedIgnores;\n\n return {\n ignores,\n name: `${namespace}/eslint-ignore`,\n };\n}\n","export const meta = Object.freeze({\n // @ts-ignore - these variables are injected at build time\n buildNumber: (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\n // @ts-ignore - these variables are injected at build time\n name: (typeof __PACKAGE_NAME__ === 'undefined' ? '' : __PACKAGE_NAME__) as string,\n // @ts-ignore - these variables are injected at build time\n version: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,\n});\n"],"mappings":";;;;;;;AAAA,MAAa,iBAAiB;CAE5B;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CAGA;CAGA;CACA;CACA;CACA;AACF;;AC5CA,MAAM,oBAAoB;;;;;;;;;;;;AAa1B,eAAsB,iBAAiB,KAAqC;CAC1E,MAAM,SAAS,SAAS,KAAK,KAAK,aAAa;CAC/C,IAAI;EACF,IAAI,OAAO;EACX,IAAI;GACF,OAAO,MAAM,GAAG,SAAS,KAAK,MAAM;EACtC,QAAQ;GACN,OAAO;EACT;EACA,IAAI,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;EAI7B,OADc,gBAAgB,MADP,GAAG,SAAS,SAAS,QAAQ,MAAM,CAE/C,CAAC,CAAC,KAAK,MAAM,GAAG,EAAE,WAAW,MAAM,GAAG,EAAE,IAAI;CACzD,QAAQ;EACN,OAAO,CAAC;CACV;AACF;;;;;;;;;;;AAYA,SAAgB,gBAAgB,SAAgC;CAC9D,MAAM,QAAuB,CAAC;CAC9B,kBAAkB,YAAY;CAC9B,SAAS;EACP,MAAM,UAAU,kBAAkB,KAAK,OAAO;EAC9C,IAAI,CAAC,SAAS;EACd,MAAM,WAAW,QAAQ;EACzB,IAAI,UAAU,MAAM,KAAK,SAAS,KAAK,CAAC;CAC1C;CACA,OAAO;AACT;;ACrDA,SAAgB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MAAM,0BAA0B,SAAS,QAAQ,sBAAsB;EAEvE,OAAO,SAAS,KAAK,YAAY,kBAAkB,yBAAyB,OAAO,CAAC;CACtF,CAAC,CAAC;CAEF,MAAM,gBAAgB,CACpB,GAAI,cAAc,iBAAiB,CAAC,GACpC,GAAG,YAAY,KAAK,CACtB;CAGA,IAAI,QAAQ,oBAAoB,MAC9B,cAAc,KAAK,GAAG,MAAM,iBAAiB,GAAG,CAAC;CASnD,OAAO;EACL,SAPc,OAAO,QAAQ,YAAY,aACvC,QAAQ,QAAQ,aAAa,IAC7B,QAAQ,UACN,CAAC,GAAG,eAAe,GAAG,QAAQ,OAAO,IACrC;EAIJ,MAAM,GAAG,UAAU;CACrB;AACF;;AC5GA,MAAa,OAAO,OAAO,OAAO;CAEhC,aAAA;CAEA,MAAA;CAEA,SAAA;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w5s/eslint-config-ignore",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.34.1",
|
|
4
4
|
"description": "Shared ESLint ignore configuration generator",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"find-up": "^8.0.0",
|
|
41
|
-
"minimatch": "^
|
|
41
|
+
"minimatch": "^11.0.0",
|
|
42
42
|
"parse-gitignore": "^2.0.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "8c839f967fbc4477af3e767c4ecfa2d8a693eda0"
|
|
63
63
|
}
|
|
@@ -82,7 +82,7 @@ export async function ignoreFileFind(
|
|
|
82
82
|
|
|
83
83
|
function isIgnored(patterns: Array<string>, candidateRel: string): boolean {
|
|
84
84
|
const m = lastMatchWins(patterns, candidateRel);
|
|
85
|
-
return m
|
|
85
|
+
return m !== null && !m.startsWith('!');
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
async function collectAncestorGitignores(startDir: string): Promise<Array<string>> {
|