()
| 182 | } |
| 183 | |
| 184 | export async function getUpdateCommandInfo(): Promise<{ |
| 185 | command: string; |
| 186 | global: boolean; |
| 187 | }> { |
| 188 | const nativeInstall = isNativeBinaryInstall(); |
| 189 | const pkgAndVersion = `${nativeInstall ? nativePackageName : packageName}@latest`; |
| 190 | |
| 191 | if (nativeInstall) { |
| 192 | // The native binary's process.argv[1] points into its virtual filesystem |
| 193 | // snapshot, so detect the package manager from the real install location. |
| 194 | const segments = process.execPath.split(sep); |
| 195 | let cliType: GlobalCliType = 'npm'; |
| 196 | if (segments.includes('pnpm') || segments.includes('.pnpm')) { |
| 197 | cliType = 'pnpm'; |
| 198 | } else if (segments.includes('yarn') || segments.includes('.yarn')) { |
| 199 | cliType = 'yarn'; |
| 200 | } |
| 201 | const install = cliType === 'yarn' ? 'global add' : 'i -g'; |
| 202 | const force = cliType === 'npm' ? ' --force' : ''; |
| 203 | return { |
| 204 | command: `${cliType} ${install} ${pkgAndVersion}${force}`, |
| 205 | global: true, |
| 206 | }; |
| 207 | } |
| 208 | |
| 209 | const { cliType, global } = await resolveInstall(); |
| 210 | const yarn = cliType === 'yarn'; |
| 211 | |
| 212 | let install = yarn ? 'add' : 'i'; |
| 213 | if (global) { |
| 214 | install = yarn ? 'global add' : 'i -g'; |
| 215 | } |
| 216 | |
| 217 | return { command: `${cliType} ${install} ${pkgAndVersion}`, global }; |
| 218 | } |
| 219 | |
| 220 | export default async function getUpdateCommand(): Promise<string> { |
| 221 | return (await getUpdateCommandInfo()).command; |
no test coverage detected