New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

unused-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unused-webpack-plugin - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

59

index.js

@@ -13,29 +13,36 @@ const path = require('path');

UnusedPlugin.prototype.apply = function(compiler) {
compiler.hooks.emit.tapAsync(
'UnusedPlugin',
function(compilation, callback) {
// Files used by Webpack during compilation
const usedModules = Array.from(compilation.fileDependencies)
.filter(file =>
this.sourceDirectories.some(dir => file.indexOf(dir) !== -1)
)
.reduce((obj, item) => {
obj[item] = true;
return obj;
}, {});
// Go through sourceDirectories to find all source files
Promise.all(
this.sourceDirectories.map(directory =>
recursive(directory, this.exclude)
)
const checkUnused = (compilation, callback) => {
// Files used by Webpack during compilation
const usedModules = Array.from(compilation.fileDependencies)
.filter(file =>
this.sourceDirectories.some(dir => file.indexOf(dir) !== -1)
)
// Find unused source files
.then(files =>
files.map(array => array.filter(file => !usedModules[file]))
)
.then(display.bind(this))
.then(continueOrFail.bind(this, this.failOnUnused, compilation))
.then(callback);
}.bind(this)
);
.reduce((obj, item) => {
obj[item] = true;
return obj;
}, {});
// Go through sourceDirectories to find all source files
Promise.all(
this.sourceDirectories.map(directory =>
recursive(directory, this.exclude)
)
)
// Find unused source files
.then(files =>
files.map(array => array.filter(file => !usedModules[file]))
)
.then(display.bind(this))
.then(continueOrFail.bind(this, this.failOnUnused, compilation))
.then(callback);
}
// webpack 4
if (compiler.hooks && compiler.hooks.emit) {
compiler.hooks.emit.tapAsync(
'UnusedPlugin',
checkUnused
);
// webpack 3
} else {
compiler.plugin('emit', checkUnused)
}
};

@@ -42,0 +49,0 @@

{
"name": "unused-webpack-plugin",
"version": "2.0.0",
"version": "2.1.0",
"description": "A webpack plugin to find unused modules/source files",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc