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

fix options test #140

Merged
merged 2 commits into from May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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