eslint-plugin: ignore type imports when checking deps

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-02-03 16:15:48 +01:00
parent d5eee2944c
commit 58e481a4f9
2 changed files with 44 additions and 11 deletions
@@ -146,6 +146,10 @@ module.exports = {
if (imp.type !== 'external') {
return;
}
// We leave checking of type imports to the repo-tools check
if (imp.kind === 'type') {
return;
}
const modulePath = path.relative(localPkg.dir, filePath);
const expectedType = getExpectedDepType(
@@ -161,6 +165,18 @@ module.exports = {
);
if (conflict) {
try {
const fullImport = imp.path
? `${imp.packageName}/${imp.path}`
: imp.packageName;
require.resolve(fullImport, {
paths: [localPkg.dir],
});
} catch {
// If the dependency doesn't resolve then it's likely a type import, ignore
return;
}
const packagePath = path.relative(packages.root.dir, localPkg.dir);
const packageJsonPath = path.join(packagePath, 'package.json');