Skip to content

Commit 96db141

Browse files
committed
feat: supports webpack5 and mini-css-extract-plugin
1 parent ca66781 commit 96db141

File tree

5 files changed

+8499
-25
lines changed

5 files changed

+8499
-25
lines changed

WrappedPlugin/index.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,35 @@ const genWrappedFunc = ({
2727
// to complete compilation. If this gets invoked and not the subsequent
2828
// call, then our data will be inaccurate, sadly
2929
addEndEvent();
30-
const normalArgMap = a => wrap(a, pluginName, smp);
3130
let ret;
3231
if (endType === "wrapDone")
3332
ret = func.apply(
3433
context,
35-
args.map(a => wrap(a, pluginName, smp, addEndEvent))
34+
args.map((a) => wrap(a, pluginName, smp, addEndEvent))
3635
);
3736
else if (endType === "async") {
3837
const argsButLast = args.slice(0, args.length - 1);
3938
const callback = args[args.length - 1];
4039
ret = func.apply(
4140
context,
42-
argsButLast.map(normalArgMap).concat((...callbackArgs) => {
41+
argsButLast.concat((...callbackArgs) => {
4342
addEndEvent();
4443
callback(...callbackArgs);
4544
})
4645
);
4746
} else if (endType === "promise")
48-
ret = func.apply(context, args.map(normalArgMap)).then(promiseArg => {
47+
ret = func.apply(context, args).then((promiseArg) => {
4948
addEndEvent();
5049
return promiseArg;
5150
});
52-
else ret = func.apply(context, args.map(normalArgMap));
51+
else ret = func.apply(context, args);
5352
addEndEvent();
5453

5554
return ret;
5655
};
5756

5857
const genPluginMethod = (orig, pluginName, smp, type) =>
59-
function(method, func) {
58+
function (method, func) {
6059
const timeEventName = pluginName + "/" + type + "/" + method;
6160
const wrappedFunc = genWrappedFunc({
6261
func,
@@ -70,7 +69,7 @@ const genPluginMethod = (orig, pluginName, smp, type) =>
7069
};
7170

7271
const wrapTap = (tap, pluginName, smp, type, method) =>
73-
function(id, func) {
72+
function (id, func) {
7473
const timeEventName = pluginName + "/" + type + "/" + method;
7574
const wrappedFunc = genWrappedFunc({
7675
func,
@@ -83,7 +82,7 @@ const wrapTap = (tap, pluginName, smp, type, method) =>
8382
};
8483

8584
const wrapTapAsync = (tapAsync, pluginName, smp, type, method) =>
86-
function(id, func) {
85+
function (id, func) {
8786
const timeEventName = pluginName + "/" + type + "/" + method;
8887
const wrappedFunc = genWrappedFunc({
8988
func,
@@ -97,7 +96,7 @@ const wrapTapAsync = (tapAsync, pluginName, smp, type, method) =>
9796
};
9897

9998
const wrapTapPromise = (tapPromise, pluginName, smp, type, method) =>
100-
function(id, func) {
99+
function (id, func) {
101100
const timeEventName = pluginName + "/" + type + "/" + method;
102101
const wrappedFunc = genWrappedFunc({
103102
func,
@@ -115,12 +114,12 @@ const wrapHooks = (orig, pluginName, smp, type) => {
115114
const hooks = orig.hooks;
116115
if (!hooks) return hooks;
117116
const prevWrapped = wrappedHooks.find(
118-
w =>
117+
(w) =>
119118
w.pluginName === pluginName && (w.orig === hooks || w.wrapped === hooks)
120119
);
121120
if (prevWrapped) return prevWrapped.wrapped;
122121

123-
const genProxy = method => {
122+
const genProxy = (method) => {
124123
const proxy = new Proxy(hooks[method], {
125124
get: (target, property) => {
126125
const raw = Reflect.get(target, property);
@@ -170,7 +169,8 @@ const construcNamesToWrap = [
170169
const wrappedObjs = [];
171170
const findWrappedObj = (orig, pluginName) => {
172171
const prevWrapped = wrappedObjs.find(
173-
w => w.pluginName === pluginName && (w.orig === orig || w.wrapped === orig)
172+
(w) =>
173+
w.pluginName === pluginName && (w.orig === orig || w.wrapped === orig)
174174
);
175175
if (prevWrapped) return prevWrapped.wrapped;
176176
};
@@ -179,15 +179,15 @@ const wrap = (orig, pluginName, smp, addEndEvent) => {
179179
const prevWrapped = findWrappedObj(orig, pluginName);
180180
if (prevWrapped) return prevWrapped;
181181

182-
const getOrigConstrucName = target =>
182+
const getOrigConstrucName = (target) =>
183183
target && target.constructor && target.constructor.name;
184-
const getShouldWrap = target => {
184+
const getShouldWrap = (target) => {
185185
const origConstrucName = getOrigConstrucName(target);
186186
return construcNamesToWrap.includes(origConstrucName);
187187
};
188188
const shouldWrap = getShouldWrap(orig);
189189
const shouldSoftWrap = Object.keys(orig)
190-
.map(k => orig[k])
190+
.map((k) => orig[k])
191191
.some(getShouldWrap);
192192

193193
let wrappedReturn;
@@ -196,7 +196,7 @@ const wrap = (orig, pluginName, smp, addEndEvent) => {
196196
const vanillaFunc = orig.name === "next";
197197
wrappedReturn =
198198
vanillaFunc && addEndEvent
199-
? function() {
199+
? function () {
200200
// do this before calling the callback, since the callback can start
201201
// the next plugin step
202202
addEndEvent();
@@ -238,12 +238,6 @@ const wrap = (orig, pluginName, smp, addEndEvent) => {
238238
Object.defineProperty(ret, "name", {
239239
value: raw.name,
240240
});
241-
const funcProxy = new Proxy(ret, {
242-
get: (target, property) => {
243-
return raw[property];
244-
},
245-
});
246-
return funcProxy;
247241
}
248242

249243
return raw;

0 commit comments

Comments
 (0)