Socket
Socket
Sign inDemoInstall

fast-glob

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-glob - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

3

index.d.ts
import { TransformFunction as Transform, IPartialOptions } from './out/managers/options';
import { ITask } from './out/managers/tasks';
import { Entry, EntryItem } from './out/types/entries';

@@ -8,2 +9,3 @@ import { Pattern } from './out/types/patterns';

type TransformFunction<T> = Transform<T>;
type Task = ITask;

@@ -16,2 +18,3 @@ interface IApi {

stream(patterns: Pattern | Pattern[], options?: IPartialOptions): NodeJS.ReadableStream;
generateTasks(patterns: Pattern | Pattern[], options?: IPartialOptions): Task[];
}

@@ -18,0 +21,0 @@ }

@@ -9,1 +9,3 @@ const pkg = require('./out/index');

module.exports.stream = pkg.stream;
module.exports.generateTasks = pkg.generateTasks;
/// <reference types="node" />
import { IPartialOptions } from './managers/options';
import { ITask } from './managers/tasks';
import { EntryItem } from './types/entries';

@@ -17,1 +18,5 @@ import { Pattern } from './types/patterns';

export declare function stream(source: Pattern | Pattern[], opts?: IPartialOptions): NodeJS.ReadableStream;
/**
* Return a set of tasks based on provided patterns.
*/
export declare function generateTasks(source: Pattern | Pattern[], opts?: IPartialOptions): ITask[];

@@ -35,2 +35,11 @@ "use strict";

/**
* Return a set of tasks based on provided patterns.
*/
function generateTasks(source, opts) {
var patterns = [].concat(source);
var options = optionsManager.prepare(opts);
return taskManager.generate(patterns, options);
}
exports.generateTasks = generateTasks;
/**
* Returns a set of works based on provided tasks and class of the reader.

@@ -37,0 +46,0 @@ */

2

out/managers/tasks.js

@@ -47,3 +47,3 @@ "use strict";

var positive = negative.map(patternUtils.convertToPositivePattern).concat(ignore);
return positive.map(patternUtils.trimTrailingSlashGlobStar);
return positive;
}

@@ -50,0 +50,0 @@ exports.getNegativePatternsAsPositive = getNegativePatternsAsPositive;

@@ -15,25 +15,37 @@ /// <reference types="micromatch" />

/**
* Returns true if directory must be read.
* Returns max depth of the provided patterns.
*/
private filter(entry, negativeRe, depth);
private getMaxPatternDepth(patterns);
/**
* Returns max depth for reading.
* Returns RegExp's for patterns that can affect the depth of reading.
*/
private getMaxDeth(positive);
private getNegativePatternsRe(patterns);
/**
* Returns true for dot directories if the «dot» option is enabled.
* Returns «true» for directory that should be readed.
*/
private isFollowedDotDirectory(entry);
private filter(entry, negativeRe, maxPatternDepth);
/**
* Returns true for symlinked directories if the «followSymlinks» option is enabled.
* Returns «true» when the directory can be skipped by nesting level.
*/
private isFollowedSymlink(entry);
private isSkippedByNestingLevel(entryDepth, maxPatternDepth);
/**
* Returns true when the «deep» options is number and entry depth greater that the option value.
* Returns «true» when the «deep» option is disabled or number and depth of the entry is greater that the option value.
*/
private skipByDeepOption(entry);
private isSkippedByDeepOption(entryDepth);
/**
* Return true when depth parameter is not an Infinity and entry depth greater that the parameter value.
* Returns «true» when depth parameter is not an Infinity and entry depth greater that the parameter value.
*/
private skipByPatternDepth(entry, depth);
private isSkippedByMaxPatternDepth(entryDepth, maxPatternDepth);
/**
* Returns «true» for symlinked directory if the «followSymlinkedDirectories» option is disabled.
*/
private isSkippedSymlinkedDirectory(entry);
/**
* Returns «true» for a directory whose name starts with a period if «dot» option is disabled.
*/
private isSkippedDotDirectory(entry);
/**
* Returns «true» for a directory whose path math to any negative pattern.
*/
private isSkippedByNegativePatterns(entry, negativeRe);
}

@@ -16,59 +16,71 @@ "use strict";

