Update checked-in dependencies
This commit is contained in:
parent
a8ade63a2f
commit
452ffd6e8e
3120 changed files with 20845 additions and 14941 deletions
1
node_modules/tinyglobby/dist/index.d.mts
generated
vendored
1
node_modules/tinyglobby/dist/index.d.mts
generated
vendored
|
|
@ -16,6 +16,7 @@ interface GlobOptions {
|
|||
expandDirectories?: boolean;
|
||||
onlyDirectories?: boolean;
|
||||
onlyFiles?: boolean;
|
||||
debug?: boolean;
|
||||
}
|
||||
declare function glob(patterns: string | string[], options?: Omit<GlobOptions, 'patterns'>): Promise<string[]>;
|
||||
declare function glob(options: GlobOptions): Promise<string[]>;
|
||||
|
|
|
|||
1
node_modules/tinyglobby/dist/index.d.ts
generated
vendored
1
node_modules/tinyglobby/dist/index.d.ts
generated
vendored
|
|
@ -16,6 +16,7 @@ interface GlobOptions {
|
|||
expandDirectories?: boolean;
|
||||
onlyDirectories?: boolean;
|
||||
onlyFiles?: boolean;
|
||||
debug?: boolean;
|
||||
}
|
||||
declare function glob(patterns: string | string[], options?: Omit<GlobOptions, 'patterns'>): Promise<string[]>;
|
||||
declare function glob(options: GlobOptions): Promise<string[]>;
|
||||
|
|
|
|||
205
node_modules/tinyglobby/dist/index.js
generated
vendored
205
node_modules/tinyglobby/dist/index.js
generated
vendored
|
|
@ -28,21 +28,75 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/index.ts
|
||||
var src_exports = {};
|
||||
__export(src_exports, {
|
||||
var index_exports = {};
|
||||
__export(index_exports, {
|
||||
convertPathToPattern: () => convertPathToPattern,
|
||||
escapePath: () => escapePath,
|
||||
glob: () => glob,
|
||||
globSync: () => globSync,
|
||||
isDynamicPattern: () => isDynamicPattern
|
||||
});
|
||||
module.exports = __toCommonJS(src_exports);
|
||||
module.exports = __toCommonJS(index_exports);
|
||||
var import_node_path = __toESM(require("path"));
|
||||
var import_fdir = require("fdir");
|
||||
var import_picomatch2 = __toESM(require("picomatch"));
|
||||
|
||||
// src/utils.ts
|
||||
var import_picomatch = __toESM(require("picomatch"));
|
||||
var ONLY_PARENT_DIRECTORIES = /^(\/?\.\.)+$/;
|
||||
function getPartialMatcher(patterns, options) {
|
||||
const patternsCount = patterns.length;
|
||||
const patternsParts = Array(patternsCount);
|
||||
const regexes = Array(patternsCount);
|
||||
for (let i = 0; i < patternsCount; i++) {
|
||||
const parts = splitPattern(patterns[i]);
|
||||
patternsParts[i] = parts;
|
||||
const partsCount = parts.length;
|
||||
const partRegexes = Array(partsCount);
|
||||
for (let j = 0; j < partsCount; j++) {
|
||||
partRegexes[j] = import_picomatch.default.makeRe(parts[j], options);
|
||||
}
|
||||
regexes[i] = partRegexes;
|
||||
}
|
||||
return (input) => {
|
||||
const inputParts = input.split("/");
|
||||
if (inputParts[0] === ".." && ONLY_PARENT_DIRECTORIES.test(input)) {
|
||||
return true;
|
||||
}
|
||||
for (let i = 0; i < patterns.length; i++) {
|
||||
const patternParts = patternsParts[i];
|
||||
const regex = regexes[i];
|
||||
const inputPatternCount = inputParts.length;
|
||||
const minParts = Math.min(inputPatternCount, patternParts.length);
|
||||
let j = 0;
|
||||
while (j < minParts) {
|
||||
const part = patternParts[j];
|
||||
if (part.includes("/")) {
|
||||
return true;
|
||||
}
|
||||
const match = regex[j].test(inputParts[j]);
|
||||
if (!match) {
|
||||
break;
|
||||
}
|
||||
if (part === "**") {
|
||||
return true;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
if (j === inputPatternCount) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
var splitPatternOptions = { parts: true };
|
||||
function splitPattern(path2) {
|
||||
var _a;
|
||||
const result = import_picomatch.default.scan(path2, splitPatternOptions);
|
||||
return ((_a = result.parts) == null ? void 0 : _a.length) ? result.parts : [path2];
|
||||
}
|
||||
var isWin = process.platform === "win32";
|
||||
var ESCAPED_WIN32_BACKSLASHES = /\\(?![()[\]{}!+@])/g;
|
||||
function convertPosixPathToPattern(path2) {
|
||||
return escapePosixPath(path2);
|
||||
|
|
@ -50,12 +104,12 @@ function convertPosixPathToPattern(path2) {
|
|||
function convertWin32PathToPattern(path2) {
|
||||
return escapeWin32Path(path2).replace(ESCAPED_WIN32_BACKSLASHES, "/");
|
||||
}
|
||||
var convertPathToPattern = process.platform === "win32" ? convertWin32PathToPattern : convertPosixPathToPattern;
|
||||
var convertPathToPattern = isWin ? convertWin32PathToPattern : convertPosixPathToPattern;
|
||||
var POSIX_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}*?|]|^!|[!+@](?=\()|\\(?![()[\]{}!*+?@|]))/g;
|
||||
var WIN32_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}]|^!|[!+@](?=\())/g;
|
||||
var escapePosixPath = (path2) => path2.replace(POSIX_UNESCAPED_GLOB_SYMBOLS, "\\$&");
|
||||
var escapeWin32Path = (path2) => path2.replace(WIN32_UNESCAPED_GLOB_SYMBOLS, "\\$&");
|
||||
var escapePath = process.platform === "win32" ? escapeWin32Path : escapePosixPath;
|
||||
var escapePath = isWin ? escapeWin32Path : escapePosixPath;
|
||||
function isDynamicPattern(pattern, options) {
|
||||
if ((options == null ? void 0 : options.caseSensitiveMatch) === false) {
|
||||
return true;
|
||||
|
|
@ -63,9 +117,15 @@ function isDynamicPattern(pattern, options) {
|
|||
const scan = import_picomatch.default.scan(pattern);
|
||||
return scan.isGlob || scan.negated;
|
||||
}
|
||||
function log(...tasks) {
|
||||
console.log(`[tinyglobby ${(/* @__PURE__ */ new Date()).toLocaleTimeString("es")}]`, ...tasks);
|
||||
}
|
||||
|
||||
// src/index.ts
|
||||
function normalizePattern(pattern, expandDirectories, cwd, properties, isIgnore) {
|
||||
var PARENT_DIRECTORY = /^(\/?\.\.)+/;
|
||||
var ESCAPING_BACKSLASHES = /\\(?=[()[\]{}!*+?@|])/g;
|
||||
var BACKSLASHES = /\\/g;
|
||||
function normalizePattern(pattern, expandDirectories, cwd, props, isIgnore) {
|
||||
var _a;
|
||||
let result = pattern;
|
||||
if (pattern.endsWith("/")) {
|
||||
|
|
@ -74,40 +134,41 @@ function normalizePattern(pattern, expandDirectories, cwd, properties, isIgnore)
|
|||
if (!result.endsWith("*") && expandDirectories) {
|
||||
result += "/**";
|
||||
}
|
||||
if (import_node_path.default.isAbsolute(result.replace(/\\(?=[()[\]{}!*+?@|])/g, ""))) {
|
||||
result = import_node_path.posix.relative(cwd, result);
|
||||
if (import_node_path.default.isAbsolute(result.replace(ESCAPING_BACKSLASHES, ""))) {
|
||||
result = import_node_path.posix.relative(escapePath(cwd), result);
|
||||
} else {
|
||||
result = import_node_path.posix.normalize(result);
|
||||
}
|
||||
const parentDirectoryMatch = /^(\/?\.\.)+/.exec(result);
|
||||
const parentDirectoryMatch = PARENT_DIRECTORY.exec(result);
|
||||
if (parentDirectoryMatch == null ? void 0 : parentDirectoryMatch[0]) {
|
||||
const potentialRoot = import_node_path.posix.join(cwd, parentDirectoryMatch[0]);
|
||||
if (properties.root.length > potentialRoot.length) {
|
||||
properties.root = potentialRoot;
|
||||
properties.depthOffset = -(parentDirectoryMatch[0].length + 1) / 3;
|
||||
if (props.root.length > potentialRoot.length) {
|
||||
props.root = potentialRoot;
|
||||
props.depthOffset = -(parentDirectoryMatch[0].length + 1) / 3;
|
||||
}
|
||||
} else if (!isIgnore && properties.depthOffset >= 0) {
|
||||
const current = result.split("/");
|
||||
(_a = properties.commonPath) != null ? _a : properties.commonPath = current;
|
||||
} else if (!isIgnore && props.depthOffset >= 0) {
|
||||
const parts = splitPattern(result);
|
||||
(_a = props.commonPath) != null ? _a : props.commonPath = parts;
|
||||
const newCommonPath = [];
|
||||
for (let i = 0; i < Math.min(properties.commonPath.length, current.length); i++) {
|
||||
const part = current[i];
|
||||
if (part === "**" && !current[i + 1]) {
|
||||
const length = Math.min(props.commonPath.length, parts.length);
|
||||
for (let i = 0; i < length; i++) {
|
||||
const part = parts[i];
|
||||
if (part === "**" && !parts[i + 1]) {
|
||||
newCommonPath.pop();
|
||||
break;
|
||||
}
|
||||
if (part !== properties.commonPath[i] || isDynamicPattern(part) || i === current.length - 1) {
|
||||
if (part !== props.commonPath[i] || isDynamicPattern(part) || i === parts.length - 1) {
|
||||
break;
|
||||
}
|
||||
newCommonPath.push(part);
|
||||
}
|
||||
properties.depthOffset = newCommonPath.length;
|
||||
properties.commonPath = newCommonPath;
|
||||
properties.root = newCommonPath.length > 0 ? `${cwd}/${newCommonPath.join("/")}` : cwd;
|
||||
props.depthOffset = newCommonPath.length;
|
||||
props.commonPath = newCommonPath;
|
||||
props.root = newCommonPath.length > 0 ? `${cwd}/${newCommonPath.join("/")}` : cwd;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function processPatterns({ patterns, ignore = [], expandDirectories = true }, cwd, properties) {
|
||||
function processPatterns({ patterns, ignore = [], expandDirectories = true }, cwd, props) {
|
||||
if (typeof patterns === "string") {
|
||||
patterns = [patterns];
|
||||
} else if (!patterns) {
|
||||
|
|
@ -119,24 +180,27 @@ function processPatterns({ patterns, ignore = [], expandDirectories = true }, cw
|
|||
const matchPatterns = [];
|
||||
const ignorePatterns = [];
|
||||
for (const pattern of ignore) {
|
||||
if (!pattern.startsWith("!") || pattern[1] === "(") {
|
||||
const newPattern = normalizePattern(pattern, expandDirectories, cwd, properties, true);
|
||||
ignorePatterns.push(newPattern);
|
||||
if (!pattern) {
|
||||
continue;
|
||||
}
|
||||
if (pattern[0] !== "!" || pattern[1] === "(") {
|
||||
ignorePatterns.push(normalizePattern(pattern, expandDirectories, cwd, props, true));
|
||||
}
|
||||
}
|
||||
for (const pattern of patterns) {
|
||||
if (!pattern.startsWith("!") || pattern[1] === "(") {
|
||||
const newPattern = normalizePattern(pattern, expandDirectories, cwd, properties, false);
|
||||
matchPatterns.push(newPattern);
|
||||
if (!pattern) {
|
||||
continue;
|
||||
}
|
||||
if (pattern[0] !== "!" || pattern[1] === "(") {
|
||||
matchPatterns.push(normalizePattern(pattern, expandDirectories, cwd, props, false));
|
||||
} else if (pattern[1] !== "!" || pattern[2] === "(") {
|
||||
const newPattern = normalizePattern(pattern.slice(1), expandDirectories, cwd, properties, true);
|
||||
ignorePatterns.push(newPattern);
|
||||
ignorePatterns.push(normalizePattern(pattern.slice(1), expandDirectories, cwd, props, true));
|
||||
}
|
||||
}
|
||||
return { match: matchPatterns, ignore: ignorePatterns };
|
||||
}
|
||||
function getRelativePath(path2, cwd, root) {
|
||||
return import_node_path.posix.relative(cwd, `${root}/${path2}`);
|
||||
return import_node_path.posix.relative(cwd, `${root}/${path2}`) || ".";
|
||||
}
|
||||
function processPath(path2, cwd, root, isDirectory, absolute) {
|
||||
const relativePath = absolute ? path2.slice(root.length + 1) || "." : path2;
|
||||
|
|
@ -145,32 +209,77 @@ function processPath(path2, cwd, root, isDirectory, absolute) {
|
|||
}
|
||||
return getRelativePath(relativePath, cwd, root);
|
||||
}
|
||||
function formatPaths(paths, cwd, root) {
|
||||
for (let i = paths.length - 1; i >= 0; i--) {
|
||||
const path2 = paths[i];
|
||||
paths[i] = getRelativePath(path2, cwd, root) + (!path2 || path2.endsWith("/") ? "/" : "");
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
function crawl(options, cwd, sync) {
|
||||
const properties = {
|
||||
if (process.env.TINYGLOBBY_DEBUG) {
|
||||
options.debug = true;
|
||||
}
|
||||
if (options.debug) {
|
||||
log("globbing with options:", options, "cwd:", cwd);
|
||||
}
|
||||
if (Array.isArray(options.patterns) && options.patterns.length === 0) {
|
||||
return sync ? [] : Promise.resolve([]);
|
||||
}
|
||||
const props = {
|
||||
root: cwd,
|
||||
commonPath: null,
|
||||
depthOffset: 0
|
||||
};
|
||||
const processed = processPatterns(options, cwd, properties);
|
||||
const processed = processPatterns(options, cwd, props);
|
||||
const nocase = options.caseSensitiveMatch === false;
|
||||
if (options.debug) {
|
||||
log("internal processing patterns:", processed);
|
||||
}
|
||||
const matcher = (0, import_picomatch2.default)(processed.match, {
|
||||
dot: options.dot,
|
||||
nocase: options.caseSensitiveMatch === false,
|
||||
nocase,
|
||||
ignore: processed.ignore
|
||||
});
|
||||
const exclude = (0, import_picomatch2.default)(processed.ignore, {
|
||||
const ignore = (0, import_picomatch2.default)(processed.ignore, {
|
||||
dot: options.dot,
|
||||
nocase: options.caseSensitiveMatch === false
|
||||
nocase
|
||||
});
|
||||
const partialMatcher = getPartialMatcher(processed.match, {
|
||||
dot: options.dot,
|
||||
nocase
|
||||
});
|
||||
const fdirOptions = {
|
||||
// use relative paths in the matcher
|
||||
filters: [(p, isDirectory) => matcher(processPath(p, cwd, properties.root, isDirectory, options.absolute))],
|
||||
exclude: (_, p) => exclude(processPath(p, cwd, properties.root, true, true)),
|
||||
filters: [
|
||||
options.debug ? (p, isDirectory) => {
|
||||
const path2 = processPath(p, cwd, props.root, isDirectory, options.absolute);
|
||||
const matches = matcher(path2);
|
||||
if (matches) {
|
||||
log(`matched ${path2}`);
|
||||
}
|
||||
return matches;
|
||||
} : (p, isDirectory) => matcher(processPath(p, cwd, props.root, isDirectory, options.absolute))
|
||||
],
|
||||
exclude: options.debug ? (_, p) => {
|
||||
const relativePath = processPath(p, cwd, props.root, true, true);
|
||||
const skipped = relativePath !== "." && !partialMatcher(relativePath) || ignore(relativePath);
|
||||
if (skipped) {
|
||||
log(`skipped ${p}`);
|
||||
} else {
|
||||
log(`crawling ${p}`);
|
||||
}
|
||||
return skipped;
|
||||
} : (_, p) => {
|
||||
const relativePath = processPath(p, cwd, props.root, true, true);
|
||||
return relativePath !== "." && !partialMatcher(relativePath) || ignore(relativePath);
|
||||
},
|
||||
pathSeparator: "/",
|
||||
relativePaths: true,
|
||||
resolveSymlinks: true
|
||||
};
|
||||
if (options.deep) {
|
||||
fdirOptions.maxDepth = Math.round(options.deep - properties.depthOffset);
|
||||
fdirOptions.maxDepth = Math.round(options.deep - props.depthOffset);
|
||||
}
|
||||
if (options.absolute) {
|
||||
fdirOptions.relativePaths = false;
|
||||
|
|
@ -187,19 +296,23 @@ function crawl(options, cwd, sync) {
|
|||
} else if (options.onlyFiles === false) {
|
||||
fdirOptions.includeDirs = true;
|
||||
}
|
||||
properties.root = properties.root.replace(/\\/g, "");
|
||||
const api = new import_fdir.fdir(fdirOptions).crawl(properties.root);
|
||||
if (cwd === properties.root || options.absolute) {
|
||||
props.root = props.root.replace(BACKSLASHES, "");
|
||||
const root = props.root;
|
||||
if (options.debug) {
|
||||
log("internal properties:", props);
|
||||
}
|
||||
const api = new import_fdir.fdir(fdirOptions).crawl(root);
|
||||
if (cwd === root || options.absolute) {
|
||||
return sync ? api.sync() : api.withPromise();
|
||||
}
|
||||
return sync ? api.sync().map((p) => getRelativePath(p, cwd, properties.root) + (!p || p.endsWith("/") ? "/" : "")) : api.withPromise().then((paths) => paths.map((p) => getRelativePath(p, cwd, properties.root) + (!p || p.endsWith("/") ? "/" : "")));
|
||||
return sync ? formatPaths(api.sync(), cwd, root) : api.withPromise().then((paths) => formatPaths(paths, cwd, root));
|
||||
}
|
||||
async function glob(patternsOrOptions, options) {
|
||||
if (patternsOrOptions && (options == null ? void 0 : options.patterns)) {
|
||||
throw new Error("Cannot pass patterns as both an argument and an option");
|
||||
}
|
||||
const opts = Array.isArray(patternsOrOptions) || typeof patternsOrOptions === "string" ? { ...options, patterns: patternsOrOptions } : patternsOrOptions;
|
||||
const cwd = opts.cwd ? import_node_path.default.resolve(opts.cwd).replace(/\\/g, "/") : process.cwd().replace(/\\/g, "/");
|
||||
const cwd = opts.cwd ? import_node_path.default.resolve(opts.cwd).replace(BACKSLASHES, "/") : process.cwd().replace(BACKSLASHES, "/");
|
||||
return crawl(opts, cwd, false);
|
||||
}
|
||||
function globSync(patternsOrOptions, options) {
|
||||
|
|
@ -207,7 +320,7 @@ function globSync(patternsOrOptions, options) {
|
|||
throw new Error("Cannot pass patterns as both an argument and an option");
|
||||
}
|
||||
const opts = Array.isArray(patternsOrOptions) || typeof patternsOrOptions === "string" ? { ...options, patterns: patternsOrOptions } : patternsOrOptions;
|
||||
const cwd = opts.cwd ? import_node_path.default.resolve(opts.cwd).replace(/\\/g, "/") : process.cwd().replace(/\\/g, "/");
|
||||
const cwd = opts.cwd ? import_node_path.default.resolve(opts.cwd).replace(BACKSLASHES, "/") : process.cwd().replace(BACKSLASHES, "/");
|
||||
return crawl(opts, cwd, true);
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
|
|
|
|||
199
node_modules/tinyglobby/dist/index.mjs
generated
vendored
199
node_modules/tinyglobby/dist/index.mjs
generated
vendored
|
|
@ -5,6 +5,60 @@ import picomatch2 from "picomatch";
|
|||
|
||||
// src/utils.ts
|
||||
import picomatch from "picomatch";
|
||||
var ONLY_PARENT_DIRECTORIES = /^(\/?\.\.)+$/;
|
||||
function getPartialMatcher(patterns, options) {
|
||||
const patternsCount = patterns.length;
|
||||
const patternsParts = Array(patternsCount);
|
||||
const regexes = Array(patternsCount);
|
||||
for (let i = 0; i < patternsCount; i++) {
|
||||
const parts = splitPattern(patterns[i]);
|
||||
patternsParts[i] = parts;
|
||||
const partsCount = parts.length;
|
||||
const partRegexes = Array(partsCount);
|
||||
for (let j = 0; j < partsCount; j++) {
|
||||
partRegexes[j] = picomatch.makeRe(parts[j], options);
|
||||
}
|
||||
regexes[i] = partRegexes;
|
||||
}
|
||||
return (input) => {
|
||||
const inputParts = input.split("/");
|
||||
if (inputParts[0] === ".." && ONLY_PARENT_DIRECTORIES.test(input)) {
|
||||
return true;
|
||||
}
|
||||
for (let i = 0; i < patterns.length; i++) {
|
||||
const patternParts = patternsParts[i];
|
||||
const regex = regexes[i];
|
||||
const inputPatternCount = inputParts.length;
|
||||
const minParts = Math.min(inputPatternCount, patternParts.length);
|
||||
let j = 0;
|
||||
while (j < minParts) {
|
||||
const part = patternParts[j];
|
||||
if (part.includes("/")) {
|
||||
return true;
|
||||
}
|
||||
const match = regex[j].test(inputParts[j]);
|
||||
if (!match) {
|
||||
break;
|
||||
}
|
||||
if (part === "**") {
|
||||
return true;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
if (j === inputPatternCount) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
var splitPatternOptions = { parts: true };
|
||||
function splitPattern(path2) {
|
||||
var _a;
|
||||
const result = picomatch.scan(path2, splitPatternOptions);
|
||||
return ((_a = result.parts) == null ? void 0 : _a.length) ? result.parts : [path2];
|
||||
}
|
||||
var isWin = process.platform === "win32";
|
||||
var ESCAPED_WIN32_BACKSLASHES = /\\(?![()[\]{}!+@])/g;
|
||||
function convertPosixPathToPattern(path2) {
|
||||
return escapePosixPath(path2);
|
||||
|
|
@ -12,12 +66,12 @@ function convertPosixPathToPattern(path2) {
|
|||
function convertWin32PathToPattern(path2) {
|
||||
return escapeWin32Path(path2).replace(ESCAPED_WIN32_BACKSLASHES, "/");
|
||||
}
|
||||
var convertPathToPattern = process.platform === "win32" ? convertWin32PathToPattern : convertPosixPathToPattern;
|
||||
var convertPathToPattern = isWin ? convertWin32PathToPattern : convertPosixPathToPattern;
|
||||
var POSIX_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}*?|]|^!|[!+@](?=\()|\\(?![()[\]{}!*+?@|]))/g;
|
||||
var WIN32_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}]|^!|[!+@](?=\())/g;
|
||||
var escapePosixPath = (path2) => path2.replace(POSIX_UNESCAPED_GLOB_SYMBOLS, "\\$&");
|
||||
var escapeWin32Path = (path2) => path2.replace(WIN32_UNESCAPED_GLOB_SYMBOLS, "\\$&");
|
||||
var escapePath = process.platform === "win32" ? escapeWin32Path : escapePosixPath;
|
||||
var escapePath = isWin ? escapeWin32Path : escapePosixPath;
|
||||
function isDynamicPattern(pattern, options) {
|
||||
if ((options == null ? void 0 : options.caseSensitiveMatch) === false) {
|
||||
return true;
|
||||
|
|
@ -25,9 +79,15 @@ function isDynamicPattern(pattern, options) {
|
|||
const scan = picomatch.scan(pattern);
|
||||
return scan.isGlob || scan.negated;
|
||||
}
|
||||
function log(...tasks) {
|
||||
console.log(`[tinyglobby ${(/* @__PURE__ */ new Date()).toLocaleTimeString("es")}]`, ...tasks);
|
||||
}
|
||||
|
||||
// src/index.ts
|
||||
function normalizePattern(pattern, expandDirectories, cwd, properties, isIgnore) {
|
||||
var PARENT_DIRECTORY = /^(\/?\.\.)+/;
|
||||
var ESCAPING_BACKSLASHES = /\\(?=[()[\]{}!*+?@|])/g;
|
||||
var BACKSLASHES = /\\/g;
|
||||
function normalizePattern(pattern, expandDirectories, cwd, props, isIgnore) {
|
||||
var _a;
|
||||
let result = pattern;
|
||||
if (pattern.endsWith("/")) {
|
||||
|
|
@ -36,40 +96,41 @@ function normalizePattern(pattern, expandDirectories, cwd, properties, isIgnore)
|
|||
if (!result.endsWith("*") && expandDirectories) {
|
||||
result += "/**";
|
||||
}
|
||||
if (path.isAbsolute(result.replace(/\\(?=[()[\]{}!*+?@|])/g, ""))) {
|
||||
result = posix.relative(cwd, result);
|
||||
if (path.isAbsolute(result.replace(ESCAPING_BACKSLASHES, ""))) {
|
||||
result = posix.relative(escapePath(cwd), result);
|
||||
} else {
|
||||
result = posix.normalize(result);
|
||||
}
|
||||
const parentDirectoryMatch = /^(\/?\.\.)+/.exec(result);
|
||||
const parentDirectoryMatch = PARENT_DIRECTORY.exec(result);
|
||||
if (parentDirectoryMatch == null ? void 0 : parentDirectoryMatch[0]) {
|
||||
const potentialRoot = posix.join(cwd, parentDirectoryMatch[0]);
|
||||
if (properties.root.length > potentialRoot.length) {
|
||||
properties.root = potentialRoot;
|
||||
properties.depthOffset = -(parentDirectoryMatch[0].length + 1) / 3;
|
||||
if (props.root.length > potentialRoot.length) {
|
||||
props.root = potentialRoot;
|
||||
props.depthOffset = -(parentDirectoryMatch[0].length + 1) / 3;
|
||||
}
|
||||
} else if (!isIgnore && properties.depthOffset >= 0) {
|
||||
const current = result.split("/");
|
||||
(_a = properties.commonPath) != null ? _a : properties.commonPath = current;
|
||||
} else if (!isIgnore && props.depthOffset >= 0) {
|
||||
const parts = splitPattern(result);
|
||||
(_a = props.commonPath) != null ? _a : props.commonPath = parts;
|
||||
const newCommonPath = [];
|
||||
for (let i = 0; i < Math.min(properties.commonPath.length, current.length); i++) {
|
||||
const part = current[i];
|
||||
if (part === "**" && !current[i + 1]) {
|
||||
const length = Math.min(props.commonPath.length, parts.length);
|
||||
for (let i = 0; i < length; i++) {
|
||||
const part = parts[i];
|
||||
if (part === "**" && !parts[i + 1]) {
|
||||
newCommonPath.pop();
|
||||
break;
|
||||
}
|
||||
if (part !== properties.commonPath[i] || isDynamicPattern(part) || i === current.length - 1) {
|
||||
if (part !== props.commonPath[i] || isDynamicPattern(part) || i === parts.length - 1) {
|
||||
break;
|
||||
}
|
||||
newCommonPath.push(part);
|
||||
}
|
||||
properties.depthOffset = newCommonPath.length;
|
||||
properties.commonPath = newCommonPath;
|
||||
properties.root = newCommonPath.length > 0 ? `${cwd}/${newCommonPath.join("/")}` : cwd;
|
||||
props.depthOffset = newCommonPath.length;
|
||||
props.commonPath = newCommonPath;
|
||||
props.root = newCommonPath.length > 0 ? `${cwd}/${newCommonPath.join("/")}` : cwd;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function processPatterns({ patterns, ignore = [], expandDirectories = true }, cwd, properties) {
|
||||
function processPatterns({ patterns, ignore = [], expandDirectories = true }, cwd, props) {
|
||||
if (typeof patterns === "string") {
|
||||
patterns = [patterns];
|
||||
} else if (!patterns) {
|
||||
|
|
@ -81,24 +142,27 @@ function processPatterns({ patterns, ignore = [], expandDirectories = true }, cw
|
|||
const matchPatterns = [];
|
||||
const ignorePatterns = [];
|
||||
for (const pattern of ignore) {
|
||||
if (!pattern.startsWith("!") || pattern[1] === "(") {
|
||||
const newPattern = normalizePattern(pattern, expandDirectories, cwd, properties, true);
|
||||
ignorePatterns.push(newPattern);
|
||||
if (!pattern) {
|
||||
continue;
|
||||
}
|
||||
if (pattern[0] !== "!" || pattern[1] === "(") {
|
||||
ignorePatterns.push(normalizePattern(pattern, expandDirectories, cwd, props, true));
|
||||
}
|
||||
}
|
||||
for (const pattern of patterns) {
|
||||
if (!pattern.startsWith("!") || pattern[1] === "(") {
|
||||
const newPattern = normalizePattern(pattern, expandDirectories, cwd, properties, false);
|
||||
matchPatterns.push(newPattern);
|
||||
if (!pattern) {
|
||||
continue;
|
||||
}
|
||||
if (pattern[0] !== "!" || pattern[1] === "(") {
|
||||
matchPatterns.push(normalizePattern(pattern, expandDirectories, cwd, props, false));
|
||||
} else if (pattern[1] !== "!" || pattern[2] === "(") {
|
||||
const newPattern = normalizePattern(pattern.slice(1), expandDirectories, cwd, properties, true);
|
||||
ignorePatterns.push(newPattern);
|
||||
ignorePatterns.push(normalizePattern(pattern.slice(1), expandDirectories, cwd, props, true));
|
||||
}
|
||||
}
|
||||
return { match: matchPatterns, ignore: ignorePatterns };
|
||||
}
|
||||
function getRelativePath(path2, cwd, root) {
|
||||
return posix.relative(cwd, `${root}/${path2}`);
|
||||
return posix.relative(cwd, `${root}/${path2}`) || ".";
|
||||
}
|
||||
function processPath(path2, cwd, root, isDirectory, absolute) {
|
||||
const relativePath = absolute ? path2.slice(root.length + 1) || "." : path2;
|
||||
|
|
@ -107,32 +171,77 @@ function processPath(path2, cwd, root, isDirectory, absolute) {
|
|||
}
|
||||
return getRelativePath(relativePath, cwd, root);
|
||||
}
|
||||
function formatPaths(paths, cwd, root) {
|
||||
for (let i = paths.length - 1; i >= 0; i--) {
|
||||
const path2 = paths[i];
|
||||
paths[i] = getRelativePath(path2, cwd, root) + (!path2 || path2.endsWith("/") ? "/" : "");
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
function crawl(options, cwd, sync) {
|
||||
const properties = {
|
||||
if (process.env.TINYGLOBBY_DEBUG) {
|
||||
options.debug = true;
|
||||
}
|
||||
if (options.debug) {
|
||||
log("globbing with options:", options, "cwd:", cwd);
|
||||
}
|
||||
if (Array.isArray(options.patterns) && options.patterns.length === 0) {
|
||||
return sync ? [] : Promise.resolve([]);
|
||||
}
|
||||
const props = {
|
||||
root: cwd,
|
||||
commonPath: null,
|
||||
depthOffset: 0
|
||||
};
|
||||
const processed = processPatterns(options, cwd, properties);
|
||||
const processed = processPatterns(options, cwd, props);
|
||||
const nocase = options.caseSensitiveMatch === false;
|
||||
if (options.debug) {
|
||||
log("internal processing patterns:", processed);
|
||||
}
|
||||
const matcher = picomatch2(processed.match, {
|
||||
dot: options.dot,
|
||||
nocase: options.caseSensitiveMatch === false,
|
||||
nocase,
|
||||
ignore: processed.ignore
|
||||
});
|
||||
const exclude = picomatch2(processed.ignore, {
|
||||
const ignore = picomatch2(processed.ignore, {
|
||||
dot: options.dot,
|
||||
nocase: options.caseSensitiveMatch === false
|
||||
nocase
|
||||
});
|
||||
const partialMatcher = getPartialMatcher(processed.match, {
|
||||
dot: options.dot,
|
||||
nocase
|
||||
});
|
||||
const fdirOptions = {
|
||||
// use relative paths in the matcher
|
||||
filters: [(p, isDirectory) => matcher(processPath(p, cwd, properties.root, isDirectory, options.absolute))],
|
||||
exclude: (_, p) => exclude(processPath(p, cwd, properties.root, true, true)),
|
||||
filters: [
|
||||
options.debug ? (p, isDirectory) => {
|
||||
const path2 = processPath(p, cwd, props.root, isDirectory, options.absolute);
|
||||
const matches = matcher(path2);
|
||||
if (matches) {
|
||||
log(`matched ${path2}`);
|
||||
}
|
||||
return matches;
|
||||
} : (p, isDirectory) => matcher(processPath(p, cwd, props.root, isDirectory, options.absolute))
|
||||
],
|
||||
exclude: options.debug ? (_, p) => {
|
||||
const relativePath = processPath(p, cwd, props.root, true, true);
|
||||
const skipped = relativePath !== "." && !partialMatcher(relativePath) || ignore(relativePath);
|
||||
if (skipped) {
|
||||
log(`skipped ${p}`);
|
||||
} else {
|
||||
log(`crawling ${p}`);
|
||||
}
|
||||
return skipped;
|
||||
} : (_, p) => {
|
||||
const relativePath = processPath(p, cwd, props.root, true, true);
|
||||
return relativePath !== "." && !partialMatcher(relativePath) || ignore(relativePath);
|
||||
},
|
||||
pathSeparator: "/",
|
||||
relativePaths: true,
|
||||
resolveSymlinks: true
|
||||
};
|
||||
if (options.deep) {
|
||||
fdirOptions.maxDepth = Math.round(options.deep - properties.depthOffset);
|
||||
fdirOptions.maxDepth = Math.round(options.deep - props.depthOffset);
|
||||
}
|
||||
if (options.absolute) {
|
||||
fdirOptions.relativePaths = false;
|
||||
|
|
@ -149,19 +258,23 @@ function crawl(options, cwd, sync) {
|
|||
} else if (options.onlyFiles === false) {
|
||||
fdirOptions.includeDirs = true;
|
||||
}
|
||||
properties.root = properties.root.replace(/\\/g, "");
|
||||
const api = new fdir(fdirOptions).crawl(properties.root);
|
||||
if (cwd === properties.root || options.absolute) {
|
||||
props.root = props.root.replace(BACKSLASHES, "");
|
||||
const root = props.root;
|
||||
if (options.debug) {
|
||||
log("internal properties:", props);
|
||||
}
|
||||
const api = new fdir(fdirOptions).crawl(root);
|
||||
if (cwd === root || options.absolute) {
|
||||
return sync ? api.sync() : api.withPromise();
|
||||
}
|
||||
return sync ? api.sync().map((p) => getRelativePath(p, cwd, properties.root) + (!p || p.endsWith("/") ? "/" : "")) : api.withPromise().then((paths) => paths.map((p) => getRelativePath(p, cwd, properties.root) + (!p || p.endsWith("/") ? "/" : "")));
|
||||
return sync ? formatPaths(api.sync(), cwd, root) : api.withPromise().then((paths) => formatPaths(paths, cwd, root));
|
||||
}
|
||||
async function glob(patternsOrOptions, options) {
|
||||
if (patternsOrOptions && (options == null ? void 0 : options.patterns)) {
|
||||
throw new Error("Cannot pass patterns as both an argument and an option");
|
||||
}
|
||||
const opts = Array.isArray(patternsOrOptions) || typeof patternsOrOptions === "string" ? { ...options, patterns: patternsOrOptions } : patternsOrOptions;
|
||||
const cwd = opts.cwd ? path.resolve(opts.cwd).replace(/\\/g, "/") : process.cwd().replace(/\\/g, "/");
|
||||
const cwd = opts.cwd ? path.resolve(opts.cwd).replace(BACKSLASHES, "/") : process.cwd().replace(BACKSLASHES, "/");
|
||||
return crawl(opts, cwd, false);
|
||||
}
|
||||
function globSync(patternsOrOptions, options) {
|
||||
|
|
@ -169,7 +282,7 @@ function globSync(patternsOrOptions, options) {
|
|||
throw new Error("Cannot pass patterns as both an argument and an option");
|
||||
}
|
||||
const opts = Array.isArray(patternsOrOptions) || typeof patternsOrOptions === "string" ? { ...options, patterns: patternsOrOptions } : patternsOrOptions;
|
||||
const cwd = opts.cwd ? path.resolve(opts.cwd).replace(/\\/g, "/") : process.cwd().replace(/\\/g, "/");
|
||||
const cwd = opts.cwd ? path.resolve(opts.cwd).replace(BACKSLASHES, "/") : process.cwd().replace(BACKSLASHES, "/");
|
||||
return crawl(opts, cwd, true);
|
||||
}
|
||||
export {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue