Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGar <gar+gh@danger.computer>2022-05-09 17:34:54 +0300
committerGitHub <noreply@github.com>2022-05-09 17:34:54 +0300
commit38cf29a0054544c575b6bce953f1d433dbb6a3b5 (patch)
treea11da84754f3b87a398d4f58a11c485df6b10db2 /lib
parent48d2db6037487fd782f67bbcd2cf12e009ece17b (diff)
fix: cleanup star/unstar (#4868)
It was querying whoami once for every package you starred/unstarred, and incorrectly trying to determine if you weren't logged in. In fact the function throws a descriptive message if you're not logged in already. The whoami check was also racing with the fetch of the packument for each package you were starring/unstarring meaning you could also get a random 401 for a private package instead of the 'you need to log in' message. unstar was setting an undocumented config item to get the shared code to unstar. The command already has a name attribute that tells us what action we are doing so we can just use that. Finally, the duplicated (and differing) params between the two commands were consolidated.
Diffstat (limited to 'lib')
-rw-r--r--lib/commands/star.js27
-rw-r--r--lib/commands/unstar.js10
2 files changed, 11 insertions, 26 deletions
diff --git a/lib/commands/star.js b/lib/commands/star.js
index fb3882bcd..7b76be3c1 100644
--- a/lib/commands/star.js
+++ b/lib/commands/star.js
@@ -11,6 +11,7 @@ class Star extends BaseCommand {
static params = [
'registry',
'unicode',
+ 'otp',
]
static ignoreImplicitWorkspace = false
@@ -23,26 +24,20 @@ class Star extends BaseCommand {
// if we're unstarring, then show an empty star image
// otherwise, show the full star image
const unicode = this.npm.config.get('unicode')
- const unstar = this.npm.config.get('star.unstar')
const full = unicode ? '\u2605 ' : '(*)'
const empty = unicode ? '\u2606 ' : '( )'
- const show = unstar ? empty : full
+ const show = this.name === 'star' ? full : empty
const pkgs = args.map(npa)
- for (const pkg of pkgs) {
- const [username, fullData] = await Promise.all([
- getIdentity(this.npm, { ...this.npm.flatOptions }),
- fetch.json(pkg.escapedName, {
- ...this.npm.flatOptions,
- spec: pkg,
- query: { write: true },
- preferOnline: true,
- }),
- ])
+ const username = await getIdentity(this.npm, this.npm.flatOptions)
- if (!username) {
- throw new Error('You need to be logged in!')
- }
+ for (const pkg of pkgs) {
+ const fullData = await fetch.json(pkg.escapedName, {
+ ...this.npm.flatOptions,
+ spec: pkg,
+ query: { write: true },
+ preferOnline: true,
+ })
const body = {
_id: fullData._id,
@@ -50,7 +45,7 @@ class Star extends BaseCommand {
users: fullData.users || {},
}
- if (!unstar) {
+ if (this.name === 'star') {
log.info('star', 'starring', body._id)
body.users[username] = true
log.verbose('star', 'starring', body)
diff --git a/lib/commands/unstar.js b/lib/commands/unstar.js
index 9a64c8431..cbcb73636 100644
--- a/lib/commands/unstar.js
+++ b/lib/commands/unstar.js
@@ -3,15 +3,5 @@ const Star = require('./star.js')
class Unstar extends Star {
static description = 'Remove an item from your favorite packages'
static name = 'unstar'
- static params = [
- 'registry',
- 'unicode',
- 'otp',
- ]
-
- async exec (args) {
- this.npm.config.set('star.unstar', true)
- return super.exec(args)
- }
}
module.exports = Unstar