Ignore:
Timestamp:
01/21/25 03:08:24 (3 days ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
0c6b92a
Message:

F4 Finalna Verzija

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
     8import readdirp from 'readdirp';
     9for 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) */
     16import type { Stats, Dirent } from 'node:fs';
     17import { Readable } from 'node:stream';
     18/** Path in file system. */
    319export type Path = string;
     20/** Emitted entry. Contains relative & absolute path, basename, and either stats or dirent. */
    421export interface EntryInfo {
    522    path: string;
     
    926    basename: string;
    1027}
     28/** Path or dir entries (files) */
    1129export type PathOrDirent = Dirent | Path;
    12 export type Tester = (path: EntryInfo) => boolean;
     30/** Filterer for files */
     31export type Tester = (entryInfo: EntryInfo) => boolean;
    1332export type Predicate = string[] | string | Tester;
    14 declare function defaultOptions(): {
     33export 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};
     39export 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 */
     48export type ReaddirpOptions = {
    1549    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;
    2357};
    24 export type ReaddirpOptions = ReturnType<typeof defaultOptions>;
     58/** Directory entry. Contains path, depth count, and files. */
    2559export interface DirEntry {
    2660    files: PathOrDirent[];
     
    2862    path: Path;
    2963}
     64/** Readable readdir stream, emitting new files as they're being listed. */
    3065export declare class ReaddirpStream extends Readable {
    3166    parents: any[];
     
    5590    _formatEntry(dirent: PathOrDirent, path: Path): Promise<EntryInfo | undefined>;
    5691    _onError(err: Error): void;
    57     _getEntryType(entry: EntryInfo): Promise<void | "" | "file" | "directory">;
     92    _getEntryType(entry: EntryInfo): Promise<void | '' | 'file' | 'directory'>;
    5893    _includeAsFile(entry: EntryInfo): boolean | undefined;
    5994}
    6095/**
    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.
    6298 * @param root Root directory
    6399 * @param options Options to specify root (start directory), filters and recursion depth
    64100 */
    65 export declare const readdirp: (root: Path, options?: Partial<ReaddirpOptions>) => ReaddirpStream;
    66 export declare const readdirpPromise: (root: Path, options?: Partial<ReaddirpOptions>) => Promise<string[]>;
     101export 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 */
     107export declare function readdirpPromise(root: Path, options?: Partial<ReaddirpOptions>): Promise<EntryInfo[]>;
    67108export 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 }
     1import { stat, lstat, readdir, realpath } from 'node:fs/promises';
     2import { Readable } from 'node:stream';
     3import { resolve as presolve, relative as prelative, join as pjoin, sep as psep } from 'node:path';
     4export const EntryTypes = {
     5    FILE_TYPE: 'files',
     6    DIR_TYPE: 'directories',
     7    FILE_DIR_TYPE: 'files_directories',
     8    EVERYTHING_TYPE: 'all',
     9};
     10const 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};
     20Object.freeze(defaultOptions);
    1621const RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR';
    1722const 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]);
     23const ALL_TYPES = [
     24    EntryTypes.DIR_TYPE,
     25    EntryTypes.EVERYTHING_TYPE,
     26    EntryTypes.FILE_DIR_TYPE,
     27    EntryTypes.FILE_TYPE,
     28];
     29const DIR_TYPES = new Set([
     30    EntryTypes.DIR_TYPE,
     31    EntryTypes.EVERYTHING_TYPE,
     32    EntryTypes.FILE_DIR_TYPE,
     33]);
     34const FILE_TYPES = new Set([
     35    EntryTypes.EVERYTHING_TYPE,
     36    EntryTypes.FILE_DIR_TYPE,
     37    EntryTypes.FILE_TYPE,
     38]);
    2539const isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
    2640const wantBigintFsStats = process.platform === 'win32';
    27 const emptyFn = (_path) => true;
     41const emptyFn = (_entryInfo) => true;
    2842const normalizeFilter = (filter) => {
    2943    if (filter === undefined)
     
    4155    return emptyFn;
    4256};
     57/** Readable readdir stream, emitting new files as they're being listed. */
    4358export class ReaddirpStream extends Readable {
    4459    constructor(options = {}) {
     
    4863            highWaterMark: options.highWaterMark,
    4964        });
    50         const opts = { ...defaultOptions(), ...options };
     65        const opts = { ...defaultOptions, ...options };
    5166        const { root, type } = opts;
    5267        this._fileFilter = normalizeFilter(opts.fileFilter);
     
    6075            this._stat = statMethod;
    6176        }
    62         this._maxDepth = opts.depth;
    63         this._wantsDir = DIR_TYPES.has(type);
    64         this._wantsFile = FILE_TYPES.has(type);
    65         this._wantsEverything = type === EVERYTHING_TYPE;
    66         this._root = pathResolve(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);
    6782        this._isDirent = !opts.alwaysStat;
    6883        this._statsProp = this._isDirent ? 'dirent' : 'stats';
     
    144159        const basename = this._isDirent ? dirent.name : dirent;
    145160        try {
    146             const fullPath = pathResolve(pathJoin(path, basename));
    147             entry = { path: pathRelative(this._root, fullPath), fullPath, basename };
     161            const fullPath = presolve(pjoin(path, basename));
     162            entry = { path: prelative(this._root, fullPath), fullPath, basename };
    148163            entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
    149164        }
     
    183198                if (entryRealPathStats.isDirectory()) {
    184199                    const len = entryRealPath.length;
    185                     if (full.startsWith(entryRealPath) && full.substr(len, 1) === pathSep) {
     200                    if (full.startsWith(entryRealPath) && full.substr(len, 1) === psep) {
    186201                        const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
    187202                        // @ts-ignore
     
    204219}
    205220/**
    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.
    207223 * @param root Root directory
    208224 * @param options Options to specify root (start directory), filters and recursion depth
    209225 */
    210 export const readdirp = (root, options = {}) => {
     226export function readdirp(root, options = {}) {
    211227    // @ts-ignore
    212228    let type = options.entryType || options.type;
    213229    if (type === 'both')
    214         type = FILE_DIR_TYPE; // backwards-compatibility
     230        type = EntryTypes.FILE_DIR_TYPE; // backwards-compatibility
    215231    if (type)
    216232        options.type = type;
     
    226242    options.root = root;
    227243    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 */
     250export function readdirpPromise(root, options = {}) {
    230251    return new Promise((resolve, reject) => {
    231252        const files = [];
     
    235256            .on('error', (error) => reject(error));
    236257    });
    237 };
     258}
    238259export default readdirp;
Note: See TracChangeset for help on using the changeset viewer.