@@ -68,7 +68,7 @@ const getPackageManagerForInstall = async (options: Options, pkgFile: string) =>
68
68
}
69
69
70
70
/** Either suggest an install command based on the package manager, or in interactive mode, prompt to autoinstall. */
71
- const npmInstallHint = async (
71
+ const npmInstall = async (
72
72
pkgs : string [ ] ,
73
73
analysis : Index < PackageFile > | PackageFile ,
74
74
options : Options ,
@@ -80,16 +80,16 @@ const npmInstallHint = async (
80
80
const someUpgraded = Object . values ( analysisNormalized ) . some ( upgrades => Object . keys ( upgrades ) . length > 0 )
81
81
if ( ! someUpgraded ) return
82
82
83
- let showInstallHint = true
84
-
85
83
// for the purpose of the install hint, just use the package manager used in the first subproject
86
84
// if autoinstalling, the actual package manager in each subproject will be used
87
85
const packageManager = await getPackageManagerForInstall ( options , pkgs [ 0 ] )
88
86
89
87
// by default, show an install hint after upgrading
90
88
// this will be disabled in interactive mode if the user chooses to have npm-check-updates execute the install command
91
- const installHint = `${ chalk . cyan ( packageManager + ' install' ) } ${
92
- pkgs . length > 1 ? ' in each project directory' : ''
89
+ const installHint = `Run ${ chalk . cyan ( packageManager + ' install' ) } ${
90
+ pkgs . length > 1 && ! options . withWorkspace && ! options . workspace && ! options . withWorkspaces && ! options . workspaces
91
+ ? ' in each project directory'
92
+ : ''
93
93
} to install new versions`
94
94
95
95
// prompt the user if they want ncu to run "npm install"
@@ -110,7 +110,6 @@ const npmInstallHint = async (
110
110
111
111
// autoinstall
112
112
if ( response . value ) {
113
- showInstallHint = false
114
113
pkgs . forEach ( async pkgFile => {
115
114
const packageManager = await getPackageManagerForInstall ( options , pkgFile )
116
115
const cmd = packageManager + ( process . platform === 'win32' ? '.cmd' : '' )
@@ -122,8 +121,8 @@ const npmInstallHint = async (
122
121
}
123
122
124
123
// show the install hint unless autoinstall occurred
125
- if ( showInstallHint ) {
126
- print ( options , `\nRun ${ installHint } .` )
124
+ else {
125
+ print ( options , `\n ${ installHint } .` )
127
126
}
128
127
}
129
128
@@ -252,8 +251,9 @@ export async function run(
252
251
}
253
252
254
253
// enable --deep if multiple package files are found
255
- options . deep =
256
- options . deep || options . withWorkspaces || options . workspaces || ! ! options . workspace || pkgs . length > 1
254
+ const isWorkspace =
255
+ options . withWorkspaces || options . workspaces || ! ! options . withWorkspace ?. length || ! ! options . workspace ?. length
256
+ options . deep = options . deep || isWorkspace || pkgs . length > 1
257
257
258
258
let analysis : Index < PackageFile > | PackageFile | void
259
259
if ( options . global ) {
@@ -302,7 +302,8 @@ export async function run(
302
302
303
303
// suggest install command or autoinstall
304
304
if ( options . upgrade ) {
305
- await npmInstallHint ( pkgs , analysis , options )
305
+ // if workspaces, install from root project folder
306
+ await npmInstall ( isWorkspace ? [ 'package.json' ] : pkgs , analysis , options )
306
307
}
307
308
308
309
return analysis
0 commit comments