Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

globby

Package Overview
Dependencies
Maintainers
3
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

globby - npm Package Compare versions

Comparing version 6.1.0 to 7.0.0

gitignore.js

142

index.js
'use strict';
var Promise = require('pinkie-promise');
var arrayUnion = require('array-union');
var objectAssign = require('object-assign');
var glob = require('glob');
var pify = require('pify');
const arrayUnion = require('array-union');
const glob = require('glob');
const pify = require('pify');
const dirGlob = require('dir-glob');
const gitignore = require('./gitignore');
var globP = pify(glob, Promise).bind(glob);
const globP = pify(glob);
const DEFAULT_FILTER = () => false;
function isNegative(pattern) {
return pattern[0] === '!';
}
const isNegative = pattern => pattern[0] === '!';
function isString(value) {
return typeof value === 'string';
}
function assertPatternsInput(patterns) {
if (!patterns.every(isString)) {
throw new TypeError('patterns must be a string or an array of strings');
const assertPatternsInput = patterns => {
if (!patterns.every(x => typeof x === 'string')) {
throw new TypeError('Patterns must be a string or an array of strings');
}
}
};
function generateGlobTasks(patterns, opts) {
const generateGlobTasks = (patterns, taskOpts) => {
patterns = [].concat(patterns);
assertPatternsInput(patterns);
var globTasks = [];
const globTasks = [];
opts = objectAssign({
taskOpts = Object.assign({
cache: Object.create(null),

@@ -35,6 +30,8 @@ statCache: Object.create(null),

symlinks: Object.create(null),
ignore: []
}, opts);
ignore: [],
expandDirectories: true,
nodir: true
}, taskOpts);
patterns.forEach(function (pattern, i) {
patterns.forEach((pattern, i) => {
if (isNegative(pattern)) {

@@ -44,20 +41,34 @@ return;

var ignore = patterns.slice(i).filter(isNegative).map(function (pattern) {
return pattern.slice(1);
const ignore = patterns
.slice(i)
.filter(isNegative)
.map(pattern => pattern.slice(1));
const opts = Object.assign({}, taskOpts, {
ignore: taskOpts.ignore.concat(ignore)
});
globTasks.push({
pattern: pattern,
opts: objectAssign({}, opts, {
ignore: opts.ignore.concat(ignore)
})
});
globTasks.push({pattern, opts});
});
return globTasks;
}
};
module.exports = function (patterns, opts) {
var globTasks;
const globDirs = (task, fn) => {
if (Array.isArray(task.opts.expandDirectories)) {
return fn(task.pattern, {files: task.opts.expandDirectories});
}
if (typeof task.opts.expandDirectories === 'object') {
return fn(task.pattern, task.opts.expandDirectories);
}
return fn(task.pattern);
};
const getPattern = (task, fn) => task.opts.expandDirectories ? globDirs(task, fn) : [task.pattern];
module.exports = (patterns, opts) => {
let globTasks;
try {

@@ -69,15 +80,50 @@ globTasks = generateGlobTasks(patterns, opts);

return Promise.all(globTasks.map(function (task) {
return globP(task.pattern, task.opts);
})).then(function (paths) {
return arrayUnion.apply(null, paths);
});
const getTasks = Promise.all(globTasks.map(task => Promise.resolve(getPattern(task, dirGlob))
.then(globs => Promise.all(globs.map(glob => ({
pattern: glob,
opts: task.opts
}))))
))
.then(tasks => arrayUnion.apply(null, tasks));
const getFilter = () => {
return Promise.resolve(
opts && opts.gitignore ?
gitignore({cwd: opts.cwd, ignore: opts.ignore}) :
DEFAULT_FILTER
);
};
return getFilter()
.then(filter => {
return getTasks
.then(tasks => Promise.all(tasks.map(task => globP(task.pattern, task.opts))))
.then(paths => arrayUnion.apply(null, paths))
.then(paths => paths.filter(p => !filter(p)));
});
};
module.exports.sync = function (patterns, opts) {
var globTasks = generateGlobTasks(patterns, opts);
module.exports.sync = (patterns, opts) => {
const globTasks = generateGlobTasks(patterns, opts);
return globTasks.reduce(function (matches, task) {
return arrayUnion(matches, glob.sync(task.pattern, task.opts));
}, []);
const getFilter = () => {
return opts && opts.gitignore ?
gitignore.sync({cwd: opts.cwd, ignore: opts.ignore}) :
DEFAULT_FILTER;
};
const tasks = globTasks.reduce(
(tasks, task) => arrayUnion(getPattern(task, dirGlob.sync).map(glob => ({
pattern: glob,
opts: task.opts
}))),
[]
);
const filter = getFilter();
return tasks.reduce(
(matches, task) => arrayUnion(matches, glob.sync(task.pattern, task.opts)),
[]
).filter(p => !filter(p));
};

@@ -87,6 +133,4 @@

module.exports.hasMagic = function (patterns, opts) {
return [].concat(patterns).some(function (pattern) {
return glob.hasMagic(pattern, opts);
});
};
module.exports.hasMagic = (patterns, opts) => []
.concat(patterns)
.some(pattern => glob.hasMagic(pattern, opts));
{
"name": "globby",
"version": "6.1.0",
"description": "Extends `glob` with support for multiple patterns and exposes a Promise API",
"license": "MIT",
"repository": "sindresorhus/globby",
"author": {
"email": "sindresorhus@gmail.com",
"name": "Sindre Sorhus",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"bench": "npm update glob-stream && matcha bench.js",
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"all",
"array",
"directories",
"dirs",
"expand",
"files",
"filesystem",
"filter",
"find",
"fnmatch",
"folders",
"fs",
"glob",
"globbing",
"globs",
"gulpfriendly",
"match",
"matcher",
"minimatch",
"multi",
"multiple",
"paths",
"pattern",
"patterns",
"traverse",
"util",
"utility",
"wildcard",
"wildcards",
"promise"
],
"dependencies": {
"array-union": "^1.0.1",
"glob": "^7.0.3",
"object-assign": "^4.0.1",
"pify": "^2.0.0",
"pinkie-promise": "^2.0.0"
},
"devDependencies": {
"ava": "*",
"glob-stream": "gulpjs/glob-stream#master",
"globby": "sindresorhus/globby#master",
"matcha": "^0.7.0",
"rimraf": "^2.2.8",
"xo": "^0.16.0"
}
"name": "globby",
"version": "7.0.0",
"description": "Extends `glob` with support for multiple patterns and exposes a Promise API",
"license": "MIT",
"repository": "sindresorhus/globby",
"author": {
"email": "sindresorhus@gmail.com",
"name": "Sindre Sorhus",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"bench": "npm update glob-stream fast-glob && matcha bench.js",
"test": "xo && ava"
},
"files": [
"index.js",
"gitignore.js"
],
"keywords": [
"all",
"array",
"directories",
"dirs",
"expand",
"files",
"filesystem",
"filter",
"find",
"fnmatch",
"folders",
"fs",
"glob",
"globbing",
"globs",
"gulpfriendly",
"match",
"matcher",
"minimatch",
"multi",
"multiple",
"paths",
"pattern",
"patterns",
"traverse",
"util",
"utility",
"wildcard",
"wildcards",
"promise",
"gitignore",
"git"
],
"dependencies": {
"array-union": "^1.0.1",
"dir-glob": "^2.0.0",
"glob": "^7.1.2",
"ignore": "^3.3.5",
"pify": "^3.0.0",
"slash": "^1.0.0"
},
"devDependencies": {
"ava": "*",
"fast-glob": "^1.0.1",
"glob-stream": "^6.1.0",
"globby": "sindresorhus/globby#master",
"matcha": "^0.7.0",
"rimraf": "^2.2.8",
"xo": "^0.18.0"
}
}
# globby [![Build Status](https://travis-ci.org/sindresorhus/globby.svg?branch=master)](https://travis-ci.org/sindresorhus/globby)
> Extends [glob](https://github.com/isaacs/node-glob) with support for multiple patterns and exposes a Promise API
> User-friendly glob matching
Based on [`glob`](https://github.com/isaacs/node-glob), but adds a bunch of useful features and a nicer API.
## Features
- Promise API
- Multiple patterns
- Negated patterns: `['foo*', '!foobar']`
- Expands directories: `dir` → `dir/**/*`
- Supports `.gitignore`
## Install
```
$ npm install --save globby
$ npm install globby
```

@@ -24,6 +35,8 @@

globby(['*', '!cake']).then(paths => {
(async () => {
const paths = await globby(['*', '!cake']);
console.log(paths);
//=> ['unicorn', 'rainbow']
});
})();
```

@@ -36,11 +49,11 @@

Returns a Promise for an array of matching paths.
Returns a `Promise<Array>` of matching paths.
### globby.sync(patterns, [options])
Returns an array of matching paths.
Returns an `Array` of matching paths.
### globby.generateGlobTasks(patterns, [options])
Returns an array of objects in the format `{ pattern: string, opts: Object }`, which can be passed as arguments to [`node-glob`](https://github.com/isaacs/node-glob). This is useful for other globbing-related packages.
Returns an `Array<Object>` in the format `{pattern: string, opts: Object}`, which can be passed as arguments to [`node-glob`](https://github.com/isaacs/node-glob). This is useful for other globbing-related packages.

@@ -65,5 +78,37 @@ Note that you should avoid running the same tasks multiple times as they contain a file system cache. Instead, run this method each time to ensure file system changes are taken into consideration.

See the `node-glob` [options](https://github.com/isaacs/node-glob#options).
See the [`node-glob` options](https://github.com/isaacs/node-glob#options) in addition to the ones below.
One difference is that `nodir` is `true` by default here.
##### expandDirectories
Type: `boolean` `Array` `Object`<br>
Default: `true`
If set to `true`, `globby` will automatically glob directories for you. If you define an `Array` it will only glob files that matches the patterns inside the `Array`. You can also define an `Object` with `files` and `extensions` like below:
```js
(async () => {
const paths = await globby('images', {
expandDirectories: {
files: ['cat', 'unicorn', '*.jpg'],
extensions: ['png']
}
});
console.log(paths);
//=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg']
})();
```
Note that if you set this option to `false`, you won't get back matched directories unless you set `nodir: false`.
##### gitignore
Type: `boolean`<br>
Default: `false`
Respect ignore patterns in `.gitignore` files that apply to the globbed files.
## Globbing patterns

@@ -79,3 +124,3 @@

[Various patterns and expected matches.](https://github.com/sindresorhus/multimatch/blob/master/test.js)
[Various patterns and expected matches.](https://github.com/sindresorhus/multimatch/blob/master/test/test.js)

@@ -86,4 +131,5 @@

- [multimatch](https://github.com/sindresorhus/multimatch) - Match against a list instead of the filesystem
- [glob-stream](https://github.com/wearefractal/glob-stream) - Streaming alternative
- [matcher](https://github.com/sindresorhus/matcher) - Simple wildcard matching
- [del](https://github.com/sindresorhus/del) - Delete files and directories
- [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed

@@ -90,0 +136,0 @@

Sorry, the diff of this file is not supported yet

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