Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edit: scoped packages #75

Merged
merged 3 commits into from Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions doc/cli/npm-edit.md
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
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>...]'
Copy link
Contributor

@iarna iarna Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into how this summary got messed up, and it goes back to the edit docs having been wrong since 2011, and folks patching this usage summary to match them.

I would like to see the summary in doc/cli/npm-edit.md updated to match!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, didn't see those were in the repo too.


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

Expand All @@ -22,6 +22,20 @@ function edit (args, cb) {
))
}
p = p.split('/')
// combine scoped parts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordinarily I'd ask for tests, but we don't have any existing tests for this route, this is a interactive route and this change is reasonably eyeballable, so I'm inclined to take this without them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I tried making tests but I'm not too familiar with all the mocking environments yet, and without something to work with I wasn't sure how to.

.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