@perfsee/webpack
Advanced tools
Comparing version 1.12.2 to 1.13.0
@@ -16,4 +16,6 @@ import { WebpackPluginInstance, Compiler } from 'webpack'; | ||
apply: (compiler: Compiler) => void; | ||
private parseModuleSource; | ||
private readonly collectModuleSources; | ||
private readonly handleEmit; | ||
private readonly afterEmit; | ||
} |
@@ -78,2 +78,11 @@ "use strict"; | ||
}; | ||
this.collectModuleSources = (compilation) => { | ||
try { | ||
const reasonsMap = bundle_analyzer_1.StatsParser.FromStats(this.stats, this.outputPath).parseReasons(); | ||
compilation.modules.forEach((module) => this.parseModuleSource(module, reasonsMap)); | ||
} | ||
catch (e) { | ||
console.error(chalk_1.default.red(`Collect module sources failed, due to: ${e.message}`)); | ||
} | ||
}; | ||
this.handleEmit = (compilation) => { | ||
@@ -85,2 +94,3 @@ if (!this.outputPath) { | ||
this.setStats(compilation.getStats()); | ||
this.collectModuleSources(compilation); | ||
} | ||
@@ -125,2 +135,40 @@ catch (e) { | ||
} | ||
parseModuleSource(module, reasonsMap) { | ||
var _a; | ||
// @ts-expect-error | ||
module.modules?.forEach((module) => this.parseModuleSource(module, reasonsMap)); | ||
const source = module.originalSource()?.source(); | ||
if (!source) { | ||
return; | ||
} | ||
const id = (0, bundle_analyzer_1.hashCode)(module.identifier()); | ||
if (source instanceof Buffer || !source || !id) { | ||
return; | ||
} | ||
const reasons = reasonsMap.get(id); | ||
if (!reasons?.length) { | ||
return; | ||
} | ||
const lines = reasons | ||
.map((r) => r[1]?.split(':')[0]) | ||
.filter(Boolean) | ||
.map((l) => Number(l) - 1); | ||
const sourceFiltered = source | ||
.split('\n') | ||
.map((lineSource, lineNum) => { | ||
if (lines.some((l) => Math.abs(l - lineNum) <= 1)) { | ||
return lineSource || ' '; | ||
} | ||
return ''; | ||
}) | ||
.join('\n'); | ||
const path = module.nameForCondition(); | ||
(_a = this.stats).moduleReasons || (_a.moduleReasons = { | ||
moduleSource: {}, | ||
}); | ||
this.stats.moduleReasons.moduleSource[id] = [ | ||
path ? (0, path_1.relative)(this.stats.buildPath, path) : 'unkown', | ||
sourceFiltered, | ||
]; | ||
} | ||
} | ||
@@ -127,0 +175,0 @@ exports.PerfseePlugin = PerfseePlugin; |
{ | ||
"name": "@perfsee/webpack", | ||
"version": "1.12.2", | ||
"version": "1.13.0", | ||
"description": "perfsee webpack plugin", | ||
@@ -22,4 +22,4 @@ "repository": "https://github.com/perfsee/perfsee", | ||
"dependencies": { | ||
"@perfsee/bundle-analyzer": "1.10.0", | ||
"@perfsee/plugin-utils": "1.12.2", | ||
"@perfsee/bundle-analyzer": "1.13.0", | ||
"@perfsee/plugin-utils": "1.13.0", | ||
"chalk": "^4.1.2", | ||
@@ -32,3 +32,3 @@ "tslib": "^2.4.0" | ||
"devDependencies": { | ||
"@perfsee/package": "1.12.2" | ||
"@perfsee/package": "1.13.0" | ||
}, | ||
@@ -38,3 +38,3 @@ "scripts": { | ||
}, | ||
"gitHead": "555355c0878dea8cc5859fbe591052f438931f08" | ||
"gitHead": "aeadc065a44054a87b72ae35f794046c27008433" | ||
} |
@@ -108,3 +108,26 @@ # `@perfsee/webpack` | ||
} | ||
/** | ||
* Used to modify the webpack stats file prcessed by perfsee plugin before uploading. | ||
* | ||
* Return undefined means skipping uploading. | ||
*/ | ||
processStats?: (stats: PerfseeReportStats) => undefined | PerfseeReportStats | ||
/** | ||
* Rules(audits) apply to this artifact | ||
* | ||
* Notice: Functions only works in local testing (when `enableAudit` is set to true). | ||
* | ||
* @default ['default'] | ||
*/ | ||
rules?: (string | Audit)[] | ||
/** | ||
* Whether to include auxiliary files to the bundle result. | ||
* | ||
* @default false | ||
*/ | ||
includeAuxiliary?: boolean | ||
} | ||
``` |
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
30036
190
133
+ Added@perfsee/bundle-analyzer@1.13.0(transitive)
+ Added@perfsee/jsonr@1.13.0(transitive)
+ Added@perfsee/plugin-utils@1.13.0(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbl@4.1.0(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedchownr@1.1.4(transitive)
+ Addeddecompress-response@6.0.0(transitive)
+ Addeddeep-extend@0.6.0(transitive)
+ Addeddetect-libc@2.0.3(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexpand-template@2.0.3(transitive)
+ Addedfs-constants@1.0.0(transitive)
+ Addedgithub-from-package@0.0.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedini@1.3.8(transitive)
+ Addedisolated-vm@4.7.2(transitive)
+ Addedmimic-response@3.1.0(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp-classic@0.5.3(transitive)
+ Addednapi-build-utils@1.0.2(transitive)
+ Addednode-abi@3.67.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedprebuild-install@7.1.2(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedrc@1.2.8(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@4.0.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedstrip-json-comments@2.0.1(transitive)
+ Addedtar-fs@2.1.1(transitive)
+ Addedtar-stream@2.2.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removed@perfsee/bundle-analyzer@1.10.0(transitive)
- Removed@perfsee/jsonr@1.10.01.12.2(transitive)
- Removed@perfsee/plugin-utils@1.12.2(transitive)
Updated@perfsee/plugin-utils@1.13.0