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

F4 Finalna Verzija

File:
1 edited

Legend:

Unmodified
Added
Removed
  • imaps-frontend/node_modules/readdirp/index.js

    r0c6b92a r79a0317  
    11"use strict";
    22Object.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 }
     3exports.ReaddirpStream = exports.EntryTypes = void 0;
     4exports.readdirp = readdirp;
     5exports.readdirpPromise = readdirpPromise;
     6const promises_1 = require("node:fs/promises");
     7const node_stream_1 = require("node:stream");
     8const node_path_1 = require("node:path");
     9exports.EntryTypes = {
     10    FILE_TYPE: 'files',
     11    DIR_TYPE: 'directories',
     12    FILE_DIR_TYPE: 'files_directories',
     13    EVERYTHING_TYPE: 'all',
     14};
     15const 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};
     25Object.freeze(defaultOptions);
    1926const RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR';
    2027const 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]);
     28const ALL_TYPES = [
     29    exports.EntryTypes.DIR_TYPE,
     30    exports.EntryTypes.EVERYTHING_TYPE,
     31    exports.EntryTypes.FILE_DIR_TYPE,
     32    exports.EntryTypes.FILE_TYPE,
     33];
     34const DIR_TYPES = new Set([
     35    exports.EntryTypes.DIR_TYPE,
     36    exports.EntryTypes.EVERYTHING_TYPE,
     37    exports.EntryTypes.FILE_DIR_TYPE,
     38]);
     39const FILE_TYPES = new Set([
     40    exports.EntryTypes.EVERYTHING_TYPE,
     41    exports.EntryTypes.FILE_DIR_TYPE,
     42    exports.EntryTypes.FILE_TYPE,
     43]);
    2844const isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
    2945const wantBigintFsStats = process.platform === 'win32';
    30 const emptyFn = (_path) => true;
     46const emptyFn = (_entryInfo) => true;
    3147const normalizeFilter = (filter) => {
    3248    if (filter === undefined)
     
    4460    return emptyFn;
    4561};
    46 class ReaddirpStream extends stream_1.Readable {
     62/** Readable readdir stream, emitting new files as they're being listed. */
     63class ReaddirpStream extends node_stream_1.Readable {
    4764    constructor(options = {}) {
    4865        super({
     
    5168            highWaterMark: options.highWaterMark,
    5269        });
    53         const opts = { ...defaultOptions(), ...options };
     70        const opts = { ...defaultOptions, ...options };
    5471        const { root, type } = opts;
    5572        this._fileFilter = normalizeFilter(opts.fileFilter);
     
    6380            this._stat = statMethod;
    6481        }
    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);
    7087        this._isDirent = !opts.alwaysStat;
    7188        this._statsProp = this._isDirent ? 'dirent' : 'stats';
     
    147164        const basename = this._isDirent ? dirent.name : dirent;
    148165        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 };
    151168            entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
    152169        }
     
    186203                if (entryRealPathStats.isDirectory()) {
    187204                    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) {
    189206                        const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
    190207                        // @ts-ignore
     
    208225exports.ReaddirpStream = ReaddirpStream;
    209226/**
    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.
    211229 * @param root Root directory
    212230 * @param options Options to specify root (start directory), filters and recursion depth
    213231 */
    214 const readdirp = (root, options = {}) => {
     232function readdirp(root, options = {}) {
    215233    // @ts-ignore
    216234    let type = options.entryType || options.type;
    217235    if (type === 'both')
    218         type = FILE_DIR_TYPE; // backwards-compatibility
     236        type = exports.EntryTypes.FILE_DIR_TYPE; // backwards-compatibility
    219237    if (type)
    220238        options.type = type;
     
    230248    options.root = root;
    231249    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 */
     256function readdirpPromise(root, options = {}) {
    235257    return new Promise((resolve, reject) => {
    236258        const files = [];
    237         (0, exports.readdirp)(root, options)
     259        readdirp(root, options)
    238260            .on('data', (entry) => files.push(entry))
    239261            .on('end', () => resolve(files))
    240262            .on('error', (error) => reject(error));
    241263    });
    242 };
    243 exports.readdirpPromise = readdirpPromise;
    244 exports.default = exports.readdirp;
     264}
     265exports.default = readdirp;
Note: See TracChangeset for help on using the changeset viewer.