From 03c4c85a55cec2884021b23bb9a235a3a83a675f Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 29 Jul 2021 11:28:17 +0200 Subject: [PATCH] chore: add wip nuxt 3 --- nuxt/README.md | 3 + nuxt/index.ts | 41 ++++++++++++++ nuxt/plugin.ts | 28 +++++++++ package.json | 2 + yarn.lock | 151 ++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 nuxt/README.md create mode 100644 nuxt/index.ts create mode 100644 nuxt/plugin.ts diff --git a/nuxt/README.md b/nuxt/README.md new file mode 100644 index 00000000..d7dc119d --- /dev/null +++ b/nuxt/README.md @@ -0,0 +1,3 @@ +# Nuxt 2/3 module + +Note this is a WIP module for Nuxt, it isn't available yet. diff --git a/nuxt/index.ts b/nuxt/index.ts new file mode 100644 index 00000000..de4df0f0 --- /dev/null +++ b/nuxt/index.ts @@ -0,0 +1,41 @@ +// @ts-check +import { resolve } from 'upath' +import { addPlugin, defineNuxtModule } from '@nuxt/kit' + +export interface PiniaNuxtOptions { + /** + * Pinia disables Vuex by default, set this option to `false` to avoid it and + * use Pinia alongside Vuex. + * + * @default `true` + */ + disableVuex?: boolean +} + +const module = defineNuxtModule({ + name: 'pinia', + configKey: 'pinia', + defaults: { + disableVuex: true, + }, + hooks: {}, + setup(options, nuxt) { + // Disable default Vuex store (options.features only exists in Nuxt v2.10+) + if (nuxt.options.features && options.disableVuex) { + nuxt.options.features.store = false + } + + addPlugin({ src: resolve(__dirname, 'plugin') }) + + // transpile pinia if @vue/composition-api is transpiled because we must use the same instance + if ( + !nuxt.options.dev && + !nuxt.options.build.transpile.includes('pinia') && + nuxt.options.build.transpile.includes('@vue/composition-api') + ) { + nuxt.options.build.transpile.push('pinia') + } + }, +}) + +export default module diff --git a/nuxt/plugin.ts b/nuxt/plugin.ts new file mode 100644 index 00000000..e25ad6dc --- /dev/null +++ b/nuxt/plugin.ts @@ -0,0 +1,28 @@ +import { defineNuxtPlugin } from '@nuxt/app' +import { markRaw } from '@nuxt/app/node_modules/@vue/runtime-core' +import { createPinia, setActivePinia } from 'pinia' + +const PiniaPlugin = defineNuxtPlugin((nuxt) => { + const pinia = createPinia() + + // if Vue 2, simulate new Vue({ pinia }) + nuxt.app.pinia = pinia + + // TODO: handle this once we know how to do it + // add $pinia to the context + // inject('pinia', pinia) + // to allow accessing pinia without the $ + // context.pinia = pinia + + setActivePinia(pinia) + + pinia._p.push(() => ({ $nuxt: markRaw(nuxt) })) + + if (process.server) { + // beforeNuxt render set nuxtState.pinia = pinia.state.value + } else { + // set pinia.state.value = nuxtState.pinia + } +}) + +export default PiniaPlugin diff --git a/package.json b/package.json index ec0fb556..e7290add 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,8 @@ "license": "MIT", "devDependencies": { "@microsoft/api-extractor": "7.18.4", + "@nuxt/app": "^0.5.0", + "@nuxt/kit": "^0.6.4", "@rollup/plugin-alias": "^3.1.4", "@rollup/plugin-commonjs": "^19.0.1", "@rollup/plugin-node-resolve": "^13.0.4", diff --git a/yarn.lock b/yarn.lock index d47067d2..34cfc4b6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -713,6 +713,38 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" +"@nuxt/app@^0.5.0": + version "0.5.0" + resolved "https://registry.yarnpkg.com/@nuxt/app/-/app-0.5.0.tgz#7a0c9c31ef8c29754c79e278d28dde450d54a4e0" + integrity sha512-UGwwQVGhAhDJ3/vZZ9mIY/1mekWR+h4Jnrthuz/UcyL2g07cK3oyqdEQG2gXJWYDkwH4HnzPt9v4mWFK03IzfQ== + dependencies: + "@vueuse/head" "^0.6.0" + hookable "^4.4.1" + ohmyfetch "^0.2.0" + vue "^3.1.1" + vue-router "^4.0.9" + vuex5 "^0.5.0-testing.3" + +"@nuxt/kit@^0.6.4": + version "0.6.4" + resolved "https://registry.yarnpkg.com/@nuxt/kit/-/kit-0.6.4.tgz#76a81e135bfeb91c0b5eb58435c8e5640046c912" + integrity sha512-NsV8TEVN+oTOgJvrsaIuyMaq/mFW+O7Rnz+sGUMlJlUskBC0KyqkrLkclNFyXsrnf4MEudAV+1WwtOyFVODltw== + 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" + jiti "^1.10.1" + rc9 "^1.2.0" + scule "^0.2.1" + std-env "^2.3.0" + ufo "^0.7.5" + unctx "^0.0.3" + untyped "^0.2.5" + upath "^2.0.1" + "@polka/url@^0.5.0": version "0.5.0" resolved "https://registry.yarnpkg.com/@polka/url/-/url-0.5.0.tgz#b21510597fd601e5d7c95008b76bf0d254ebfd31" @@ -1223,6 +1255,11 @@ "@vueuse/shared" "5.2.0" vue-demi "*" +"@vueuse/head@^0.6.0": + version "0.6.0" + resolved "https://registry.yarnpkg.com/@vueuse/head/-/head-0.6.0.tgz#5584b1f724327cfce941c42efec9e590f5799329" + integrity sha512-fi7ZjkMpEAUtTT6iR5wgL2HkX1+3zbrmbpcwU//RgJIWEr5b42jk8E9yOheaC2dYAAHzelAllVpX0pDmhcTXuw== + "@vueuse/shared@5.2.0": version "5.2.0" resolved "https://registry.yarnpkg.com/@vueuse/shared/-/shared-5.2.0.tgz#894921cf5e5fc7f9afa7d7870800b0c9cd265e0c" @@ -1721,6 +1758,11 @@ ci-info@^2.0.0: resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46" integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ== +ci-info@^3.0.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.2.0.tgz#2876cb948a498797b5236f0095bc057d0dca38b6" + integrity sha512-dVqRX7fLUm8J6FgHJ418XuIgDLZDkYcDFTeL6TA2gt5WlIZUQrrH6EZrNClwT/H0FateUsZkGIOPRrLbP+PR9A== + cjs-module-lexer@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/cjs-module-lexer/-/cjs-module-lexer-0.6.0.tgz#4186fcca0eae175970aee870b9fe2d6cf8d5655f" @@ -1903,6 +1945,11 @@ concat-map@0.0.1: resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= +consola@^2.15.3: + version "2.15.3" + resolved "https://registry.yarnpkg.com/consola/-/consola-2.15.3.tgz#2e11f98d6a4be71ff72e0bdf07bd23e12cb61550" + integrity sha512-9vAdYbHj6x2fLKC4+oPH0kFzY/orMZyG2Aj+kNylHxKGJ/Ed4dpNyAQYwJOdqO4zdM7XpVHmyejQDcQHrnuXbw== + consolidate@^0.16.0: version "0.16.0" resolved "https://registry.yarnpkg.com/consolidate/-/consolidate-0.16.0.tgz#a11864768930f2f19431660a65906668f5fbdc16" @@ -2094,6 +2141,11 @@ cosmiconfig@^7.0.0: 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" @@ -2250,11 +2302,26 @@ define-property@^2.0.2: is-descriptor "^1.0.2" isobject "^3.0.1" +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" + integrity sha512-VHg73EDeRXlu7oYWRmmrNp/nl7QkdXUxkQQKig0Zk8daNmm84AbGoC8Be6/VVLJEKxn12hR0UBmz8O+xQiAPKQ== + delayed-stream@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk= +destr@^1.0.0, destr@^1.1.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-newline@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651" @@ -2291,6 +2358,11 @@ dot-prop@^5.1.0: 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== + electron-to-chromium@^1.3.723: version "1.3.780" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.780.tgz#f946e10dc0005a3b59b9afa2d2c92f5c421f7fc5" @@ -2607,6 +2679,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== + for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" @@ -2806,7 +2883,7 @@ globals@^11.1.0: resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== -globby@^11.0.3: +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== @@ -2920,6 +2997,11 @@ hash-sum@^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@^4.4.1: + version "4.4.1" + resolved "https://registry.yarnpkg.com/hookable/-/hookable-4.4.1.tgz#3d7154ac7e1f6f147e50fef583832f2645b9f04f" + integrity sha512-KWjZM8C7IVT2qne5HTXjM6R6VnRfjfRlf/oCnHd+yFxoHO1DzOl6B9LzV/VqGQK/IrFewq+EG+ePVrE9Tpc3fg== + 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" @@ -3711,6 +3793,11 @@ jest@^26.6.3: import-local "^3.0.2" jest-cli "^26.6.3" +jiti@^1.10.1: + version "1.11.0" + resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.11.0.tgz#64120a30d97b9bf37b8b032cf4564dfadc28984c" + integrity sha512-/2c7e61hxxTIN34UeHBB0LCJ5Tq64kgJDV7GR+++e8XRxCKRIKmB8tH6ww1W+Z6Kgd6By+C3RSCu1lXjbPT68A== + jju@~1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/jju/-/jju-1.4.0.tgz#a3abe2718af241a2b2904f84a625970f389ae32a" @@ -4421,6 +4508,15 @@ object.pick@^1.3.0: dependencies: isobject "^3.0.1" +ohmyfetch@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/ohmyfetch/-/ohmyfetch-0.2.0.tgz#09c03a6c107ddfe6a75c83f0a9cdaa59fb31e54b" + integrity sha512-tbrMD8LauY8xivHmDJItpfth/caVDHmDljeZE+4DzA2sbSp72Vzb//NJD1LtAm3pEnK5hY48i4V/zcraeiS3FQ== + dependencies: + destr "^1.1.0" + node-fetch "^2.6.1" + ufo "^0.6.10" + on-headers@~1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/on-headers/-/on-headers-1.0.2.tgz#772b0ae6aaa525c399e489adfad90c403eb3c28f" @@ -4810,6 +4906,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" @@ -5075,6 +5180,11 @@ saxes@^5.0.1: dependencies: xmlchars "^2.2.0" +scule@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/scule/-/scule-0.2.1.tgz#0c1dc847b18e07219ae9a3832f2f83224e2079dc" + integrity sha512-M9gnWtn3J0W+UhJOHmBxBTwv8mZCan5i1Himp60t6vvZcor0wr+IM0URKmIglsWJ7bRujNAVVN77fp+uZaWoKg== + section-matter@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/section-matter/-/section-matter-1.0.0.tgz#e9041953506780ec01d59f292a19c7b850b84167" @@ -5349,6 +5459,13 @@ static-extend@^0.1.1: define-property "^0.2.5" object-copy "^0.1.0" +std-env@^2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/std-env/-/std-env-2.3.0.tgz#66d4a4a4d5224242ed8e43f5d65cfa9095216eee" + integrity sha512-4qT5B45+Kjef2Z6pE0BkskzsH0GO7GrND0wGlTM1ioUe3v0dGYx9ZJH0Aro/YyA8fqQ5EyIKDRjZojJYMFTflw== + dependencies: + ci-info "^3.0.0" + stream-events@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/stream-events/-/stream-events-1.0.5.tgz#bbc898ec4df33a4902d892333d47da9bf1c406d5" @@ -5752,11 +5869,26 @@ uc.micro@^1.0.1, uc.micro@^1.0.5: resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac" integrity sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA== +ufo@^0.6.10: + version "0.6.11" + resolved "https://registry.yarnpkg.com/ufo/-/ufo-0.6.11.tgz#69311ed4abc8ab671c83754b79ce0d396fea1075" + integrity sha512-Yu7TJThwlr23peOkX/+hm6LfkyBs+eDWV880468PTrjKBKjjsNWFFwIuOqDfmXngRo9TZ4+twFYueRH0OLl0Gw== + +ufo@^0.7.5: + version "0.7.7" + resolved "https://registry.yarnpkg.com/ufo/-/ufo-0.7.7.tgz#0062f9e5e790819b0fb23ca24d7c63a4011c036a" + integrity sha512-N25aY3HBkJBnahm+2l4JRBBrX5I+JPakF/tDHYDTjd3wUR7iFLdyiPhj8mBwBz21v728BKwM9L9tgBfCntgdlw== + uglify-js@^3.1.4: version "3.13.10" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.13.10.tgz#a6bd0d28d38f592c3adb6b180ea6e07e1e540a8d" integrity sha512-57H3ACYFXeo1IaZ1w02sfA71wI60MGco/IQFjOqK+WtKoprh7Go2/yvd2HPtoJILO2Or84ncLccI4xoHMTSbGg== +unctx@^0.0.3: + version "0.0.3" + resolved "https://registry.yarnpkg.com/unctx/-/unctx-0.0.3.tgz#e06f67d5bebe2babe5a57c1dc13d77255e3458c0" + integrity sha512-x+NCoXiYn93laQNnoJGZx2UZj7vv8ViFKadUCDx9S4QoPIkGRCYT0OLUDEMlg/B+Q6bnqdSkPLmiy/kjNIwVyQ== + union-value@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.1.tgz#0b6fe7b835aecda61c6ea4d4f02c14221e109847" @@ -5785,6 +5917,16 @@ unset-value@^1.0.0: has-value "^0.3.1" isobject "^3.0.0" +untyped@^0.2.5: + version "0.2.7" + resolved "https://registry.yarnpkg.com/untyped/-/untyped-0.2.7.tgz#7e9badb916388a5bb0f97aa2b643ee5b0033d241" + integrity sha512-5/1MN1Am+W0d7hbg3bPY1N6sfc7HygsGRtdrcp6UnoDxfz6R99kA1liHSp/qiX/lCUbTsLWKGTr1Kojtka/fmA== + +upath@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/upath/-/upath-2.0.1.tgz#50c73dea68d6f6b990f51d279ce6081665d61a8b" + integrity sha512-1uEe95xksV1O0CYKXo8vQvN1JEbtJp7lb7C5U9HMsIp6IVwntkH/oNUzyVNQSd4S1sYk2FpSSW44FqMc8qee5w== + uri-js@^4.2.2: version "4.4.1" resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e" @@ -5920,7 +6062,7 @@ vue-promised@^2.1.0: dependencies: vue-demi latest -vue-router@^4.0.10: +vue-router@^4.0.10, vue-router@^4.0.9: version "4.0.10" resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-4.0.10.tgz#ec8fda032949b2a31d3273170f8f376e86eb52ac" integrity sha512-YbPf6QnZpyyWfnk7CUt2Bme+vo7TLfg1nGZNkvYqKYh4vLaFw6Gn8bPGdmt5m4qrGnKoXLqc4htAsd3dIukICA== @@ -5945,6 +6087,11 @@ vue@^3.2.0-beta.1: "@vue/runtime-dom" "3.2.0-beta.6" "@vue/shared" "3.2.0-beta.6" +vuex5@^0.5.0-testing.3: + version "0.5.0-testing.3" + resolved "https://registry.yarnpkg.com/vuex5/-/vuex5-0.5.0-testing.3.tgz#2e7e5d45fabc26870c80257215f0e38696a45d59" + integrity sha512-fKcpx/RwnfD2L7Lv4VKjY9hmBZp3LJi2G7tUblCUQB5vhOKpoWkip5XIYHEDmJe5KnJJvZ7nf9Ih8wvCIOCVQg== + w3c-hr-time@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/w3c-hr-time/-/w3c-hr-time-1.0.2.tgz#0a89cdf5cc15822df9c360543676963e0cc308cd" -- 2.47.2