Skip to content

Commit

Permalink
Merge pull request #92 from SocketDev/cg/infoPackageDefaultVersion
Browse files Browse the repository at this point in the history
Handle dist tags / no version argument when running the info command
  • Loading branch information
charliegerard authored Nov 29, 2023
2 parents d4b792e + b60f028 commit d384029
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions lib/commands/info/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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: [email protected]')
}

const pkgName = rawPkgName.slice(0, versionSeparator)
const pkgVersion = rawPkgName.slice(versionSeparator + 1)

if (!pkgVersion) {
throw new InputError('Need to specify a version, like eg: [email protected]')
}
const pkgName = versionSeparator < 1 ? rawPkgName : rawPkgName.slice(0, versionSeparator)
const pkgVersion = versionSeparator < 1 ? 'latest' : rawPkgName.slice(versionSeparator + 1)

return {
includeAllIssues,
Expand Down Expand Up @@ -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'))
}
Expand Down

0 comments on commit d384029

Please sign in to comment.