@@ -55,9 +55,7 @@ const fs = require("fs");
55
55
const path = require ( "path" ) ;
56
56
const { pathToFileURL } = require ( "url" ) ;
57
57
const util = require ( "util" ) ;
58
-
59
58
const { program, Option } = require ( "commander" ) ;
60
- const envinfo = require ( "envinfo" ) ;
61
59
62
60
const WEBPACK_PACKAGE = process . env . WEBPACK_PACKAGE || "webpack" ;
63
61
const WEBPACK_DEV_SERVER_PACKAGE = process . env . WEBPACK_DEV_SERVER_PACKAGE || "webpack-dev-server" ;
@@ -449,6 +447,8 @@ class WebpackCLI implements IWebpackCLI {
449
447
450
448
defaultInformation . npmPackages = `{${ defaultPackages . map ( ( item ) => `*${ item } *` ) . join ( "," ) } }` ;
451
449
450
+ const envinfo = await this . tryRequireThenImport < typeof import ( "envinfo" ) > ( "envinfo" , false ) ;
451
+
452
452
let info = await envinfo . run ( defaultInformation , envinfoConfig ) ;
453
453
454
454
info = info . replace ( / n p m P a c k a g e s / g, "Packages" ) ;
@@ -1873,19 +1873,18 @@ class WebpackCLI implements IWebpackCLI {
1873
1873
".webpack/webpackfile" ,
1874
1874
]
1875
1875
. 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
+ ) ,
1882
1881
)
1883
1882
. reduce ( ( accumulator , currentValue ) => accumulator . concat ( currentValue ) , [ ] ) ;
1884
1883
1885
1884
let foundDefaultConfigFile ;
1886
1885
1887
1886
for ( const defaultConfigFile of defaultConfigFiles ) {
1888
- if ( ! fs . existsSync ( defaultConfigFile . path ) ) {
1887
+ if ( ! fs . existsSync ( defaultConfigFile ) ) {
1889
1888
continue ;
1890
1889
}
1891
1890
@@ -1894,7 +1893,7 @@ class WebpackCLI implements IWebpackCLI {
1894
1893
}
1895
1894
1896
1895
if ( foundDefaultConfigFile ) {
1897
- const loadedConfig = await loadConfigByPath ( foundDefaultConfigFile . path , options . argv ) ;
1896
+ const loadedConfig = await loadConfigByPath ( foundDefaultConfigFile , options . argv ) ;
1898
1897
1899
1898
config . options = loadedConfig . options as WebpackConfiguration [ ] ;
1900
1899
0 commit comments