Inline eslint-import-resolver-typescript
This commit is contained in:
20
src/index.ts
20
src/index.ts
@ -1,5 +1,5 @@
|
||||
import Module from 'module';
|
||||
import type { ESLintConfig } from 'eslint-define-config';
|
||||
import './redirect';
|
||||
// @ts-expect-error
|
||||
const { name } = (0, require)('./package.json');
|
||||
|
||||
@ -24,7 +24,7 @@ export function extendConfig({
|
||||
extends: _extends,
|
||||
overrides,
|
||||
...rest
|
||||
}: ESLintConfig): ESLintConfig {
|
||||
}: ESLintConfig = {}): ESLintConfig {
|
||||
const hasReact = plugins?.includes('react');
|
||||
const hasUnicorn = plugins?.includes('unicorn');
|
||||
const hasReactRefresh = plugins?.includes('react-refresh');
|
||||
@ -200,19 +200,3 @@ export function extendConfig({
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const _resolveFilename = (Module as any)._resolveFilename;
|
||||
(Module as any)._resolveFilename = function (module: string, ...args: any[]) {
|
||||
switch (module) {
|
||||
case 'eslint-plugin-import':
|
||||
case 'eslint-plugin-jsx-a11y':
|
||||
case 'eslint-plugin-local':
|
||||
case 'eslint-plugin-react':
|
||||
case 'eslint-plugin-react-hooks':
|
||||
case 'eslint-plugin-rules':
|
||||
case 'eslint-plugin-n':
|
||||
module = `${name}/${module.slice(14)}`;
|
||||
}
|
||||
|
||||
return _resolveFilename(module, ...args);
|
||||
};
|
||||
|
22
src/redirect.ts
Normal file
22
src/redirect.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import Module from 'module';
|
||||
// @ts-expect-error
|
||||
const { name } = (0, require)('./package.json');
|
||||
|
||||
const _resolveFilename = (Module as any)._resolveFilename;
|
||||
const alias = new Set([
|
||||
'eslint-import-resolver-typescript',
|
||||
'eslint-plugin-import',
|
||||
'eslint-plugin-jsx-a11y',
|
||||
'eslint-plugin-local',
|
||||
'eslint-plugin-n',
|
||||
'eslint-plugin-react-hooks',
|
||||
'eslint-plugin-react',
|
||||
'eslint-plugin-rules',
|
||||
]);
|
||||
|
||||
(Module as any)._resolveFilename = function (module: string, ...args: any[]) {
|
||||
if (alias.has(module)) {
|
||||
module = `${name}/${module}`;
|
||||
}
|
||||
return _resolveFilename(module, ...args);
|
||||
};
|
Reference in New Issue
Block a user