sherif icon indicating copy to clipboard operation
sherif copied to clipboard

[Feature Request] - Missing dependencies

Open Netail opened this issue 1 year ago • 5 comments

Summary

When working in a mono repo, you can import packages from the node_modules which are used by other packages within the mono repo, but not listed in the dependency list of the package you are working in. It might be nice to give the user a heads up to include the dependency in their dependency list too.

Example

{
  "name": "package-a",
  "dependencies": {
    "react": "^18"
  }
}
{
  "name": "package-b",
  "dependencies": {
    "react": "^18"
  }
}
{
  "name": "package-c",
  "dependencies": {}
}

As both package a & b use react, the react is installed in the root node_modules, thus allowing it to be imported by package c too. When react is also used in the source code of package c, it should be listed in the dependency or dev dependency list

Netail avatar Aug 11 '24 19:08 Netail

That's a cool idea, but I'm not sure how we could reliably detect if another package is using a dependency that isn't specified in its own dependencies / devDependencies. At a first glance, we would have to analyze the source code for all packages to detect any import statements, which might be expensive.

Do you have any other idea in mind?

QuiiBz avatar Aug 12 '24 07:08 QuiiBz

That's a good question, to which I do not have the answer to :(

Netail avatar Aug 13 '24 09:08 Netail

eslint-plugin-import has a similar rule.

alSergey avatar Sep 03 '24 20:09 alSergey

eslint-plugin-import has a similar rule.

Does it work with monorepo's?

Netail avatar Sep 03 '24 20:09 Netail

Yes, it looks for dependencies in the nearest package.json file. I use it in my monorepo.

alSergey avatar Sep 03 '24 20:09 alSergey

Closing in favor of https://github.com/QuiiBz/sherif/issues/121, see https://github.com/QuiiBz/sherif/issues/121#issuecomment-2993363062 for a rough idea of how that would work.

QuiiBz avatar Jun 21 '25 06:06 QuiiBz