-import { defineConfig, Plugin } from 'vite'
+import { defineConfig, type Plugin } from 'vite'
import _fs from 'fs'
import path from 'path'
// import TypeDocPlugin from './vite-typedoc-plugin'
__BROWSER__: 'true',
},
optimizeDeps: {
- exclude: ['vue-demi', '@vueuse/shared', '@vueuse/core', 'pinia'],
+ exclude: ['@vueuse/shared', '@vueuse/core', 'pinia'],
},
})
+++ /dev/null
-import _Vue2 from 'vue'
-import { createPinia, setActivePinia, PiniaVuePlugin } from 'pinia'
-
-// TODO: workaround that should probably be removed in the future
-const Vue = 'default' in _Vue2 ? (_Vue2 as any).default : _Vue2
-Vue.use(PiniaVuePlugin)
-
-export default (context: any, provide: any) => {
- const pinia = createPinia()
- context.app.pinia = pinia
- setActivePinia(pinia)
-
- // add access to `$nuxt`
- pinia._p.push(({ store }) => {
- // make it non enumerable so it avoids any serialization and devtools
- Object.defineProperty(store, '$nuxt', { value: context })
- })
-
- if (import.meta.server) {
- context.beforeNuxtRender((ctx: any) => {
- ctx.nuxtState.pinia = pinia.state.value
- })
- } else if (context.nuxtState && context.nuxtState.pinia) {
- pinia.state.value = context.nuxtState.pinia
- }
-
- // Inject $pinia
- provide('pinia', pinia)
-}
-
-declare module 'pinia' {
- export interface PiniaCustomProperties {
- /**
- * Nuxt context. Requires you to install `@nuxt/types` to have types.
- *
- * @deprecated use `useNuxtApp()` and global `$fetch()` instead. See
- * https://v3.nuxtjs.org/bridge/bridge-composition-api/
- */
- // @ts-ignore: heavy types, must be added by the user
- $nuxt: import('@nuxt/types').Context
- }
-}
import { describe, beforeEach, it, expect, vi } from 'vitest'
import { computed, reactive, ref, ToRefs } from 'vue'
import { createPinia, defineStore, setActivePinia, storeToRefs } from '../src'
-import { set } from 'vue-demi'
describe('storeToRefs', () => {
beforeEach(() => {
const { double } = storeToRefs(store)
// Assuming HMR operation
- set(
- store,
- 'double',
+ // @ts-expect-error: hmr
+ store.double =
+ //
computed(() => 1)
- )
expect(double.value).toEqual(1)
})
"@vue/test-utils": "^2.4.6"
},
"dependencies": {
- "@vue/devtools-api": "^6.6.3",
- "vue-demi": "^0.14.10"
+ "@vue/devtools-api": "^6.6.3"
},
"peerDependencies": {
"typescript": ">=4.4.4",
import { Pinia, PiniaPlugin, setActivePinia, piniaSymbol } from './rootStore'
-import { ref, App, markRaw, effectScope, isVue2, Ref } from 'vue-demi'
+import { ref, App, markRaw, effectScope, Ref } from 'vue'
import { registerPiniaDevtools, devtoolsPlugin } from './devtools'
import { IS_CLIENT } from './env'
import { StateTree, StoreGeneric } from './types'
// this allows calling useStore() outside of a component setup after
// installing pinia's plugin
setActivePinia(pinia)
- if (!isVue2) {
- pinia._a = app
- app.provide(piniaSymbol, pinia)
- app.config.globalProperties.$pinia = pinia
- /* istanbul ignore else */
- if (__USE_DEVTOOLS__ && IS_CLIENT) {
- registerPiniaDevtools(app, pinia)
- }
- toBeInstalled.forEach((plugin) => _p.push(plugin))
- toBeInstalled = []
+ pinia._a = app
+ app.provide(piniaSymbol, pinia)
+ app.config.globalProperties.$pinia = pinia
+ /* istanbul ignore else */
+ if (__USE_DEVTOOLS__ && IS_CLIENT) {
+ registerPiniaDevtools(app, pinia)
}
+ toBeInstalled.forEach((plugin) => _p.push(plugin))
+ toBeInstalled = []
},
use(plugin) {
- if (!this._a && !isVue2) {
+ if (!this._a) {
toBeInstalled.push(plugin)
} else {
_p.push(plugin)
CustomInspectorState,
} from '@vue/devtools-api'
import { MutationType, StoreGeneric } from '../types'
-import { DebuggerEvent } from 'vue-demi'
+import { DebuggerEvent } from 'vue'
import { Pinia } from '../rootStore'
import { isPinia } from './utils'
TimelineEvent,
App as DevtoolsApp,
} from '@vue/devtools-api'
-import { ComponentPublicInstance, markRaw, toRaw, unref, watch } from 'vue-demi'
+import { ComponentPublicInstance, markRaw, toRaw, unref, watch } from 'vue'
import { Pinia, PiniaPluginContext } from '../rootStore'
import {
_GettersTree,
-import { isRef, isReactive, isVue2, set } from 'vue-demi'
+import { isRef, isReactive } from 'vue'
import { Pinia } from './rootStore'
import {
isPlainObject,
} else {
// objects are either a bit more complex (e.g. refs) or primitives, so we
// just set the whole thing
- if (isVue2) {
- set(newState, key, subPatch)
- } else {
- newState[key] = subPatch
- }
+ newState[key] = subPatch
}
}
-import type { ComponentPublicInstance, ComputedRef, UnwrapRef } from 'vue-demi'
+import type { ComponentPublicInstance, ComputedRef, UnwrapRef } from 'vue'
import type {
_GettersTree,
_StoreWithGetters_Writable,
hasInjectionContext,
InjectionKey,
Ref,
-} from 'vue-demi'
+} from 'vue'
import {
StateTree,
PiniaCustomProperties,
toRefs,
Ref,
ref,
- set,
- del,
nextTick,
- isVue2,
-} from 'vue-demi'
+} from 'vue'
import {
StateTree,
SubscriptionCallback,
function setup() {
if (!initialState && (!__DEV__ || !hot)) {
/* istanbul ignore if */
- if (isVue2) {
- set(pinia.state.value, id, state ? state() : {})
- } else {
- pinia.state.value[id] = state ? state() : {}
- }
+ pinia.state.value[id] = state ? state() : {}
}
// avoid creating a state in pinia.state.value
const store = pinia._s.get(id)!
// allow cross using stores
- /* istanbul ignore if */
- if (isVue2 && !store._r) return
// @ts-expect-error
// return getters![name].call(context, context)
// watcher options for $subscribe
const $subscribeOptions: WatchOptions = { deep: true }
/* istanbul ignore else */
- if (__DEV__ && !isVue2) {
+ if (__DEV__) {
$subscribeOptions.onTrigger = (event) => {
/* istanbul ignore else */
if (isListening) {
// by the setup
if (!isOptionsStore && !initialState && (!__DEV__ || !hot)) {
/* istanbul ignore if */
- if (isVue2) {
- set(pinia.state.value, $id, {})
- } else {
- pinia.state.value[$id] = {}
- }
+ pinia.state.value[$id] = {}
}
const hotState = ref({} as S)
$dispose,
} as _StoreWithState<Id, S, G, A>
- /* istanbul ignore if */
- if (isVue2) {
- // start as non ready
- partialStore._r = false
- }
-
const store: Store<Id, S, G, A> = reactive(
__DEV__ || (__USE_DEVTOOLS__ && IS_CLIENT)
? assign(
if ((isRef(prop) && !isComputed(prop)) || isReactive(prop)) {
// mark it as a piece of state to be serialized
if (__DEV__ && hot) {
- set(hotState.value, key, toRef(setupStore, key))
+ hotState.value[key] = toRef(setupStore, key)
// createOptionStore directly sets the state in pinia.state.value so we
// can just skip that
} else if (!isOptionsStore) {
}
}
// transfer the ref to the pinia state to keep everything in sync
- /* istanbul ignore if */
- if (isVue2) {
- set(pinia.state.value[$id], key, prop)
- } else {
- pinia.state.value[$id][key] = prop
- }
+ pinia.state.value[$id][key] = prop
}
/* istanbul ignore else */
const actionValue = __DEV__ && hot ? prop : action(prop as _Method, key)
// this a hot module replacement store because the hotUpdate method needs
// to do it with the right context
- /* istanbul ignore if */
- if (isVue2) {
- set(setupStore, key, actionValue)
- } else {
- // @ts-expect-error
- setupStore[key] = actionValue
- }
+ // @ts-expect-error
+ setupStore[key] = actionValue
/* istanbul ignore else */
if (__DEV__) {
// add the state, getters, and action properties
/* istanbul ignore if */
- if (isVue2) {
- Object.keys(setupStore).forEach((key) => {
- set(store, key, setupStore[key])
- })
- } else {
- assign(store, setupStore)
- // allows retrieving reactive objects with `storeToRefs()`. Must be called after assigning to the reactive object.
- // Make `storeToRefs()` work with `reactive()` #799
- assign(toRaw(store), setupStore)
- }
+ assign(store, setupStore)
+ // allows retrieving reactive objects with `storeToRefs()`. Must be called after assigning to the reactive object.
+ // Make `storeToRefs()` work with `reactive()` #799
+ assign(toRaw(store), setupStore)
// use this instead of a computed with setter to be able to create it anywhere
// without linking the computed lifespan to wherever the store is first
}
// patch direct access properties to allow store.stateProperty to work as
// store.$state.stateProperty
- set(store, stateKey, toRef(newStore.$state, stateKey))
+ // @ts-expect-error: any type
+ store[stateKey] = toRef(newStore.$state, stateKey)
})
// remove deleted state properties
Object.keys(store.$state).forEach((stateKey) => {
if (!(stateKey in newStore.$state)) {
- del(store, stateKey)
+ // @ts-expect-error: noop if doesn't exist
+ delete store[stateKey]
}
})
for (const actionName in newStore._hmrPayload.actions) {
const actionFn: _Method = newStore[actionName]
- set(store, actionName, action(actionFn, actionName))
+ // @ts-expect-error: actionName is a string
+ store[actionName] =
+ //
+ action(actionFn, actionName)
}
// TODO: does this work in both setup and option store?
})
: getter
- set(store, getterName, getterValue)
+ // @ts-expect-error: getterName is a string
+ store[getterName] =
+ //
+ getterValue
}
// remove deleted getters
Object.keys(store._hmrPayload.getters).forEach((key) => {
if (!(key in newStore._hmrPayload.getters)) {
- del(store, key)
+ // @ts-expect-error: noop if doesn't exist
+ delete store[key]
}
})
// remove old actions
Object.keys(store._hmrPayload.actions).forEach((key) => {
if (!(key in newStore._hmrPayload.actions)) {
- del(store, key)
+ // @ts-expect-error: noop if doesn't exist
+ delete store[key]
}
})
)
}
- /* istanbul ignore if */
- if (isVue2) {
- // mark the store as ready before plugins
- store._r = true
- }
-
// apply all plugins
pinia._p.forEach((extender) => {
/* istanbul ignore else */
ComputedRef,
isReactive,
isRef,
- isVue2,
toRaw,
ToRef,
toRef,
ToRefs,
- toRefs,
WritableComputedRef,
-} from 'vue-demi'
+} from 'vue'
import { StoreGetters, StoreState } from './store'
import type {
_ActionsTree,
export function storeToRefs<SS extends StoreGeneric>(
store: SS
): StoreToRefs<SS> {
- // See https://github.com/vuejs/pinia/issues/852
- // It's easier to just use toRefs() even if it includes more stuff
- if (isVue2) {
- // @ts-expect-error: toRefs include methods and others
- return toRefs(store)
- } else {
- const rawStore = toRaw(store)
+ const rawStore = toRaw(store)
- const refs = {} as StoreToRefs<SS>
- for (const key in rawStore) {
- const value = rawStore[key]
- // There is no native method to check for a computed
- // https://github.com/vuejs/core/pull/4165
- if (value.effect) {
- // @ts-expect-error: too hard to type correctly
- refs[key] =
- // ...
- computed({
- get: () => store[key],
- set(value) {
- store[key] = value
- },
- })
- } else if (isRef(value) || isReactive(value)) {
- // @ts-expect-error: the key is state or getter
- refs[key] =
- // ---
- toRef(store, key)
- }
+ const refs = {} as StoreToRefs<SS>
+ for (const key in rawStore) {
+ const value = rawStore[key]
+ // There is no native method to check for a computed
+ // https://github.com/vuejs/core/pull/4165
+ if (value.effect) {
+ // @ts-expect-error: too hard to type correctly
+ refs[key] =
+ // ...
+ computed({
+ get: () => store[key],
+ set(value) {
+ store[key] = value
+ },
+ })
+ } else if (isRef(value) || isReactive(value)) {
+ // @ts-expect-error: the key is state or getter
+ refs[key] =
+ // ---
+ toRef(store, key)
}
-
- return refs
}
+
+ return refs
}
-import { getCurrentScope, onScopeDispose } from 'vue-demi'
+import { getCurrentScope, onScopeDispose } from 'vue'
import { _Method } from './types'
export const noop = () => {}
UnwrapRef,
WatchOptions,
WritableComputedRef,
-} from 'vue-demi'
+} from 'vue'
import { Pinia } from './rootStore'
/**
-import type { Plugin } from 'vue-demi'
+import type { Plugin } from 'vue'
import { registerPiniaDevtools } from './devtools'
import { IS_CLIENT } from './env'
import { Pinia, piniaSymbol, setActivePinia } from './rootStore'
import { useUserStore } from '../stores/user'
import { useCartStore } from '../stores/cart'
import { useCounter } from '../stores/counter'
-import { onUnmounted } from 'vue-demi'
+import { onUnmounted } from 'vue'
const userStore = useUserStore()
const cartStore = useCartStore()
__TEST__: 'false',
},
resolve: {
- // alias: {
- // '@vue/composition-api': 'vue-demi',
- // },
- dedupe: ['vue-demi', 'vue', 'pinia'],
+ dedupe: ['vue', 'pinia'],
alias: {
// FIXME: use fileToUrl
pinia: path.resolve(__dirname, '../pinia/src/index.ts'),
},
},
optimizeDeps: {
- exclude: ['vue-demi', '@vueuse/shared', '@vueuse/core', 'pinia'],
+ exclude: ['@vueuse/shared', '@vueuse/core', 'pinia'],
},
})
"build": "tsup",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . -l @pinia/testing -r 1"
},
- "dependencies": {
- "vue-demi": "^0.14.10"
- },
"devDependencies": {
"pinia": "workspace:*",
"tsup": "^8.3.5"
-import {
- App,
- createApp,
- customRef,
- isReactive,
- isRef,
- isVue2,
- set,
- toRaw,
- triggerRef,
-} from 'vue-demi'
-import type { ComputedRef, WritableComputedRef } from 'vue-demi'
+import { createApp, customRef, isReactive, isRef, toRaw, triggerRef } from 'vue'
+import type { App, ComputedRef, WritableComputedRef } from 'vue'
import {
Pinia,
PiniaPlugin,
) {
target[key] = mergeReactiveObjects(targetValue, subPatch)
} else {
- if (isVue2) {
- set(target, key, subPatch)
- } else {
- // @ts-expect-error: subPatch is a valid value
- target[key] = subPatch
- }
+ // @ts-expect-error: subPatch is a valid value
+ target[key] =
+ //
+ subPatch
}
}
clean: true,
format: ['cjs', 'esm'],
dts: true,
- external: ['vue-demi', 'vue', 'pinia'],
+ external: ['vue', 'pinia'],
tsconfig: './tsconfig.build.json',
// onSuccess: 'npm run build:fix',
})
vue:
specifier: ^2.7.0 || ^3.5.11
version: 3.5.13(typescript@5.6.3)
- vue-demi:
- specifier: ^0.14.10
- version: 0.14.10(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.6.3)))(vue@3.5.13(typescript@5.6.3))
devDependencies:
'@microsoft/api-extractor':
specifier: 7.48.0
version: 1.0.5
packages/testing:
- dependencies:
- vue-demi:
- specifier: ^0.14.10
- version: 0.14.10(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.6.3)))(vue@3.5.13(typescript@5.6.3))
devDependencies:
pinia:
specifier: workspace:*
output.banner = banner
output.externalLiveBindings = false
output.globals = {
- 'vue-demi': 'VueDemi',
vue: 'Vue',
}
// during a single build.
hasTSChecked = true
- const external = ['vue-demi', 'vue']
+ const external = ['vue']
if (
!isGlobalBuild &&
// pinia.prod.cjs should not require `@vue/devtools-api` (like Vue)