Socket
Socket
Sign inDemoInstall

speed-measure-webpack-plugin

Package Overview
Dependencies
297
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.3 to 1.4.0

.all-contributorsrc

2

colours.js

@@ -12,2 +12,2 @@ const chalk = require("chalk");

module.exports.bg = text => chalk.bgBlack.green.bold(text);
module.exports.bg = (text) => chalk.bgBlack.green.bold(text);

@@ -41,6 +41,6 @@ const path = require("path");

config.plugins = (config.plugins || []).map(plugin => {
config.plugins = (config.plugins || []).map((plugin) => {
const pluginName =
Object.keys(this.options.pluginNames || {}).find(
pluginName => plugin === this.options.pluginNames[pluginName]
(pluginName) => plugin === this.options.pluginNames[pluginName]
) ||

@@ -54,3 +54,3 @@ (plugin.constructor && plugin.constructor.name) ||

config.optimization.minimizer = config.optimization.minimizer.map(
plugin => {
(plugin) => {
return new WrappedPlugin(plugin, plugin.constructor.name, this);

@@ -87,2 +87,3 @@ }

return getHumanOutput(outputObj, {
...this.options,
verbose: this.options.outputFormat === "humanVerbose",

@@ -106,3 +107,3 @@ });

} else if (eventType === "end") {
const matchingEvent = eventList.find(e => {
const matchingEvent = eventList.find((e) => {
const allowOverwrite = !e.end || !data.fillLast;

@@ -115,3 +116,3 @@ const idMatch = e.id !== undefined && e.id === data.id;

const eventToModify =
matchingEvent || (data.fillLast && eventList.find(e => !e.end));
matchingEvent || (data.fillLast && eventList.find((e) => !e.end));
if (!eventToModify) {

@@ -162,8 +163,8 @@ console.error(

tap(compiler, "compilation", compilation => {
tap(compilation, "normal-module-loader", loaderContext => {
tap(compiler, "compilation", (compilation) => {
tap(compilation, "normal-module-loader", (loaderContext) => {
loaderContext[NS] = this.provideLoaderTiming;
});
tap(compilation, "build-module", module => {
tap(compilation, "build-module", (module) => {
const name = getModuleName(module);

@@ -179,3 +180,3 @@ if (name) {

tap(compilation, "succeed-module", module => {
tap(compilation, "succeed-module", (module) => {
const name = getModuleName(module);

@@ -182,0 +183,0 @@ if (name) {

module.exports = {
testPathIgnorePatterns: ["__tests__"],
testURL: "http://localhost",
}
};
{
"lerna": "2.9.0",
"packages": [
"__tests__/setups/*"
],
"packages": ["__tests__/setups/*"],
"version": "0.0.0"
}

@@ -9,3 +9,3 @@ const path = require("path");

const getLoaderName = path => {
const getLoaderName = (path) => {
const standardPath = path.replace(/\\/g, "/");

@@ -16,8 +16,8 @@ const nodeModuleName = /\/node_modules\/([^\/]+)/.exec(standardPath);

module.exports.pitch = function() {
module.exports.pitch = function () {
const callback = this[NS];
const module = this.resourcePath;
const loaderPaths = this.loaders
.map(l => l.path)
.filter(l => !l.includes("speed-measure-webpack-plugin"));
.map((l) => l.path)
.filter((l) => !l.includes("speed-measure-webpack-plugin"));

@@ -28,10 +28,10 @@ // Hack ourselves to overwrite the `require` method so we can override the

const loaderName = getLoaderName(path);
const wrapFunc = func =>
function() {
const wrapFunc = (func) =>
function () {
const loaderId = id++;
const almostThis = Object.assign({}, this, {
async: function() {
async: function () {
const asyncCallback = this.async.apply(this, arguments);
return function() {
return function () {
callback({

@@ -38,0 +38,0 @@ id: loaderId,

@@ -9,7 +9,7 @@ # Migration Guide

If you're using the `SpeedMeasurePlugin.wrapPlugins(plugins, options)` static method, then
If you're using the `SpeedMeasurePlugin.wrapPlugins(plugins, options)` static method, then
* remove all `.wrapPlugins` calls
* instantiate an `smp`
* call `smp.wrap` on your entire config
- remove all `.wrapPlugins` calls
- instantiate an `smp`
- call `smp.wrap` on your entire config

@@ -21,5 +21,8 @@ e.g.

const webpackConfig = {
plugins: SpeedMeasurePlugin.wrapPlugins({
FooPlugin: new FooPlugin()
}, smpOptions)
plugins: SpeedMeasurePlugin.wrapPlugins(
{
FooPlugin: new FooPlugin(),
},
smpOptions
),
};

@@ -30,3 +33,3 @@

const webpackConfig = smp.wrap({
plugins: [new FooPlugin()]
plugins: [new FooPlugin()],
});

@@ -39,4 +42,4 @@ ```

* remove all `.wrapPlugins` calls
* call `smp.wrap` on your entire config
- remove all `.wrapPlugins` calls
- call `smp.wrap` on your entire config

@@ -50,4 +53,4 @@ e.g.

plugins: smp.wrapPlugins({
FooPlugin: new FooPlugin()
})
FooPlugin: new FooPlugin(),
}),
};

@@ -58,3 +61,3 @@

const webpackConfig = smp.wrap({
plugins: [new FooPlugin()]
plugins: [new FooPlugin()],
});

@@ -71,8 +74,8 @@ ```

pluginNames: {
customFooPluginName: fooPlugin
}
customFooPluginName: fooPlugin,
},
});
const webpackConfig = smp.wrap({
plugins: [fooPlugin]
plugins: [fooPlugin],
});
```
const SpeedMeasurePlugin = require(".");
const smp = new SpeedMeasurePlugin();
module.exports = neutrino => {
module.exports = (neutrino) => {
const origConfig = neutrino.config;

@@ -6,0 +6,0 @@ const wrappedConfig = smp.wrap(origConfig.toConfig());

@@ -38,3 +38,3 @@ const MS_IN_MINUTE = 60000;

module.exports.getHumanOutput = (outputObj, options = {}) => {
const hT = x => humanTime(x, options);
const hT = (x) => humanTime(x, options);
let output = "\n\n" + smpTag() + "\n";

@@ -54,3 +54,3 @@

)
.forEach(pluginName => {
.forEach((pluginName) => {
output +=

@@ -68,3 +68,3 @@ chalk.bold(pluginName) +

.sort((obj1, obj2) => obj2.activeTime - obj1.activeTime)
.forEach(loaderObj => {
.forEach((loaderObj) => {
output +=

@@ -93,3 +93,3 @@ loaderObj.loaders.map(fg).join(", and \n") +

if (loaderObj.loaders.length > 1) {
Object.keys(loaderObj.subLoadersTime).forEach(subLoader => {
Object.keys(loaderObj.subLoadersTime).forEach((subLoader) => {
xEqualsY.push([subLoader, hT(loaderObj.subLoadersTime[subLoader])]);

@@ -101,2 +101,13 @@ });

if (options.loaderTopFiles) {
const loopLen = Math.min(
loaderObj.rawStartEnds.length,
options.loaderTopFiles
);
for (let i = 0; i < loopLen; i++) {
const rawItem = loaderObj.rawStartEnds[i];
xEqualsY.push([rawItem.name, hT(rawItem.end - rawItem.start)]);
}
}
const maxXLength = xEqualsY.reduce(

@@ -106,3 +117,3 @@ (acc, cur) => Math.max(acc, cur[0].length),

);
xEqualsY.forEach(xY => {
xEqualsY.forEach((xY) => {
const padEnd = maxXLength - xY[0].length;

@@ -119,7 +130,7 @@ output += " " + xY[0] + " ".repeat(padEnd) + " = " + xY[1] + "\n";

module.exports.getMiscOutput = data => ({
module.exports.getMiscOutput = (data) => ({
compileTime: data.compile[0].end - data.compile[0].start,
});
module.exports.getPluginsOutput = data =>
module.exports.getPluginsOutput = (data) =>
Object.keys(data).reduce((acc, key) => {

@@ -137,7 +148,7 @@ const inData = data[key];

module.exports.getLoadersOutput = data => {
module.exports.getLoadersOutput = (data) => {
const startEndsByLoader = groupBy("loaders", data.build);
const allSubLoaders = data["build-specific"] || [];
const buildData = startEndsByLoader.map(startEnds => {
const buildData = startEndsByLoader.map((startEnds) => {
const averages = getAverages(startEnds);

@@ -147,3 +158,3 @@ const activeTime = getTotalActiveTime(startEnds);

"loader",
allSubLoaders.filter(l => startEnds.find(x => x.name === l.name))
allSubLoaders.filter((l) => startEnds.find((x) => x.name === l.name))
);

@@ -160,2 +171,5 @@ const subLoadersActiveTime = subLoaders.reduce((acc, loaders) => {

subLoadersTime: subLoadersActiveTime,
rawStartEnds: startEnds.sort(
(a, b) => b.end - b.start - (a.end - a.start)
),
};

@@ -162,0 +176,0 @@ });

{
"name": "speed-measure-webpack-plugin",
"version": "1.3.3",
"version": "1.4.0",
"description": "Measure + analyse the speed of your webpack loaders and plugins",

@@ -10,3 +10,6 @@ "main": "index.js",

"audit-fix": "npm audit fix && lerna run audit-fix --parallel",
"documentation-test": "alex ./*.md && write-good ./*.md"
"documentation-test": "alex ./*.md && write-good ./*.md",
"lint": "prettier --check \"*.{js,json,css,md}\"",
"fixlint": "prettier --write \"*.{js,json,css,md}\"",
"ac": "all-contributors"
},

@@ -44,13 +47,14 @@ "repository": {

"devDependencies": {
"alex": "^8.1.1",
"alex": "^9.1.0",
"all-contributors-cli": "^6.19.0",
"husky": "^4.2.3",
"jest": "^22.4.2",
"lerna": "^2.9.0",
"jest": "^26.6.3",
"lerna": "^3.22.1",
"lint-staged": "^10.0.8",
"prettier": "^2.0.1",
"prettier": "^2.2.1",
"write-good": "^1.0.2"
},
"dependencies": {
"chalk": "^2.0.1"
"chalk": "^4.1.0"
}
}

@@ -8,6 +8,6 @@ <div align="center">

<a href="https://travis-ci.org/stephencookdev/speed-measure-webpack-plugin"><img src="https://travis-ci.org/stephencookdev/speed-measure-webpack-plugin.svg?branch=master" /></a>
<a href="https://npmjs.com/package/speed-measure-webpack-plugin"><img src="https://img.shields.io/npm/dw/speed-measure-webpack-plugin.svg" /></a>
<a href="https://npmjs.com/package/speed-measure-webpack-plugin"><img src="https://img.shields.io/node/v/speed-measure-webpack-plugin.svg" /></a>
<a href="https://github.com/prettier/prettier"><img src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<a href="https://travis-ci.org/stephencookdev/speed-measure-webpack-plugin"><img src="https://travis-ci.org/stephencookdev/speed-measure-webpack-plugin.svg?branch=master" /></a> <a href="https://npmjs.com/package/speed-measure-webpack-plugin"><img src="https://img.shields.io/npm/dw/speed-measure-webpack-plugin.svg" /></a> <a href="https://npmjs.com/package/speed-measure-webpack-plugin"><img src="https://img.shields.io/node/v/speed-measure-webpack-plugin.svg" /></a> <a href="https://github.com/prettier/prettier"><img src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg" /></a> <a href="#contributors"><img src="https://img.shields.io/badge/all_contributors-8-orange.svg" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
</div>

@@ -44,7 +44,4 @@ <br>

const webpackConfig = {
plugins: [
new MyPlugin(),
new MyOtherPlugin()
]
}
plugins: [new MyPlugin(), new MyOtherPlugin()],
};
```

@@ -60,6 +57,3 @@

const webpackConfig = smp.wrap({
plugins: [
new MyPlugin(),
new MyOtherPlugin()
]
plugins: [new MyPlugin(), new MyOtherPlugin()],
});

@@ -96,6 +90,6 @@ ```

* `"json"` - produces a JSON blob
* `"human"` - produces a human readable output
* `"humanVerbose"` - produces a more verbose version of the human readable output
* If a function, it will call the function with the JSON blob, and output the response
- `"json"` - produces a JSON blob
- `"human"` - produces a human readable output
- `"humanVerbose"` - produces a more verbose version of the human readable output
- If a function, it will call the function with the JSON blob, and output the response

@@ -107,4 +101,4 @@ ### `options.outputTarget`

* If a string, it specifies the path to a file to output to.
* If a function, it will call the function with the output as the first parameter
- If a string, it specifies the path to a file to output to.
- If a function, it will call the function with the output as the first parameter

@@ -124,13 +118,25 @@ ### `options.pluginNames`

pluginNames: {
customUglifyName: uglify
}
customUglifyName: uglify,
},
});
const webpackConfig = smp.wrap({
plugins: [
uglify
]
plugins: [uglify],
});
```
### `options.loaderTopFiles`
Type: `Number`<br>
Default: `0`
You can configure SMP to include the files that take the most time per loader, when using `outputFormat: 'humanVerbose'`. E.g., to show the top 10 files per loader:
```javascript
const smp = new SpeedMeasurePlugin({
outputFormat: "humanVerbose",
loaderTopFiles: 10,
});
```
### `options.granularLoaderData` _(experimental)_

@@ -145,4 +151,4 @@

* loaders using separate processes (e.g. `thread-loader`)
* loaders emitting file output (e.g. `file-loader`)
- loaders using separate processes (e.g. `thread-loader`)
- loaders emitting file output (e.g. `file-loader`)

@@ -174,1 +180,30 @@ We will find solutions to these issues before removing the _(experimental)_ flag on this option.

[MIT](/LICENSE)
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://stephencookdev.co.uk/"><img src="https://avatars.githubusercontent.com/u/8496655?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stephen Cook</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=stephencookdev" title="Code">πŸ’»</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=stephencookdev" title="Documentation">πŸ“–</a> <a href="#blog-stephencookdev" title="Blogposts">πŸ“</a> <a href="#design-stephencookdev" title="Design">🎨</a> <a href="#question-stephencookdev" title="Answering Questions">πŸ’¬</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/pulls?q=is%3Apr+reviewed-by%3Astephencookdev" title="Reviewed Pull Requests">πŸ‘€</a></td>
<td align="center"><a href="https://scarletsky.github.io/"><img src="https://avatars.githubusercontent.com/u/2386165?v=4?s=100" width="100px;" alt=""/><br /><sub><b>scarletsky</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=scarletsky" title="Code">πŸ’»</a></td>
<td align="center"><a href="https://github.com/wayou"><img src="https://avatars.githubusercontent.com/u/3783096?v=4?s=100" width="100px;" alt=""/><br /><sub><b>牛さん</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=wayou" title="Code">πŸ’»</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/issues?q=author%3Awayou" title="Bug reports">πŸ›</a></td>
<td align="center"><a href="https://github.com/ThomasHarper"><img src="https://avatars.githubusercontent.com/u/3199791?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Thomas Bentkowski</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=ThomasHarper" title="Documentation">πŸ“–</a></td>
<td align="center"><a href="https://github.com/alan-agius4"><img src="https://avatars.githubusercontent.com/u/17563226?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alan Agius</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=alan-agius4" title="Code">πŸ’»</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/issues?q=author%3Aalan-agius4" title="Bug reports">πŸ›</a></td>
<td align="center"><a href="https://daix.me/"><img src="https://avatars.githubusercontent.com/u/1396511?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ximing</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=NdYAG" title="Code">πŸ’»</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/issues?q=author%3ANdYAG" title="Bug reports">πŸ›</a></td>
<td align="center"><a href="https://twitter.com/lihautan"><img src="https://avatars.githubusercontent.com/u/2338632?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tan Li Hau</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=tanhauhau" title="Code">πŸ’»</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/issues?q=author%3Atanhauhau" title="Bug reports">πŸ›</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=tanhauhau" title="Tests">⚠️</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/ZauberNerd"><img src="https://avatars.githubusercontent.com/u/249542?v=4?s=100" width="100px;" alt=""/><br /><sub><b>BjΓΆrn Brauer</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=ZauberNerd" title="Code">πŸ’»</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/issues?q=author%3AZauberNerd" title="Bug reports">πŸ›</a></td>
</tr>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
const isEqual = (x, y) =>
Array.isArray(x)
? Array.isArray(y) &&
x.every(xi => y.includes(xi)) &&
y.every(yi => x.includes(yi))
x.every((xi) => y.includes(xi)) &&
y.every((yi) => x.includes(yi))
: x === y;
const mergeRanges = rangeList => {
const mergeRanges = (rangeList) => {
const mergedQueue = [];

@@ -14,3 +14,3 @@ const inputQueue = [...rangeList];

const overlapIndex = mergedQueue.findIndex(
item =>
(item) =>
(item.start >= cur.start && item.start <= cur.end) ||

@@ -34,8 +34,8 @@ (item.end >= cur.start && item.end <= cur.end)

const sqr = x => x * x;
const mean = xs => xs.reduce((acc, x) => acc + x, 0) / xs.length;
const median = xs => xs.sort()[Math.floor(xs.length / 2)];
const sqr = (x) => x * x;
const mean = (xs) => xs.reduce((acc, x) => acc + x, 0) / xs.length;
const median = (xs) => xs.sort()[Math.floor(xs.length / 2)];
const variance = (xs, mean) =>
xs.reduce((acc, x) => acc + sqr(x - mean), 0) / (xs.length - 1);
const range = xs =>
const range = (xs) =>
xs.reduce(

@@ -49,9 +49,9 @@ (acc, x) => ({

module.exports.getModuleName = module => module.userRequest;
module.exports.getModuleName = (module) => module.userRequest;
module.exports.getLoaderNames = loaders =>
module.exports.getLoaderNames = (loaders) =>
loaders && loaders.length
? loaders
.map(l => l.loader || l)
.map(l =>
.map((l) => l.loader || l)
.map((l) =>
l

@@ -64,3 +64,3 @@ .replace(/\\/g, "/")

)
.filter(l => !l.includes("speed-measure-webpack-plugin"))
.filter((l) => !l.includes("speed-measure-webpack-plugin"))
: ["modules with no loaders"];

@@ -70,4 +70,6 @@

const groups = [];
(arr || []).forEach(arrItem => {
const groupItem = groups.find(poss => isEqual(poss[0][key], arrItem[key]));
(arr || []).forEach((arrItem) => {
const groupItem = groups.find((poss) =>
isEqual(poss[0][key], arrItem[key])
);
if (groupItem) groupItem.push(arrItem);

@@ -80,4 +82,4 @@ else groups.push([arrItem]);

module.exports.getAverages = group => {
const durationList = group.map(cur => cur.end - cur.start);
module.exports.getAverages = (group) => {
const durationList = group.map((cur) => cur.end - cur.start);

@@ -95,3 +97,3 @@ const averages = {};

module.exports.getTotalActiveTime = group => {
module.exports.getTotalActiveTime = (group) => {
const mergedRanges = mergeRanges(group);

@@ -101,3 +103,3 @@ return mergedRanges.reduce((acc, range) => acc + range.end - range.start, 0);

const prependLoader = rules => {
const prependLoader = (rules) => {
if (!rules) return rules;

@@ -108,2 +110,6 @@ if (Array.isArray(rules)) return rules.map(prependLoader);

rules.use = [rules.loader];
if (rules.options) {
rules.use[0] = { loader: rules.loader, options: rules.options };
delete rules.options;
}
delete rules.loader;

@@ -138,4 +144,4 @@ }

module.exports.hackWrapLoaders = (loaderPaths, callback) => {
const wrapReq = reqMethod => {
return function() {
const wrapReq = (reqMethod) => {
return function () {
const ret = reqMethod.apply(this, arguments);

@@ -158,3 +164,3 @@ if (loaderPaths.includes(arguments[0])) {

const toCamelCase = s => s.replace(/(\-\w)/g, m => m[1].toUpperCase());
const toCamelCase = (s) => s.replace(/(\-\w)/g, (m) => m[1].toUpperCase());
module.exports.tap = (obj, hookName, func) => {

@@ -161,0 +167,0 @@ if (obj.hooks) {

@@ -30,2 +30,19 @@ const { prependLoader } = require("./utils");

{
name: "single loader with options",
from: {
test: /\.jsx?$/,
loader: "babel-loader",
options: {},
},
to: {
test: /\.jsx?$/,
use: [
"speed-measure-webpack-plugin/loader",
{ loader: "babel-loader", options: {} },
],
},
},
{
name: "single complex use",

@@ -108,3 +125,3 @@

expectedMappings.forEach(mapping => {
expectedMappings.forEach((mapping) => {
it('should create the expected mapping for "' + mapping.name + '"', () => {

@@ -111,0 +128,0 @@ expect(prependLoader(mapping.from)).toEqual(mapping.to);

@@ -128,2 +128,6 @@ let idInc = 0;

if (Object.isFrozen(target)) {
return raw;
}
if (property === "tap" && typeof raw === "function")

@@ -130,0 +134,0 @@ return wrapTap(raw, pluginName, smp, type, method).bind(proxy);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc