Skip to content

Commit

Permalink
fix: support webpack >= v4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
clydin authored and michael-ciniawsky committed Feb 8, 2018
1 parent 7780271 commit 6a16b3c
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,45 @@ function CopyWebpackPlugin(patterns = [], options = {}) {
cb();
};

const compilationFileDependencies = new Set(compilation.fileDependencies);
const compilationContextDependencies = new Set(compilation.contextDependencies);
let compilationFileDependencies;
let addFileDependency;
if (Array.isArray(compilation.fileDependencies)) {
compilationFileDependencies = new Set(compilation.fileDependencies);
addFileDependency = (file) => compilation.fileDependencies.push(file);
} else {
compilationFileDependencies = compilation.fileDependencies;
addFileDependency = (file) => compilation.fileDependencies.add(file);
}

let compilationContextDependencies;
let addContextDependency;
if (Array.isArray(compilation.contextDependencies)) {
compilationContextDependencies = new Set(compilation.contextDependencies);
addContextDependency = (file) => compilation.contextDependencies.push(file);
} else {
compilationContextDependencies = compilation.contextDependencies;
addContextDependency = (file) => compilation.contextDependencies.add(file);
}

// Add file dependencies if they're not already tracked
fileDependencies.forEach((file) => {
for (const file of fileDependencies) {
if (compilationFileDependencies.has(file)) {
debug(`not adding ${file} to change tracking, because it's already tracked`);
} else {
debug(`adding ${file} to change tracking`);
compilation.fileDependencies.push(file);
addFileDependency(file);
}
});
}

// Add context dependencies if they're not already tracked
contextDependencies.forEach((context) => {
for (const context of contextDependencies) {
if (compilationContextDependencies.has(context)) {
debug(`not adding ${context} to change tracking, because it's already tracked`);
} else {
debug(`adding ${context} to change tracking`);
compilation.contextDependencies.push(context);
addContextDependency(context);
}
});
}

callback();
});
Expand Down

0 comments on commit 6a16b3c

Please sign in to comment.