fast-glob
Advanced tools
Comparing version 3.2.12 to 3.3.0
@@ -5,9 +5,9 @@ /// <reference types="node" /> | ||
import { Entry as EntryInternal, FileSystemAdapter as FileSystemAdapterInternal, Pattern as PatternInternal } from './types'; | ||
declare type EntryObjectModePredicate = { | ||
type EntryObjectModePredicate = { | ||
[TKey in keyof Pick<OptionsInternal, 'objectMode'>]-?: true; | ||
}; | ||
declare type EntryStatsPredicate = { | ||
type EntryStatsPredicate = { | ||
[TKey in keyof Pick<OptionsInternal, 'stats'>]-?: true; | ||
}; | ||
declare type EntryObjectPredicate = EntryObjectModePredicate | EntryStatsPredicate; | ||
type EntryObjectPredicate = EntryObjectModePredicate | EntryStatsPredicate; | ||
declare function FastGlob(source: PatternInternal | PatternInternal[], options: OptionsInternal & EntryObjectPredicate): Promise<EntryInternal[]>; | ||
@@ -21,2 +21,6 @@ declare function FastGlob(source: PatternInternal | PatternInternal[], options?: OptionsInternal): Promise<string[]>; | ||
type FileSystemAdapter = FileSystemAdapterInternal; | ||
const glob: typeof FastGlob; | ||
const globSync: typeof sync; | ||
const globStream: typeof stream; | ||
const async: typeof FastGlob; | ||
function sync(source: PatternInternal | PatternInternal[], options: OptionsInternal & EntryObjectPredicate): EntryInternal[]; | ||
@@ -27,4 +31,13 @@ function sync(source: PatternInternal | PatternInternal[], options?: OptionsInternal): string[]; | ||
function isDynamicPattern(source: PatternInternal, options?: OptionsInternal): boolean; | ||
function escapePath(source: PatternInternal): PatternInternal; | ||
function escapePath(source: string): PatternInternal; | ||
function convertPathToPattern(source: string): PatternInternal; | ||
namespace posix { | ||
function escapePath(source: string): PatternInternal; | ||
function convertPathToPattern(source: string): PatternInternal; | ||
} | ||
namespace win32 { | ||
function escapePath(source: string): PatternInternal; | ||
function convertPathToPattern(source: string): PatternInternal; | ||
} | ||
} | ||
export = FastGlob; |
"use strict"; | ||
const taskManager = require("./managers/tasks"); | ||
const patternManager = require("./managers/patterns"); | ||
const async_1 = require("./providers/async"); | ||
@@ -18,2 +17,6 @@ const stream_1 = require("./providers/stream"); | ||
(function (FastGlob) { | ||
FastGlob.glob = FastGlob; | ||
FastGlob.globSync = sync; | ||
FastGlob.globStream = stream; | ||
FastGlob.async = FastGlob; | ||
function sync(source, options) { | ||
@@ -38,3 +41,3 @@ assertPatternsInput(source); | ||
assertPatternsInput(source); | ||
const patterns = patternManager.transform([].concat(source)); | ||
const patterns = [].concat(source); | ||
const settings = new settings_1.default(options); | ||
@@ -55,5 +58,36 @@ return taskManager.generate(patterns, settings); | ||
FastGlob.escapePath = escapePath; | ||
function convertPathToPattern(source) { | ||
assertPatternsInput(source); | ||
return utils.path.convertPathToPattern(source); | ||
} | ||
FastGlob.convertPathToPattern = convertPathToPattern; | ||
let posix; | ||
(function (posix) { | ||
function escapePath(source) { | ||
assertPatternsInput(source); | ||
return utils.path.escapePosixPath(source); | ||
} | ||
posix.escapePath = escapePath; | ||
function convertPathToPattern(source) { | ||
assertPatternsInput(source); | ||
return utils.path.convertPosixPathToPattern(source); | ||
} | ||
posix.convertPathToPattern = convertPathToPattern; | ||
})(posix = FastGlob.posix || (FastGlob.posix = {})); | ||
let win32; | ||
(function (win32) { | ||
function escapePath(source) { | ||
assertPatternsInput(source); | ||
return utils.path.escapeWindowsPath(source); | ||
} | ||
win32.escapePath = escapePath; | ||
function convertPathToPattern(source) { | ||
assertPatternsInput(source); | ||
return utils.path.convertWindowsPathToPattern(source); | ||
} | ||
win32.convertPathToPattern = convertPathToPattern; | ||
})(win32 = FastGlob.win32 || (FastGlob.win32 = {})); | ||
})(FastGlob || (FastGlob = {})); | ||
function getWorks(source, _Provider, options) { | ||
const patterns = patternManager.transform([].concat(source)); | ||
const patterns = [].concat(source); | ||
const settings = new settings_1.default(options); | ||
@@ -60,0 +94,0 @@ const tasks = taskManager.generate(patterns, settings); |
import Settings from '../settings'; | ||
import { Pattern, PatternsGroup } from '../types'; | ||
export declare type Task = { | ||
export type Task = { | ||
base: string; | ||
@@ -10,3 +10,3 @@ dynamic: boolean; | ||
}; | ||
export declare function generate(patterns: Pattern[], settings: Settings): Task[]; | ||
export declare function generate(input: Pattern[], settings: Settings): Task[]; | ||
/** | ||
@@ -13,0 +13,0 @@ * Returns tasks grouped by basic pattern directories. |
@@ -5,5 +5,7 @@ "use strict"; | ||
const utils = require("../utils"); | ||
function generate(patterns, settings) { | ||
function generate(input, settings) { | ||
const patterns = processPatterns(input, settings); | ||
const ignore = processPatterns(settings.ignore, settings); | ||
const positivePatterns = getPositivePatterns(patterns); | ||
const negativePatterns = getNegativePatternsAsPositive(patterns, settings.ignore); | ||
const negativePatterns = getNegativePatternsAsPositive(patterns, ignore); | ||
const staticPatterns = positivePatterns.filter((pattern) => utils.pattern.isStaticPattern(pattern, settings)); | ||
@@ -16,2 +18,30 @@ const dynamicPatterns = positivePatterns.filter((pattern) => utils.pattern.isDynamicPattern(pattern, settings)); | ||
exports.generate = generate; | ||
function processPatterns(input, settings) { | ||
let patterns = input; | ||
/** | ||
* The original pattern like `{,*,**,a/*}` can lead to problems checking the depth when matching entry | ||
* and some problems with the micromatch package (see fast-glob issues: #365, #394). | ||
* | ||
* To solve this problem, we expand all patterns containing brace expansion. This can lead to a slight slowdown | ||
* in matching in the case of a large set of patterns after expansion. | ||
*/ | ||
if (settings.braceExpansion) { | ||
patterns = utils.pattern.expandPatternsWithBraceExpansion(patterns); | ||
} | ||
/** | ||
* If the `baseNameMatch` option is enabled, we must add globstar to patterns, so that they can be used | ||
* at any nesting level. | ||
* | ||
* We do this here, because otherwise we have to complicate the filtering logic. For example, we need to change | ||
* the pattern in the filter before creating a regular expression. There is no need to change the patterns | ||
* in the application. Only on the input. | ||
*/ | ||
if (settings.baseNameMatch) { | ||
patterns = patterns.map((pattern) => pattern.includes('/') ? pattern : `**/${pattern}`); | ||
} | ||
/** | ||
* This method also removes duplicate slashes that may have been in the pattern or formed as a result of expansion. | ||
*/ | ||
return patterns.map((pattern) => utils.pattern.removeDuplicateSlashes(pattern)); | ||
} | ||
/** | ||
@@ -18,0 +48,0 @@ * Returns tasks grouped by basic pattern directories. |
@@ -0,0 +0,0 @@ import { Task } from '../managers/tasks'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { MicromatchOptions, EntryFilterFunction, Pattern } from '../../types'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Settings from '../../settings'; |
@@ -12,7 +12,8 @@ "use strict"; | ||
const positiveRe = utils.pattern.convertPatternsToRe(positive, this._micromatchOptions); | ||
const negativeRe = utils.pattern.convertPatternsToRe(negative, this._micromatchOptions); | ||
const negativeRe = utils.pattern.convertPatternsToRe(negative, Object.assign(Object.assign({}, this._micromatchOptions), { dot: true })); | ||
return (entry) => this._filter(entry, positiveRe, negativeRe); | ||
} | ||
_filter(entry, positiveRe, negativeRe) { | ||
if (this._settings.unique && this._isDuplicateEntry(entry)) { | ||
const filepath = utils.path.removeLeadingDotSegment(entry.path); | ||
if (this._settings.unique && this._isDuplicateEntry(filepath)) { | ||
return false; | ||
@@ -23,18 +24,17 @@ } | ||
} | ||
if (this._isSkippedByAbsoluteNegativePatterns(entry.path, negativeRe)) { | ||
if (this._isSkippedByAbsoluteNegativePatterns(filepath, negativeRe)) { | ||
return false; | ||
} | ||
const filepath = this._settings.baseNameMatch ? entry.name : entry.path; | ||
const isDirectory = entry.dirent.isDirectory(); | ||
const isMatched = this._isMatchToPatterns(filepath, positiveRe, isDirectory) && !this._isMatchToPatterns(entry.path, negativeRe, isDirectory); | ||
const isMatched = this._isMatchToPatterns(filepath, positiveRe, isDirectory) && !this._isMatchToPatterns(filepath, negativeRe, isDirectory); | ||
if (this._settings.unique && isMatched) { | ||
this._createIndexRecord(entry); | ||
this._createIndexRecord(filepath); | ||
} | ||
return isMatched; | ||
} | ||
_isDuplicateEntry(entry) { | ||
return this.index.has(entry.path); | ||
_isDuplicateEntry(filepath) { | ||
return this.index.has(filepath); | ||
} | ||
_createIndexRecord(entry) { | ||
this.index.set(entry.path, undefined); | ||
_createIndexRecord(filepath) { | ||
this.index.set(filepath, undefined); | ||
} | ||
@@ -54,4 +54,3 @@ _onlyFileFilter(entry) { | ||
} | ||
_isMatchToPatterns(entryPath, patternsRe, isDirectory) { | ||
const filepath = utils.path.removeLeadingDotSegment(entryPath); | ||
_isMatchToPatterns(filepath, patternsRe, isDirectory) { | ||
// Trying to match files and directories by patterns. | ||
@@ -58,0 +57,0 @@ const isMatched = utils.pattern.matchAny(filepath, patternsRe); |
@@ -0,0 +0,0 @@ import Settings from '../../settings'; |
@@ -0,0 +0,0 @@ "use strict"; |
import { Pattern, MicromatchOptions, PatternRe } from '../../types'; | ||
import Settings from '../../settings'; | ||
export declare type PatternSegment = StaticPatternSegment | DynamicPatternSegment; | ||
declare type StaticPatternSegment = { | ||
export type PatternSegment = StaticPatternSegment | DynamicPatternSegment; | ||
type StaticPatternSegment = { | ||
dynamic: false; | ||
pattern: Pattern; | ||
}; | ||
declare type DynamicPatternSegment = { | ||
type DynamicPatternSegment = { | ||
dynamic: true; | ||
@@ -13,4 +13,4 @@ pattern: Pattern; | ||
}; | ||
export declare type PatternSection = PatternSegment[]; | ||
export declare type PatternInfo = { | ||
export type PatternSection = PatternSegment[]; | ||
export type PatternInfo = { | ||
/** | ||
@@ -17,0 +17,0 @@ * Indicates that the pattern has a globstar (more than a single section). |
@@ -13,8 +13,3 @@ "use strict"; | ||
_fillStorage() { | ||
/** | ||
* The original pattern may include `{,*,**,a/*}`, which will lead to problems with matching (unresolved level). | ||
* So, before expand patterns with brace expansion into separated patterns. | ||
*/ | ||
const patterns = utils.pattern.expandPatternsWithBraceExpansion(this._patterns); | ||
for (const pattern of patterns) { | ||
for (const pattern of this._patterns) { | ||
const segments = this._getPatternSegments(pattern); | ||
@@ -21,0 +16,0 @@ const sections = this._splitSegmentsIntoSections(segments); |
@@ -0,0 +0,0 @@ import Matcher from './matcher'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Task } from '../managers/tasks'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /// <reference types="node" /> |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Task } from '../managers/tasks'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Settings from '../../settings'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import * as fsWalk from '@nodelib/fs.walk'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /// <reference types="node" /> |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /// <reference types="node" /> |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import * as fsStat from '@nodelib/fs.stat'; |
@@ -0,0 +0,0 @@ "use strict"; |
import { FileSystemAdapter, Pattern } from './types'; | ||
export declare const DEFAULT_FILE_SYSTEM_ADAPTER: FileSystemAdapter; | ||
export declare type Options = { | ||
export type Options = { | ||
/** | ||
@@ -5,0 +5,0 @@ * Return the absolute path for entries. |
@@ -0,0 +0,0 @@ "use strict"; |
/// <reference types="node" /> | ||
import * as fsWalk from '@nodelib/fs.walk'; | ||
export declare type ErrnoException = NodeJS.ErrnoException; | ||
export declare type Entry = fsWalk.Entry; | ||
export declare type EntryItem = string | Entry; | ||
export declare type Pattern = string; | ||
export declare type PatternRe = RegExp; | ||
export declare type PatternsGroup = Record<string, Pattern[]>; | ||
export declare type ReaderOptions = fsWalk.Options & { | ||
export type ErrnoException = NodeJS.ErrnoException; | ||
export type Entry = fsWalk.Entry; | ||
export type EntryItem = string | Entry; | ||
export type Pattern = string; | ||
export type PatternRe = RegExp; | ||
export type PatternsGroup = Record<string, Pattern[]>; | ||
export type ReaderOptions = fsWalk.Options & { | ||
transform(entry: Entry): EntryItem; | ||
@@ -17,7 +17,7 @@ deepFilter: DeepFilterFunction; | ||
}; | ||
export declare type ErrorFilterFunction = fsWalk.ErrorFilterFunction; | ||
export declare type EntryFilterFunction = fsWalk.EntryFilterFunction; | ||
export declare type DeepFilterFunction = fsWalk.DeepFilterFunction; | ||
export declare type EntryTransformerFunction = (entry: Entry) => EntryItem; | ||
export declare type MicromatchOptions = { | ||
export type ErrorFilterFunction = fsWalk.ErrorFilterFunction; | ||
export type EntryFilterFunction = fsWalk.EntryFilterFunction; | ||
export type DeepFilterFunction = fsWalk.DeepFilterFunction; | ||
export type EntryTransformerFunction = (entry: Entry) => EntryItem; | ||
export type MicromatchOptions = { | ||
dot?: boolean; | ||
@@ -32,2 +32,2 @@ matchBase?: boolean; | ||
}; | ||
export declare type FileSystemAdapter = fsWalk.FileSystemAdapter; | ||
export type FileSystemAdapter = fsWalk.FileSystemAdapter; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
export declare function flatten<T>(items: T[][]): T[]; | ||
export declare function splitWhen<T>(items: T[], predicate: (item: T) => boolean): T[][]; |
@@ -0,0 +0,0 @@ "use strict"; |
import { ErrnoException } from '../types'; | ||
export declare function isEnoentCodeError(error: ErrnoException): boolean; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /// <reference types="node" /> |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import * as array from './array'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -7,3 +7,8 @@ import { Pattern } from '../types'; | ||
export declare function makeAbsolute(cwd: string, filepath: string): string; | ||
export declare function escape(pattern: Pattern): Pattern; | ||
export declare function removeLeadingDotSegment(entry: string): string; | ||
export declare const escape: typeof escapeWindowsPath; | ||
export declare function escapeWindowsPath(pattern: Pattern): Pattern; | ||
export declare function escapePosixPath(pattern: Pattern): Pattern; | ||
export declare const convertPathToPattern: typeof convertWindowsPathToPattern; | ||
export declare function convertWindowsPathToPattern(filepath: string): Pattern; | ||
export declare function convertPosixPathToPattern(filepath: string): Pattern; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.removeLeadingDotSegment = exports.escape = exports.makeAbsolute = exports.unixify = void 0; | ||
exports.convertPosixPathToPattern = exports.convertWindowsPathToPattern = exports.convertPathToPattern = exports.escapePosixPath = exports.escapeWindowsPath = exports.escape = exports.removeLeadingDotSegment = exports.makeAbsolute = exports.unixify = void 0; | ||
const os = require("os"); | ||
const path = require("path"); | ||
const IS_WINDOWS_PLATFORM = os.platform() === 'win32'; | ||
const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\ | ||
const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g; | ||
/** | ||
* All non-escaped special characters. | ||
* Posix: ()*?[\]{|}, !+@ before (, ! at the beginning, \\ before non-special characters. | ||
* Windows: (){}, !+@ before (, ! at the beginning. | ||
*/ | ||
const POSIX_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\()|\\(?![!()*+?@[\]{|}]))/g; | ||
const WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([(){}]|^!|[!+@](?=\())/g; | ||
/** | ||
* The device path (\\.\ or \\?\). | ||
* https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#dos-device-paths | ||
*/ | ||
const DOS_DEVICE_PATH_RE = /^\\\\([.?])/; | ||
/** | ||
* All backslashes except those escaping special characters. | ||
* Windows: !()+@{} | ||
* https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions | ||
*/ | ||
const WINDOWS_BACKSLASHES_RE = /\\(?![!()+@{}])/g; | ||
/** | ||
* Designed to work only with simple paths: `dir\\file`. | ||
@@ -18,6 +37,2 @@ */ | ||
exports.makeAbsolute = makeAbsolute; | ||
function escape(pattern) { | ||
return pattern.replace(UNESCAPED_GLOB_SYMBOLS_RE, '\\$2'); | ||
} | ||
exports.escape = escape; | ||
function removeLeadingDotSegment(entry) { | ||
@@ -35,1 +50,21 @@ // We do not use `startsWith` because this is 10x slower than current implementation for some cases. | ||
exports.removeLeadingDotSegment = removeLeadingDotSegment; | ||
exports.escape = IS_WINDOWS_PLATFORM ? escapeWindowsPath : escapePosixPath; | ||
function escapeWindowsPath(pattern) { | ||
return pattern.replace(WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE, '\\$2'); | ||
} | ||
exports.escapeWindowsPath = escapeWindowsPath; | ||
function escapePosixPath(pattern) { | ||
return pattern.replace(POSIX_UNESCAPED_GLOB_SYMBOLS_RE, '\\$2'); | ||
} | ||
exports.escapePosixPath = escapePosixPath; | ||
exports.convertPathToPattern = IS_WINDOWS_PLATFORM ? convertWindowsPathToPattern : convertPosixPathToPattern; | ||
function convertWindowsPathToPattern(filepath) { | ||
return escapeWindowsPath(filepath) | ||
.replace(DOS_DEVICE_PATH_RE, '//$1') | ||
.replace(WINDOWS_BACKSLASHES_RE, '/'); | ||
} | ||
exports.convertWindowsPathToPattern = convertWindowsPathToPattern; | ||
function convertPosixPathToPattern(filepath) { | ||
return escapePosixPath(filepath); | ||
} | ||
exports.convertPosixPathToPattern = convertPosixPathToPattern; |
import { MicromatchOptions, Pattern, PatternRe } from '../types'; | ||
declare type PatternTypeOptions = { | ||
type PatternTypeOptions = { | ||
braceExpansion?: boolean; | ||
@@ -42,2 +42,7 @@ caseSensitiveMatch?: boolean; | ||
export declare function matchAny(entry: string, patternsRe: PatternRe[]): boolean; | ||
/** | ||
* This package only works with forward slashes as a path separator. | ||
* Because of this, we cannot use the standard `path.normalize` method, because on Windows platform it will use of backslashes. | ||
*/ | ||
export declare function removeDuplicateSlashes(pattern: string): string; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.matchAny = exports.convertPatternsToRe = exports.makeRe = exports.getPatternParts = exports.expandBraceExpansion = exports.expandPatternsWithBraceExpansion = exports.isAffectDepthOfReadingPattern = exports.endsWithSlashGlobStar = exports.hasGlobStar = exports.getBaseDirectory = exports.isPatternRelatedToParentDirectory = exports.getPatternsOutsideCurrentDirectory = exports.getPatternsInsideCurrentDirectory = exports.getPositivePatterns = exports.getNegativePatterns = exports.isPositivePattern = exports.isNegativePattern = exports.convertToNegativePattern = exports.convertToPositivePattern = exports.isDynamicPattern = exports.isStaticPattern = void 0; | ||
exports.removeDuplicateSlashes = exports.matchAny = exports.convertPatternsToRe = exports.makeRe = exports.getPatternParts = exports.expandBraceExpansion = exports.expandPatternsWithBraceExpansion = exports.isAffectDepthOfReadingPattern = exports.endsWithSlashGlobStar = exports.hasGlobStar = exports.getBaseDirectory = exports.isPatternRelatedToParentDirectory = exports.getPatternsOutsideCurrentDirectory = exports.getPatternsInsideCurrentDirectory = exports.getPositivePatterns = exports.getNegativePatterns = exports.isPositivePattern = exports.isNegativePattern = exports.convertToNegativePattern = exports.convertToPositivePattern = exports.isDynamicPattern = exports.isStaticPattern = void 0; | ||
const path = require("path"); | ||
@@ -14,2 +14,7 @@ const globParent = require("glob-parent"); | ||
const BRACE_EXPANSION_SEPARATORS_RE = /,|\.\./; | ||
/** | ||
* Matches a sequence of two or more consecutive slashes, excluding the first two slashes at the beginning of the string. | ||
* The latter is due to the presence of the device path at the beginning of the UNC path. | ||
*/ | ||
const DOUBLE_SLASH_RE = /(?!^)\/{2,}/g; | ||
function isStaticPattern(pattern, options = {}) { | ||
@@ -133,6 +138,12 @@ return !isDynamicPattern(pattern, options); | ||
function expandBraceExpansion(pattern) { | ||
return micromatch.braces(pattern, { | ||
expand: true, | ||
nodupes: true | ||
}); | ||
const patterns = micromatch.braces(pattern, { expand: true, nodupes: true }); | ||
/** | ||
* Sort the patterns by length so that the same depth patterns are processed side by side. | ||
* `a/{b,}/{c,}/*` – `['a///*', 'a/b//*', 'a//c/*', 'a/b/c/*']` | ||
*/ | ||
patterns.sort((a, b) => a.length - b.length); | ||
/** | ||
* Micromatch can return an empty string in the case of patterns like `{a,}`. | ||
*/ | ||
return patterns.filter((pattern) => pattern !== ''); | ||
} | ||
@@ -172,1 +183,9 @@ exports.expandBraceExpansion = expandBraceExpansion; | ||
exports.matchAny = matchAny; | ||
/** | ||
* This package only works with forward slashes as a path separator. | ||
* Because of this, we cannot use the standard `path.normalize` method, because on Windows platform it will use of backslashes. | ||
*/ | ||
function removeDuplicateSlashes(pattern) { | ||
return pattern.replace(DOUBLE_SLASH_RE, '/'); | ||
} | ||
exports.removeDuplicateSlashes = removeDuplicateSlashes; |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { Readable } from 'stream'; | ||
export declare function merge(streams: Readable[]): NodeJS.ReadableStream; |
@@ -0,0 +0,0 @@ "use strict"; |
export declare function isString(input: unknown): input is string; | ||
export declare function isEmpty(input: string): boolean; |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "fast-glob", | ||
"version": "3.2.12", | ||
"version": "3.3.0", | ||
"description": "It's a very fast and efficient glob library for Node.js", | ||
@@ -30,30 +30,22 @@ "license": "MIT", | ||
"@nodelib/fs.macchiato": "^1.0.1", | ||
"@types/compute-stdev": "^1.0.0", | ||
"@types/easy-table": "^0.0.32", | ||
"@types/glob": "^7.1.1", | ||
"@types/glob-parent": "^5.1.0", | ||
"@types/is-ci": "^2.0.0", | ||
"@types/merge2": "^1.1.4", | ||
"@types/micromatch": "^4.0.0", | ||
"@types/minimist": "^1.2.0", | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "^12.7.8", | ||
"@types/rimraf": "^2.0.2", | ||
"@types/picomatch": "^2.3.0", | ||
"@types/sinon": "^7.5.0", | ||
"compute-stdev": "^1.0.0", | ||
"easy-table": "^1.1.1", | ||
"bencho": "^0.1.1", | ||
"eslint": "^6.5.1", | ||
"eslint-config-mrmlnc": "^1.1.0", | ||
"execa": "^2.0.4", | ||
"execa": "^7.1.1", | ||
"fast-glob": "^3.0.4", | ||
"fdir": "^5.1.0", | ||
"glob": "^7.1.4", | ||
"is-ci": "^2.0.0", | ||
"log-update": "^4.0.0", | ||
"minimist": "^1.2.0", | ||
"fdir": "^6.0.1", | ||
"glob": "^10.0.0", | ||
"hereby": "^1.8.1", | ||
"mocha": "^6.2.1", | ||
"rimraf": "^3.0.0", | ||
"rimraf": "^5.0.0", | ||
"sinon": "^7.5.0", | ||
"tiny-glob": "^0.2.6", | ||
"typescript": "^3.6.3" | ||
"snap-shot-it": "^7.9.10", | ||
"typescript": "^4.9.5" | ||
}, | ||
@@ -72,25 +64,20 @@ "dependencies": { | ||
"test": "mocha \"out/**/*.spec.js\" -s 0", | ||
"smoke": "mocha \"out/**/*.smoke.js\" -s 0", | ||
"smoke:sync": "mocha \"out/**/*.smoke.js\" -s 0 --grep \"\\(sync\\)\"", | ||
"smoke:async": "mocha \"out/**/*.smoke.js\" -s 0 --grep \"\\(async\\)\"", | ||
"smoke:stream": "mocha \"out/**/*.smoke.js\" -s 0 --grep \"\\(stream\\)\"", | ||
"test:e2e": "mocha \"out/**/*.e2e.js\" -s 0", | ||
"test:e2e:sync": "mocha \"out/**/*.e2e.js\" -s 0 --grep \"\\(sync\\)\"", | ||
"test:e2e:async": "mocha \"out/**/*.e2e.js\" -s 0 --grep \"\\(async\\)\"", | ||
"test:e2e:stream": "mocha \"out/**/*.e2e.js\" -s 0 --grep \"\\(stream\\)\"", | ||
"build": "npm run clean && npm run compile && npm run lint && npm test", | ||
"watch": "npm run clean && npm run compile -- --sourceMap --watch", | ||
"bench": "npm run bench-async && npm run bench-stream && npm run bench-sync", | ||
"bench-async": "npm run bench-async-flatten && npm run bench-async-deep && npm run bench-async-partial-flatten && npm run bench-async-partial-deep", | ||
"bench-stream": "npm run bench-stream-flatten && npm run bench-stream-deep && npm run bench-stream-partial-flatten && npm run bench-stream-partial-deep", | ||
"bench-sync": "npm run bench-sync-flatten && npm run bench-sync-deep && npm run bench-sync-partial-flatten && npm run bench-sync-partial-deep", | ||
"bench-async-flatten": "node ./out/benchmark --mode async --pattern \"*\"", | ||
"bench-async-deep": "node ./out/benchmark --mode async --pattern \"**\"", | ||
"bench-async-partial-flatten": "node ./out/benchmark --mode async --pattern \"{fixtures,out}/{first,second}/*\"", | ||
"bench-async-partial-deep": "node ./out/benchmark --mode async --pattern \"{fixtures,out}/**\"", | ||
"bench-stream-flatten": "node ./out/benchmark --mode stream --pattern \"*\"", | ||
"bench-stream-deep": "node ./out/benchmark --mode stream --pattern \"**\"", | ||
"bench-stream-partial-flatten": "node ./out/benchmark --mode stream --pattern \"{fixtures,out}/{first,second}/*\"", | ||
"bench-stream-partial-deep": "node ./out/benchmark --mode stream --pattern \"{fixtures,out}/**\"", | ||
"bench-sync-flatten": "node ./out/benchmark --mode sync --pattern \"*\"", | ||
"bench-sync-deep": "node ./out/benchmark --mode sync --pattern \"**\"", | ||
"bench-sync-partial-flatten": "node ./out/benchmark --mode sync --pattern \"{fixtures,out}/{first,second}/*\"", | ||
"bench-sync-partial-deep": "node ./out/benchmark --mode sync --pattern \"{fixtures,out}/**\"" | ||
"bench:async": "npm run bench:product:async && npm run bench:regression:async", | ||
"bench:stream": "npm run bench:product:stream && npm run bench:regression:stream", | ||
"bench:sync": "npm run bench:product:sync && npm run bench:regression:sync", | ||
"bench:product": "npm run bench:product:async && npm run bench:product:sync && npm run bench:product:stream", | ||
"bench:product:async": "hereby bench:product:async", | ||
"bench:product:sync": "hereby bench:product:sync", | ||
"bench:product:stream": "hereby bench:product:stream", | ||
"bench:regression": "npm run bench:regression:async && npm run bench:regression:sync && npm run bench:regression:stream", | ||
"bench:regression:async": "hereby bench:regression:async", | ||
"bench:regression:sync": "hereby bench:regression:sync", | ||
"bench:regression:stream": "hereby bench:regression:stream" | ||
} | ||
} |
@@ -28,3 +28,4 @@ # fast-glob | ||
* [isDynamicPattern](#isdynamicpatternpattern-options) | ||
* [escapePath](#escapepathpattern) | ||
* [escapePath](#escapepathpath) | ||
* [convertPathToPattern](#convertpathtopatternpath) | ||
* [Options](#options-3) | ||
@@ -146,2 +147,4 @@ * [Common](#common) | ||
fg(patterns, [options]) | ||
fg.async(patterns, [options]) | ||
fg.glob(patterns, [options]) | ||
``` | ||
@@ -163,2 +166,3 @@ | ||
fg.sync(patterns, [options]) | ||
fg.globSync(patterns, [options]) | ||
``` | ||
@@ -180,2 +184,3 @@ | ||
fg.stream(patterns, [options]) | ||
fg.globStream(patterns, [options]) | ||
``` | ||
@@ -271,18 +276,54 @@ | ||
#### `escapePath(pattern)` | ||
#### `escapePath(path)` | ||
Returns a path with escaped special characters (`*?|(){}[]`, `!` at the beginning of line, `@+!` before the opening parenthesis). | ||
Returns the path with escaped special characters depending on the platform. | ||
* Posix: | ||
* `*?|(){}[]`; | ||
* `!` at the beginning of line; | ||
* `@+!` before the opening parenthesis; | ||
* `\\` before non-special characters; | ||
* Windows: | ||
* `(){}` | ||
* `!` at the beginning of line; | ||
* `@+!` before the opening parenthesis; | ||
* Characters like `*?|[]` cannot be used in the path ([windows_naming_conventions][windows_naming_conventions]), so they will not be escaped; | ||
```js | ||
fg.escapePath('!abc'); // \\!abc | ||
fg.escapePath('C:/Program Files (x86)'); // C:/Program Files \\(x86\\) | ||
fg.escapePath('!abc'); | ||
// \\!abc | ||
fg.escapePath('[OpenSource] mrmlnc – fast-glob (Deluxe Edition) 2014') + '/*.flac' | ||
// \\[OpenSource\\] mrmlnc – fast-glob \\(Deluxe Edition\\) 2014/*.flac | ||
fg.posix.escapePath('C:\\Program Files (x86)\\**\\*'); | ||
// C:\\\\Program Files \\(x86\\)\\*\\*\\* | ||
fg.win32.escapePath('C:\\Program Files (x86)\\**\\*'); | ||
// Windows: C:\\Program Files \\(x86\\)\\**\\* | ||
``` | ||
##### pattern | ||
#### `convertPathToPattern(path)` | ||
* Required: `true` | ||
* Type: `string` | ||
Converts a path to a pattern depending on the platform, including special character escaping. | ||
Any string, for example, a path to a file. | ||
* Posix. Works similarly to the `fg.posix.escapePath` method. | ||
* Windows. Works similarly to the `fg.win32.escapePath` method, additionally converting backslashes to forward slashes in cases where they are not escape characters (`!()+@{}`). | ||
```js | ||
fg.convertPathToPattern('[OpenSource] mrmlnc – fast-glob (Deluxe Edition) 2014') + '/*.flac'; | ||
// \\[OpenSource\\] mrmlnc – fast-glob \\(Deluxe Edition\\) 2014/*.flac | ||
fg.convertPathToPattern('C:/Program Files (x86)/**/*'); | ||
// Posix: C:/Program Files \\(x86\\)/\\*\\*/\\* | ||
// Windows: C:/Program Files \\(x86\\)/**/* | ||
fg.convertPathToPattern('C:\\Program Files (x86)\\**\\*'); | ||
// Posix: C:\\\\Program Files \\(x86\\)\\*\\*\\* | ||
// Windows: C:/Program Files \\(x86\\)/**/* | ||
fg.posix.convertPathToPattern('\\\\?\\c:\\Program Files (x86)') + '/**/*'; | ||
// Posix: \\\\\\?\\\\c:\\\\Program Files \\(x86\\)/**/* (broken pattern) | ||
fg.win32.convertPathToPattern('\\\\?\\c:\\Program Files (x86)') + '/**/*'; | ||
// Windows: //?/c:/Program Files \\(x86\\)/**/* | ||
``` | ||
## Options | ||
@@ -301,2 +342,18 @@ | ||
<details> | ||
<summary>More details</summary> | ||
In Node, there are [two types of threads][nodejs_thread_pool]: Event Loop (code) and a Thread Pool (fs, dns, …). The thread pool size controlled by the `UV_THREADPOOL_SIZE` environment variable. Its default size is 4 ([documentation][libuv_thread_pool]). The pool is one for all tasks within a single Node process. | ||
Any code can make 4 real concurrent accesses to the file system. The rest of the FS requests will wait in the queue. | ||
> :book: Each new instance of FG in the same Node process will use the same Thread pool. | ||
But this package also has the `concurrency` option. This option allows you to control the number of concurrent accesses to the FS at the package level. By default, this package has a value equal to the number of cores available for the current Node process. This allows you to set a value smaller than the pool size (`concurrency: 1`) or, conversely, to prepare tasks for the pool queue more quickly (`concurrency: Number.POSITIVE_INFINITY`). | ||
So, in fact, this package can **only make 4 concurrent requests to the FS**. You can increase this value by using an environment variable (`UV_THREADPOOL_SIZE`), but in practice this does not give a multiple advantage. | ||
</details> | ||
#### cwd | ||
@@ -662,7 +719,7 @@ | ||
'directory/*', | ||
path.join(process.cwd(), '**').replace(/\\/g, '/') | ||
fg.convertPathToPattern(process.cwd()) + '/**' | ||
] | ||
``` | ||
> :book: Use the [`normalize-path`][npm_normalize_path] or the [`unixify`][npm_unixify] package to convert Windows-style path to a Unix-style path. | ||
> :book: Use the [`.convertPathToPattern`](#convertpathtopatternpath) package to convert Windows-style path to a Unix-style path. | ||
@@ -688,3 +745,3 @@ Read more about [matching with backslashes][micromatch_backslashes]. | ||
Read more about [matching special characters as literals][picomatch_matching_special_characters_as_literals]. | ||
Read more about [matching special characters as literals][picomatch_matching_special_characters_as_literals]. Or use the [`.escapePath`](#escapepathpath). | ||
@@ -715,7 +772,11 @@ ## How to exclude directory from reading? | ||
You cannot use [Uniform Naming Convention (UNC)][unc_path] paths as patterns (due to syntax), but you can use them as [`cwd`](#cwd) directory. | ||
You cannot use [Uniform Naming Convention (UNC)][unc_path] paths as patterns (due to syntax) directly, but you can use them as [`cwd`](#cwd) directory or use the `fg.convertPathToPattern` method. | ||
```ts | ||
// cwd | ||
fg.sync('*', { cwd: '\\\\?\\C:\\Python27' /* or //?/C:/Python27 */ }); | ||
fg.sync('Python27/*', { cwd: '\\\\?\\C:\\' /* or //?/C:/ */ }); | ||
// .convertPathToPattern | ||
fg.sync(fg.convertPathToPattern('\\\\?\\c:\\Python27') + '/*'); | ||
``` | ||
@@ -801,5 +862,8 @@ | ||
[silicon_power_ssd]: https://www.silicon-power.com/web/product-1 | ||
[unc_path]: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/62e862f4-2a51-452e-8eeb-dc4ff5ee33cc | ||
[unc_path]: https://learn.microsoft.com/openspecs/windows_protocols/ms-dtyp/62e862f4-2a51-452e-8eeb-dc4ff5ee33cc | ||
[vultr_pricing_baremetal]: https://www.vultr.com/pricing/baremetal | ||
[wikipedia_case_sensitivity]: https://en.wikipedia.org/wiki/Case_sensitivity | ||
[zotac_bi323]: https://www.zotac.com/ee/product/mini_pcs/zbox-bi323 | ||
[nodejs_thread_pool]: https://nodejs.org/en/docs/guides/dont-block-the-event-loop | ||
[libuv_thread_pool]: http://docs.libuv.org/en/v1.x/threadpool.html | ||
[windows_naming_conventions]: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions |
97594
21
1685
860
55