[79a0317] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | const WEBPACK_PACKAGE = process.env.WEBPACK_PACKAGE || "webpack";
|
---|
| 4 | class ConfigTestCommand {
|
---|
| 5 | async apply(cli) {
|
---|
| 6 | await cli.makeCommand({
|
---|
| 7 | name: "configtest [config-path]",
|
---|
| 8 | alias: "t",
|
---|
| 9 | description: "Validate a webpack configuration.",
|
---|
| 10 | pkg: "@webpack-cli/configtest",
|
---|
| 11 | dependencies: [WEBPACK_PACKAGE],
|
---|
| 12 | }, [], async (configPath) => {
|
---|
| 13 | cli.webpack = await cli.loadWebpack();
|
---|
| 14 | const config = await cli.loadConfig(configPath ? { config: [configPath] } : {});
|
---|
| 15 | const configPaths = new Set();
|
---|
| 16 | if (Array.isArray(config.options)) {
|
---|
| 17 | config.options.forEach((options) => {
|
---|
| 18 | const loadedConfigPaths = config.path.get(options);
|
---|
| 19 | if (loadedConfigPaths) {
|
---|
| 20 | loadedConfigPaths.forEach((path) => configPaths.add(path));
|
---|
| 21 | }
|
---|
| 22 | });
|
---|
| 23 | }
|
---|
| 24 | else {
|
---|
| 25 | if (config.path.get(config.options)) {
|
---|
| 26 | const loadedConfigPaths = config.path.get(config.options);
|
---|
| 27 | if (loadedConfigPaths) {
|
---|
| 28 | loadedConfigPaths.forEach((path) => configPaths.add(path));
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 | if (configPaths.size === 0) {
|
---|
| 33 | cli.logger.error("No configuration found.");
|
---|
| 34 | process.exit(2);
|
---|
| 35 | }
|
---|
| 36 | cli.logger.info(`Validate '${Array.from(configPaths).join(" ,")}'.`);
|
---|
| 37 | try {
|
---|
| 38 | cli.webpack.validate(config.options);
|
---|
| 39 | }
|
---|
| 40 | catch (error) {
|
---|
| 41 | if (cli.isValidationError(error)) {
|
---|
| 42 | cli.logger.error(error.message);
|
---|
| 43 | }
|
---|
| 44 | else {
|
---|
| 45 | cli.logger.error(error);
|
---|
| 46 | }
|
---|
| 47 | process.exit(2);
|
---|
| 48 | }
|
---|
| 49 | cli.logger.success("There are no validation errors in the given webpack configuration.");
|
---|
| 50 | });
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 | exports.default = ConfigTestCommand;
|
---|