`npm edit @scoped/package` incorrectly parses slash in package name

cli
help-wanted
good-first-patch
priority:low
triaged

(Mac Cowell) #1

What I Wanted to Do

Wanted to use npm edit to quickly make changes to a locally-installed package. A scoped package in this case. I expected the command to open ./node_modules/<@scoped/package> in a new editor window.

What Happened Instead

The package installed to ./node_modules/@scope/name, but npm edit tries to open ./node_modules/@scope/node_modules/name

❯ npm edit @atlaskit/media-card                                                                                                                   387ms  Mon Sep 17 17:05:13 2018
npm ERR! path /Users/100ideas/dev/ak-mediacard-starter/node_modules/@atlaskit/node_modules/media-card
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall lstat
npm ERR! enoent ENOENT: no such file or directory, lstat '/Users/100ideas/dev/ak-mediacard-starter/node_modules/@atlaskit/node_modules/media-card'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/100ideas/.npm/_logs/2018-09-18T00_05_14_401Z-debug.log

Reproduction Steps

  1. local npm install any scoped package
  2. try to use npm edit to open that package in an editor

Details

npm/cli/lib/edit.js doesn’t know how to handle the slash that is in all scoped package names.

function edit (args, cb) {
  var p = args[0]
  if (args.length !== 1 || !p) return cb(edit.usage)
...
  p = p.split('/')
    .join('/node_modules/')
    .replace(/(\/node_modules)+/, '/node_modules')

Also occurs with node 10.10.0 and npm 6.4.1.

I am just going to use npm link for now, probably a better idea anyway.

Platform Info

$ npm --versions
{ npmbug: '1.0.0',
  npm: '5.6.0',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.8.0',
  icu: '60.1',
  modules: '57',
  napi: '3',
  nghttp2: '1.32.0',
  node: '8.11.3',
  openssl: '1.0.2o',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.19.1',
  v8: '6.2.414.54',
  zlib: '1.2.11' }
$ node -p process.platform
darwin

(Lars Willighagen) #2

I made a PR: