-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a means to install package peer dependencies for development / testing #1503
Comments
@jpollard-cs I am not referring to adding a package as a peer dependency, I am referring to having a means to install all packages currently listed as peer dependencies. |
Is there a way to install a declared packages in peerDependencies? My use case is development / testing of a react native module. |
Here's NPM issue, which they closed: npm/npm#11213 Apparently not important to NPM devs. |
+1 this is important for library authors |
I already wrote this on the NPM issue, but for Yarn people: I wrote a cli program install a package's peer dependendencies:
If you have any problems with it please open an issue on the repo! |
@nathanhleung, that package appears to install all of your dependencies peer dependencies. Which isn't quite what this ticket is about. This about installing your own package's peer dependencies. I have fixed it with a package to do that https://www.npmjs.com/package/@team-griffin/install-self-peers |
@nathanhleung you rocks. |
Hmm... If one needs dependencies for development / testing, shouldn't one put them under |
@nikolakanacki Totally see where you're coming from, I think the weirdness is that it'd be both a peer dependency and dev dependency, since you should never force your consumers installing your dev dependencies. I vote making it easy to install peers! |
@nikolakanacki If you author a package that relies on another package that the user installs, you don't want it in devDependencies, that may result in a duplicate of that package in a different version., and won't makes sense in some cases... Use case eslint-find-rulesThe package looks up rules available in ESLint that are not configured in your config. Now if you want to contribute to the project, you want to have ESLint installed in node_modules so you can test your code, without doing some npm-link with a dummy project that installs ESLint. When the user runs So... a flag that makes yarn install peer deps if they're not already installed would kindly solve that problem. Interesting point
|
I'm currently following @nikolakanacki model and it seems to work. I agree it can be confusing and I would prefer a |
If I'm getting this right @kyleholzinger / @gaastonsr, you're not looking to install To clarify: You install If this is your point it could be super useful, I thought that you were referring to auto-installing them when developing. The feature could be introduced for more then pure convenience, for example: multiple dependencies could depend on the same package from the peer target, but require different versions of it - this feature could make the best of it by trying to resolve to a single best-matching target (if possible). Something to think about definitely. |
This is what I'm looking for. Installing peerDependencies when I'm developing a package. |
Yeah exactly @nikolakanacki! I feel like there's a great opportunity for us to help people out with managing their peer deps. |
@gaastonsr need to add it to Two simple and totally unrelated questions one should ask before installing said dependency in cases like this:
In other words: All the packages which are expected to be present during development and are not listed as a direct dependency of the package being developed should reside in |
@nikolakanacki When we build a plugin for a package we should depend on the installed package version by the user, if we add it as a Unless we defined the dependency as Currently it's not so: |
@alexilyaev I think @nikolakanacki means to install it both as a peerDependency and devDependency. This has the problem that we need to keep both in sync. For me it works good for now but I don't think it's ideal. |
@alexilyaev when you declare a Non the less The point is: I don't see how all this is relevant? |
I can see the pain of keeping them in sync, but you could easily write a The point I'm trying to make is that in no way should we break the On the other hand |
@nikolakanacki Let's say my plugin accepts If it does, my plugin might mistakingly use the installed |
@alexilyaev Your package will always, as any other package in any other case, use the highest available version which satisfies the "semver range" defined in your package for this peer dep. I'd be more specific but I don't quite understand the case you've presented, could you please clarify? |
Yarn doesn't install |
@gaastonsr you're absolutely right except that Peer dependencies never get installed, dev dependencies do not get installed by default if the package is not the main package. The "end-user" needs to define which peer dependencies it want's to satisfy by adding them to regular "dependencies" of the project, along with the range. It can either satisfy or not satisfy the "semver range" you require in your plugin, and the user will be notified of the latter. Semver ranges explained by npm: https://docs.npmjs.com/misc/semver |
@nikolakanacki to be able to easily install packages peerdependencies would be great! |
@nikolakanacki Ok, so indeed when the end-user installs the package, So, this solves the local development issue. But, it seems that a lot of projects didn't add the peer dependency as a dev dependency. So... I'm proposing to still support a way to install peer dependencies, at least so we won't have to use |
What's the actual issue here? It does not seem installing one list of deps would be more complicated than installing another list of deps. Peer dependencies have been around for some years. How has this not bothered anyone? |
@nikolakanacki solution makes perfect sense. It's what we're using for our library development. You need There is the small headache of keepin them in sync. But as @nikolakanacki pointed out this could easily be mitigated through some |
This is needed in development because yarn doesn't install peerDependencies by default. Yarn issue: yarnpkg/yarn#1503
npm has this feature now with v7... any reason not add this to yarn? |
@sajadghawami as far as I know, @arcanis has some pretty big reservations about doing this: |
Hi guys! I'm using yarn to develop library which is using peerDeps, so let me add my 5 cents on this topic. I have some UI dependencies (react, react-dom, styled-component, etc) in peerDependecies. I can't add them to devDeps, because it'll cause some issues (for example, web app which will use my library, can't have 2 instances of react / styled-component when versions mismatch). So it makes sense to me to use peerDeps here. But it make a lot of pain for me, because I have storybook and I need react / react-dom to render it and develop components of my library. To solve this right now I need to:
Please, correct me if I'm missing something, but is there any way to make this automatically? I was looking something like "yarn install --with-peers", but didn't find something except some third-party libraries. |
Hi! It doesn't work for my case, because I need react itself to run tests and build / run storybook. |
You are right, I've updated my comment. The point is that you should have playground package/folder for those kind of things. Playground package is used just for hosting libraries. It should provide environment in which you can test or develop you library. That package has all dependencies you need as devDependecies so you can work normaly. If you work with monorepo it should be simple to do it and use your lib as a local dependency. Emotionjs is a great example for this case https://github.com/emotion-js/emotion |
It makes sense, but this approach still has some limitations. For example, your project should have another "playground repo" (in monorepo or independent repo - it's just a technical details). I pretty sure it works, but it still looks like a workaround for me. For example, I'm developing the library. I would like to test (jest) and document (storybook) without any additional repos, because I would like to have smooth automated CI from commit to production (npm registry with new version). So, my library should be able to test it itself. I'm okay to have react in peer and dev deps at the same time (because it looks like react should be checked like peer on install and needed during development to me). But this is also not supported. I found https://github.com/christopherthielen/check-peer-dependencies for now, but I didn't implement needed behavior yet. I'd like yarn to install peer deps on local install and doesn't install them when my lib is used like dependency for another project. Playing with npm scripts right now. |
Adding a reference point in case it helps broaden the context: our use-case is a (large commercial) project that deploys via container environments that do a
For download+build speed, we originally chose an explicit At the project's large size and heavy complexity now, we're considering making the call to pay that cost in slower builds. But it's a horrible trade-off. So is adding "yet another dependency" to manage our dependency installation because our package manager doesn't stretch that far. So we try to choose the lesser of the evils, but that's a moving target as the project evolves. The ideal would be any of the following (which would allow us to separate 'build requirements' into a separate stack of dependencies):
|
Closing as fixed in v2 where you can make a small plugin to install a subset of your dependencies (cherry picking build dependencies out of As an example the |
A more thorough discussion can be found here [1]. [1] yarnpkg/yarn#1503
Why can't yarn just implement auto-peer dependencies installation just like how npm 7 has done? It's much easier and cleaner IMO. I don't want to jump ship, again, but this takes development time just to do something that the other package manager can do out of the box. I believe yarn can do this better than npm. |
@merceyz I think the issue should be reopened. As seen from the reactions, the solution proposed is largely considered suboptimal. npm is indeed way ahead with this. There is a lot of cumulative development time spent dealing with peer dependencies that yarn could easily handle automatically. |
This comment was marked as abuse.
This comment was marked as abuse.
Yea, I agree that you shouldn't need to write a plugin to do this, it's a fairly common use case... |
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
N/A
What is the expected behavior?
Provide a CLI command
yarn install --peer
which will install peer dependencies specified inpackage.json
. That way development / testing can use the peers such as react/ng2/grunt.The text was updated successfully, but these errors were encountered: