@@ -31,13 +31,20 @@ const runCommand = (command, args) => {
3131module . exports = function promptForInstallation ( packages , ...args ) {
3232 const nameOfPackage = "@webpack-cli/" + packages ;
3333 let packageIsInstalled = false ;
34+ let pathForCmd ;
3435 try {
35- require . resolve ( nameOfPackage ) ;
36+ const path = require ( "path" ) ;
37+ pathForCmd = path . resolve (
38+ process . cwd ( ) ,
39+ "node_modules" ,
40+ "@webpack-cli" ,
41+ packages
42+ ) ;
43+ require . resolve ( pathForCmd ) ;
3644 packageIsInstalled = true ;
3745 } catch ( err ) {
3846 packageIsInstalled = false ;
3947 }
40-
4148 if ( ! packageIsInstalled ) {
4249 const path = require ( "path" ) ;
4350 const fs = require ( "fs" ) ;
@@ -71,10 +78,16 @@ module.exports = function promptForInstallation(packages, ...args) {
7178 //eslint-disable-next-line
7279 runCommand ( packageManager , options )
7380 . then ( result => {
81+ pathForCmd = path . resolve (
82+ process . cwd ( ) ,
83+ "node_modules" ,
84+ "@webpack-cli" ,
85+ packages
86+ ) ;
7487 if ( packages === "serve" ) {
75- return require ( `@webpack-cli/ ${ packages } ` ) . serve ( ) ;
88+ return require ( pathForCmd ) . serve ( ) ;
7689 }
77- return require ( nameOfPackage ) ( ...args ) ; //eslint-disable-line
90+ return require ( pathForCmd ) ( ...args ) ; //eslint-disable-line
7891 } )
7992 . catch ( error => {
8093 console . error ( error ) ;
@@ -92,6 +105,6 @@ module.exports = function promptForInstallation(packages, ...args) {
92105 }
93106 } ) ;
94107 } else {
95- require ( nameOfPackage ) ( ...args ) ; // eslint-disable-line
108+ require ( pathForCmd ) ( ...args ) ; // eslint-disable-line
96109 }
97110} ;
0 commit comments