diff --git a/README.md b/README.md index 51b8a21..827749d 100644 --- a/README.md +++ b/README.md @@ -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() diff --git a/src/clean-webpack-plugin.ts b/src/clean-webpack-plugin.ts index 7942986..b13f1f8 100644 --- a/src/clean-webpack-plugin.ts +++ b/src/clean-webpack-plugin.ts @@ -48,7 +48,7 @@ export interface Options { * * Use !negative patterns to exclude files * - * default: disabled + * default: [] */ cleanAfterEveryBuildPatterns?: string[]; @@ -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; @@ -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`); }