@nodelib/fs.walk
Advanced tools
Comparing version 1.2.8 to 2.0.0
@@ -1,14 +0,6 @@ | ||
/// <reference types="node" /> | ||
import type { Readable } from 'stream'; | ||
import type { Dirent, FileSystemAdapter } from '@nodelib/fs.scandir'; | ||
import { AsyncCallback } from './providers/async'; | ||
import Settings, { DeepFilterFunction, EntryFilterFunction, ErrorFilterFunction, Options } from './settings'; | ||
import type { Entry } from './types'; | ||
declare function walk(directory: string, callback: AsyncCallback): void; | ||
declare function walk(directory: string, optionsOrSettings: Options | Settings, callback: AsyncCallback): void; | ||
declare namespace walk { | ||
function __promisify__(directory: string, optionsOrSettings?: Options | Settings): Promise<Entry[]>; | ||
} | ||
declare function walkSync(directory: string, optionsOrSettings?: Options | Settings): Entry[]; | ||
declare function walkStream(directory: string, optionsOrSettings?: Options | Settings): Readable; | ||
export { walk, walkSync, walkStream, Settings, AsyncCallback, Dirent, Entry, FileSystemAdapter, Options, DeepFilterFunction, EntryFilterFunction, ErrorFilterFunction }; | ||
export { walk, walkStream, walkSync } from './walk'; | ||
export { Settings } from './settings'; | ||
export type { Dirent, FileSystemAdapter } from '@nodelib/fs.scandir'; | ||
export type { DeepFilterFunction, ErrorFilterFunction, EntryFilterFunction, Options } from './settings'; | ||
export type { AsyncCallback } from './providers/async'; | ||
export type { Entry } from './types'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Settings = exports.walkStream = exports.walkSync = exports.walk = void 0; | ||
const async_1 = require("./providers/async"); | ||
const stream_1 = require("./providers/stream"); | ||
const sync_1 = require("./providers/sync"); | ||
const settings_1 = require("./settings"); | ||
exports.Settings = settings_1.default; | ||
function walk(directory, optionsOrSettingsOrCallback, callback) { | ||
if (typeof optionsOrSettingsOrCallback === 'function') { | ||
new async_1.default(directory, getSettings()).read(optionsOrSettingsOrCallback); | ||
return; | ||
} | ||
new async_1.default(directory, getSettings(optionsOrSettingsOrCallback)).read(callback); | ||
} | ||
exports.walk = walk; | ||
function walkSync(directory, optionsOrSettings) { | ||
const settings = getSettings(optionsOrSettings); | ||
const provider = new sync_1.default(directory, settings); | ||
return provider.read(); | ||
} | ||
exports.walkSync = walkSync; | ||
function walkStream(directory, optionsOrSettings) { | ||
const settings = getSettings(optionsOrSettings); | ||
const provider = new stream_1.default(directory, settings); | ||
return provider.read(); | ||
} | ||
exports.walkStream = walkStream; | ||
function getSettings(settingsOrOptions = {}) { | ||
if (settingsOrOptions instanceof settings_1.default) { | ||
return settingsOrOptions; | ||
} | ||
return new settings_1.default(settingsOrOptions); | ||
} | ||
exports.Settings = exports.walkSync = exports.walkStream = exports.walk = void 0; | ||
var walk_1 = require("./walk"); | ||
Object.defineProperty(exports, "walk", { enumerable: true, get: function () { return walk_1.walk; } }); | ||
Object.defineProperty(exports, "walkStream", { enumerable: true, get: function () { return walk_1.walkStream; } }); | ||
Object.defineProperty(exports, "walkSync", { enumerable: true, get: function () { return walk_1.walkSync; } }); | ||
var settings_1 = require("./settings"); | ||
Object.defineProperty(exports, "Settings", { enumerable: true, get: function () { return settings_1.Settings; } }); |
@@ -1,12 +0,8 @@ | ||
import AsyncReader from '../readers/async'; | ||
import type Settings from '../settings'; | ||
import type { Entry, Errno } from '../types'; | ||
export declare type AsyncCallback = (error: Errno, entries: Entry[]) => void; | ||
export default class AsyncProvider { | ||
private readonly _root; | ||
private readonly _settings; | ||
protected readonly _reader: AsyncReader; | ||
private readonly _storage; | ||
constructor(_root: string, _settings: Settings); | ||
read(callback: AsyncCallback): void; | ||
import type { IAsyncReader } from '../readers'; | ||
import type { Entry, ErrnoException } from '../types'; | ||
export type AsyncCallback = (error: ErrnoException | null, entries: Entry[]) => void; | ||
export declare class AsyncProvider { | ||
#private; | ||
constructor(reader: IAsyncReader); | ||
read(root: string, callback: AsyncCallback): void; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const async_1 = require("../readers/async"); | ||
exports.AsyncProvider = void 0; | ||
class AsyncProvider { | ||
constructor(_root, _settings) { | ||
this._root = _root; | ||
this._settings = _settings; | ||
this._reader = new async_1.default(this._root, this._settings); | ||
this._storage = []; | ||
#reader; | ||
constructor(reader) { | ||
this.#reader = reader; | ||
} | ||
read(callback) { | ||
this._reader.onError((error) => { | ||
read(root, callback) { | ||
const entries = []; | ||
this.#reader.onError((error) => { | ||
callFailureCallback(callback, error); | ||
}); | ||
this._reader.onEntry((entry) => { | ||
this._storage.push(entry); | ||
this.#reader.onEntry((entry) => { | ||
entries.push(entry); | ||
}); | ||
this._reader.onEnd(() => { | ||
callSuccessCallback(callback, this._storage); | ||
this.#reader.onEnd(() => { | ||
callSuccessCallback(callback, entries); | ||
}); | ||
this._reader.read(); | ||
this.#reader.read(root); | ||
} | ||
} | ||
exports.default = AsyncProvider; | ||
exports.AsyncProvider = AsyncProvider; | ||
function callFailureCallback(callback, error) { | ||
@@ -26,0 +25,0 @@ callback(error); |
@@ -1,4 +0,3 @@ | ||
import AsyncProvider from './async'; | ||
import StreamProvider from './stream'; | ||
import SyncProvider from './sync'; | ||
export { AsyncProvider, StreamProvider, SyncProvider }; | ||
export * from './async'; | ||
export * from './stream'; | ||
export * from './sync'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SyncProvider = exports.StreamProvider = exports.AsyncProvider = void 0; | ||
const async_1 = require("./async"); | ||
exports.AsyncProvider = async_1.default; | ||
const stream_1 = require("./stream"); | ||
exports.StreamProvider = stream_1.default; | ||
const sync_1 = require("./sync"); | ||
exports.SyncProvider = sync_1.default; | ||
__exportStar(require("./async"), exports); | ||
__exportStar(require("./stream"), exports); | ||
__exportStar(require("./sync"), exports); |
/// <reference types="node" /> | ||
import { Readable } from 'stream'; | ||
import AsyncReader from '../readers/async'; | ||
import type Settings from '../settings'; | ||
export default class StreamProvider { | ||
private readonly _root; | ||
private readonly _settings; | ||
protected readonly _reader: AsyncReader; | ||
protected readonly _stream: Readable; | ||
constructor(_root: string, _settings: Settings); | ||
read(): Readable; | ||
import { Readable } from 'node:stream'; | ||
import type { IAsyncReader } from '../readers'; | ||
export declare class StreamProvider { | ||
#private; | ||
constructor(reader: IAsyncReader); | ||
read(root: string): Readable; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const stream_1 = require("stream"); | ||
const async_1 = require("../readers/async"); | ||
exports.StreamProvider = void 0; | ||
const node_stream_1 = require("node:stream"); | ||
class StreamProvider { | ||
constructor(_root, _settings) { | ||
this._root = _root; | ||
this._settings = _settings; | ||
this._reader = new async_1.default(this._root, this._settings); | ||
this._stream = new stream_1.Readable({ | ||
#reader; | ||
#stream; | ||
constructor(reader) { | ||
this.#reader = reader; | ||
this.#stream = this.#createOutputStream(); | ||
} | ||
read(root) { | ||
this.#reader.onError((error) => { | ||
this.#stream.emit('error', error); | ||
}); | ||
this.#reader.onEntry((entry) => { | ||
this.#stream.push(entry); | ||
}); | ||
this.#reader.onEnd(() => { | ||
this.#stream.push(null); | ||
}); | ||
this.#reader.read(root); | ||
return this.#stream; | ||
} | ||
#createOutputStream() { | ||
return new node_stream_1.Readable({ | ||
objectMode: true, | ||
read: () => { }, | ||
destroy: () => { | ||
if (!this._reader.isDestroyed) { | ||
this._reader.destroy(); | ||
if (!this.#reader.isDestroyed) { | ||
this.#reader.destroy(); | ||
} | ||
} | ||
}, | ||
}); | ||
} | ||
read() { | ||
this._reader.onError((error) => { | ||
this._stream.emit('error', error); | ||
}); | ||
this._reader.onEntry((entry) => { | ||
this._stream.push(entry); | ||
}); | ||
this._reader.onEnd(() => { | ||
this._stream.push(null); | ||
}); | ||
this._reader.read(); | ||
return this._stream; | ||
} | ||
} | ||
exports.default = StreamProvider; | ||
exports.StreamProvider = StreamProvider; |
@@ -1,10 +0,7 @@ | ||
import SyncReader from '../readers/sync'; | ||
import type Settings from '../settings'; | ||
import type { ISyncReader } from '../readers'; | ||
import type { Entry } from '../types'; | ||
export default class SyncProvider { | ||
private readonly _root; | ||
private readonly _settings; | ||
protected readonly _reader: SyncReader; | ||
constructor(_root: string, _settings: Settings); | ||
read(): Entry[]; | ||
export declare class SyncProvider { | ||
#private; | ||
constructor(reader: ISyncReader); | ||
read(root: string): Entry[]; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const sync_1 = require("../readers/sync"); | ||
exports.SyncProvider = void 0; | ||
class SyncProvider { | ||
constructor(_root, _settings) { | ||
this._root = _root; | ||
this._settings = _settings; | ||
this._reader = new sync_1.default(this._root, this._settings); | ||
#reader; | ||
constructor(reader) { | ||
this.#reader = reader; | ||
} | ||
read() { | ||
return this._reader.read(); | ||
read(root) { | ||
return this.#reader.read(root); | ||
} | ||
} | ||
exports.default = SyncProvider; | ||
exports.SyncProvider = SyncProvider; |
@@ -1,30 +0,28 @@ | ||
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
import * as fsScandir from '@nodelib/fs.scandir'; | ||
import type Settings from '../settings'; | ||
import type { Entry, Errno } from '../types'; | ||
import Reader from './reader'; | ||
declare type EntryEventCallback = (entry: Entry) => void; | ||
declare type ErrorEventCallback = (error: Errno) => void; | ||
declare type EndEventCallback = () => void; | ||
export default class AsyncReader extends Reader { | ||
protected readonly _settings: Settings; | ||
protected readonly _scandir: typeof fsScandir.scandir; | ||
protected readonly _emitter: EventEmitter; | ||
private readonly _queue; | ||
private _isFatalError; | ||
private _isDestroyed; | ||
constructor(_root: string, _settings: Settings); | ||
read(): EventEmitter; | ||
get isDestroyed(): boolean; | ||
destroy(): void; | ||
import type { IFileSystemAdapter } from '../adapters/fs'; | ||
import type { Settings } from '../settings'; | ||
import type { EndEventCallback, Entry, EntryEventCallback, ErrorEventCallback } from '../types'; | ||
export interface IAsyncReader { | ||
isDestroyed: boolean; | ||
onError: (callback: ErrorEventCallback) => void; | ||
onEntry: (callback: EntryEventCallback) => void; | ||
onEnd: (callback: EndEventCallback) => void; | ||
read: (root: string) => void; | ||
destroy: () => void; | ||
} | ||
declare class AsyncReaderEmitter { | ||
#private; | ||
onEntry(callback: EntryEventCallback): void; | ||
onError(callback: ErrorEventCallback): void; | ||
onEnd(callback: EndEventCallback): void; | ||
private _pushToQueue; | ||
private _worker; | ||
private _handleError; | ||
private _handleEntry; | ||
private _emitEntry; | ||
protected _emitEntry(entry: Entry): void; | ||
protected _emitEnd(): void; | ||
protected _emitError(error: Error): void; | ||
} | ||
export declare class AsyncReader extends AsyncReaderEmitter implements IAsyncReader { | ||
#private; | ||
constructor(fs: IFileSystemAdapter, settings: Settings); | ||
read(root: string): void; | ||
get isDestroyed(): boolean; | ||
destroy(): void; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const events_1 = require("events"); | ||
const fsScandir = require("@nodelib/fs.scandir"); | ||
exports.AsyncReader = void 0; | ||
const node_events_1 = require("node:events"); | ||
const fastq = require("fastq"); | ||
const common = require("./common"); | ||
const reader_1 = require("./reader"); | ||
class AsyncReader extends reader_1.default { | ||
constructor(_root, _settings) { | ||
super(_root, _settings); | ||
this._settings = _settings; | ||
this._scandir = fsScandir.scandir; | ||
this._emitter = new events_1.EventEmitter(); | ||
this._queue = fastq(this._worker.bind(this), this._settings.concurrency); | ||
this._isFatalError = false; | ||
this._isDestroyed = false; | ||
this._queue.drain = () => { | ||
if (!this._isFatalError) { | ||
this._emitter.emit('end'); | ||
class AsyncReaderEmitter { | ||
#emitter = new node_events_1.EventEmitter(); | ||
onEntry(callback) { | ||
this.#emitter.on('entry', callback); | ||
} | ||
onError(callback) { | ||
this.#emitter.once('error', callback); | ||
} | ||
onEnd(callback) { | ||
this.#emitter.once('end', callback); | ||
} | ||
_emitEntry(entry) { | ||
this.#emitter.emit('entry', entry); | ||
} | ||
_emitEnd() { | ||
this.#emitter.emit('end'); | ||
} | ||
_emitError(error) { | ||
this.#emitter.emit('error', error); | ||
} | ||
} | ||
class AsyncReader extends AsyncReaderEmitter { | ||
#isFatalError = false; | ||
#isDestroyed = false; | ||
#fs; | ||
#settings; | ||
#queue; | ||
constructor(fs, settings) { | ||
super(); | ||
const queue = fastq(this.#worker.bind(this), settings.concurrency); | ||
queue.drain = () => { | ||
if (!this.#isFatalError) { | ||
this._emitEnd(); | ||
} | ||
}; | ||
this.#fs = fs; | ||
this.#settings = settings; | ||
this.#queue = queue; | ||
} | ||
read() { | ||
this._isFatalError = false; | ||
this._isDestroyed = false; | ||
setImmediate(() => { | ||
this._pushToQueue(this._root, this._settings.basePath); | ||
}); | ||
return this._emitter; | ||
read(root) { | ||
this.#isFatalError = false; | ||
this.#isDestroyed = false; | ||
const directory = common.replacePathSegmentSeparator(root, this.#settings.pathSegmentSeparator); | ||
this.#pushToQueue(directory, this.#settings.basePath); | ||
} | ||
get isDestroyed() { | ||
return this._isDestroyed; | ||
return this.#isDestroyed; | ||
} | ||
destroy() { | ||
if (this._isDestroyed) { | ||
throw new Error('The reader is already destroyed'); | ||
if (this.#isDestroyed) { | ||
return; | ||
} | ||
this._isDestroyed = true; | ||
this._queue.killAndDrain(); | ||
this.#isDestroyed = true; | ||
this.#queue.killAndDrain(); | ||
} | ||
onEntry(callback) { | ||
this._emitter.on('entry', callback); | ||
} | ||
onError(callback) { | ||
this._emitter.once('error', callback); | ||
} | ||
onEnd(callback) { | ||
this._emitter.once('end', callback); | ||
} | ||
_pushToQueue(directory, base) { | ||
const queueItem = { directory, base }; | ||
this._queue.push(queueItem, (error) => { | ||
#pushToQueue(directory, base) { | ||
this.#queue.push({ directory, base }, (error) => { | ||
if (error !== null) { | ||
this._handleError(error); | ||
this.#handleError(error); | ||
} | ||
}); | ||
} | ||
_worker(item, done) { | ||
this._scandir(item.directory, this._settings.fsScandirSettings, (error, entries) => { | ||
#worker(item, done) { | ||
this.#fs.scandir(item.directory, this.#settings.fsScandirSettings, (error, entries) => { | ||
if (error !== null) { | ||
@@ -65,3 +76,3 @@ done(error, undefined); | ||
for (const entry of entries) { | ||
this._handleEntry(entry, item.base); | ||
this.#handleEntry(entry, item.base); | ||
} | ||
@@ -71,12 +82,12 @@ done(null, undefined); | ||
} | ||
_handleError(error) { | ||
if (this._isDestroyed || !common.isFatalError(this._settings, error)) { | ||
#handleError(error) { | ||
if (this.#isDestroyed || !common.isFatalError(this.#settings, error)) { | ||
return; | ||
} | ||
this._isFatalError = true; | ||
this._isDestroyed = true; | ||
this._emitter.emit('error', error); | ||
this.#isFatalError = true; | ||
this.#isDestroyed = true; | ||
this._emitError(error); | ||
} | ||
_handleEntry(entry, base) { | ||
if (this._isDestroyed || this._isFatalError) { | ||
#handleEntry(entry, base) { | ||
if (this.#isDestroyed || this.#isFatalError) { | ||
return; | ||
@@ -86,15 +97,12 @@ } | ||
if (base !== undefined) { | ||
entry.path = common.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator); | ||
entry.path = common.joinPathSegments(base, entry.name, this.#settings.pathSegmentSeparator); | ||
} | ||
if (common.isAppliedFilter(this._settings.entryFilter, entry)) { | ||
if (common.isAppliedFilter(this.#settings.entryFilter, entry)) { | ||
this._emitEntry(entry); | ||
} | ||
if (entry.dirent.isDirectory() && common.isAppliedFilter(this._settings.deepFilter, entry)) { | ||
this._pushToQueue(fullpath, base === undefined ? undefined : entry.path); | ||
if (entry.dirent.isDirectory() && common.isAppliedFilter(this.#settings.deepFilter, entry)) { | ||
this.#pushToQueue(fullpath, base === undefined ? undefined : entry.path); | ||
} | ||
} | ||
_emitEntry(entry) { | ||
this._emitter.emit('entry', entry); | ||
} | ||
} | ||
exports.default = AsyncReader; | ||
exports.AsyncReader = AsyncReader; |
@@ -1,7 +0,6 @@ | ||
import type { FilterFunction } from '../settings'; | ||
import type Settings from '../settings'; | ||
import type { Errno } from '../types'; | ||
export declare function isFatalError(settings: Settings, error: Errno): boolean; | ||
import type { FilterFunction, Settings } from '../settings'; | ||
import type { ErrnoException } from '../types'; | ||
export declare function isFatalError(settings: Settings, error: ErrnoException): boolean; | ||
export declare function isAppliedFilter<T>(filter: FilterFunction<T> | null, value: T): boolean; | ||
export declare function replacePathSegmentSeparator(filepath: string, separator: string): string; | ||
export declare function joinPathSegments(a: string, b: string, separator: string): string; |
@@ -1,15 +0,11 @@ | ||
import * as fsScandir from '@nodelib/fs.scandir'; | ||
import type { IFileSystemAdapter } from '../adapters/fs'; | ||
import type { Settings } from '../settings'; | ||
import type { Entry } from '../types'; | ||
import Reader from './reader'; | ||
export default class SyncReader extends Reader { | ||
protected readonly _scandir: typeof fsScandir.scandirSync; | ||
private readonly _storage; | ||
private readonly _queue; | ||
read(): Entry[]; | ||
private _pushToQueue; | ||
private _handleQueue; | ||
private _handleDirectory; | ||
private _handleError; | ||
private _handleEntry; | ||
private _pushToStorage; | ||
export interface ISyncReader { | ||
read: (root: string) => Entry[]; | ||
} | ||
export declare class SyncReader implements ISyncReader { | ||
#private; | ||
constructor(fs: IFileSystemAdapter, settings: Settings); | ||
read(root: string): Entry[]; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fsScandir = require("@nodelib/fs.scandir"); | ||
exports.SyncReader = void 0; | ||
const common = require("./common"); | ||
const reader_1 = require("./reader"); | ||
class SyncReader extends reader_1.default { | ||
constructor() { | ||
super(...arguments); | ||
this._scandir = fsScandir.scandirSync; | ||
this._storage = []; | ||
this._queue = new Set(); | ||
class SyncReader { | ||
#fs; | ||
#settings; | ||
#queue = new Set(); | ||
#storage = []; | ||
constructor(fs, settings) { | ||
this.#fs = fs; | ||
this.#settings = settings; | ||
} | ||
read() { | ||
this._pushToQueue(this._root, this._settings.basePath); | ||
this._handleQueue(); | ||
return this._storage; | ||
read(root) { | ||
const directory = common.replacePathSegmentSeparator(root, this.#settings.pathSegmentSeparator); | ||
this.#pushToQueue(directory, this.#settings.basePath); | ||
this.#handleQueue(); | ||
return this.#storage; | ||
} | ||
_pushToQueue(directory, base) { | ||
this._queue.add({ directory, base }); | ||
#pushToQueue(directory, base) { | ||
this.#queue.add({ directory, base }); | ||
} | ||
_handleQueue() { | ||
for (const item of this._queue.values()) { | ||
this._handleDirectory(item.directory, item.base); | ||
#handleQueue() { | ||
for (const item of this.#queue.values()) { | ||
this.#handleDirectory(item.directory, item.base); | ||
} | ||
} | ||
_handleDirectory(directory, base) { | ||
#handleDirectory(directory, base) { | ||
try { | ||
const entries = this._scandir(directory, this._settings.fsScandirSettings); | ||
const entries = this.#fs.scandirSync(directory, this.#settings.fsScandirSettings); | ||
for (const entry of entries) { | ||
this._handleEntry(entry, base); | ||
this.#handleEntry(entry, base); | ||
} | ||
} | ||
catch (error) { | ||
this._handleError(error); | ||
this.#handleError(error); | ||
} | ||
} | ||
_handleError(error) { | ||
if (!common.isFatalError(this._settings, error)) { | ||
return; | ||
#handleError(error) { | ||
if (common.isFatalError(this.#settings, error)) { | ||
throw error; | ||
} | ||
throw error; | ||
} | ||
_handleEntry(entry, base) { | ||
#handleEntry(entry, base) { | ||
const fullpath = entry.path; | ||
if (base !== undefined) { | ||
entry.path = common.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator); | ||
entry.path = common.joinPathSegments(base, entry.name, this.#settings.pathSegmentSeparator); | ||
} | ||
if (common.isAppliedFilter(this._settings.entryFilter, entry)) { | ||
this._pushToStorage(entry); | ||
if (common.isAppliedFilter(this.#settings.entryFilter, entry)) { | ||
this.#pushToStorage(entry); | ||
} | ||
if (entry.dirent.isDirectory() && common.isAppliedFilter(this._settings.deepFilter, entry)) { | ||
this._pushToQueue(fullpath, base === undefined ? undefined : entry.path); | ||
if (entry.dirent.isDirectory() && common.isAppliedFilter(this.#settings.deepFilter, entry)) { | ||
this.#pushToQueue(fullpath, base === undefined ? undefined : entry.path); | ||
} | ||
} | ||
_pushToStorage(entry) { | ||
this._storage.push(entry); | ||
#pushToStorage(entry) { | ||
this.#storage.push(entry); | ||
} | ||
} | ||
exports.default = SyncReader; | ||
exports.SyncReader = SyncReader; |
import * as fsScandir from '@nodelib/fs.scandir'; | ||
import type { Entry, Errno } from './types'; | ||
export declare type FilterFunction<T> = (value: T) => boolean; | ||
export declare type DeepFilterFunction = FilterFunction<Entry>; | ||
export declare type EntryFilterFunction = FilterFunction<Entry>; | ||
export declare type ErrorFilterFunction = FilterFunction<Errno>; | ||
import type { Entry, ErrnoException } from './types'; | ||
export type FilterFunction<T> = (value: T) => boolean; | ||
export type DeepFilterFunction = FilterFunction<Entry>; | ||
export type EntryFilterFunction = FilterFunction<Entry>; | ||
export type ErrorFilterFunction = FilterFunction<ErrnoException>; | ||
export interface Options { | ||
@@ -19,4 +19,3 @@ basePath?: string; | ||
} | ||
export default class Settings { | ||
private readonly _options; | ||
export declare class Settings { | ||
readonly basePath?: string; | ||
@@ -29,4 +28,3 @@ readonly concurrency: number; | ||
readonly fsScandirSettings: fsScandir.Settings; | ||
constructor(_options?: Options); | ||
private _getValue; | ||
constructor(options?: Options); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path = require("path"); | ||
exports.Settings = void 0; | ||
const path = require("node:path"); | ||
const fsScandir = require("@nodelib/fs.scandir"); | ||
class Settings { | ||
constructor(_options = {}) { | ||
this._options = _options; | ||
this.basePath = this._getValue(this._options.basePath, undefined); | ||
this.concurrency = this._getValue(this._options.concurrency, Number.POSITIVE_INFINITY); | ||
this.deepFilter = this._getValue(this._options.deepFilter, null); | ||
this.entryFilter = this._getValue(this._options.entryFilter, null); | ||
this.errorFilter = this._getValue(this._options.errorFilter, null); | ||
this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path.sep); | ||
basePath; | ||
concurrency; | ||
deepFilter; | ||
entryFilter; | ||
errorFilter; | ||
pathSegmentSeparator; | ||
fsScandirSettings; | ||
constructor(options = {}) { | ||
this.basePath = options.basePath ?? undefined; | ||
this.concurrency = options.concurrency ?? Number.POSITIVE_INFINITY; | ||
this.deepFilter = options.deepFilter ?? null; | ||
this.entryFilter = options.entryFilter ?? null; | ||
this.errorFilter = options.errorFilter ?? null; | ||
this.pathSegmentSeparator = options.pathSegmentSeparator ?? path.sep; | ||
this.fsScandirSettings = new fsScandir.Settings({ | ||
followSymbolicLinks: this._options.followSymbolicLinks, | ||
fs: this._options.fs, | ||
pathSegmentSeparator: this._options.pathSegmentSeparator, | ||
stats: this._options.stats, | ||
throwErrorOnBrokenSymbolicLink: this._options.throwErrorOnBrokenSymbolicLink | ||
followSymbolicLinks: options.followSymbolicLinks, | ||
fs: options.fs, | ||
pathSegmentSeparator: this.pathSegmentSeparator, | ||
stats: options.stats, | ||
throwErrorOnBrokenSymbolicLink: options.throwErrorOnBrokenSymbolicLink, | ||
}); | ||
} | ||
_getValue(option, value) { | ||
return option !== null && option !== void 0 ? option : value; | ||
} | ||
} | ||
exports.default = Settings; | ||
exports.Settings = Settings; |
/// <reference types="node" /> | ||
import type * as scandir from '@nodelib/fs.scandir'; | ||
export declare type Entry = scandir.Entry; | ||
export declare type Errno = NodeJS.ErrnoException; | ||
export type Entry = scandir.Entry; | ||
export type ErrnoException = NodeJS.ErrnoException; | ||
export interface QueueItem { | ||
@@ -9,1 +9,4 @@ directory: string; | ||
} | ||
export type EntryEventCallback = (entry: Entry) => void; | ||
export type ErrorEventCallback = (error: ErrnoException) => void; | ||
export type EndEventCallback = () => void; |
{ | ||
"name": "@nodelib/fs.walk", | ||
"version": "1.2.8", | ||
"version": "2.0.0", | ||
"description": "A library for efficiently walking a directory recursively", | ||
@@ -17,6 +17,7 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">= 8" | ||
"node": ">=16.14.0" | ||
}, | ||
"files": [ | ||
"out/**", | ||
"!out/benchmark", | ||
"!out/**/*.map", | ||
@@ -32,15 +33,19 @@ "!out/**/*.spec.*", | ||
"compile": "tsc -b .", | ||
"compile:watch": "tsc -p . --watch --sourceMap", | ||
"compile:watch": "tsc -b . --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" | ||
"watch": "npm run clean && npm run compile:watch", | ||
"bench": "npm run bench:sync && npm run bench:async && npm run bench:stream", | ||
"bench:sync": "hereby bench:sync", | ||
"bench:async": "hereby bench:async", | ||
"bench:stream": "hereby bench:stream" | ||
}, | ||
"dependencies": { | ||
"@nodelib/fs.scandir": "2.1.5", | ||
"fastq": "^1.6.0" | ||
"@nodelib/fs.scandir": "3.0.0", | ||
"fastq": "^1.15.0" | ||
}, | ||
"devDependencies": { | ||
"@nodelib/fs.macchiato": "1.0.4" | ||
}, | ||
"gitHead": "1e5bad48565da2b06b8600e744324ea240bf49d8" | ||
"@nodelib/fs.macchiato": "2.0.0", | ||
"@nodelib/fs.walk.previous": "npm:@nodelib/fs.walk@2" | ||
} | ||
} |
@@ -8,3 +8,2 @@ # @nodelib/fs.walk | ||
* :moneybag: Returns useful information: `name`, `path`, `dirent` and `stats` (optional). | ||
* :rocket: On Node.js 10.10+ uses the mechanism without additional calls to determine the entry type for performance reasons. See [`old` and `modern` mode](https://github.com/nodelib/nodelib/blob/master/packages/fs/fs.scandir/README.md#old-and-modern-mode). | ||
* :gear: Built-in directories/files and error filtering system. | ||
@@ -11,0 +10,0 @@ * :link: Can safely work with broken symbolic links. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
27139
28
543
2
215
1
+ Added@nodelib/fs.scandir@3.0.0(transitive)
+ Added@nodelib/fs.stat@3.0.0(transitive)
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
Updated@nodelib/fs.scandir@3.0.0
Updatedfastq@^1.15.0