Skip to content

Commit

Permalink
fix: ensure moduleResolution option in compilerOptions
Browse files Browse the repository at this point in the history
fix #277
  • Loading branch information
qmhc committed Oct 24, 2023
1 parent 9382c60 commit 01528a4
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -58,7 +58,7 @@
"@vue/language-core": "^1.8.8",
"debug": "^4.3.4",
"kolorist": "^1.8.0",
"vue-tsc": "^1.8.8"
"vue-tsc": "^1.8.20"
},
"devDependencies": {
"@commitlint/cli": "^17.7.1",
Expand Down
68 changes: 55 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 19 additions & 7 deletions src/plugin.ts
Expand Up @@ -245,6 +245,9 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
: undefined

compilerOptions = {
// (#277) If user don't specify `moduleResolution` in top config file,
// declaration of Vue files will be inferred to `any` type.
moduleResolution: ts.ModuleResolutionKind.Node10,
...(content?.options || {}),
...(options.compilerOptions || {}),
...fixedCompilerOptions,
Expand Down Expand Up @@ -298,13 +301,22 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {

filter = createFilter(include, exclude)

const rootNames = Object.values(entries)
.map(entry => ensureAbsolute(entry, root))
.concat(content?.fileNames.filter(filter) || [])
.map(normalizePath)

host = ts.createCompilerHost(compilerOptions, true)
program = createProgram({ host, rootNames, options: compilerOptions })
const rootNames = [
...new Set(
Object.values(entries)
.map(entry => ensureAbsolute(entry, root))
.concat(content?.fileNames.filter(filter) || [])
.map(normalizePath)
)
]

host = ts.createCompilerHost(compilerOptions)
program = createProgram({
host,
rootNames,
projectReferences: content?.projectReferences,
options: compilerOptions
})

libName = toCapitalCase(libName || '_default')
indexName = indexName || defaultIndex
Expand Down

0 comments on commit 01528a4

Please sign in to comment.