Skip to content

Commit

Permalink
refactor: code
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Sep 28, 2020
1 parent 0bbcbf9 commit ff8cdcb
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ async function resolveFilename(
loaderContext,
webpackFileResolver,
webpackGlobResolver,
globTask,
isGlob,
context,
filename
) {
const resolve = globTask ? webpackGlobResolver : webpackFileResolver;
const resolve = isGlob ? webpackGlobResolver : webpackFileResolver;

let globTask;

if (isGlob) {
[globTask] = fastGlob.generateTasks(filename);

if (globTask) {
// eslint-disable-next-line no-param-reassign
filename = globTask.base === '.' ? context : globTask.base;
}
Expand Down Expand Up @@ -168,24 +172,19 @@ async function getDependencies(
}

const isGlob = fastGlob.isDynamicPattern(nodePath);
let globTask;

if (isGlob) {
[globTask] = fastGlob.generateTasks(nodePath);
found = utils.find(nodePath, this.paths, this.filename);

// For webpack resolving we need to add the context dependency later
if (!nodePath.startsWith('~')) {
const context =
globTask.base === '.'
? path.dirname(filename)
: path.join(path.dirname(filename), globTask.base);
if (found && isGlob) {
const [globTask] = fastGlob.generateTasks(nodePath);
const context =
globTask.base === '.'
? path.dirname(filename)
: path.join(path.dirname(filename), globTask.base);

loaderContext.addContextDependency(context);
}
loaderContext.addContextDependency(context);
}

found = utils.find(nodePath, this.paths, this.filename);

if (!found && oldNodePath) {
found = utils.lookupIndex(oldNodePath, this.paths, this.filename);
}
Expand All @@ -211,7 +210,7 @@ async function getDependencies(
loaderContext,
fileResolver,
globResolver,
globTask,
isGlob,
path.dirname(filename),
originalNodePath
),
Expand Down

0 comments on commit ff8cdcb

Please sign in to comment.