diff --git a/package.json b/package.json index fb8a7bfa836..24662893eac 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/Bundler.js b/src/Bundler.js index b83c039495c..9fd063d97e1 100644 --- a/src/Bundler.js +++ b/src/Bundler.js @@ -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, @@ -81,7 +81,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)); } diff --git a/src/Parser.js b/src/Parser.js index 8c6fc23b50e..db1305edbe3 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -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('is-glob'); class Parser { constructor(options = {}) { @@ -62,7 +62,7 @@ class Parser { } findParser(filename, fromPipeline) { - if (!fromPipeline && /[*+{}]/.test(filename) && glob.hasMagic(filename)) { + if (!fromPipeline && isGlob(filename)) { return GlobAsset; } diff --git a/src/Resolver.js b/src/Resolver.js index 245f5287e6e..734d6e86aeb 100644 --- a/src/Resolver.js +++ b/src/Resolver.js @@ -1,11 +1,10 @@ const builtins = require('./builtins'); const path = require('path'); -const glob = require('glob'); +const isGlob = require('is-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: @@ -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)}; } @@ -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]); diff --git a/src/assets/GlobAsset.js b/src/assets/GlobAsset.js index 63f151f5bde..af7451f7ac2 100644 --- a/src/assets/GlobAsset.js +++ b/src/assets/GlobAsset.js @@ -1,6 +1,5 @@ const Asset = require('../Asset'); -const promisify = require('../utils/promisify'); -const glob = promisify(require('glob')); +const glob = require('fast-glob'); const micromatch = require('micromatch'); const path = require('path'); @@ -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 = {}; diff --git a/yarn.lock b/yarn.lock index 5ec943b74a4..a411044b0b2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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" @@ -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" @@ -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"