Skip to content

Commit

Permalink
refactor: migrate on Set (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Feb 18, 2019
1 parent 9e1c35e commit e870664
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Expand Up @@ -54,8 +54,8 @@ class CopyPlugin {
log(msg, 2);
}

const fileDependencies = [];
const contextDependencies = [];
const fileDependencies = new Set();
const contextDependencies = new Set();
const written = {};

let context;
Expand Down
2 changes: 1 addition & 1 deletion src/postProcessPattern.js
Expand Up @@ -32,7 +32,7 @@ export default function postProcessPattern(globalRef, pattern, file) {

// If this came from a glob, add it to the file watchlist
if (pattern.fromType === 'glob') {
fileDependencies.push(file.absoluteFrom);
fileDependencies.add(file.absoluteFrom);
}

info(`reading ${file.absoluteFrom} to write to assets`);
Expand Down
4 changes: 2 additions & 2 deletions src/preProcessPattern.js
Expand Up @@ -117,7 +117,7 @@ export default function preProcessPattern(globalRef, pattern) {
}

if (stats.isDirectory()) {
contextDependencies.push(pattern.absoluteFrom);
contextDependencies.add(pattern.absoluteFrom);

pattern.fromType = 'dir';
pattern.context = pattern.absoluteFrom;
Expand All @@ -127,7 +127,7 @@ export default function preProcessPattern(globalRef, pattern) {
dot: true,
};
} else if (stats.isFile()) {
fileDependencies.push(pattern.absoluteFrom);
fileDependencies.add(pattern.absoluteFrom);

pattern.fromType = 'file';
pattern.context = path.dirname(pattern.absoluteFrom);
Expand Down
7 changes: 2 additions & 5 deletions src/processPattern.js
Expand Up @@ -45,11 +45,8 @@ export default function processPattern(globalRef, pattern) {
// a new file is added it triggeres a rebuild
const contextPath = path.dirname(path.resolve(from));

if (
contextDependencies.indexOf(contextPath) === -1 &&
isGlob(pattern.glob)
) {
contextDependencies.push(contextPath);
if (isGlob(pattern.glob)) {
contextDependencies.add(contextPath);
}

debug(`found ${from}`);
Expand Down

0 comments on commit e870664

Please sign in to comment.