diff --git a/dist/index.js b/dist/index.js index 52e02aa..4fe2c62 100644 --- a/dist/index.js +++ b/dist/index.js @@ -46985,7 +46985,9 @@ class AST { if (this.#root === this) this.#fillNegs(); if (!this.type) { - const noEmpty = this.isStart() && this.isEnd(); + const noEmpty = this.isStart() && + this.isEnd() && + !this.#parts.some(s => typeof s !== 'string'); const src = this.#parts .map(p => { const [re, _, hasMagic, uflag] = typeof p === 'string' @@ -47141,10 +47143,7 @@ class AST { } } if (c === '*') { - if (noEmpty && glob === '*') - re += starNoEmpty; - else - re += star; + re += noEmpty && glob === '*' ? starNoEmpty : star; hasMagic = true; continue; } @@ -47332,16 +47331,24 @@ exports.escape = void 0; /** * Escape all magic characters in a glob pattern. * - * If the {@link windowsPathsNoEscape | GlobOptions.windowsPathsNoEscape} + * If the {@link MinimatchOptions.windowsPathsNoEscape} * option is used, then characters are escaped by wrapping in `[]`, because * a magic character wrapped in a character class can only be satisfied by * that exact character. In this mode, `\` is _not_ escaped, because it is * not interpreted as a magic character, but instead as a path separator. + * + * If the {@link MinimatchOptions.magicalBraces} option is used, + * then braces (`{` and `}`) will be escaped. */ -const escape = (s, { windowsPathsNoEscape = false, } = {}) => { +const escape = (s, { windowsPathsNoEscape = false, magicalBraces = false, } = {}) => { // don't need to escape +@! because we escape the parens // that make those magic, and escaping ! as [!] isn't valid, // because [!]] is a valid glob class meaning not ']'. + if (magicalBraces) { + return windowsPathsNoEscape + ? s.replace(/[?*()[\]{}]/g, '[$&]') + : s.replace(/[?*()[\]\\{}]/g, '\\$&'); + } return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, '[$&]') : s.replace(/[?*()[\]\\]/g, '\\$&'); @@ -47997,7 +48004,7 @@ class Minimatch { } } // resolve and reduce . and .. portions in the file as well. - // dont' need to do the second phase, because it's only one string[] + // don't need to do the second phase, because it's only one string[] const { optimizationLevel = 1 } = this.options; if (optimizationLevel >= 2) { file = this.levelTwoFileOptimize(file); @@ -48250,14 +48257,25 @@ class Minimatch { } } else if (next === undefined) { - pp[i - 1] = prev + '(?:\\/|' + twoStar + ')?'; + pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + ')?'; } else if (next !== exports.GLOBSTAR) { pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + '\\/)' + next; pp[i + 1] = exports.GLOBSTAR; } }); - return pp.filter(p => p !== exports.GLOBSTAR).join('/'); + const filtered = pp.filter(p => p !== exports.GLOBSTAR); + // For partial matches, we need to make the pattern match + // any prefix of the full path. We do this by generating + // alternative patterns that match progressively longer prefixes. + if (this.partial && filtered.length >= 1) { + const prefixes = []; + for (let i = 1; i <= filtered.length; i++) { + prefixes.push(filtered.slice(0, i).join('/')); + } + return '(?:' + prefixes.join('|') + ')'; + } + return filtered.join('/'); }) .join('|'); // need to wrap in parens if we had more than one thing with |, @@ -48266,6 +48284,10 @@ class Minimatch { // must match entire pattern // ending in a * or ** will make it less strict. re = '^' + open + re + close + '$'; + // In partial mode, '/' should always match as it's a valid prefix for any pattern + if (this.partial) { + re = '^(?:\\/|' + open + re.slice(1, -1) + close + ')$'; + } // can match anything, as long as it's not this. if (this.negate) re = '^(?!' + re + ').+$'; @@ -48382,21 +48404,35 @@ exports.unescape = void 0; /** * Un-escape a string that has been escaped with {@link escape}. * - * If the {@link windowsPathsNoEscape} option is used, then square-brace - * escapes are removed, but not backslash escapes. For example, it will turn - * the string `'[*]'` into `*`, but it will not turn `'\\*'` into `'*'`, - * becuase `\` is a path separator in `windowsPathsNoEscape` mode. + * If the {@link MinimatchOptions.windowsPathsNoEscape} option is used, then + * square-bracket escapes are removed, but not backslash escapes. * - * When `windowsPathsNoEscape` is not set, then both brace escapes and + * For example, it will turn the string `'[*]'` into `*`, but it will not + * turn `'\\*'` into `'*'`, because `\` is a path separator in + * `windowsPathsNoEscape` mode. + * + * When `windowsPathsNoEscape` is not set, then both square-bracket escapes and * backslash escapes are removed. * * Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot be escaped * or unescaped. + * + * When `magicalBraces` is not set, escapes of braces (`{` and `}`) will not be + * unescaped. */ -const unescape = (s, { windowsPathsNoEscape = false, } = {}) => { +const unescape = (s, { windowsPathsNoEscape = false, magicalBraces = true, } = {}) => { + if (magicalBraces) { + return windowsPathsNoEscape + ? s.replace(/\[([^\/\\])\]/g, '$1') + : s + .replace(/((?!\\).|^)\[([^\/\\])\]/g, '$1$2') + .replace(/\\([^\/])/g, '$1'); + } return windowsPathsNoEscape - ? s.replace(/\[([^\/\\])\]/g, '$1') - : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, '$1$2').replace(/\\([^\/])/g, '$1'); + ? s.replace(/\[([^\/\\{}])\]/g, '$1') + : s + .replace(/((?!\\).|^)\[([^\/\\{}])\]/g, '$1$2') + .replace(/\\([^\/{}])/g, '$1'); }; exports.unescape = unescape; //# sourceMappingURL=unescape.js.map diff --git a/package-lock.json b/package-lock.json index 30b56e6..f7ea104 100644 --- a/package-lock.json +++ b/package-lock.json @@ -424,14 +424,14 @@ } }, "node_modules/glob": { - "version": "11.0.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-11.0.3.tgz", - "integrity": "sha512-2Nim7dha1KVkaiF4q6Dj+ngPPMdfvLJEOpZk/jKiUAkqKebpGAWQXAq9z1xu9HKu5lWfqw/FASuccEjyznjPaA==", - "license": "ISC", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-11.1.0.tgz", + "integrity": "sha512-vuNwKSaKiqm7g0THUBu2x7ckSs3XJLXE+2ssL7/MfTGPLLcrJQ/4Uq1CjPTtO5cCIiRxqvN6Twy1qOwhL0Xjcw==", + "license": "BlueOak-1.0.0", "dependencies": { "foreground-child": "^3.3.1", "jackspeak": "^4.1.1", - "minimatch": "^10.0.3", + "minimatch": "^10.1.1", "minipass": "^7.1.2", "package-json-from-dist": "^1.0.0", "path-scurry": "^2.0.0" @@ -579,10 +579,10 @@ } }, "node_modules/minimatch": { - "version": "10.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.3.tgz", - "integrity": "sha512-IPZ167aShDZZUMdRk66cyQAW3qr0WzbHkPdMYa8bzZhlHhO3jALbKdxcaak7W9FfT2rZNpQuUu4Od7ILEpXSaw==", - "license": "ISC", + "version": "10.1.1", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.1.1.tgz", + "integrity": "sha512-enIvLvRAFZYXJzkCYG5RKmPfrFArdLv+R+lbQ53BmIMLIry74bjKzX6iHAm8WYamJkhSSEabrWN5D97XnKObjQ==", + "license": "BlueOak-1.0.0", "dependencies": { "@isaacs/brace-expansion": "^5.0.0" },