Skip to content

Commit 059d608

Browse files
refactor: move configtest into core (#4654)
1 parent ab0545e commit 059d608

9 files changed

Lines changed: 50 additions & 245 deletions

File tree

packages/configtest/CHANGELOG.md

Lines changed: 0 additions & 79 deletions
This file was deleted.

packages/configtest/README.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/configtest/package.json

Lines changed: 0 additions & 26 deletions
This file was deleted.

packages/configtest/src/index.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

packages/configtest/tsconfig.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/webpack-cli/src/webpack-cli.ts

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,10 +1175,10 @@ class WebpackCLI implements IWebpackCLI {
11751175
},
11761176
configtest: {
11771177
rawName: "configtest",
1178-
external: true,
11791178
name: "configtest [config-path]",
11801179
alias: "t",
1181-
pkg: "@webpack-cli/configtest",
1180+
description: "Validate a webpack configuration.",
1181+
dependencies: [WEBPACK_PACKAGE],
11821182
},
11831183
};
11841184

@@ -1234,7 +1234,6 @@ class WebpackCLI implements IWebpackCLI {
12341234
// Stub for the `help` command
12351235
});
12361236
} else if (this.#isCommand(commandName, WebpackCLI.#commands.version)) {
1237-
// Stub for the `version` command
12381237
this.makeCommand(
12391238
WebpackCLI.#commands.version,
12401239
this.getInfoOptions(),
@@ -1244,6 +1243,54 @@ class WebpackCLI implements IWebpackCLI {
12441243
this.logger.raw(info);
12451244
},
12461245
);
1246+
} else if (this.#isCommand(commandName, WebpackCLI.#commands.configtest)) {
1247+
this.makeCommand(
1248+
WebpackCLI.#commands.configtest,
1249+
[],
1250+
async (configPath: string | undefined) => {
1251+
this.webpack = await this.loadWebpack();
1252+
1253+
const config = await this.loadConfig(configPath ? { config: [configPath] } : {});
1254+
const configPaths = new Set<string>();
1255+
1256+
if (Array.isArray(config.options)) {
1257+
for (const options of config.options) {
1258+
const loadedConfigPaths = config.path.get(options);
1259+
1260+
if (loadedConfigPaths) {
1261+
for (const path of loadedConfigPaths) configPaths.add(path);
1262+
}
1263+
}
1264+
} else if (config.path.get(config.options)) {
1265+
const loadedConfigPaths = config.path.get(config.options);
1266+
1267+
if (loadedConfigPaths) {
1268+
for (const path of loadedConfigPaths) configPaths.add(path);
1269+
}
1270+
}
1271+
1272+
if (configPaths.size === 0) {
1273+
this.logger.error("No configuration found.");
1274+
process.exit(2);
1275+
}
1276+
1277+
this.logger.info(`Validate '${[...configPaths].join(" ,")}'.`);
1278+
1279+
try {
1280+
this.webpack.validate(config.options);
1281+
} catch (error) {
1282+
if (this.isValidationError(error as Error)) {
1283+
this.logger.error((error as Error).message);
1284+
} else {
1285+
this.logger.error(error);
1286+
}
1287+
1288+
process.exit(2);
1289+
}
1290+
1291+
this.logger.success("There are no validation errors in the given webpack configuration.");
1292+
},
1293+
);
12471294
} else {
12481295
const builtInExternalCommandInfo = Object.values(WebpackCLI.#commands)
12491296
.filter((item) => item.external)

smoketests/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const tests = [
44
require("./missing-packages/webpack-bundle-analyzer.test"),
55
require("./missing-command-packages/serve.test"),
66
require("./missing-command-packages/info.test"),
7-
require("./missing-command-packages/configtest.test"),
87
];
98

109
// eslint-disable-next-line unicorn/prefer-top-level-await

smoketests/missing-command-packages/configtest.test.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

tsconfig.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
"declaration": true
2222
},
2323
"references": [
24-
{
25-
"path": "packages/configtest"
26-
},
2724
{
2825
"path": "packages/info"
2926
},

0 commit comments

Comments
 (0)