From 01528a45050ecae81ff2b2a836839e0e3d468824 Mon Sep 17 00:00:00 2001 From: qmhc <40221744+qmhc@users.noreply.github.com> Date: Tue, 24 Oct 2023 10:06:59 +0800 Subject: [PATCH] fix: ensure `moduleResolution` option in compilerOptions fix #277 --- package.json | 2 +- pnpm-lock.yaml | 68 ++++++++++++++++++++++++++++++++++++++++---------- src/plugin.ts | 26 +++++++++++++------ 3 files changed, 75 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 9d628c2..4edd5c8 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a57c85e..a3163c7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,8 +29,8 @@ importers: specifier: ^1.8.0 version: 1.8.0 vue-tsc: - specifier: ^1.8.8 - version: 1.8.8(typescript@5.1.6) + specifier: ^1.8.20 + version: 1.8.20(typescript@5.1.6) devDependencies: '@commitlint/cli': specifier: ^17.7.1 @@ -2192,16 +2192,28 @@ packages: '@volar/source-map': 1.10.0 dev: false + /@volar/language-core@1.10.4: + resolution: {integrity: sha512-Na69qA6uwVIdA0rHuOc2W3pHtVQQO8hCNim7FOaKNpRJh0oAFnu5r9i7Oopo5C4cnELZkPNjTrbmpcCTiW+CMQ==} + dependencies: + '@volar/source-map': 1.10.4 + dev: false + /@volar/source-map@1.10.0: resolution: {integrity: sha512-/ibWdcOzDGiq/GM1JU2eX8fH1bvAhl66hfe8yEgLEzg9txgr6qb5sQ/DEz5PcDL75tF5H5sCRRwn8Eu8ezi9mw==} dependencies: muggle-string: 0.3.1 dev: false - /@volar/typescript@1.10.0: - resolution: {integrity: sha512-OtqGtFbUKYC0pLNIk3mHQp5xWnvL1CJIUc9VE39VdZ/oqpoBh5jKfb9uJ45Y4/oP/WYTrif/Uxl1k8VTPz66Gg==} + /@volar/source-map@1.10.4: + resolution: {integrity: sha512-RxZdUEL+pV8p+SMqnhVjzy5zpb1QRZTlcwSk4bdcBO7yOu4rtEWqDGahVCEj4CcXour+0yJUMrMczfSCpP9Uxg==} dependencies: - '@volar/language-core': 1.10.0 + muggle-string: 0.3.1 + dev: false + + /@volar/typescript@1.10.4: + resolution: {integrity: sha512-BCCUEBASBEMCrz7qmNSi2hBEWYsXD0doaktRKpmmhvb6XntM2sAWYu6gbyK/MluLDgluGLFiFRpWgobgzUqolg==} + dependencies: + '@volar/language-core': 1.10.4 dev: false /@vue/babel-helper-vue-transform-on@1.0.2: @@ -2317,6 +2329,25 @@ packages: - supports-color dev: true + /@vue/language-core@1.8.20(typescript@5.1.6): + resolution: {integrity: sha512-vNJaqjCTSrWEr+erSq6Rq0CqDC8MOAwyxirxwK8esOxd+1LmAUJUTG2p7I84Mj1Izy5uHiHQAkRTVR2QxMBY+A==} + peerDependencies: + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@volar/language-core': 1.10.4 + '@volar/source-map': 1.10.4 + '@vue/compiler-dom': 3.3.4 + '@vue/shared': 3.3.4 + computeds: 0.0.1 + minimatch: 9.0.3 + muggle-string: 0.3.1 + typescript: 5.1.6 + vue-template-compiler: 2.7.14 + dev: false + /@vue/language-core@1.8.8(typescript@5.1.6): resolution: {integrity: sha512-i4KMTuPazf48yMdYoebTkgSOJdFraE4pQf0B+FTOFkbB+6hAfjrSou/UmYWRsWyZV6r4Rc6DDZdI39CJwL0rWw==} peerDependencies: @@ -2385,11 +2416,11 @@ packages: resolution: {integrity: sha512-7OjdcV8vQ74eiz1TZLzZP4JwqM5fA94K6yntPS5Z25r9HDuGNzaGdgvwKYq6S+MxwF0TFRwe50fIR/MYnakdkQ==} dev: false - /@vue/typescript@1.8.8(typescript@5.1.6): - resolution: {integrity: sha512-jUnmMB6egu5wl342eaUH236v8tdcEPXXkPgj+eI/F6JwW/lb+yAU6U07ZbQ3MVabZRlupIlPESB7ajgAGixhow==} + /@vue/typescript@1.8.20(typescript@5.1.6): + resolution: {integrity: sha512-F0XX1wK71Fo9ewtzLSCSo5dfOuwKrSi/dR2AlI00iTJ4Bfk0wq1BNTRgnlvfx4kz/vQovaGXqwpIkif14W9KrA==} dependencies: - '@volar/typescript': 1.10.0 - '@vue/language-core': 1.8.8(typescript@5.1.6) + '@volar/typescript': 1.10.4 + '@vue/language-core': 1.8.20(typescript@5.1.6) transitivePeerDependencies: - typescript dev: false @@ -2891,6 +2922,10 @@ packages: dot-prop: 5.3.0 dev: true + /computeds@0.0.1: + resolution: {integrity: sha512-7CEBgcMjVmitjYo5q8JTJVra6X5mQ20uTThdK+0kR7UEaDrAWEQcRiBtWJzga4eRpP6afNwwLsX2SET2JhVB1Q==} + dev: false + /concat-map@0.0.1: resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} dev: true @@ -5146,6 +5181,13 @@ packages: dependencies: brace-expansion: 2.0.1 + /minimatch@9.0.3: + resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==} + engines: {node: '>=16 || 14 >=14.17'} + dependencies: + brace-expansion: 2.0.1 + dev: false + /minimist-options@4.1.0: resolution: {integrity: sha512-Q4r8ghd80yhO/0j1O3B2BjweX3fiHg9cdOwjJd2J76Q135c+NDxGCqdYKQ1SKBuFfgWbAUzBfvYjPUEeNgqN1A==} engines: {node: '>= 6'} @@ -6907,14 +6949,14 @@ packages: he: 1.2.0 dev: false - /vue-tsc@1.8.8(typescript@5.1.6): - resolution: {integrity: sha512-bSydNFQsF7AMvwWsRXD7cBIXaNs/KSjvzWLymq/UtKE36697sboX4EccSHFVxvgdBlI1frYPc/VMKJNB7DFeDQ==} + /vue-tsc@1.8.20(typescript@5.1.6): + resolution: {integrity: sha512-bIADlyxJl+1ZWQQHAi47NZoi2iTiw/lBwQLL98wXROcQlUuGVtyroAIiqvto9pJotcyhtU0JbGvsHN6JN0fYfg==} hasBin: true peerDependencies: typescript: '*' dependencies: - '@vue/language-core': 1.8.8(typescript@5.1.6) - '@vue/typescript': 1.8.8(typescript@5.1.6) + '@vue/language-core': 1.8.20(typescript@5.1.6) + '@vue/typescript': 1.8.20(typescript@5.1.6) semver: 7.5.4 typescript: 5.1.6 dev: false diff --git a/src/plugin.ts b/src/plugin.ts index 4ab8528..d94492c 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -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, @@ -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