Skip to content

Commit 8bbac82

Browse files
committed
fix(checker): ensure paths are defined in checker
1 parent dcb0bf0 commit 8bbac82

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/parser/checker.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createCheckerByJson } from "vue-component-meta"
22
import type { MetaCheckerOptions } from 'vue-component-meta'
3-
import { existsSync } from "fs"
3+
import { existsSync, readFileSync } from "fs"
4+
import { joinURL } from "ufo"
45

56
export interface Options {
67
rootDir: string
@@ -11,6 +12,18 @@ export interface Options {
1112
}
1213

1314
export function createMetaChecker(opts: Options) {
15+
const baseUrl = joinURL(opts.rootDir, '.nuxt');
16+
let paths: Record<string, string[]> | undefined = undefined;
17+
try {
18+
const appTsconfig = JSON.parse(readFileSync(joinURL(baseUrl, 'tsconfig.app.json'), 'utf8'));
19+
const sharedTsconfig = JSON.parse(readFileSync(joinURL(baseUrl, 'tsconfig.shared.json'), 'utf8'));
20+
paths = {
21+
...appTsconfig.compilerOptions.paths,
22+
...sharedTsconfig.compilerOptions.paths,
23+
}
24+
} catch {
25+
// Failed to load tsconfig.app.json or tsconfig.shared.json, ignore
26+
}
1427
return createCheckerByJson(
1528
opts.rootDir,
1629
{
@@ -22,7 +35,8 @@ export function createMetaChecker(opts: Options) {
2235
? tryResolveTypesDeclaration(path)
2336
: `${path}/**/*`
2437
}),
25-
exclude: []
38+
exclude: [],
39+
...(paths ? { compilerOptions: { baseUrl, paths } } : {})
2640
},
2741
opts.checkerOptions || {
2842
forceUseTs: true,

0 commit comments

Comments
 (0)