Initial commit

This commit is contained in:
jiapengyu
2026-07-27 13:37:48 +08:00
commit ecba71e2a5
39123 changed files with 5989154 additions and 0 deletions
+106
View File
@@ -0,0 +1,106 @@
import * as fs from 'fs';
import { EventEmitter } from 'events';
export type Stat = fs.Dirent | fs.Stats;
export type Match = {
relative: string;
absolute: string;
stat?: Stat;
};
export type Options = {
/**
* Glob pattern or Array of Glob patterns to match the found files with.
* A file has to match at least one of the provided patterns to be returned.
*/
pattern?: string | string[];
/**
* Allow pattern to match filenames starting with a period, even if the pattern
* does not explicitly have a period in that spot.
*/
dot?: boolean;
/**
* Disable `**` matching against multiple folder names.
*/
noglobstar?: boolean;
/**
* Perform a basename-only match if the pattern does not contain any slash
* characters. That is, `*.js` would be treated as equivalent to `**\/*.js`,
* matching all js files in all directories.
*/
matchBase?: boolean;
/**
* Perform a case-insensitive match. Note: on case-insensitive file systems,
* non-magic patterns will match by default, since `stat` and `readdir` will
* not raise errors.
*/
nocase?: boolean;
/**
* Glob pattern or Array of Glob patterns to exclude matches. If a file or a
* folder matches at least one of the provided patterns, it's not returned.
* It doesn't prevent files from folder content to be returned. Note: ignore
* patterns are always in dot:true mode.
*/
ignore?: string | string[];
/**
* Glob pattern or Array of Glob patterns to exclude folders.
* If a folder matches one of the provided patterns, it's not returned, and
* it's not explored: this prevents any of its children to be returned.
* Note: skip patterns are always in dot:true mode.
*/
skip?: string | string[];
/**
* Follow symlinked directories. Note that requires to stat _all_ results,
* and so reduces performance.
*/
follow?: boolean;
/**
* Set to true to stat _all_ results. This reduces performance.
*/
stat?: boolean;
/**
* Do not match directories, only files.
*/
nodir?: boolean;
/**
* Add a `/` character to directory matches.
*/
mark?: boolean;
/**
* When an unusual error is encountered when attempting to read a directory,
* a warning will be printed to stderr. Set the `silent` option to true to
* suppress these warnings.
*/
silent?: boolean;
/**
* Absolute paths will be returned instead of relative paths.
*/
absolute?: boolean;
};
type StrictOptions = Options & Required<Omit<Options, 'pattern' | 'ignore' | 'skip'>>;
export type Callback = (err: Error | null, matches?: readonly string[]) => void;
export declare class ReaddirGlob extends EventEmitter<{
match: [Match];
end: [];
error: [NodeJS.ErrnoException];
}> {
options: StrictOptions;
private matchers;
private ignoreMatchers;
private skipMatchers;
paused: boolean;
aborted: boolean;
private inactive;
private iterator;
constructor(cwd?: string, options?: Options | Callback, cb?: Callback);
private _shouldSkipDirectory;
private _fileMatches;
private _next;
abort(): void;
pause(): void;
resume(): void;
}
interface readdirGlobInterface {
(pattern?: string, options?: Options | Callback, cb?: Callback): ReaddirGlob;
ReaddirGlob: typeof ReaddirGlob;
}
export declare const readdirGlob: readdirGlobInterface;
export default readdirGlob;
+226
View File
@@ -0,0 +1,226 @@
"use strict";
//#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 fs = __toESM(require("fs"));
const events = __toESM(require("events"));
const minimatch = __toESM(require("minimatch"));
const path = __toESM(require("path"));
//#region src/index.ts
function readdir(dir, strict) {
return new Promise((resolve$1, reject) => {
fs.readdir(dir, { withFileTypes: true }, (err, files) => {
if (err) switch (err.code) {
case "ENOTDIR":
if (strict) reject(err);
else resolve$1([]);
break;
case "ENOTSUP":
case "ENOENT":
case "ENAMETOOLONG":
case "UNKNOWN":
resolve$1([]);
break;
case "ELOOP":
default:
reject(err);
break;
}
else resolve$1(files);
});
});
}
function getStat(file, followSymlinks) {
return new Promise((resolve$1) => {
const statFunc = followSymlinks ? fs.stat : fs.lstat;
statFunc(file, (err, stats) => {
if (err) switch (err.code) {
case "ENOENT":
if (followSymlinks) resolve$1(getStat(file, false));
else resolve$1(null);
break;
default:
resolve$1(null);
break;
}
else resolve$1(stats);
});
});
}
async function* exploreWalkAsync(dir, path$1, followSymlinks, useStat, shouldSkip, strict) {
let files = await readdir(path$1 + dir, strict);
for (const file of files) {
let name = file.name;
const filename = dir + "/" + name;
const relative = filename.slice(1);
const absolute = path$1 + "/" + relative;
let stat = file;
if (useStat || followSymlinks) stat = await getStat(absolute, followSymlinks) ?? stat;
if (stat.isDirectory()) {
if (!shouldSkip(relative)) {
yield {
relative,
absolute,
stat
};
yield* exploreWalkAsync(filename, path$1, followSymlinks, useStat, shouldSkip, false);
}
} else yield {
relative,
absolute,
stat
};
}
}
async function* explore(path$1, followSymlinks, useStat, shouldSkip) {
yield* exploreWalkAsync("", path$1, followSymlinks, useStat, shouldSkip, true);
}
function readOptions(options) {
return {
pattern: options.pattern,
dot: !!options.dot,
noglobstar: !!options.noglobstar,
matchBase: !!options.matchBase,
nocase: !!options.nocase,
ignore: options.ignore,
skip: options.skip,
follow: !!options.follow,
stat: !!options.stat,
nodir: !!options.nodir,
mark: !!options.mark,
silent: !!options.silent,
absolute: !!options.absolute
};
}
var ReaddirGlob = class extends events.EventEmitter {
options;
matchers;
ignoreMatchers;
skipMatchers;
paused;
aborted;
inactive;
iterator;
constructor(cwd, options, cb) {
super();
if (typeof options === "function") {
cb = options;
options = undefined;
}
this.options = readOptions(options || {});
this.matchers = [];
if (this.options.pattern) {
const matchers = Array.isArray(this.options.pattern) ? this.options.pattern : [this.options.pattern];
this.matchers = matchers.map((m) => new minimatch.Minimatch(m, {
dot: this.options.dot,
noglobstar: this.options.noglobstar,
matchBase: this.options.matchBase,
nocase: this.options.nocase
}));
}
this.ignoreMatchers = [];
if (this.options.ignore) {
const ignorePatterns = Array.isArray(this.options.ignore) ? this.options.ignore : [this.options.ignore];
this.ignoreMatchers = ignorePatterns.map((ignore) => new minimatch.Minimatch(ignore, { dot: true }));
}
this.skipMatchers = [];
if (this.options.skip) {
const skipPatterns = Array.isArray(this.options.skip) ? this.options.skip : [this.options.skip];
this.skipMatchers = skipPatterns.map((skip) => new minimatch.Minimatch(skip, { dot: true }));
}
this.iterator = explore((0, path.resolve)(cwd || "."), this.options.follow, this.options.stat, this._shouldSkipDirectory.bind(this));
this.paused = false;
this.inactive = false;
this.aborted = false;
if (cb) {
const nonNullCb = cb;
const matches = [];
this.on("match", (match) => matches.push(this.options.absolute ? match.absolute : match.relative));
this.on("error", (err) => nonNullCb(err));
this.on("end", () => nonNullCb(null, matches));
}
setTimeout(() => this._next());
}
_shouldSkipDirectory(relative) {
return this.skipMatchers.some((m) => m.match(relative));
}
_fileMatches(relative, isDirectory) {
const file = relative + (isDirectory ? "/" : "");
return (this.matchers.length === 0 || this.matchers.some((m) => m.match(file))) && !this.ignoreMatchers.some((m) => m.match(file)) && (!this.options.nodir || !isDirectory);
}
_next() {
if (!this.paused && !this.aborted) this.iterator.next().then((obj) => {
if (!obj.done) {
const isDirectory = obj.value.stat.isDirectory();
if (this._fileMatches(obj.value.relative, isDirectory)) {
let relative = obj.value.relative;
let absolute = obj.value.absolute;
if (this.options.mark && isDirectory) {
relative += "/";
absolute += "/";
}
if (this.options.stat) this.emit("match", {
relative,
absolute,
stat: obj.value.stat
});
else this.emit("match", {
relative,
absolute
});
}
this._next();
} else this.emit("end");
}).catch((err) => {
this.abort();
this.emit("error", err);
if (!err.code && !this.options.silent) console.error(err);
});
else this.inactive = true;
}
abort() {
this.aborted = true;
}
pause() {
this.paused = true;
}
resume() {
this.paused = false;
if (this.inactive) {
this.inactive = false;
this._next();
}
}
};
const readdirGlob = (pattern, options, cb) => new ReaddirGlob(pattern, options, cb);
readdirGlob.ReaddirGlob = ReaddirGlob;
var src_default = readdirGlob;
//#endregion
//#region src/cjs.ts
var cjs_default = src_default;
//#endregion
module.exports = cjs_default;
//# sourceMappingURL=index.js.map
+1
View File
File diff suppressed because one or more lines are too long
+198
View File
@@ -0,0 +1,198 @@
import * as fs from "fs";
import { EventEmitter } from "events";
import { Minimatch } from "minimatch";
import { resolve } from "path";
//#region src/index.ts
function readdir(dir, strict) {
return new Promise((resolve$1, reject) => {
fs.readdir(dir, { withFileTypes: true }, (err, files) => {
if (err) switch (err.code) {
case "ENOTDIR":
if (strict) reject(err);
else resolve$1([]);
break;
case "ENOTSUP":
case "ENOENT":
case "ENAMETOOLONG":
case "UNKNOWN":
resolve$1([]);
break;
case "ELOOP":
default:
reject(err);
break;
}
else resolve$1(files);
});
});
}
function getStat(file, followSymlinks) {
return new Promise((resolve$1) => {
const statFunc = followSymlinks ? fs.stat : fs.lstat;
statFunc(file, (err, stats) => {
if (err) switch (err.code) {
case "ENOENT":
if (followSymlinks) resolve$1(getStat(file, false));
else resolve$1(null);
break;
default:
resolve$1(null);
break;
}
else resolve$1(stats);
});
});
}
async function* exploreWalkAsync(dir, path, followSymlinks, useStat, shouldSkip, strict) {
let files = await readdir(path + dir, strict);
for (const file of files) {
let name = file.name;
const filename = dir + "/" + name;
const relative = filename.slice(1);
const absolute = path + "/" + relative;
let stat = file;
if (useStat || followSymlinks) stat = await getStat(absolute, followSymlinks) ?? stat;
if (stat.isDirectory()) {
if (!shouldSkip(relative)) {
yield {
relative,
absolute,
stat
};
yield* exploreWalkAsync(filename, path, followSymlinks, useStat, shouldSkip, false);
}
} else yield {
relative,
absolute,
stat
};
}
}
async function* explore(path, followSymlinks, useStat, shouldSkip) {
yield* exploreWalkAsync("", path, followSymlinks, useStat, shouldSkip, true);
}
function readOptions(options) {
return {
pattern: options.pattern,
dot: !!options.dot,
noglobstar: !!options.noglobstar,
matchBase: !!options.matchBase,
nocase: !!options.nocase,
ignore: options.ignore,
skip: options.skip,
follow: !!options.follow,
stat: !!options.stat,
nodir: !!options.nodir,
mark: !!options.mark,
silent: !!options.silent,
absolute: !!options.absolute
};
}
var ReaddirGlob = class extends EventEmitter {
options;
matchers;
ignoreMatchers;
skipMatchers;
paused;
aborted;
inactive;
iterator;
constructor(cwd, options, cb) {
super();
if (typeof options === "function") {
cb = options;
options = undefined;
}
this.options = readOptions(options || {});
this.matchers = [];
if (this.options.pattern) {
const matchers = Array.isArray(this.options.pattern) ? this.options.pattern : [this.options.pattern];
this.matchers = matchers.map((m) => new Minimatch(m, {
dot: this.options.dot,
noglobstar: this.options.noglobstar,
matchBase: this.options.matchBase,
nocase: this.options.nocase
}));
}
this.ignoreMatchers = [];
if (this.options.ignore) {
const ignorePatterns = Array.isArray(this.options.ignore) ? this.options.ignore : [this.options.ignore];
this.ignoreMatchers = ignorePatterns.map((ignore) => new Minimatch(ignore, { dot: true }));
}
this.skipMatchers = [];
if (this.options.skip) {
const skipPatterns = Array.isArray(this.options.skip) ? this.options.skip : [this.options.skip];
this.skipMatchers = skipPatterns.map((skip) => new Minimatch(skip, { dot: true }));
}
this.iterator = explore(resolve(cwd || "."), this.options.follow, this.options.stat, this._shouldSkipDirectory.bind(this));
this.paused = false;
this.inactive = false;
this.aborted = false;
if (cb) {
const nonNullCb = cb;
const matches = [];
this.on("match", (match) => matches.push(this.options.absolute ? match.absolute : match.relative));
this.on("error", (err) => nonNullCb(err));
this.on("end", () => nonNullCb(null, matches));
}
setTimeout(() => this._next());
}
_shouldSkipDirectory(relative) {
return this.skipMatchers.some((m) => m.match(relative));
}
_fileMatches(relative, isDirectory) {
const file = relative + (isDirectory ? "/" : "");
return (this.matchers.length === 0 || this.matchers.some((m) => m.match(file))) && !this.ignoreMatchers.some((m) => m.match(file)) && (!this.options.nodir || !isDirectory);
}
_next() {
if (!this.paused && !this.aborted) this.iterator.next().then((obj) => {
if (!obj.done) {
const isDirectory = obj.value.stat.isDirectory();
if (this._fileMatches(obj.value.relative, isDirectory)) {
let relative = obj.value.relative;
let absolute = obj.value.absolute;
if (this.options.mark && isDirectory) {
relative += "/";
absolute += "/";
}
if (this.options.stat) this.emit("match", {
relative,
absolute,
stat: obj.value.stat
});
else this.emit("match", {
relative,
absolute
});
}
this._next();
} else this.emit("end");
}).catch((err) => {
this.abort();
this.emit("error", err);
if (!err.code && !this.options.silent) console.error(err);
});
else this.inactive = true;
}
abort() {
this.aborted = true;
}
pause() {
this.paused = true;
}
resume() {
this.paused = false;
if (this.inactive) {
this.inactive = false;
this._next();
}
}
};
const readdirGlob = (pattern, options, cb) => new ReaddirGlob(pattern, options, cb);
readdirGlob.ReaddirGlob = ReaddirGlob;
var src_default = readdirGlob;
//#endregion
export { ReaddirGlob, src_default as default, readdirGlob };
//# sourceMappingURL=index.mjs.map
+1
View File
File diff suppressed because one or more lines are too long