@@ -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 )
0 commit comments