Skip to content

Add setting to specify external modules by package name pattern #1510

Closed
@Blasz

Description

@Blasz

I'm proposing a new setting to specify external modules by a package name pattern to satisfy the following use case:

We have a monorepo consisting of multiple packages that depend on each other. We'd like to enforce that every package that is imported by another package in the same repository is listed as a dependency in package.json. We want to use the import/no-extraneous-dependencies rule to enforce this, however, we can't specify that each package in the monorepo is an external dependency because:

  1. We resolve package dependencies using a custom resolver that resolves packages to their source location
  2. Eslint detects these dependencies as internal modules because their resolved path does not fall under node_modules

In the past, our packages were scoped which resulted in them being treated as external modules because of #1293. However, since that has been fixed we now run into this problem.

The existing import/external-module-folders setting isn't sufficient for us because:

  1. Our packages don't reside as a flat list under a single directory such as node_modules
  2. The package dir name does not match the package name in all cases, especially not with scoped prefixes

Instead, a new import/external-module-patterns setting that allowed one to specify an array of string/regex patterns to match against package names, could be used to match all of our packages as external since they all share a common scope.


A second option could be to add some further metadata in the returned value from custom resolvers to specify whether a module is external or not.


Alternatively, it would be worth revisiting the decision made in #943 to only report errors for dependencies that can be resolved and provide a config option to opt-in to reporting errors for unresolved dependencies. As then, we would no longer need to mark our modules as external and would just remove our custom resolver altogether so that they are always unresolved and therefore marked as external.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions