-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace use of recursive-readdir package with local implementation (#…
…4537) * remove and reimplement recursive-readdir package * remove minimatch dependency * don't add unused package to browser approved package list * rush change * change var to const/let and remove unecessary comments * remove unnecessary comment * rename readdir export * fix function import Co-authored-by: Matthew Jordan <14913576+mattbjordan@users.noreply.github.com> Co-authored-by: Paul Connelly <22944042+pmconne@users.noreply.github.com>
- Loading branch information
1 parent
75240c8
commit 7ca2709
Showing
6 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/changes/@itwin/build-tools/fix-minimatch-dependency-version_2022-10-24-15-27.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@itwin/build-tools", | ||
"comment": "Replace use of recursive-readdir package with local implementation", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@itwin/build-tools" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
const fs = require("fs"); | ||
const p = require("path"); | ||
|
||
function matchesFile(ignorePath) { | ||
return function (path, stats) { | ||
return stats.isFile() && ignorePath === path; | ||
}; | ||
} | ||
|
||
function toMatcherFunction(ignoreEntry) { | ||
if (typeof ignoreEntry == "function") { | ||
return ignoreEntry; | ||
} else { | ||
return matchesFile(ignoreEntry); | ||
} | ||
} | ||
|
||
function readdir(path, ignores, callback) { | ||
if (typeof ignores == "function") { | ||
callback = ignores; | ||
ignores = []; | ||
} | ||
|
||
if (!callback) { | ||
return new Promise(function (resolve, reject) { | ||
readdir(path, ignores || [], function (err, data) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(data); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
ignores = ignores.map(toMatcherFunction); | ||
|
||
let list = []; | ||
|
||
fs.readdir(path, function (err, files) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
|
||
let pending = files.length; | ||
if (!pending) { | ||
// we are done | ||
return callback(null, list); | ||
} | ||
|
||
files.forEach(function (file) { | ||
const filePath = p.join(path, file); | ||
fs.stat(filePath, function (_err, stats) { | ||
if (_err) { | ||
return callback(_err); | ||
} | ||
|
||
if ( | ||
ignores.some(function (matcher) { | ||
return matcher(filePath, stats); | ||
}) | ||
) { | ||
pending -= 1; | ||
if (!pending) { | ||
return callback(null, list); | ||
} | ||
return null; | ||
} | ||
|
||
if (stats.isDirectory()) { | ||
readdir(filePath, ignores, function (__err, res) { | ||
if (__err) { | ||
return callback(__err); | ||
} | ||
|
||
list = list.concat(res); | ||
pending -= 1; | ||
if (!pending) { | ||
return callback(null, list); | ||
} | ||
}); | ||
} else { | ||
list.push(filePath); | ||
pending -= 1; | ||
if (!pending) { | ||
return callback(null, list); | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
readDirectory: readdir | ||
}; |