fix(linter): support directories for relative path fix (#16854)
This commit is contained in:
parent
7920fb6a20
commit
62fb39de02
@ -7,7 +7,7 @@ import {
|
|||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { findNodes } from '@nx/js';
|
import { findNodes } from '@nx/js';
|
||||||
import { getModifiers } from '@typescript-eslint/type-utils';
|
import { getModifiers } from '@typescript-eslint/type-utils';
|
||||||
import { existsSync, readFileSync } from 'fs';
|
import { existsSync, lstatSync, readdirSync, readFileSync } from 'fs';
|
||||||
import { dirname } from 'path';
|
import { dirname } from 'path';
|
||||||
import ts = require('typescript');
|
import ts = require('typescript');
|
||||||
|
|
||||||
@ -81,6 +81,16 @@ function hasMemberExport(exportedMember, filePath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getRelativeImportPath(exportedMember, filePath, basePath) {
|
export function getRelativeImportPath(exportedMember, filePath, basePath) {
|
||||||
|
if (lstatSync(filePath).isDirectory()) {
|
||||||
|
const file = readdirSync(filePath).find((file) =>
|
||||||
|
/^index\.[jt]sx?$/.exec(file)
|
||||||
|
);
|
||||||
|
if (file) {
|
||||||
|
filePath = joinPathFragments(filePath, file);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
const fileContent = readFileSync(filePath, 'utf8');
|
const fileContent = readFileSync(filePath, 'utf8');
|
||||||
|
|
||||||
// use the TypeScript AST to find the path to the file where exportedMember is defined
|
// use the TypeScript AST to find the path to the file where exportedMember is defined
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user