Skip to content

Commit 262f0e7

Browse files
committed
fix: fix ts issues
1 parent 36dc2f8 commit 262f0e7

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/rules/prefer-alias.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import pathLib from 'node:path';
22

3-
import { OptionManager } from '@babel/core';
3+
import { loadOptions } from '@babel/core';
44
import defu from '@dword-design/defu';
55
import { resolvePath as defaultResolvePath } from 'babel-plugin-module-resolver';
66

7+
interface BabelPlugin {
8+
key: string;
9+
options?: Record<string, unknown>;
10+
}
11+
interface BabelConfig {
12+
plugins?: BabelPlugin[];
13+
}
714
const isParentImport = path => /^(\.\/)?\.\.\//.test(path);
815

916
const findMatchingAlias = (sourcePath, currentFile, options) => {
@@ -32,16 +39,18 @@ export default {
3239
const folder = pathLib.dirname(currentFile);
3340
// can't check a non-file
3441
if (currentFile === '<text>') return {};
35-
const manager = new OptionManager();
42+
const optionsFromRule = context.options[0] ?? {};
3643

37-
const babelConfig = manager.init({
44+
const babelConfig = (loadOptions({
3845
filename: currentFile,
39-
...context.options[0]?.babelOptions,
40-
});
46+
...optionsFromRule.babelOptions,
47+
}) || {}) as BabelConfig;
4148

42-
const plugin = babelConfig.plugins.find(_ => _.key === 'module-resolver');
49+
const optionsFromPlugin =
50+
babelConfig?.plugins?.find(_ => _.key === 'module-resolver')?.options ??
51+
{};
4352

44-
const options = defu(context.options[0] || {}, plugin?.options || {}, {
53+
const options = defu(optionsFromRule, optionsFromPlugin, {
4554
alias: [],
4655
cwd: context.cwd,
4756
});

0 commit comments

Comments
 (0)