From 063f1a75a45b36e17163d5785d83df2fd433e918 Mon Sep 17 00:00:00 2001 From: David Anson Date: Sun, 25 Oct 2026 22:55:25 +0000 Subject: [PATCH] Freshen generated package-lock.json file, freshen generated index.js file. --- dist/index.mjs | 108 ++++++++++++++++++++++++---------------------- package-lock.json | 36 ++++++++-------- 2 files changed, 74 insertions(+), 70 deletions(-) diff --git a/dist/index.mjs b/dist/index.mjs index 753d71d..d581492 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -3530,6 +3530,8 @@ const ESCAPE = '\\' const REGEX_LITERAL_SPECIAL = /[.*+?()[\]{}^$|\\/]/ const BOM = '\uFEFF' const REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/ +// A run of two or more asterisks is a globstar (#175) +const REGEX_ANCHORED_GLOBSTAR = /^\/\*{2,}$/ const REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/ const REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/ const REGEX_SPLITALL_CRLF = /\r?\n/g @@ -3938,6 +3940,21 @@ const REPLACERS = [ ESCAPE + SPACE ], + // git's wildmatch() reads a run of two or more asterisks as one globstar + // whenever the run fills a path segment: it starts the pattern or follows + // a `/`, and it ends the pattern or comes before a `/`. A run of two is + // already `**`; a longer one is folded into `**` here, so the steps + // below only ever have to know `**`. + // `***/foo` -> `**/foo`, `a/***/b` -> `a/**/b`, `a/***` -> `a/**` + // git also takes a run beside a literal prefix (`a***/b`) or beside an + // escaped slash (`***\/b`) as a globstar, and this does not; the README + // lists both, under "A run of asterisks". + [ + /(^|\/)\*{3,}(?=\/|$)/g, + (_, start) => `${start}**`, + '*' + ], + // Escape metacharacters // which is written down by users but means special for regular expressions. @@ -4368,6 +4385,15 @@ const pinWildcards = source => { // @param {pattern} const makeRegexPrefix = pattern => { + // `/**` matches every path, as `**` does. The translation below only finds + // a globstar beside a slash it keeps, and the leading one is turned into + // an anchor, so `/**` would come out as `/*` and match one level only. + // Here rather than in `createRule`, so that `checkSourceOf`, which + // compiles `/**/` again without its trailing slash, gets it too. + if (REGEX_ANCHORED_GLOBSTAR.test(pattern)) { + pattern = '**' + } + const {source, sources} = extractBrackets(pattern) const replaced = REPLACERS.reduce( @@ -4786,17 +4812,10 @@ class RuleManager { // Test one single path without recursively checking parent directories // - // - checkUnignored `boolean` whether should check if the path is unignored, - // setting `checkUnignored` to `false` could reduce additional - // path matching. - // - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE` - - // @returns {TestResult} true if a file is ignored - test (path, checkUnignored, mode) { - let ignored = false - let unignored = false - let matchedRule + // - mode `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE` + // @returns {TestResult} + test (path, mode) { // Most of a .gitignore is patterns with no slash in them, and running // those against the whole path makes the regular expression engine walk // every directory name on the way to the only segment that could match. @@ -4811,52 +4830,40 @@ class RuleManager { ? basenameOf(path) : path + // The last rule to match decides, as in git, and it is the rule + // `git check-ignore -v` reports, so the scan runs from the end and stops + // at the first match. // A plain loop rather than `forEach`, so that `path`, `basename` and // `shortcut` are locals. As a callback they became closure variables, // and reaching for one of those once per rule cost 10% of a scan over a // large rule set -- more than the shortcut they were there to serve. - for (let index = 0; index < length; index ++) { + for (let index = length - 1; index >= 0; index --) { const rule = rules[index] - const {negative} = rule - // | ignored : unignored - // -------- | --------------------------------------- - // negative | 0:0 | 0:1 | 1:0 | 1:1 - // -------- | ------- | ------- | ------- | -------- - // 0 | TEST | TEST | SKIP | X - // 1 | TESTIF | SKIP | TEST | X - - // - SKIP: always skip - // - TEST: always test - // - TESTIF: only test if checkUnignored - // - X: that never happen - const skip = unignored === negative && ignored !== unignored - || negative && !ignored && !unignored && !checkUnignored - - if (!skip && rule[mode].test( + if (rule[mode].test( shortcut && rule._basenameOnly ? basename : path )) { - ignored = !negative - unignored = negative + const {negative} = rule - matchedRule = negative - ? UNDEFINED - : rule + const ret = { + ignored: !negative, + unignored: negative + } + + if (!negative) { + ret.rule = rule + } + + return ret } } - const ret = { - ignored, - unignored + return { + ignored: false, + unignored: false } - - if (matchedRule) { - ret.rule = matchedRule - } - - return ret } } @@ -4972,7 +4979,7 @@ class Ignore { } // @returns {TestResult} - _test (originalPath, cache, checkUnignored) { + _test (originalPath, cache) { const path = originalPath // Supports nullable path && checkPath.convert(originalPath) @@ -4985,7 +4992,7 @@ class Ignore { : RETURN_FALSE ) - return this._t(path, cache, checkUnignored) + return this._t(path, cache) } checkIgnore (path) { @@ -4998,7 +5005,7 @@ class Ignore { // Like `git check-ignore`: a directory excluded by itself or by an // ancestor settles it, and only then is the literal 'abc/' matched // against the rules (see `checkSourceOf`). - const dir = this._t(path, this._testCache, true) + const dir = this._t(path, this._testCache) if (dir.ignored) { return dir @@ -5016,10 +5023,7 @@ class Ignore { path, // The cache for the result of a certain checking - cache, - - // Whether should check if the path is unignored - checkUnignored + cache ) { if (path in cache) { return cache[path] @@ -5029,18 +5033,18 @@ class Ignore { // If the path contains a parent directory, check the parent first const parent = parentPath - ? this._t(parentPath, cache, checkUnignored) + ? this._t(parentPath, cache) : UNDEFINED return cache[path] = parent && parent.ignored // > It is not possible to re-include a file if a parent directory of // > that file is excluded. ? parent - : this._rules.test(path, checkUnignored, MODE_IGNORE) + : this._rules.test(path, MODE_IGNORE) } ignores (path) { - return this._test(path, this._ignoreCache, false).ignored + return this._test(path, this._ignoreCache).ignored } createFilter () { @@ -5053,7 +5057,7 @@ class Ignore { // @returns {TestResult} test (path) { - return this._test(path, this._testCache, true) + return this._test(path, this._testCache) } } diff --git a/package-lock.json b/package-lock.json index bd7111b..c036936 100644 --- a/package-lock.json +++ b/package-lock.json @@ -535,9 +535,9 @@ } }, "node_modules/argparse": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-3.0.3.tgz", - "integrity": "sha512-Sn98ftV3KfsO8xfLPHG6oT8y+b0yvbrLgZjgPDXsharNY15tTAjqIsIju4S32nl6/iEUNNE4v+yL2Zhm8ooP3w==", + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-3.0.4.tgz", + "integrity": "sha512-fwWK3Zq22l4XJJjx5mcBHGikIk+hJqO+32dPm0Jur7+rtG5x1scOjSfdT9ZKeWHPpsya/l0HHK4tDImBkTrtvA==", "funding": [ { "type": "github", @@ -561,9 +561,9 @@ } }, "node_modules/baseline-browser-mapping": { - "version": "2.11.30", - "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.30.tgz", - "integrity": "sha512-YJs6Pz17RMNv8HoyKREtCY38E3BV1nPkWVmIb+XN1uHC1Vqt3KZCH/uJH9ZKRoiKb/icZ6tvehyee6RZNbFfRA==", + "version": "2.11.33", + "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.33.tgz", + "integrity": "sha512-yiVKDX+qCMRKBE084lXvq9EcwFUhKZ2nU8TK1EQQuOgPNR/lmbGxXOeDdlGUqC2Zz11Cs9rk1d/8NfgBmlkt0w==", "dev": true, "license": "Apache-2.0", "bin": { @@ -660,9 +660,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001817", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001817.tgz", - "integrity": "sha512-uZ1JG80BwhtMalIAGPxPfmNhHyd/B/nTdr3hITWlRamSyAdUStP1Gop01e7SD5q6J90ixJvWDbvmiFVfDgn4bw==", + "version": "1.0.30001819", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001819.tgz", + "integrity": "sha512-LFUqIIAwpzsIuevnKnsR9qnStBcgzPShTX61lBwN9uFkkf8o8zLiebEjbW8AYtZiF+1YKDWfdt/pWDtMuG8Xwg==", "dev": true, "funding": [ { @@ -847,9 +847,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.463", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.463.tgz", - "integrity": "sha512-nVWNU6ltFjopvOdD44J4zoBkgO0M+WZiFKKFV7EjebOH9z0KNphk6bCEjplXtJofL21ARIuuwWOCsFkBVklm6w==", + "version": "1.5.464", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.464.tgz", + "integrity": "sha512-nRa65aFge40viPAKxMKULIY8tcXKwKboJWNn4RoKwyWXJ6SP7BnrDGKUTzc64818jIciH0PK7LSF8QzZes19GA==", "dev": true, "license": "ISC" }, @@ -1449,9 +1449,9 @@ } }, "node_modules/globby/node_modules/ignore": { - "version": "7.0.13", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.13.tgz", - "integrity": "sha512-2E8Q6rh+1RRSq/YdaGsNfXsEZy9FVqv6BSSrkmZJP7BnaoPnRfKL+YaofPvP+5rzdk144qSm6i4+hvPgUcbV4Q==", + "version": "7.0.14", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.14.tgz", + "integrity": "sha512-wCBiZ77u1tuWde6G/nfOtLaCTYcFDU5yCzARzK10y+rLhzYoL7a7yEemcopcc2Mzow7gZOIjnV2ym1NYmdiJOQ==", "license": "MIT", "engines": { "node": ">= 4" @@ -2538,9 +2538,9 @@ "license": "MIT" }, "node_modules/node-releases": { - "version": "2.0.59", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.59.tgz", - "integrity": "sha512-5qr2okC4ItAI0hG5SaV0HoYMpnM/Y6+Oqr7AmPYy/2uEoGvS+GbSKLeRxSS1uAdu59yz0ouzcuXievSgg///WA==", + "version": "2.0.60", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.60.tgz", + "integrity": "sha512-OmO8+GM1JUZqXET720VrJCwkjUCXmCMQm0Z3UDDRbfNLHS4NEAvY60j5jiFv0tkKw2PNNlqOLhahVmwJIOLDIQ==", "dev": true, "license": "MIT", "engines": {