Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes whole project when outputpath is root #183

Open
thet opened this issue Sep 2, 2020 · 6 comments
Open

Removes whole project when outputpath is root #183

thet opened this issue Sep 2, 2020 · 6 comments

Comments

@thet
Copy link

thet commented Sep 2, 2020

Issue description or question

When using clean-webpack-plugin when webpacks output.path is the project root, everything is blindly deleted including the .git directory.
IMO it should only remove old build assets - I don't know if it's possible to find out which one are build assets and which one are not.

Webpack Config

The config is in webpack/base.config.js.

process.traceDeprecation = true;
const path = require('path');
const webpack = require('webpack');

// plugins
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = env => {
    return {
        entry: {
            "bundle": path.resolve(__dirname, "../src/init.js"),
        },
        output: {
            filename: "[name].js",
            path: path.resolve(__dirname, '../'),
        },
        },
        plugins: [
            new CleanWebpackPlugin(),
        ]
    };
};

Environment

  System:
    OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
    Memory: 6.36 GB / 23.39 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 12.16.3 - ~/.nvm/versions/node/v12.16.3/bin/node
    Yarn: 1.22.5 - /home/_thet/data/dev/syslab/REPOS/patternslib/Patterns-es6/node_modules/.bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v12.16.3/bin/npm
  npmPackages:
    clean-webpack-plugin: ^3.0.0 => 3.0.0 
    webpack: ^4.43.0 => 4.44.1 
@Sociosarbis
Copy link

What about use cleanOnceBeforeBuildPatterns option, and then you can only remove the files that match your defined patterns.

@alpadev
Copy link

alpadev commented Sep 4, 2020

To my understanding, the idea in general is it shouldn't be possible to delete the working directory and/or outside of it without setting dangerouslyAllowCleanPatternsOutsideProject to true. Though it looks like this isn't properly working depending on the folder structure and how webpack is run.

@thet would you mind adding some more details about that?

As far as I can tell your project looks something like this:

app
├── src
│   └── init.js
├── webpack
│   └── base.config.js
└── bundle.js

It would be nice to know the location of the package.json (or if there is more than one) and how you run webpack e.g. like npx webpack ... or using some npm script like npm run build.

Edit: the removal of the working directory is caused by del version being outdated - that is already fixed with #165 ...
You likely have to use cleanOnceBeforeBuildPatterns though as Sociosarbis mentioned e.g.

new CleanWebpackPlugin({
  cleanOnceBeforeBuildPatterns: ['bundle.js']
})

@ganeshrvel
Copy link

ganeshrvel commented Nov 1, 2020

this happened to me just now! luckily I had the backup of my project.

Please document this in the readme and warn users of such incidents

@strarsis
Copy link

strarsis commented Mar 5, 2021

Yes, this is very bad indeed. Even the .git folder was removed which meant that I lost everything since the last git push. That's very bad.

@ganeshrvel
Copy link

They should put a check for the root directory ASAP!

@eddjimlab
Copy link

It removes everything except webpack files !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants