Skip to content

Commit

Permalink
use **/* instead of ** and update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisblossom committed Mar 4, 2019
1 parent e19b19d commit d6e2e38
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 88 deletions.
106 changes: 45 additions & 61 deletions README.md
Expand Up @@ -48,79 +48,63 @@ module.exports = webpackConfig;

```js
new CleanWebpackPlugin({
/**
* Simulate the removal of files
*
* default: false
*/
// Simulate the removal of files
//
// default: false
dry: true,

/**
* Write Logs to Console
* (Always enabled when dry is true)
*
* default: false
*/
// Write Logs to Console
// (Always enabled when dry is true)
//
// default: false
verbose: true,

/**
* Automatically remove all unused webpack assets on rebuild
*
* default: true
*/
// Automatically remove all unused webpack assets on rebuild
//
// default: true
cleanStaleWebpackAssets: false,

/**
* Do not allow removal of current webpack assets
*
* default: true
*/
// Do not allow removal of current webpack assets
//
// default: true
protectWebpackAssets: false,

/**
* **WARNING**
*
* Notes for the below options:
*
* They are unsafe...so test initially with dry: true.
*
* Relative to webpack's output.path directory.
* If outside of webpack's output.path directory,
* use full path. path.join(process.cwd(), 'build/**')
*
* These options extend del's pattern matching API.
* See https://github.com/sindresorhus/del#patterns
* for pattern matching documentation
*/

/**
* Removes files once prior to Webpack compilation
* Not included in rebuilds (watch mode)
*
* Use !negative patterns to exclude files
*
* default: ['**']
*/
cleanOnceBeforeBuildPatterns: ['**', '!static-files*'],
// **WARNING**
//
// Notes for the below options:
//
// They are unsafe...so test initially with dry: true.
//
// Relative to webpack's output.path directory.
// If outside of webpack's output.path directory,
// use full path. path.join(process.cwd(), 'build/**/*')
//
// These options extend del's pattern matching API.
// See https://github.com/sindresorhus/del#patterns
// for pattern matching documentation

// Removes files once prior to Webpack compilation
// Not included in rebuilds (watch mode)
//
// Use !negative patterns to exclude files
//
// default: ['**/*']
cleanOnceBeforeBuildPatterns: ['**/*', '!static-files*'],
cleanOnceBeforeBuildPatterns: [], // disables cleanOnceBeforeBuildPatterns

/**
* Removes files after every build (including watch mode) that match this pattern.
* Used for files that are not created directly by Webpack.
*
* Use !negative patterns to exclude files
*
* default: disabled
*/
// Removes files after every build (including watch mode) that match this pattern.
// Used for files that are not created directly by Webpack.
//
// Use !negative patterns to exclude files
//
// default: disabled
cleanAfterEveryBuildPatterns: ['static*.*', '!static1.js'],

/**
* Allow clean patterns outside of process.cwd()
*
* requires dry option to be explicitly set
*
* default: false
*/
// Allow clean patterns outside of process.cwd()
//
// requires dry option to be explicitly set
//
// default: false
dangerouslyAllowCleanPatternsOutsideProject: true,
dry: true,
});
Expand Down
27 changes: 13 additions & 14 deletions package.json
Expand Up @@ -50,36 +50,35 @@
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.3.3",
"@babel/plugin-proposal-class-properties": "^7.3.3",
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-class-properties": "^7.3.4",
"@babel/plugin-transform-strict-mode": "^7.2.0",
"@babel/preset-env": "^7.3.1",
"@babel/preset-env": "^7.3.4",
"@babel/preset-typescript": "^7.3.3",
"@chrisblossom/eslint-config": "^4.0.9",
"@types/del": "^3.0.1",
"@types/jest": "^24.0.6",
"@types/node": "^11.9.4",
"@chrisblossom/eslint-config": "^4.0.10",
"@types/jest": "^24.0.9",
"@types/node": "^11.10.4",
"@types/read-pkg-up": "^3.0.1",
"@types/webpack": "^4.4.24",
"@types/webpack": "^4.4.25",
"babel-jest": "^24.1.0",
"babel-plugin-add-module-exports": "^1.0.0",
"codecov": "^3.2.0",
"cross-env": "^5.2.0",
"del-cli": "^1.1.0",
"eslint": "^5.14.1",
"eslint": "^5.15.0",
"execa": "^1.0.0",
"husky": "^1.3.1",
"jest": "^24.1.0",
"lint-staged": "^8.1.4",
"lint-staged": "^8.1.5",
"listr": "^0.14.3",
"prettier": "^1.16.4",
"read-pkg-up": "^4.0.0",
"semver": "^5.6.0",
"temp-sandbox": "^1.0.16",
"typescript": "^3.3.3",
"webpack": "^4.29.5"
"temp-sandbox": "^1.0.17",
"typescript": "^3.3.3333",
"webpack": "^4.29.6"
},
"dependencies": {
"del": "^3.0.0"
"del": "^4.0.0"
}
}
24 changes: 16 additions & 8 deletions src/clean-webpack-plugin.test.ts
Expand Up @@ -593,7 +593,7 @@ describe('cleanOnceBeforeBuildPatterns option', () => {
]);

const cleanWebpackPlugin = new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['**'],
cleanOnceBeforeBuildPatterns: ['**/*'],
});

const compiler = webpack({
Expand Down Expand Up @@ -691,7 +691,7 @@ describe('cleanOnceBeforeBuildPatterns option', () => {
]);

const cleanWebpackPlugin = new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['**', '!static2.*'],
cleanOnceBeforeBuildPatterns: ['**/*', '!static2.*'],
});

const compiler = webpack({
Expand Down Expand Up @@ -739,7 +739,9 @@ describe('cleanOnceBeforeBuildPatterns option', () => {
expect(initialOutsideFiles).toEqual(['outside-file.js']);

const cleanWebpackPlugin = new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [path.join(sandbox.dir, 'build/**')],
cleanOnceBeforeBuildPatterns: [
path.join(sandbox.dir, 'build/**/*'),
],
});

const compiler = webpack({
Expand Down Expand Up @@ -862,7 +864,9 @@ describe('cleanAfterEveryBuildPatterns option', () => {
expect(initialOutsideFiles).toEqual(['outside-file.js']);

const cleanWebpackPlugin = new CleanWebpackPlugin({
cleanAfterEveryBuildPatterns: [path.join(sandbox.dir, 'build/**')],
cleanAfterEveryBuildPatterns: [
path.join(sandbox.dir, 'build/**/*'),
],
});

const compiler = webpack({
Expand Down Expand Up @@ -894,7 +898,9 @@ describe('dangerouslyAllowCleanPatternsOutsideProject option', () => {

const cleanWebpackPlugin = new CleanWebpackPlugin({
// Use cleanOnceBeforeBuildPatterns because webpack 2/3 doesn't handle errors in done lifecycle correctly
cleanOnceBeforeBuildPatterns: [path.join(sandbox.dir, 'build/**')],
cleanOnceBeforeBuildPatterns: [
path.join(sandbox.dir, 'build/**/*'),
],
});

const compiler = webpack({
Expand Down Expand Up @@ -925,7 +931,9 @@ describe('dangerouslyAllowCleanPatternsOutsideProject option', () => {
const cleanWebpackPlugin = new CleanWebpackPlugin({
dangerouslyAllowCleanPatternsOutsideProject: true,
dry: false,
cleanAfterEveryBuildPatterns: [path.join(sandbox.dir, 'build/**')],
cleanAfterEveryBuildPatterns: [
path.join(sandbox.dir, 'build/**/*'),
],
});

expect(consoleSpy.mock.calls).toEqual([]);
Expand Down Expand Up @@ -1199,15 +1207,15 @@ describe('detect old options', () => {
test('throws if options is a string', () => {
expect(() => CleanWebpackPlugin('dist'))
.toThrowErrorMatchingInlineSnapshot(`
"clean-webpack-plugin only accepts an options object. See:
"clean-webpack-plugin only accepts an options object. See:
https://github.com/johnagan/clean-webpack-plugin#options-and-defaults-optional"
`);
});

test('throws if options is an array', () => {
expect(() => CleanWebpackPlugin(['dist']))
.toThrowErrorMatchingInlineSnapshot(`
"clean-webpack-plugin only accepts an options object. See:
"clean-webpack-plugin only accepts an options object. See:
https://github.com/johnagan/clean-webpack-plugin#options-and-defaults-optional"
`);
});
Expand Down
10 changes: 5 additions & 5 deletions src/clean-webpack-plugin.ts
@@ -1,6 +1,6 @@
import { Compiler, Stats } from 'webpack';
import path from 'path';
import del from 'del';
import { sync as delSync } from 'del';

interface Options {
/**
Expand Down Expand Up @@ -38,7 +38,7 @@ interface Options {
*
* Use !negative patterns to exclude files
*
* default: ['**']
* default: ['**\/*']
*/
cleanOnceBeforeBuildPatterns: string[];

Expand Down Expand Up @@ -76,7 +76,7 @@ class CleanWebpackPlugin {

constructor(options: Partial<Options> = {}) {
if (typeof options !== 'object' || Array.isArray(options) === true) {
throw new Error(`clean-webpack-plugin only accepts an options object. See:
throw new Error(`clean-webpack-plugin only accepts an options object. See:
https://github.com/johnagan/clean-webpack-plugin#options-and-defaults-optional`);
}

Expand Down Expand Up @@ -132,7 +132,7 @@ class CleanWebpackPlugin {
options.cleanOnceBeforeBuildPatterns,
)
? options.cleanOnceBeforeBuildPatterns
: ['**'];
: ['**/*'];

/**
* Store webpack build assets
Expand Down Expand Up @@ -266,7 +266,7 @@ class CleanWebpackPlugin {

removeFiles(patterns: string[]) {
try {
const deleted = del.sync(patterns, {
const deleted = delSync(patterns, {
force: this.dangerouslyAllowCleanPatternsOutsideProject,
// Change context to build directory
cwd: this.outputPath,
Expand Down

0 comments on commit d6e2e38

Please sign in to comment.