diff --git a/lib/commands/info/index.js b/lib/commands/info/index.js index 02b37d11..48903505 100644 --- a/lib/commands/info/index.js +++ b/lib/commands/info/index.js @@ -21,7 +21,8 @@ export const info = { const input = setupCommand(name, info.description, argv, importMeta) if (input) { - const spinner = ora(`Looking up data for version ${input.pkgVersion} of ${input.pkgName}\n`).start() + const spinnerText = input.pkgVersion === 'latest' ? `Looking up data for the latest version of ${input.pkgName}\n` : `Looking up data for version ${input.pkgVersion} of ${input.pkgName}\n` + const spinner = ora(spinnerText).start() const packageData = await fetchPackageData(input.pkgName, input.pkgVersion, input, spinner) if (packageData) { formatPackageDataOutput(packageData, { name, ...input }, spinner) @@ -92,16 +93,8 @@ function setupCommand (name, description, argv, importMeta) { const versionSeparator = rawPkgName.lastIndexOf('@') - if (versionSeparator < 1) { - throw new InputError('Need to specify a full package identifier, like eg: webtorrent@1.0.0') - } - - const pkgName = rawPkgName.slice(0, versionSeparator) - const pkgVersion = rawPkgName.slice(versionSeparator + 1) - - if (!pkgVersion) { - throw new InputError('Need to specify a version, like eg: webtorrent@1.0.0') - } + const pkgName = versionSeparator < 1 ? rawPkgName : rawPkgName.slice(0, versionSeparator) + const pkgVersion = versionSeparator < 1 ? 'latest' : rawPkgName.slice(versionSeparator + 1) return { includeAllIssues, @@ -184,7 +177,11 @@ async function fetchPackageData (pkgName, pkgVersion, { includeAllIssues }, spin // Link to issues list const format = new ChalkOrMarkdown(!!outputMarkdown) const url = `https://socket.dev/npm/package/${pkgName}/overview/${pkgVersion}` - console.log('\nDetailed info on socket.dev: ' + format.hyperlink(`${pkgName} v${pkgVersion}`, url, { fallbackToUrl: true })) + if (pkgVersion === 'latest') { + console.log('\nDetailed info on socket.dev: ' + format.hyperlink(`${pkgName}`, url, { fallbackToUrl: true })) + } else { + console.log('\nDetailed info on socket.dev: ' + format.hyperlink(`${pkgName} v${pkgVersion}`, url, { fallbackToUrl: true })) + } if (!outputMarkdown) { console.log(chalk.dim('\nOr rerun', chalk.italic(name), 'using the', chalk.italic('--json'), 'flag to get full JSON output')) }