package/LICENSE000664 0000002067 3560116604 010274 0ustar00000000 000000 The MIT License (MIT) Copyright (c) Denis Malinochkin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/out/providers/async.js000664 0000007146 3560116604 013571 0ustar00000000 000000 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readdir = exports.readdirWithFileTypes = exports.read = void 0; const fsStat = require("@nodelib/fs.stat"); const rpl = require("run-parallel"); const constants_1 = require("../constants"); const utils = require("../utils"); const common = require("./common"); function read(directory, settings, callback) { if (!settings.stats && constants_1.IS_SUPPORT_READDIR_WITH_FILE_TYPES) { readdirWithFileTypes(directory, settings, callback); return; } readdir(directory, settings, callback); } exports.read = read; function readdirWithFileTypes(directory, settings, callback) { settings.fs.readdir(directory, { withFileTypes: true }, (readdirError, dirents) => { if (readdirError !== null) { callFailureCallback(callback, readdirError); return; } const entries = dirents.map((dirent) => ({ dirent, name: dirent.name, path: common.joinPathSegments(directory, dirent.name, settings.pathSegmentSeparator) })); if (!settings.followSymbolicLinks) { callSuccessCallback(callback, entries); return; } const tasks = entries.map((entry) => makeRplTaskEntry(entry, settings)); rpl(tasks, (rplError, rplEntries) => { if (rplError !== null) { callFailureCallback(callback, rplError); return; } callSuccessCallback(callback, rplEntries); }); }); } exports.readdirWithFileTypes = readdirWithFileTypes; function makeRplTaskEntry(entry, settings) { return (done) => { if (!entry.dirent.isSymbolicLink()) { done(null, entry); return; } settings.fs.stat(entry.path, (statError, stats) => { if (statError !== null) { if (settings.throwErrorOnBrokenSymbolicLink) { done(statError); return; } done(null, entry); return; } entry.dirent = utils.fs.createDirentFromStats(entry.name, stats); done(null, entry); }); }; } function readdir(directory, settings, callback) { settings.fs.readdir(directory, (readdirError, names) => { if (readdirError !== null) { callFailureCallback(callback, readdirError); return; } const tasks = names.map((name) => { const path = common.joinPathSegments(directory, name, settings.pathSegmentSeparator); return (done) => { fsStat.stat(path, settings.fsStatSettings, (error, stats) => { if (error !== null) { done(error); return; } const entry = { name, path, dirent: utils.fs.createDirentFromStats(name, stats) }; if (settings.stats) { entry.stats = stats; } done(null, entry); }); }; }); rpl(tasks, (rplError, entries) => { if (rplError !== null) { callFailureCallback(callback, rplError); return; } callSuccessCallback(callback, entries); }); }); } exports.readdir = readdir; function callFailureCallback(callback, error) { callback(error); } function callSuccessCallback(callback, result) { callback(null, result); } package/out/providers/common.js000664 0000000643 3560116604 013737 0ustar00000000 000000 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.joinPathSegments = void 0; function joinPathSegments(a, b, separator) { /** * The correct handling of cases when the first segment is a root (`/`, `C:/`) or UNC path (`//?/C:/`). */ if (a.endsWith(separator)) { return a + b; } return a + separator + b; } exports.joinPathSegments = joinPathSegments; package/out/constants.js000664 0000001736 3560116604 012452 0ustar00000000 000000 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IS_SUPPORT_READDIR_WITH_FILE_TYPES = void 0; const NODE_PROCESS_VERSION_PARTS = process.versions.node.split('.'); if (NODE_PROCESS_VERSION_PARTS[0] === undefined || NODE_PROCESS_VERSION_PARTS[1] === undefined) { throw new Error(`Unexpected behavior. The 'process.versions.node' variable has invalid value: ${process.versions.node}`); } const MAJOR_VERSION = Number.parseInt(NODE_PROCESS_VERSION_PARTS[0], 10); const MINOR_VERSION = Number.parseInt(NODE_PROCESS_VERSION_PARTS[1], 10); const SUPPORTED_MAJOR_VERSION = 10; const SUPPORTED_MINOR_VERSION = 10; const IS_MATCHED_BY_MAJOR = MAJOR_VERSION > SUPPORTED_MAJOR_VERSION; const IS_MATCHED_BY_MAJOR_AND_MINOR = MAJOR_VERSION === SUPPORTED_MAJOR_VERSION && MINOR_VERSION >= SUPPORTED_MINOR_VERSION; /** * IS `true` for Node.js 10.10 and greater. */ exports.IS_SUPPORT_READDIR_WITH_FILE_TYPES = IS_MATCHED_BY_MAJOR || IS_MATCHED_BY_MAJOR_AND_MINOR; package/out/adapters/fs.js000664 0000001200 3560116604 012633 0ustar00000000 000000 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0; const fs = require("fs"); exports.FILE_SYSTEM_ADAPTER = { lstat: fs.lstat, stat: fs.stat, lstatSync: fs.lstatSync, statSync: fs.statSync, readdir: fs.readdir, readdirSync: fs.readdirSync }; function createFileSystemAdapter(fsMethods) { if (fsMethods === undefined) { return exports.FILE_SYSTEM_ADAPTER; } return Object.assign(Object.assign({}, exports.FILE_SYSTEM_ADAPTER), fsMethods); } exports.createFileSystemAdapter = createFileSystemAdapter; package/out/utils/fs.js000664 0000001364 3560116604 012203 0ustar00000000 000000 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createDirentFromStats = void 0; class DirentFromStats { constructor(name, stats) { this.name = name; this.isBlockDevice = stats.isBlockDevice.bind(stats); this.isCharacterDevice = stats.isCharacterDevice.bind(stats); this.isDirectory = stats.isDirectory.bind(stats); this.isFIFO = stats.isFIFO.bind(stats); this.isFile = stats.isFile.bind(stats); this.isSocket = stats.isSocket.bind(stats); this.isSymbolicLink = stats.isSymbolicLink.bind(stats); } } function createDirentFromStats(name, stats) { return new DirentFromStats(name, stats); } exports.createDirentFromStats = createDirentFromStats; package/out/index.js000664 0000001761 3560116604 011543 0ustar00000000 000000 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Settings = exports.scandirSync = exports.scandir = void 0; const async = require("./providers/async"); const sync = require("./providers/sync"); const settings_1 = require("./settings"); exports.Settings = settings_1.default; function scandir(path, optionsOrSettingsOrCallback, callback) { if (typeof optionsOrSettingsOrCallback === 'function') { async.read(path, getSettings(), optionsOrSettingsOrCallback); return; } async.read(path, getSettings(optionsOrSettingsOrCallback), callback); } exports.scandir = scandir; function scandirSync(path, optionsOrSettings) { const settings = getSettings(optionsOrSettings); return sync.read(path, settings); } exports.scandirSync = scandirSync; function getSettings(settingsOrOptions = {}) { if (settingsOrOptions instanceof settings_1.default) { return settingsOrOptions; } return new settings_1.default(settingsOrOptions); } package/out/types/index.js000664 0000000115 3560116604 012677 0ustar00000000 000000 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); package/out/utils/index.js000664 0000000217 3560116604 012676 0ustar00000000 000000 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fs = void 0; const fs = require("./fs"); exports.fs = fs; package/out/settings.js000664 0000002064 3560116604 012271 0ustar00000000 000000 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const path = require("path"); const fsStat = require("@nodelib/fs.stat"); const fs = require("./adapters/fs"); class Settings { constructor(_options = {}) { this._options = _options; this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, false); this.fs = fs.createFileSystemAdapter(this._options.fs); this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path.sep); this.stats = this._getValue(this._options.stats, false); this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true); this.fsStatSettings = new fsStat.Settings({ followSymbolicLink: this.followSymbolicLinks, fs: this.fs, throwErrorOnBrokenSymbolicLink: this.throwErrorOnBrokenSymbolicLink }); } _getValue(option, value) { return option !== null && option !== void 0 ? option : value; } } exports.default = Settings; package/out/providers/sync.js000664 0000003706 3560116604 013426 0ustar00000000 000000 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readdir = exports.readdirWithFileTypes = exports.read = void 0; const fsStat = require("@nodelib/fs.stat"); const constants_1 = require("../constants"); const utils = require("../utils"); const common = require("./common"); function read(directory, settings) { if (!settings.stats && constants_1.IS_SUPPORT_READDIR_WITH_FILE_TYPES) { return readdirWithFileTypes(directory, settings); } return readdir(directory, settings); } exports.read = read; function readdirWithFileTypes(directory, settings) { const dirents = settings.fs.readdirSync(directory, { withFileTypes: true }); return dirents.map((dirent) => { const entry = { dirent, name: dirent.name, path: common.joinPathSegments(directory, dirent.name, settings.pathSegmentSeparator) }; if (entry.dirent.isSymbolicLink() && settings.followSymbolicLinks) { try { const stats = settings.fs.statSync(entry.path); entry.dirent = utils.fs.createDirentFromStats(entry.name, stats); } catch (error) { if (settings.throwErrorOnBrokenSymbolicLink) { throw error; } } } return entry; }); } exports.readdirWithFileTypes = readdirWithFileTypes; function readdir(directory, settings) { const names = settings.fs.readdirSync(directory); return names.map((name) => { const entryPath = common.joinPathSegments(directory, name, settings.pathSegmentSeparator); const stats = fsStat.statSync(entryPath, settings.fsStatSettings); const entry = { name, path: entryPath, dirent: utils.fs.createDirentFromStats(name, stats) }; if (settings.stats) { entry.stats = stats; } return entry; }); } exports.readdir = readdir; package/package.json000664 0000002213 3560116604 011546 0ustar00000000 000000 { "name": "@nodelib/fs.scandir", "version": "2.1.5", "description": "List files and directories inside the specified directory", "license": "MIT", "repository": "https://github.com/nodelib/nodelib/tree/master/packages/fs/fs.scandir", "keywords": [ "NodeLib", "fs", "FileSystem", "file system", "scandir", "readdir", "dirent" ], "engines": { "node": ">= 8" }, "files": [ "out/**", "!out/**/*.map", "!out/**/*.spec.*" ], "main": "out/index.js", "typings": "out/index.d.ts", "scripts": { "clean": "rimraf {tsconfig.tsbuildinfo,out}", "lint": "eslint \"src/**/*.ts\" --cache", "compile": "tsc -b .", "compile:watch": "tsc -p . --watch --sourceMap", "test": "mocha \"out/**/*.spec.js\" -s 0", "build": "npm run clean && npm run compile && npm run lint && npm test", "watch": "npm run clean && npm run compile:watch" }, "dependencies": { "@nodelib/fs.stat": "2.0.5", "run-parallel": "^1.1.9" }, "devDependencies": { "@nodelib/fs.macchiato": "1.0.4", "@types/run-parallel": "^1.1.0" }, "gitHead": "d6a7960d5281d3dd5f8e2efba49bb552d090f562" } package/README.md000664 0000011537 3560116604 010550 0ustar00000000 000000 # @nodelib/fs.scandir > List files and directories inside the specified directory. ## :bulb: Highlights The package is aimed at obtaining information about entries in the directory. * :moneybag: Returns useful information: `name`, `path`, `dirent` and `stats` (optional). * :gear: On Node.js 10.10+ uses the mechanism without additional calls to determine the entry type. See [`old` and `modern` mode](#old-and-modern-mode). * :link: Can safely work with broken symbolic links. ## Install ```console npm install @nodelib/fs.scandir ``` ## Usage ```ts import * as fsScandir from '@nodelib/fs.scandir'; fsScandir.scandir('path', (error, stats) => { /* … */ }); ``` ## API ### .scandir(path, [optionsOrSettings], callback) Returns an array of plain objects ([`Entry`](#entry)) with information about entry for provided path with standard callback-style. ```ts fsScandir.scandir('path', (error, entries) => { /* … */ }); fsScandir.scandir('path', {}, (error, entries) => { /* … */ }); fsScandir.scandir('path', new fsScandir.Settings(), (error, entries) => { /* … */ }); ``` ### .scandirSync(path, [optionsOrSettings]) Returns an array of plain objects ([`Entry`](#entry)) with information about entry for provided path. ```ts const entries = fsScandir.scandirSync('path'); const entries = fsScandir.scandirSync('path', {}); const entries = fsScandir.scandirSync(('path', new fsScandir.Settings()); ``` #### path * Required: `true` * Type: `string | Buffer | URL` A path to a file. If a URL is provided, it must use the `file:` protocol. #### optionsOrSettings * Required: `false` * Type: `Options | Settings` * Default: An instance of `Settings` class An [`Options`](#options) object or an instance of [`Settings`](#settingsoptions) class. > :book: When you pass a plain object, an instance of the `Settings` class will be created automatically. If you plan to call the method frequently, use a pre-created instance of the `Settings` class. ### Settings([options]) A class of full settings of the package. ```ts const settings = new fsScandir.Settings({ followSymbolicLinks: false }); const entries = fsScandir.scandirSync('path', settings); ``` ## Entry * `name` — The name of the entry (`unknown.txt`). * `path` — The path of the entry relative to call directory (`root/unknown.txt`). * `dirent` — An instance of [`fs.Dirent`](./src/types/index.ts) class. On Node.js below 10.10 will be emulated by [`DirentFromStats`](./src/utils/fs.ts) class. * `stats` (optional) — An instance of `fs.Stats` class. For example, the `scandir` call for `tools` directory with one directory inside: ```ts { dirent: Dirent { name: 'typedoc', /* … */ }, name: 'typedoc', path: 'tools/typedoc' } ``` ## Options ### stats * Type: `boolean` * Default: `false` Adds an instance of `fs.Stats` class to the [`Entry`](#entry). > :book: Always use `fs.readdir` without the `withFileTypes` option. ??TODO?? ### followSymbolicLinks * Type: `boolean` * Default: `false` Follow symbolic links or not. Call `fs.stat` on symbolic link if `true`. ### `throwErrorOnBrokenSymbolicLink` * Type: `boolean` * Default: `true` Throw an error when symbolic link is broken if `true` or safely use `lstat` call if `false`. ### `pathSegmentSeparator` * Type: `string` * Default: `path.sep` By default, this package uses the correct path separator for your OS (`\` on Windows, `/` on Unix-like systems). But you can set this option to any separator character(s) that you want to use instead. ### `fs` * Type: [`FileSystemAdapter`](./src/adapters/fs.ts) * Default: A default FS methods By default, the built-in Node.js module (`fs`) is used to work with the file system. You can replace any method with your own. ```ts interface FileSystemAdapter { lstat?: typeof fs.lstat; stat?: typeof fs.stat; lstatSync?: typeof fs.lstatSync; statSync?: typeof fs.statSync; readdir?: typeof fs.readdir; readdirSync?: typeof fs.readdirSync; } const settings = new fsScandir.Settings({ fs: { lstat: fakeLstat } }); ``` ## `old` and `modern` mode This package has two modes that are used depending on the environment and parameters of use. ### old * Node.js below `10.10` or when the `stats` option is enabled When working in the old mode, the directory is read first (`fs.readdir`), then the type of entries is determined (`fs.lstat` and/or `fs.stat` for symbolic links). ### modern * Node.js 10.10+ and the `stats` option is disabled In the modern mode, reading the directory (`fs.readdir` with the `withFileTypes` option) is combined with obtaining information about its entries. An additional call for symbolic links (`fs.stat`) is still present. This mode makes fewer calls to the file system. It's faster. ## Changelog See the [Releases section of our GitHub project](https://github.com/nodelib/nodelib/releases) for changelog for each release version. ## License This software is released under the terms of the MIT license. package/out/providers/async.d.ts000664 0000001014 3560116604 014011 0ustar00000000 000000 /// import type Settings from '../settings'; import type { Entry } from '../types'; export declare type AsyncCallback = (error: NodeJS.ErrnoException, entries: Entry[]) => void; export declare function read(directory: string, settings: Settings, callback: AsyncCallback): void; export declare function readdirWithFileTypes(directory: string, settings: Settings, callback: AsyncCallback): void; export declare function readdir(directory: string, settings: Settings, callback: AsyncCallback): void; package/out/providers/common.d.ts000664 0000000133 3560116604 014165 0ustar00000000 000000 export declare function joinPathSegments(a: string, b: string, separator: string): string; package/out/constants.d.ts000664 0000000166 3560116604 012702 0ustar00000000 000000 /** * IS `true` for Node.js 10.10 and greater. */ export declare const IS_SUPPORT_READDIR_WITH_FILE_TYPES: boolean; package/out/adapters/fs.d.ts000664 0000001556 3560116604 013105 0ustar00000000 000000 import type * as fsStat from '@nodelib/fs.stat'; import type { Dirent, ErrnoException } from '../types'; export interface ReaddirAsynchronousMethod { (filepath: string, options: { withFileTypes: true; }, callback: (error: ErrnoException | null, files: Dirent[]) => void): void; (filepath: string, callback: (error: ErrnoException | null, files: string[]) => void): void; } export interface ReaddirSynchronousMethod { (filepath: string, options: { withFileTypes: true; }): Dirent[]; (filepath: string): string[]; } export declare type FileSystemAdapter = fsStat.FileSystemAdapter & { readdir: ReaddirAsynchronousMethod; readdirSync: ReaddirSynchronousMethod; }; export declare const FILE_SYSTEM_ADAPTER: FileSystemAdapter; export declare function createFileSystemAdapter(fsMethods?: Partial): FileSystemAdapter; package/out/utils/fs.d.ts000664 0000000202 3560116604 012425 0ustar00000000 000000 import type { Dirent, Stats } from '../types'; export declare function createDirentFromStats(name: string, stats: Stats): Dirent; package/out/index.d.ts000664 0000001527 3560116604 011777 0ustar00000000 000000 import type { FileSystemAdapter, ReaddirAsynchronousMethod, ReaddirSynchronousMethod } from './adapters/fs'; import * as async from './providers/async'; import Settings, { Options } from './settings'; import type { Dirent, Entry } from './types'; declare type AsyncCallback = async.AsyncCallback; declare function scandir(path: string, callback: AsyncCallback): void; declare function scandir(path: string, optionsOrSettings: Options | Settings, callback: AsyncCallback): void; declare namespace scandir { function __promisify__(path: string, optionsOrSettings?: Options | Settings): Promise; } declare function scandirSync(path: string, optionsOrSettings?: Options | Settings): Entry[]; export { scandir, scandirSync, Settings, AsyncCallback, Dirent, Entry, FileSystemAdapter, ReaddirAsynchronousMethod, ReaddirSynchronousMethod, Options }; package/out/types/index.d.ts000664 0000001022 3560116604 013131 0ustar00000000 000000 /// import type * as fs from 'fs'; export interface Entry { dirent: Dirent; name: string; path: string; stats?: Stats; } export declare type Stats = fs.Stats; export declare type ErrnoException = NodeJS.ErrnoException; export interface Dirent { isBlockDevice: () => boolean; isCharacterDevice: () => boolean; isDirectory: () => boolean; isFIFO: () => boolean; isFile: () => boolean; isSocket: () => boolean; isSymbolicLink: () => boolean; name: string; } package/out/utils/index.d.ts000664 0000000053 3560116604 013130 0ustar00000000 000000 import * as fs from './fs'; export { fs }; package/out/settings.d.ts000664 0000001232 3560116604 012521 0ustar00000000 000000 import * as fsStat from '@nodelib/fs.stat'; import * as fs from './adapters/fs'; export interface Options { followSymbolicLinks?: boolean; fs?: Partial; pathSegmentSeparator?: string; stats?: boolean; throwErrorOnBrokenSymbolicLink?: boolean; } export default class Settings { private readonly _options; readonly followSymbolicLinks: boolean; readonly fs: fs.FileSystemAdapter; readonly pathSegmentSeparator: string; readonly stats: boolean; readonly throwErrorOnBrokenSymbolicLink: boolean; readonly fsStatSettings: fsStat.Settings; constructor(_options?: Options); private _getValue; } package/out/providers/sync.d.ts000664 0000000515 3560116604 013655 0ustar00000000 000000 import type Settings from '../settings'; import type { Entry } from '../types'; export declare function read(directory: string, settings: Settings): Entry[]; export declare function readdirWithFileTypes(directory: string, settings: Settings): Entry[]; export declare function readdir(directory: string, settings: Settings): Entry[];