From 52d317502639b158b161e48d5755f67ac4efd5e2 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 11 Nov 2021 00:04:42 +0100 Subject: [PATCH 1/3] feat(nuxt): rewrite nuxt module --- packages/nuxt/build.config.ts | 2 +- packages/nuxt/package.json | 15 +-- packages/nuxt/src/module.ts | 89 +++++++---------- packages/nuxt/src/runtime/plugin.vue2.mjs | 26 +++++ packages/nuxt/src/runtime/plugin.vue3.mjs | 17 ++++ packages/nuxt/src/templates/plugin.ts | 53 ----------- packages/nuxt/tsconfig.json | 4 + tsconfig.json | 2 +- yarn.lock | 110 +++++++++++++++++++++- 9 files changed, 194 insertions(+), 124 deletions(-) create mode 100644 packages/nuxt/src/runtime/plugin.vue2.mjs create mode 100644 packages/nuxt/src/runtime/plugin.vue3.mjs delete mode 100644 packages/nuxt/src/templates/plugin.ts create mode 100644 packages/nuxt/tsconfig.json diff --git a/packages/nuxt/build.config.ts b/packages/nuxt/build.config.ts index 28415771de..d8f50199da 100644 --- a/packages/nuxt/build.config.ts +++ b/packages/nuxt/build.config.ts @@ -4,6 +4,6 @@ export default defineBuildConfig({ declaration: true, emitCJS: false, cjsBridge: true, - entries: ['src/module', 'src/templates/plugin'], + entries: ['src/module', { input: 'src/runtime/', outDir: 'dist/runtime' }], externals: ['pinia', '@nuxt/kit-edge', '@nuxt/types'], }) diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index a6cf2b06c0..e6f6f14c6c 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -35,26 +35,17 @@ "types": "./dist/module.d.ts", "files": [ "module.cjs", - "dist/*.js", - "dist/*.mjs", - "dist/*.d.ts" + "dist" ], "scripts": { "build": "unbuild", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . -l @pinia/nuxt -r 1" }, "dependencies": { - "vue-demi": "*" + "@nuxt/kit": "latest", + "pinia": "^2.0.3" }, "devDependencies": { - "@nuxt/types": "^2.15.8", - "pinia": "^2.0.0-0", "unbuild": "^0.5.11" - }, - "peerDependencies": { - "pinia": "~2.0.3" - }, - "publishConfig": { - "access": "public" } } diff --git a/packages/nuxt/src/module.ts b/packages/nuxt/src/module.ts index 44e751296f..027deacbd5 100644 --- a/packages/nuxt/src/module.ts +++ b/packages/nuxt/src/module.ts @@ -1,11 +1,8 @@ -/** - * @module @pinia/nuxt - */ -// import { isVue2 } from 'vue-demi' +import { name, version } from '../package.json' +import { defineNuxtModule, addPlugin, isNuxt2 } from '@nuxt/kit' import type { Pinia } from 'pinia' -import type { Context, Module } from '@nuxt/types' -export interface PiniaNuxtOptions { +export interface PiniaModuleOptions { /** * Pinia disables Vuex by default, set this option to `false` to avoid it and * use Pinia alongside Vuex. @@ -15,56 +12,38 @@ export interface PiniaNuxtOptions { disableVuex?: boolean } -const DEFAULTS = { - disableVuex: true, -} - -export default function (_options) { - const nuxt = this.nuxt - const options = { - ...DEFAULTS, - ...(_options || {}), - ...(nuxt.options.pinia || {}), - } - - // Disable default Vuex store (options.features only exists in Nuxt v2.10+) - if (nuxt.options.features && options.disableVuex) { - nuxt.options.features.store = false - } - - // make sure we use the mjs for pinia so node doesn't complain about using a module js with an extension that is js - // but doesn't have the type: module in its packages.json file - nuxt.options.alias.pinia = 'pinia/dist/pinia.mjs' - - this.addPlugin({ src: require.resolve('./plugin.mjs') }) - - // transpile pinia for nuxt 2 and nuxt bridge - // if (isVue2 && !nuxt.options.build.transpile.includes('pinia')) { - // nuxt.options.build.transpile.push('pinia') - // } -} - -declare module '@nuxt/types' { - export interface Context { - /** - * Pinia instance attached to the app. - * - * @deprecated: use context.$pinia instead - */ - pinia: Pinia - - /** - * Pinia instance attached to the app. - */ +export default defineNuxtModule({ + name, + version, + configKey: 'pinia', + defaults: { + disableVuex: true, + } as PiniaModuleOptions, + setup(options, nuxt) { + // Disable default Vuex store for Nuxt 2 (options.features only exists in Nuxt v2.10+) + if (isNuxt2() && nuxt.options.features && options.disableVuex) { + nuxt.options.features.store = false + } + + // Resolve pinia + // TODO: Use kit to use proper search path + nuxt.options.alias.pinia = require.resolve('pinia/dist/pinia.mjs') + + // Add vue2 or vue3 plugin + addPlugin({ + src: isNuxt2() + ? require.resolve('./runtime/plugin.vue2.mjs') + : require.resolve('./runtime/plugin.vue3.mjs'), + }) + }, +}) + +declare module '@nuxt/kit' { + export interface NuxtApp { + /** Pinia instance attached to the app.*/ $pinia: Pinia } -} - -declare module 'pinia' { - export interface PiniaCustomProperties { - /** - * Nuxt context. - */ - $nuxt: Context + export interface NuxtConfig { + pinia: PiniaModuleOptions } } diff --git a/packages/nuxt/src/runtime/plugin.vue2.mjs b/packages/nuxt/src/runtime/plugin.vue2.mjs new file mode 100644 index 0000000000..b497a7598b --- /dev/null +++ b/packages/nuxt/src/runtime/plugin.vue2.mjs @@ -0,0 +1,26 @@ +import { createPinia, setActivePinia, PiniaVuePlugin } from 'pinia' +import Vue from 'vue' + +// @ts-ignore +Vue.use(PiniaVuePlugin) + +export default function (context, inject) { + const pinia = createPinia() + context.app.pinia = pinia + inject('pinia', pinia) + setActivePinia(pinia) + + pinia._p.push(({ store }) => { + // Make it non enumerable so it avoids any serialization and devtools + Object.defineProperty(store, '$nuxt', { value: context }) + }) + + // Hydrate state + if (process.server) { + context.beforeNuxtRender(({ nuxtState }) => { + nuxtState.pinia = pinia.state.value + }) + } else if (context.nuxtState && context.nuxtState.pinia) { + pinia.state.value = context.nuxtState.pinia + } +} diff --git a/packages/nuxt/src/runtime/plugin.vue3.mjs b/packages/nuxt/src/runtime/plugin.vue3.mjs new file mode 100644 index 0000000000..233436b2da --- /dev/null +++ b/packages/nuxt/src/runtime/plugin.vue3.mjs @@ -0,0 +1,17 @@ +import { defineNuxtPlugin } from '#app' +import { createPinia, setActivePinia } from 'pinia' + +export default defineNuxtPlugin((nuxtApp) => { + const pinia = createPinia() + nuxtApp.vueApp.use(pinia) + nuxtApp.provide('pinia', pinia) + setActivePinia(pinia) + + // Hydrate state + if (process.server) { + nuxtApp.payload.state.pinia = pinia.state.value + } + if (process.client && nuxtApp.payload.state.pinia) { + pinia.state.value = nuxtApp.payload.state.pinia + } +}) diff --git a/packages/nuxt/src/templates/plugin.ts b/packages/nuxt/src/templates/plugin.ts deleted file mode 100644 index df6717d043..0000000000 --- a/packages/nuxt/src/templates/plugin.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { install, isVue2, Vue2 } from 'vue-demi' -import { createPinia, setActivePinia, PiniaVuePlugin } from 'pinia' -import type { Plugin } from '@nuxt/types' - -const PiniaNuxtPlugin: Plugin = (context, inject) => { - if (isVue2) { - install() - // TODO: workaround that should probably be removed in the future - const Vue = 'default' in Vue2 ? Vue2.default : Vue2 - Vue.use(PiniaVuePlugin) - } - - const pinia = createPinia() - if (isVue2) { - // simulate new Vue({ pinia }) - context.app.pinia = pinia - } else { - // @ts-expect-error: vue 3 only - context.vueApp.use(pinia) - } - - // make sure to inject pinia after installing the plugin because in Nuxt 3, inject defines a non configurable getter - // on app.config.globalProperties - // add $pinia to the context - inject('pinia', pinia) - // to allow accessing pinia without the $ - // TODO: remove this in deprecation - context.pinia = pinia - - setActivePinia(pinia) - - // add access to `$nuxt` - // TODO: adapt to Nuxt 3 with a definePlugin - pinia._p.push(({ store }) => { - // make it non enumerable so it avoids any serialization and devtools - Object.defineProperty(store, '$nuxt', { value: context }) - }) - - if (process.server) { - if (isVue2) { - context.beforeNuxtRender(({ nuxtState }) => { - nuxtState.pinia = pinia.state.value - }) - } else { - // there is no beforeNuxtRender in Nuxt 3 - context.nuxtState.pinia = pinia.state.value - } - } else if (context.nuxtState && context.nuxtState.pinia) { - pinia.state.value = context.nuxtState.pinia - } -} - -export default PiniaNuxtPlugin diff --git a/packages/nuxt/tsconfig.json b/packages/nuxt/tsconfig.json new file mode 100644 index 0000000000..abeea01102 --- /dev/null +++ b/packages/nuxt/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "types": ["@nuxt/kit"] +} diff --git a/tsconfig.json b/tsconfig.json index f4a2f5cc0e..120efeaa8f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "packages/pinia/src/global.d.ts", "packages/*/src/**/*.ts", "packages/*/__tests__/**/*.ts" - ], +, "packages/nuxt/src/runtime/plugin.vue3.mjs", "packages/nuxt/src/runtime/plugin.vue2.mjs" ], "exclude": ["packages/test-vue-2", "packages/pinia/__tests__/test-utils.ts"], "compilerOptions": { "baseUrl": ".", diff --git a/yarn.lock b/yarn.lock index 0254306869..7c5cc62fdc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1433,6 +1433,39 @@ node-gyp "^7.1.0" read-package-json-fast "^2.0.1" +"@nuxt/kit-edge@latest": + version "3.0.0-27276275.abfbd2f" + resolved "https://registry.yarnpkg.com/@nuxt/kit-edge/-/kit-edge-3.0.0-27276275.abfbd2f.tgz#fb44b2f34d554a6cab5d8139060f342d37976e6a" + integrity sha512-BtYM+3bDdAOtnXYUkGEqtTk5V1dWJC5+8TMz8Bl5nG9Ygn9nyzAKaMRzNveE50ZWZLVIjQ0fDQrgVtIyQhHwmA== + dependencies: + consola "^2.15.3" + create-require "^1.1.1" + defu "^5.0.0" + dotenv "^10.0.0" + globby "^11.0.4" + hash-sum "^2.0.0" + hookable "^5.0.0" + jiti "^1.12.9" + lodash.template "^4.5.0" + mlly "^0.3.12" + pathe "^0.2.0" + pkg-types "^0.3.1" + rc9 "^1.2.0" + scule "^0.2.1" + semver "^7.3.5" + std-env "^3.0.1" + ufo "^0.7.9" + unctx "^1.0.2" + untyped "^0.2.12" + +"@nuxt/kit@latest": + version "0.7.0-edge" + resolved "https://registry.yarnpkg.com/@nuxt/kit/-/kit-0.7.0-edge.tgz#37da0dda70b76f9df054708ea3c066d60689f811" + integrity sha512-3+azijGDlERcmhK/Gp97cn8+I++/pn/AmYcj7ceRF++6T86ohckAY0ip/+y4dLlWJ0AGnwB6x4gybG03ltEPew== + dependencies: + "@nuxt/kit-edge" latest + jiti "^1.12.9" + "@nuxt/types@^2.15.8": version "2.15.8" resolved "https://registry.yarnpkg.com/@nuxt/types/-/types-2.15.8.tgz#1249de448f68169fe17e9379ee7b5caa0eb336b0" @@ -3182,6 +3215,11 @@ cosmiconfig@^7.0.0, cosmiconfig@^7.0.1: path-type "^4.0.0" yaml "^1.10.0" +create-require@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" + integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== + cross-spawn@^5.0.1: version "5.1.0" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449" @@ -3312,6 +3350,11 @@ define-properties@^1.1.3: dependencies: object-keys "^1.0.12" +defu@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/defu/-/defu-2.0.4.tgz#09659a6e87a8fd7178be13bd43e9357ebf6d1c46" + integrity sha512-G9pEH1UUMxShy6syWk01VQSRVs3CDWtlxtZu7A+NyqjxaCA4gSlWAKDBx6QiUEKezqS8+DUlXLI14Fp05Hmpwg== + defu@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/defu/-/defu-5.0.0.tgz#5768f0d402a555bfc4c267246b20f82ce8b5a10b" @@ -3337,6 +3380,11 @@ deprecation@^2.0.0, deprecation@^2.3.1: resolved "https://registry.yarnpkg.com/deprecation/-/deprecation-2.3.1.tgz#6368cbdb40abf3373b525ac87e4a260c3a700919" integrity sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ== +destr@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/destr/-/destr-1.1.0.tgz#2da6add6ba71e04fd0abfb1e642d4f6763235095" + integrity sha512-Ev/sqS5AzzDwlpor/5wFCDu0dYMQu/0x2D6XfAsQ0E7uQmamIgYJ6Dppo2T2EOFVkeVYWjc+PCLKaqZZ57qmLg== + detect-indent@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d" @@ -3393,6 +3441,11 @@ dot-prop@^6.0.1: dependencies: is-obj "^2.0.0" +dotenv@^10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81" + integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q== + duplexer@^0.1.1: version "0.1.2" resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.2.tgz#3abe43aef3835f8ae077d136ddce0f276b0400e6" @@ -3819,6 +3872,11 @@ find-up@^4.0.0, find-up@^4.1.0: locate-path "^5.0.0" path-exists "^4.0.0" +flat@^5.0.0: + version "5.0.2" + resolved "https://registry.yarnpkg.com/flat/-/flat-5.0.2.tgz#8ca6fe332069ffa9d324c327198c598259ceb241" + integrity sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ== + forever-agent@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" @@ -4095,7 +4153,7 @@ globby@10.0.0: merge2 "^1.2.3" slash "^3.0.0" -globby@^11.0.2, globby@^11.0.3: +globby@^11.0.2, globby@^11.0.3, globby@^11.0.4: version "11.0.4" resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5" integrity sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg== @@ -4193,6 +4251,16 @@ has@^1.0.3: dependencies: function-bind "^1.1.1" +hash-sum@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/hash-sum/-/hash-sum-2.0.0.tgz#81d01bb5de8ea4a214ad5d6ead1b523460b0b45a" + integrity sha512-WdZTbAByD+pHfl/g9QSsBIIwy8IT+EsPiKDs0KNX+zSHhdDLFKdZu0BQHljvO+0QI/BasbMSUa8wYNCZTvhslg== + +hookable@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/hookable/-/hookable-5.0.0.tgz#bac6f1d4b56e3f590f21cfe3f813731372c0c69f" + integrity sha512-IqoJ8oXCNTUtNfqwbUQvLd+6ebVXk5qqGpSMOe4BS514vd4bEEH+hd9lva48mbbbe9q4eFKmsOViTZkr7ludHg== + hosted-git-info@^2.1.4: version "2.8.9" resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9" @@ -5761,7 +5829,7 @@ mkdist@^0.3.3, mkdist@^0.3.5: mri "^1.2.0" pathe "^0.2.0" -mlly@^0.3.0: +mlly@^0.3.0, mlly@^0.3.12, mlly@^0.3.6: version "0.3.12" resolved "https://registry.yarnpkg.com/mlly/-/mlly-0.3.12.tgz#9928d517622558ea6ce3d5544df1a4f7c6687811" integrity sha512-+5DdpxP48PpfV/FcP4j/8TREPycnROCg0hX1nmD6aoZ2lD4FpZI4sxWG6l6YpUktXi/vckj8NaAl3DVQSkIn3w== @@ -6421,6 +6489,15 @@ pkg-dir@^4.1.0, pkg-dir@^4.2.0: dependencies: find-up "^4.0.0" +pkg-types@^0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/pkg-types/-/pkg-types-0.3.1.tgz#d7a8b69efb8777a05afc5aabfc259a29a5d6d159" + integrity sha512-BjECNgz/tsyqg0/T4Z/U7WbFQXUT24nfkxPbALcrk/uHVeZf9MrGG4tfvYtu+jsrHCFMseLQ6woQddDEBATw3A== + dependencies: + jsonc-parser "^3.0.0" + mlly "^0.3.6" + pathe "^0.2.0" + please-upgrade-node@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz#aeddd3f994c933e4ad98b99d9a556efa0e2fe942" @@ -6582,6 +6659,15 @@ randombytes@^2.1.0: dependencies: safe-buffer "^5.1.0" +rc9@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/rc9/-/rc9-1.2.0.tgz#ef098181fdde714efc4c426383d6e46c14b1254a" + integrity sha512-/jknmhG0USFAx5uoKkAKhtG40sONds9RWhFHrP1UzJ3OvVfqFWOypSUpmsQD0fFwAV7YtzHhsn3QNasfAoxgcQ== + dependencies: + defu "^2.0.4" + destr "^1.0.0" + flat "^5.0.0" + react-is@^17.0.1: version "17.0.2" resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" @@ -7296,6 +7382,11 @@ stack-utils@^2.0.3: dependencies: escape-string-regexp "^2.0.0" +std-env@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/std-env/-/std-env-3.0.1.tgz#bc4cbc0e438610197e34c2d79c3df30b491f5182" + integrity sha512-mC1Ps9l77/97qeOZc+HrOL7TIaOboHqMZ24dGVQrlxFcpPpfCHpH+qfUT7Dz+6mlG8+JPA1KfBQo19iC/+Ngcw== + strict-uri-encode@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546" @@ -7777,6 +7868,11 @@ typescript@^4.3.5, typescript@^4.4.4, typescript@~4.4.2: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== +ufo@^0.7.9: + version "0.7.9" + resolved "https://registry.yarnpkg.com/ufo/-/ufo-0.7.9.tgz#0268e3734b413c9ed6f3510201f42372821b875c" + integrity sha512-6t9LrLk3FhqTS+GW3IqlITtfRB5JAVr5MMNjpBECfK827W+Vh5Ilw/LhTcHWrt6b3hkeBvcbjx4Ti7QVFzmcww== + uglify-js@^3.1.4: version "3.14.3" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.14.3.tgz#c0f25dfea1e8e5323eccf59610be08b6043c15cf" @@ -7832,6 +7928,11 @@ unbuild@^0.5.11: typescript "^4.4.4" untyped "^0.2.9" +unctx@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/unctx/-/unctx-1.0.2.tgz#d8d9c83a0965aa277f61058c94548fcee6861e48" + integrity sha512-qxRfnQZWJqkg180JeOCJEvtjj5/7wnWVqkNHln8muY5/z8kMWBFqikFBPwIPCQrZJ+jtaSWkVHJkuHUAXls6zw== + unique-filename@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/unique-filename/-/unique-filename-1.1.1.tgz#1d69769369ada0583103a1e6ae87681b56573230" @@ -7861,6 +7962,11 @@ universalify@^2.0.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== +untyped@^0.2.12: + version "0.2.13" + resolved "https://registry.yarnpkg.com/untyped/-/untyped-0.2.13.tgz#31be48c9cf1d81b65d05f762a0332b2b5e9a9cb3" + integrity sha512-dnvCmDKTb+zg504JyQ9h1sWINAyxnP6KgmvUH6s6BjLV+3fvjZTiUklL15VvEqpDjy4Leq/xzlZ+JxskeoM5mg== + untyped@^0.2.9: version "0.2.12" resolved "https://registry.yarnpkg.com/untyped/-/untyped-0.2.12.tgz#7bd9fee523e82e087af46248038680ee4ee56359" From 49db94c1aaf858b1726d36df18e49c5fe7370b92 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 11 Nov 2021 00:18:35 +0100 Subject: [PATCH 2/3] fix: remove $nuxt injection --- packages/nuxt/src/runtime/plugin.vue2.mjs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/nuxt/src/runtime/plugin.vue2.mjs b/packages/nuxt/src/runtime/plugin.vue2.mjs index b497a7598b..afa2628b65 100644 --- a/packages/nuxt/src/runtime/plugin.vue2.mjs +++ b/packages/nuxt/src/runtime/plugin.vue2.mjs @@ -10,11 +10,6 @@ export default function (context, inject) { inject('pinia', pinia) setActivePinia(pinia) - pinia._p.push(({ store }) => { - // Make it non enumerable so it avoids any serialization and devtools - Object.defineProperty(store, '$nuxt', { value: context }) - }) - // Hydrate state if (process.server) { context.beforeNuxtRender(({ nuxtState }) => { From 16399e088e454a76e6e53612e09202408ee4f822 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 11 Nov 2021 00:23:18 +0100 Subject: [PATCH 3/3] feat: auto import `defineStore` --- packages/nuxt/src/module.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/nuxt/src/module.ts b/packages/nuxt/src/module.ts index 027deacbd5..8c8833b3df 100644 --- a/packages/nuxt/src/module.ts +++ b/packages/nuxt/src/module.ts @@ -29,6 +29,15 @@ export default defineNuxtModule({ // TODO: Use kit to use proper search path nuxt.options.alias.pinia = require.resolve('pinia/dist/pinia.mjs') + // Register auto imports + nuxt.hook('autoImports:extend', (autoImports) => { + autoImports.push({ + name: 'defineStore', + as: 'defineStore', + from: 'pinia', + }) + }) + // Add vue2 or vue3 plugin addPlugin({ src: isNuxt2()