]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
refactor: create playground package
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 18 Aug 2021 22:10:39 +0000 (00:10 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 18 Aug 2021 22:10:39 +0000 (00:10 +0200)
35 files changed:
jest.config.js
package.json
packages/pinia/package.json
packages/pinia/vite.config.ts [deleted file]
packages/playground/.gitignore [moved from packages/pinia/playground/.gitignore with 100% similarity]
packages/playground/index.html [moved from packages/pinia/index.html with 93% similarity]
packages/playground/package.json [new file with mode: 0644]
packages/playground/src/App.vue [moved from packages/pinia/playground/src/App.vue with 100% similarity]
packages/playground/src/api/jokes.ts [moved from packages/pinia/playground/src/api/jokes.ts with 100% similarity]
packages/playground/src/api/nasa.ts [moved from packages/pinia/playground/src/api/nasa.ts with 100% similarity]
packages/playground/src/main.ts [moved from packages/pinia/playground/src/main.ts with 80% similarity]
packages/playground/src/router.ts [moved from packages/pinia/playground/src/router.ts with 100% similarity]
packages/playground/src/shims-vue.d.ts [moved from packages/pinia/playground/src/shims-vue.d.ts with 100% similarity]
packages/playground/src/stores/cart.ts [moved from packages/pinia/playground/src/stores/cart.ts with 95% similarity]
packages/playground/src/stores/counter.ts [moved from packages/pinia/playground/src/stores/counter.ts with 95% similarity]
packages/playground/src/stores/counterSetup.ts [moved from packages/pinia/playground/src/stores/counterSetup.ts with 95% similarity]
packages/playground/src/stores/jokes-swrv.ts [moved from packages/pinia/playground/src/stores/jokes-swrv.ts with 76% similarity]
packages/playground/src/stores/jokes.ts [moved from packages/pinia/playground/src/stores/jokes.ts with 95% similarity]
packages/playground/src/stores/jokesUsePromised.ts [moved from packages/pinia/playground/src/stores/jokesUsePromised.ts with 93% similarity]
packages/playground/src/stores/nasa.ts [moved from packages/pinia/playground/src/stores/nasa.ts with 87% similarity]
packages/playground/src/stores/user.ts [moved from packages/pinia/playground/src/stores/user.ts with 83% similarity]
packages/playground/src/test.ts [moved from packages/pinia/playground/src/test.ts with 100% similarity]
packages/playground/src/views/404.vue [moved from packages/pinia/playground/src/views/404.vue with 100% similarity]
packages/playground/src/views/About.vue [moved from packages/pinia/playground/src/views/About.vue with 100% similarity]
packages/playground/src/views/AllStores.vue [moved from packages/pinia/playground/src/views/AllStores.vue with 100% similarity]
packages/playground/src/views/CounterSetupStore.vue [moved from packages/pinia/playground/src/views/CounterSetupStore.vue with 100% similarity]
packages/playground/src/views/CounterStore.vue [moved from packages/pinia/playground/src/views/CounterStore.vue with 100% similarity]
packages/playground/src/views/Jokes.vue [moved from packages/pinia/playground/src/views/Jokes.vue with 100% similarity]
packages/playground/src/views/JokesPromised.vue [moved from packages/pinia/playground/src/views/JokesPromised.vue with 100% similarity]
packages/playground/src/views/NasaPOD-swrv.vue [moved from packages/pinia/playground/src/views/NasaPOD-swrv.vue with 100% similarity]
packages/playground/src/views/swrv.vue [moved from packages/pinia/playground/src/views/swrv.vue with 100% similarity]
packages/playground/src/vite-env.d.ts [moved from packages/pinia/playground/src/vite-env.d.ts with 100% similarity]
packages/playground/tsconfig.json [moved from packages/pinia/playground/tsconfig.json with 68% similarity]
packages/playground/vite.config.ts [new file with mode: 0644]
yarn.lock

index ace2e0b2ad28f83ad71270d1ba4a4cf43178aef9..c46474700b7674d6d33ba2cce31e035052ebf7f8 100644 (file)
@@ -3,7 +3,7 @@ module.exports = {
   collectCoverage: true,
   coverageDirectory: 'coverage',
   coverageReporters: ['html', 'lcov', 'text'],
-  collectCoverageFrom: ['packages/*/src/**/*.ts'],
+  collectCoverageFrom: ['packages/pinia/src/**/*.ts'],
   coveragePathIgnorePatterns: [
     '/node_modules/',
     'src/index.ts',
@@ -13,7 +13,7 @@ module.exports = {
     'src/deprecated.ts',
     'src/vue2-plugin.ts',
   ],
-  testMatch: ['<rootDir>/packages/*/__tests__/**/*.spec.ts'],
+  testMatch: ['<rootDir>/packages/pinia/__tests__/**/*.spec.ts'],
   transform: {
     '^.+\\.tsx?$': '@sucrase/jest-plugin',
   },
index cb9e7e56d1a3ab6c586ce6836211a69ccd3e6148..16ad8115df5ff13ec933d8722c1f0c06ca2e1b99 100644 (file)
@@ -8,6 +8,7 @@
     "release": "node TODO: scripts/release.mjs",
     "size": "lerna run size",
     "build": "lerna run build --parallel",
+    "play": "lerna run play",
     "build:dts": "lerna run build:dts --parallel",
     "lint": "prettier -c --parser typescript \"packages/*/{src,__tests__,e2e}/**/*.[jt]s?(x)\"",
     "lint:fix": "yarn run lint --write",
index 5cc89af58b86bed7b5e92dc2706b218ea4979ef7..c4df7c56c0f623db48e70c95627dfdddb2776578 100644 (file)
@@ -30,7 +30,6 @@
     "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . -l pinia -r 1",
     "test:dts": "tsc -p ./test-dts/tsconfig.json",
     "dev": "yarn run test:unit --watchAll",
-    "play": "yarn vite",
     "test": "yarn run build && yarn run build:dts && yarn test:dts"
   },
   "files": [
     "@microsoft/api-extractor": "7.18.5",
     "@nuxt/app": "^0.5.0",
     "@nuxt/kit": "^0.6.4",
-    "@vitejs/plugin-vue": "^1.4.0",
     "@vue/compiler-sfc": "^3.2.2",
     "@vue/server-renderer": "^3.2.2",
     "@vue/test-utils": "^2.0.0-rc.12",
-    "@vueuse/core": "^6.0.0",
-    "mande": "^1.0.0",
-    "swrv": "^1.0.0-beta.8",
-    "vite": "^2.5.0",
     "vitepress": "^0.16.1",
     "vue": "^3.2.2",
-    "vue-promised": "^2.1.0",
-    "vue-router": "^4.0.11",
     "vue2": "npm:vue@2"
   },
   "dependencies": {
diff --git a/packages/pinia/vite.config.ts b/packages/pinia/vite.config.ts
deleted file mode 100644 (file)
index 064353e..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-import { defineConfig } from 'vite'
-import vue from '@vitejs/plugin-vue'
-
-// https://vitejs.dev/config/
-export default defineConfig({
-  plugins: [vue()],
-  define: {
-    __DEV__: 'true',
-    __BROWSER__: 'true',
-    __TEST__: 'false',
-  },
-  optimizeDeps: {
-    exclude: ['vue-demi', '@vueuse/shared', '@vueuse/core'],
-  },
-})
similarity index 93%
rename from packages/pinia/index.html
rename to packages/playground/index.html
index 3d7f1bbc03d0b9afcaf6f714a591fd3d04e63899..71f6a63b7b5dd80492fb180243f390f3e2ad8fb9 100644 (file)
@@ -37,6 +37,6 @@
   <body>
     <div id="app"></div>
 
-    <script type="module" src="/playground/src/main.ts"></script>
+    <script type="module" src="/src/main.ts"></script>
   </body>
 </html>
diff --git a/packages/playground/package.json b/packages/playground/package.json
new file mode 100644 (file)
index 0000000..f5d922b
--- /dev/null
@@ -0,0 +1,23 @@
+{
+  "name": "@pinia/playground",
+  "version": "0.0.0",
+  "private": true,
+  "scripts": {
+    "play": "vite",
+    "play:build": "vite build",
+    "serve": "vite preview"
+  },
+  "devDependencies": {
+    "@vitejs/plugin-vue": "^1.4.0",
+    "vite": "^2.4.0"
+  },
+  "dependencies": {
+    "@vueuse/core": "^6.0.0",
+    "mande": "^1.0.0",
+    "swrv": "^1.0.0-beta.8",
+    "vue": "^3.2.2",
+    "@vue/compiler-sfc": "^3.2.2",
+    "vue-promised": "^2.1.0",
+    "vue-router": "^4.0.11"
+  }
+}
similarity index 80%
rename from packages/pinia/playground/src/main.ts
rename to packages/playground/src/main.ts
index 3de1a062a7b09c8fa2ac99d1089cffa31a755558..cb71b2fd75af0034591d82c8451f7fc989f42a07 100644 (file)
@@ -1,11 +1,25 @@
-import { computed, createApp, markRaw } from 'vue'
+import { computed, createApp, markRaw, Ref } from 'vue'
 import App from './App.vue'
-import { createPinia } from '../../src'
+import { createPinia } from 'pinia'
 import { router } from './router'
+import {
+  RouteLocationNormalized,
+  RouteLocationNormalizedLoaded,
+} from 'vue-router'
 
 const pinia = createPinia()
 
+declare module 'pinia' {
+  export interface PiniaCustomProperties {
+    set route(
+      value: RouteLocationNormalizedLoaded | Ref<RouteLocationNormalizedLoaded>
+    )
+    get route(): RouteLocationNormalized
+  }
+}
+
 pinia.use(() => ({
+  // @ts-expect-error: WHY?
   route: computed(() => markRaw(router.currentRoute.value)),
 }))
 
similarity index 95%
rename from packages/pinia/playground/src/stores/cart.ts
rename to packages/playground/src/stores/cart.ts
index a1fe4bbb328af1bc81f2993cf15344c3e15957c5..1adeaba7ed401e32bafbaffeece7866f0f115db6 100644 (file)
@@ -1,4 +1,4 @@
-import { defineStore } from '../../../src'
+import { defineStore } from 'pinia'
 import { useUserStore } from './user'
 
 export const useCartStore = defineStore({
similarity index 95%
rename from packages/pinia/playground/src/stores/counter.ts
rename to packages/playground/src/stores/counter.ts
index bc1d0c9cd5e5ca40b35c2c88f9eedf03baa6a160..9e1841bffa5d06978d0e235508f50890122ea4b7 100644 (file)
@@ -1,4 +1,4 @@
-import { acceptHMRUpdate, defineStore } from '../../../src'
+import { acceptHMRUpdate, defineStore } from 'pinia'
 
 const delay = (t: number) => new Promise((r) => setTimeout(r, t))
 
similarity index 95%
rename from packages/pinia/playground/src/stores/counterSetup.ts
rename to packages/playground/src/stores/counterSetup.ts
index fadca0a05e2553694dbc37f5641106ae433aeca2..4c5330da2336a4aa16b874968a7b3af97839dff6 100644 (file)
@@ -1,5 +1,5 @@
 import { computed, toRefs, reactive } from 'vue'
-import { acceptHMRUpdate, defineStore } from '../../../src'
+import { acceptHMRUpdate, defineStore } from 'pinia'
 
 const delay = (t: number) => new Promise((r) => setTimeout(r, t))
 
similarity index 76%
rename from packages/pinia/playground/src/stores/jokes-swrv.ts
rename to packages/playground/src/stores/jokes-swrv.ts
index 3656bfbcf96f511b954458d8028e0a3f249837de..3ce07d9fc4c71491241fe21b0f76a5dd5d264af2 100644 (file)
@@ -1,5 +1,5 @@
-import { ref, toRaw, unref, watch } from 'vue'
-import { acceptHMRUpdate, defineStore } from '../../../src'
+import { ref, toRaw, watch } from 'vue'
+import { acceptHMRUpdate, defineStore } from 'pinia'
 import { getRandomJoke, Joke } from '../api/jokes'
 import useSWRV from 'swrv'
 
@@ -7,7 +7,7 @@ export const useJokesSetup = defineStore('jokes-swrv-setup', () => {
   // const current = ref<null | Joke>(null)
   const history = ref<Joke[]>([])
 
-  const { data, error, isValidating, mutate } = useSWRV('jokes', getRandomJoke)
+  const { data, error, mutate } = useSWRV('jokes', getRandomJoke)
 
   watch(data, (joke) => {
     console.log('changed from within the store', joke)
similarity index 95%
rename from packages/pinia/playground/src/stores/jokes.ts
rename to packages/playground/src/stores/jokes.ts
index 340d7f50ef99dd435edfba50ceb289be4bae3e9f..e344a2f5a81028a22ab6aa7654318e5e6c773292 100644 (file)
@@ -1,5 +1,5 @@
 import { ref, unref } from 'vue'
-import { acceptHMRUpdate, defineStore } from '../../../src'
+import { acceptHMRUpdate, defineStore } from 'pinia'
 import { getRandomJoke, Joke } from '../api/jokes'
 
 export const useJokes = defineStore('jokes', {
similarity index 93%
rename from packages/pinia/playground/src/stores/jokesUsePromised.ts
rename to packages/playground/src/stores/jokesUsePromised.ts
index d3648e38da19b64b05af2c1b37f15994dab72f9a..c7a4820ee8a6c95639e45d9655dd63ae65753dcc 100644 (file)
@@ -1,4 +1,4 @@
-import { acceptHMRUpdate, defineStore } from '../../../src'
+import { acceptHMRUpdate, defineStore } from 'pinia'
 import { getRandomJoke, Joke } from '../api/jokes'
 import { usePromise } from 'vue-promised'
 import { ref, watch } from 'vue'
@@ -85,6 +85,6 @@ export const useSetupJokes = defineStore('jokes-setup-vue-promised', () => {
 })
 
 if (import.meta.hot) {
-  // import.meta.hot.accept(acceptHMRUpdate(useJokes, import.meta.hot))
+  import.meta.hot.accept(acceptHMRUpdate(useJokes, import.meta.hot))
   // import.meta.hot.accept(acceptHMRUpdate(useSetupJokes, import.meta.hot))
 }
similarity index 87%
rename from packages/pinia/playground/src/stores/nasa.ts
rename to packages/playground/src/stores/nasa.ts
index 705d712a2e822b70d080184c33d90bee4b988b85..a491c0ea881e9215a138db1b6ed7ad26ce504463 100644 (file)
@@ -1,10 +1,8 @@
 import useSWRV from 'swrv'
-import { computed, ref } from 'vue'
-import { acceptHMRUpdate, defineStore } from '../../../src'
+import { ref } from 'vue'
+import { acceptHMRUpdate, defineStore } from 'pinia'
 import { getNASAPOD } from '../api/nasa'
 
-import LocalStorageCache from 'swrv/dist/cache/adapters/localStorage'
-
 export const useNasaStore = defineStore('nasa-pod-swrv', () => {
   // can't go past today
   const today = new Date().toISOString().slice(0, 10)
similarity index 83%
rename from packages/pinia/playground/src/stores/user.ts
rename to packages/playground/src/stores/user.ts
index 32970ecd25bb281d5c41838926c8743b36175290..d8c1afd34d8018f6bf1473772433ae5c0ead0d69 100644 (file)
@@ -1,7 +1,6 @@
-import { defineStore } from '../../../src'
+import { defineStore } from 'pinia'
 
-export const useUserStore = defineStore({
-  id: 'user',
+export const useUserStore = defineStore('user', {
   state: () => ({
     name: 'Eduardo',
     isAdmin: true,
@@ -13,13 +12,13 @@ export const useUserStore = defineStore({
     async login(user: string, password: string) {
       const userData = await apiLogin(user, password)
 
-      this.patch({
+      this.$patch({
         name: user,
         ...userData,
       })
     },
     logout() {
-      this.patch({
+      this.$patch({
         name: '',
         isAdmin: false,
       })
similarity index 68%
rename from packages/pinia/playground/tsconfig.json
rename to packages/playground/tsconfig.json
index 5b6c24dfc57c0dfe642dc79b85338324fa1940fd..181bbeb2465ed59c0e329e8fe123575e71f5ae01 100644 (file)
@@ -1,4 +1,5 @@
 {
+  "extends": "../../tsconfig.json",
   "compilerOptions": {
     "target": "esnext",
     "module": "esnext",
@@ -9,6 +10,6 @@
     "resolveJsonModule": true,
     "esModuleInterop": true,
     "lib": ["esnext", "dom"]
-  },
-  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
+  }
+  // "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
 }
diff --git a/packages/playground/vite.config.ts b/packages/playground/vite.config.ts
new file mode 100644 (file)
index 0000000..1998ab7
--- /dev/null
@@ -0,0 +1,46 @@
+import { defineConfig, Plugin } from 'vite'
+import vue from '@vitejs/plugin-vue'
+import _fs from 'fs'
+import path from 'path'
+
+const fs = _fs.promises
+
+// https://vitejs.dev/config/
+export default defineConfig({
+  plugins: [vue(), copyPiniaPlugin()],
+  define: {
+    // __DEV__: 'true',
+    // __BROWSER__: 'true',
+    __TEST__: 'false',
+  },
+  resolve: {
+    // alias: {
+    //   '@vue/composition-api': 'vue-demi',
+    // },
+    dedupe: ['vue-demi', 'vue'],
+  },
+  optimizeDeps: {
+    exclude: ['vue-demi', '@vueuse/shared', '@vueuse/core', 'pinia'],
+  },
+})
+
+function copyPiniaPlugin(): Plugin {
+  return {
+    name: 'copy-pinia',
+    async generateBundle() {
+      const filePath = path.resolve(
+        __dirname,
+        '../pinia/dist/pinia.esm-bundler.js'
+      )
+
+      // throws if file doesn't exist
+      await fs.access(filePath)
+
+      this.emitFile({
+        type: 'asset',
+        fileName: 'pinia.esm-bundler.js',
+        source: await fs.readFile(filePath, 'utf-8'),
+      })
+    },
+  }
+}
index 182543f56cc7916350df6634c2aa73a125ff208d..cd35d4ae169bf0dee21478511a098bfcae791c97 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -7778,7 +7778,7 @@ verror@1.10.0:
     core-util-is "1.0.2"
     extsprintf "^1.2.0"
 
-vite@^2.4.4, vite@^2.5.0:
+vite@^2.4.0, vite@^2.4.4:
   version "2.5.0"
   resolved "https://registry.yarnpkg.com/vite/-/vite-2.5.0.tgz#111ba3679432d426e44566acf480005a7914cbd6"
   integrity sha512-Dn4B+g54PJsMG5WCc4QeFy1ygMXRdTtFrUPegqfk4+vzVQcbF/DqqmI/1bxezArzbujBJg/67QeT5wz8edfJVQ==