Skip to content

Commit

Permalink
fix: better vueDependency importing, close #564 (#572)
Browse files Browse the repository at this point in the history
Co-authored-by: Javier Pérez <kiroushi@gmail.com>
  • Loading branch information
antfu and kiroushi committed Oct 21, 2020
1 parent e675726 commit 555f20a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/runtimeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ import { assert, hasOwn, warn } from './utils'
let vueDependency: VueConstructor | undefined = undefined

try {
vueDependency = require('vue')
const requiredVue = require('vue')
if (requiredVue && isVue(requiredVue)) {
vueDependency = requiredVue
} else if (
requiredVue &&
'default' in requiredVue &&
isVue(requiredVue.default)
) {
vueDependency = requiredVue.default
}
} catch {
// not available
}
Expand All @@ -15,6 +24,10 @@ let currentInstance: ComponentInstance | null = null

const PluginInstalledFlag = '__composition_api_installed__'

function isVue(obj: any): obj is VueConstructor {
return obj && typeof obj === 'function' && obj.name === 'Vue'
}

export function isPluginInstalled() {
return !!vueConstructor
}
Expand Down

0 comments on commit 555f20a

Please sign in to comment.