fix(linter): support ESM js imports in ast utils (#16049)
This commit is contained in:
parent
c3ba5ab66f
commit
89d0b8bf6f
@ -198,19 +198,33 @@ export function getRelativeImportPath(exportedMember, filePath, basePath) {
|
|||||||
|
|
||||||
const modulePath = (exportDeclaration as any).moduleSpecifier.text;
|
const modulePath = (exportDeclaration as any).moduleSpecifier.text;
|
||||||
|
|
||||||
let moduleFilePath = joinPathFragments(
|
let moduleFilePath;
|
||||||
dirname(filePath),
|
if (modulePath.endsWith('.js') || modulePath.endsWith('.jsx')) {
|
||||||
`${modulePath}.ts`
|
moduleFilePath = joinPathFragments(dirname(filePath), modulePath);
|
||||||
);
|
if (!existsSync(moduleFilePath)) {
|
||||||
if (!existsSync(moduleFilePath)) {
|
const tsifiedModulePath = modulePath.replace(/\.js(x?)$/, '.ts$1');
|
||||||
// might be a tsx file
|
moduleFilePath = joinPathFragments(
|
||||||
|
dirname(filePath),
|
||||||
|
`${tsifiedModulePath}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (modulePath.endsWith('.ts') || modulePath.endsWith('.tsx')) {
|
||||||
|
moduleFilePath = joinPathFragments(dirname(filePath), modulePath);
|
||||||
|
} else {
|
||||||
moduleFilePath = joinPathFragments(
|
moduleFilePath = joinPathFragments(
|
||||||
dirname(filePath),
|
dirname(filePath),
|
||||||
`${modulePath}.tsx`
|
`${modulePath}.ts`
|
||||||
);
|
);
|
||||||
|
if (!existsSync(moduleFilePath)) {
|
||||||
|
// might be a tsx file
|
||||||
|
moduleFilePath = joinPathFragments(
|
||||||
|
dirname(filePath),
|
||||||
|
`${modulePath}.tsx`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!existsSync(moduleFilePath)) {
|
if (!existsSync(moduleFilePath)) {
|
||||||
// might be a index.ts
|
// might be an index.ts
|
||||||
moduleFilePath = joinPathFragments(
|
moduleFilePath = joinPathFragments(
|
||||||
dirname(filePath),
|
dirname(filePath),
|
||||||
`${modulePath}/index.ts`
|
`${modulePath}/index.ts`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user