var _this = this;
var depth = this.getMaxDeth(positive);
var negativeRe = patternUtils.convertPatternsToRe(negative, this.micromatchOptions);
return function (entry) { return _this.filter(entry, negativeRe, depth); };
var maxPatternDepth = this.getMaxPatternDepth(positive);
var negativeRe = this.getNegativePatternsRe(negative);
return function (entry) { return _this.filter(entry, negativeRe, maxPatternDepth); };
};
/**
* Returns true if directory must be read.
* Returns max depth of the provided patterns.
*/
DeepFilter.prototype.filter = function (entry, negativeRe, depth) {
// Skip reading, depending on the nesting level
if (!this.options.deep || this.skipByDeepOption(entry) || this.skipByPatternDepth(entry, depth)) {
DeepFilter.prototype.getMaxPatternDepth = function (patterns) {
var globstar = patterns.some(patternUtils.hasGlobStar);
var patternDepths = patterns.map(patternUtils.getDepth);
return globstar ? Infinity : arrayUtils.max(patternDepths);
};
/**
* Returns RegExp's for patterns that can affect the depth of reading.
*/
DeepFilter.prototype.getNegativePatternsRe = function (patterns) {
var affectDepthOfReadingPatterns = patterns.filter(patternUtils.isAffectDepthOfReadingPattern);
return patternUtils.convertPatternsToRe(affectDepthOfReadingPatterns, this.micromatchOptions);
};
/**
* Returns «true» for directory that should be readed.
*/
DeepFilter.prototype.filter = function (entry, negativeRe, maxPatternDepth) {
if (this.isSkippedByNestingLevel(entry.depth, maxPatternDepth)) {
return false;
}
// Skip reading if the directory is symlink and we don't want expand symlinks
if (this.isFollowedSymlink(entry)) {
if (this.isSkippedSymlinkedDirectory(entry)) {
return false;
}
// Skip reading if the directory name starting with a period and is not expected
if (this.isFollowedDotDirectory(entry)) {
if (this.isSkippedDotDirectory(entry)) {
return false;
}
// Skip by negative patterns
if (patternUtils.matchAny(entry.path, negativeRe)) {
return false;
}
return true;
return this.isSkippedByNegativePatterns(entry, negativeRe);
};
/**
* Returns max depth for reading.
* Returns «true» when the directory can be skipped by nesting level.
*/
DeepFilter.prototype.getMaxDeth = function (positive) {
var globstar = positive.some(patternUtils.hasGlobStar);
var patternDepths = positive.map(patternUtils.getDepth);
return globstar ? Infinity : arrayUtils.max(patternDepths);
DeepFilter.prototype.isSkippedByNestingLevel = function (entryDepth, maxPatternDepth) {
return this.isSkippedByDeepOption(entryDepth) || this.isSkippedByMaxPatternDepth(entryDepth, maxPatternDepth);
};
/**
* Returns true for dot directories if the «dot» option is enabled.
* Returns «true» when the «deep» option is disabled or number and depth of the entry is greater that the option value.
*/
DeepFilter.prototype.isFollowedDotDirectory = function (entry) {
return !this.options.dot && pathUtils.isDotDirectory(entry.path);
DeepFilter.prototype.isSkippedByDeepOption = function (entryDepth) {
return !this.options.deep || (typeof this.options.deep === 'number' && entryDepth > this.options.deep);
};
/**
* Returns true for symlinked directories if the «followSymlinks» option is enabled.
* Returns «true» when depth parameter is not an Infinity and entry depth greater that the parameter value.
*/
DeepFilter.prototype.isFollowedSymlink = function (entry) {
DeepFilter.prototype.isSkippedByMaxPatternDepth = function (entryDepth, maxPatternDepth) {
return maxPatternDepth !== Infinity && entryDepth > maxPatternDepth;
};
/**
* Returns «true» for symlinked directory if the «followSymlinkedDirectories» option is disabled.
*/
DeepFilter.prototype.isSkippedSymlinkedDirectory = function (entry) {
return !this.options.followSymlinkedDirectories && entry.isSymbolicLink();
};
/**
* Returns true when the «deep» options is number and entry depth greater that the option value.
* Returns «true» for a directory whose name starts with a period if «dot» option is disabled.
*/
DeepFilter.prototype.skipByDeepOption = function (entry) {
return typeof this.options.deep === 'number' && entry.depth > this.options.deep;
DeepFilter.prototype.isSkippedDotDirectory = function (entry) {
return !this.options.dot && pathUtils.isDotDirectory(entry.path);
};
/**
* Return true when depth parameter is not an Infinity and entry depth greater that the parameter value.
* Returns «true» for a directory whose path math to any negative pattern.
*/
DeepFilter.prototype.skipByPatternDepth = function (entry, depth) {
return depth !== Infinity && entry.depth > depth;
DeepFilter.prototype.isSkippedByNegativePatterns = function (entry, negativeRe) {
return !patternUtils.matchAny(entry.path, negativeRe);
};

@@ -75,0 +87,0 @@ return DeepFilter;

@@ -35,2 +35,9 @@ /// <reference types="micromatch" />

private onlyDirectoryFilter(entry);
/**
* Return true when entry match to provided patterns.
*
* First, just trying to apply patterns to the path.
* Second, trying to apply patterns to the path with final slash (need to micromatch to support «directory/**» patterns).
*/
private isMatchToPatterns(entry, patternsRe);
}

@@ -23,3 +23,2 @@ "use strict";

DeepFilter.prototype.filter = function (entry, positiveRe, negativeRe) {
var entryPath = entry.path;
// Exclude duplicate results

@@ -32,10 +31,2 @@ if (this.options.unique) {

}
// Mark directory by the final slash. Need to micromatch to support «directory/**» patterns
if (entry.isDirectory()) {
entryPath += '/';
}
// Filter directories that will be excluded by deep filter
if (entry.isDirectory() && patternUtils.matchAny(entryPath, negativeRe)) {
return false;
}
// Filter files and directories by options

@@ -45,3 +36,3 @@ if (this.onlyFileFilter(entry) || this.onlyDirectoryFilter(entry)) {

}
return patternUtils.match(entryPath, positiveRe, negativeRe);
return this.isMatchToPatterns(entry, positiveRe) && !this.isMatchToPatterns(entry, negativeRe);
};

@@ -72,4 +63,13 @@ /**

};
/**
* Return true when entry match to provided patterns.
*
* First, just trying to apply patterns to the path.
* Second, trying to apply patterns to the path with final slash (need to micromatch to support «directory/**» patterns).
*/
DeepFilter.prototype.isMatchToPatterns = function (entry, patternsRe) {
return patternUtils.matchAny(entry.path, patternsRe) || patternUtils.matchAny(entry.path + '/', patternsRe);
};
return DeepFilter;
}());
exports.default = DeepFilter;

@@ -6,2 +6,3 @@ "use strict";

var entry_1 = require("./filters/entry");
var pathUtil = require("../utils/path");
var Reader = /** @class */ (function () {

@@ -52,3 +53,4 @@ function Reader(options) {

if (this.options.absolute && !path.isAbsolute(entry.path)) {
entry.path = path.resolve(this.options.cwd, entry.path);
entry.path = pathUtil.resolve(this.options.cwd, entry.path);
entry.path = pathUtil.normalize(entry.path);
}

@@ -55,0 +57,0 @@ var item = this.options.stats ? entry : entry.path;

/**
* Returns true if the last partial of the path starting with a period.
* Returns «true» if the last partial of the path starting with a period.
*/
export declare function isDotDirectory(path: string): boolean;
export declare function isDotDirectory(filepath: string): boolean;
/**

@@ -9,1 +9,9 @@ * Return naive depth of provided filepath.

export declare function getDepth(filepath: string): number;
/**
* Return resolved a sequence of paths segments into an absolute path.
*/
export declare function resolve(from: string, to: string): string;
/**
* Convert a windows-like path to a unix-style path.
*/
export declare function normalize(filepath: string): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var path = require("path");
/**
* Returns true if the last partial of the path starting with a period.
* Returns «true» if the last partial of the path starting with a period.
*/
function isDotDirectory(path) {
var pathPartials = path.split('/');
var lastPathPartial = pathPartials[pathPartials.length - 1];
return lastPathPartial.startsWith('.');
function isDotDirectory(filepath) {
return path.basename(filepath).startsWith('.');
}

@@ -19,1 +18,15 @@ exports.isDotDirectory = isDotDirectory;

exports.getDepth = getDepth;
/**
* Return resolved a sequence of paths segments into an absolute path.
*/
function resolve(from, to) {
return path.resolve(from, to);
}
exports.resolve = resolve;
/**
* Convert a windows-like path to a unix-style path.
*/
function normalize(filepath) {
return filepath.replace(/\\/g, '/');
}
exports.normalize = normalize;

@@ -53,5 +53,5 @@ /// <reference types="micromatch" />

/**
* Trim trailing globstar if provided pattern ends with slash and globstar.
* Returns «true» when pattern ends with a slash and globstar or the last partial of the pattern is static pattern.
*/
export declare function trimTrailingSlashGlobStar(pattern: Pattern): Pattern;
export declare function isAffectDepthOfReadingPattern(pattern: Pattern): boolean;
/**

@@ -73,5 +73,1 @@ * Return naive depth of provided pattern.

export declare function matchAny(entry: string, patternsRe: PatternRe[]): boolean;
/**
* Returns true if the entry doesn't match any of the given negative RegExp's and match any of the given positive RegExp's.
*/
export declare function match(entry: string, positiveRe: PatternRe[], negativeRe: PatternRe[]): boolean;

@@ -13,2 +13,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var path = require("path");
var globParent = require("glob-parent");

@@ -103,8 +104,9 @@ var isGlob = require("is-glob");

/**
* Trim trailing globstar if provided pattern ends with slash and globstar.
* Returns «true» when pattern ends with a slash and globstar or the last partial of the pattern is static pattern.
*/
function trimTrailingSlashGlobStar(pattern) {
return endsWithSlashGlobStar(pattern) ? pattern.slice(0, -3) : pattern;
function isAffectDepthOfReadingPattern(pattern) {
var basename = path.basename(pattern);
return endsWithSlashGlobStar(pattern) || isStaticPattern(basename);
}
exports.trimTrailingSlashGlobStar = trimTrailingSlashGlobStar;
exports.isAffectDepthOfReadingPattern = isAffectDepthOfReadingPattern;
/**

@@ -154,8 +156,1 @@ * Return naive depth of provided pattern.

exports.matchAny = matchAny;
/**
* Returns true if the entry doesn't match any of the given negative RegExp's and match any of the given positive RegExp's.
*/
function match(entry, positiveRe, negativeRe) {
return matchAny(entry, negativeRe) ? false : matchAny(entry, positiveRe);
}
exports.match = match;
{
"name": "fast-glob",
"version": "2.1.0",
"version": "2.2.0",
"description": "Is a faster `node-glob` alternative",

@@ -25,2 +25,3 @@ "license": "MIT",

"@types/compute-stdev": "^1.0.0",
"@types/easy-table": "0.0.31",
"@types/execa": "^0.8.1",

@@ -40,4 +41,6 @@ "@types/glob": "^5.0.35",

"compute-stdev": "^1.0.0",
"easy-table": "^1.1.1",
"execa": "^0.9.0",
"fast-glob": "^2.0.1",
"glob": "^7.1.2",
"glob-stream": "^6.1.0",

@@ -61,5 +64,6 @@ "globby": "^8.0.0",

"clean": "rimraf out",
"lint": "tslint src/{,**/}*.ts -p . -t stylish",
"lint": "tslint \"src/**/*.ts\" -p . -t stylish",
"compile": "tsc",
"test": "mocha \"out/**/*.spec.js\" -s 0",
"smoke": "mocha \"out/**/*.smoke.js\" -s 0",
"build": "npm run clean && npm run lint && npm run compile && npm test",

@@ -66,0 +70,0 @@ "watch": "npm run clean && npm run lint & npm run compile -- --sourceMap --watch",

@@ -91,2 +91,31 @@ # :rocket: fast-glob

### fg.generateTasks(patterns, [options])
Return a set of tasks based on provided patterns. All tasks satisfy the `Task` interface:
```ts
interface Task {
/**
* Parent directory for all patterns inside this task.
*/
base: string;
/**
* Dynamic or static patterns are in this task.
*/
dynamic: boolean;
/**
* All patterns.
*/
patterns: string[];
/**
* Only positive patterns.
*/
positive: string[];
/**
* Only negative patterns without ! symbol.
*/
negative: string[];
}
```
## Options

@@ -256,9 +285,9 @@

interface IEntry {
interface IMyOwnEntry {
path: string;
}
const entries: IEntry[] = fg.sync<IEntry>(['*.md'], {
const entries: IMyOwnEntry[] = fg.sync<IMyOwnEntry>(['*.md'], {
transform: (entry) => typeof entry === 'string' ? { path: entry } : { path: entry.path }
// Will throw compilation error for non-IEntry types (boolean, for example)
// Will throw compilation error for non-IMyOwnEntry types (boolean, for example)
});

@@ -271,6 +300,8 @@ ```

* **first/**
* **second/**
* file.md
* file.md
```
first/
├── file.md
└── second
└── file.txt
```

@@ -277,0 +308,0 @@ If you don't want to read the `second` directory, you must write the following pattern: `!**/second` or `!**/second/**`.

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc