@@ -93,59 +93,59 @@ namespace ts.server.typingsInstaller {
9393 const id = this . installRunCount ;
9494 this . installRunCount ++ ;
9595 let execInstallCmdCount = 0 ;
96- let filteredTypings : string [ ] = [ ] ;
96+ const filteredTypings : string [ ] = [ ] ;
9797 for ( const typing of typingsToInstall ) {
9898 const command = `npm view @types/${ typing } --silent name` ;
99- if ( this . log . isEnabled ( ) ) {
100- this . log . writeLine ( `Running npm view @types ${ id } , command ' ${ command } '.` ) ;
101- }
102- this . exec ( command , { cwd : cachePath } , ( err , stdout , stderr ) => {
99+ this . execAsync ( "npm view" , command , cachePath , id , ( err , stdout , stderr ) => {
100+ if ( stdout ) {
101+ filteredTypings . push ( typing ) ;
102+ }
103103 execInstallCmdCount ++ ;
104- if ( this . log . isEnabled ( ) ) {
105- this . log . writeLine ( `npm install @types ${ id } stdout: ${ stdout } ` ) ;
106- this . log . writeLine ( `npm install @types ${ id } stderr: ${ stderr } ` ) ;
104+ if ( execInstallCmdCount === typingsToInstall . length ) {
105+ installFilteredTypings ( this , filteredTypings ) ;
107106 }
108- if ( stdout !== "" ) {
109- filteredTypings . push ( typing ) ;
107+ } ) ;
108+ }
109+
110+ function installFilteredTypings ( self : NodeTypingsInstaller , filteredTypings : string [ ] ) {
111+ const command = `npm install ${ filteredTypings . map ( t => "@types/" + t ) . join ( " " ) } --save-dev` ;
112+ self . execAsync ( "npm install" , command , cachePath , id , ( err , stdout , stderr ) => {
113+ if ( stdout ) {
114+ reportInstalledTypings ( self ) ;
110115 }
111- if ( execInstallCmdCount >= typingsToInstall . length ) {
112- const command = `npm install ${ filteredTypings . map ( t => "@types/" + t ) . join ( " " ) } --save-dev` ;
113- if ( this . log . isEnabled ( ) ) {
114- this . log . writeLine ( `Running npm install @types ${ id } , command '${ command } '. cache path '${ cachePath } '` ) ;
116+ } ) ;
117+ }
118+
119+ function reportInstalledTypings ( self : NodeTypingsInstaller ) {
120+ const command = "npm ls -json" ;
121+ self . execAsync ( "npm ls" , command , cachePath , id , ( err , stdout , stderr ) => {
122+ let installedTypings : string [ ] ;
123+ try {
124+ const response = JSON . parse ( stdout ) ;
125+ if ( response . dependencies ) {
126+ installedTypings = getOwnKeys ( response . dependencies ) ;
115127 }
116- this . exec ( command , { cwd : cachePath } , ( err , stdout , stderr ) => {
117- if ( this . log . isEnabled ( ) ) {
118- this . log . writeLine ( `npm install @types ${ id } stdout: ${ stdout } ` ) ;
119- this . log . writeLine ( `npm install @types ${ id } stderr: ${ stderr } ` ) ;
120- }
121- if ( stdout === "" ) {
122- return ;
123- }
124- const command = "npm ls -json" ;
125- this . exec ( command , { cwd : cachePath } , ( err , stdout , stderr ) => {
126- if ( this . log . isEnabled ( ) ) {
127- this . log . writeLine ( `npm ls -json ${ id } stdout: ${ stdout } ` ) ;
128- this . log . writeLine ( `npm ls -json ${ id } stderr: ${ stderr } ` ) ;
129- }
130- const installedTypings : string [ ] = [ ] ;
131- try {
132- const response = JSON . parse ( stdout ) ;
133- if ( response . dependencies ) {
134- for ( const typing in response . dependencies ) {
135- installedTypings . push ( typing ) ;
136- }
137- }
138- }
139- catch ( e ) {
140- this . log . writeLine ( `Error parsing installed @types dependencies. Error details: ${ e . message } ` ) ;
141- }
142- postInstallAction ( installedTypings ) ;
143- } ) ;
144- } ) ;
145128 }
129+ catch ( e ) {
130+ self . log . writeLine ( `Error parsing installed @types dependencies. Error details: ${ e . message } ` ) ;
131+ }
132+ postInstallAction ( installedTypings || [ ] ) ;
146133 } ) ;
147134 }
148135 }
136+
137+ private execAsync ( prefix : string , command : string , cwd : string , requestId : number , cb : ( err : Error , stdout : string , stderr : string ) => void ) {
138+ if ( this . log . isEnabled ( ) ) {
139+ this . log . writeLine ( `#${ requestId } running command '${ command } '.` ) ;
140+ }
141+ this . exec ( command , { cwd } , ( err , stdout , stderr ) => {
142+ if ( this . log . isEnabled ( ) ) {
143+ this . log . writeLine ( `${ prefix } #${ requestId } stdout: ${ stdout } ` ) ;
144+ this . log . writeLine ( `${ prefix } #${ requestId } stderr: ${ stderr } ` ) ;
145+ }
146+ cb ( err , stdout , stderr ) ;
147+ } ) ;
148+ }
149149 }
150150
151151 function findArgument ( argumentName : string ) {
0 commit comments