Changeset 79a0317 for imaps-frontend/node_modules/readdirp/esm
- Timestamp:
- 01/21/25 03:08:24 (3 days ago)
- Branches:
- main
- Parents:
- 0c6b92a
- Location:
- imaps-frontend/node_modules/readdirp/esm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/readdirp/esm/index.d.ts
r0c6b92a r79a0317 1 import type { Stats, Dirent } from 'fs'; 2 import { Readable } from 'stream'; 1 /** 2 * Recursive version of readdir. Exposes a streaming API and promise API. 3 * Streaming API allows to use a small amount of RAM. 4 * 5 * @module 6 * @example 7 ```js 8 import readdirp from 'readdirp'; 9 for await (const entry of readdirp('.')) { 10 const {path} = entry; 11 console.log(`${JSON.stringify({path})}`); 12 } 13 ``` 14 */ 15 /*! readdirp - MIT License (c) 2012-2019 Thorsten Lorenz, Paul Miller (https://paulmillr.com) */ 16 import type { Stats, Dirent } from 'node:fs'; 17 import { Readable } from 'node:stream'; 18 /** Path in file system. */ 3 19 export type Path = string; 20 /** Emitted entry. Contains relative & absolute path, basename, and either stats or dirent. */ 4 21 export interface EntryInfo { 5 22 path: string; … … 9 26 basename: string; 10 27 } 28 /** Path or dir entries (files) */ 11 29 export type PathOrDirent = Dirent | Path; 12 export type Tester = (path: EntryInfo) => boolean; 30 /** Filterer for files */ 31 export type Tester = (entryInfo: EntryInfo) => boolean; 13 32 export type Predicate = string[] | string | Tester; 14 declare function defaultOptions(): { 33 export declare const EntryTypes: { 34 readonly FILE_TYPE: "files"; 35 readonly DIR_TYPE: "directories"; 36 readonly FILE_DIR_TYPE: "files_directories"; 37 readonly EVERYTHING_TYPE: "all"; 38 }; 39 export type EntryType = (typeof EntryTypes)[keyof typeof EntryTypes]; 40 /** 41 * Options for readdirp. 42 * * type: files, directories, or both 43 * * lstat: whether to use symlink-friendly stat 44 * * depth: max depth 45 * * alwaysStat: whether to use stat (more resources) or dirent 46 * * highWaterMark: streaming param, specifies max amount of resources per entry 47 */ 48 export type ReaddirpOptions = { 15 49 root: string; 16 fileFilter : (_path: EntryInfo) => boolean;17 directoryFilter : (_path: EntryInfo) => boolean;18 type : string;19 lstat : boolean;20 depth : number;21 alwaysStat : boolean;22 highWaterMark : number;50 fileFilter?: Predicate; 51 directoryFilter?: Predicate; 52 type?: EntryType; 53 lstat?: boolean; 54 depth?: number; 55 alwaysStat?: boolean; 56 highWaterMark?: number; 23 57 }; 24 export type ReaddirpOptions = ReturnType<typeof defaultOptions>; 58 /** Directory entry. Contains path, depth count, and files. */ 25 59 export interface DirEntry { 26 60 files: PathOrDirent[]; … … 28 62 path: Path; 29 63 } 64 /** Readable readdir stream, emitting new files as they're being listed. */ 30 65 export declare class ReaddirpStream extends Readable { 31 66 parents: any[]; … … 55 90 _formatEntry(dirent: PathOrDirent, path: Path): Promise<EntryInfo | undefined>; 56 91 _onError(err: Error): void; 57 _getEntryType(entry: EntryInfo): Promise<void | "" | "file" | "directory">;92 _getEntryType(entry: EntryInfo): Promise<void | '' | 'file' | 'directory'>; 58 93 _includeAsFile(entry: EntryInfo): boolean | undefined; 59 94 } 60 95 /** 61 * Main function which ends up calling readdirRec and reads all files and directories in given root recursively. 96 * Streaming version: Reads all files and directories in given root recursively. 97 * Consumes ~constant small amount of RAM. 62 98 * @param root Root directory 63 99 * @param options Options to specify root (start directory), filters and recursion depth 64 100 */ 65 export declare const readdirp: (root: Path, options?: Partial<ReaddirpOptions>) => ReaddirpStream; 66 export declare const readdirpPromise: (root: Path, options?: Partial<ReaddirpOptions>) => Promise<string[]>; 101 export declare function readdirp(root: Path, options?: Partial<ReaddirpOptions>): ReaddirpStream; 102 /** 103 * Promise version: Reads all files and directories in given root recursively. 104 * Compared to streaming version, will consume a lot of RAM e.g. when 1 million files are listed. 105 * @returns array of paths and their entry infos 106 */ 107 export declare function readdirpPromise(root: Path, options?: Partial<ReaddirpOptions>): Promise<EntryInfo[]>; 67 108 export default readdirp; -
imaps-frontend/node_modules/readdirp/esm/index.js
r0c6b92a r79a0317 1 import { stat, lstat, readdir, realpath } from 'fs/promises'; 2 import { Readable } from 'stream'; 3 import { resolve as pathResolve, relative as pathRelative, join as pathJoin, sep as pathSep, } from 'path'; 4 function defaultOptions() { 5 return { 6 root: '.', 7 fileFilter: (_path) => true, 8 directoryFilter: (_path) => true, 9 type: FILE_TYPE, 10 lstat: false, 11 depth: 2147483648, 12 alwaysStat: false, 13 highWaterMark: 4096, 14 }; 15 } 1 import { stat, lstat, readdir, realpath } from 'node:fs/promises'; 2 import { Readable } from 'node:stream'; 3 import { resolve as presolve, relative as prelative, join as pjoin, sep as psep } from 'node:path'; 4 export const EntryTypes = { 5 FILE_TYPE: 'files', 6 DIR_TYPE: 'directories', 7 FILE_DIR_TYPE: 'files_directories', 8 EVERYTHING_TYPE: 'all', 9 }; 10 const defaultOptions = { 11 root: '.', 12 fileFilter: (_entryInfo) => true, 13 directoryFilter: (_entryInfo) => true, 14 type: EntryTypes.FILE_TYPE, 15 lstat: false, 16 depth: 2147483648, 17 alwaysStat: false, 18 highWaterMark: 4096, 19 }; 20 Object.freeze(defaultOptions); 16 21 const RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR'; 17 22 const NORMAL_FLOW_ERRORS = new Set(['ENOENT', 'EPERM', 'EACCES', 'ELOOP', RECURSIVE_ERROR_CODE]); 18 const FILE_TYPE = 'files'; 19 const DIR_TYPE = 'directories'; 20 const FILE_DIR_TYPE = 'files_directories'; 21 const EVERYTHING_TYPE = 'all'; 22 const ALL_TYPES = [FILE_TYPE, DIR_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE]; 23 const DIR_TYPES = new Set([DIR_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE]); 24 const FILE_TYPES = new Set([FILE_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE]); 23 const ALL_TYPES = [ 24 EntryTypes.DIR_TYPE, 25 EntryTypes.EVERYTHING_TYPE, 26 EntryTypes.FILE_DIR_TYPE, 27 EntryTypes.FILE_TYPE, 28 ]; 29 const DIR_TYPES = new Set([ 30 EntryTypes.DIR_TYPE, 31 EntryTypes.EVERYTHING_TYPE, 32 EntryTypes.FILE_DIR_TYPE, 33 ]); 34 const FILE_TYPES = new Set([ 35 EntryTypes.EVERYTHING_TYPE, 36 EntryTypes.FILE_DIR_TYPE, 37 EntryTypes.FILE_TYPE, 38 ]); 25 39 const isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code); 26 40 const wantBigintFsStats = process.platform === 'win32'; 27 const emptyFn = (_ path) => true;41 const emptyFn = (_entryInfo) => true; 28 42 const normalizeFilter = (filter) => { 29 43 if (filter === undefined) … … 41 55 return emptyFn; 42 56 }; 57 /** Readable readdir stream, emitting new files as they're being listed. */ 43 58 export class ReaddirpStream extends Readable { 44 59 constructor(options = {}) { … … 48 63 highWaterMark: options.highWaterMark, 49 64 }); 50 const opts = { ...defaultOptions (), ...options };65 const opts = { ...defaultOptions, ...options }; 51 66 const { root, type } = opts; 52 67 this._fileFilter = normalizeFilter(opts.fileFilter); … … 60 75 this._stat = statMethod; 61 76 } 62 this._maxDepth = opts.depth ;63 this._wantsDir = DIR_TYPES.has(type);64 this._wantsFile = FILE_TYPES.has(type);65 this._wantsEverything = type === E VERYTHING_TYPE;66 this._root = p athResolve(root);77 this._maxDepth = opts.depth ?? defaultOptions.depth; 78 this._wantsDir = type ? DIR_TYPES.has(type) : false; 79 this._wantsFile = type ? FILE_TYPES.has(type) : false; 80 this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE; 81 this._root = presolve(root); 67 82 this._isDirent = !opts.alwaysStat; 68 83 this._statsProp = this._isDirent ? 'dirent' : 'stats'; … … 144 159 const basename = this._isDirent ? dirent.name : dirent; 145 160 try { 146 const fullPath = p athResolve(pathJoin(path, basename));147 entry = { path: p athRelative(this._root, fullPath), fullPath, basename };161 const fullPath = presolve(pjoin(path, basename)); 162 entry = { path: prelative(this._root, fullPath), fullPath, basename }; 148 163 entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath); 149 164 } … … 183 198 if (entryRealPathStats.isDirectory()) { 184 199 const len = entryRealPath.length; 185 if (full.startsWith(entryRealPath) && full.substr(len, 1) === p athSep) {200 if (full.startsWith(entryRealPath) && full.substr(len, 1) === psep) { 186 201 const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`); 187 202 // @ts-ignore … … 204 219 } 205 220 /** 206 * Main function which ends up calling readdirRec and reads all files and directories in given root recursively. 221 * Streaming version: Reads all files and directories in given root recursively. 222 * Consumes ~constant small amount of RAM. 207 223 * @param root Root directory 208 224 * @param options Options to specify root (start directory), filters and recursion depth 209 225 */ 210 export const readdirp = (root, options = {}) =>{226 export function readdirp(root, options = {}) { 211 227 // @ts-ignore 212 228 let type = options.entryType || options.type; 213 229 if (type === 'both') 214 type = FILE_DIR_TYPE; // backwards-compatibility230 type = EntryTypes.FILE_DIR_TYPE; // backwards-compatibility 215 231 if (type) 216 232 options.type = type; … … 226 242 options.root = root; 227 243 return new ReaddirpStream(options); 228 }; 229 export const readdirpPromise = (root, options = {}) => { 244 } 245 /** 246 * Promise version: Reads all files and directories in given root recursively. 247 * Compared to streaming version, will consume a lot of RAM e.g. when 1 million files are listed. 248 * @returns array of paths and their entry infos 249 */ 250 export function readdirpPromise(root, options = {}) { 230 251 return new Promise((resolve, reject) => { 231 252 const files = []; … … 235 256 .on('error', (error) => reject(error)); 236 257 }); 237 } ;258 } 238 259 export default readdirp;
Note:
See TracChangeset
for help on using the changeset viewer.