(fix): pr comments

This commit is contained in:
Sergey Melyukov 2020-10-07 15:30:14 +03:00
parent d35cf1e056
commit ee0c891c67
9 changed files with 74 additions and 105 deletions

View File

@ -423,6 +423,21 @@ export type ChunkLoadTimeout = number;
* The global variable used by webpack for loading of chunks.
*/
export type ChunkLoadingGlobal = string;
/**
* Clean the output directory before emit.
*/
export type CleanPlugin =
| boolean
| {
/**
* Log the assets that should be removed instead of delete them.
*/
dry?: boolean;
/**
* Not delete the assets, that matches to this regexp or a function.
*/
ignore?: RegExp | ((asset: string) => boolean);
};
/**
* Check if to be emitted file already exists and have the same content before writing to output filesystem.
*/
@ -1735,7 +1750,7 @@ export interface Output {
/**
* Clean the output directory before emit.
*/
clean?: boolean | CleanPlugin;
clean?: CleanPlugin;
/**
* Check if to be emitted file already exists and have the same content before writing to output filesystem.
*/
@ -1889,23 +1904,6 @@ export interface Output {
*/
workerWasmLoading?: WasmLoading;
}
/**
* Clean the output directory before emit.
*/
export interface CleanPlugin {
/**
* Log the assets that should be removed instead of delete them.
*/
dry?: boolean;
/**
* Is clean enabled.
*/
enabled?: boolean;
/**
* Not delete the assets, that matches to this regexp or a function.
*/
ignore?: RegExp | ((asset: string) => boolean);
}
/**
* The abilities of the environment where the webpack generated code should run.
*/

View File

@ -9,10 +9,6 @@ export interface CleanPluginArgument {
* Log the assets that should be removed instead of delete them.
*/
dry?: boolean;
/**
* Is clean enabled.
*/
enabled?: boolean;
/**
* Not delete the assets, that matches to this regexp or a function.
*/

View File

@ -63,8 +63,8 @@ class CleanPlugin {
}
/** @param {CleanPluginArgument} [options] options */
constructor(options) {
this.options = Object.assign({ enabled: true, dry: false }, options || {});
constructor(options = {}) {
this.options = { dry: false, ...options };
if (options && typeof options === "object") {
validate(schema, options, {
@ -174,7 +174,7 @@ class CleanPlugin {
if (this.ignoreList.some(ignore => checkToIgnore(ignore, child))) {
if (this.options.dry) {
this.logger.info(`[${child}] was ignored`);
this.logger.info(`[${child}] will be ignored in non-dry mode`);
}
return callback();
@ -188,7 +188,9 @@ class CleanPlugin {
if (stat.isFile()) {
if (this.fsState.files.has(child)) {
if (this.options.dry) {
this.logger.info(`[${child}] was ignored`);
this.logger.info(
`[${child}] will be ignored in non-dry mode`
);
}
return callback();

View File

@ -168,7 +168,9 @@ class WebpackOptionsApply extends OptionsApply {
if (options.output.clean) {
const CleanPlugin = require("./CleanPlugin");
new CleanPlugin(options.output.clean).apply(compiler);
new CleanPlugin(
options.output.clean === true ? {} : options.output.clean
).apply(compiler);
}
if (options.devtool) {

View File

@ -251,10 +251,7 @@ const getNormalizedWebpackOptions = config => {
chunkLoading: output.chunkLoading,
chunkLoadingGlobal: output.chunkLoadingGlobal,
chunkLoadTimeout: output.chunkLoadTimeout,
clean:
typeof output.clean === "boolean"
? { enabled: output.clean }
: output.clean,
clean: output.clean,
compareBeforeEmit: output.compareBeforeEmit,
crossOriginLoading: output.crossOriginLoading,
devtoolFallbackModuleFilenameTemplate:

View File

@ -130,6 +130,11 @@
},
"CleanPlugin": {
"description": "Clean the output directory before emit.",
"anyOf": [
{
"type": "boolean"
},
{
"type": "object",
"additionalProperties": false,
"properties": {
@ -137,10 +142,6 @@
"description": "Log the assets that should be removed instead of delete them.",
"type": "boolean"
},
"enabled": {
"description": "Is clean enabled.",
"type": "boolean"
},
"ignore": {
"description": "Not delete the assets, that matches to this regexp or a function.",
"anyOf": [
@ -155,6 +156,8 @@
]
}
}
}
]
},
"CompareBeforeEmit": {
"description": "Check if to be emitted file already exists and have the same content before writing to output filesystem.",
@ -1908,15 +1911,7 @@
"$ref": "#/definitions/ChunkLoadingGlobal"
},
"clean": {
"description": "Clean the output directory before emit.",
"anyOf": [
{
"type": "boolean"
},
{
"$ref": "#/definitions/CleanPlugin"
}
]
},
"compareBeforeEmit": {
"$ref": "#/definitions/CompareBeforeEmit"

View File

@ -7,10 +7,6 @@
"description": "Log the assets that should be removed instead of delete them.",
"type": "boolean"
},
"enabled": {
"description": "Is clean enabled.",
"type": "boolean"
},
"ignore": {
"description": "Not delete the assets, that matches to this regexp or a function.",
"anyOf": [

View File

@ -2133,19 +2133,6 @@ Object {
"multiple": false,
"simpleType": "boolean",
},
"output-clean-enabled": Object {
"configs": Array [
Object {
"description": "Is clean enabled.",
"multiple": false,
"path": "output.clean.enabled",
"type": "boolean",
},
],
"description": "Is clean enabled.",
"multiple": false,
"simpleType": "boolean",
},
"output-clean-ignore": Object {
"configs": Array [
Object {

36
types.d.ts vendored
View File

@ -1002,19 +1002,23 @@ declare interface CleanPluginArgument {
*/
dry?: boolean;
/**
* Is clean enabled.
*/
enabled?: boolean;
/**
* Not delete the assets, that matches to this regexp or a function.
*/
ignore?: RegExp | ((asset: string) => boolean);
}
declare class CleanPluginClass {
constructor(options: CleanPluginArgument);
options: { enabled: boolean; dry: boolean } & CleanPluginArgument;
constructor(options?: CleanPluginArgument);
options: {
/**
* Log the assets that should be removed instead of delete them.
*/
dry: boolean;
/**
* Not delete the assets, that matches to this regexp or a function.
*/
ignore?: RegExp | ((asset: string) => boolean);
};
ignoreList: (RegExp | ((arg0: string) => boolean))[];
logger: WebpackLogger;
fs: OutputFileSystem;
@ -1035,26 +1039,18 @@ declare interface CleanPluginCompilationHooks {
void
>;
}
/**
* Clean the output directory before emit.
*/
declare interface CleanPluginWebpackOptions {
type CleanPluginWebpackOptions =
| boolean
| {
/**
* Log the assets that should be removed instead of delete them.
*/
dry?: boolean;
/**
* Is clean enabled.
*/
enabled?: boolean;
/**
* Not delete the assets, that matches to this regexp or a function.
*/
ignore?: RegExp | ((asset: string) => boolean);
}
};
declare interface CodeGenerationContext {
/**
* the dependency templates
@ -6153,7 +6149,7 @@ declare interface Output {
/**
* Clean the output directory before emit.
*/
clean?: boolean | CleanPluginWebpackOptions;
clean?: CleanPluginWebpackOptions;
/**
* Check if to be emitted file already exists and have the same content before writing to output filesystem.