Skip to content

Conversation

@larsgw
Copy link
Contributor

@larsgw larsgw commented Oct 3, 2018

  • handle scoped packages properly
  • change usage info so it matches old (and current) behavior.

There's an easier way to do this, but that handles some edge cases differently (namely, ignore leading and trailing forward slashes instead of trying to edit root folders), and I don't know if that is allowed.

diff --git a/lib/edit.js b/lib/edit.js
index 48bcd5d34..2b2a02224 100644
--- a/lib/edit.js
+++ b/lib/edit.js
@@ -21,7 +21,7 @@ function edit (args, cb) {
       "No editor set.  Set the 'editor' config, or $EDITOR environ."
     ))
   }
-  p = p.split('/')
+  p = (p.match(/(@[^/]+\/[^/]+|[^/]+)/g) || [])
     .join('/node_modules/')
     .replace(/(\/node_modules)+/, '/node_modules')
   var f = path.resolve(npm.dir, p)

See https://npm.community/t/2258.

@larsgw larsgw requested a review from a team as a code owner October 3, 2018 18:49
Copy link
Contributor

@iarna iarna left a comment

Choose a reason for hiding this comment

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

A small doc update to do here, either by @larsgw or when we land this. Otherwise, yes, let's get this in!


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.

))
}
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.

@larsgw
Copy link
Contributor Author

larsgw commented Oct 24, 2018

Ping? I added the docs, is there something else?

@zkat zkat changed the base branch from latest to release-next November 13, 2018 15:02
@zkat zkat added the semver:patch semver patch level for changes label Nov 13, 2018
@zkat zkat merged commit a34246b into npm:release-next Nov 26, 2018
zkat pushed a commit that referenced this pull request Dec 10, 2018
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver:patch semver patch level for changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants