Skip to content

Commit

Permalink
Update to the latest glob
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Oct 23, 2023
1 parent 192271d commit f201757
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
25 changes: 21 additions & 4 deletions lib/utils/apply-action-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
// Requirements
// ------------------------------------------------------------------------------

const glob = require('glob-gitignore')
const { globSync } = require('glob')
const ignore = require('ignore')

// ------------------------------------------------------------------------------
// Exports
Expand All @@ -28,14 +29,30 @@ const glob = require('glob-gitignore')
* @private
*/
module.exports = function applyActionSync (pattern, options, action) {
const ig = ignore().add(options.ignore ?? [])
ig.add(options.ignore ?? [])
const globOptions = {
nodir: !options.includeEmptyDirs,
silent: true,
follow: Boolean(options.dereference),
ignore: options.ignore
ignore: {
ignored: p => {
try {
return p.relative() ? ig.ignores(p.relative()) : false
} catch (err) {
console.error(err)
}
},
childrenIgnored: (p) => {
try {
return p.relative() ? ig.ignores(p.relative()) : false
} catch (err) {
console.error(err)
}
}
}
}
const results = []
for (const sourcePath of glob.sync(pattern, globOptions)) {
for (const sourcePath of globSync(pattern, globOptions)) {
const result = action(sourcePath)
results.push(result)
}
Expand Down
26 changes: 21 additions & 5 deletions lib/utils/apply-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
// Requirements
// ------------------------------------------------------------------------------

const glob = require('glob-gitignore')
const { glob } = require('glob')
const ignore = require('ignore')
const pMapPromise = import('p-map')

// ------------------------------------------------------------------------------
Expand All @@ -29,14 +30,29 @@ const pMapPromise = import('p-map')
* @private
*/
module.exports = async function applyAction (pattern, options, action) {
const ig = ignore().add(options.ignore ?? [])
ig.add(options.ignore ?? [])
const globOptions = {
nodir: !options.includeEmptyDirs,
silent: true,
follow: Boolean(options.dereference),
nosort: true,
ignore: options.ignore
ignore: {
ignored: (p) => {
try {
return p.relative() ? ig.ignores(p.relative()) : false
} catch (err) {
console.error(err)
}
},
childrenIgnored: (p) => {
try {
return p.relative() ? ig.ignores(p.relative()) : false
} catch (err) {
console.error(err)
}
}
}
}
const sourcePaths = await glob.glob(pattern, globOptions)
const sourcePaths = await glob(pattern, globOptions)
const pMap = (await pMapPromise).default
return pMap(sourcePaths, action, { concurrency: 5 })
}
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"clean": "rm -rf .nyc_output coverage test-ws",
"coverage": "nyc report -r lcov && opener coverage/lcov-report/index.html",
"lint": "standard",
"pretest": "npm run -s lint",
"test": "nyc --require @babel/register npm run -s _mocha",
"watch": "npm run -s _mocha -- --require @babel/register --watch --growl"
},
Expand All @@ -29,9 +28,9 @@
"debug": "^4.1.1",
"duplexer": "^0.1.1",
"fs-extra": "^11.1.0",
"glob-gitignore": "^1.0.14",
"glob": "^10.3.10",
"glob2base": "0.0.12",
"ignore": "^5.1.8",
"ignore": "^5.2.4",
"minimatch": "^9.0.0",
"p-map": "^6.0.0",
"resolve": "^1.12.0",
Expand Down

0 comments on commit f201757

Please sign in to comment.