Skip to content

Commit 6b22580

Browse files
committed
fix: try to find typescript declaration file for node_module components
1 parent 08b7b72 commit 6b22580

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/parser/index.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,37 @@ export function getComponentMeta(component: string, options?: Options): Componen
5757
* @returns component meta
5858
*/
5959
function _getComponentMeta(fullPath: string, opts: Options) {
60+
// Check if the component is in node_modules and adjust configuration accordingly
61+
const isNodeModule = fullPath.includes('node_modules')
62+
63+
// For node_modules components, try to find the TypeScript declaration file first
64+
let resolvedPath = fullPath
65+
if (isNodeModule && fullPath.endsWith('.vue')) {
66+
// Try different TypeScript declaration file patterns
67+
const patterns = [
68+
fullPath.replace('.vue', '.d.vue.ts'),
69+
fullPath.replace('.vue', '.vue.d.ts'),
70+
fullPath.replace('.vue', '.d.ts')
71+
]
72+
73+
for (const pattern of patterns) {
74+
if (existsSync(pattern)) {
75+
resolvedPath = pattern
76+
break
77+
}
78+
}
79+
}
80+
6081
const checker = createCheckerByJson(
6182
opts.rootDir,
6283
{
6384
extends: `${opts.rootDir}/tsconfig.json`,
6485
skipLibCheck: true,
65-
include: [fullPath],
86+
include: [resolvedPath],
6687
exclude: []
67-
},
68-
)
88+
}
89+
);
6990
return refineMeta(
70-
checker.getComponentMeta(fullPath)
91+
checker.getComponentMeta(resolvedPath)
7192
)
7293
}

0 commit comments

Comments
 (0)