Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fast glob #1650

Merged
merged 5 commits into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@
"cssnano": "^3.10.0",
"deasync": "^0.1.13",
"dotenv": "^5.0.0",
"fast-glob": "^2.2.2",
"filesize": "^3.6.0",
"fswatcher-child": "^1.0.3",
"get-port": "^3.2.0",
"glob": "^7.1.2",
"grapheme-breaker": "^0.3.2",
"htmlnano": "^0.1.9",
"is-glob": "^4.0.0",
"is-url": "^1.2.2",
"js-yaml": "^3.10.0",
"json5": "^1.0.1",
Expand All @@ -62,9 +63,9 @@
"serve-static": "^1.12.4",
"source-map": "0.6.1",
"strip-ansi": "^4.0.0",
"terser": "^3.7.3",
"toml": "^2.3.3",
"tomlify-j0.4": "^3.0.0",
"terser": "^3.7.3",
"v8-compile-cache": "^2.0.0",
"ws": "^5.1.1"
},
Expand Down
4 changes: 2 additions & 2 deletions src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const installPackage = require('./utils/installPackage');
const bundleReport = require('./utils/bundleReport');
const prettifyTime = require('./utils/prettifyTime');
const getRootDir = require('./utils/getRootDir');
const glob = require('glob');
const glob = require('fast-glob');

/**
* The Bundler is the main entry point. It resolves and loads assets,
Expand Down Expand Up @@ -80,7 +80,7 @@ class Bundler extends EventEmitter {

// Match files as globs
return entryFiles
.reduce((p, m) => p.concat(glob.sync(m, {nonull: true})), [])
.reduce((p, m) => p.concat(glob.sync(m)), [])
.map(f => Path.resolve(f));
}

Expand Down
4 changes: 2 additions & 2 deletions src/Parser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const RawAsset = require('./assets/RawAsset');
const GlobAsset = require('./assets/GlobAsset');
const glob = require('glob');
const {isGlob} = require('./utils/glob');

class Parser {
constructor(options = {}) {
Expand Down Expand Up @@ -62,7 +62,7 @@ class Parser {
}

findParser(filename, fromPipeline) {
if (!fromPipeline && /[*+{}]/.test(filename) && glob.hasMagic(filename)) {
if (!fromPipeline && isGlob(filename)) {
return GlobAsset;
}

Expand Down
7 changes: 3 additions & 4 deletions src/Resolver.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const builtins = require('./builtins');
const path = require('path');
const glob = require('glob');
const {isGlob} = require('./utils/glob');
const fs = require('./utils/fs');
const micromatch = require('micromatch');

const EMPTY_SHIM = require.resolve('./builtins/_empty');
const GLOB_RE = /[*+{}]/;

/**
* This resolver implements a modified version of the node_modules resolution algorithm:
Expand Down Expand Up @@ -38,7 +37,7 @@ class Resolver {
}

// Check if this is a glob
if (GLOB_RE.test(filename) && glob.hasMagic(filename)) {
if (isGlob(filename)) {
return {path: path.resolve(path.dirname(parent), filename)};
}

Expand Down Expand Up @@ -391,7 +390,7 @@ class Resolver {

// Otherwise, try replacing glob keys
for (let key in aliases) {
if (GLOB_RE.test(key)) {
if (isGlob(key)) {
let re = micromatch.makeRe(key, {capture: true});
if (re.test(filename)) {
return filename.replace(re, aliases[key]);
Expand Down
6 changes: 2 additions & 4 deletions src/assets/GlobAsset.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Asset = require('../Asset');
const promisify = require('../utils/promisify');
const glob = promisify(require('glob'));
const {glob} = require('../utils/glob');
const micromatch = require('micromatch');
const path = require('path');

Expand All @@ -16,8 +15,7 @@ class GlobAsset extends Asset {
regularExpressionSafeName = regularExpressionSafeName.replace(/\\/g, '/');

let files = await glob(regularExpressionSafeName, {
strict: true,
nodir: true
onlyFiles: true
});
let re = micromatch.makeRe(regularExpressionSafeName, {capture: true});
let matches = {};
Expand Down
9 changes: 9 additions & 0 deletions src/utils/glob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const isGlob = require('is-glob');

exports.isGlob = function(filename) {
return isGlob(filename, {
strict: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

});
};

exports.glob = require('fast-glob');
34 changes: 34 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
esutils "^2.0.2"
js-tokens "^3.0.0"

"@mrmlnc/readdir-enhanced@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde"
dependencies:
call-me-maybe "^1.0.1"
glob-to-regexp "^0.3.0"

"@nodelib/fs.stat@^1.0.1":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.0.tgz#50c1e2260ac0ed9439a181de3725a0168d59c48a"

"@samverschueren/stream-to-observable@^0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz#ecdf48d532c58ea477acfcab80348424f8d0662f"
Expand Down Expand Up @@ -1109,6 +1120,10 @@ caching-transform@^1.0.0:
mkdirp "^0.5.1"
write-file-atomic "^1.1.4"

call-me-maybe@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b"

caller-path@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-0.1.0.tgz#94085ef63581ecd3daa92444a8fe94e82577751f"
Expand Down Expand Up @@ -2329,6 +2344,17 @@ fast-deep-equal@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz#c053477817c86b51daa853c81e059b733d023614"

fast-glob@^2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-2.2.2.tgz#71723338ac9b4e0e2fff1d6748a2a13d5ed352bf"
dependencies:
"@mrmlnc/readdir-enhanced" "^2.2.1"
"@nodelib/fs.stat" "^1.0.1"
glob-parent "^3.1.0"
is-glob "^4.0.0"
merge2 "^1.2.1"
micromatch "^3.1.10"

fast-json-stable-stringify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
Expand Down Expand Up @@ -2613,6 +2639,10 @@ glob-parent@^3.1.0:
is-glob "^3.1.0"
path-dirname "^1.0.0"

glob-to-regexp@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab"

glob@7.0.x:
version "7.0.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.6.tgz#211bafaf49e525b8cd93260d14ab136152b3f57a"
Expand Down Expand Up @@ -4276,6 +4306,10 @@ merge-source-map@^1.1.0:
dependencies:
source-map "^0.6.1"

merge2@^1.2.1:
version "1.2.2"
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.2.2.tgz#03212e3da8d86c4d8523cebd6318193414f94e34"

micromatch@^2.1.5, micromatch@^2.3.11:
version "2.3.11"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565"
Expand Down