Socket
Socket
Sign inDemoInstall

@nodelib/fs.walk

Package Overview
Dependencies
6
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 1.2.0

out/readers/reader.d.ts

8

out/readers/async.d.ts

@@ -6,8 +6,8 @@ /// <reference types="node" />

import { Entry, Errno } from '../types/index';
import Reader from './reader';
declare type EntryEventCallback = (entry: Entry) => void;
declare type ErrorEventCallback = (error: Errno) => void;
declare type EndEventCallback = () => void;
export default class AsyncReader {
private readonly _root;
private readonly _settings;
export default class AsyncReader extends Reader {
protected readonly _settings: Settings;
protected readonly _scandir: typeof fsScandir.scandir;

@@ -24,3 +24,3 @@ protected readonly _emitter: EventEmitter;

onEnd(callback: EndEventCallback): void;
private _handleDirectory;
private _pushToQueue;
private _worker;

@@ -27,0 +27,0 @@ private _handleError;

@@ -7,5 +7,6 @@ "use strict";

const common = require("./common");
class AsyncReader {
const reader_1 = require("./reader");
class AsyncReader extends reader_1.default {
constructor(_root, _settings) {
this._root = _root;
super(_root, _settings);
this._settings = _settings;

@@ -27,3 +28,3 @@ this._scandir = fsScandir.scandir;

setImmediate(() => {
this._handleDirectory(this._root);
this._pushToQueue(this._root, this._settings.basePath);
});

@@ -48,4 +49,5 @@ return this._emitter;

}
_handleDirectory(dir) {
this._queue.push(dir, (error) => {
_pushToQueue(dir, base) {
const queueItem = { dir, base };
this._queue.push(queueItem, (error) => {
if (error) {

@@ -56,4 +58,4 @@ this._handleError(error);

}
_worker(dir, done) {
this._scandir(dir, this._settings.fsScandirSettings, (error, entries) => {
_worker(item, done) {
this._scandir(item.dir, this._settings.fsScandirSettings, (error, entries) => {
if (error) {

@@ -63,3 +65,3 @@ return done(error, undefined);

for (const entry of entries) {
this._handleEntry(entry);
this._handleEntry(entry, item.base);
}

@@ -77,3 +79,3 @@ done(null, undefined);

}
_handleEntry(entry) {
_handleEntry(entry, base) {
if (this._isDestroyed || this._isFatalError) {

@@ -83,4 +85,4 @@ return;

const fullpath = entry.path;
if (this._settings.basePath !== null) {
entry.path = common.setBasePathForEntryPath(fullpath, this._root, this._settings.basePath);
if (base) {
entry.path = common.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator);
}

@@ -91,3 +93,3 @@ if (common.isAppliedFilter(this._settings.entryFilter, entry)) {

if (entry.dirent.isDirectory() && common.isAppliedFilter(this._settings.deepFilter, entry)) {
this._handleDirectory(fullpath);
this._pushToQueue(fullpath, entry.path);
}

@@ -94,0 +96,0 @@ }

@@ -5,3 +5,4 @@ import Settings, { FilterFunction } from '../settings';

export declare function isAppliedFilter<T>(filter: FilterFunction<T> | null, value: T): boolean;
export declare function setBasePathForEntryPath(fullpath: string, root: string, base: string): string;
export declare function replacePathSegmentSeparator(filepath: string, separator: string): string;
export declare function joinPathSegments(a: string, b: string, separator: string): string;
//# sourceMappingURL=common.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
function isFatalError(settings, error) {

@@ -15,15 +14,9 @@ if (settings.errorFilter === null) {

exports.isAppliedFilter = isAppliedFilter;
function setBasePathForEntryPath(fullpath, root, base) {
let relative;
if (fullpath.startsWith(root)) {
relative = fullpath.replace(root, '').replace(/^[\\\/]/, '');
}
else {
relative = path.relative(root, fullpath);
}
if (base === '') {
return relative;
}
return `${base}${path.sep}${relative}`;
function replacePathSegmentSeparator(filepath, separator) {
return filepath.split(/[\\\/]/).join(separator);
}
exports.setBasePathForEntryPath = setBasePathForEntryPath;
exports.replacePathSegmentSeparator = replacePathSegmentSeparator;
function joinPathSegments(a, b, separator) {
return a + separator + b;
}
exports.joinPathSegments = joinPathSegments;
import * as fsScandir from '@nodelib/fs.scandir';
import Settings from '../settings';
import { Entry } from '../types/index';
export default class SyncReader {
private readonly _root;
private readonly _settings;
import Reader from './reader';
export default class SyncReader extends Reader {
protected readonly _scandir: typeof fsScandir.scandirSync;
private readonly _storage;
private readonly _queue;
constructor(_root: string, _settings: Settings);
read(): Entry[];

@@ -12,0 +9,0 @@ private _pushToQueue;

@@ -5,6 +5,6 @@ "use strict";

const common = require("./common");
class SyncReader {
constructor(_root, _settings) {
this._root = _root;
this._settings = _settings;
const reader_1 = require("./reader");
class SyncReader extends reader_1.default {
constructor() {
super(...arguments);
this._scandir = fsScandir.scandirSync;

@@ -15,19 +15,19 @@ this._storage = new Set();

read() {
this._pushToQueue(this._root);
this._pushToQueue(this._root, this._settings.basePath);
this._handleQueue();
return Array.from(this._storage);
}
_pushToQueue(dir) {
this._queue.add(dir);
_pushToQueue(dir, base) {
this._queue.add({ dir, base });
}
_handleQueue() {
for (const item of this._queue.values()) {
this._handleDirectory(item);
this._handleDirectory(item.dir, item.base);
}
}
_handleDirectory(dir) {
_handleDirectory(dir, base) {
try {
const entries = this._scandir(dir, this._settings.fsScandirSettings);
for (const entry of entries) {
this._handleEntry(entry);
this._handleEntry(entry, base);
}

@@ -45,6 +45,6 @@ }

}
_handleEntry(entry) {
_handleEntry(entry, base) {
const fullpath = entry.path;
if (this._settings.basePath !== null) {
entry.path = common.setBasePathForEntryPath(fullpath, this._root, this._settings.basePath);
if (base) {
entry.path = common.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator);
}

@@ -55,3 +55,3 @@ if (common.isAppliedFilter(this._settings.entryFilter, entry)) {

if (entry.dirent.isDirectory() && common.isAppliedFilter(this._settings.deepFilter, entry)) {
this._handleDirectory(fullpath);
this._pushToQueue(fullpath, entry.path);
}

@@ -58,0 +58,0 @@ }

@@ -8,3 +8,3 @@ import * as fsScandir from '@nodelib/fs.scandir';

export interface Options {
basePath?: string | null;
basePath?: string;
concurrency?: number;

@@ -16,2 +16,3 @@ deepFilter?: DeepFilterFunction;

fs?: Partial<fsScandir.FileSystemAdapter>;
pathSegmentSeparator?: string;
stats?: boolean;

@@ -22,3 +23,3 @@ throwErrorOnBrokenSymbolicLink?: boolean;

private readonly _options;
readonly basePath: string | null;
readonly basePath?: string;
readonly concurrency: number;

@@ -28,2 +29,3 @@ readonly deepFilter: DeepFilterFunction | null;

readonly errorFilter: ErrorFilterFunction | null;
readonly pathSegmentSeparator: string;
readonly fsScandirSettings: fsScandir.Settings;

@@ -30,0 +32,0 @@ constructor(_options?: Options);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const fsScandir = require("@nodelib/fs.scandir");

@@ -7,3 +8,3 @@ class Settings {

this._options = _options;
this.basePath = this._getValue(this._options.basePath, null);
this.basePath = this._getValue(this._options.basePath, undefined);
this.concurrency = this._getValue(this._options.concurrency, Infinity);

@@ -13,6 +14,8 @@ this.deepFilter = this._getValue(this._options.deepFilter, null);

this.errorFilter = this._getValue(this._options.errorFilter, null);
this.pathSegmentSeparator = this._getValue(this._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,
followSymbolicLinks: this._options.followSymbolicLinks,
throwErrorOnBrokenSymbolicLink: this._options.throwErrorOnBrokenSymbolicLink

@@ -19,0 +22,0 @@ });

@@ -5,2 +5,6 @@ /// <reference types="node" />

export declare type Errno = NodeJS.ErrnoException;
export interface QueueItem {
dir: string;
base?: string;
}
//# sourceMappingURL=index.d.ts.map
{
"name": "@nodelib/fs.walk",
"version": "1.1.1",
"version": "1.2.0",
"description": "A library for efficiently walking a directory recursively",

@@ -31,6 +31,6 @@ "license": "MIT",

"dependencies": {
"@nodelib/fs.scandir": "2.0.1",
"@nodelib/fs.scandir": "2.1.0",
"fastq": "^1.6.0"
},
"gitHead": "14a421c7401f269bf868e1a53fac0c3624247518"
"gitHead": "e23fc3908c45a4a71f0cc844cbf5e4fbdd6c71aa"
}

@@ -99,3 +99,3 @@ # @nodelib/fs.walk

* Type: `string`
* Default: `null`
* Default: `undefined`

@@ -122,4 +122,4 @@ By default, all paths are built relative to the root path. You can use this option to set custom root path.

* Type: [`DeepFilterFunction`](./src/settings.ts) | `null`
* Default: `null`
* Type: [`DeepFilterFunction`](./src/settings.ts)
* Default: `undefined`

@@ -135,4 +135,4 @@ A function that indicates whether the directory will be read deep or not.

* Type: [`EntryFilterFunction`](./src/settings.ts) | `null`
* Default: `null`
* Type: [`EntryFilterFunction`](./src/settings.ts)
* Default: `undefined`

@@ -148,4 +148,4 @@ A function that indicates whether the entry will be included to results or not.

* Type: [`ErrorFilterFunction`](./src/settings.ts) | `null`
* Default: `null`
* Type: [`ErrorFilterFunction`](./src/settings.ts)
* Default: `undefined`

@@ -164,3 +164,3 @@ A function that allows you to skip errors that occur when reading directories.

* Type: `boolean`
* Default: `true`
* Default: `false`

@@ -174,3 +174,3 @@ Adds an instance of `fs.Stats` class to the [`Entry`](#entry).

* Type: `boolean`
* Default: `true`
* Default: `false`

@@ -186,2 +186,9 @@ Follow symbolic links or not. Call `fs.stat` on symbolic link if `true`.

### `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`

@@ -188,0 +195,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc