mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
fs: expose glob and globSync
PR-URL: https://github.com/nodejs/node/pull/51912 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Nitzan Uziely <linkgoron@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
parent
2a33e95093
commit
151d365ad1
6 changed files with 443 additions and 34 deletions
36
lib/fs.js
36
lib/fs.js
|
@ -86,6 +86,8 @@ const {
|
|||
const { toPathIfFileURL } = require('internal/url');
|
||||
const {
|
||||
customPromisifyArgs: kCustomPromisifyArgsSymbol,
|
||||
emitExperimentalWarning,
|
||||
getLazy,
|
||||
kEmptyObject,
|
||||
promisify: {
|
||||
custom: kCustomPromisifiedSymbol,
|
||||
|
@ -3102,6 +3104,38 @@ function createWriteStream(path, options) {
|
|||
return new WriteStream(path, options);
|
||||
}
|
||||
|
||||
const lazyGlob = getLazy(() => require('internal/fs/glob').Glob);
|
||||
|
||||
function glob(pattern, options, callback) {
|
||||
emitExperimentalWarning('glob');
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = undefined;
|
||||
}
|
||||
callback = makeCallback(callback);
|
||||
|
||||
const Glob = lazyGlob();
|
||||
// TODO: Use iterator helpers when available
|
||||
(async () => {
|
||||
try {
|
||||
const res = [];
|
||||
for await (const entry of new Glob(pattern, options).glob()) {
|
||||
ArrayPrototypePush(res, entry);
|
||||
}
|
||||
callback(null, res);
|
||||
} catch (err) {
|
||||
callback(err);
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
function globSync(pattern, options) {
|
||||
emitExperimentalWarning('globSync');
|
||||
const Glob = lazyGlob();
|
||||
return new Glob(pattern, options).globSync();
|
||||
}
|
||||
|
||||
|
||||
module.exports = fs = {
|
||||
appendFile,
|
||||
appendFileSync,
|
||||
|
@ -3135,6 +3169,8 @@ module.exports = fs = {
|
|||
ftruncateSync,
|
||||
futimes,
|
||||
futimesSync,
|
||||
glob,
|
||||
globSync,
|
||||
lchown,
|
||||
lchownSync,
|
||||
lchmod: constants.O_SYMLINK !== undefined ? lchmod : undefined,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue