speed-measure-webpack-plugin
Advanced tools
Comparing version 1.4.2 to 1.5.0
103
index.js
@@ -33,2 +33,5 @@ const path = require("path"); | ||
this.provideLoaderTiming = this.provideLoaderTiming.bind(this); | ||
this.generateLoadersBuildComparison = this.generateLoadersBuildComparison.bind( | ||
this | ||
); | ||
} | ||
@@ -72,2 +75,90 @@ | ||
generateLoadersBuildComparison() { | ||
const objBuildData = { loaderInfo: [] }; | ||
const loaderFile = this.options.compareLoadersBuild.filePath; | ||
const outputObj = getLoadersOutput(this.timeEventData.loaders); | ||
if (!loaderFile) { | ||
throw new Error( | ||
"`options.compareLoadersBuild.filePath` is a required field" | ||
); | ||
} | ||
if (!outputObj) { | ||
throw new Error("No output found!"); | ||
} | ||
const buildDetailsFile = fs.existsSync(loaderFile) | ||
? fs.readFileSync(loaderFile) | ||
: "[]"; | ||
const buildDetails = JSON.parse(buildDetailsFile.toString()); | ||
const buildCount = buildDetails.length; | ||
const buildNo = | ||
buildCount > 0 ? buildDetails[buildCount - 1]["buildNo"] + 1 : 1; | ||
// create object format of current loader and write in the file | ||
outputObj.build.forEach((loaderObj) => { | ||
const loaderInfo = {}; | ||
loaderInfo["Name"] = loaderObj.loaders.join(",") || ""; | ||
loaderInfo["Time"] = loaderObj.activeTime || ""; | ||
loaderInfo["Count"] = | ||
this.options.outputFormat === "humanVerbose" | ||
? loaderObj.averages.dataPoints | ||
: ""; | ||
loaderInfo[`Comparison`] = ""; | ||
// Getting the comparison from the previous build by default only | ||
// in case if build data is more then one | ||
if (buildCount > 0) { | ||
const prevBuildIndex = buildCount - 1; | ||
for ( | ||
var y = 0; | ||
y < buildDetails[prevBuildIndex]["loaderInfo"].length; | ||
y++ | ||
) { | ||
const prevloaderDetails = | ||
buildDetails[prevBuildIndex]["loaderInfo"][y]; | ||
if ( | ||
loaderInfo["Name"] == prevloaderDetails["Name"] && | ||
prevloaderDetails["Time"] | ||
) { | ||
const previousBuildTime = | ||
buildDetails[prevBuildIndex]["loaderInfo"][y]["Time"]; | ||
const savedTime = previousBuildTime > loaderObj.activeTime; | ||
loaderInfo[`Comparison`] = `${savedTime ? "-" : "+"}${Math.abs( | ||
loaderObj.activeTime - previousBuildTime | ||
)}ms | ${savedTime ? "(slower)" : "(faster)"}`; | ||
} | ||
} | ||
} | ||
objBuildData["loaderInfo"].push(loaderInfo); | ||
}); | ||
buildDetails.push({ buildNo, loaderInfo: objBuildData["loaderInfo"] }); | ||
fs.writeFileSync(loaderFile, JSON.stringify(buildDetails)); | ||
for (let i = 0; i < buildDetails.length; i++) { | ||
const outputTable = []; | ||
console.log("--------------------------------------------"); | ||
console.log("Build No ", buildDetails[i]["buildNo"]); | ||
console.log("--------------------------------------------"); | ||
if (buildDetails[i]["loaderInfo"]) { | ||
buildDetails[i]["loaderInfo"].forEach((buildInfo) => { | ||
const objCurrentBuild = {}; | ||
objCurrentBuild["Name"] = buildInfo["Name"] || ""; | ||
objCurrentBuild["Time (ms)"] = buildInfo["Time"] || ""; | ||
if (this.options.outputFormat === "humanVerbose") | ||
objCurrentBuild["Count"] = buildInfo["Count"] || 0; | ||
objCurrentBuild["Comparison"] = buildInfo["Comparison"] || ""; | ||
outputTable.push(objCurrentBuild); | ||
}); | ||
} | ||
console.table(outputTable); | ||
} | ||
} | ||
getOutput() { | ||
@@ -86,5 +177,8 @@ const outputObj = {}; | ||
return this.options.outputFormat(outputObj); | ||
return getHumanOutput(outputObj, Object.assign( | ||
{ verbose: this.options.outputFormat === "humanVerbose" }, | ||
this.options) | ||
return getHumanOutput( | ||
outputObj, | ||
Object.assign( | ||
{ verbose: this.options.outputFormat === "humanVerbose" }, | ||
this.options | ||
) | ||
); | ||
@@ -158,2 +252,5 @@ } | ||
if (this.options.compareLoadersBuild) | ||
this.generateLoadersBuildComparison(); | ||
this.timeEventData = {}; | ||
@@ -160,0 +257,0 @@ }); |
{ | ||
"name": "speed-measure-webpack-plugin", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"description": "Measure + analyse the speed of your webpack loaders and plugins", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,4 +8,6 @@ <div align="center"> | ||
<!-- 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:START --> | ||
<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-10-orange.svg" /></a> | ||
<!-- ALL-CONTRIBUTORS-BADGE:END --> | ||
@@ -137,2 +139,19 @@ | ||
### `options.compareLoadersBuild` | ||
Type: `Object`<br> | ||
Default: `{}` | ||
This option gives you a comparison over time of the module count and time spent, per loader. This option provides more data when `outputFormat: "humanVerbose"`. | ||
Given a required `filePath` to store the build information, this option allows you to compare differences to your codebase over time. E.g. | ||
```javascript | ||
const smp = new SpeedMeasurePlugin({ | ||
compareLoadersBuild: { | ||
filePath: "./buildInfo.json", | ||
}, | ||
}); | ||
``` | ||
### `options.granularLoaderData` _(experimental)_ | ||
@@ -180,3 +199,3 @@ | ||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> | ||
<!-- ALL-CONTRIBUTORS-LIST:START --> | ||
<!-- prettier-ignore-start --> | ||
@@ -196,2 +215,4 @@ <!-- markdownlint-disable --> | ||
<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> | ||
<td align="center"><a href="https://github.com/The-Only-Matrix"><img src="https://avatars.githubusercontent.com/u/61681157?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Suraj Patel</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=The-Only-Matrix" title="Code">π»</a></td> | ||
<td align="center"><a href="https://github.com/hanzooo"><img src="https://avatars.githubusercontent.com/u/16368939?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jm</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=hanzooo" title="Code">π»</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/issues?q=author%3Ahanzooo" title="Bug reports">π</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=hanzooo" title="Tests">β οΈ</a></td> | ||
</tr> | ||
@@ -205,2 +226,2 @@ </table> | ||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! | ||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! |
@@ -241,3 +241,8 @@ let idInc = 0; | ||
}); | ||
return ret; | ||
const funcProxy = new Proxy(ret, { | ||
get: (target, property) => { | ||
return raw[property]; | ||
}, | ||
}); | ||
return funcProxy; | ||
} | ||
@@ -244,0 +249,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
246829
1011
223