-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
no-extraneous-dependencies only targets one package.json #935
Comments
Also related to #458 which allows for a single package folder to be set. But in this case, I have multiple.. |
It walks up the tree until it finds |
Yes, it shouldn't. It should keep walking and find all of the |
Can you provide a concrete example of what problem you need solved? |
Sure, I have a Lerna monorepo which has several packages that contain tests that make use of Chai and Sinon. Since I don't want to install those in all packages, I installed it at the root level. This works perfectly well, except that this rule is complaining. |
That's not how a lerna monorepo is supposed to be organized tho; lerna bootstrap is supposed to install all those as dev deps via npm link. Each package in that multirepo is supposed to be able to function as if it was the root of the repo. |
Hmm thats not true though. Just look at the Babel repository for example. Besides this works because of the way node works. So why shouldn't it work here?
|
The babel repo isn't the best example for the best way to set up a lerna monorepo :-) Regardless, does that mean you're running the linter per-package? |
No I'm running the linter for all packages at once. Each package has their own .eslintrc file however.
|
Gotcha. While I think that organizing your repo this way is a very bad practice, I agree that since node does it, this plugin should support it - at least up to the dir in which eslint is run (traversing upwards from there could hide bugs if there's |
Aside from this issue, what would be your suggested way of organizing such a repo?
|
I'd suggest making each dir inside Then, the root |
Lerna docs disagree: https://github.com/lerna/lerna#common-devdependencies |
I'm using "supposed" here based on community best practices; if Lerna documentation deviates from that, Lerna is wrong. |
I guess you can make both work by having Lerna hoist certain dev dependencies. This will make each module still self-contained, but you'll also run into this problem potentially. |
Yes, lerna should only hoist deps when the versions are the same; if it doesn’t work this way now, it’s a bug. |
Any update on this? I would like to use this rule, but I can't until it works properly. |
|
+1 i feel like this could be solved by providing a way to configure lookup paths for a |
@ljharb hopefully this is a concrete example of why you would want some dependencies to be at the root of a monorepo. I have a monorepo, one of the packages is a dev tool to generate documentation that is a devDependency of a lot of other packages. I only expect to run this tool with the package checked out under the monorepo structure. I can either:
Unfortunately, if I do (1), then make a code change to the tool and then run I only want to republish packages when dependencies that are relevant to users outside of the monorepo structure change, so I am considering putting devDependencies like these on the monorepo's root package.json. Project specific issue: govuk-react/govuk-react#175 (comment) Alternatively, it would be nice for no-extraneous-dependencies config to accept an array of whitelisted dependencies so that should not error if missing. |
https://github.com/benmosher/eslint-plugin-import#importcore-modules |
@penx tbh that sounds like a flaw (not the only one) in |
@penx Just turn off brittle ---
# repo-root .eslintrc.yaml
root: true
plugins:
# or just extend airbnb ¯\_(ツ)_/¯
- import
rules:
import/no-extraneous-dependencies: error
# ↓ this is the important part
overrides:
- files: "**/*{-,.}{test,stories}.js"
rules:
# devDependencies are all in the root
import/no-extraneous-dependencies: off
@ljharb Citation needed? |
The reasons to "bother" with a multi-package repo aren't because you don't want self-sufficient leaf packages, they're because you can make related changes in multiple packages in the same PR, and more easily run tests against multiple packages at once. |
Self-sufficient leaf packages aren’t at all necessary to accomplish those two goals, they’re just a stylistic preference. Repeating the same devDependencies and scripts and configuration &c in every single leaf package is a mind-numbing maintenance burden. |
I think having a config option for I can certainly see the argument for making a package in a monorepo self sufficient so that a developer who only wants to work on one package can just cd to that package and yarn/npm install. For devDependencies that install a CLI tool it is useful to have this on the path when running scripts in a sub project (I'm not sure if .bin from a parent node_modules folder is included in the npm script resolution path, I don't think it is). However I agree with @evocateur that this is a stylistic preference. I also find the maintenance of repeated devDependencies a pain, and can see the benefit of certain devDependencies (that are only used by files that assume they are being run as part of the monorepo) to be in the root package.json. |
@ljharb I view this as a debate of correctness vs efficiency/what's practical. I believe I have a very valid use case for needing to hoist dev dependencies to monorepo root. I don't think being "correct" is worth the trade of a poorer dev environment. Not to.mention, the difference also has performance implications - Using leaf packages for dev dependencies being far less work for installs. I also think it's inappropriate to suggest that it's not a valid concern all because you personally find it ugly. |
Fixes #175 (hopefully) Updates to a devDependency for a package causes `lerna publish` to republish that package. This has a knock on effect throughout our repo meaning a single change to one component can result in every component being republished. We don't want this to happen so are including most devDependencies at the project root (where we expect these dependencies are only used when using the package as part of a monorepo). Exceptions are where a component has specific peerDependencies and we want to also represent that in the devDependencies. Related: lerna/lerna#1269 lerna/lerna#1345 import-js/eslint-plugin-import#935
In the Node.js environment, a call using
require()
will walk up the tree to find the dependency, this means that a dependency that is required can be in anynode_modules
folder up the tree. Currently it only looks at one folder.Could this be adjusted?
The text was updated successfully, but these errors were encountered: