Skip to content

Commit

Permalink
Merge pull request #140 from zmj97/patch-1
Browse files Browse the repository at this point in the history
fix options test
  • Loading branch information
chrisblossom committed May 21, 2019
2 parents 11fe42f + 57d2cd4 commit 030dbaa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -109,7 +109,7 @@ new CleanWebpackPlugin({
//
// Use !negative patterns to exclude files
//
// default: disabled
// default: []
cleanAfterEveryBuildPatterns: ['static*.*', '!static1.js'],

// Allow clean patterns outside of process.cwd()
Expand Down
14 changes: 12 additions & 2 deletions src/clean-webpack-plugin.ts
Expand Up @@ -48,7 +48,7 @@ export interface Options {
*
* Use !negative patterns to exclude files
*
* default: disabled
* default: []
*/
cleanAfterEveryBuildPatterns?: string[];

Expand All @@ -62,6 +62,16 @@ export interface Options {
dangerouslyAllowCleanPatternsOutsideProject?: boolean;
}

// Copied from https://github.com/sindresorhus/is-plain-obj/blob/97480673cf12145b32ec2ee924980d66572e8a86/index.js
function isPlainObject(value: unknown): boolean {
if (Object.prototype.toString.call(value) !== '[object Object]') {
return false;
}

const prototype = Object.getPrototypeOf(value);
return prototype === null || prototype === Object.getPrototypeOf({});
}

class CleanWebpackPlugin {
private readonly dry: boolean;
private readonly verbose: boolean;
Expand All @@ -75,7 +85,7 @@ class CleanWebpackPlugin {
private outputPath: string;

constructor(options: Options = {}) {
if (typeof options !== 'object' || Array.isArray(options) === true) {
if (isPlainObject(options) === false) {
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

0 comments on commit 030dbaa

Please sign in to comment.