44using System . Collections . Generic ;
55using System . ComponentModel . Composition ;
66using System . Diagnostics ;
7+ using System . IO ;
78using System . Linq ;
89using System . Threading ;
910using Microsoft . NodejsTools . Npm ;
@@ -80,21 +81,21 @@ public int Exec(List<WorkspaceVisualNodeBase> selection, Guid pguidCmdGroup, uin
8081 switch ( nCmdID )
8182 {
8283 case PkgCmdId . cmdidWorkSpaceNpmInstallMissing :
83- ExecNpmInstallMissing ( node ) ;
84+ ExecNpmInstallMissing ( ( IFileNode ) node ) ;
8485 return VSConstants . S_OK ;
8586
8687 case PkgCmdId . cmdidWorkSpaceNpmInstallNew :
87- ExecNpmInstallNew ( node ) ;
88+ ExecNpmInstallNew ( ( IFileNode ) node ) ;
8889 return VSConstants . S_OK ;
8990
9091 case PkgCmdId . cmdidWorkSpaceNpmUpdate :
91- ExecNpmUpdate ( node ) ;
92+ ExecNpmUpdate ( ( IFileNode ) node ) ;
9293 return VSConstants . S_OK ;
9394 }
9495
9596 if ( nCmdID >= PkgCmdId . cmdidWorkSpaceNpmDynamicScript && nCmdID < PkgCmdId . cmdidWorkSpaceNpmDynamicScriptMax )
9697 {
97- ExecDynamic ( node , nCmdID ) ;
98+ ExecDynamic ( ( IFileNode ) node , nCmdID ) ;
9899 return VSConstants . S_OK ;
99100 }
100101 }
@@ -116,43 +117,43 @@ public int Exec(List<WorkspaceVisualNodeBase> selection, Guid pguidCmdGroup, uin
116117 // Note: all the Exec commands are async, this allows us to call them in a fire and forget
117118 // pattern, without blocking the UI or losing any logging
118119
119- private async void ExecNpmInstallMissing ( WorkspaceVisualNodeBase node )
120+ private async void ExecNpmInstallMissing ( IFileNode node )
120121 {
121- using ( var npmController = this . CreateController ( node . Workspace ) )
122+ using ( var npmController = this . CreateController ( node . FullPath ) )
122123 using ( var commander = npmController . CreateNpmCommander ( ) )
123124 {
124125 await commander . Install ( ) ;
125126 }
126127 }
127128
128- private void ExecNpmInstallNew ( WorkspaceVisualNodeBase node )
129+ private void ExecNpmInstallNew ( IFileNode node )
129130 {
130- using ( var npmController = this . CreateController ( node . Workspace ) )
131+ using ( var npmController = this . CreateController ( node . FullPath ) )
131132 using ( var npmWorker = new NpmWorker ( npmController ) )
132133 using ( var manager = new NpmPackageInstallWindow ( npmController , npmWorker ) )
133134 {
134135 manager . ShowModal ( ) ;
135136 }
136137 }
137138
138- private async void ExecNpmUpdate ( WorkspaceVisualNodeBase node )
139+ private async void ExecNpmUpdate ( IFileNode node )
139140 {
140- using ( var npmController = this . CreateController ( node . Workspace ) )
141+ using ( var npmController = this . CreateController ( node . FullPath ) )
141142 using ( var commander = npmController . CreateNpmCommander ( ) )
142143 {
143144 await commander . UpdatePackagesAsync ( ) ;
144145 }
145146 }
146147
147- private async void ExecDynamic ( WorkspaceVisualNodeBase node , uint nCmdID )
148+ private async void ExecDynamic ( IFileNode node , uint nCmdID )
148149 {
149150 // Unfortunately the NpmController (and NpmCommander), used for the install and update commands
150151 // doesn't support running arbitrary scripts. And changing that is outside
151152 // the scope of these changes.
152- var filePath = ( ( IFileNode ) node ) . FullPath ;
153+ var filePath = node . FullPath ;
153154 if ( TryGetCommand ( nCmdID , filePath , out var commandName ) )
154155 {
155- using ( var npmController = this . CreateController ( node . Workspace ) )
156+ using ( var npmController = this . CreateController ( filePath ) )
156157 using ( var commander = npmController . CreateNpmCommander ( ) )
157158 {
158159 await commander . ExecuteNpmCommandAsync ( $ "run-script { commandName } ", showConsole : true ) ;
@@ -264,9 +265,11 @@ private static bool TryGetCommand(uint nCmdID, string filePath, out string comma
264265 return false ;
265266 }
266267
267- private INpmController CreateController ( IWorkspace workspace )
268+ private INpmController CreateController ( string packageJsonPath )
268269 {
269- var projectHome = workspace . Location ;
270+ Debug . Assert ( Path . IsPathRooted ( packageJsonPath ) && PackageJsonFactory . IsPackageJsonFile ( packageJsonPath ) ) ;
271+
272+ var projectHome = Path . GetDirectoryName ( packageJsonPath ) ;
270273
271274 var npmController = NpmControllerFactory . Create (
272275 projectHome ,
0 commit comments