Skip to content

Commit

Permalink
Fix compatibility with plugins depending on plugin properties (e.g. H…
Browse files Browse the repository at this point in the history
…appyPack's 'name' and 'id' references)
  • Loading branch information
stephencookdev committed Mar 4, 2018
1 parent 1212447 commit 2cf8023
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
16 changes: 16 additions & 0 deletions WrappedPlugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ module.exports.WrappedPlugin = class WrappedPlugin {
this._smp = smp;

this.apply = this.apply.bind(this);

const wp = this;
return new Proxy(plugin, {
get(target, property) {
if (property === "apply") {
return wp.apply;
}
return target[property];
},
set: (target, property, value) => {
return Reflect.set(target, property, value);
},
deleteProperty: (target, property) => {
return Reflect.deleteProperty(target, property);
},
});
}

apply(compiler) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "speed-measure-webpack-plugin",
"version": "1.0.1",
"version": "1.0.2",
"description": "Measure + analyse the speed of your webpack loaders and plugins",
"main": "index.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const prependLoader = rules => {
}

if (rules.use) {
if (!Array.isArray(rules.use)) rules.use = [rules.use];
rules.use.unshift("speed-measure-webpack-plugin/loader");
}

Expand Down Expand Up @@ -122,7 +123,7 @@ module.exports.hackWrapLoaders = (loaderPaths, callback) => {
return function() {
const ret = reqMethod.apply(this, arguments);
if (loaderPaths.includes(arguments[0])) {
if(ret.__smpHacked) return ret;
if (ret.__smpHacked) return ret;
ret.__smpHacked = true;
return callback(ret, arguments[0]);
}
Expand Down

0 comments on commit 2cf8023

Please sign in to comment.