Repository: npm/cli (JavaScript)

Issue:
`npm hook ls` duplicates hook name prefixes
Hooks for scopes get a double prefix, ie `@@scope`, when shown with the `npm hook ls` command. This is due to the response from the web request already including the prefix in the `name` field, and the [following lines](https://github.com/npm/cli/blob/d8aac8448e983692cacb427e03f4688cd1b62e30/lib/commands/hook.js#L123-L132) of code then locally adding the prefix again, duplicating it.


Discussion:
@Dionysusnu can i work on this issue? if yes any extra guidance you would like to provide
It appears that the hooks feature has been disabled on the server side anyways, so I wouldn't waste time on a low priority thing like this.
If this has been disabled on the server-side, can't we close the issue?
@Bruce-Hopkins it could still be used by private registries.
> If this has been disabled on the server-side, can't we close the issue?

To clarify, the hooks can still get created, modified, and all that around it, so the bug still exists.

However, in my testing, the actual hook configured URL was never accessed when the hook should have triggered. That's what I meant by "seemingly disabled on the server side".
Since this issue is tagged as 'good first issue' and since people looking for 'good first issues' are looking for good first issues that can be assigned now, maybe it would be appropriate to remove the tag. 
@552020 it still is one. The above comments are just folks who don’t think it’s worth the effort, but nobody from npm has agreed with that.



Patch:
diff --git a/lib/commands/hook.js b/lib/commands/hook.js
index bb3a34b8d2d1b..084741c0c5eea 100644
--- a/lib/commands/hook.js
+++ b/lib/commands/hook.js
@@ -126,9 +126,6 @@ class Hook extends BaseCommand {
 
   hookName (hook) {
     let target = hook.name
-    if (hook.type === 'scope') {
-      target = '@' + target
-    }
     if (hook.type === 'owner') {
       target = '~' + target
     }


Test patch:
diff --git a/test/lib/commands/hook.js b/test/lib/commands/hook.js
index 95bac83d7b6eb..0cd6a7490dda2 100644
--- a/test/lib/commands/hook.js
+++ b/test/lib/commands/hook.js
@@ -28,7 +28,7 @@ let hookArgs = null
 const libnpmhook = {
   add: async (pkg, uri, secret, opts) => {
     hookArgs = { pkg, uri, secret, opts }
-    return { id: 1, name: pkg.replace(/^@/, ''), type: pkgTypes[pkg], endpoint: uri }
+    return { id: 1, name: pkg, type: pkgTypes[pkg], endpoint: uri }
   },
   ls: async opts => {
     hookArgs = opts
@@ -39,7 +39,7 @@ const libnpmhook = {
 
     return Object.keys(pkgTypes).map(name => ({
       id: ++id,
-      name: name.replace(/^@/, ''),
+      name,
       type: pkgTypes[name],
       endpoint: 'https://google.com',
       last_delivery: id % 2 === 0 ? now : undefined,
@@ -50,7 +50,7 @@ const libnpmhook = {
     const pkg = Object.keys(pkgTypes)[0]
     return {
       id: 1,
-      name: pkg.replace(/^@/, ''),
+      name: pkg,
       type: pkgTypes[pkg],
       endpoint: 'https://google.com',
     }
@@ -58,7 +58,7 @@ const libnpmhook = {
   update: async (id, uri, secret, opts) => {
     hookArgs = { id, uri, secret, opts }
     const pkg = Object.keys(pkgTypes)[0]
-    return { id, name: pkg.replace(/^@/, ''), type: pkgTypes[pkg], endpoint: uri }
+    return { id, name: pkg, type: pkgTypes[pkg], endpoint: uri }
   },
 }
 
@@ -92,6 +92,48 @@ t.test('npm hook add', async t => {
   t.strictSame(output, ['+ semver  ->  https://google.com'], 'prints the correct output')
 })
 
+t.test('npm hook add - correct owner hook output', async t => {
+  t.teardown(() => {
+    hookArgs = null
+    output.length = 0
+  })
+
+  await hook.exec(['add', '~npm', 'https://google.com', 'some-secret'])
+
+  t.match(
+    hookArgs,
+    {
+      pkg: '~npm',
+      uri: 'https://google.com',
+      secret: 'some-secret',
+      opts: npm.flatOptions,
+    },
+    'provided the correct arguments to libnpmhook'
+  )
+  t.strictSame(output, ['+ ~npm  ->  https://google.com'], 'prints the correct output')
+})
+
+t.test('npm hook add - correct scope hook output', async t => {
+  t.teardown(() => {
+    hookArgs = null
+    output.length = 0
+  })
+
+  await hook.exec(['add', '@npmcli', 'https://google.com', 'some-secret'])
+
+  t.match(
+    hookArgs,
+    {
+      pkg: '@npmcli',
+      uri: 'https://google.com',
+      secret: 'some-secret',
+      opts: npm.flatOptions,
+    },
+    'provided the correct arguments to libnpmhook'
+  )
+  t.strictSame(output, ['+ @npmcli  ->  https://google.com'], 'prints the correct output')
+})
+
 t.test('npm hook add - unicode output', async t => {
   npm.flatOptions.unicode = true
   t.teardown(() => {
@@ -139,7 +181,7 @@ t.test('npm hook add - json output', async t => {
     JSON.parse(output[0]),
     {
       id: 1,
-      name: 'npmcli',
+      name: '@npmcli',
       endpoint: 'https://google.com',
       type: 'scope',
     },
@@ -174,7 +216,7 @@ t.test('npm hook add - parseable output', async t => {
   )
   t.strictSame(
     output[1].split(/\t/),
-    ['1', 'npmcli', 'scope', 'https://google.com'],
+    ['1', '@npmcli', 'scope', 'https://google.com'],
     'prints the correct parseable values'
   )
 })
@@ -345,7 +387,7 @@ t.test('npm hook ls - parseable output', async t => {
     [
       ['id', 'name', 'type', 'endpoint', 'last_delivery'],
       ['1', 'semver', 'package', 'https://google.com', ''],
-      ['2', 'npmcli', 'scope', 'https://google.com', `${now}`],
+      ['2', '@npmcli', 'scope', 'https://google.com', `${now}`],
       ['3', 'npm', 'owner', 'https://google.com', ''],
     ],
     'prints the correct result'