Skip to content

Commit

Permalink
major: use fast-glob instead glob
Browse files Browse the repository at this point in the history
reasons of migration:
* fast-glob faster than glob
* fast-glob does not have a memory leak, unlike glob
  • Loading branch information
DudaGod committed Oct 2, 2018
1 parent 74ef7e8 commit 55e74c9
Show file tree
Hide file tree
Showing 6 changed files with 1,328 additions and 323 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# glob-extra

Wrapper for utility [glob](https://github.com/isaacs/node-glob) with promises support which provides expanding of masks, dirs and files to absolute file paths.
Wrapper for utility [fast-glob](https://github.com/mrmlnc/fast-glob) with promises support which provides expanding of masks, dirs and files to absolute file paths.

[![NPM version](https://img.shields.io/npm/v/glob-extra.svg?style=flat)](https://www.npmjs.org/package/glob-extra)
[![Build Status](https://travis-ci.org/gemini-testing/glob-extra.svg?branch=master)](https://travis-ci.org/gemini-testing/glob-extra)
Expand Down
11 changes: 8 additions & 3 deletions lib/defaults.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'use strict';
const _ = require('lodash');

module.exports = (options) => {
return _.defaults(options || {}, {
const defaultOpts = {
expandOpts: {
root: null,
formats: []
});
},
globOpts: {
onlyFiles: false
}
};

module.exports = (name, options = {}) => _.defaults(options, defaultOpts[name]);
26 changes: 19 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'use strict';

const path = require('path');
const Promise = require('bluebird');
const _ = require('lodash');
const glob = Promise.promisify(require('glob'));
const fg = require('fast-glob');
const {Minimatch} = require('minimatch');
const defaults = require('./defaults');
const utils = require('./utils');
const path = require('path');

const isMask = (pattern) => glob.hasMagic(pattern);

const getFilesByMask = (pattern, options) => glob(pattern, options);
const getFilesByMask = (pattern, options) => fg(pattern, options);

const expandPath = (basePath, options) => {
basePath = options.root ? path.resolve(options.root, basePath) : basePath;
Expand All @@ -26,12 +25,25 @@ const processPaths = (paths, cb) => {
};

exports.expandPaths = (paths, expandOpts, globOpts) => {
expandOpts = defaults(expandOpts);
expandOpts = defaults('expandOpts', expandOpts);
globOpts = _(defaults('globOpts', globOpts)).omitBy(_.isUndefined).value();

paths = [].concat(paths);

return processPaths(paths, (path) => getFilesByMask(path, globOpts))
.then((matchedPaths) => processPaths(matchedPaths, (path) => expandPath(path, expandOpts)));
};

exports.isMask = isMask;
exports.isMask = (pattern) => {
if (!pattern) {
return false;
}

const {set} = new Minimatch(pattern);

if (set.length > 1) {
return true;
}

return set[0].some((v) => typeof v !== 'string');
};
Loading

0 comments on commit 55e74c9

Please sign in to comment.