Comparing version 0.4.5 to 0.5.0
@@ -1,1 +0,1 @@ | ||
module.exports = require('./v2/index.cjs') | ||
module.exports = require('./v3/index.cjs') |
@@ -1,1 +0,1 @@ | ||
export * from './v2/index.d' | ||
export * from './v3/index' |
@@ -1,1 +0,1 @@ | ||
export * from './v2/index.esm' | ||
export * from './v3/index.esm' |
@@ -16,2 +16,3 @@ ;(function (window) { | ||
VueDemi.isVue3 = false | ||
VueDemi.install = function (){} | ||
VueDemi.Vue = Vue | ||
@@ -30,2 +31,3 @@ VueDemi.version = Vue.version | ||
VueDemi.isVue3 = true | ||
VueDemi.install = function (){} | ||
VueDemi.Vue = Vue | ||
@@ -32,0 +34,0 @@ VueDemi.version = Vue.version |
var Vue = require('vue') | ||
var VueCompositionAPI = require('@vue/composition-api') | ||
if (Vue && !Vue['__composition_api_installed__']) { | ||
if (VueCompositionAPI && 'default' in VueCompositionAPI) | ||
Vue.use(VueCompositionAPI.default) | ||
else if (VueCompositionAPI) | ||
Vue.use(VueCompositionAPI) | ||
function install(_vue) { | ||
_vue = _vue || Vue | ||
if (_vue && !_vue['__composition_api_installed__']) { | ||
if (VueCompositionAPI && 'default' in VueCompositionAPI) | ||
_vue.use(VueCompositionAPI.default) | ||
else if (VueCompositionAPI) | ||
_vue.use(VueCompositionAPI) | ||
} | ||
} | ||
install(Vue) | ||
Object.keys(VueCompositionAPI).forEach(function(key) { | ||
@@ -18,2 +23,3 @@ exports[key] = VueCompositionAPI[key] | ||
exports.isVue3 = false | ||
exports.install = install | ||
exports.version = Vue.version |
@@ -5,2 +5,4 @@ import Vue from 'vue' | ||
declare const version: string | ||
declare const install: (vue?: Vue) => void | ||
export * from '@vue/composition-api' | ||
@@ -12,2 +14,3 @@ export { | ||
version, | ||
} | ||
install, | ||
} |
import Vue from 'vue' | ||
import VueCompositionAPI from '@vue/composition-api' | ||
if (Vue && !Vue['__composition_api_installed__']) | ||
Vue.use(VueCompositionAPI) | ||
function install(_vue) { | ||
_vue = _vue || Vue | ||
if (_vue && !_vue['__composition_api_installed__']) | ||
Vue.use(VueCompositionAPI) | ||
} | ||
install(Vue) | ||
var isVue2 = true | ||
@@ -17,2 +22,3 @@ var isVue3 = false | ||
version, | ||
install, | ||
} |
@@ -9,1 +9,2 @@ var Vue = require('vue') | ||
exports.isVue3 = true | ||
exports.install = function(){} |
import * as Vue from 'vue' | ||
declare const isVue2: boolean | ||
declare const isVue3: boolean | ||
declare const install: (vue?: Vue) => void | ||
export * from 'vue' | ||
@@ -9,2 +11,3 @@ export { | ||
isVue3, | ||
install, | ||
} |
@@ -6,2 +6,4 @@ import * as Vue from 'vue' | ||
function install() {} | ||
export * from 'vue' | ||
@@ -12,2 +14,3 @@ export { | ||
isVue3, | ||
install, | ||
} |
{ | ||
"name": "vue-demi", | ||
"version": "0.4.5", | ||
"version": "0.5.0", | ||
"main": "lib/index.cjs.js", | ||
@@ -24,4 +24,5 @@ "typings": "lib/index.d.ts", | ||
"bin": { | ||
"vue-demi-fix": "./scripts/postinstall.js" | ||
"vue-demi-fix": "./scripts/postinstall.js", | ||
"vue-demi-switch": "./scripts/switch-cli.js" | ||
} | ||
} |
@@ -52,6 +52,8 @@ <p align="center"> | ||
`Vue Demi` provides extra APIs `isVue2` and `isVue3` to help distinguishing users' environments and to do some version specific logics. | ||
`Vue Demi` provides extra APIs to help distinguishing users' environments and to do some version-specific logics. | ||
### `isVue2` `isVue3` | ||
```ts | ||
import { isVue2 } from 'vue-demi' | ||
import { isVue2, isVue3 } from 'vue-demi' | ||
@@ -65,2 +67,29 @@ if (isVue2) { | ||
### `install()` | ||
Composition API in Vue 2 is provided as a plugin and need to install to Vue instance before using. Normally, `vue-demi` will try to install it automatically. For some usages that you might need to ensure the plugin get installed correctly, the `install()` API is exposed to as a safe version of `Vue.use(CompositionAPI)`. `install()` in Vue 3 environment will be an empty function (no-op). | ||
```ts | ||
import Vue from 'vue' | ||
import { install } from 'vue-demi' | ||
install(Vue) | ||
``` | ||
### CLI | ||
To explicitly switch the redirecting version, you can use these commands in your project's root. | ||
```bash | ||
npx vue-demi-switch 2 | ||
# or | ||
npx vue-demi-switch 3 | ||
``` | ||
If the `postinstall` hook doesn't get triggered or you have updated the Vue version, try to run the following command to resolve the redirecting. | ||
```bash | ||
npx vue-demi-fix | ||
``` | ||
## Examples | ||
@@ -83,15 +112,4 @@ | ||
<details> | ||
<summary>Redirecting Reslove</summary> | ||
<br> | ||
If the script doesn't get triggered or you have updated the Vue version, try to run the following command to resolve the redirecting. | ||
```bash | ||
npx vue-demi-fix | ||
``` | ||
</details> | ||
## License | ||
MIT License © 2020 [Anthony Fu](https://github.com/antfu) |
@@ -1,6 +0,3 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const switchVersion = require('./switch') | ||
const dir = path.resolve(__dirname, '..') | ||
function loadModule(name) { | ||
@@ -14,8 +11,2 @@ try { | ||
function switchVersion(version) { | ||
fs.writeFileSync(path.join(dir, 'lib', 'index.cjs.js'), `module.exports = require('./v${version}/index.cjs')\n`, 'utf-8') | ||
fs.writeFileSync(path.join(dir, 'lib', 'index.esm.js'), `export * from './v${version}/index.esm'\n`, 'utf-8') | ||
fs.writeFileSync(path.join(dir, 'lib', 'index.d.ts'), `export * from './v${version}/index'\n`, 'utf-8') | ||
} | ||
const Vue = loadModule('vue') | ||
@@ -22,0 +13,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9290
16
168
113