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

webpack-clean

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-clean - npm Package Compare versions

Comparing version

to
1.2.3

yarn-error.log

28

index.js

@@ -13,2 +13,6 @@ /**

const INFO = 'info';
const WARN = 'warn';
const ERROR = 'error';
function log (type, msg) {

@@ -30,3 +34,3 @@ logger[type](`${pluginName} - ${msg}`);

function addMapExtension (file) {
return file + '.map';
return `${file}.map`;
};

@@ -49,3 +53,3 @@

} else {
log('info', 'removed ' + file);
log(INFO, `removed ${file}`);
resolve(self.pluginName, 'file removed:', file);

@@ -65,3 +69,3 @@ }

} else {
log('warn', 'file ' + filePath + ' does not exist');
log(WARN, `file ${filePath} does not exist`);
}

@@ -96,3 +100,3 @@ })

.then(removalPromises => Promise.all(removalPromises))
.then(() => { log('info', 'DONE'); })
.then(() => { log(INFO, 'DONE'); })
.catch(err => throwErr(pluginName, err));

@@ -102,6 +106,7 @@ }

// allow the options object to be omitted in the constructor function
function WebpackClean (files, {basePath = null, removeMaps = false} = {}) {
function WebpackClean (files, {basePath = null, removeMaps = false, forceDelete = false} = {}) {
this.files = getFileList(files);
this.context = getContext(basePath); // get webpack roots
this.removeMaps = removeMaps;
this.forceDelete = forceDelete;
}

@@ -112,5 +117,11 @@

const hasLifecycleHooks = compiler.hasOwnProperty('hooks'); // Webpack 4.x.x
const logErrMsg = 'Files removal aborted due to:';
if (hasLifecycleHooks) {
compiler.hooks.failed.tap(pluginName, err => throwErr(pluginName, err));
compiler.hooks.failed.tap(pluginName, err => {
if (!self.forceDelete) {
log(ERROR, `${logErrMsg} \n${err}`);
return false;
}
});
compiler.hooks.done.tap(pluginName, stats => {

@@ -121,4 +132,5 @@ doRemove.call(self);

compiler.plugin('done', stats => {
if (stats.compilation.errors && stats.compilation.errors.length > 0) {
throwErr(pluginName, stats.compilation.errors);
if (!self.forceDelete && stats.compilation.errors && stats.compilation.errors.length > 0) {
log(ERROR, `${logErrMsg} \n${stats.compilation.errors}`);
return false;
}

@@ -125,0 +137,0 @@ doRemove.call(self);

{
"name": "webpack-clean",
"version": "1.2.2",
"version": "1.2.3",
"description": "A webpack plugin to clean specified files after build",

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

@@ -38,4 +38,5 @@ [![GitHub stars](https://img.shields.io/github/stars/allexcd/webpack-clean.svg?style=flat-square)](https://github.com/allexcd/webpack-clean/stargazers)

* `files` - array of files or string for a single file relative to the `basePath` or to the `context` of your config (if the `basePath` param is not specified),
* `basePath` (optional) - directory to be resolved to
* `removeMaps` (optional) - specify if the `.map` files should be automatically removed
* `basePath` (optional) - string - directory to be resolved to
* `removeMaps` (optional) - boolean - specify if the `.map` files should be automatically removed. Disabled by default.
* `forceDelete` (optional) - boolean - specify if the files should be force deleted in case of compile errors. If `forceDelete` is not enabled, the compile errors will be logged to `stdout` but the deletion of the files will not take place. Disabled by default.

@@ -88,2 +89,11 @@ ### Usage

};
module.exports = {
plugins: [
new WebpackCleanPlugin([
'fileA.js',
'fileB.js'
], {basePath: path.join(__dirname, 'dist'), removeMaps: true, forceDelete: true)}
]
};
```