Skip to content

Commit

Permalink
chore: update dependency minimatch to v9 (#167)
Browse files Browse the repository at this point in the history
* chore: update dependency minimatch to v9

* fix: add "allowWindowsEscape" to Minimatch options

* fix: Convert all patterns to posix from win32 in Minimatch

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Sebastian Good <2230835+scagood@users.noreply.github.com>
  • Loading branch information
renovate[bot] and scagood committed Jan 22, 2024
1 parent fc77da2 commit 5ad657c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lib/util/check-restricted.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ class Restriction {
const negate = raw[0] === "!" && raw[1] !== "("
const pattern = negate ? raw.slice(1) : raw
const absolute = path.isAbsolute(pattern)
const matcher = new Minimatch(pattern, { dot: true })

const posix = pattern.replace(/\\/g, "/")
const matcher = new Minimatch(posix, {
allowWindowsEscape: true,
dot: true,
})
return { absolute, matcher, negate }
})

Expand Down
17 changes: 14 additions & 3 deletions lib/util/get-convert-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
"use strict"

const Minimatch = require("minimatch").Minimatch
const { Minimatch } = require("minimatch")

/**
* @param {any} x - An any value.
Expand Down Expand Up @@ -45,6 +45,17 @@ function toStringArray(x) {
return []
}

/**
* @param {string} pattern
* @return {Minimatch}
*/
function makeMatcher(pattern) {
const posix = pattern.replace(/\\/g, "/")
return new Minimatch(posix, {
allowWindowsEscape: true,
})
}

/**
* Creates the function which checks whether a file path is matched with the given pattern or not.
*
Expand All @@ -53,8 +64,8 @@ function toStringArray(x) {
* @returns {function} Created predicate function.
*/
function createMatch(includePatterns, excludePatterns) {
const include = includePatterns.map(pattern => new Minimatch(pattern))
const exclude = excludePatterns.map(pattern => new Minimatch(pattern))
const include = includePatterns.map(makeMatcher)
const exclude = excludePatterns.map(makeMatcher)

return filePath =>
include.some(m => m.match(filePath)) &&
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"ignore": "^5.2.4",
"is-builtin-module": "^3.2.1",
"is-core-module": "^2.12.1",
"minimatch": "^3.1.2",
"minimatch": "^9.0.0",
"semver": "^7.5.3"
},
"devDependencies": {
Expand Down

0 comments on commit 5ad657c

Please sign in to comment.