Skip to content

Commit 43947b4

Browse files
authored
fix: compatible with CJS (#486)
1 parent 99c476e commit 43947b4

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

src/core/options.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { join, resolve } from 'path'
2-
import { createRequire } from 'module'
32
import { slash, toArray } from '@antfu/utils'
4-
import { isPackageExists } from 'local-pkg'
3+
import { getPackageInfoSync, isPackageExists } from 'local-pkg'
54
import type { ComponentResolver, ComponentResolverObject, Options, ResolvedOptions } from '../types'
65
import { detectTypeImports } from './type-imports/detect'
76

@@ -76,14 +75,7 @@ export function resolveOptions(options: Options, root: string): ResolvedOptions
7675
return resolved
7776
}
7877

79-
const _require = typeof require === 'undefined' ? createRequire(import.meta.url) : require
8078
function getVueVersion() {
81-
try {
82-
const vue = _require('vue')
83-
const version = vue?.default?.version || vue?.version || '3'
84-
return version.startsWith('2.') ? 'vue2' : 'vue3'
85-
}
86-
catch {
87-
return null
88-
}
79+
const version = getPackageInfoSync('vue')?.version || '3'
80+
return version.startsWith('2.') ? 'vue2' : 'vue3'
8981
}

0 commit comments

Comments
 (0)