Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

[BUG] (CLI-related) npm install ignores explicit prefix #253

Closed
jameschensmith opened this issue Mar 17, 2021 · 1 comment · Fixed by #254
Closed

[BUG] (CLI-related) npm install ignores explicit prefix #253

jameschensmith opened this issue Mar 17, 2021 · 1 comment · Fixed by #254

Comments

@jameschensmith
Copy link
Contributor

jameschensmith commented Mar 17, 2021

What / Why

I install a package with npm using an explicit prefix, npm ignores the prefix and is using save-prefix instead.

The reason appears to be the npa call on line 893 (v2.2.8 snippet). Currently, it's only passing spec as the argument. This results in an invalid req object as a result of the parse. This req object is no longer the expected type range, but rather tag. When it reaches lines 908-909, range is evaluated to prefixRange.

I think the fix would be to address the npa call on line 893 mentioned above. Below is a possible solution:

    if (this[_resolvedAdd]) {
      const root = this.idealTree
      const pkg = root.package
      for (const { name } of this[_resolvedAdd]) {
-        const req = npa(root.edgesOut.get(name).spec, root.realpath)
+        const req = npa.resolve(name, root.edgesOut.get(name).spec, root.realpath)

When

I install a package with npm using an explicit prefix.

Example

npm i -D typescript@~3.5.0

Current Behavior

After the installation, package.json has "typescript": "^3.5.3".

Expected Behavior

npm should honor the explicit prefix. package.json should have "typescript": "~3.5.3".

References

@jameschensmith
Copy link
Contributor Author

jameschensmith commented Mar 17, 2021

Ran into an issue with the following change:

    if (this[_resolvedAdd]) {
      const root = this.idealTree
      const pkg = root.package
      for (const { name } of this[_resolvedAdd]) {
-        const req = npa(root.edgesOut.get(name).spec, root.realpath)
+        const req = npa.resolve(name, root.edgesOut.get(name).spec, root.realpath)

If spec is not supplied, * will be passed in. This is not treated as a tag, but rather a valid semver range. This fails at least 14 tests, which don't pass a spec and validate prefixRange is the result. Instead * is the result in package.json. This also follows the code comment on lines 902-906:

  • * is a range.
  • * is not a subset of prefixRange (at least up to node-semver v7.3.4, only * can be a subset of *)

Therefore the current logic correctly chooses * to place in package.json. Looking for a way to resolve this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant