-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from SocketDev/cg/infoPackageDefaultVersion
Handle dist tags / no version argument when running the info command
- Loading branch information
Showing
1 changed file
with
9 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: [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, | ||
|
@@ -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')) | ||
} | ||
|