Skip to content

Commit

Permalink
edit: scoped packages (#75)
Browse files Browse the repository at this point in the history
* edit: fix handling of scoped packages

* edit: fix usage info

* docs: fix docs for the npm-edit command

PR-URL: #75
Credit: @larsgw
Reviewed-By: @iarna
  • Loading branch information
larsgw authored and zkat committed Dec 10, 2018
1 parent dd38cc0 commit e818cd4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 5 additions & 3 deletions doc/cli/npm-edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ npm-edit(1) -- Edit an installed package

## SYNOPSIS

npm edit <pkg>[@<version>]
npm edit <pkg>[/<subpkg>...]

## DESCRIPTION

Opens the package folder in the default editor (or whatever you've
configured as the npm `editor` config -- see `npm-config(7)`.)
Selects a (sub)dependency in the current
working directory and opens the package folder in the default editor
(or whatever you've configured as the npm `editor` config -- see
`npm-config(7)`.)

After it has been edited, the package is rebuilt so as to pick up any
changes in compiled packages.
Expand Down
16 changes: 15 additions & 1 deletion lib/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// open the package folder in the $EDITOR

module.exports = edit
edit.usage = 'npm edit <pkg>[@<version>]'
edit.usage = 'npm edit <pkg>[/<subpkg>...]'

edit.completion = require('./utils/completion/installed-shallow.js')

Expand All @@ -22,6 +22,20 @@ function edit (args, cb) {
))
}
p = p.split('/')
// combine scoped parts
.reduce(function (parts, part) {
if (parts.length === 0) {
return [part]
}
var lastPart = parts[parts.length - 1]
// check if previous part is the first part of a scoped package
if (lastPart[0] === '@' && !lastPart.includes('/')) {
parts[parts.length - 1] += '/' + part
} else {
parts.push(part)
}
return parts
}, [])
.join('/node_modules/')
.replace(/(\/node_modules)+/, '/node_modules')
var f = path.resolve(npm.dir, p)
Expand Down

0 comments on commit e818cd4

Please sign in to comment.