Open dtgriscom opened 7 years ago
90% sure I introduced this bug and it represents my misunderstanding of how npm-package-arg
works. I won't go so far as to say it's a bug in npm-package-arg
but I do think it's at least surprising behavior.
Anyway, I think the right thing to do might just to be to make it always concat name@spec
, but IIRC I made that change because of at least some concerns for how that interacted with local path specs (e.g. "foo": "../../pkg/foo"
and URL specs (e.g. `"foo": "http://example.com/foo.tgz").
Well, I'm not sure how to proceed. I see that there's some complexity in the handling of the code, but the only thing I could do would be to short-circuit that complexity.
Is npm packageName@versionSpec
always the same as a package.json
with "packageName": "versionSpec" in the
dependencies` array? If not, why and when?
but the only thing I could do would be to short-circuit that complexity.
What I meant by my comment was just that. fixDependency()
could (probably) be simplified to just return key+"@"+value
(and perhaps removed entirely with that concat inlined).
OK, would you like me to make a pull request?
I was hoping @arei would have chimed in. I've only ever merged changes that he approved of (either PR approval per se or based on discussion).
The unfortunate facts are that the module doesn't have unit tests, and it's also hard to judge the full extent of the impact of changes to this module in general. On the other hand, if this change were made and it broke someone, npm
makes it easy for them to just peg themselves at the earlier version of this module (especially true since this module is by and large a top-level install and not an embedded dependency) until / unless a fix comes in. And as a bit more color, my project (https://github.com/danfuzz/bayou) might actually be the only current user of npmbox
with local-path dependencies, and I promise that if this change breaks my project I won't complain to you.
So… I'm comfortable with you submitting a PR, but maybe wait a bit to see what @arei has to say.
I want to use npmbox to box all dependencies specified in the following
package.json
:Unfortunately, this fails with npmbox trying to capture a package called "4.x", which is wrong.
The details:
npmbox package.json
npmbox.js
invokesnpmboxxer.js
'sbox
functionbox
starts walking the list of sources by callingbox.next
box.next
sees thatpackage.json
is a json file, and it should parse the file and push all the mentioned dependencies by callinglistDependencies
for each type of dependencylistDependencies
takes one of thepackage.json
dependency maps, intending to return a list of full dependency names. It does so by iterating through the dependency map keys, and accumulating the result of callingbox.fixDependency
with the key and the key valuebox.fixDependency
is first called with"express"
and"4.x"
. It invokesnpm-package-arg
with the latter, and checks whether the returned object has aname
property. It does, sobox.fixDependency
just returns thename
property's value, which is"4.x"
, which is wrong. (If the property hadn't existed, thenbox.fixDependency
would have returned"express" + "@" + "4.x"
.)box.next
call, the source list ends up with"4.x"
as its first item. npmbox then tries to capture the package named"4.x"
, which is wrong.The key here seems to be
box.fixDependency
, which when it is called with"express"
and"4.x"
should return"express@4.x"
, but instead returns"4.x"
, breaking things. I'd be happy to file a pull request. but at this point it would just be to havefixDependency
always return its two arguments with "@" between them. However,fixDependency
must have been designed to do something; since I have no idea what, any change I'd make would certainly break something else.Any ideas?
Edit: also happens when I edit the
express
version spec to"4.1.14"
, the current version.