Skip to content

Commit

Permalink
Use async modules when possibles (#1433)
Browse files Browse the repository at this point in the history
* Use async version of `resolve` for `localRequire`

* Use async version of `glob` for `GlobAsset`
  • Loading branch information
fathyb authored and Jasper De Moor committed May 24, 2018
1 parent 1cb05e0 commit 83dfa3e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/assets/GlobAsset.js
@@ -1,5 +1,6 @@
const Asset = require('../Asset');
const glob = require('glob');
const promisify = require('../utils/promisify');
const glob = promisify(require('glob'));
const micromatch = require('micromatch');
const path = require('path');

Expand All @@ -14,7 +15,7 @@ class GlobAsset extends Asset {
if (process.platform === 'win32')
regularExpressionSafeName = regularExpressionSafeName.replace(/\\/g, '/');

let files = glob.sync(regularExpressionSafeName, {
let files = await glob(regularExpressionSafeName, {
strict: true,
nodir: true
});
Expand Down
5 changes: 3 additions & 2 deletions src/utils/localRequire.js
@@ -1,5 +1,6 @@
const {dirname} = require('path');
const resolve = require('resolve');
const promisify = require('../utils/promisify');
const resolve = promisify(require('resolve'));
const worker = require('../worker');

const cache = new Map();
Expand All @@ -10,7 +11,7 @@ async function localRequire(name, path, triedInstall = false) {
let resolved = cache.get(key);
if (!resolved) {
try {
resolved = resolve.sync(name, {basedir});
resolved = await resolve(name, {basedir}).then(([name]) => name);
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND' && !triedInstall) {
await worker.addCall({
Expand Down

0 comments on commit 83dfa3e

Please sign in to comment.