Socket
Socket
Sign inDemoInstall

fdir

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fdir - npm Package Compare versions

Comparing version 6.4.0 to 6.4.1

dist/api/functions/is-recursive-symlink.d.ts

73

dist/api/functions/resolve-symlink.js

@@ -8,23 +8,14 @@ "use strict";

const fs_1 = __importDefault(require("fs"));
const path_1 = require("path");
const resolveSymlinksAsync = function (path, state, callback) {
const { queue, options: { suppressErrors }, } = state;
queue.enqueue();
fs_1.default.stat(path, (error, stat) => {
if (error) {
queue.dequeue(suppressErrors ? null : error, state);
return;
}
callback(stat, path);
queue.dequeue(null, state);
});
};
const resolveSymlinksWithRealPathsAsync = function (path, state, callback) {
const { queue, options: { suppressErrors }, } = state;
queue.enqueue();
fs_1.default.realpath(path, (error, resolvedPath) => {
if (error) {
queue.dequeue(suppressErrors ? null : error, state);
return;
}
fs_1.default.lstat(resolvedPath, (_error, stat) => {
if (error)
return queue.dequeue(suppressErrors ? null : error, state);
fs_1.default.stat(resolvedPath, (error, stat) => {
if (error)
return queue.dequeue(suppressErrors ? null : error, state);
if (stat.isDirectory() && isRecursive(path, resolvedPath, state))
return queue.dequeue(null, state);
callback(stat, resolvedPath);

@@ -35,20 +26,14 @@ queue.dequeue(null, state);

};
const resolveSymlinksSync = function (path, state, callback) {
const resolveSymlinks = function (path, state, callback) {
const { queue, options: { suppressErrors }, } = state;
queue.enqueue();
try {
const stat = fs_1.default.statSync(path);
callback(stat, path);
}
catch (e) {
if (!state.options.suppressErrors)
throw e;
}
};
const resolveSymlinksWithRealPathsSync = function (path, state, callback) {
try {
const resolvedPath = fs_1.default.realpathSync(path);
const stat = fs_1.default.lstatSync(resolvedPath);
const stat = fs_1.default.statSync(resolvedPath);
if (stat.isDirectory() && isRecursive(path, resolvedPath, state))
return;
callback(stat, resolvedPath);
}
catch (e) {
if (!state.options.suppressErrors)
if (!suppressErrors)
throw e;

@@ -60,8 +45,26 @@ }

return null;
if (options.useRealPaths)
return isSynchronous
? resolveSymlinksWithRealPathsSync
: resolveSymlinksWithRealPathsAsync;
return isSynchronous ? resolveSymlinksSync : resolveSymlinksAsync;
return isSynchronous ? resolveSymlinks : resolveSymlinksAsync;
}
exports.build = build;
function isRecursive(path, resolved, state) {
if (state.options.useRealPaths)
return isRecursiveUsingRealPaths(resolved, state);
let parent = (0, path_1.dirname)(path);
let depth = 1;
while (parent !== state.root && depth < 2) {
const resolvedPath = state.symlinks.get(parent);
const isSameRoot = !!resolvedPath &&
(resolvedPath === resolved ||
resolvedPath.startsWith(resolved) ||
resolved.startsWith(resolvedPath));
if (isSameRoot)
depth++;
else
parent = (0, path_1.dirname)(parent);
}
state.symlinks.set(path, resolved);
return depth > 1;
}
function isRecursiveUsingRealPaths(resolved, state) {
return state.visited.includes(resolved + state.options.pathSeparator);
}
/// <reference types="node" />
import { WalkerState } from "../../types";
import fs from "fs";
export type WalkDirectoryFunction = (state: WalkerState, directoryPath: string, depth: number, callback: (entries: fs.Dirent[], directoryPath: string, depth: number) => void) => void;
export type WalkDirectoryFunction = (state: WalkerState, crawlPath: string, directoryPath: string, depth: number, callback: (entries: fs.Dirent[], directoryPath: string, depth: number) => void) => void;
export declare function build(isSynchronous: boolean): WalkDirectoryFunction;

@@ -9,12 +9,11 @@ "use strict";

const readdirOpts = { withFileTypes: true };
const walkAsync = (state, directoryPath, currentDepth, callback) => {
state.queue.enqueue();
if (currentDepth < 0) {
state.queue.dequeue(null, state);
const walkAsync = (state, crawlPath, directoryPath, currentDepth, callback) => {
if (currentDepth < 0)
return;
}
state.visited.push(crawlPath);
state.counts.directories++;
state.queue.enqueue();
// Perf: Node >= 10 introduced withFileTypes that helps us
// skip an extra fs.stat call.
fs_1.default.readdir(directoryPath || ".", readdirOpts, function process(error, entries = []) {
fs_1.default.readdir(crawlPath || ".", readdirOpts, (error, entries = []) => {
callback(entries, directoryPath, currentDepth);

@@ -24,10 +23,10 @@ state.queue.dequeue(state.options.suppressErrors ? null : error, state);

};
const walkSync = (state, directoryPath, currentDepth, callback) => {
if (currentDepth < 0) {
const walkSync = (state, crawlPath, directoryPath, currentDepth, callback) => {
if (currentDepth < 0)
return;
}
state.visited.push(crawlPath);
state.counts.directories++;
let entries = [];
try {
entries = fs_1.default.readdirSync(directoryPath || ".", readdirOpts);
entries = fs_1.default.readdirSync(crawlPath || ".", readdirOpts);
}

@@ -34,0 +33,0 @@ catch (e) {

@@ -54,3 +54,5 @@ "use strict";

this.callbackInvoker = invokeCallback.build(options, this.isSynchronous);
this.root = (0, utils_1.normalizePath)(root, options);
this.state = {
root: this.root.slice(0, -1),
// Perf: we explicitly tell the compiler to optimize for String arrays

@@ -62,4 +64,5 @@ paths: [""].slice(0, 0),

queue: new queue_1.Queue((error, state) => this.callbackInvoker(state, error, callback)),
symlinks: new Map(),
visited: [""].slice(0, 0),
};
this.root = (0, utils_1.normalizePath)(root, this.state.options);
/*

@@ -79,7 +82,7 @@ * Perf: We conditionally change functions according to options. This gives a slight

start() {
this.walkDirectory(this.state, this.root, this.state.options.maxDepth, this.walk);
this.walkDirectory(this.state, this.root, this.root, this.state.options.maxDepth, this.walk);
return this.isSynchronous ? this.callbackInvoker(this.state, null) : null;
}
walk = (entries, directoryPath, depth) => {
const { paths, options: { filters, resolveSymlinks, excludeSymlinks, exclude, maxFiles, signal, }, } = this.state;
const { paths, options: { filters, resolveSymlinks, excludeSymlinks, exclude, maxFiles, signal, useRealPaths, pathSeparator, }, } = this.state;
if ((signal && signal.aborted) || (maxFiles && paths.length > maxFiles))

@@ -100,3 +103,3 @@ return;

continue;
this.walkDirectory(this.state, path, depth - 1, this.walk);
this.walkDirectory(this.state, path, path, depth - 1, this.walk);
}

@@ -110,5 +113,6 @@ else if (entry.isSymbolicLink() && this.resolveSymlink) {

return;
this.walkDirectory(this.state, resolvedPath, depth - 1, this.walk);
this.walkDirectory(this.state, resolvedPath, useRealPaths ? resolvedPath : path + pathSeparator, depth - 1, this.walk);
}
else {
resolvedPath = useRealPaths ? resolvedPath : path;
const filename = (0, path_1.basename)(resolvedPath);

@@ -115,0 +119,0 @@ const directoryPath = (0, utils_1.normalizePath)((0, path_1.dirname)(resolvedPath), this.state.options);

@@ -24,2 +24,3 @@ /// <reference types="node" />

export type WalkerState = {
root: string;
paths: string[];

@@ -30,2 +31,4 @@ groups: Group[];

queue: Queue;
symlinks: Map<string, string>;
visited: string[];
};

@@ -58,3 +61,3 @@ export type ResultCallback<TOutput extends Output> = (error: Error | null, output: TOutput) => void;

export type GlobMatcher = (test: string) => boolean;
export type GlobFunction = ((glob: string | string[], ...params: unknown[]) => GlobMatcher);
export type GlobFunction = (glob: string | string[], ...params: unknown[]) => GlobMatcher;
export type GlobParams<T> = T extends (globs: string | string[], ...params: infer TParams extends unknown[]) => GlobMatcher ? TParams : [];
{
"name": "fdir",
"version": "6.4.0",
"version": "6.4.1",
"description": "The fastest directory crawler & globbing alternative to glob, fast-glob, & tiny-glob. Crawls 1m files in < 1s",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc