Changeset 79a0317 for imaps-frontend/node_modules/readdirp/index.js
- Timestamp:
- 01/21/25 03:08:24 (3 days ago)
- Branches:
- main
- Parents:
- 0c6b92a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/readdirp/index.js
r0c6b92a r79a0317 1 1 "use strict"; 2 2 Object.defineProperty(exports, "__esModule", { value: true }); 3 exports.readdirpPromise = exports.readdirp = exports.ReaddirpStream = void 0; 4 const promises_1 = require("fs/promises"); 5 const stream_1 = require("stream"); 6 const path_1 = require("path"); 7 function defaultOptions() { 8 return { 9 root: '.', 10 fileFilter: (_path) => true, 11 directoryFilter: (_path) => true, 12 type: FILE_TYPE, 13 lstat: false, 14 depth: 2147483648, 15 alwaysStat: false, 16 highWaterMark: 4096, 17 }; 18 } 3 exports.ReaddirpStream = exports.EntryTypes = void 0; 4 exports.readdirp = readdirp; 5 exports.readdirpPromise = readdirpPromise; 6 const promises_1 = require("node:fs/promises"); 7 const node_stream_1 = require("node:stream"); 8 const node_path_1 = require("node:path"); 9 exports.EntryTypes = { 10 FILE_TYPE: 'files', 11 DIR_TYPE: 'directories', 12 FILE_DIR_TYPE: 'files_directories', 13 EVERYTHING_TYPE: 'all', 14 }; 15 const defaultOptions = { 16 root: '.', 17 fileFilter: (_entryInfo) => true, 18 directoryFilter: (_entryInfo) => true, 19 type: exports.EntryTypes.FILE_TYPE, 20 lstat: false, 21 depth: 2147483648, 22 alwaysStat: false, 23 highWaterMark: 4096, 24 }; 25 Object.freeze(defaultOptions); 19 26 const RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR'; 20 27 const NORMAL_FLOW_ERRORS = new Set(['ENOENT', 'EPERM', 'EACCES', 'ELOOP', RECURSIVE_ERROR_CODE]); 21 const FILE_TYPE = 'files'; 22 const DIR_TYPE = 'directories'; 23 const FILE_DIR_TYPE = 'files_directories'; 24 const EVERYTHING_TYPE = 'all'; 25 const ALL_TYPES = [FILE_TYPE, DIR_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE]; 26 const DIR_TYPES = new Set([DIR_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE]); 27 const FILE_TYPES = new Set([FILE_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE]); 28 const ALL_TYPES = [ 29 exports.EntryTypes.DIR_TYPE, 30 exports.EntryTypes.EVERYTHING_TYPE, 31 exports.EntryTypes.FILE_DIR_TYPE, 32 exports.EntryTypes.FILE_TYPE, 33 ]; 34 const DIR_TYPES = new Set([ 35 exports.EntryTypes.DIR_TYPE, 36 exports.EntryTypes.EVERYTHING_TYPE, 37 exports.EntryTypes.FILE_DIR_TYPE, 38 ]); 39 const FILE_TYPES = new Set([ 40 exports.EntryTypes.EVERYTHING_TYPE, 41 exports.EntryTypes.FILE_DIR_TYPE, 42 exports.EntryTypes.FILE_TYPE, 43 ]); 28 44 const isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code); 29 45 const wantBigintFsStats = process.platform === 'win32'; 30 const emptyFn = (_ path) => true;46 const emptyFn = (_entryInfo) => true; 31 47 const normalizeFilter = (filter) => { 32 48 if (filter === undefined) … … 44 60 return emptyFn; 45 61 }; 46 class ReaddirpStream extends stream_1.Readable { 62 /** Readable readdir stream, emitting new files as they're being listed. */ 63 class ReaddirpStream extends node_stream_1.Readable { 47 64 constructor(options = {}) { 48 65 super({ … … 51 68 highWaterMark: options.highWaterMark, 52 69 }); 53 const opts = { ...defaultOptions (), ...options };70 const opts = { ...defaultOptions, ...options }; 54 71 const { root, type } = opts; 55 72 this._fileFilter = normalizeFilter(opts.fileFilter); … … 63 80 this._stat = statMethod; 64 81 } 65 this._maxDepth = opts.depth ;66 this._wantsDir = DIR_TYPES.has(type);67 this._wantsFile = FILE_TYPES.has(type);68 this._wantsEverything = type === EVERYTHING_TYPE;69 this._root = (0, path_1.resolve)(root);82 this._maxDepth = opts.depth ?? defaultOptions.depth; 83 this._wantsDir = type ? DIR_TYPES.has(type) : false; 84 this._wantsFile = type ? FILE_TYPES.has(type) : false; 85 this._wantsEverything = type === exports.EntryTypes.EVERYTHING_TYPE; 86 this._root = (0, node_path_1.resolve)(root); 70 87 this._isDirent = !opts.alwaysStat; 71 88 this._statsProp = this._isDirent ? 'dirent' : 'stats'; … … 147 164 const basename = this._isDirent ? dirent.name : dirent; 148 165 try { 149 const fullPath = (0, path_1.resolve)((0,path_1.join)(path, basename));150 entry = { path: (0, path_1.relative)(this._root, fullPath), fullPath, basename };166 const fullPath = (0, node_path_1.resolve)((0, node_path_1.join)(path, basename)); 167 entry = { path: (0, node_path_1.relative)(this._root, fullPath), fullPath, basename }; 151 168 entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath); 152 169 } … … 186 203 if (entryRealPathStats.isDirectory()) { 187 204 const len = entryRealPath.length; 188 if (full.startsWith(entryRealPath) && full.substr(len, 1) === path_1.sep) {205 if (full.startsWith(entryRealPath) && full.substr(len, 1) === node_path_1.sep) { 189 206 const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`); 190 207 // @ts-ignore … … 208 225 exports.ReaddirpStream = ReaddirpStream; 209 226 /** 210 * Main function which ends up calling readdirRec and reads all files and directories in given root recursively. 227 * Streaming version: Reads all files and directories in given root recursively. 228 * Consumes ~constant small amount of RAM. 211 229 * @param root Root directory 212 230 * @param options Options to specify root (start directory), filters and recursion depth 213 231 */ 214 const readdirp = (root, options = {}) =>{232 function readdirp(root, options = {}) { 215 233 // @ts-ignore 216 234 let type = options.entryType || options.type; 217 235 if (type === 'both') 218 type = FILE_DIR_TYPE; // backwards-compatibility236 type = exports.EntryTypes.FILE_DIR_TYPE; // backwards-compatibility 219 237 if (type) 220 238 options.type = type; … … 230 248 options.root = root; 231 249 return new ReaddirpStream(options); 232 }; 233 exports.readdirp = readdirp; 234 const readdirpPromise = (root, options = {}) => { 250 } 251 /** 252 * Promise version: Reads all files and directories in given root recursively. 253 * Compared to streaming version, will consume a lot of RAM e.g. when 1 million files are listed. 254 * @returns array of paths and their entry infos 255 */ 256 function readdirpPromise(root, options = {}) { 235 257 return new Promise((resolve, reject) => { 236 258 const files = []; 237 (0, exports.readdirp)(root, options)259 readdirp(root, options) 238 260 .on('data', (entry) => files.push(entry)) 239 261 .on('end', () => resolve(files)) 240 262 .on('error', (error) => reject(error)); 241 263 }); 242 }; 243 exports.readdirpPromise = readdirpPromise; 244 exports.default = exports.readdirp; 264 } 265 exports.default = readdirp;
Note:
See TracChangeset
for help on using the changeset viewer.