"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }); var rfs = require("fs"), require$$0 = require("constants"), require$$0$1 = require("stream"), require$$4 = require("util"), assert = require("assert"), path = require("path"), web = require("stream/web"), promises = require("stream/promises"), commonjsGlobal = "undefined" != typeof globalThis ? globalThis : "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : {}, constants = require$$0, origCwd = process.cwd, cwd = null, platform = process.env.GRACEFUL_FS_PLATFORM || process.platform; process.cwd = function () { return cwd || (cwd = origCwd.call(process)), cwd; }; try { process.cwd(); } catch (er) {} if ("function" == typeof process.chdir) { var chdir = process.chdir; process.chdir = function (d) { cwd = null, chdir.call(process, d); }, Object.setPrototypeOf && Object.setPrototypeOf(process.chdir, chdir); } var gracefulQueue, previousSymbol, Stream = require$$0$1.Stream, getPrototypeOf = Object.getPrototypeOf || function (obj) { return obj.__proto__; }, fs = rfs, polyfills = function (fs) { function chmodFix(orig) { return orig ? function (target, mode, cb) { return orig.call(fs, target, mode, function (er) { chownErOk(er) && (er = null), cb && cb.apply(this, arguments); }); } : orig; } function chmodFixSync(orig) { return orig ? function (target, mode) { try { return orig.call(fs, target, mode); } catch (er) { if (!chownErOk(er)) throw er; } } : orig; } function chownFix(orig) { return orig ? function (target, uid, gid, cb) { return orig.call(fs, target, uid, gid, function (er) { chownErOk(er) && (er = null), cb && cb.apply(this, arguments); }); } : orig; } function chownFixSync(orig) { return orig ? function (target, uid, gid) { try { return orig.call(fs, target, uid, gid); } catch (er) { if (!chownErOk(er)) throw er; } } : orig; } function statFix(orig) { return orig ? function (target, options, cb) { function callback(er, stats) { stats && (stats.uid < 0 && (stats.uid += 4294967296), stats.gid < 0 && (stats.gid += 4294967296)), cb && cb.apply(this, arguments); } return "function" == typeof options && (cb = options, options = null), options ? orig.call(fs, target, options, callback) : orig.call(fs, target, callback); } : orig; } function statFixSync(orig) { return orig ? function (target, options) { var stats = options ? orig.call(fs, target, options) : orig.call(fs, target); return stats && (stats.uid < 0 && (stats.uid += 4294967296), stats.gid < 0 && (stats.gid += 4294967296)), stats; } : orig; } function chownErOk(er) { return !er || "ENOSYS" === er.code || !(process.getuid && 0 === process.getuid() || "EINVAL" !== er.code && "EPERM" !== er.code); } var fs$readSync; constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./) && function (fs) { fs.lchmod = function (path, mode, callback) { fs.open(path, constants.O_WRONLY | constants.O_SYMLINK, mode, function (err, fd) { err ? callback && callback(err) : fs.fchmod(fd, mode, function (err) { fs.close(fd, function (err2) { callback && callback(err || err2); }); }); }); }, fs.lchmodSync = function (path, mode) { var ret, fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode), threw = !0; try { ret = fs.fchmodSync(fd, mode), threw = !1; } finally { if (threw) try { fs.closeSync(fd); } catch (er) {} else fs.closeSync(fd); } return ret; }; }(fs), fs.lutimes || function (fs) { constants.hasOwnProperty("O_SYMLINK") && fs.futimes ? (fs.lutimes = function (path, at, mt, cb) { fs.open(path, constants.O_SYMLINK, function (er, fd) { er ? cb && cb(er) : fs.futimes(fd, at, mt, function (er) { fs.close(fd, function (er2) { cb && cb(er || er2); }); }); }); }, fs.lutimesSync = function (path, at, mt) { var ret, fd = fs.openSync(path, constants.O_SYMLINK), threw = !0; try { ret = fs.futimesSync(fd, at, mt), threw = !1; } finally { if (threw) try { fs.closeSync(fd); } catch (er) {} else fs.closeSync(fd); } return ret; }) : fs.futimes && (fs.lutimes = function (_a, _b, _c, cb) { cb && process.nextTick(cb); }, fs.lutimesSync = function () {}); }(fs), fs.chown = chownFix(fs.chown), fs.fchown = chownFix(fs.fchown), fs.lchown = chownFix(fs.lchown), fs.chmod = chmodFix(fs.chmod), fs.fchmod = chmodFix(fs.fchmod), fs.lchmod = chmodFix(fs.lchmod), fs.chownSync = chownFixSync(fs.chownSync), fs.fchownSync = chownFixSync(fs.fchownSync), fs.lchownSync = chownFixSync(fs.lchownSync), fs.chmodSync = chmodFixSync(fs.chmodSync), fs.fchmodSync = chmodFixSync(fs.fchmodSync), fs.lchmodSync = chmodFixSync(fs.lchmodSync), fs.stat = statFix(fs.stat), fs.fstat = statFix(fs.fstat), fs.lstat = statFix(fs.lstat), fs.statSync = statFixSync(fs.statSync), fs.fstatSync = statFixSync(fs.fstatSync), fs.lstatSync = statFixSync(fs.lstatSync), fs.chmod && !fs.lchmod && (fs.lchmod = function (path, mode, cb) { cb && process.nextTick(cb); }, fs.lchmodSync = function () {}), fs.chown && !fs.lchown && (fs.lchown = function (path, uid, gid, cb) { cb && process.nextTick(cb); }, fs.lchownSync = function () {}), "win32" === platform && (fs.rename = "function" != typeof fs.rename ? fs.rename : function (fs$rename) { function rename(from, to, cb) { var start = Date.now(), backoff = 0; fs$rename(from, to, function CB(er) { if (er && ("EACCES" === er.code || "EPERM" === er.code || "EBUSY" === er.code) && Date.now() - start < 6e4) return setTimeout(function () { fs.stat(to, function (stater, st) { stater && "ENOENT" === stater.code ? fs$rename(from, to, CB) : cb(er); }); }, backoff), void (backoff < 100 && (backoff += 10)); cb && cb(er); }); } return Object.setPrototypeOf && Object.setPrototypeOf(rename, fs$rename), rename; }(fs.rename)), fs.read = "function" != typeof fs.read ? fs.read : function (fs$read) { function read(fd, buffer, offset, length, position, callback_) { var callback; if (callback_ && "function" == typeof callback_) { var eagCounter = 0; callback = function (er, _, __) { if (er && "EAGAIN" === er.code && eagCounter < 10) return eagCounter++, fs$read.call(fs, fd, buffer, offset, length, position, callback); callback_.apply(this, arguments); }; } return fs$read.call(fs, fd, buffer, offset, length, position, callback); } return Object.setPrototypeOf && Object.setPrototypeOf(read, fs$read), read; }(fs.read), fs.readSync = "function" != typeof fs.readSync ? fs.readSync : (fs$readSync = fs.readSync, function (fd, buffer, offset, length, position) { for (var eagCounter = 0;;) try { return fs$readSync.call(fs, fd, buffer, offset, length, position); } catch (er) { if ("EAGAIN" === er.code && eagCounter < 10) { eagCounter++; continue; } throw er; } }); }, legacy = function (fs) { return { ReadStream: function ReadStream(path, options) { if (!(this instanceof ReadStream)) return new ReadStream(path, options); Stream.call(this); var self = this; this.path = path, this.fd = null, this.readable = !0, this.paused = !1, this.flags = "r", this.mode = 438, this.bufferSize = 65536, options = options || {}; for (var keys = Object.keys(options), index = 0, length = keys.length; index < length; index++) { var key = keys[index]; this[key] = options[key]; } if (this.encoding && this.setEncoding(this.encoding), void 0 !== this.start) { if ("number" != typeof this.start) throw TypeError("start must be a Number"); if (void 0 === this.end) this.end = Infinity;else if ("number" != typeof this.end) throw TypeError("end must be a Number"); if (this.start > this.end) throw new Error("start must be <= end"); this.pos = this.start; } null === this.fd ? fs.open(this.path, this.flags, this.mode, function (err, fd) { if (err) return self.emit("error", err), void (self.readable = !1); self.fd = fd, self.emit("open", fd), self._read(); }) : process.nextTick(function () { self._read(); }); }, WriteStream: function WriteStream(path, options) { if (!(this instanceof WriteStream)) return new WriteStream(path, options); Stream.call(this), this.path = path, this.fd = null, this.writable = !0, this.flags = "w", this.encoding = "binary", this.mode = 438, this.bytesWritten = 0, options = options || {}; for (var keys = Object.keys(options), index = 0, length = keys.length; index < length; index++) { var key = keys[index]; this[key] = options[key]; } if (void 0 !== this.start) { if ("number" != typeof this.start) throw TypeError("start must be a Number"); if (this.start < 0) throw new Error("start must be >= zero"); this.pos = this.start; } this.busy = !1, this._queue = [], null === this.fd && (this._open = fs.open, this._queue.push([this._open, this.path, this.flags, this.mode, void 0]), this.flush()); } }; }, util = require$$4; function publishQueue(context, queue) { Object.defineProperty(context, gracefulQueue, { get: function () { return queue; } }); } "function" == typeof Symbol && "function" == typeof Symbol.for ? (gracefulQueue = Symbol.for("graceful-fs.queue"), previousSymbol = Symbol.for("graceful-fs.previous")) : (gracefulQueue = "___graceful-fs.queue", previousSymbol = "___graceful-fs.previous"); var debug = function () {}; if (util.debuglog ? debug = util.debuglog("gfs4") : /\bgfs4\b/i.test(process.env.NODE_DEBUG || "") && (debug = function () { var m = util.format.apply(util, arguments); m = "GFS4: " + m.split(/\n/).join("\nGFS4: "), console.error(m); }), !fs[gracefulQueue]) { var queue = commonjsGlobal[gracefulQueue] || []; publishQueue(fs, queue), fs.close = function (fs$close) { function close(fd, cb) { return fs$close.call(fs, fd, function (err) { err || resetQueue(), "function" == typeof cb && cb.apply(this, arguments); }); } return Object.defineProperty(close, previousSymbol, { value: fs$close }), close; }(fs.close), fs.closeSync = function (fs$closeSync) { function closeSync(fd) { fs$closeSync.apply(fs, arguments), resetQueue(); } return Object.defineProperty(closeSync, previousSymbol, { value: fs$closeSync }), closeSync; }(fs.closeSync), /\bgfs4\b/i.test(process.env.NODE_DEBUG || "") && process.on("exit", function () { debug(fs[gracefulQueue]), assert.equal(fs[gracefulQueue].length, 0); }); } commonjsGlobal[gracefulQueue] || publishQueue(commonjsGlobal, fs[gracefulQueue]); var retryTimer, gracefulFs = patch(function (obj) { if (null === obj || "object" != typeof obj) return obj; if (obj instanceof Object) var copy = { __proto__: getPrototypeOf(obj) };else copy = Object.create(null); return Object.getOwnPropertyNames(obj).forEach(function (key) { Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key)); }), copy; }(fs)); function patch(fs) { polyfills(fs), fs.gracefulify = patch, fs.createReadStream = function (path, options) { return new fs.ReadStream(path, options); }, fs.createWriteStream = function (path, options) { return new fs.WriteStream(path, options); }; var fs$readFile = fs.readFile; fs.readFile = function (path, options, cb) { return "function" == typeof options && (cb = options, options = null), function go$readFile(path, options, cb, startTime) { return fs$readFile(path, options, function (err) { !err || "EMFILE" !== err.code && "ENFILE" !== err.code ? "function" == typeof cb && cb.apply(this, arguments) : enqueue([go$readFile, [path, options, cb], err, startTime || Date.now(), Date.now()]); }); }(path, options, cb); }; var fs$writeFile = fs.writeFile; fs.writeFile = function (path, data, options, cb) { return "function" == typeof options && (cb = options, options = null), function go$writeFile(path, data, options, cb, startTime) { return fs$writeFile(path, data, options, function (err) { !err || "EMFILE" !== err.code && "ENFILE" !== err.code ? "function" == typeof cb && cb.apply(this, arguments) : enqueue([go$writeFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()]); }); }(path, data, options, cb); }; var fs$appendFile = fs.appendFile; fs$appendFile && (fs.appendFile = function (path, data, options, cb) { return "function" == typeof options && (cb = options, options = null), function go$appendFile(path, data, options, cb, startTime) { return fs$appendFile(path, data, options, function (err) { !err || "EMFILE" !== err.code && "ENFILE" !== err.code ? "function" == typeof cb && cb.apply(this, arguments) : enqueue([go$appendFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()]); }); }(path, data, options, cb); }); var fs$copyFile = fs.copyFile; fs$copyFile && (fs.copyFile = function (src, dest, flags, cb) { return "function" == typeof flags && (cb = flags, flags = 0), function go$copyFile(src, dest, flags, cb, startTime) { return fs$copyFile(src, dest, flags, function (err) { !err || "EMFILE" !== err.code && "ENFILE" !== err.code ? "function" == typeof cb && cb.apply(this, arguments) : enqueue([go$copyFile, [src, dest, flags, cb], err, startTime || Date.now(), Date.now()]); }); }(src, dest, flags, cb); }); var fs$readdir = fs.readdir; fs.readdir = function (path, options, cb) { "function" == typeof options && (cb = options, options = null); var go$readdir = noReaddirOptionVersions.test(process.version) ? function (path, options, cb, startTime) { return fs$readdir(path, fs$readdirCallback(path, options, cb, startTime)); } : function (path, options, cb, startTime) { return fs$readdir(path, options, fs$readdirCallback(path, options, cb, startTime)); }; return go$readdir(path, options, cb); function fs$readdirCallback(path, options, cb, startTime) { return function (err, files) { !err || "EMFILE" !== err.code && "ENFILE" !== err.code ? (files && files.sort && files.sort(), "function" == typeof cb && cb.call(this, err, files)) : enqueue([go$readdir, [path, options, cb], err, startTime || Date.now(), Date.now()]); }; } }; var noReaddirOptionVersions = /^v[0-5]\./; if ("v0.8" === process.version.substr(0, 4)) { var legStreams = legacy(fs); ReadStream = legStreams.ReadStream, WriteStream = legStreams.WriteStream; } var fs$ReadStream = fs.ReadStream; fs$ReadStream && (ReadStream.prototype = Object.create(fs$ReadStream.prototype), ReadStream.prototype.open = function () { var that = this; open(that.path, that.flags, that.mode, function (err, fd) { err ? (that.autoClose && that.destroy(), that.emit("error", err)) : (that.fd = fd, that.emit("open", fd), that.read()); }); }); var fs$WriteStream = fs.WriteStream; fs$WriteStream && (WriteStream.prototype = Object.create(fs$WriteStream.prototype), WriteStream.prototype.open = function () { var that = this; open(that.path, that.flags, that.mode, function (err, fd) { err ? (that.destroy(), that.emit("error", err)) : (that.fd = fd, that.emit("open", fd)); }); }), Object.defineProperty(fs, "ReadStream", { get: function () { return ReadStream; }, set: function (val) { ReadStream = val; }, enumerable: !0, configurable: !0 }), Object.defineProperty(fs, "WriteStream", { get: function () { return WriteStream; }, set: function (val) { WriteStream = val; }, enumerable: !0, configurable: !0 }); var FileReadStream = ReadStream; Object.defineProperty(fs, "FileReadStream", { get: function () { return FileReadStream; }, set: function (val) { FileReadStream = val; }, enumerable: !0, configurable: !0 }); var FileWriteStream = WriteStream; function ReadStream(path, options) { return this instanceof ReadStream ? (fs$ReadStream.apply(this, arguments), this) : ReadStream.apply(Object.create(ReadStream.prototype), arguments); } function WriteStream(path, options) { return this instanceof WriteStream ? (fs$WriteStream.apply(this, arguments), this) : WriteStream.apply(Object.create(WriteStream.prototype), arguments); } Object.defineProperty(fs, "FileWriteStream", { get: function () { return FileWriteStream; }, set: function (val) { FileWriteStream = val; }, enumerable: !0, configurable: !0 }); var fs$open = fs.open; function open(path, flags, mode, cb) { return "function" == typeof mode && (cb = mode, mode = null), function go$open(path, flags, mode, cb, startTime) { return fs$open(path, flags, mode, function (err, fd) { !err || "EMFILE" !== err.code && "ENFILE" !== err.code ? "function" == typeof cb && cb.apply(this, arguments) : enqueue([go$open, [path, flags, mode, cb], err, startTime || Date.now(), Date.now()]); }); }(path, flags, mode, cb); } return fs.open = open, fs; } function enqueue(elem) { debug("ENQUEUE", elem[0].name, elem[1]), fs[gracefulQueue].push(elem), retry(); } function resetQueue() { for (var now = Date.now(), i = 0; i < fs[gracefulQueue].length; ++i) fs[gracefulQueue][i].length > 2 && (fs[gracefulQueue][i][3] = now, fs[gracefulQueue][i][4] = now); retry(); } function retry() { if (clearTimeout(retryTimer), retryTimer = void 0, 0 !== fs[gracefulQueue].length) { var elem = fs[gracefulQueue].shift(), fn = elem[0], args = elem[1], err = elem[2], startTime = elem[3], lastTime = elem[4]; if (void 0 === startTime) debug("RETRY", fn.name, args), fn.apply(null, args);else if (Date.now() - startTime >= 6e4) { debug("TIMEOUT", fn.name, args); var cb = args.pop(); "function" == typeof cb && cb.call(null, err); } else { var sinceAttempt = Date.now() - lastTime, sinceStart = Math.max(lastTime - startTime, 1); sinceAttempt >= Math.min(1.2 * sinceStart, 100) ? (debug("RETRY", fn.name, args), fn.apply(null, args.concat([startTime]))) : fs[gracefulQueue].push(elem); } void 0 === retryTimer && (retryTimer = setTimeout(retry, 0)); } } function promisifyFallback(fn, fallbackObjectCreator) { return "__promisify__" in fn || require$$4.promisify.custom in fn ? require$$4.promisify(fn) : (...args) => new Promise((resolve, reject) => { fn(...args, (err, ...results) => { err && reject(err), resolve(fallbackObjectCreator(...results)); }); }); } process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs.__patched && (gracefulFs = patch(fs), fs.__patched = !0); var universalifiedSymbol = Symbol(); function universalify(fn, fallbackMultiResultObjectCreator) { if (!fn) return fn; if (universalifiedSymbol in fn) return fn[universalifiedSymbol]; var promisified = fallbackMultiResultObjectCreator ? promisifyFallback(fn, fallbackMultiResultObjectCreator) : require$$4.promisify(fn), f = (...args) => "function" == typeof args[args.length - 1] ? fn(...args) : promisified(...args), attr = { value: f, enumerable: !1, writable: !1, configurable: !0 }; return Object.defineProperty(fn, universalifiedSymbol, attr), Object.defineProperty(f, universalifiedSymbol, attr), f; } var rename$1 = universalify(gracefulFs.rename), truncate = universalify(gracefulFs.truncate), ftruncate = universalify(gracefulFs.ftruncate), chown = universalify(gracefulFs.chown), fchown = universalify(gracefulFs.fchown), lchown = universalify(gracefulFs.lchown), lutimes = universalify(gracefulFs.lutimes), chmod = universalify(gracefulFs.chmod), fchmod = universalify(gracefulFs.fchmod), lchmod = universalify(gracefulFs.lchmod), stat = universalify(gracefulFs.stat), fstat = universalify(gracefulFs.fstat), lstat = universalify(gracefulFs.lstat), statfs = universalify(gracefulFs.statfs), link = universalify(gracefulFs.link), symlink = universalify(gracefulFs.symlink), readlink = universalify(gracefulFs.readlink), realpath = universalify(gracefulFs.realpath), unlink = universalify(gracefulFs.unlink), rmdir = universalify(gracefulFs.rmdir), rm = universalify(gracefulFs.rm), mkdir = universalify(gracefulFs.mkdir), mkdtemp = universalify(gracefulFs.mkdtemp), readdir = universalify(gracefulFs.readdir), close = universalify(gracefulFs.close), open = universalify(gracefulFs.open), utimes = universalify(gracefulFs.utimes), futimes = universalify(gracefulFs.futimes), write = universalify(gracefulFs.write, (bytesWritten, buffer) => ({ bytesWritten, buffer })), read = universalify(gracefulFs.read, (bytesRead, buffer) => ({ bytesRead, buffer })), readFile = universalify(gracefulFs.readFile), writeFile$1 = universalify(gracefulFs.writeFile), appendFile = universalify(gracefulFs.appendFile), access = universalify(gracefulFs.access), copyFile$2 = universalify(gracefulFs.copyFile), writev = universalify(gracefulFs.writev, (bytesWritten, buffers) => ({ bytesWritten, buffers })), readv = universalify(gracefulFs.readv, (bytesRead, buffers) => ({ bytesRead, buffers })), opendir = universalify(gracefulFs.opendir), cp = universalify(gracefulFs.cp); function stripTrailingSep(thePath) { return thePath[thePath.length - 1] === path.sep ? thePath.slice(0, -1) : thePath; } "function" == typeof rfs.realpath.native ? realpath.native = universalify(rfs.realpath.native) : process.emitWarning("fs.realpath.native is not a function. Is fs being monkey-patched?", "Warning", "fs-extra-WARN0003"); var noop = () => {}; function vacuum(leaf, options = {}, cb) { var base; function next(branch) { if (branch = branch && path.resolve(branch), base && branch === base || branch === path.dirname(branch)) return log("finished vacuuming up to", branch), cb(null); gracefulFs.readdir(branch, (error, files) => error ? "ENOENT" === error.code ? cb(null) : (log("unable to check directory", branch, "due to", error.message), cb(error)) : files.length > 0 ? (log("quitting because other entries in", branch), cb(null)) : branch === process.env.HOME ? (log("quitting because cannot remove home directory", branch), cb(null)) : (log("removing", branch), void gracefulFs.lstat(branch, (error, stat) => { if (error) return "ENOENT" === error.code ? cb(null) : (log("unable to lstat", branch, "due to", error.message), cb(error)); (stat.isDirectory() ? gracefulFs.rmdir : gracefulFs.unlink)(branch, error => { if (error) return "ENOENT" === error.code ? (log("quitting because lost the race to remove", branch), cb(null)) : "ENOTEMPTY" === error.code || "EEXIST" === error.code ? (log("quitting because new (racy) entries in", branch), cb(null)) : (log("unable to remove", branch, "due to", error.message), cb(error)); next(path.dirname(branch)); }); }))); } if (void 0 === cb) return new Promise((resolve, reject) => { vacuum(leaf, options, err => err ? reject(err) : resolve()); }); assert("string" == typeof leaf, "must pass in path to remove"), assert("object" == typeof options, "options must be an object"), assert("function" == typeof cb, "must pass in callback"); var log = options.log ?? noop; if (leaf = leaf && path.resolve(leaf), (base = options.base && path.resolve(options.base)) && (potentialParent = base, thePath = stripTrailingSep(thePath = leaf), potentialParent = stripTrailingSep(potentialParent), "win32" === process.platform && (thePath = thePath.toLowerCase(), potentialParent = potentialParent.toLowerCase()), 0 !== thePath.lastIndexOf(potentialParent, 0) || thePath[potentialParent.length] !== path.sep && void 0 !== thePath[potentialParent.length])) return cb(Error(leaf + " is not a child of " + base)); var thePath, potentialParent; gracefulFs.lstat(leaf, (error, stat) => error ? "ENOENT" === error.code ? cb(null) : (log(error.stack), cb(error)) : stat && (stat.isDirectory() || stat.isSymbolicLink() || stat.isFile()) ? void (options.purge ? (log("purging", leaf), gracefulFs.rm(leaf, { recursive: !0, force: !0 }, error => { if (error) return cb(error); next(path.dirname(leaf)); })) : stat.isDirectory() ? next(leaf) : (log("removing", leaf), gracefulFs.unlink(leaf, error => { if (error) return cb(error); next(path.dirname(leaf)); }))) : (log(leaf, "is not a directory, file, or link"), cb(Error(leaf + " is not a directory, file, or link")))); } var fromPromise = function (fn) { return Object.defineProperty(function (...args) { var cb = args[args.length - 1]; if ("function" != typeof cb) return fn.apply(this, args); args.pop(), fn.apply(this, args).then(r => cb(null, r), cb); }, "name", { value: fn.name }); }; function checkPath(pth) { if ("win32" === process.platform && /[<>:"|?*]/.test(pth.replace(path.parse(pth).root, ""))) { var error = Error("Path contains invalid characters: " + pth); throw error.code = "EINVAL", error; } } var getMode = options => "number" == typeof options ? options : { mode: 511, ...options }.mode; function makeDirSync(dir, options) { return checkPath(dir), gracefulFs.mkdirSync(dir, { mode: getMode(options), recursive: !0 }); } var mkdirs = fromPromise(async function (dir, options) { return checkPath(dir), mkdir(dir, { mode: getMode(options), recursive: !0 }); }); function exists(path, callback) { return callback ? access(path, err => callback(null, !err)) : access(path).then(() => !0, () => !1); } function utimesMillisSync(path, atime, mtime) { var fd = gracefulFs.openSync(path, "r+"); return gracefulFs.futimesSync(fd, atime, mtime), gracefulFs.closeSync(fd); } var utimesMillis = fromPromise(async function (path, atime, mtime) { var fd = await open(path, "r+"), closeErr = null; try { await futimes(fd, atime, mtime); } finally { try { await close(fd); } catch (e) { closeErr = e; } } if (closeErr) throw closeErr; }); async function getStats$1(src, dest, opts) { var statFunc = opts.dereference ? file => stat(file, { bigint: !0 }) : file => lstat(file, { bigint: !0 }), [srcStat, destStat] = await Promise.all([statFunc(src), statFunc(dest).catch(err => { if ("ENOENT" === err.code) return null; throw err; })]); return { srcStat, destStat }; } function getStatsSync(src, dest, opts) { var destStat, statFunc = opts.dereference ? file => gracefulFs.statSync(file, { bigint: !0 }) : file => gracefulFs.lstatSync(file, { bigint: !0 }), srcStat = statFunc(src); try { destStat = statFunc(dest); } catch (err) { if ("ENOENT" === err.code) return { srcStat, destStat: null }; throw err; } return { srcStat, destStat }; } function errMsg(src, dest, funcName) { return `Cannot ${funcName} '${src}' to a subdirectory of itself, '${dest}'.`; } function checkPathsSync(src, dest, funcName, opts) { var { srcStat, destStat } = getStatsSync(src, dest, opts); if (destStat) { if (areIdentical(srcStat, destStat)) { var srcBaseName = path.basename(src), destBaseName = path.basename(dest); if ("move" === funcName && srcBaseName !== destBaseName && srcBaseName.toLowerCase() === destBaseName.toLowerCase()) return { srcStat, destStat, isChangingCase: !0 }; throw Error("Source and destination must not be the same."); } if (srcStat.isDirectory() && !destStat.isDirectory()) throw Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`); if (!srcStat.isDirectory() && destStat.isDirectory()) throw Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`); } if (srcStat.isDirectory() && isSrcSubdir(src, dest)) throw Error(errMsg(src, dest, funcName)); return { srcStat, destStat }; } function checkParentPathsSync(src, srcStat, dest, funcName) { var destStat, srcParent = path.resolve(path.dirname(src)), destParent = path.resolve(path.dirname(dest)); if (destParent !== srcParent && destParent !== path.parse(destParent).root) { try { destStat = gracefulFs.statSync(destParent, { bigint: !0 }); } catch (err) { if ("ENOENT" === err.code) return; throw err; } if (areIdentical(srcStat, destStat)) throw Error(errMsg(src, dest, funcName)); return checkParentPathsSync(src, srcStat, destParent, funcName); } } function areIdentical(srcStat, destStat) { return !!destStat.ino && !!destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev; } function isSrcSubdir(src, dest) { var srcArr = path.resolve(src).split(path.sep).filter(i => i), destArr = path.resolve(dest).split(path.sep).filter(i => i); return srcArr.every((cur, i) => destArr[i] === cur); } var checkPaths = fromPromise(async function (src, dest, funcName, opts) { var { srcStat, destStat } = await getStats$1(src, dest, opts); if (destStat) { if (areIdentical(srcStat, destStat)) { var srcBaseName = path.basename(src), destBaseName = path.basename(dest); if ("move" === funcName && srcBaseName !== destBaseName && srcBaseName.toLowerCase() === destBaseName.toLowerCase()) return { srcStat, destStat, isChangingCase: !0 }; throw Error("Source and destination must not be the same."); } if (srcStat.isDirectory() && !destStat.isDirectory()) throw Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`); if (!srcStat.isDirectory() && destStat.isDirectory()) throw Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`); } if (srcStat.isDirectory() && isSrcSubdir(src, dest)) throw Error(errMsg(src, dest, funcName)); return { srcStat, destStat }; }), checkParentPaths = fromPromise(async function (src, srcStat, dest, funcName) { var destStat, srcParent = path.resolve(path.dirname(src)), destParent = path.resolve(path.dirname(dest)); if (destParent !== srcParent && destParent !== path.parse(destParent).root) { try { destStat = await stat(destParent, { bigint: !0 }); } catch (err) { if ("ENOENT" === err.code) return; throw err; } if (areIdentical(srcStat, destStat)) throw Error(errMsg(src, dest, funcName)); return checkParentPaths(src, srcStat, destParent, funcName); } }); async function runFilter(src, dest, opts) { return !opts.filter || opts.filter(src, dest); } async function getStatsAndPerformCopy(destStat, src, dest, opts) { var statFn = opts.dereference ? stat : lstat, srcStat = await statFn(src); if (srcStat.isDirectory()) return onDir$1(srcStat, destStat, src, dest, opts); if (srcStat.isFile() || srcStat.isCharacterDevice() || srcStat.isBlockDevice()) return onFile$1(srcStat, destStat, src, dest, opts); if (srcStat.isSymbolicLink()) return onLink$1(destStat, src, dest, opts); if (srcStat.isSocket()) throw Error("Cannot copy a socket file: " + src); if (srcStat.isFIFO()) throw Error("Cannot copy a FIFO pipe: " + src); throw Error("Unknown file: " + src); } async function onFile$1(srcStat, destStat, src, dest, opts) { if (!destStat) return copyFile$1(srcStat, src, dest, opts); if (opts.overwrite) return await unlink(dest), copyFile$1(srcStat, src, dest, opts); if (opts.errorOnExist) throw Error(`'${dest}' already exists`); } async function copyFile$1(srcStat, src, dest, opts) { if (await copyFile$2(src, dest), opts.preserveTimestamps) { 0 == (128 & srcStat.mode) && (await makeFileWritable$1(dest, srcStat.mode)); var updatedSrcStat = await stat(src); await utimesMillis(dest, updatedSrcStat.atime, updatedSrcStat.mtime); } return chmod(dest, srcStat.mode); } function makeFileWritable$1(dest, srcMode) { return chmod(dest, 128 | srcMode); } async function onDir$1(srcStat, destStat, src, dest, opts) { destStat || (await mkdir(dest)); var items = await readdir(src); await Promise.all(items.map(async item => { var srcItem = path.join(src, item), destItem = path.join(dest, item); if (await runFilter(srcItem, destItem, opts)) { var { destStat } = await checkPaths(srcItem, destItem, "copy", opts); return getStatsAndPerformCopy(destStat, srcItem, destItem, opts); } })), destStat || (await chmod(dest, srcStat.mode)); } async function onLink$1(destStat, src, dest, opts) { var resolvedSrc = await readlink(src); if (opts.dereference && (resolvedSrc = path.resolve(process.cwd(), resolvedSrc)), !destStat) return symlink(resolvedSrc, dest); var resolvedDest = null; try { resolvedDest = await readlink(dest); } catch (e) { if ("EINVAL" === e.code || "UNKNOWN" === e.code) return symlink(resolvedSrc, dest); throw e; } if (opts.dereference && (resolvedDest = path.resolve(process.cwd(), resolvedDest)), isSrcSubdir(resolvedSrc, resolvedDest)) throw Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`); if (isSrcSubdir(resolvedDest, resolvedSrc)) throw Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`); return await unlink(dest), symlink(resolvedSrc, dest); } var copy = fromPromise(async (src, dest, opts = {}) => { "function" == typeof opts && (opts = { filter: opts }), opts.clobber = !("clobber" in opts) || !!opts.clobber, opts.overwrite = "overwrite" in opts ? !!opts.overwrite : opts.clobber, opts.preserveTimestamps && "ia32" === process.arch && process.emitWarning("Using the preserveTimestamps option in 32-bit node is not recommended;\n\n\tsee https://github.com/jprichardson/node-fs-extra/issues/269", "Warning", "fs-extra-WARN0001"); var { srcStat, destStat } = await checkPaths(src, dest, "copy", opts); if (await checkParentPaths(src, srcStat, dest, "copy"), await runFilter(src, dest, opts)) { var destParent = path.dirname(dest); (await exists(destParent)) || (await mkdirs(destParent)), await getStatsAndPerformCopy(destStat, src, dest, opts); } }); function copySync(src, dest, opts) { "function" == typeof opts && (opts = { filter: opts }), (opts = opts || {}).clobber = !("clobber" in opts) || !!opts.clobber, opts.overwrite = "overwrite" in opts ? !!opts.overwrite : opts.clobber, opts.preserveTimestamps && "ia32" === process.arch && process.emitWarning("Using the preserveTimestamps option in 32-bit node is not recommended;\n\n\tsee https://github.com/jprichardson/node-fs-extra/issues/269", "Warning", "fs-extra-WARN0002"); var { srcStat, destStat } = checkPathsSync(src, dest, "copy", opts); if (checkParentPathsSync(src, srcStat, dest, "copy"), !opts.filter || opts.filter(src, dest)) { var destParent = path.dirname(dest); return gracefulFs.existsSync(destParent) || makeDirSync(destParent), getStats(destStat, src, dest, opts); } } function getStats(destStat, src, dest, opts) { var srcStat = (opts.dereference ? gracefulFs.statSync : gracefulFs.lstatSync)(src); if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts); if (srcStat.isFile() || srcStat.isCharacterDevice() || srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts); if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts); if (srcStat.isSocket()) throw Error("Cannot copy a socket file: " + src); if (srcStat.isFIFO()) throw Error("Cannot copy a FIFO pipe: " + src); throw Error("Unknown file: " + src); } function onFile(srcStat, destStat, src, dest, opts) { return destStat ? mayCopyFile(srcStat, src, dest, opts) : copyFile(srcStat, src, dest, opts); } function mayCopyFile(srcStat, src, dest, opts) { if (opts.overwrite) return gracefulFs.unlinkSync(dest), copyFile(srcStat, src, dest, opts); if (opts.errorOnExist) throw Error(`'${dest}' already exists`); } function copyFile(srcStat, src, dest, opts) { return gracefulFs.copyFileSync(src, dest), opts.preserveTimestamps && handleTimestamps(srcStat.mode, src, dest), setDestMode(dest, srcStat.mode); } function handleTimestamps(srcMode, src, dest) { return fileIsNotWritable(srcMode) && makeFileWritable(dest, srcMode), setDestTimestamps(src, dest); } function fileIsNotWritable(srcMode) { return 0 == (128 & srcMode); } function makeFileWritable(dest, srcMode) { return setDestMode(dest, 128 | srcMode); } function setDestMode(dest, srcMode) { return gracefulFs.chmodSync(dest, srcMode); } function setDestTimestamps(src, dest) { var updatedSrcStat = gracefulFs.statSync(src); return utimesMillisSync(dest, updatedSrcStat.atime, updatedSrcStat.mtime); } function onDir(srcStat, destStat, src, dest, opts) { return destStat ? copyDir(src, dest, opts) : mkDirAndCopy(srcStat.mode, src, dest, opts); } function mkDirAndCopy(srcMode, src, dest, opts) { return gracefulFs.mkdirSync(dest), copyDir(src, dest, opts), setDestMode(dest, srcMode); } function copyDir(src, dest, opts) { gracefulFs.readdirSync(src).forEach(item => copyDirItem(item, src, dest, opts)); } function copyDirItem(item, src, dest, opts) { var srcItem = path.join(src, item), destItem = path.join(dest, item); if (!opts.filter || opts.filter(srcItem, destItem)) { var { destStat } = checkPathsSync(srcItem, destItem, "copy", opts); return getStats(destStat, srcItem, destItem, opts); } } function onLink(destStat, src, dest, opts) { var resolvedDest, resolvedSrc = gracefulFs.readlinkSync(src); if (opts.dereference && (resolvedSrc = path.resolve(process.cwd(), resolvedSrc)), !destStat) return gracefulFs.symlinkSync(resolvedSrc, dest); try { resolvedDest = gracefulFs.readlinkSync(dest); } catch (err) { if ("EINVAL" === err.code || "UNKNOWN" === err.code) return gracefulFs.symlinkSync(resolvedSrc, dest); throw err; } if (opts.dereference && (resolvedDest = path.resolve(process.cwd(), resolvedDest)), isSrcSubdir(resolvedSrc, resolvedDest)) throw Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`); if (isSrcSubdir(resolvedDest, resolvedSrc)) throw Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`); return copyLink(resolvedSrc, dest); } function copyLink(resolvedSrc, dest) { return gracefulFs.unlinkSync(dest), gracefulFs.symlinkSync(resolvedSrc, dest); } var remove = fromPromise(path => rm(path, { recursive: !0, force: !0 })); function removeSync(path) { gracefulFs.rmSync(path, { recursive: !0, force: !0 }); } var emptyDir = fromPromise(async dir => { var items; try { items = await readdir(dir); } catch { return mkdirs(dir); } return Promise.all(items.map(item => remove(path.join(dir, item)))); }); function emptyDirSync(dir) { var items; try { items = gracefulFs.readdirSync(dir); } catch { return makeDirSync(dir); } items.forEach(item => { removeSync(item = path.join(dir, item)); }); } var createFile = fromPromise(async function (file) { try { stats = await stat(file); } catch {} if (!stats || !stats.isFile()) { var stats, dir = path.dirname(file), dirStats = null; try { dirStats = await stat(dir); } catch (err) { if ("ENOENT" === err.code) return await mkdirs(dir), void (await writeFile$1(file, "")); throw err; } dirStats.isDirectory() ? await writeFile$1(file, "") : await readdir(dir); } }); function createFileSync(file) { try { stats = gracefulFs.statSync(file); } catch {} if (!stats || !stats.isFile()) { var stats, dir = path.dirname(file); try { gracefulFs.statSync(dir).isDirectory() || gracefulFs.readdirSync(dir); } catch (err) { if (!err || "ENOENT" !== err.code) throw err; makeDirSync(dir); } gracefulFs.writeFileSync(file, ""); } } var createLink = fromPromise(async function (srcpath, dstpath) { try { dstStat = await lstat(dstpath); } catch {} try { srcStat = await lstat(srcpath); } catch (err) { throw err.message = err.message.replace("lstat", "ensureLink"), err; } if (!dstStat || !areIdentical(srcStat, dstStat)) { var dstStat, srcStat, dir = path.dirname(dstpath); (await exists(dir)) || (await mkdirs(dir)), await link(srcpath, dstpath); } }); function createLinkSync(srcpath, dstpath) { try { dstStat = gracefulFs.lstatSync(dstpath); } catch {} try { var dstStat, srcStat = gracefulFs.lstatSync(srcpath); if (dstStat && areIdentical(srcStat, dstStat)) return; } catch (err) { throw err.message = err.message.replace("lstat", "ensureLink"), err; } var dir = path.dirname(dstpath); return gracefulFs.existsSync(dir) || makeDirSync(dir), gracefulFs.linkSync(srcpath, dstpath); } var symlinkPaths = fromPromise(async function (srcpath, dstpath) { if (path.isAbsolute(srcpath)) { try { await lstat(srcpath); } catch (err) { throw err.message = err.message.replace("lstat", "ensureSymlink"), err; } return { toCwd: srcpath, toDst: srcpath }; } var dstdir = path.dirname(dstpath), relativeToDst = path.join(dstdir, srcpath); if (await exists(relativeToDst)) return { toCwd: relativeToDst, toDst: srcpath }; try { await lstat(srcpath); } catch (err) { throw err.message = err.message.replace("lstat", "ensureSymlink"), err; } return { toCwd: srcpath, toDst: path.relative(dstdir, srcpath) }; }); function symlinkPathsSync(srcpath, dstpath) { if (path.isAbsolute(srcpath)) { if (!gracefulFs.existsSync(srcpath)) throw Error("absolute srcpath does not exist"); return { toCwd: srcpath, toDst: srcpath }; } var dstdir = path.dirname(dstpath), relativeToDst = path.join(dstdir, srcpath); if (gracefulFs.existsSync(relativeToDst)) return { toCwd: relativeToDst, toDst: srcpath }; if (!gracefulFs.existsSync(srcpath)) throw Error("relative srcpath does not exist"); return { toCwd: srcpath, toDst: path.relative(dstdir, srcpath) }; } var symlinkType = fromPromise(async function (srcpath, type) { var stats; if (type) return type; try { stats = await lstat(srcpath); } catch { return "file"; } return stats && stats.isDirectory() ? "dir" : "file"; }); function symlinkTypeSync(srcpath, type) { var stats; if (type) return type; try { stats = gracefulFs.lstatSync(srcpath); } catch { return "file"; } return stats && stats.isDirectory() ? "dir" : "file"; } var createSymlink = fromPromise(async function (srcpath, dstpath, type) { try { stats = await lstat(dstpath); } catch {} if (stats && stats.isSymbolicLink()) { var stats, [srcStat, dstStat] = await Promise.all([stat(srcpath), stat(dstpath)]); if (areIdentical(srcStat, dstStat)) return; } var relative = await symlinkPaths(srcpath, dstpath); srcpath = relative.toDst; var toType = await symlinkType(relative.toCwd, type), dir = path.dirname(dstpath); return (await exists(dir)) || (await mkdirs(dir)), symlink(srcpath, dstpath, toType); }); function createSymlinkSync(srcpath, dstpath, type) { try { stats = gracefulFs.lstatSync(dstpath); } catch {} var stats; if (!(stats && stats.isSymbolicLink() && areIdentical(gracefulFs.statSync(srcpath), gracefulFs.statSync(dstpath)))) { var relative = symlinkPathsSync(srcpath, dstpath); srcpath = relative.toDst, type = symlinkTypeSync(relative.toCwd, type); var dir = path.dirname(dstpath); return gracefulFs.existsSync(dir) || makeDirSync(dir), gracefulFs.symlinkSync(srcpath, dstpath, type); } } async function doRename$1(src, dest, overwrite, isChangingCase) { if (!isChangingCase) if (overwrite) await remove(dest);else if (await exists(dest)) throw Error("dest already exists."); try { await rename$1(src, dest); } catch (err) { if ("EXDEV" !== err.code) throw err; await moveAcrossDevice$1(src, dest, overwrite); } } async function moveAcrossDevice$1(src, dest, overwrite) { return await copy(src, dest, { overwrite, errorOnExist: !0, preserveTimestamps: !0 }), remove(src); } var move = fromPromise(async function (src, dest, opts = {}) { var overwrite = opts.overwrite || opts.clobber || !1, { srcStat, isChangingCase = !1 } = await checkPaths(src, dest, "move", opts); await checkParentPaths(src, srcStat, dest, "move"); var destParent = path.dirname(dest); return path.parse(destParent).root !== destParent && (await mkdirs(destParent)), doRename$1(src, dest, overwrite, isChangingCase); }); function isParentRoot(dest) { var parent = path.dirname(dest); return path.parse(parent).root === parent; } function doRename(src, dest, overwrite, isChangingCase) { if (isChangingCase) return rename(src, dest, overwrite); if (overwrite) return removeSync(dest), rename(src, dest, overwrite); if (gracefulFs.existsSync(dest)) throw Error("dest already exists."); return rename(src, dest, overwrite); } function rename(src, dest, overwrite) { try { gracefulFs.renameSync(src, dest); } catch (err) { if ("EXDEV" !== err.code) throw err; return moveAcrossDevice(src, dest, overwrite); } } function moveAcrossDevice(src, dest, overwrite) { return copySync(src, dest, { overwrite, errorOnExist: !0, preserveTimestamps: !0 }), removeSync(src); } function moveSync(src, dest, opts) { var overwrite = (opts = opts || {}).overwrite || opts.clobber || !1, { srcStat, isChangingCase = !1 } = checkPathsSync(src, dest, "move", opts); return checkParentPathsSync(src, srcStat, dest, "move"), isParentRoot(dest) || makeDirSync(path.dirname(dest)), doRename(src, dest, overwrite, isChangingCase); } var outputFile = fromPromise(async function (file, data, encoding = "utf-8") { var dir = path.dirname(file); return (await exists(dir)) || (await mkdirs(dir)), writeFile$1(file, data, encoding); }); function outputFileSync(file, ...args) { var dir = path.dirname(file); gracefulFs.existsSync(dir) || makeDirSync(dir), gracefulFs.writeFileSync(file, ...args); } function matches(str, test) { return "string" == typeof test ? str.includes(test) : test.test(str); } async function _diveHelper(directory, action, options = {}) { for await (var [file, _stat] of _diveWorker(directory, options)) await action(file, _stat); } async function _diveWorkerCallback(directory, action, options = {}) { var children, err; try { children = await readdir(directory, { withFileTypes: !0 }); } catch (err1) { err = err1; } if ((!children || 0 === children.length) && options.directories && action(null, directory, await stat(directory)), err) action(err);else for (var item of children) if (options.all || !item.name.startsWith(".")) try { var path$1 = path.resolve(item.path ?? directory, item.name); item.isDirectory() ? options.recursive ? await _diveWorkerCallback(path$1, action, options) : !options.directories || options.ignore && matches(path$1, options.ignore) || action(null, path$1, await stat(path$1)) : !options.files || options.ignore && matches(path$1, options.ignore) || action(null, path$1, await stat(path$1)); } catch (err) { action(err); } } function* _diveSyncWorker(directory, options = {}) { var children = gracefulFs.readdirSync(directory, { withFileTypes: !0 }); for (var item of (0 === children.length && options.directories && (yield directory), children)) { if (!options.all && item.name.startsWith(".")) continue; var path$1 = path.resolve(item.path ?? directory, item.name); item.isDirectory() ? options.recursive ? yield* _diveSyncWorker(path$1, options) : !options.directories || options.ignore && matches(path$1, options.ignore) || (yield path$1) : !options.files || options.ignore && matches(path$1, options.ignore) || (yield path$1); } } async function* _diveWorker(directory, options = {}) { var children = await readdir(directory, { withFileTypes: !0 }); for (var item of (0 === children.length && options.directories && (yield [directory, await stat(directory)]), children)) { if (!options.all && item.name.startsWith(".")) continue; var path$1 = path.resolve(item.path ?? directory, item.name); item.isDirectory() ? options.recursive ? yield* _diveWorker(path$1, options) : !options.directories || options.ignore && matches(path$1, options.ignore) || (yield [path$1, await stat(path$1)]) : !options.files || options.ignore && matches(path$1, options.ignore) || (yield [path$1, await stat(path$1)]); } } function dive(directory, o1, o2, o3) { var options = "object" == typeof o1 ? o1 : void 0, action = options ? o2 : o1, complete = options ? o3 : o2; if (options = { recursive: !0, all: !0, files: !0, ...options }, !complete) return _diveHelper(directory, action, options); _diveWorkerCallback(directory, action, options).finally(complete); } function diveSync(directory, options = {}) { return [..._diveSyncWorker(directory, options = { recursive: !0, all: !0, files: !0, ...options })]; } async function _forEachChildHelper(path, options, func) { for (var child of await readdir(path, options)) { var ret = func(child); ret instanceof Promise && (await ret); } } function forEachChild(path, o1, o2, o3) { var options = "object" == typeof o1 ? o1 : void 0, func = options ? o2 : o1, callback = options ? o3 : o2; if (!callback) return _forEachChildHelper(path, options, func); readdir(path, options, (err, children) => { if (err) callback(err);else { for (var child of children) func(child); callback(); } }); } function forEachChildSync(path, func, options) { for (var child of gracefulFs.readdirSync(path, options)) func(child); } async function _isDirectoryHelper(path) { return (await stat(path)).isDirectory(); } function isDirectory(path, callback) { if (!callback) return _isDirectoryHelper(path); stat(path, (err, stats) => { if (err) return callback(err); callback(null, stats.isDirectory()); }); } function isDirectorySync(path) { return gracefulFs.statSync(path).isDirectory(); } var Array_fromAsync = Array.fromAsync ?? (async (iterableOrArrayLike, mapperFn) => { var items = []; if (mapperFn) { if (Symbol.asyncIterator in iterableOrArrayLike) for await (var item of iterableOrArrayLike) items.push(await mapperFn(item));else if (Symbol.iterator in iterableOrArrayLike) for (var _item of iterableOrArrayLike) items.push(await mapperFn(await _item));else { var length = iterableOrArrayLike.length; for (var i = 0; i < length; i++) { var _item2 = await iterableOrArrayLike[i]; items.push(await mapperFn(_item2)); } } } else if (Symbol.asyncIterator in iterableOrArrayLike) for await (var _item3 of iterableOrArrayLike) items.push(_item3);else if (Symbol.iterator in iterableOrArrayLike) for (var _item4 of iterableOrArrayLike) items.push(await _item4);else { var _length = iterableOrArrayLike.length; for (var _i = 0; _i < _length; _i++) { var _item5 = await iterableOrArrayLike[_i]; items.push(_item5); } } return items; }); async function* _asyncFilter(iterable, condition) { var i = 0; for (var value of iterable) (await condition(value, i++, iterable)) && (yield value); } async function mapChildren(path, mapper, readOptions, writeOptions) { var children = await Array_fromAsync(_asyncFilter((await readdir(path)).map(child => path + "/" + child), async e => !(await isDirectory(e)))); for (var e of children) { var contents = await readFile(e, readOptions), result = mapper(contents, e.slice(e.lastIndexOf("/") + 1), path, e); result instanceof Promise && (result = await result), result != contents && (await writeFile$1(e, result, writeOptions)); } return children; } async function _mapStructureProcessFile(file, stat, mapper, readOptions, writeOptions) { var contents = await readFile(file, readOptions), result = mapper(contents, file, stat); result instanceof Promise && (result = await result), result != contents && (await writeFile$1(file, result, writeOptions)); } async function mapStructure(path, mapper, readOptions, writeOptions) { var promiseArr = [], results = []; return await dive(path, { all: !0 }, (file, stat) => { promiseArr.push(_mapStructureProcessFile(file, stat, mapper, readOptions, writeOptions)), results.push({ file, stat }); }), await Promise.all(promiseArr), results; } async function mapStructureOrdered(path, mapper, readOptions, writeOptions) { var entries = []; for await (var [file, _stat2] of _diveWorker(path)) entries.push({ file, stat: _stat2 }), await _mapStructureProcessFile(file, _stat2, mapper, readOptions, writeOptions); return entries; } function _readLinesHelper(path, encoding, resolve, reject) { readFile(path, encoding, (err, data) => { err ? reject(err) : data.indexOf("\r\n") > -1 ? resolve(data.split("\r\n")) : data.indexOf("\n") > -1 ? resolve(data.split("\n")) : resolve([data]); }); } function readLines(path, o1, o2) { var encoding = "string" == typeof o1 ? o1 : "utf8", callback = "string" == typeof o1 ? o2 : o1; if (!callback) return new Promise((resolve, reject) => { _readLinesHelper(path, encoding, resolve, reject); }); _readLinesHelper(path, encoding, e => callback(null, e), callback); } function readLinesSync(path, encoding = "utf8") { var data = gracefulFs.readFileSync(path, encoding); return data.indexOf("\r\n") > -1 ? data.split("\r\n") : data.indexOf("\n") > -1 ? data.split("\n") : [data]; } function readText(path, callback) { if (!callback) return readFile(path, "utf8"); readFile(path, "utf8", callback); } function readTextSync(path) { return gracefulFs.readFileSync(path, "utf8"); } var backingWriteFile = universalify(gracefulFs.writeFile), _writeFileStreamHelper = fromPromise(async (path, data, options) => { var stream; function getOptions(options) { return options ? "string" == typeof options ? { encoding: options } : { encoding: options.encoding || void 0, mode: "string" == typeof options.mode ? parseInt(options.mode, 8) : options.mode, flush: options.flush } : void 0; } stream = "number" == typeof path ? gracefulFs.createWriteStream("", { ...getOptions(options), fd: path }) : gracefulFs.createWriteStream(path, getOptions(options)), await promises.finished(data.pipe(stream)); }); function writeFile(path, data, optionsOrCallback, optionalCallback) { var options = "function" != typeof optionsOrCallback ? optionsOrCallback : void 0, callback = optionalCallback ?? ("function" == typeof optionsOrCallback ? optionsOrCallback : void 0); return data instanceof web.ReadableStream && (data = require$$0$1.Readable.fromWeb(data)), "object" == typeof (stream = data) && "readable" in stream && require$$0$1.isReadable(stream) ? _writeFileStreamHelper(path, data, options, callback) : ((data instanceof SharedArrayBuffer || data instanceof ArrayBuffer) && (data = new Uint8Array(data)), backingWriteFile(path, data, optionsOrCallback, optionalCallback)); var stream; } async function _readJson(file, options) { var obj; "string" == typeof options && (options = { encoding: options }); var _readFile = options?.fs?.readFile ? universalify(options.fs.readFile) : readFile, data = stripBom(await _readFile(file, options)); try { obj = JSON.parse(data, options?.reviver); } catch (err) { if (!(options?.throws ?? 1)) return null; if (err instanceof Error) throw err.message = `${file}: ${err.message}`, err; throw Error(`${file}: ${err}`); } return obj; } function stringify(obj, { EOL = "\n", finalEOL = !0, replacer, spaces }) { var EOF = finalEOL ? EOL : ""; return JSON.stringify(obj, replacer, spaces).replace(/\n/g, EOL) + EOF; } function stripBom(content) { return Buffer.isBuffer(content) && (content = content.toString("utf8")), content.replace(/^\uFEFF/, ""); } async function _writeJson(file, obj, options) { "string" == typeof options && (options = { encoding: options }); var _writeFile = options?.fs?.writeFile ? universalify(options.fs.writeFile) : writeFile$1, str = stringify(obj, options ?? {}); await _writeFile(file, str, options); } function readJson(file, o1, o2) { var options = o2 ?? ("function" != typeof o1 ? o1 : void 0), callback = o2 ?? (void 0 === options ? o1 : void 0); return callback ? _readJson(file, options).then(result => callback(null, result), error => callback(error, void 0)) : _readJson(file, options); } function readJsonSync(file, options) { "string" == typeof options && (options = { encoding: options }); var _readFileSync = options?.fs?.readFileSync ?? gracefulFs.readFileSync; try { var content = stripBom(_readFileSync(file, options)); return JSON.parse(content, options?.reviver); } catch (err) { if (!(options?.throws ?? 1)) return null; if (err instanceof Error) throw err.message = `${file}: ${err.message}`, err; throw Error(`${file}: ${err}`); } } function writeJson(file, obj, o1, o2) { var options = o2 ?? ("function" != typeof o1 ? o1 : void 0), callback = o2 ?? (void 0 === options ? o1 : void 0); return callback ? _writeJson(file, obj, options).then(() => callback(null), error => callback(error)) : _writeJson(file, obj, options); } function writeJsonSync(file, obj, options) { "string" == typeof options && (options = { encoding: options }), (options?.fs?.writeFileSync ?? gracefulFs.writeFileSync)(file, stringify(obj, options ?? {}), options); } function outputJson(file, data, optionsOrCallback, callback) { var options = "object" == typeof optionsOrCallback ? optionsOrCallback : {}; if (!(callback = callback ?? ("function" == typeof optionsOrCallback ? optionsOrCallback : void 0))) return new Promise((resolve, reject) => { outputJson(file, data, options, err => err ? reject(err) : resolve()); }); outputFile(file, stringify(data, options), options, callback); } function outputJsonSync(file, data, options = {}) { outputFileSync(file, stringify(data, options), options); } function resolve(path, child) { return path.endsWith("/") || path.endsWith("\\") ? path + child : path.indexOf("/") > -1 ? `${path}/${child}` : path.indexOf("\\") > -1 ? `${path}\\${child}` : `${path}/${child}`; } function isSymlink(file, callback) { return callback ? lstat(file, (err, stats) => err ? callback(err) : callback(null, stats.isSymbolicLink())) : lstat(file).then(stats => stats.isSymbolicLink()); } var subindex = Object.freeze({ __proto__: null, access, appendFile, chmod, chown, close, copy, copyFile: copyFile$2, copySync, cp, dive, diveSync, emptyDir, emptyDirSync, ensureDir: mkdirs, ensureDirSync: makeDirSync, ensureFile: createFile, ensureFileSync: createFileSync, ensureLink: createLink, ensureLinkSync: createLinkSync, ensureSymlink: createSymlink, ensureSymlinkSync: createSymlinkSync, exists, fchmod, fchown, forEachChild, forEachChildSync, fstat, ftruncate, futimes, isDirectory, isDirectorySync, isSymlink, lchmod, lchown, link, lstat, lutimes, mapChildren, mapStructure, mapStructureOrdered, mkdir, mkdirs, mkdirsSync: makeDirSync, mkdtemp, move, moveSync, open, opendir, outputFile, outputFileSync, outputJson, outputJsonSync, read, readFile, readJson, readJsonSync, readLines, readLinesSync, readText, readTextSync, readdir, readlink, readv, realpath, remove, removeSync, rename: rename$1, resolve, rm, rmdir, stat, statfs, symlink, truncate, unlink, utimes, vacuum, write, writeFile, writeJson, writeJsonSync, writev }); exports.access = access, exports.appendFile = appendFile, exports.chmod = chmod, exports.chown = chown, exports.close = close, exports.copy = copy, exports.copyFile = copyFile$2, exports.copySync = copySync, exports.cp = cp, exports.default = subindex, exports.dive = dive, exports.diveSync = diveSync, exports.emptyDir = emptyDir, exports.emptyDirSync = emptyDirSync, exports.ensureDir = mkdirs, exports.ensureDirSync = makeDirSync, exports.ensureFile = createFile, exports.ensureFileSync = createFileSync, exports.ensureLink = createLink, exports.ensureLinkSync = createLinkSync, exports.ensureSymlink = createSymlink, exports.ensureSymlinkSync = createSymlinkSync, exports.exists = exists, exports.fchmod = fchmod, exports.fchown = fchown, exports.forEachChild = forEachChild, exports.forEachChildSync = forEachChildSync, exports.fstat = fstat, exports.ftruncate = ftruncate, exports.futimes = futimes, exports.isDirectory = isDirectory, exports.isDirectorySync = isDirectorySync, exports.isSymlink = isSymlink, exports.lchmod = lchmod, exports.lchown = lchown, exports.link = link, exports.lstat = lstat, exports.lutimes = lutimes, exports.mapChildren = mapChildren, exports.mapStructure = mapStructure, exports.mapStructureOrdered = mapStructureOrdered, exports.mkdir = mkdir, exports.mkdirs = mkdirs, exports.mkdirsSync = makeDirSync, exports.mkdtemp = mkdtemp, exports.move = move, exports.moveSync = moveSync, exports.open = open, exports.opendir = opendir, exports.outputFile = outputFile, exports.outputFileSync = outputFileSync, exports.outputJson = outputJson, exports.outputJsonSync = outputJsonSync, exports.read = read, exports.readFile = readFile, exports.readJson = readJson, exports.readJsonSync = readJsonSync, exports.readLines = readLines, exports.readLinesSync = readLinesSync, exports.readText = readText, exports.readTextSync = readTextSync, exports.readdir = readdir, exports.readlink = readlink, exports.readv = readv, exports.realpath = realpath, exports.remove = remove, exports.removeSync = removeSync, exports.rename = rename$1, exports.resolve = resolve, exports.rm = rm, exports.rmdir = rmdir, exports.stat = stat, exports.statfs = statfs, exports.symlink = symlink, exports.truncate = truncate, exports.unlink = unlink, exports.utimes = utimes, exports.vacuum = vacuum, exports.write = write, exports.writeFile = writeFile, exports.writeJson = writeJson, exports.writeJsonSync = writeJsonSync, exports.writev = writev; //# sourceMappingURL=index.cjs.map