Skip to content

Commit

Permalink
refactor: code (#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Mar 4, 2021
1 parent 9e12a33 commit 83601dc
Showing 1 changed file with 25 additions and 30 deletions.
55 changes: 25 additions & 30 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class CopyPlugin {
}

static async runPattern(
assetMap,
compiler,
compilation,
logger,
Expand Down Expand Up @@ -319,7 +318,6 @@ class CopyPlugin {
sourceFilename,
filename,
toType,
priority: pattern.priority || 0,
};
})
);
Expand All @@ -329,13 +327,7 @@ class CopyPlugin {
try {
assets = await Promise.all(
files.map(async (file) => {
const {
absoluteFilename,
sourceFilename,
filename,
toType,
priority,
} = file;
const { absoluteFilename, sourceFilename, filename, toType } = file;
const info =
typeof pattern.info === "function"
? pattern.info(file) || {}
Expand Down Expand Up @@ -585,12 +577,6 @@ class CopyPlugin {
result.filename = normalizePath(result.filename);
}

if (!assetMap.has(priority)) {
assetMap.set(priority, []);
}

assetMap.get(priority).push(result);

// eslint-disable-next-line consistent-return
return result;
})
Expand Down Expand Up @@ -627,29 +613,38 @@ class CopyPlugin {

const assetMap = new Map();

try {
await Promise.all(
this.patterns.map((item, index) =>
limit(async () =>
CopyPlugin.runPattern(
assetMap,
await Promise.all(
this.patterns.map((item, index) =>
limit(async () => {
let assets;

try {
assets = await CopyPlugin.runPattern(
compiler,
compilation,
logger,
cache,
item,
index
)
)
)
);
} catch (error) {
compilation.errors.push(error);
);
} catch (error) {
compilation.errors.push(error);

callback();
return;
}

return;
}
if (assets && assets.length > 0) {
const priority = item.priority || 0;

if (!assetMap.has(priority)) {
assetMap.set(priority, []);
}

assetMap.get(priority).push(...assets);
}
})
)
);

const assets = [...assetMap.entries()].sort((a, b) => a[0] - b[0]);

Expand Down

0 comments on commit 83601dc

Please sign in to comment.