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

Symlink local dependencies #6251

Closed
timoxley opened this issue Sep 21, 2014 · 17 comments
Closed

Symlink local dependencies #6251

timoxley opened this issue Sep 21, 2014 · 17 comments

Comments

@timoxley
Copy link
Contributor

It would be great if it were possible to symlink local dependencies during development, without using clobbering global links. Specifically, it'd be nice if npm could automatically link any dependencies in the package.json with relative, local paths.

Local dependencies in their current form do not create a very compelling workflow if you have multiple things depending on a single local dependency – each dependee must reinstall the local dependency after each change leading to possible strange behaviour whereby you have the "same" dependency installed in multiple locations, with the same version number, but different code.

First npm probably needs ability to do an npm link without using the global namespace.

I've prototyped local linking as an external tool over here: https://github.com/timoxley/linklocal

edit: terrible english

@timoxley
Copy link
Contributor Author

cc @dylang interested in your opinion on this. Not trying to rally support for my issue, just curious.

@dylang
Copy link
Contributor

dylang commented Sep 30, 2014

I agree.

It also bothers me that it makes a mess of our globals and I'm compelled to regularly clean them out, especially when npm install -g i has warns about linked packages.

I wonder if I've ever npm linked npm not realizing overwrote my local global stable copy of npm.

@dylang
Copy link
Contributor

dylang commented Sep 30, 2014

I remember when everything npm installed was global, and all node projects on your computer looked in that one shared node_modules directory. Maybe this is an artifact of that.

@othiym23
Copy link
Contributor

othiym23 commented Oct 1, 2014

I'm not opposed to this landing in npm eventually as a matter of principal (but I'm not the one you need to convince – @isaacs is the one who came up with the current setup for npm link, and he's the person with the best argument for why that shouldn't change). I will say that until we have the edges of local dependencies smoothed down (#6363), it's a bit premature to build additional functionality atop them.

@faiq
Copy link
Contributor

faiq commented Jan 9, 2015

absolutely agree. It's silly that I'll have multiple copies of the same code in different places.

@williscool
Copy link

+1000

I had made a comment looking for this I'm glad I carefully read this thread.

#7426 (comment)

Whats really bad is that the messaging around using file: in the package.json right now makes it seem like this already works like this :(

@williscool
Copy link

@timoxley thanks for linklocal exactly what I was looking for

@bopjesvla
Copy link

bopjesvla commented Apr 25, 2016

Is there any chance of symlinks landing in the foreseeable future?

To an outsider, something like { "devDependencies" : { "my-module": "link:./my-module"} } seems both easier to implement and easier for users to manage than allowing npm link outside the global namespace.

@yoshuawuyts
Copy link

I kinda stopped using linklocal; not nesting more than one level deep sort of solved all my problems. To be honest I'm not too fussed about npm adding more features, I feel like there are bigger fish to fry at the moment. But if you want to have local links, linklocal is definitely the way to go!

@alex-pex
Copy link

I'd really like to have local package as symlinks. I don't see the point of having a copy of the files instead of a link, unless the module lives outside of my project (but then it is no longer a "local" package).

My opinion is symlink should be the default behavior, but i might be wrong.

@timoxley
Copy link
Contributor Author

@yoshuawuyts I had a similar change of heart, flat > nested in most cases. However, I'm not sure if I feel this way because it's better or because I've just grown tired of swimming upstream or perhaps both.

@yoshuawuyts
Copy link

yeah, it might be a bit of both for me - became tired of explaining all this stuff to people and debugging it across operating systems. Feel like flat hierarchies are generally good enough - especially when engineering it in such a way that stuff can be refactored out of the project at some point when needed - it's like eventual modularization (which can be admittedly tricky)

@othiym23
Copy link
Contributor

othiym23 commented Sep 1, 2016

The CLI team has pointed a lot of people who want something like this at linklocal over the last couple years. That says to us that this is functionality that’s broadly useful, and would be even more useful if it were available in the CLI out of the box. That said, being honest with ourselves and the rest of y’all, this isn’t more important than a lot of the other work on the CLI team’s to-do list, and as such we are unlikely to do the work to integrate this ourselves.

Were an enterprising soul (say, perhaps, the original author of linklocal) to start a patch to bring this into the CLI, it should probably be an optional behavior (with the eventual goal of making the default behavior to use links). I was thinking that putting it behind a --local switch so you get the new linking behavior for either npm link --local or npm install --local would be a pretty easy to learn and remember way of invoking this new behavior.

Because this isn’t something the CLI team is likely to get to in the next year or so, I’m going to close this feature request. Because this is also behavior the CLI team would be happy to see added to the CLI, I’ve added the patch-welcome label to the issue. Feel free to ask questions about how this might get integrated or to send us half-baked exploratory PRs once you have something you want people to play with. Thanks to all for their time and contributions!

@timoxley
Copy link
Contributor Author

timoxley commented Mar 2, 2017

Looks like this might be happening 🎉 See: #15900

@akosyakov
Copy link

@timoxley How packages referenced outside of the current package are handled by linklocal, e.g. in a case with siblings? My concerns are here.

@z-vr
Copy link

z-vr commented Sep 27, 2017

This is a horrible idea, I cannot debug my apps in a monorepo, for example a dependency installs debug package, but because it is required within the dependency folder and not the project folder, my editor won't pause there and I just spent an hour trying to figure out why the breakpoint is not working. It makes no sense why not to install file dependency property instead of doing this. -- to whoever thought this was a good idea. npm5 is so rubbish.

@z-vr
Copy link

z-vr commented Sep 27, 2017

If you update your local dependency code, you should install the package again just as you would with any other dependency. Honestly WTH?

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

No branches or pull requests

10 participants