Skip to content

Commit

Permalink
fix: correct resolve Vue when create program
Browse files Browse the repository at this point in the history
fix #380
  • Loading branch information
qmhc committed Sep 6, 2024
1 parent 7bbef0c commit 0621332
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 85 deletions.
6 changes: 3 additions & 3 deletions examples/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "react-example",
"version": "0.0.0",
"auth": "qmhc",
"type": "module",
"private": true,
"scripts": {
Expand All @@ -16,7 +15,8 @@
"@types/react-dom": "^18.2.22",
"@vitejs/plugin-react": "^4.2.1",
"tslib": "^2.6.2",
"typescript": "5.5.3",
"typescript": "5.5.4",
"vite": "^5.3.4"
}
},
"auth": "qmhc"
}
1 change: 1 addition & 0 deletions examples/react/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default defineConfig({
},
plugins: [
react(),
// @ts-ignore
dts({
outDir: ['dist', 'types'],
// include: ['src/index.ts'],
Expand Down
4 changes: 2 additions & 2 deletions examples/svelte/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "svelte-example",
"version": "0.0.0",
"author": "qmhc",
"type": "module",
"private": true,
"author": "qmhc",
"scripts": {
"build": "DEBUG=\"vite-plugin-dts:bundle\" vite build"
},
Expand All @@ -13,7 +13,7 @@
"svelte": "^4.2.12",
"svelte-check": "^3.6.8",
"tslib": "^2.6.2",
"typescript": "5.5.3",
"typescript": "5.5.4",
"vite": "^5.3.4"
}
}
1 change: 1 addition & 0 deletions examples/svelte/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default defineConfig({
},
plugins: [
svelte(),
// @ts-ignore
dts({
outDir: ['dist', 'types'],
staticImport: true,
Expand Down
6 changes: 3 additions & 3 deletions examples/ts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "ts-example",
"version": "0.0.0",
"auth": "qmhc",
"type": "module",
"private": true,
"scripts": {
Expand All @@ -11,7 +10,8 @@
"types": "dist/ts-test.d.ts",
"devDependencies": {
"tslib": "^2.6.2",
"typescript": "5.5.3",
"typescript": "5.5.4",
"vite": "^5.3.4"
}
},
"auth": "qmhc"
}
3 changes: 2 additions & 1 deletion examples/ts/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ export default defineConfig({
}
},
plugins: [
// @ts-ignore
dts({
outDir: ['dist', 'types'],
// include: ['src/index.ts'],
exclude: ['src/ignore'],
// aliasesExclude: [/^@components/],
staticImport: true,
// insertTypesEntry: true,
rollupTypes: false,
rollupTypes: true,
declarationOnly: true,
compilerOptions: {
declarationMap: true
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@vitejs/plugin-vue": "^5.0.4",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"tslib": "^2.6.2",
"typescript": "5.5.3",
"typescript": "5.5.4",
"vite": "^5.3.4"
},
"auth": "qmhc"
Expand Down
1 change: 1 addition & 0 deletions examples/vue/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default defineConfig({
}
},
plugins: [
// @ts-ignore
dts({
copyDtsFiles: true,
outDir: [
Expand Down
55 changes: 24 additions & 31 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
outDir,
entryPath: path,
fileName: basename(path),
libFolder: getTsLibFolder({ root, entryRoot }),
libFolder: getTsLibFolder(),
rollupConfig,
rollupOptions
})
Expand Down
11 changes: 2 additions & 9 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@ import {

import { proxyCreateProgram } from '@volar/typescript'
import ts from 'typescript'
import { getPackageInfoSync, resolveModule } from 'local-pkg'
import { removeEmitGlobalTypes } from 'vue-tsc'
import { tryGetPackageInfo } from './utils'

export { createParsedCommandLine }

let hasVue = false

try {
hasVue = !!(
getPackageInfoSync('vue') ??
getPackageInfoSync('svelte', { paths: [resolveModule('svelte') || process.cwd()] })
)
} catch (e) {}
const hasVue = !!tryGetPackageInfo('vue')

// If there has no Vue dependency, we think it's a normal TypeScript project.
// So we use the original createProgram of TypeScript.
Expand Down
6 changes: 2 additions & 4 deletions src/resolvers/svelte.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { relative } from 'node:path'

import { getPackageInfoSync, resolveModule } from 'local-pkg'
import { compare } from 'compare-versions'
import { tryGetPackageInfo } from '../utils'

import type { Resolver } from '../types'

Expand All @@ -13,9 +13,7 @@ function querySvelteVersion() {
if (typeof lowerVersion === 'boolean') return

try {
const version =
getPackageInfoSync('svelte')?.version ??
getPackageInfoSync('svelte', { paths: [resolveModule('svelte') || process.cwd()] })?.version
const version = tryGetPackageInfo('svelte')?.version
lowerVersion = version ? compare(version, '4.0.0', '<') : false
} catch (e) {
lowerVersion = false
Expand Down
6 changes: 2 additions & 4 deletions src/rollup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { resolve } from 'node:path'

import { Extractor, ExtractorConfig } from '@microsoft/api-extractor'
import { tryGetPkgPath } from './utils'
import { resolve, tryGetPkgPath } from './utils'

import type { ExtractorLogLevel, IExtractorInvokeOptions } from '@microsoft/api-extractor'
import type { RollupConfig } from './types'
Expand Down Expand Up @@ -93,7 +91,7 @@ export function rollupDeclarationFiles({
localBuild: false,
showVerboseMessages: false,
showDiagnostics: false,
typescriptCompilerFolder: libFolder ? resolve(libFolder) : undefined,
typescriptCompilerFolder: libFolder,
...rollupOptions
})
}
Loading

0 comments on commit 0621332

Please sign in to comment.