Eslint-plugin-import: How to treat imports inside a monorepo as internal

Created on 26 Jun 2018  路  5Comments  路  Source: benmosher/eslint-plugin-import

I am working on a monorepo where I have some files with a list of imports that looks like this:

import React from 'react';

import MyComponent from '@my/src/MyComponent';

import styles from './styles.scss';

In this example, the second import refers to a package inside the monorepo and I would like it to be treated as an internal import by import/order. Is this possible to achieve?

imporexport ordering question

Most helpful comment

Would it be possible to add an option to import/order that allows you to pass a regex to identify internal imports? In that way I could simply specify that all internal imports start with @my.

All 5 comments

Since technically it鈥檚 not internal - that syntax is for npm-installed scoped modules - i don鈥檛 believe it鈥檚 currently possible.

Would it be possible to add an option to import/order that allows you to pass a regex to identify internal imports? In that way I could simply specify that all internal imports start with @my.

Is it not an option to use a prefix that isn't also a valid npm package name?

I don't think that is possible in a monorepo. The packages inside a monorepo will always have valid package names since you have to create a package.json for each one of them. Besides that, I need my packages in the monorepo to be scoped. This is also how other projects like babel and jest are doing it.

Another option would also be to check via the root package.json if the current project is a monorepo, to determine where the modules are located and consider those internal (I mean by reading the workspaces property). Or is this the wrong way around?

I think it should simply be possible for us to specify what's treated as "internal".
See also my comment in https://github.com/benmosher/eslint-plugin-import/issues/807#issuecomment-415358830, which actually belongs here rather than in the other issue.

Was this page helpful?
0 / 5 - 0 ratings