Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle dist tags / no version argument when running the info command #92

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading