Skip to content

Commit

Permalink
feat!: add Vue2 export and deprecate Vue (#43)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

- Named export `Vue` is depreacted, use `Vue2` export instead in Vue 2 or named exports in Vue 3.
  • Loading branch information
Justineo authored Feb 27, 2021
1 parent e9639af commit 3620a54
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 9 deletions.
19 changes: 14 additions & 5 deletions .github/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const fs = require('fs')
const { join } = require('path')
const { execSync, exec } = require('child_process')
const { execSync } = require('child_process')

const DIR = '../vue-demi-test'

const [install, version, source="file:../vue-demi"] = process.argv.slice(2)
const [install, version, source='file:../vue-demi'] = process.argv.slice(2)

isVue2 = version === '2'

Expand All @@ -24,9 +24,18 @@ if (!cjs.includes(`exports.isVue2 = ${isVue2}`)) {
process.exit(1)
}

const value = execSync('node -e "console.log(require(\'vue-demi\').isVue2)"', { cwd: DIR }).toString().trim()
const is2 = execSync('node -e "console.log(require(\'vue-demi\').isVue2)"', { cwd: DIR }).toString().trim()

if (value !== `${isVue2}`) {
console.log("eval", value)
if (is2 !== `${isVue2}`) {
console.log('isVue2', is2)
process.exit(1)
}

const has2 = execSync('node -e "console.log(require(\'vue-demi\').Vue2 !== undefined)"', { cwd: DIR }).toString().trim()

if (has2 !== `${isVue2}`) {
console.log('has2', has2)
console.log('is2', is2)
console.log('cjs', cjs)
process.exit(1)
}
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,26 @@ if (isVue2) {
}
```

### `Vue2`

To avoid bringing in all the tree-shakable modules, we provide a `Vue2` export to support access to Vue 2's global API. (See [#41](https://github.com/vueuse/vue-demi/issues/41).)

```ts
import { Vue2 } from 'vue-demi'

if (Vue2) {
Vue2.config.ignoredElements.push('x-foo')
}
```

### `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)
install()
```

## CLI
Expand Down Expand Up @@ -101,10 +112,12 @@ import * as Vue from 'vue3'

var isVue2 = false
var isVue3 = true
var Vue2 = undefined

export * from 'vue3'
export {
Vue,
Vue2,
isVue2,
isVue3,
}
Expand Down
2 changes: 2 additions & 0 deletions lib/index.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
VueDemi.isVue3 = false
VueDemi.install = function (){}
VueDemi.Vue = Vue
VueDemi.Vue2 = Vue
VueDemi.version = Vue.version
} else {
console.error(
Expand All @@ -29,6 +30,7 @@
VueDemi.isVue3 = true
VueDemi.install = function (){}
VueDemi.Vue = Vue
VueDemi.Vue2 = undefined
VueDemi.version = Vue.version
VueDemi.set = function(target, key, val) {
if (Array.isArray(target)) {
Expand Down
1 change: 1 addition & 0 deletions lib/v2/index.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Object.keys(VueCompositionAPI).forEach(function(key) {
})

exports.Vue = Vue
exports.Vue2 = Vue
exports.isVue2 = true
exports.isVue3 = false
exports.install = install
Expand Down
9 changes: 8 additions & 1 deletion lib/v2/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import Vue from 'vue'
declare const isVue2: boolean
declare const isVue3: boolean
declare const Vue2: Vue | undefined
declare const version: string
declare const install: (vue?: Vue) => void
/**
* @deprecated To avoid bringing in all the tree-shakable modules, this API has been deprecated. Use `Vue2` or named exports instead.
* Refer to https://github.com/vueuse/vue-demi/issues/41
*/
declare const V: Vue

export * from '@vue/composition-api'
export {
Vue,
V as Vue,
Vue2,
isVue2,
isVue3,
version,
Expand Down
2 changes: 2 additions & 0 deletions lib/v2/index.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ install(Vue)

var isVue2 = true
var isVue3 = false
var Vue2 = Vue
var version = Vue.version

/**VCA-EXPORTS**/
Expand All @@ -19,6 +20,7 @@ export * from '@vue/composition-api'

export {
Vue,
Vue2,
isVue2,
isVue3,
version,
Expand Down
1 change: 1 addition & 0 deletions lib/v3/index.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ exports.del = function(target, key) {
}

exports.Vue = Vue
exports.Vue2 = undefined
exports.isVue2 = false
exports.isVue3 = true
exports.install = function(){}
9 changes: 8 additions & 1 deletion lib/v3/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import * as Vue from 'vue'
declare const isVue2: boolean
declare const isVue3: boolean
declare const Vue2: any
declare const install: (vue?: any) => void
/**
* @deprecated To avoid bringing in all the tree-shakable modules, this API has been deprecated. Use `Vue2` or named exports instead.
* Refer to https://github.com/vueuse/vue-demi/issues/41
*/
declare const V: Vue

export function set<T>(target: any, key: any, val: T): T
export function del(target: any, key: any)

export * from 'vue'
export {
Vue,
V as Vue,
Vue2,
isVue2,
isVue3,
install,
Expand Down
2 changes: 2 additions & 0 deletions lib/v3/index.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Vue from 'vue'

var isVue2 = false
var isVue3 = true
var Vue2 = undefined

function install() {}

Expand All @@ -26,6 +27,7 @@ export function del(target, key) {
export * from 'vue'
export {
Vue,
Vue2,
isVue2,
isVue3,
install,
Expand Down

0 comments on commit 3620a54

Please sign in to comment.