full site update
This commit is contained in:
3
node_modules/fdir/dist/api/async.d.ts
generated
vendored
Normal file
3
node_modules/fdir/dist/api/async.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Output, Options, ResultCallback } from "../types";
|
||||
export declare function promise<TOutput extends Output>(root: string, options: Options): Promise<TOutput>;
|
||||
export declare function callback<TOutput extends Output>(root: string, options: Options, callback: ResultCallback<TOutput>): void;
|
19
node_modules/fdir/dist/api/async.js
generated
vendored
Normal file
19
node_modules/fdir/dist/api/async.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.callback = exports.promise = void 0;
|
||||
const walker_1 = require("./walker");
|
||||
function promise(root, options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
callback(root, options, (err, output) => {
|
||||
if (err)
|
||||
return reject(err);
|
||||
resolve(output);
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.promise = promise;
|
||||
function callback(root, options, callback) {
|
||||
let walker = new walker_1.Walker(root, options, callback);
|
||||
walker.start();
|
||||
}
|
||||
exports.callback = callback;
|
12
node_modules/fdir/dist/api/counter.d.ts
generated
vendored
Normal file
12
node_modules/fdir/dist/api/counter.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
export declare class Counter {
|
||||
private _files;
|
||||
private _directories;
|
||||
set files(num: number);
|
||||
get files(): number;
|
||||
set directories(num: number);
|
||||
get directories(): number;
|
||||
/**
|
||||
* @deprecated use `directories` instead
|
||||
*/
|
||||
get dirs(): number;
|
||||
}
|
27
node_modules/fdir/dist/api/counter.js
generated
vendored
Normal file
27
node_modules/fdir/dist/api/counter.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Counter = void 0;
|
||||
class Counter {
|
||||
_files = 0;
|
||||
_directories = 0;
|
||||
set files(num) {
|
||||
this._files = num;
|
||||
}
|
||||
get files() {
|
||||
return this._files;
|
||||
}
|
||||
set directories(num) {
|
||||
this._directories = num;
|
||||
}
|
||||
get directories() {
|
||||
return this._directories;
|
||||
}
|
||||
/**
|
||||
* @deprecated use `directories` instead
|
||||
*/
|
||||
/* c8 ignore next 3 */
|
||||
get dirs() {
|
||||
return this._directories;
|
||||
}
|
||||
}
|
||||
exports.Counter = Counter;
|
3
node_modules/fdir/dist/api/functions/get-array.d.ts
generated
vendored
Normal file
3
node_modules/fdir/dist/api/functions/get-array.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Options } from "../../types";
|
||||
export type GetArrayFunction = (paths: string[]) => string[];
|
||||
export declare function build(options: Options): GetArrayFunction;
|
13
node_modules/fdir/dist/api/functions/get-array.js
generated
vendored
Normal file
13
node_modules/fdir/dist/api/functions/get-array.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.build = void 0;
|
||||
const getArray = (paths) => {
|
||||
return paths;
|
||||
};
|
||||
const getArrayGroup = () => {
|
||||
return [""].slice(0, 0);
|
||||
};
|
||||
function build(options) {
|
||||
return options.group ? getArrayGroup : getArray;
|
||||
}
|
||||
exports.build = build;
|
3
node_modules/fdir/dist/api/functions/group-files.d.ts
generated
vendored
Normal file
3
node_modules/fdir/dist/api/functions/group-files.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Group, Options } from "../../types";
|
||||
export type GroupFilesFunction = (groups: Group[], directory: string, files: string[]) => void;
|
||||
export declare function build(options: Options): GroupFilesFunction;
|
11
node_modules/fdir/dist/api/functions/group-files.js
generated
vendored
Normal file
11
node_modules/fdir/dist/api/functions/group-files.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.build = void 0;
|
||||
const groupFiles = (groups, directory, files) => {
|
||||
groups.push({ directory, files, dir: directory });
|
||||
};
|
||||
const empty = () => { };
|
||||
function build(options) {
|
||||
return options.group ? groupFiles : empty;
|
||||
}
|
||||
exports.build = build;
|
3
node_modules/fdir/dist/api/functions/invoke-callback.d.ts
generated
vendored
Normal file
3
node_modules/fdir/dist/api/functions/invoke-callback.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Output, ResultCallback, WalkerState, Options } from "../../types";
|
||||
export type InvokeCallbackFunction<TOutput extends Output> = (state: WalkerState, error: Error | null, callback?: ResultCallback<TOutput>) => null | TOutput;
|
||||
export declare function build<TOutput extends Output>(options: Options, isSynchronous: boolean): InvokeCallbackFunction<TOutput>;
|
57
node_modules/fdir/dist/api/functions/invoke-callback.js
generated
vendored
Normal file
57
node_modules/fdir/dist/api/functions/invoke-callback.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.build = void 0;
|
||||
const onlyCountsSync = (state) => {
|
||||
return state.counts;
|
||||
};
|
||||
const groupsSync = (state) => {
|
||||
return state.groups;
|
||||
};
|
||||
const defaultSync = (state) => {
|
||||
return state.paths;
|
||||
};
|
||||
const limitFilesSync = (state) => {
|
||||
return state.paths.slice(0, state.options.maxFiles);
|
||||
};
|
||||
const onlyCountsAsync = (state, error, callback) => {
|
||||
report(error, callback, state.counts, state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
const defaultAsync = (state, error, callback) => {
|
||||
report(error, callback, state.paths, state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
const limitFilesAsync = (state, error, callback) => {
|
||||
report(error, callback, state.paths.slice(0, state.options.maxFiles), state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
const groupsAsync = (state, error, callback) => {
|
||||
report(error, callback, state.groups, state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
function report(error, callback, output, suppressErrors) {
|
||||
if (error && !suppressErrors)
|
||||
callback(error, output);
|
||||
else
|
||||
callback(null, output);
|
||||
}
|
||||
function build(options, isSynchronous) {
|
||||
const { onlyCounts, group, maxFiles } = options;
|
||||
if (onlyCounts)
|
||||
return isSynchronous
|
||||
? onlyCountsSync
|
||||
: onlyCountsAsync;
|
||||
else if (group)
|
||||
return isSynchronous
|
||||
? groupsSync
|
||||
: groupsAsync;
|
||||
else if (maxFiles)
|
||||
return isSynchronous
|
||||
? limitFilesSync
|
||||
: limitFilesAsync;
|
||||
else
|
||||
return isSynchronous
|
||||
? defaultSync
|
||||
: defaultAsync;
|
||||
}
|
||||
exports.build = build;
|
5
node_modules/fdir/dist/api/functions/join-path.d.ts
generated
vendored
Normal file
5
node_modules/fdir/dist/api/functions/join-path.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Options, PathSeparator } from "../../types";
|
||||
export declare function joinPathWithBasePath(filename: string, directoryPath: string): string;
|
||||
export declare function joinDirectoryPath(filename: string, directoryPath: string, separator: PathSeparator): string;
|
||||
export type JoinPathFunction = (filename: string, directoryPath: string) => string;
|
||||
export declare function build(root: string, options: Options): JoinPathFunction;
|
36
node_modules/fdir/dist/api/functions/join-path.js
generated
vendored
Normal file
36
node_modules/fdir/dist/api/functions/join-path.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.build = exports.joinDirectoryPath = exports.joinPathWithBasePath = void 0;
|
||||
const path_1 = require("path");
|
||||
const utils_1 = require("../../utils");
|
||||
function joinPathWithBasePath(filename, directoryPath) {
|
||||
return directoryPath + filename;
|
||||
}
|
||||
exports.joinPathWithBasePath = joinPathWithBasePath;
|
||||
function joinPathWithRelativePath(root, options) {
|
||||
return function (filename, directoryPath) {
|
||||
const sameRoot = directoryPath.startsWith(root);
|
||||
if (sameRoot)
|
||||
return directoryPath.replace(root, "") + filename;
|
||||
else
|
||||
return ((0, utils_1.convertSlashes)((0, path_1.relative)(root, directoryPath), options.pathSeparator) +
|
||||
options.pathSeparator +
|
||||
filename);
|
||||
};
|
||||
}
|
||||
function joinPath(filename) {
|
||||
return filename;
|
||||
}
|
||||
function joinDirectoryPath(filename, directoryPath, separator) {
|
||||
return directoryPath + filename + separator;
|
||||
}
|
||||
exports.joinDirectoryPath = joinDirectoryPath;
|
||||
function build(root, options) {
|
||||
const { relativePaths, includeBasePath } = options;
|
||||
return relativePaths && root
|
||||
? joinPathWithRelativePath(root, options)
|
||||
: includeBasePath
|
||||
? joinPathWithBasePath
|
||||
: joinPath;
|
||||
}
|
||||
exports.build = build;
|
3
node_modules/fdir/dist/api/functions/push-directory.d.ts
generated
vendored
Normal file
3
node_modules/fdir/dist/api/functions/push-directory.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { FilterPredicate, Options } from "../../types";
|
||||
export type PushDirectoryFunction = (directoryPath: string, paths: string[], filters?: FilterPredicate[]) => void;
|
||||
export declare function build(root: string, options: Options): PushDirectoryFunction;
|
37
node_modules/fdir/dist/api/functions/push-directory.js
generated
vendored
Normal file
37
node_modules/fdir/dist/api/functions/push-directory.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.build = void 0;
|
||||
function pushDirectoryWithRelativePath(root) {
|
||||
return function (directoryPath, paths) {
|
||||
paths.push(directoryPath.substring(root.length) || ".");
|
||||
};
|
||||
}
|
||||
function pushDirectoryFilterWithRelativePath(root) {
|
||||
return function (directoryPath, paths, filters) {
|
||||
const relativePath = directoryPath.substring(root.length) || ".";
|
||||
if (filters.every((filter) => filter(relativePath, true))) {
|
||||
paths.push(relativePath);
|
||||
}
|
||||
};
|
||||
}
|
||||
const pushDirectory = (directoryPath, paths) => {
|
||||
paths.push(directoryPath || ".");
|
||||
};
|
||||
const pushDirectoryFilter = (directoryPath, paths, filters) => {
|
||||
const path = directoryPath || ".";
|
||||
if (filters.every((filter) => filter(path, true))) {
|
||||
paths.push(path);
|
||||
}
|
||||
};
|
||||
const empty = () => { };
|
||||
function build(root, options) {
|
||||
const { includeDirs, filters, relativePaths } = options;
|
||||
if (!includeDirs)
|
||||
return empty;
|
||||
if (relativePaths)
|
||||
return filters && filters.length
|
||||
? pushDirectoryFilterWithRelativePath(root)
|
||||
: pushDirectoryWithRelativePath(root);
|
||||
return filters && filters.length ? pushDirectoryFilter : pushDirectory;
|
||||
}
|
||||
exports.build = build;
|
3
node_modules/fdir/dist/api/functions/push-file.d.ts
generated
vendored
Normal file
3
node_modules/fdir/dist/api/functions/push-file.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { FilterPredicate, Options, Counts } from "../../types";
|
||||
export type PushFileFunction = (directoryPath: string, paths: string[], counts: Counts, filters?: FilterPredicate[]) => void;
|
||||
export declare function build(options: Options): PushFileFunction;
|
33
node_modules/fdir/dist/api/functions/push-file.js
generated
vendored
Normal file
33
node_modules/fdir/dist/api/functions/push-file.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.build = void 0;
|
||||
const pushFileFilterAndCount = (filename, _paths, counts, filters) => {
|
||||
if (filters.every((filter) => filter(filename, false)))
|
||||
counts.files++;
|
||||
};
|
||||
const pushFileFilter = (filename, paths, _counts, filters) => {
|
||||
if (filters.every((filter) => filter(filename, false)))
|
||||
paths.push(filename);
|
||||
};
|
||||
const pushFileCount = (_filename, _paths, counts, _filters) => {
|
||||
counts.files++;
|
||||
};
|
||||
const pushFile = (filename, paths) => {
|
||||
paths.push(filename);
|
||||
};
|
||||
const empty = () => { };
|
||||
function build(options) {
|
||||
const { excludeFiles, filters, onlyCounts } = options;
|
||||
if (excludeFiles)
|
||||
return empty;
|
||||
if (filters && filters.length) {
|
||||
return onlyCounts ? pushFileFilterAndCount : pushFileFilter;
|
||||
}
|
||||
else if (onlyCounts) {
|
||||
return pushFileCount;
|
||||
}
|
||||
else {
|
||||
return pushFile;
|
||||
}
|
||||
}
|
||||
exports.build = build;
|
5
node_modules/fdir/dist/api/functions/resolve-symlink.d.ts
generated
vendored
Normal file
5
node_modules/fdir/dist/api/functions/resolve-symlink.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/// <reference types="node" />
|
||||
import fs from "fs";
|
||||
import { WalkerState, Options } from "../../types";
|
||||
export type ResolveSymlinkFunction = (path: string, state: WalkerState, callback: (stat: fs.Stats, path: string) => void) => void;
|
||||
export declare function build(options: Options, isSynchronous: boolean): ResolveSymlinkFunction | null;
|
67
node_modules/fdir/dist/api/functions/resolve-symlink.js
generated
vendored
Normal file
67
node_modules/fdir/dist/api/functions/resolve-symlink.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.build = void 0;
|
||||
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.realpath(path, (error, resolvedPath) => {
|
||||
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);
|
||||
queue.dequeue(null, state);
|
||||
});
|
||||
});
|
||||
};
|
||||
const resolveSymlinks = function (path, state, callback) {
|
||||
const { queue, options: { suppressErrors }, } = state;
|
||||
queue.enqueue();
|
||||
try {
|
||||
const resolvedPath = fs_1.default.realpathSync(path);
|
||||
const stat = fs_1.default.statSync(resolvedPath);
|
||||
if (stat.isDirectory() && isRecursive(path, resolvedPath, state))
|
||||
return;
|
||||
callback(stat, resolvedPath);
|
||||
}
|
||||
catch (e) {
|
||||
if (!suppressErrors)
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
function build(options, isSynchronous) {
|
||||
if (!options.resolveSymlinks || options.excludeSymlinks)
|
||||
return null;
|
||||
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);
|
||||
}
|
5
node_modules/fdir/dist/api/functions/walk-directory.d.ts
generated
vendored
Normal file
5
node_modules/fdir/dist/api/functions/walk-directory.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/// <reference types="node" />
|
||||
import { WalkerState } from "../../types";
|
||||
import fs from "fs";
|
||||
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;
|
40
node_modules/fdir/dist/api/functions/walk-directory.js
generated
vendored
Normal file
40
node_modules/fdir/dist/api/functions/walk-directory.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.build = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const readdirOpts = { withFileTypes: true };
|
||||
const walkAsync = (state, crawlPath, directoryPath, currentDepth, callback) => {
|
||||
state.queue.enqueue();
|
||||
if (currentDepth < 0)
|
||||
return state.queue.dequeue(null, state);
|
||||
state.visited.push(crawlPath);
|
||||
state.counts.directories++;
|
||||
// Perf: Node >= 10 introduced withFileTypes that helps us
|
||||
// skip an extra fs.stat call.
|
||||
fs_1.default.readdir(crawlPath || ".", readdirOpts, (error, entries = []) => {
|
||||
callback(entries, directoryPath, currentDepth);
|
||||
state.queue.dequeue(state.options.suppressErrors ? null : error, state);
|
||||
});
|
||||
};
|
||||
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(crawlPath || ".", readdirOpts);
|
||||
}
|
||||
catch (e) {
|
||||
if (!state.options.suppressErrors)
|
||||
throw e;
|
||||
}
|
||||
callback(entries, directoryPath, currentDepth);
|
||||
};
|
||||
function build(isSynchronous) {
|
||||
return isSynchronous ? walkSync : walkAsync;
|
||||
}
|
||||
exports.build = build;
|
15
node_modules/fdir/dist/api/queue.d.ts
generated
vendored
Normal file
15
node_modules/fdir/dist/api/queue.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { WalkerState } from "../types";
|
||||
type OnQueueEmptyCallback = (error: Error | null, output: WalkerState) => void;
|
||||
/**
|
||||
* This is a custom stateless queue to track concurrent async fs calls.
|
||||
* It increments a counter whenever a call is queued and decrements it
|
||||
* as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
|
||||
*/
|
||||
export declare class Queue {
|
||||
private onQueueEmpty?;
|
||||
count: number;
|
||||
constructor(onQueueEmpty?: OnQueueEmptyCallback | undefined);
|
||||
enqueue(): number;
|
||||
dequeue(error: Error | null, output: WalkerState): void;
|
||||
}
|
||||
export {};
|
29
node_modules/fdir/dist/api/queue.js
generated
vendored
Normal file
29
node_modules/fdir/dist/api/queue.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Queue = void 0;
|
||||
/**
|
||||
* This is a custom stateless queue to track concurrent async fs calls.
|
||||
* It increments a counter whenever a call is queued and decrements it
|
||||
* as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
|
||||
*/
|
||||
class Queue {
|
||||
onQueueEmpty;
|
||||
count = 0;
|
||||
constructor(onQueueEmpty) {
|
||||
this.onQueueEmpty = onQueueEmpty;
|
||||
}
|
||||
enqueue() {
|
||||
this.count++;
|
||||
return this.count;
|
||||
}
|
||||
dequeue(error, output) {
|
||||
if (this.onQueueEmpty && (--this.count <= 0 || error)) {
|
||||
this.onQueueEmpty(error, output);
|
||||
if (error) {
|
||||
output.controller.abort();
|
||||
this.onQueueEmpty = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Queue = Queue;
|
2
node_modules/fdir/dist/api/sync.d.ts
generated
vendored
Normal file
2
node_modules/fdir/dist/api/sync.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Output, Options } from "../types";
|
||||
export declare function sync<TOutput extends Output>(root: string, options: Options): TOutput;
|
9
node_modules/fdir/dist/api/sync.js
generated
vendored
Normal file
9
node_modules/fdir/dist/api/sync.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.sync = void 0;
|
||||
const walker_1 = require("./walker");
|
||||
function sync(root, options) {
|
||||
const walker = new walker_1.Walker(root, options);
|
||||
return walker.start();
|
||||
}
|
||||
exports.sync = sync;
|
18
node_modules/fdir/dist/api/walker.d.ts
generated
vendored
Normal file
18
node_modules/fdir/dist/api/walker.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { ResultCallback, Options } from "../types";
|
||||
import { Output } from "../types";
|
||||
export declare class Walker<TOutput extends Output> {
|
||||
private readonly root;
|
||||
private readonly isSynchronous;
|
||||
private readonly state;
|
||||
private readonly joinPath;
|
||||
private readonly pushDirectory;
|
||||
private readonly pushFile;
|
||||
private readonly getArray;
|
||||
private readonly groupFiles;
|
||||
private readonly resolveSymlink;
|
||||
private readonly walkDirectory;
|
||||
private readonly callbackInvoker;
|
||||
constructor(root: string, options: Options, callback?: ResultCallback<TOutput>);
|
||||
start(): TOutput | null;
|
||||
private walk;
|
||||
}
|
129
node_modules/fdir/dist/api/walker.js
generated
vendored
Normal file
129
node_modules/fdir/dist/api/walker.js
generated
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
"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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Walker = void 0;
|
||||
const path_1 = require("path");
|
||||
const utils_1 = require("../utils");
|
||||
const joinPath = __importStar(require("./functions/join-path"));
|
||||
const pushDirectory = __importStar(require("./functions/push-directory"));
|
||||
const pushFile = __importStar(require("./functions/push-file"));
|
||||
const getArray = __importStar(require("./functions/get-array"));
|
||||
const groupFiles = __importStar(require("./functions/group-files"));
|
||||
const resolveSymlink = __importStar(require("./functions/resolve-symlink"));
|
||||
const invokeCallback = __importStar(require("./functions/invoke-callback"));
|
||||
const walkDirectory = __importStar(require("./functions/walk-directory"));
|
||||
const queue_1 = require("./queue");
|
||||
const counter_1 = require("./counter");
|
||||
class Walker {
|
||||
root;
|
||||
isSynchronous;
|
||||
state;
|
||||
joinPath;
|
||||
pushDirectory;
|
||||
pushFile;
|
||||
getArray;
|
||||
groupFiles;
|
||||
resolveSymlink;
|
||||
walkDirectory;
|
||||
callbackInvoker;
|
||||
constructor(root, options, callback) {
|
||||
this.isSynchronous = !callback;
|
||||
this.callbackInvoker = invokeCallback.build(options, this.isSynchronous);
|
||||
this.root = (0, utils_1.normalizePath)(root, options);
|
||||
this.state = {
|
||||
root: (0, utils_1.isRootDirectory)(this.root) ? this.root : this.root.slice(0, -1),
|
||||
// Perf: we explicitly tell the compiler to optimize for String arrays
|
||||
paths: [""].slice(0, 0),
|
||||
groups: [],
|
||||
counts: new counter_1.Counter(),
|
||||
options,
|
||||
queue: new queue_1.Queue((error, state) => this.callbackInvoker(state, error, callback)),
|
||||
symlinks: new Map(),
|
||||
visited: [""].slice(0, 0),
|
||||
controller: new AbortController(),
|
||||
};
|
||||
/*
|
||||
* Perf: We conditionally change functions according to options. This gives a slight
|
||||
* performance boost. Since these functions are so small, they are automatically inlined
|
||||
* by the javascript engine so there's no function call overhead (in most cases).
|
||||
*/
|
||||
this.joinPath = joinPath.build(this.root, options);
|
||||
this.pushDirectory = pushDirectory.build(this.root, options);
|
||||
this.pushFile = pushFile.build(options);
|
||||
this.getArray = getArray.build(options);
|
||||
this.groupFiles = groupFiles.build(options);
|
||||
this.resolveSymlink = resolveSymlink.build(options, this.isSynchronous);
|
||||
this.walkDirectory = walkDirectory.build(this.isSynchronous);
|
||||
}
|
||||
start() {
|
||||
this.pushDirectory(this.root, this.state.paths, this.state.options.filters);
|
||||
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, useRealPaths, pathSeparator, }, controller, } = this.state;
|
||||
if (controller.signal.aborted ||
|
||||
(signal && signal.aborted) ||
|
||||
(maxFiles && paths.length > maxFiles))
|
||||
return;
|
||||
const files = this.getArray(this.state.paths);
|
||||
for (let i = 0; i < entries.length; ++i) {
|
||||
const entry = entries[i];
|
||||
if (entry.isFile() ||
|
||||
(entry.isSymbolicLink() && !resolveSymlinks && !excludeSymlinks)) {
|
||||
const filename = this.joinPath(entry.name, directoryPath);
|
||||
this.pushFile(filename, files, this.state.counts, filters);
|
||||
}
|
||||
else if (entry.isDirectory()) {
|
||||
let path = joinPath.joinDirectoryPath(entry.name, directoryPath, this.state.options.pathSeparator);
|
||||
if (exclude && exclude(entry.name, path))
|
||||
continue;
|
||||
this.pushDirectory(path, paths, filters);
|
||||
this.walkDirectory(this.state, path, path, depth - 1, this.walk);
|
||||
}
|
||||
else if (this.resolveSymlink && entry.isSymbolicLink()) {
|
||||
let path = joinPath.joinPathWithBasePath(entry.name, directoryPath);
|
||||
this.resolveSymlink(path, this.state, (stat, resolvedPath) => {
|
||||
if (stat.isDirectory()) {
|
||||
resolvedPath = (0, utils_1.normalizePath)(resolvedPath, this.state.options);
|
||||
if (exclude &&
|
||||
exclude(entry.name, useRealPaths ? resolvedPath : path + pathSeparator))
|
||||
return;
|
||||
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);
|
||||
const directoryPath = (0, utils_1.normalizePath)((0, path_1.dirname)(resolvedPath), this.state.options);
|
||||
resolvedPath = this.joinPath(filename, directoryPath);
|
||||
this.pushFile(resolvedPath, files, this.state.counts, filters);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
this.groupFiles(this.state.groups, directoryPath, files);
|
||||
};
|
||||
}
|
||||
exports.Walker = Walker;
|
9
node_modules/fdir/dist/builder/api-builder.d.ts
generated
vendored
Normal file
9
node_modules/fdir/dist/builder/api-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Options, Output, ResultCallback } from "../types";
|
||||
export declare class APIBuilder<TReturnType extends Output> {
|
||||
private readonly root;
|
||||
private readonly options;
|
||||
constructor(root: string, options: Options);
|
||||
withPromise(): Promise<TReturnType>;
|
||||
withCallback(cb: ResultCallback<TReturnType>): void;
|
||||
sync(): TReturnType;
|
||||
}
|
23
node_modules/fdir/dist/builder/api-builder.js
generated
vendored
Normal file
23
node_modules/fdir/dist/builder/api-builder.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.APIBuilder = void 0;
|
||||
const async_1 = require("../api/async");
|
||||
const sync_1 = require("../api/sync");
|
||||
class APIBuilder {
|
||||
root;
|
||||
options;
|
||||
constructor(root, options) {
|
||||
this.root = root;
|
||||
this.options = options;
|
||||
}
|
||||
withPromise() {
|
||||
return (0, async_1.promise)(this.root, this.options);
|
||||
}
|
||||
withCallback(cb) {
|
||||
(0, async_1.callback)(this.root, this.options, cb);
|
||||
}
|
||||
sync() {
|
||||
return (0, sync_1.sync)(this.root, this.options);
|
||||
}
|
||||
}
|
||||
exports.APIBuilder = APIBuilder;
|
41
node_modules/fdir/dist/builder/index.d.ts
generated
vendored
Normal file
41
node_modules/fdir/dist/builder/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
/// <reference types="node" />
|
||||
import { Output, OnlyCountsOutput, GroupOutput, PathsOutput, Options, FilterPredicate, ExcludePredicate, GlobParams } from "../types";
|
||||
import { APIBuilder } from "./api-builder";
|
||||
import type picomatch from "picomatch";
|
||||
export declare class Builder<TReturnType extends Output = PathsOutput, TGlobFunction = typeof picomatch> {
|
||||
private readonly globCache;
|
||||
private options;
|
||||
private globFunction?;
|
||||
constructor(options?: Partial<Options<TGlobFunction>>);
|
||||
group(): Builder<GroupOutput, TGlobFunction>;
|
||||
withPathSeparator(separator: "/" | "\\"): this;
|
||||
withBasePath(): this;
|
||||
withRelativePaths(): this;
|
||||
withDirs(): this;
|
||||
withMaxDepth(depth: number): this;
|
||||
withMaxFiles(limit: number): this;
|
||||
withFullPaths(): this;
|
||||
withErrors(): this;
|
||||
withSymlinks({ resolvePaths }?: {
|
||||
resolvePaths?: boolean | undefined;
|
||||
}): this;
|
||||
withAbortSignal(signal: AbortSignal): this;
|
||||
normalize(): this;
|
||||
filter(predicate: FilterPredicate): this;
|
||||
onlyDirs(): this;
|
||||
exclude(predicate: ExcludePredicate): this;
|
||||
onlyCounts(): Builder<OnlyCountsOutput, TGlobFunction>;
|
||||
crawl(root?: string): APIBuilder<TReturnType>;
|
||||
withGlobFunction<TFunc>(fn: TFunc): Builder<TReturnType, TFunc>;
|
||||
/**
|
||||
* @deprecated Pass options using the constructor instead:
|
||||
* ```ts
|
||||
* new fdir(options).crawl("/path/to/root");
|
||||
* ```
|
||||
* This method will be removed in v7.0
|
||||
*/
|
||||
crawlWithOptions(root: string, options: Partial<Options<TGlobFunction>>): APIBuilder<TReturnType>;
|
||||
glob(...patterns: string[]): Builder<TReturnType, TGlobFunction>;
|
||||
globWithOptions(patterns: string[]): Builder<TReturnType, TGlobFunction>;
|
||||
globWithOptions(patterns: string[], ...options: GlobParams<TGlobFunction>): Builder<TReturnType, TGlobFunction>;
|
||||
}
|
136
node_modules/fdir/dist/builder/index.js
generated
vendored
Normal file
136
node_modules/fdir/dist/builder/index.js
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Builder = void 0;
|
||||
const path_1 = require("path");
|
||||
const api_builder_1 = require("./api-builder");
|
||||
var pm = null;
|
||||
/* c8 ignore next 6 */
|
||||
try {
|
||||
require.resolve("picomatch");
|
||||
pm = require("picomatch");
|
||||
}
|
||||
catch (_e) {
|
||||
// do nothing
|
||||
}
|
||||
class Builder {
|
||||
globCache = {};
|
||||
options = {
|
||||
maxDepth: Infinity,
|
||||
suppressErrors: true,
|
||||
pathSeparator: path_1.sep,
|
||||
filters: [],
|
||||
};
|
||||
globFunction;
|
||||
constructor(options) {
|
||||
this.options = { ...this.options, ...options };
|
||||
this.globFunction = this.options.globFunction;
|
||||
}
|
||||
group() {
|
||||
this.options.group = true;
|
||||
return this;
|
||||
}
|
||||
withPathSeparator(separator) {
|
||||
this.options.pathSeparator = separator;
|
||||
return this;
|
||||
}
|
||||
withBasePath() {
|
||||
this.options.includeBasePath = true;
|
||||
return this;
|
||||
}
|
||||
withRelativePaths() {
|
||||
this.options.relativePaths = true;
|
||||
return this;
|
||||
}
|
||||
withDirs() {
|
||||
this.options.includeDirs = true;
|
||||
return this;
|
||||
}
|
||||
withMaxDepth(depth) {
|
||||
this.options.maxDepth = depth;
|
||||
return this;
|
||||
}
|
||||
withMaxFiles(limit) {
|
||||
this.options.maxFiles = limit;
|
||||
return this;
|
||||
}
|
||||
withFullPaths() {
|
||||
this.options.resolvePaths = true;
|
||||
this.options.includeBasePath = true;
|
||||
return this;
|
||||
}
|
||||
withErrors() {
|
||||
this.options.suppressErrors = false;
|
||||
return this;
|
||||
}
|
||||
withSymlinks({ resolvePaths = true } = {}) {
|
||||
this.options.resolveSymlinks = true;
|
||||
this.options.useRealPaths = resolvePaths;
|
||||
return this.withFullPaths();
|
||||
}
|
||||
withAbortSignal(signal) {
|
||||
this.options.signal = signal;
|
||||
return this;
|
||||
}
|
||||
normalize() {
|
||||
this.options.normalizePath = true;
|
||||
return this;
|
||||
}
|
||||
filter(predicate) {
|
||||
this.options.filters.push(predicate);
|
||||
return this;
|
||||
}
|
||||
onlyDirs() {
|
||||
this.options.excludeFiles = true;
|
||||
this.options.includeDirs = true;
|
||||
return this;
|
||||
}
|
||||
exclude(predicate) {
|
||||
this.options.exclude = predicate;
|
||||
return this;
|
||||
}
|
||||
onlyCounts() {
|
||||
this.options.onlyCounts = true;
|
||||
return this;
|
||||
}
|
||||
crawl(root) {
|
||||
return new api_builder_1.APIBuilder(root || ".", this.options);
|
||||
}
|
||||
withGlobFunction(fn) {
|
||||
// cast this since we don't have the new type params yet
|
||||
this.globFunction = fn;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @deprecated Pass options using the constructor instead:
|
||||
* ```ts
|
||||
* new fdir(options).crawl("/path/to/root");
|
||||
* ```
|
||||
* This method will be removed in v7.0
|
||||
*/
|
||||
/* c8 ignore next 4 */
|
||||
crawlWithOptions(root, options) {
|
||||
this.options = { ...this.options, ...options };
|
||||
return new api_builder_1.APIBuilder(root || ".", this.options);
|
||||
}
|
||||
glob(...patterns) {
|
||||
if (this.globFunction) {
|
||||
return this.globWithOptions(patterns);
|
||||
}
|
||||
return this.globWithOptions(patterns, ...[{ dot: true }]);
|
||||
}
|
||||
globWithOptions(patterns, ...options) {
|
||||
const globFn = (this.globFunction || pm);
|
||||
/* c8 ignore next 5 */
|
||||
if (!globFn) {
|
||||
throw new Error("Please specify a glob function to use glob matching.");
|
||||
}
|
||||
var isMatch = this.globCache[patterns.join("\0")];
|
||||
if (!isMatch) {
|
||||
isMatch = globFn(patterns, ...options);
|
||||
this.globCache[patterns.join("\0")] = isMatch;
|
||||
}
|
||||
this.options.filters.push((path) => isMatch(path));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
exports.Builder = Builder;
|
572
node_modules/fdir/dist/index.cjs
generated
vendored
Normal file
572
node_modules/fdir/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,572 @@
|
||||
//#region rolldown:runtime
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
||||
key = keys[i];
|
||||
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
||||
get: ((k) => from[k]).bind(null, key),
|
||||
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
||||
});
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
||||
value: mod,
|
||||
enumerable: true
|
||||
}) : target, mod));
|
||||
|
||||
//#endregion
|
||||
const path = __toESM(require("path"));
|
||||
const fs = __toESM(require("fs"));
|
||||
|
||||
//#region src/utils.ts
|
||||
function cleanPath(path$1) {
|
||||
let normalized = (0, path.normalize)(path$1);
|
||||
if (normalized.length > 1 && normalized[normalized.length - 1] === path.sep) normalized = normalized.substring(0, normalized.length - 1);
|
||||
return normalized;
|
||||
}
|
||||
const SLASHES_REGEX = /[\\/]/g;
|
||||
function convertSlashes(path$1, separator) {
|
||||
return path$1.replace(SLASHES_REGEX, separator);
|
||||
}
|
||||
const WINDOWS_ROOT_DIR_REGEX = /^[a-z]:[\\/]$/i;
|
||||
function isRootDirectory(path$1) {
|
||||
return path$1 === "/" || WINDOWS_ROOT_DIR_REGEX.test(path$1);
|
||||
}
|
||||
function normalizePath(path$1, options) {
|
||||
const { resolvePaths, normalizePath: normalizePath$1, pathSeparator } = options;
|
||||
const pathNeedsCleaning = process.platform === "win32" && path$1.includes("/") || path$1.startsWith(".");
|
||||
if (resolvePaths) path$1 = (0, path.resolve)(path$1);
|
||||
if (normalizePath$1 || pathNeedsCleaning) path$1 = cleanPath(path$1);
|
||||
if (path$1 === ".") return "";
|
||||
const needsSeperator = path$1[path$1.length - 1] !== pathSeparator;
|
||||
return convertSlashes(needsSeperator ? path$1 + pathSeparator : path$1, pathSeparator);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/join-path.ts
|
||||
function joinPathWithBasePath(filename, directoryPath) {
|
||||
return directoryPath + filename;
|
||||
}
|
||||
function joinPathWithRelativePath(root, options) {
|
||||
return function(filename, directoryPath) {
|
||||
const sameRoot = directoryPath.startsWith(root);
|
||||
if (sameRoot) return directoryPath.replace(root, "") + filename;
|
||||
else return convertSlashes((0, path.relative)(root, directoryPath), options.pathSeparator) + options.pathSeparator + filename;
|
||||
};
|
||||
}
|
||||
function joinPath(filename) {
|
||||
return filename;
|
||||
}
|
||||
function joinDirectoryPath(filename, directoryPath, separator) {
|
||||
return directoryPath + filename + separator;
|
||||
}
|
||||
function build$7(root, options) {
|
||||
const { relativePaths, includeBasePath } = options;
|
||||
return relativePaths && root ? joinPathWithRelativePath(root, options) : includeBasePath ? joinPathWithBasePath : joinPath;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/push-directory.ts
|
||||
function pushDirectoryWithRelativePath(root) {
|
||||
return function(directoryPath, paths) {
|
||||
paths.push(directoryPath.substring(root.length) || ".");
|
||||
};
|
||||
}
|
||||
function pushDirectoryFilterWithRelativePath(root) {
|
||||
return function(directoryPath, paths, filters) {
|
||||
const relativePath = directoryPath.substring(root.length) || ".";
|
||||
if (filters.every((filter) => filter(relativePath, true))) paths.push(relativePath);
|
||||
};
|
||||
}
|
||||
const pushDirectory = (directoryPath, paths) => {
|
||||
paths.push(directoryPath || ".");
|
||||
};
|
||||
const pushDirectoryFilter = (directoryPath, paths, filters) => {
|
||||
const path$1 = directoryPath || ".";
|
||||
if (filters.every((filter) => filter(path$1, true))) paths.push(path$1);
|
||||
};
|
||||
const empty$2 = () => {};
|
||||
function build$6(root, options) {
|
||||
const { includeDirs, filters, relativePaths } = options;
|
||||
if (!includeDirs) return empty$2;
|
||||
if (relativePaths) return filters && filters.length ? pushDirectoryFilterWithRelativePath(root) : pushDirectoryWithRelativePath(root);
|
||||
return filters && filters.length ? pushDirectoryFilter : pushDirectory;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/push-file.ts
|
||||
const pushFileFilterAndCount = (filename, _paths, counts, filters) => {
|
||||
if (filters.every((filter) => filter(filename, false))) counts.files++;
|
||||
};
|
||||
const pushFileFilter = (filename, paths, _counts, filters) => {
|
||||
if (filters.every((filter) => filter(filename, false))) paths.push(filename);
|
||||
};
|
||||
const pushFileCount = (_filename, _paths, counts, _filters) => {
|
||||
counts.files++;
|
||||
};
|
||||
const pushFile = (filename, paths) => {
|
||||
paths.push(filename);
|
||||
};
|
||||
const empty$1 = () => {};
|
||||
function build$5(options) {
|
||||
const { excludeFiles, filters, onlyCounts } = options;
|
||||
if (excludeFiles) return empty$1;
|
||||
if (filters && filters.length) return onlyCounts ? pushFileFilterAndCount : pushFileFilter;
|
||||
else if (onlyCounts) return pushFileCount;
|
||||
else return pushFile;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/get-array.ts
|
||||
const getArray = (paths) => {
|
||||
return paths;
|
||||
};
|
||||
const getArrayGroup = () => {
|
||||
return [""].slice(0, 0);
|
||||
};
|
||||
function build$4(options) {
|
||||
return options.group ? getArrayGroup : getArray;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/group-files.ts
|
||||
const groupFiles = (groups, directory, files) => {
|
||||
groups.push({
|
||||
directory,
|
||||
files,
|
||||
dir: directory
|
||||
});
|
||||
};
|
||||
const empty = () => {};
|
||||
function build$3(options) {
|
||||
return options.group ? groupFiles : empty;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/resolve-symlink.ts
|
||||
const resolveSymlinksAsync = function(path$1, state, callback$1) {
|
||||
const { queue, options: { suppressErrors } } = state;
|
||||
queue.enqueue();
|
||||
fs.default.realpath(path$1, (error, resolvedPath) => {
|
||||
if (error) return queue.dequeue(suppressErrors ? null : error, state);
|
||||
fs.default.stat(resolvedPath, (error$1, stat) => {
|
||||
if (error$1) return queue.dequeue(suppressErrors ? null : error$1, state);
|
||||
if (stat.isDirectory() && isRecursive(path$1, resolvedPath, state)) return queue.dequeue(null, state);
|
||||
callback$1(stat, resolvedPath);
|
||||
queue.dequeue(null, state);
|
||||
});
|
||||
});
|
||||
};
|
||||
const resolveSymlinks = function(path$1, state, callback$1) {
|
||||
const { queue, options: { suppressErrors } } = state;
|
||||
queue.enqueue();
|
||||
try {
|
||||
const resolvedPath = fs.default.realpathSync(path$1);
|
||||
const stat = fs.default.statSync(resolvedPath);
|
||||
if (stat.isDirectory() && isRecursive(path$1, resolvedPath, state)) return;
|
||||
callback$1(stat, resolvedPath);
|
||||
} catch (e) {
|
||||
if (!suppressErrors) throw e;
|
||||
}
|
||||
};
|
||||
function build$2(options, isSynchronous) {
|
||||
if (!options.resolveSymlinks || options.excludeSymlinks) return null;
|
||||
return isSynchronous ? resolveSymlinks : resolveSymlinksAsync;
|
||||
}
|
||||
function isRecursive(path$1, resolved, state) {
|
||||
if (state.options.useRealPaths) return isRecursiveUsingRealPaths(resolved, state);
|
||||
let parent = (0, path.dirname)(path$1);
|
||||
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.dirname)(parent);
|
||||
}
|
||||
state.symlinks.set(path$1, resolved);
|
||||
return depth > 1;
|
||||
}
|
||||
function isRecursiveUsingRealPaths(resolved, state) {
|
||||
return state.visited.includes(resolved + state.options.pathSeparator);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/invoke-callback.ts
|
||||
const onlyCountsSync = (state) => {
|
||||
return state.counts;
|
||||
};
|
||||
const groupsSync = (state) => {
|
||||
return state.groups;
|
||||
};
|
||||
const defaultSync = (state) => {
|
||||
return state.paths;
|
||||
};
|
||||
const limitFilesSync = (state) => {
|
||||
return state.paths.slice(0, state.options.maxFiles);
|
||||
};
|
||||
const onlyCountsAsync = (state, error, callback$1) => {
|
||||
report(error, callback$1, state.counts, state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
const defaultAsync = (state, error, callback$1) => {
|
||||
report(error, callback$1, state.paths, state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
const limitFilesAsync = (state, error, callback$1) => {
|
||||
report(error, callback$1, state.paths.slice(0, state.options.maxFiles), state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
const groupsAsync = (state, error, callback$1) => {
|
||||
report(error, callback$1, state.groups, state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
function report(error, callback$1, output, suppressErrors) {
|
||||
if (error && !suppressErrors) callback$1(error, output);
|
||||
else callback$1(null, output);
|
||||
}
|
||||
function build$1(options, isSynchronous) {
|
||||
const { onlyCounts, group, maxFiles } = options;
|
||||
if (onlyCounts) return isSynchronous ? onlyCountsSync : onlyCountsAsync;
|
||||
else if (group) return isSynchronous ? groupsSync : groupsAsync;
|
||||
else if (maxFiles) return isSynchronous ? limitFilesSync : limitFilesAsync;
|
||||
else return isSynchronous ? defaultSync : defaultAsync;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/walk-directory.ts
|
||||
const readdirOpts = { withFileTypes: true };
|
||||
const walkAsync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
|
||||
state.queue.enqueue();
|
||||
if (currentDepth <= 0) return state.queue.dequeue(null, state);
|
||||
state.visited.push(crawlPath);
|
||||
state.counts.directories++;
|
||||
fs.default.readdir(crawlPath || ".", readdirOpts, (error, entries = []) => {
|
||||
callback$1(entries, directoryPath, currentDepth);
|
||||
state.queue.dequeue(state.options.suppressErrors ? null : error, state);
|
||||
});
|
||||
};
|
||||
const walkSync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
|
||||
if (currentDepth <= 0) return;
|
||||
state.visited.push(crawlPath);
|
||||
state.counts.directories++;
|
||||
let entries = [];
|
||||
try {
|
||||
entries = fs.default.readdirSync(crawlPath || ".", readdirOpts);
|
||||
} catch (e) {
|
||||
if (!state.options.suppressErrors) throw e;
|
||||
}
|
||||
callback$1(entries, directoryPath, currentDepth);
|
||||
};
|
||||
function build(isSynchronous) {
|
||||
return isSynchronous ? walkSync : walkAsync;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/queue.ts
|
||||
/**
|
||||
* This is a custom stateless queue to track concurrent async fs calls.
|
||||
* It increments a counter whenever a call is queued and decrements it
|
||||
* as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
|
||||
*/
|
||||
var Queue = class {
|
||||
count = 0;
|
||||
constructor(onQueueEmpty) {
|
||||
this.onQueueEmpty = onQueueEmpty;
|
||||
}
|
||||
enqueue() {
|
||||
this.count++;
|
||||
return this.count;
|
||||
}
|
||||
dequeue(error, output) {
|
||||
if (this.onQueueEmpty && (--this.count <= 0 || error)) {
|
||||
this.onQueueEmpty(error, output);
|
||||
if (error) {
|
||||
output.controller.abort();
|
||||
this.onQueueEmpty = void 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/api/counter.ts
|
||||
var Counter = class {
|
||||
_files = 0;
|
||||
_directories = 0;
|
||||
set files(num) {
|
||||
this._files = num;
|
||||
}
|
||||
get files() {
|
||||
return this._files;
|
||||
}
|
||||
set directories(num) {
|
||||
this._directories = num;
|
||||
}
|
||||
get directories() {
|
||||
return this._directories;
|
||||
}
|
||||
/**
|
||||
* @deprecated use `directories` instead
|
||||
*/
|
||||
/* c8 ignore next 3 */
|
||||
get dirs() {
|
||||
return this._directories;
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/api/walker.ts
|
||||
var Walker = class {
|
||||
root;
|
||||
isSynchronous;
|
||||
state;
|
||||
joinPath;
|
||||
pushDirectory;
|
||||
pushFile;
|
||||
getArray;
|
||||
groupFiles;
|
||||
resolveSymlink;
|
||||
walkDirectory;
|
||||
callbackInvoker;
|
||||
constructor(root, options, callback$1) {
|
||||
this.isSynchronous = !callback$1;
|
||||
this.callbackInvoker = build$1(options, this.isSynchronous);
|
||||
this.root = normalizePath(root, options);
|
||||
this.state = {
|
||||
root: isRootDirectory(this.root) ? this.root : this.root.slice(0, -1),
|
||||
paths: [""].slice(0, 0),
|
||||
groups: [],
|
||||
counts: new Counter(),
|
||||
options,
|
||||
queue: new Queue((error, state) => this.callbackInvoker(state, error, callback$1)),
|
||||
symlinks: /* @__PURE__ */ new Map(),
|
||||
visited: [""].slice(0, 0),
|
||||
controller: new AbortController()
|
||||
};
|
||||
this.joinPath = build$7(this.root, options);
|
||||
this.pushDirectory = build$6(this.root, options);
|
||||
this.pushFile = build$5(options);
|
||||
this.getArray = build$4(options);
|
||||
this.groupFiles = build$3(options);
|
||||
this.resolveSymlink = build$2(options, this.isSynchronous);
|
||||
this.walkDirectory = build(this.isSynchronous);
|
||||
}
|
||||
start() {
|
||||
this.pushDirectory(this.root, this.state.paths, this.state.options.filters);
|
||||
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: resolveSymlinks$1, excludeSymlinks, exclude, maxFiles, signal, useRealPaths, pathSeparator }, controller } = this.state;
|
||||
if (controller.signal.aborted || signal && signal.aborted || maxFiles && paths.length > maxFiles) return;
|
||||
const files = this.getArray(this.state.paths);
|
||||
for (let i = 0; i < entries.length; ++i) {
|
||||
const entry = entries[i];
|
||||
if (entry.isFile() || entry.isSymbolicLink() && !resolveSymlinks$1 && !excludeSymlinks) {
|
||||
const filename = this.joinPath(entry.name, directoryPath);
|
||||
this.pushFile(filename, files, this.state.counts, filters);
|
||||
} else if (entry.isDirectory()) {
|
||||
let path$1 = joinDirectoryPath(entry.name, directoryPath, this.state.options.pathSeparator);
|
||||
if (exclude && exclude(entry.name, path$1)) continue;
|
||||
this.pushDirectory(path$1, paths, filters);
|
||||
this.walkDirectory(this.state, path$1, path$1, depth - 1, this.walk);
|
||||
} else if (this.resolveSymlink && entry.isSymbolicLink()) {
|
||||
let path$1 = joinPathWithBasePath(entry.name, directoryPath);
|
||||
this.resolveSymlink(path$1, this.state, (stat, resolvedPath) => {
|
||||
if (stat.isDirectory()) {
|
||||
resolvedPath = normalizePath(resolvedPath, this.state.options);
|
||||
if (exclude && exclude(entry.name, useRealPaths ? resolvedPath : path$1 + pathSeparator)) return;
|
||||
this.walkDirectory(this.state, resolvedPath, useRealPaths ? resolvedPath : path$1 + pathSeparator, depth - 1, this.walk);
|
||||
} else {
|
||||
resolvedPath = useRealPaths ? resolvedPath : path$1;
|
||||
const filename = (0, path.basename)(resolvedPath);
|
||||
const directoryPath$1 = normalizePath((0, path.dirname)(resolvedPath), this.state.options);
|
||||
resolvedPath = this.joinPath(filename, directoryPath$1);
|
||||
this.pushFile(resolvedPath, files, this.state.counts, filters);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
this.groupFiles(this.state.groups, directoryPath, files);
|
||||
};
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/api/async.ts
|
||||
function promise(root, options) {
|
||||
return new Promise((resolve$1, reject) => {
|
||||
callback(root, options, (err, output) => {
|
||||
if (err) return reject(err);
|
||||
resolve$1(output);
|
||||
});
|
||||
});
|
||||
}
|
||||
function callback(root, options, callback$1) {
|
||||
let walker = new Walker(root, options, callback$1);
|
||||
walker.start();
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/sync.ts
|
||||
function sync(root, options) {
|
||||
const walker = new Walker(root, options);
|
||||
return walker.start();
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/builder/api-builder.ts
|
||||
var APIBuilder = class {
|
||||
constructor(root, options) {
|
||||
this.root = root;
|
||||
this.options = options;
|
||||
}
|
||||
withPromise() {
|
||||
return promise(this.root, this.options);
|
||||
}
|
||||
withCallback(cb) {
|
||||
callback(this.root, this.options, cb);
|
||||
}
|
||||
sync() {
|
||||
return sync(this.root, this.options);
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/builder/index.ts
|
||||
var pm = null;
|
||||
/* c8 ignore next 6 */
|
||||
try {
|
||||
require.resolve("picomatch");
|
||||
pm = require("picomatch");
|
||||
} catch (_e) {}
|
||||
var Builder = class {
|
||||
globCache = {};
|
||||
options = {
|
||||
maxDepth: Infinity,
|
||||
suppressErrors: true,
|
||||
pathSeparator: path.sep,
|
||||
filters: []
|
||||
};
|
||||
globFunction;
|
||||
constructor(options) {
|
||||
this.options = {
|
||||
...this.options,
|
||||
...options
|
||||
};
|
||||
this.globFunction = this.options.globFunction;
|
||||
}
|
||||
group() {
|
||||
this.options.group = true;
|
||||
return this;
|
||||
}
|
||||
withPathSeparator(separator) {
|
||||
this.options.pathSeparator = separator;
|
||||
return this;
|
||||
}
|
||||
withBasePath() {
|
||||
this.options.includeBasePath = true;
|
||||
return this;
|
||||
}
|
||||
withRelativePaths() {
|
||||
this.options.relativePaths = true;
|
||||
return this;
|
||||
}
|
||||
withDirs() {
|
||||
this.options.includeDirs = true;
|
||||
return this;
|
||||
}
|
||||
withMaxDepth(depth) {
|
||||
this.options.maxDepth = depth;
|
||||
return this;
|
||||
}
|
||||
withMaxFiles(limit) {
|
||||
this.options.maxFiles = limit;
|
||||
return this;
|
||||
}
|
||||
withFullPaths() {
|
||||
this.options.resolvePaths = true;
|
||||
this.options.includeBasePath = true;
|
||||
return this;
|
||||
}
|
||||
withErrors() {
|
||||
this.options.suppressErrors = false;
|
||||
return this;
|
||||
}
|
||||
withSymlinks({ resolvePaths = true } = {}) {
|
||||
this.options.resolveSymlinks = true;
|
||||
this.options.useRealPaths = resolvePaths;
|
||||
return this.withFullPaths();
|
||||
}
|
||||
withAbortSignal(signal) {
|
||||
this.options.signal = signal;
|
||||
return this;
|
||||
}
|
||||
normalize() {
|
||||
this.options.normalizePath = true;
|
||||
return this;
|
||||
}
|
||||
filter(predicate) {
|
||||
this.options.filters.push(predicate);
|
||||
return this;
|
||||
}
|
||||
onlyDirs() {
|
||||
this.options.excludeFiles = true;
|
||||
this.options.includeDirs = true;
|
||||
return this;
|
||||
}
|
||||
exclude(predicate) {
|
||||
this.options.exclude = predicate;
|
||||
return this;
|
||||
}
|
||||
onlyCounts() {
|
||||
this.options.onlyCounts = true;
|
||||
return this;
|
||||
}
|
||||
crawl(root) {
|
||||
return new APIBuilder(root || ".", this.options);
|
||||
}
|
||||
withGlobFunction(fn) {
|
||||
this.globFunction = fn;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @deprecated Pass options using the constructor instead:
|
||||
* ```ts
|
||||
* new fdir(options).crawl("/path/to/root");
|
||||
* ```
|
||||
* This method will be removed in v7.0
|
||||
*/
|
||||
/* c8 ignore next 4 */
|
||||
crawlWithOptions(root, options) {
|
||||
this.options = {
|
||||
...this.options,
|
||||
...options
|
||||
};
|
||||
return new APIBuilder(root || ".", this.options);
|
||||
}
|
||||
glob(...patterns) {
|
||||
if (this.globFunction) return this.globWithOptions(patterns);
|
||||
return this.globWithOptions(patterns, ...[{ dot: true }]);
|
||||
}
|
||||
globWithOptions(patterns, ...options) {
|
||||
const globFn = this.globFunction || pm;
|
||||
/* c8 ignore next 5 */
|
||||
if (!globFn) throw new Error("Please specify a glob function to use glob matching.");
|
||||
var isMatch = this.globCache[patterns.join("\0")];
|
||||
if (!isMatch) {
|
||||
isMatch = globFn(patterns, ...options);
|
||||
this.globCache[patterns.join("\0")] = isMatch;
|
||||
}
|
||||
this.options.filters.push((path$1) => isMatch(path$1));
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
exports.fdir = Builder;
|
134
node_modules/fdir/dist/index.d.cts
generated
vendored
Normal file
134
node_modules/fdir/dist/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
/// <reference types="node" />
|
||||
import picomatch from "picomatch";
|
||||
|
||||
//#region src/api/queue.d.ts
|
||||
type OnQueueEmptyCallback = (error: Error | null, output: WalkerState) => void;
|
||||
/**
|
||||
* This is a custom stateless queue to track concurrent async fs calls.
|
||||
* It increments a counter whenever a call is queued and decrements it
|
||||
* as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
|
||||
*/
|
||||
declare class Queue {
|
||||
private onQueueEmpty?;
|
||||
count: number;
|
||||
constructor(onQueueEmpty?: OnQueueEmptyCallback | undefined);
|
||||
enqueue(): number;
|
||||
dequeue(error: Error | null, output: WalkerState): void;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/types.d.ts
|
||||
type Counts = {
|
||||
files: number;
|
||||
directories: number;
|
||||
/**
|
||||
* @deprecated use `directories` instead. Will be removed in v7.0.
|
||||
*/
|
||||
dirs: number;
|
||||
};
|
||||
type Group = {
|
||||
directory: string;
|
||||
files: string[];
|
||||
/**
|
||||
* @deprecated use `directory` instead. Will be removed in v7.0.
|
||||
*/
|
||||
dir: string;
|
||||
};
|
||||
type GroupOutput = Group[];
|
||||
type OnlyCountsOutput = Counts;
|
||||
type PathsOutput = string[];
|
||||
type Output = OnlyCountsOutput | PathsOutput | GroupOutput;
|
||||
type WalkerState = {
|
||||
root: string;
|
||||
paths: string[];
|
||||
groups: Group[];
|
||||
counts: Counts;
|
||||
options: Options;
|
||||
queue: Queue;
|
||||
controller: AbortController;
|
||||
symlinks: Map<string, string>;
|
||||
visited: string[];
|
||||
};
|
||||
type ResultCallback<TOutput extends Output> = (error: Error | null, output: TOutput) => void;
|
||||
type FilterPredicate = (path: string, isDirectory: boolean) => boolean;
|
||||
type ExcludePredicate = (dirName: string, dirPath: string) => boolean;
|
||||
type PathSeparator = "/" | "\\";
|
||||
type Options<TGlobFunction = unknown> = {
|
||||
includeBasePath?: boolean;
|
||||
includeDirs?: boolean;
|
||||
normalizePath?: boolean;
|
||||
maxDepth: number;
|
||||
maxFiles?: number;
|
||||
resolvePaths?: boolean;
|
||||
suppressErrors: boolean;
|
||||
group?: boolean;
|
||||
onlyCounts?: boolean;
|
||||
filters: FilterPredicate[];
|
||||
resolveSymlinks?: boolean;
|
||||
useRealPaths?: boolean;
|
||||
excludeFiles?: boolean;
|
||||
excludeSymlinks?: boolean;
|
||||
exclude?: ExcludePredicate;
|
||||
relativePaths?: boolean;
|
||||
pathSeparator: PathSeparator;
|
||||
signal?: AbortSignal;
|
||||
globFunction?: TGlobFunction;
|
||||
};
|
||||
type GlobMatcher = (test: string) => boolean;
|
||||
type GlobFunction = (glob: string | string[], ...params: unknown[]) => GlobMatcher;
|
||||
type GlobParams<T> = T extends ((globs: string | string[], ...params: infer TParams extends unknown[]) => GlobMatcher) ? TParams : [];
|
||||
//#endregion
|
||||
//#region src/builder/api-builder.d.ts
|
||||
declare class APIBuilder<TReturnType extends Output> {
|
||||
private readonly root;
|
||||
private readonly options;
|
||||
constructor(root: string, options: Options);
|
||||
withPromise(): Promise<TReturnType>;
|
||||
withCallback(cb: ResultCallback<TReturnType>): void;
|
||||
sync(): TReturnType;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/builder/index.d.ts
|
||||
declare class Builder<TReturnType extends Output = PathsOutput, TGlobFunction = typeof picomatch> {
|
||||
private readonly globCache;
|
||||
private options;
|
||||
private globFunction?;
|
||||
constructor(options?: Partial<Options<TGlobFunction>>);
|
||||
group(): Builder<GroupOutput, TGlobFunction>;
|
||||
withPathSeparator(separator: "/" | "\\"): this;
|
||||
withBasePath(): this;
|
||||
withRelativePaths(): this;
|
||||
withDirs(): this;
|
||||
withMaxDepth(depth: number): this;
|
||||
withMaxFiles(limit: number): this;
|
||||
withFullPaths(): this;
|
||||
withErrors(): this;
|
||||
withSymlinks({
|
||||
resolvePaths
|
||||
}?: {
|
||||
resolvePaths?: boolean | undefined;
|
||||
}): this;
|
||||
withAbortSignal(signal: AbortSignal): this;
|
||||
normalize(): this;
|
||||
filter(predicate: FilterPredicate): this;
|
||||
onlyDirs(): this;
|
||||
exclude(predicate: ExcludePredicate): this;
|
||||
onlyCounts(): Builder<OnlyCountsOutput, TGlobFunction>;
|
||||
crawl(root?: string): APIBuilder<TReturnType>;
|
||||
withGlobFunction<TFunc>(fn: TFunc): Builder<TReturnType, TFunc>;
|
||||
/**
|
||||
* @deprecated Pass options using the constructor instead:
|
||||
* ```ts
|
||||
* new fdir(options).crawl("/path/to/root");
|
||||
* ```
|
||||
* This method will be removed in v7.0
|
||||
*/
|
||||
crawlWithOptions(root: string, options: Partial<Options<TGlobFunction>>): APIBuilder<TReturnType>;
|
||||
glob(...patterns: string[]): Builder<TReturnType, TGlobFunction>;
|
||||
globWithOptions(patterns: string[]): Builder<TReturnType, TGlobFunction>;
|
||||
globWithOptions(patterns: string[], ...options: GlobParams<TGlobFunction>): Builder<TReturnType, TGlobFunction>;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/index.d.ts
|
||||
type Fdir = typeof Builder;
|
||||
//#endregion
|
||||
export { Counts, ExcludePredicate, Fdir, FilterPredicate, GlobFunction, GlobMatcher, GlobParams, Group, GroupOutput, OnlyCountsOutput, Options, Output, PathSeparator, PathsOutput, ResultCallback, WalkerState, Builder as fdir };
|
134
node_modules/fdir/dist/index.d.mts
generated
vendored
Normal file
134
node_modules/fdir/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
/// <reference types="node" />
|
||||
import picomatch from "picomatch";
|
||||
|
||||
//#region src/api/queue.d.ts
|
||||
type OnQueueEmptyCallback = (error: Error | null, output: WalkerState) => void;
|
||||
/**
|
||||
* This is a custom stateless queue to track concurrent async fs calls.
|
||||
* It increments a counter whenever a call is queued and decrements it
|
||||
* as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
|
||||
*/
|
||||
declare class Queue {
|
||||
private onQueueEmpty?;
|
||||
count: number;
|
||||
constructor(onQueueEmpty?: OnQueueEmptyCallback | undefined);
|
||||
enqueue(): number;
|
||||
dequeue(error: Error | null, output: WalkerState): void;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/types.d.ts
|
||||
type Counts = {
|
||||
files: number;
|
||||
directories: number;
|
||||
/**
|
||||
* @deprecated use `directories` instead. Will be removed in v7.0.
|
||||
*/
|
||||
dirs: number;
|
||||
};
|
||||
type Group = {
|
||||
directory: string;
|
||||
files: string[];
|
||||
/**
|
||||
* @deprecated use `directory` instead. Will be removed in v7.0.
|
||||
*/
|
||||
dir: string;
|
||||
};
|
||||
type GroupOutput = Group[];
|
||||
type OnlyCountsOutput = Counts;
|
||||
type PathsOutput = string[];
|
||||
type Output = OnlyCountsOutput | PathsOutput | GroupOutput;
|
||||
type WalkerState = {
|
||||
root: string;
|
||||
paths: string[];
|
||||
groups: Group[];
|
||||
counts: Counts;
|
||||
options: Options;
|
||||
queue: Queue;
|
||||
controller: AbortController;
|
||||
symlinks: Map<string, string>;
|
||||
visited: string[];
|
||||
};
|
||||
type ResultCallback<TOutput extends Output> = (error: Error | null, output: TOutput) => void;
|
||||
type FilterPredicate = (path: string, isDirectory: boolean) => boolean;
|
||||
type ExcludePredicate = (dirName: string, dirPath: string) => boolean;
|
||||
type PathSeparator = "/" | "\\";
|
||||
type Options<TGlobFunction = unknown> = {
|
||||
includeBasePath?: boolean;
|
||||
includeDirs?: boolean;
|
||||
normalizePath?: boolean;
|
||||
maxDepth: number;
|
||||
maxFiles?: number;
|
||||
resolvePaths?: boolean;
|
||||
suppressErrors: boolean;
|
||||
group?: boolean;
|
||||
onlyCounts?: boolean;
|
||||
filters: FilterPredicate[];
|
||||
resolveSymlinks?: boolean;
|
||||
useRealPaths?: boolean;
|
||||
excludeFiles?: boolean;
|
||||
excludeSymlinks?: boolean;
|
||||
exclude?: ExcludePredicate;
|
||||
relativePaths?: boolean;
|
||||
pathSeparator: PathSeparator;
|
||||
signal?: AbortSignal;
|
||||
globFunction?: TGlobFunction;
|
||||
};
|
||||
type GlobMatcher = (test: string) => boolean;
|
||||
type GlobFunction = (glob: string | string[], ...params: unknown[]) => GlobMatcher;
|
||||
type GlobParams<T> = T extends ((globs: string | string[], ...params: infer TParams extends unknown[]) => GlobMatcher) ? TParams : [];
|
||||
//#endregion
|
||||
//#region src/builder/api-builder.d.ts
|
||||
declare class APIBuilder<TReturnType extends Output> {
|
||||
private readonly root;
|
||||
private readonly options;
|
||||
constructor(root: string, options: Options);
|
||||
withPromise(): Promise<TReturnType>;
|
||||
withCallback(cb: ResultCallback<TReturnType>): void;
|
||||
sync(): TReturnType;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/builder/index.d.ts
|
||||
declare class Builder<TReturnType extends Output = PathsOutput, TGlobFunction = typeof picomatch> {
|
||||
private readonly globCache;
|
||||
private options;
|
||||
private globFunction?;
|
||||
constructor(options?: Partial<Options<TGlobFunction>>);
|
||||
group(): Builder<GroupOutput, TGlobFunction>;
|
||||
withPathSeparator(separator: "/" | "\\"): this;
|
||||
withBasePath(): this;
|
||||
withRelativePaths(): this;
|
||||
withDirs(): this;
|
||||
withMaxDepth(depth: number): this;
|
||||
withMaxFiles(limit: number): this;
|
||||
withFullPaths(): this;
|
||||
withErrors(): this;
|
||||
withSymlinks({
|
||||
resolvePaths
|
||||
}?: {
|
||||
resolvePaths?: boolean | undefined;
|
||||
}): this;
|
||||
withAbortSignal(signal: AbortSignal): this;
|
||||
normalize(): this;
|
||||
filter(predicate: FilterPredicate): this;
|
||||
onlyDirs(): this;
|
||||
exclude(predicate: ExcludePredicate): this;
|
||||
onlyCounts(): Builder<OnlyCountsOutput, TGlobFunction>;
|
||||
crawl(root?: string): APIBuilder<TReturnType>;
|
||||
withGlobFunction<TFunc>(fn: TFunc): Builder<TReturnType, TFunc>;
|
||||
/**
|
||||
* @deprecated Pass options using the constructor instead:
|
||||
* ```ts
|
||||
* new fdir(options).crawl("/path/to/root");
|
||||
* ```
|
||||
* This method will be removed in v7.0
|
||||
*/
|
||||
crawlWithOptions(root: string, options: Partial<Options<TGlobFunction>>): APIBuilder<TReturnType>;
|
||||
glob(...patterns: string[]): Builder<TReturnType, TGlobFunction>;
|
||||
globWithOptions(patterns: string[]): Builder<TReturnType, TGlobFunction>;
|
||||
globWithOptions(patterns: string[], ...options: GlobParams<TGlobFunction>): Builder<TReturnType, TGlobFunction>;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/index.d.ts
|
||||
type Fdir = typeof Builder;
|
||||
//#endregion
|
||||
export { Counts, ExcludePredicate, Fdir, FilterPredicate, GlobFunction, GlobMatcher, GlobParams, Group, GroupOutput, OnlyCountsOutput, Options, Output, PathSeparator, PathsOutput, ResultCallback, WalkerState, Builder as fdir };
|
4
node_modules/fdir/dist/index.d.ts
generated
vendored
Normal file
4
node_modules/fdir/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { Builder } from "./builder";
|
||||
export { Builder as fdir };
|
||||
export type Fdir = typeof Builder;
|
||||
export * from "./types";
|
20
node_modules/fdir/dist/index.js
generated
vendored
Normal file
20
node_modules/fdir/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"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.fdir = void 0;
|
||||
const builder_1 = require("./builder");
|
||||
Object.defineProperty(exports, "fdir", { enumerable: true, get: function () { return builder_1.Builder; } });
|
||||
__exportStar(require("./types"), exports);
|
554
node_modules/fdir/dist/index.mjs
generated
vendored
Normal file
554
node_modules/fdir/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,554 @@
|
||||
import { createRequire } from "module";
|
||||
import { basename, dirname, normalize, relative, resolve, sep } from "path";
|
||||
import fs from "fs";
|
||||
|
||||
//#region rolldown:runtime
|
||||
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
||||
|
||||
//#endregion
|
||||
//#region src/utils.ts
|
||||
function cleanPath(path) {
|
||||
let normalized = normalize(path);
|
||||
if (normalized.length > 1 && normalized[normalized.length - 1] === sep) normalized = normalized.substring(0, normalized.length - 1);
|
||||
return normalized;
|
||||
}
|
||||
const SLASHES_REGEX = /[\\/]/g;
|
||||
function convertSlashes(path, separator) {
|
||||
return path.replace(SLASHES_REGEX, separator);
|
||||
}
|
||||
const WINDOWS_ROOT_DIR_REGEX = /^[a-z]:[\\/]$/i;
|
||||
function isRootDirectory(path) {
|
||||
return path === "/" || WINDOWS_ROOT_DIR_REGEX.test(path);
|
||||
}
|
||||
function normalizePath(path, options) {
|
||||
const { resolvePaths, normalizePath: normalizePath$1, pathSeparator } = options;
|
||||
const pathNeedsCleaning = process.platform === "win32" && path.includes("/") || path.startsWith(".");
|
||||
if (resolvePaths) path = resolve(path);
|
||||
if (normalizePath$1 || pathNeedsCleaning) path = cleanPath(path);
|
||||
if (path === ".") return "";
|
||||
const needsSeperator = path[path.length - 1] !== pathSeparator;
|
||||
return convertSlashes(needsSeperator ? path + pathSeparator : path, pathSeparator);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/join-path.ts
|
||||
function joinPathWithBasePath(filename, directoryPath) {
|
||||
return directoryPath + filename;
|
||||
}
|
||||
function joinPathWithRelativePath(root, options) {
|
||||
return function(filename, directoryPath) {
|
||||
const sameRoot = directoryPath.startsWith(root);
|
||||
if (sameRoot) return directoryPath.replace(root, "") + filename;
|
||||
else return convertSlashes(relative(root, directoryPath), options.pathSeparator) + options.pathSeparator + filename;
|
||||
};
|
||||
}
|
||||
function joinPath(filename) {
|
||||
return filename;
|
||||
}
|
||||
function joinDirectoryPath(filename, directoryPath, separator) {
|
||||
return directoryPath + filename + separator;
|
||||
}
|
||||
function build$7(root, options) {
|
||||
const { relativePaths, includeBasePath } = options;
|
||||
return relativePaths && root ? joinPathWithRelativePath(root, options) : includeBasePath ? joinPathWithBasePath : joinPath;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/push-directory.ts
|
||||
function pushDirectoryWithRelativePath(root) {
|
||||
return function(directoryPath, paths) {
|
||||
paths.push(directoryPath.substring(root.length) || ".");
|
||||
};
|
||||
}
|
||||
function pushDirectoryFilterWithRelativePath(root) {
|
||||
return function(directoryPath, paths, filters) {
|
||||
const relativePath = directoryPath.substring(root.length) || ".";
|
||||
if (filters.every((filter) => filter(relativePath, true))) paths.push(relativePath);
|
||||
};
|
||||
}
|
||||
const pushDirectory = (directoryPath, paths) => {
|
||||
paths.push(directoryPath || ".");
|
||||
};
|
||||
const pushDirectoryFilter = (directoryPath, paths, filters) => {
|
||||
const path = directoryPath || ".";
|
||||
if (filters.every((filter) => filter(path, true))) paths.push(path);
|
||||
};
|
||||
const empty$2 = () => {};
|
||||
function build$6(root, options) {
|
||||
const { includeDirs, filters, relativePaths } = options;
|
||||
if (!includeDirs) return empty$2;
|
||||
if (relativePaths) return filters && filters.length ? pushDirectoryFilterWithRelativePath(root) : pushDirectoryWithRelativePath(root);
|
||||
return filters && filters.length ? pushDirectoryFilter : pushDirectory;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/push-file.ts
|
||||
const pushFileFilterAndCount = (filename, _paths, counts, filters) => {
|
||||
if (filters.every((filter) => filter(filename, false))) counts.files++;
|
||||
};
|
||||
const pushFileFilter = (filename, paths, _counts, filters) => {
|
||||
if (filters.every((filter) => filter(filename, false))) paths.push(filename);
|
||||
};
|
||||
const pushFileCount = (_filename, _paths, counts, _filters) => {
|
||||
counts.files++;
|
||||
};
|
||||
const pushFile = (filename, paths) => {
|
||||
paths.push(filename);
|
||||
};
|
||||
const empty$1 = () => {};
|
||||
function build$5(options) {
|
||||
const { excludeFiles, filters, onlyCounts } = options;
|
||||
if (excludeFiles) return empty$1;
|
||||
if (filters && filters.length) return onlyCounts ? pushFileFilterAndCount : pushFileFilter;
|
||||
else if (onlyCounts) return pushFileCount;
|
||||
else return pushFile;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/get-array.ts
|
||||
const getArray = (paths) => {
|
||||
return paths;
|
||||
};
|
||||
const getArrayGroup = () => {
|
||||
return [""].slice(0, 0);
|
||||
};
|
||||
function build$4(options) {
|
||||
return options.group ? getArrayGroup : getArray;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/group-files.ts
|
||||
const groupFiles = (groups, directory, files) => {
|
||||
groups.push({
|
||||
directory,
|
||||
files,
|
||||
dir: directory
|
||||
});
|
||||
};
|
||||
const empty = () => {};
|
||||
function build$3(options) {
|
||||
return options.group ? groupFiles : empty;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/resolve-symlink.ts
|
||||
const resolveSymlinksAsync = function(path, state, callback$1) {
|
||||
const { queue, options: { suppressErrors } } = state;
|
||||
queue.enqueue();
|
||||
fs.realpath(path, (error, resolvedPath) => {
|
||||
if (error) return queue.dequeue(suppressErrors ? null : error, state);
|
||||
fs.stat(resolvedPath, (error$1, stat) => {
|
||||
if (error$1) return queue.dequeue(suppressErrors ? null : error$1, state);
|
||||
if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return queue.dequeue(null, state);
|
||||
callback$1(stat, resolvedPath);
|
||||
queue.dequeue(null, state);
|
||||
});
|
||||
});
|
||||
};
|
||||
const resolveSymlinks = function(path, state, callback$1) {
|
||||
const { queue, options: { suppressErrors } } = state;
|
||||
queue.enqueue();
|
||||
try {
|
||||
const resolvedPath = fs.realpathSync(path);
|
||||
const stat = fs.statSync(resolvedPath);
|
||||
if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return;
|
||||
callback$1(stat, resolvedPath);
|
||||
} catch (e) {
|
||||
if (!suppressErrors) throw e;
|
||||
}
|
||||
};
|
||||
function build$2(options, isSynchronous) {
|
||||
if (!options.resolveSymlinks || options.excludeSymlinks) return null;
|
||||
return isSynchronous ? resolveSymlinks : resolveSymlinksAsync;
|
||||
}
|
||||
function isRecursive(path, resolved, state) {
|
||||
if (state.options.useRealPaths) return isRecursiveUsingRealPaths(resolved, state);
|
||||
let parent = 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 = dirname(parent);
|
||||
}
|
||||
state.symlinks.set(path, resolved);
|
||||
return depth > 1;
|
||||
}
|
||||
function isRecursiveUsingRealPaths(resolved, state) {
|
||||
return state.visited.includes(resolved + state.options.pathSeparator);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/invoke-callback.ts
|
||||
const onlyCountsSync = (state) => {
|
||||
return state.counts;
|
||||
};
|
||||
const groupsSync = (state) => {
|
||||
return state.groups;
|
||||
};
|
||||
const defaultSync = (state) => {
|
||||
return state.paths;
|
||||
};
|
||||
const limitFilesSync = (state) => {
|
||||
return state.paths.slice(0, state.options.maxFiles);
|
||||
};
|
||||
const onlyCountsAsync = (state, error, callback$1) => {
|
||||
report(error, callback$1, state.counts, state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
const defaultAsync = (state, error, callback$1) => {
|
||||
report(error, callback$1, state.paths, state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
const limitFilesAsync = (state, error, callback$1) => {
|
||||
report(error, callback$1, state.paths.slice(0, state.options.maxFiles), state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
const groupsAsync = (state, error, callback$1) => {
|
||||
report(error, callback$1, state.groups, state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
function report(error, callback$1, output, suppressErrors) {
|
||||
if (error && !suppressErrors) callback$1(error, output);
|
||||
else callback$1(null, output);
|
||||
}
|
||||
function build$1(options, isSynchronous) {
|
||||
const { onlyCounts, group, maxFiles } = options;
|
||||
if (onlyCounts) return isSynchronous ? onlyCountsSync : onlyCountsAsync;
|
||||
else if (group) return isSynchronous ? groupsSync : groupsAsync;
|
||||
else if (maxFiles) return isSynchronous ? limitFilesSync : limitFilesAsync;
|
||||
else return isSynchronous ? defaultSync : defaultAsync;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/walk-directory.ts
|
||||
const readdirOpts = { withFileTypes: true };
|
||||
const walkAsync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
|
||||
state.queue.enqueue();
|
||||
if (currentDepth <= 0) return state.queue.dequeue(null, state);
|
||||
state.visited.push(crawlPath);
|
||||
state.counts.directories++;
|
||||
fs.readdir(crawlPath || ".", readdirOpts, (error, entries = []) => {
|
||||
callback$1(entries, directoryPath, currentDepth);
|
||||
state.queue.dequeue(state.options.suppressErrors ? null : error, state);
|
||||
});
|
||||
};
|
||||
const walkSync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
|
||||
if (currentDepth <= 0) return;
|
||||
state.visited.push(crawlPath);
|
||||
state.counts.directories++;
|
||||
let entries = [];
|
||||
try {
|
||||
entries = fs.readdirSync(crawlPath || ".", readdirOpts);
|
||||
} catch (e) {
|
||||
if (!state.options.suppressErrors) throw e;
|
||||
}
|
||||
callback$1(entries, directoryPath, currentDepth);
|
||||
};
|
||||
function build(isSynchronous) {
|
||||
return isSynchronous ? walkSync : walkAsync;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/queue.ts
|
||||
/**
|
||||
* This is a custom stateless queue to track concurrent async fs calls.
|
||||
* It increments a counter whenever a call is queued and decrements it
|
||||
* as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
|
||||
*/
|
||||
var Queue = class {
|
||||
count = 0;
|
||||
constructor(onQueueEmpty) {
|
||||
this.onQueueEmpty = onQueueEmpty;
|
||||
}
|
||||
enqueue() {
|
||||
this.count++;
|
||||
return this.count;
|
||||
}
|
||||
dequeue(error, output) {
|
||||
if (this.onQueueEmpty && (--this.count <= 0 || error)) {
|
||||
this.onQueueEmpty(error, output);
|
||||
if (error) {
|
||||
output.controller.abort();
|
||||
this.onQueueEmpty = void 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/api/counter.ts
|
||||
var Counter = class {
|
||||
_files = 0;
|
||||
_directories = 0;
|
||||
set files(num) {
|
||||
this._files = num;
|
||||
}
|
||||
get files() {
|
||||
return this._files;
|
||||
}
|
||||
set directories(num) {
|
||||
this._directories = num;
|
||||
}
|
||||
get directories() {
|
||||
return this._directories;
|
||||
}
|
||||
/**
|
||||
* @deprecated use `directories` instead
|
||||
*/
|
||||
/* c8 ignore next 3 */
|
||||
get dirs() {
|
||||
return this._directories;
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/api/walker.ts
|
||||
var Walker = class {
|
||||
root;
|
||||
isSynchronous;
|
||||
state;
|
||||
joinPath;
|
||||
pushDirectory;
|
||||
pushFile;
|
||||
getArray;
|
||||
groupFiles;
|
||||
resolveSymlink;
|
||||
walkDirectory;
|
||||
callbackInvoker;
|
||||
constructor(root, options, callback$1) {
|
||||
this.isSynchronous = !callback$1;
|
||||
this.callbackInvoker = build$1(options, this.isSynchronous);
|
||||
this.root = normalizePath(root, options);
|
||||
this.state = {
|
||||
root: isRootDirectory(this.root) ? this.root : this.root.slice(0, -1),
|
||||
paths: [""].slice(0, 0),
|
||||
groups: [],
|
||||
counts: new Counter(),
|
||||
options,
|
||||
queue: new Queue((error, state) => this.callbackInvoker(state, error, callback$1)),
|
||||
symlinks: /* @__PURE__ */ new Map(),
|
||||
visited: [""].slice(0, 0),
|
||||
controller: new AbortController()
|
||||
};
|
||||
this.joinPath = build$7(this.root, options);
|
||||
this.pushDirectory = build$6(this.root, options);
|
||||
this.pushFile = build$5(options);
|
||||
this.getArray = build$4(options);
|
||||
this.groupFiles = build$3(options);
|
||||
this.resolveSymlink = build$2(options, this.isSynchronous);
|
||||
this.walkDirectory = build(this.isSynchronous);
|
||||
}
|
||||
start() {
|
||||
this.pushDirectory(this.root, this.state.paths, this.state.options.filters);
|
||||
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: resolveSymlinks$1, excludeSymlinks, exclude, maxFiles, signal, useRealPaths, pathSeparator }, controller } = this.state;
|
||||
if (controller.signal.aborted || signal && signal.aborted || maxFiles && paths.length > maxFiles) return;
|
||||
const files = this.getArray(this.state.paths);
|
||||
for (let i = 0; i < entries.length; ++i) {
|
||||
const entry = entries[i];
|
||||
if (entry.isFile() || entry.isSymbolicLink() && !resolveSymlinks$1 && !excludeSymlinks) {
|
||||
const filename = this.joinPath(entry.name, directoryPath);
|
||||
this.pushFile(filename, files, this.state.counts, filters);
|
||||
} else if (entry.isDirectory()) {
|
||||
let path = joinDirectoryPath(entry.name, directoryPath, this.state.options.pathSeparator);
|
||||
if (exclude && exclude(entry.name, path)) continue;
|
||||
this.pushDirectory(path, paths, filters);
|
||||
this.walkDirectory(this.state, path, path, depth - 1, this.walk);
|
||||
} else if (this.resolveSymlink && entry.isSymbolicLink()) {
|
||||
let path = joinPathWithBasePath(entry.name, directoryPath);
|
||||
this.resolveSymlink(path, this.state, (stat, resolvedPath) => {
|
||||
if (stat.isDirectory()) {
|
||||
resolvedPath = normalizePath(resolvedPath, this.state.options);
|
||||
if (exclude && exclude(entry.name, useRealPaths ? resolvedPath : path + pathSeparator)) return;
|
||||
this.walkDirectory(this.state, resolvedPath, useRealPaths ? resolvedPath : path + pathSeparator, depth - 1, this.walk);
|
||||
} else {
|
||||
resolvedPath = useRealPaths ? resolvedPath : path;
|
||||
const filename = basename(resolvedPath);
|
||||
const directoryPath$1 = normalizePath(dirname(resolvedPath), this.state.options);
|
||||
resolvedPath = this.joinPath(filename, directoryPath$1);
|
||||
this.pushFile(resolvedPath, files, this.state.counts, filters);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
this.groupFiles(this.state.groups, directoryPath, files);
|
||||
};
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/api/async.ts
|
||||
function promise(root, options) {
|
||||
return new Promise((resolve$1, reject) => {
|
||||
callback(root, options, (err, output) => {
|
||||
if (err) return reject(err);
|
||||
resolve$1(output);
|
||||
});
|
||||
});
|
||||
}
|
||||
function callback(root, options, callback$1) {
|
||||
let walker = new Walker(root, options, callback$1);
|
||||
walker.start();
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/sync.ts
|
||||
function sync(root, options) {
|
||||
const walker = new Walker(root, options);
|
||||
return walker.start();
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/builder/api-builder.ts
|
||||
var APIBuilder = class {
|
||||
constructor(root, options) {
|
||||
this.root = root;
|
||||
this.options = options;
|
||||
}
|
||||
withPromise() {
|
||||
return promise(this.root, this.options);
|
||||
}
|
||||
withCallback(cb) {
|
||||
callback(this.root, this.options, cb);
|
||||
}
|
||||
sync() {
|
||||
return sync(this.root, this.options);
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/builder/index.ts
|
||||
var pm = null;
|
||||
/* c8 ignore next 6 */
|
||||
try {
|
||||
__require.resolve("picomatch");
|
||||
pm = __require("picomatch");
|
||||
} catch (_e) {}
|
||||
var Builder = class {
|
||||
globCache = {};
|
||||
options = {
|
||||
maxDepth: Infinity,
|
||||
suppressErrors: true,
|
||||
pathSeparator: sep,
|
||||
filters: []
|
||||
};
|
||||
globFunction;
|
||||
constructor(options) {
|
||||
this.options = {
|
||||
...this.options,
|
||||
...options
|
||||
};
|
||||
this.globFunction = this.options.globFunction;
|
||||
}
|
||||
group() {
|
||||
this.options.group = true;
|
||||
return this;
|
||||
}
|
||||
withPathSeparator(separator) {
|
||||
this.options.pathSeparator = separator;
|
||||
return this;
|
||||
}
|
||||
withBasePath() {
|
||||
this.options.includeBasePath = true;
|
||||
return this;
|
||||
}
|
||||
withRelativePaths() {
|
||||
this.options.relativePaths = true;
|
||||
return this;
|
||||
}
|
||||
withDirs() {
|
||||
this.options.includeDirs = true;
|
||||
return this;
|
||||
}
|
||||
withMaxDepth(depth) {
|
||||
this.options.maxDepth = depth;
|
||||
return this;
|
||||
}
|
||||
withMaxFiles(limit) {
|
||||
this.options.maxFiles = limit;
|
||||
return this;
|
||||
}
|
||||
withFullPaths() {
|
||||
this.options.resolvePaths = true;
|
||||
this.options.includeBasePath = true;
|
||||
return this;
|
||||
}
|
||||
withErrors() {
|
||||
this.options.suppressErrors = false;
|
||||
return this;
|
||||
}
|
||||
withSymlinks({ resolvePaths = true } = {}) {
|
||||
this.options.resolveSymlinks = true;
|
||||
this.options.useRealPaths = resolvePaths;
|
||||
return this.withFullPaths();
|
||||
}
|
||||
withAbortSignal(signal) {
|
||||
this.options.signal = signal;
|
||||
return this;
|
||||
}
|
||||
normalize() {
|
||||
this.options.normalizePath = true;
|
||||
return this;
|
||||
}
|
||||
filter(predicate) {
|
||||
this.options.filters.push(predicate);
|
||||
return this;
|
||||
}
|
||||
onlyDirs() {
|
||||
this.options.excludeFiles = true;
|
||||
this.options.includeDirs = true;
|
||||
return this;
|
||||
}
|
||||
exclude(predicate) {
|
||||
this.options.exclude = predicate;
|
||||
return this;
|
||||
}
|
||||
onlyCounts() {
|
||||
this.options.onlyCounts = true;
|
||||
return this;
|
||||
}
|
||||
crawl(root) {
|
||||
return new APIBuilder(root || ".", this.options);
|
||||
}
|
||||
withGlobFunction(fn) {
|
||||
this.globFunction = fn;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @deprecated Pass options using the constructor instead:
|
||||
* ```ts
|
||||
* new fdir(options).crawl("/path/to/root");
|
||||
* ```
|
||||
* This method will be removed in v7.0
|
||||
*/
|
||||
/* c8 ignore next 4 */
|
||||
crawlWithOptions(root, options) {
|
||||
this.options = {
|
||||
...this.options,
|
||||
...options
|
||||
};
|
||||
return new APIBuilder(root || ".", this.options);
|
||||
}
|
||||
glob(...patterns) {
|
||||
if (this.globFunction) return this.globWithOptions(patterns);
|
||||
return this.globWithOptions(patterns, ...[{ dot: true }]);
|
||||
}
|
||||
globWithOptions(patterns, ...options) {
|
||||
const globFn = this.globFunction || pm;
|
||||
/* c8 ignore next 5 */
|
||||
if (!globFn) throw new Error("Please specify a glob function to use glob matching.");
|
||||
var isMatch = this.globCache[patterns.join("\0")];
|
||||
if (!isMatch) {
|
||||
isMatch = globFn(patterns, ...options);
|
||||
this.globCache[patterns.join("\0")] = isMatch;
|
||||
}
|
||||
this.options.filters.push((path) => isMatch(path));
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
export { Builder as fdir };
|
61
node_modules/fdir/dist/types.d.ts
generated
vendored
Normal file
61
node_modules/fdir/dist/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/// <reference types="node" />
|
||||
import { Queue } from "./api/queue";
|
||||
export type Counts = {
|
||||
files: number;
|
||||
directories: number;
|
||||
/**
|
||||
* @deprecated use `directories` instead. Will be removed in v7.0.
|
||||
*/
|
||||
dirs: number;
|
||||
};
|
||||
export type Group = {
|
||||
directory: string;
|
||||
files: string[];
|
||||
/**
|
||||
* @deprecated use `directory` instead. Will be removed in v7.0.
|
||||
*/
|
||||
dir: string;
|
||||
};
|
||||
export type GroupOutput = Group[];
|
||||
export type OnlyCountsOutput = Counts;
|
||||
export type PathsOutput = string[];
|
||||
export type Output = OnlyCountsOutput | PathsOutput | GroupOutput;
|
||||
export type WalkerState = {
|
||||
root: string;
|
||||
paths: string[];
|
||||
groups: Group[];
|
||||
counts: Counts;
|
||||
options: Options;
|
||||
queue: Queue;
|
||||
controller: AbortController;
|
||||
symlinks: Map<string, string>;
|
||||
visited: string[];
|
||||
};
|
||||
export type ResultCallback<TOutput extends Output> = (error: Error | null, output: TOutput) => void;
|
||||
export type FilterPredicate = (path: string, isDirectory: boolean) => boolean;
|
||||
export type ExcludePredicate = (dirName: string, dirPath: string) => boolean;
|
||||
export type PathSeparator = "/" | "\\";
|
||||
export type Options<TGlobFunction = unknown> = {
|
||||
includeBasePath?: boolean;
|
||||
includeDirs?: boolean;
|
||||
normalizePath?: boolean;
|
||||
maxDepth: number;
|
||||
maxFiles?: number;
|
||||
resolvePaths?: boolean;
|
||||
suppressErrors: boolean;
|
||||
group?: boolean;
|
||||
onlyCounts?: boolean;
|
||||
filters: FilterPredicate[];
|
||||
resolveSymlinks?: boolean;
|
||||
useRealPaths?: boolean;
|
||||
excludeFiles?: boolean;
|
||||
excludeSymlinks?: boolean;
|
||||
exclude?: ExcludePredicate;
|
||||
relativePaths?: boolean;
|
||||
pathSeparator: PathSeparator;
|
||||
signal?: AbortSignal;
|
||||
globFunction?: TGlobFunction;
|
||||
};
|
||||
export type GlobMatcher = (test: string) => boolean;
|
||||
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 : [];
|
2
node_modules/fdir/dist/types.js
generated
vendored
Normal file
2
node_modules/fdir/dist/types.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
9
node_modules/fdir/dist/utils.d.ts
generated
vendored
Normal file
9
node_modules/fdir/dist/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { PathSeparator } from "./types";
|
||||
export declare function cleanPath(path: string): string;
|
||||
export declare function convertSlashes(path: string, separator: PathSeparator): string;
|
||||
export declare function isRootDirectory(path: string): boolean;
|
||||
export declare function normalizePath(path: string, options: {
|
||||
resolvePaths?: boolean;
|
||||
normalizePath?: boolean;
|
||||
pathSeparator: PathSeparator;
|
||||
}): string;
|
37
node_modules/fdir/dist/utils.js
generated
vendored
Normal file
37
node_modules/fdir/dist/utils.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.normalizePath = exports.isRootDirectory = exports.convertSlashes = exports.cleanPath = void 0;
|
||||
const path_1 = require("path");
|
||||
function cleanPath(path) {
|
||||
let normalized = (0, path_1.normalize)(path);
|
||||
// we have to remove the last path separator
|
||||
// to account for / root path
|
||||
if (normalized.length > 1 && normalized[normalized.length - 1] === path_1.sep)
|
||||
normalized = normalized.substring(0, normalized.length - 1);
|
||||
return normalized;
|
||||
}
|
||||
exports.cleanPath = cleanPath;
|
||||
const SLASHES_REGEX = /[\\/]/g;
|
||||
function convertSlashes(path, separator) {
|
||||
return path.replace(SLASHES_REGEX, separator);
|
||||
}
|
||||
exports.convertSlashes = convertSlashes;
|
||||
const WINDOWS_ROOT_DIR_REGEX = /^[a-z]:[\\/]$/i;
|
||||
function isRootDirectory(path) {
|
||||
return path === "/" || WINDOWS_ROOT_DIR_REGEX.test(path);
|
||||
}
|
||||
exports.isRootDirectory = isRootDirectory;
|
||||
function normalizePath(path, options) {
|
||||
const { resolvePaths, normalizePath, pathSeparator } = options;
|
||||
const pathNeedsCleaning = (process.platform === "win32" && path.includes("/")) ||
|
||||
path.startsWith(".");
|
||||
if (resolvePaths)
|
||||
path = (0, path_1.resolve)(path);
|
||||
if (normalizePath || pathNeedsCleaning)
|
||||
path = cleanPath(path);
|
||||
if (path === ".")
|
||||
return "";
|
||||
const needsSeperator = path[path.length - 1] !== pathSeparator;
|
||||
return convertSlashes(needsSeperator ? path + pathSeparator : path, pathSeparator);
|
||||
}
|
||||
exports.normalizePath = normalizePath;
|
Reference in New Issue
Block a user