From 3c6cc8ebff593e496e524d182947419f8bf1ae0a Mon Sep 17 00:00:00 2001 From: prazdevs <1631886+prazdevs@users.noreply.github.com> Date: Sun, 23 Jul 2023 22:11:59 +0200 Subject: [PATCH] :fire: remove hmr package (deprecated) --- packages/hmr/CHANGELOG.md | 16 ------------- packages/hmr/README.md | 32 -------------------------- packages/hmr/package.json | 33 --------------------------- packages/hmr/src/index.ts | 47 --------------------------------------- 4 files changed, 128 deletions(-) delete mode 100644 packages/hmr/CHANGELOG.md delete mode 100644 packages/hmr/README.md delete mode 100644 packages/hmr/package.json delete mode 100644 packages/hmr/src/index.ts diff --git a/packages/hmr/CHANGELOG.md b/packages/hmr/CHANGELOG.md deleted file mode 100644 index c214b57..0000000 --- a/packages/hmr/CHANGELOG.md +++ /dev/null @@ -1,16 +0,0 @@ -# Changelog - - -## 0.2.0 (2023-05-09) - -### Added - -- 🏷️ better type docs - - - -## 0.1.0 (2023-05-09) - -### Added - -- 🚀 override Pinia's `acceptHMRUpdate` diff --git a/packages/hmr/README.md b/packages/hmr/README.md deleted file mode 100644 index 62d9824..0000000 --- a/packages/hmr/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# `@pinia-plugin-persistedstate/hmr` - -> Override for Pinia's `acceptHMRUpdate` - -## 🚀 Quickstart - -1. Install with your favorite package manager: - - **pnpm** : `pnpm i -D @pinia-plugin-persistedstate/hmr` - - npm : `npm i -D @pinia-plugin-persistedstate/hmr` - - yarn : `yarn add -D @pinia-plugin-persistedstate/hmr` - -2. Replace `acceptHMRUpdate` in your store definition file with: -```ts -import { defineStore } from 'pinia' -import { acceptHMRUpdateWithHydration } from '@pinia-plugin-persistedstate/hmr' - -const useStore = defineStore('store', { - // ... -}) - -if (import.meta.hot) - import.meta.hot.accept(acceptHMRUpdateWithHydration(useStore, import.meta.hot)) -``` - -## ⚠️ Warning - -This is a copy/paste of Pinia's `acceptHMRUpdate` function that triggers `$hydrate` on HMR update. Use at your own risk. :) - -## 📝 License - -Copyright © 2022 [Sacha Bouillez](https://github.com/prazdevs). -This project is under [MIT](https://github.com/prazdevs/pinia-plugin-persistedstate/blob/main/LICENSE) license. diff --git a/packages/hmr/package.json b/packages/hmr/package.json deleted file mode 100644 index d6620b4..0000000 --- a/packages/hmr/package.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "@pinia-plugin-persistedstate/hmr", - "version": "0.2.0", - "license": "MIT", - "repository": { - "type": "git", - "url": "https://github.com/prazdevs/pinia-plugin-persistedstate/tree/main/packages/hmr" - }, - "exports": { - ".": { - "types": "./dist/index.d.ts", - "require": "./dist/index.js", - "import": "./dist/index.mjs" - } - }, - "main": "dist/index.js", - "module": "dist/index.mjs", - "types": "dist/index.d.ts", - "files": [ - "dist" - ], - "scripts": { - "build": "tsup --dts --format esm,cjs src/index.ts" - }, - "peerDependencies": { - "pinia": "^2.0.0", - "pinia-plugin-persistedstate": "^3.0.0" - }, - "devDependencies": { - "pinia": "^2.1.4", - "pinia-plugin-persistedstate": "^3.1.0" - } -} diff --git a/packages/hmr/src/index.ts b/packages/hmr/src/index.ts deleted file mode 100644 index 0dd95ca..0000000 --- a/packages/hmr/src/index.ts +++ /dev/null @@ -1,47 +0,0 @@ -import type { - Pinia, - StoreDefinition, - StoreGeneric, -} from 'pinia' - -function isUseStore(fn: any): fn is StoreDefinition { - return typeof fn === 'function' && typeof fn.$id === 'string' -} - -/** - * Override of Pinia's `acceptHMRUpdate`. Use at your own discretion. - * @param initialUseStore return of the `defineStore` to hot update - * @param hot `import.meta.hot` - */ -export function acceptHMRUpdateWithHydration(initialUseStore: any, hot: any) { - return (newModule: any) => { - const pinia: Pinia | undefined = hot.data.pinia || initialUseStore._pinia - - if (!pinia) - return - - hot.data.pinia = pinia - - for (const exportName in newModule) { - const useStore = newModule[exportName] - // @ts-expect-error `_s is a stripped @internal` - if (isUseStore(useStore) && pinia._s.has(useStore.$id)) { - const id = useStore.$id - - if (id !== initialUseStore.$id) { - console.warn( - `The id of the store changed from "${initialUseStore.$id}" to "${id}". Reloading.`, - ) - return hot.invalidate() - } - - // @ts-expect-error `_s is a stripped @internal` - const existingStore: StoreGeneric = pinia._s.get(id)! - if (!existingStore) - return - - useStore(pinia, existingStore) - } - } - } -}