Skip to content

Commit 7e64686

Browse files
Bump to enable explicit v5 support
1 parent ca66781 commit 7e64686

34 files changed

+73671
-42491
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12.20.0
1+
18

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Contributors are welcome to help out with this repository! 😊
44

55
Please follow this guide when raising issues, and contributing to the SMP repository.
66

7+
Running the repo locally and executing the test suite requires Node v18+.
8+
79
## Raising an Issue
810

911
If you're raising an issue with SMP being incompatible with a particular webpack config, plugin, or loader - then please include reproduction steps.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ yarn add -D speed-measure-webpack-plugin
3434

3535
## Requirements
3636

37-
SMP requires at least **Node v6**. But otherwise, accepts **all webpack** versions (1, 2, 3, and 4).
37+
SMP requires at least **Node v6**. But otherwise, accepts **all webpack** versions (1, 2, 3, 4, and 5).
38+
39+
To work on the repository itself and run the test suite, use **Node v18+**.
3840

3941
## Usage
4042

WrappedPlugin/index.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ 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);
30+
const normalArgMap = (a) => wrap(a, pluginName, smp);
3131
let ret;
3232
if (endType === "wrapDone")
3333
ret = func.apply(
3434
context,
35-
args.map(a => wrap(a, pluginName, smp, addEndEvent))
35+
args.map((a) => wrap(a, pluginName, smp, addEndEvent))
3636
);
3737
else if (endType === "async") {
3838
const argsButLast = args.slice(0, args.length - 1);
@@ -45,7 +45,7 @@ const genWrappedFunc = ({
4545
})
4646
);
4747
} else if (endType === "promise")
48-
ret = func.apply(context, args.map(normalArgMap)).then(promiseArg => {
48+
ret = func.apply(context, args.map(normalArgMap)).then((promiseArg) => {
4949
addEndEvent();
5050
return promiseArg;
5151
});
@@ -56,7 +56,7 @@ const genWrappedFunc = ({
5656
};
5757

5858
const genPluginMethod = (orig, pluginName, smp, type) =>
59-
function(method, func) {
59+
function (method, func) {
6060
const timeEventName = pluginName + "/" + type + "/" + method;
6161
const wrappedFunc = genWrappedFunc({
6262
func,
@@ -70,7 +70,7 @@ const genPluginMethod = (orig, pluginName, smp, type) =>
7070
};
7171

7272
const wrapTap = (tap, pluginName, smp, type, method) =>
73-
function(id, func) {
73+
function (id, func) {
7474
const timeEventName = pluginName + "/" + type + "/" + method;
7575
const wrappedFunc = genWrappedFunc({
7676
func,
@@ -83,7 +83,7 @@ const wrapTap = (tap, pluginName, smp, type, method) =>
8383
};
8484

8585
const wrapTapAsync = (tapAsync, pluginName, smp, type, method) =>
86-
function(id, func) {
86+
function (id, func) {
8787
const timeEventName = pluginName + "/" + type + "/" + method;
8888
const wrappedFunc = genWrappedFunc({
8989
func,
@@ -97,7 +97,7 @@ const wrapTapAsync = (tapAsync, pluginName, smp, type, method) =>
9797
};
9898

9999
const wrapTapPromise = (tapPromise, pluginName, smp, type, method) =>
100-
function(id, func) {
100+
function (id, func) {
101101
const timeEventName = pluginName + "/" + type + "/" + method;
102102
const wrappedFunc = genWrappedFunc({
103103
func,
@@ -115,12 +115,12 @@ const wrapHooks = (orig, pluginName, smp, type) => {
115115
const hooks = orig.hooks;
116116
if (!hooks) return hooks;
117117
const prevWrapped = wrappedHooks.find(
118-
w =>
118+
(w) =>
119119
w.pluginName === pluginName && (w.orig === hooks || w.wrapped === hooks)
120120
);
121121
if (prevWrapped) return prevWrapped.wrapped;
122122

123-
const genProxy = method => {
123+
const genProxy = (method) => {
124124
const proxy = new Proxy(hooks[method], {
125125
get: (target, property) => {
126126
const raw = Reflect.get(target, property);
@@ -149,6 +149,15 @@ const wrapHooks = (orig, pluginName, smp, type) => {
149149
};
150150

151151
const wrapped = Object.keys(hooks).reduce((acc, method) => {
152+
if (method === "normalModuleLoader") {
153+
Object.defineProperty(acc, method, {
154+
configurable: true,
155+
enumerable: true,
156+
get: () => genProxy(method),
157+
});
158+
return acc;
159+
}
160+
152161
acc[method] = genProxy(method);
153162
return acc;
154163
}, {});
@@ -170,7 +179,8 @@ const construcNamesToWrap = [
170179
const wrappedObjs = [];
171180
const findWrappedObj = (orig, pluginName) => {
172181
const prevWrapped = wrappedObjs.find(
173-
w => w.pluginName === pluginName && (w.orig === orig || w.wrapped === orig)
182+
(w) =>
183+
w.pluginName === pluginName && (w.orig === orig || w.wrapped === orig)
174184
);
175185
if (prevWrapped) return prevWrapped.wrapped;
176186
};
@@ -179,15 +189,15 @@ const wrap = (orig, pluginName, smp, addEndEvent) => {
179189
const prevWrapped = findWrappedObj(orig, pluginName);
180190
if (prevWrapped) return prevWrapped;
181191

182-
const getOrigConstrucName = target =>
192+
const getOrigConstrucName = (target) =>
183193
target && target.constructor && target.constructor.name;
184-
const getShouldWrap = target => {
194+
const getShouldWrap = (target) => {
185195
const origConstrucName = getOrigConstrucName(target);
186196
return construcNamesToWrap.includes(origConstrucName);
187197
};
188198
const shouldWrap = getShouldWrap(orig);
189199
const shouldSoftWrap = Object.keys(orig)
190-
.map(k => orig[k])
200+
.map((k) => orig[k])
191201
.some(getShouldWrap);
192202

193203
let wrappedReturn;
@@ -196,7 +206,7 @@ const wrap = (orig, pluginName, smp, addEndEvent) => {
196206
const vanillaFunc = orig.name === "next";
197207
wrappedReturn =
198208
vanillaFunc && addEndEvent
199-
? function() {
209+
? function () {
200210
// do this before calling the callback, since the callback can start
201211
// the next plugin step
202212
addEndEvent();

0 commit comments

Comments
 (0)