@webpack-cli/configtest
Advanced tools
Comparing version
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const WEBPACK_PACKAGE = process.env.WEBPACK_PACKAGE || "webpack"; | ||
class ConfigTestCommand { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any | ||
async apply(cli) { | ||
const { logger, webpack } = cli; | ||
await cli.makeCommand({ | ||
@@ -12,4 +12,6 @@ name: "configtest [config-path]", | ||
pkg: "@webpack-cli/configtest", | ||
dependencies: [WEBPACK_PACKAGE], | ||
}, [], async (configPath) => { | ||
const config = await cli.resolveConfig(configPath ? { config: [configPath] } : {}); | ||
cli.webpack = await cli.loadWebpack(); | ||
const config = await cli.loadConfig(configPath ? { config: [configPath] } : {}); | ||
const configPaths = new Set(); | ||
@@ -29,12 +31,12 @@ if (Array.isArray(config.options)) { | ||
if (configPaths.size === 0) { | ||
logger.error("No configuration found."); | ||
cli.logger.error("No configuration found."); | ||
process.exit(2); | ||
} | ||
logger.info(`Validate '${Array.from(configPaths).join(" ,")}'.`); | ||
cli.logger.info(`Validate '${Array.from(configPaths).join(" ,")}'.`); | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const error = webpack.validate(config.options); | ||
const error = cli.webpack.validate(config.options); | ||
// TODO remove this after drop webpack@4 | ||
if (error && error.length > 0) { | ||
throw new webpack.WebpackOptionsValidationError(error); | ||
throw new cli.webpack.WebpackOptionsValidationError(error); | ||
} | ||
@@ -44,10 +46,10 @@ } | ||
if (cli.isValidationError(error)) { | ||
logger.error(error.message); | ||
cli.logger.error(error.message); | ||
} | ||
else { | ||
logger.error(error); | ||
cli.logger.error(error); | ||
} | ||
process.exit(2); | ||
} | ||
logger.success("There are no validation errors in the given webpack configuration."); | ||
cli.logger.success("There are no validation errors in the given webpack configuration."); | ||
}); | ||
@@ -54,0 +56,0 @@ } |
{ | ||
"name": "@webpack-cli/configtest", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "Validate a webpack configuration.", | ||
@@ -22,4 +22,3 @@ "main": "lib/index.js", | ||
"webpack-cli": "4.x.x" | ||
}, | ||
"gitHead": "2be9b9254009598e021b830091fba8832dfdb57b" | ||
} | ||
} |
59
3.51%3401
-22.39%4
-20%