( channel: ReleaseChannel, )
| 327 | } |
| 328 | |
| 329 | export async function getLatestVersion( |
| 330 | channel: ReleaseChannel, |
| 331 | ): Promise<string | null> { |
| 332 | const npmTag = channel === 'stable' ? 'stable' : 'latest' |
| 333 | |
| 334 | // Run from home directory to avoid reading project-level .npmrc |
| 335 | // which could be maliciously crafted to redirect to an attacker's registry |
| 336 | const result = await execFileNoThrowWithCwd( |
| 337 | 'npm', |
| 338 | ['view', `${MACRO.PACKAGE_URL}@${npmTag}`, 'version', '--prefer-online'], |
| 339 | { abortSignal: AbortSignal.timeout(5000), cwd: homedir() }, |
| 340 | ) |
| 341 | if (result.code !== 0) { |
| 342 | logForDebugging(`npm view failed with code ${result.code}`) |
| 343 | if (result.stderr) { |
| 344 | logForDebugging(`npm stderr: ${result.stderr.trim()}`) |
| 345 | } else { |
| 346 | logForDebugging('npm stderr: (empty)') |
| 347 | } |
| 348 | if (result.stdout) { |
| 349 | logForDebugging(`npm stdout: ${result.stdout.trim()}`) |
| 350 | } |
| 351 | return null |
| 352 | } |
| 353 | return result.stdout.trim() |
| 354 | } |
| 355 | |
| 356 | export type NpmDistTags = { |
| 357 | latest: string | null |
no test coverage detected