Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

npm destroys a link to a package if local version is not strictly equal to what is in the repo #3974

Open
notatestuser opened this Issue · 1 comment

3 participants

@notatestuser

We're referencing all of our internal packages by their git repositories in package.json files. We don't store our internal modules in the npm registry.

When one of these packages are linked (via npm link) and the local version doesn't strictly match the version in the package stored in the package.json in the git master, npm assumes that the package is not installed and will overwrite the link in order to install it from scratch.

Reproducing the issue (with toy package names):

Given that the version of package1 in git is NOT exactly the same as what is local:
1. cd package1
2. npm link
3. cd ../package2
4. npm link package1
5. grep -e version ./node_modules/package1/package.json
(observe that it is not your local version and that it has instead been pulled from git)

I propose that npm runs a smarter check to permit a link if the locally linked package has a later package version than what is in git. This will allow for a development of subsequent versions on the local machine while leaving links intact.

An even smarter solution could include ensuring the HEAD commit is in the git tree of the local package while disregarding the version number altogether.


Appendix 1: The offending code (highlighted in red circle):

npm link bug

@lloydde

An even smarter solution could include ensuring the HEAD commit is in the git tree of the local package while disregarding the version number altogether.

That sounds dangerous and too smart, as history could be rewritten. As you propose earlier, using the explicitly defined version seems like a good balance.

@othiym23 othiym23 added the bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.