Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d141479
commit 41868ba
Showing
1 changed file
with
61 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,65 @@ | ||
class ConfigTestCommand { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any | ||
async apply(cli: any): Promise<void> { | ||
await cli.makeCommand( | ||
{ | ||
name: "configtest [config-path]", | ||
alias: "t", | ||
description: "Validate a webpack configuration.", | ||
pkg: "@webpack-cli/configtest", | ||
dependencies: ["webpack"], | ||
}, | ||
[], | ||
async (configPath: string | undefined): Promise<void> => { | ||
const config = await cli.resolveConfig(configPath ? { config: [configPath] } : {}); | ||
const configPaths = new Set<string>(); | ||
|
||
if (Array.isArray(config.options)) { | ||
config.options.forEach((options) => { | ||
if (config.path.get(options)) { | ||
configPaths.add(config.path.get(options)); | ||
} | ||
}); | ||
} else { | ||
if (config.path.get(config.options)) { | ||
configPaths.add(config.path.get(config.options)); | ||
} | ||
} | ||
|
||
if (configPaths.size === 0) { | ||
cli.logger.error("No configuration found."); | ||
process.exit(2); | ||
} | ||
|
||
cli.logger.info(`Validate '${Array.from(configPaths).join(" ,")}'.`); | ||
|
||
const webpack = await cli.loadWebpack(); | ||
|
||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const error: any = webpack.validate(config.options); | ||
|
||
// TODO remove this after drop webpack@4 | ||
if (error && error.length > 0) { | ||
throw new webpack.WebpackOptionsValidationError(error); | ||
} | ||
} catch (error) { | ||
if (cli.isValidationError(error)) { | ||
cli.logger.error(error.message); | ||
} else { | ||
cli.logger.error(error); | ||
} | ||
|
||
process.exit(2); | ||
} | ||
|
||
cli.logger.success("There are no validation errors in the given webpack configuration."); | ||
}, | ||
); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any | ||
async apply(cli: any): Promise<void> { | ||
await cli.makeCommand( | ||
{ | ||
name: "configtest [config-path]", | ||
alias: "t", | ||
description: "Validate a webpack configuration.", | ||
pkg: "@webpack-cli/configtest", | ||
dependencies: ["webpack"], | ||
}, | ||
[], | ||
async (configPath: string | undefined): Promise<void> => { | ||
cli.webpack = await cli.loadWebpack(); | ||
|
||
const config = await cli.resolveConfig(configPath ? { config: [configPath] } : {}); | ||
const configPaths = new Set<string>(); | ||
|
||
if (Array.isArray(config.options)) { | ||
config.options.forEach((options) => { | ||
if (config.path.get(options)) { | ||
configPaths.add(config.path.get(options)); | ||
} | ||
}); | ||
} else { | ||
if (config.path.get(config.options)) { | ||
configPaths.add(config.path.get(config.options)); | ||
} | ||
} | ||
|
||
if (configPaths.size === 0) { | ||
cli.logger.error("No configuration found."); | ||
process.exit(2); | ||
} | ||
|
||
cli.logger.info(`Validate '${Array.from(configPaths).join(" ,")}'.`); | ||
|
||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const error: any = cli.webpack.validate(config.options); | ||
|
||
// TODO remove this after drop webpack@4 | ||
if (error && error.length > 0) { | ||
throw new cli.webpack.WebpackOptionsValidationError(error); | ||
} | ||
} catch (error) { | ||
if (error instanceof cli.webpack.ValidationError || | ||
error.name === "ValidationError") { | ||
cli.logger.error(error.message); | ||
} else { | ||
cli.logger.error(error); | ||
} | ||
|
||
process.exit(2); | ||
} | ||
|
||
cli.logger.success( | ||
"There are no validation errors in the given webpack configuration.", | ||
); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
export default ConfigTestCommand; |