@@ -55,9 +55,7 @@ const fs = require("fs");
5555const  path  =  require ( "path" ) ; 
5656const  {  pathToFileURL }  =  require ( "url" ) ; 
5757const  util  =  require ( "util" ) ; 
58- 
5958const  {  program,  Option }  =  require ( "commander" ) ; 
60- const  envinfo  =  require ( "envinfo" ) ; 
6159
6260const  WEBPACK_PACKAGE  =  process . env . WEBPACK_PACKAGE  ||  "webpack" ; 
6361const  WEBPACK_DEV_SERVER_PACKAGE  =  process . env . WEBPACK_DEV_SERVER_PACKAGE  ||  "webpack-dev-server" ; 
@@ -449,6 +447,8 @@ class WebpackCLI implements IWebpackCLI {
449447
450448 defaultInformation . npmPackages  =  `{${ defaultPackages . map ( ( item )  =>  `*${ item }  ) . join ( "," ) }  ; 
451449
450+  const  envinfo  =  await  this . tryRequireThenImport < typeof  import ( "envinfo" ) > ( "envinfo" ,  false ) ; 
451+ 
452452 let  info  =  await  envinfo . run ( defaultInformation ,  envinfoConfig ) ; 
453453
454454 info  =  info . replace ( / n p m P a c k a g e s / g,  "Packages" ) ; 
@@ -1873,19 +1873,18 @@ class WebpackCLI implements IWebpackCLI {
18731873 ".webpack/webpackfile" , 
18741874 ] 
18751875 . map ( ( filename )  => 
1876-  // Since .cjs is not available on interpret side add it manually to default config extension list 
1877-  [ ...Object . keys ( interpret . extensions ) ,  ".cjs" ] . map ( ( ext )  =>  ( { 
1878-  path : path . resolve ( filename  +  ext ) , 
1879-  ext : ext , 
1880-  module : interpret . extensions [ ext ] , 
1881-  } ) ) , 
1876+  // Prioritize popular extensions first to avoid unnecessary fs calls 
1877+  // TODO ".mts" is not supported by `interpret`, need to add it 
1878+  [ ".js" ,  ".mjs" ,  ".cjs" ,  ".ts" ,  ".cts" ,  ...Object . keys ( interpret . extensions ) ] . map ( ( ext )  => 
1879+  path . resolve ( filename  +  ext ) , 
1880+  ) , 
18821881 ) 
18831882 . reduce ( ( accumulator ,  currentValue )  =>  accumulator . concat ( currentValue ) ,  [ ] ) ; 
18841883
18851884 let  foundDefaultConfigFile ; 
18861885
18871886 for  ( const  defaultConfigFile  of  defaultConfigFiles )  { 
1888-  if  ( ! fs . existsSync ( defaultConfigFile . path ) )  { 
1887+  if  ( ! fs . existsSync ( defaultConfigFile ) )  { 
18891888 continue ; 
18901889 } 
18911890
@@ -1894,7 +1893,7 @@ class WebpackCLI implements IWebpackCLI {
18941893 } 
18951894
18961895 if  ( foundDefaultConfigFile )  { 
1897-  const  loadedConfig  =  await  loadConfigByPath ( foundDefaultConfigFile . path ,  options . argv ) ; 
1896+  const  loadedConfig  =  await  loadConfigByPath ( foundDefaultConfigFile ,  options . argv ) ; 
18981897
18991898 config . options  =  loadedConfig . options  as  WebpackConfiguration [ ] ; 
19001899
0 commit comments