-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(#238): isomorphic vue2 and vue3 #563
feat(#238): isomorphic vue2 and vue3 #563
Conversation
4cdbca6
to
9ae8469
Compare
9ae8469
to
40f35c4
Compare
}, | ||
"peerDependencies": { | ||
"@vue/composition-api": "^1.0.0", | ||
"vue": "^2.6.0 || >=3.2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be "vue": "^2.0.0 || >=3.0.0"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory yes, but vue-demi
only supports ^2.6.0
and since we depend on it, I opted per matching that limit.
On the 3.2.0
I don't actually remember why I did it 🤔 , maybe I had some errors while running the tests on prior v3 version, but will re-investigate.
Hi @renatodeleao thank you for this awesome contribution ❤️, I will also add some examples to the examples folder and then release a new version 👍🏻 |
@ndelvalle hold-on this for a bit longer. Installed on my real-world project (via git branch install) and some weird unrelated stuff started breaking, and i think it's related with EDIT: related vueuse/vue-demi#151 |
@ndelvalle update on ☝️ I don't think we'll have a "solution" soon. Depending on how consumer's vue project is bundled and which version they are using it might be necessary to apply extra configs while vueuse/vue-demi#151 and similar are sorted. So I guess we'll have to add a note to the readme, something along these lines: ### If you're using [email protected] + @vue/composition-api
If you start getting issues and suspect they came from duplicated `@vue/composition-api` calls like, the cause might be that `vue-demi` installed a second instance of `@vue/composition-api` plugin on your vue instance.
1. your `console.error` logs trace back to two different composition-api exports `.mjs` and `.common.js` as an example.
1. _the setup() binding property "x" is already declared_
1. etc
In this scenario you might need to tweak your bundler config to ensure that all your dependencies point to the same `@vue/composition-api` package:
#### Vite
// vite.config.js
// https://github.com/vueuse/vue-demi/issues/151#issuecomment-1088785153
resolve: {
alias: [
{ find: '@vue/composition-api/dist/vue-composition-api.mjs', replacement: '@vue/composition-api' },
],
}
#### webpack
// webpack.config.js
resolve: {
alias: {
'@vue/composition-api$': 'path/to/node_modules/@vue/composition-api/dist/vue-composition-api.esm.js' // the one you want
}
}
#### yarn resolutions
// package.json
// https://github.com/yarnpkg/rfcs/blob/master/implemented/0000-selective-versions-resolutions.md
{
"resolutions": {
"**/@vue/composition-api": "1.x" // or "file: ./path to the node_modules" version you want (depends on yarn version)
}
}
AlternativeI guess the alternative is to drop this PR implementation relying on Let me know what you think, when you have the time |
Thanks for the research @renatodeleao. Yes, this is a tricky situation. I wonder how many people are using vue3 vs vue2. |
@ndelvalle I'll give one last shot trying to force dependencies as Our usecase is very simple, so yes we can also try that approach. The only downsides i'm seeing is that, by tweaking the code that way, it would be a breaking change for vue2 users and there's still a lot of people stuck with it.. so i don't know... I suspect that the majority of our users are still on vue2, but this is just a guess, because the edgy ones on vue3 maybe moved to another package in the meantime. Also, what would we do if we find a bug and need to patch the library? The vue2 users would have to go through a breaking change just to get that fix since the new version ( There's also another option that is dropping
The only reason to actually use I'll let you know when I have news, enjoy the weekend! 👋 |
also included vue 2 and 3 as devDependencies for testing
This is "almost" an "integration" test, to ensure the code works on actual vue environment. Add plugin instalation tests. SIDE-EFFECTS: - shoutout to the Dobromir for the code vueuse/vue-demi#38 (comment) - forward correct test utils exports - add ifVue2 and ifVue3 test utils, when testing breaking changes — code that is not inter-compatible - add universalDestroy, because lifecycle hook names changed and this prevents the version check on test code
these are now asserted on both vue2 and vue3 context via vue-
40f35c4
to
4ddf640
Compare
@ndelvalle update: i've decided to remove The benefits we we're getting were not outweighing the cons: one extra dependency + mandatory
If we ever get into using new vue Let me know if you want me to squash commits before merge to remove this |
411ccce
to
a8b3def
Compare
using vue-demi requires that vue2.6 projects install "@vue/composition-api", always! Even though I believe is the norm in 2.6.x projects but still kind of bummer to get an install error. vue-demi lists @vue/composition-api as optional peer dependency because it would otherwise install it for vue2.7 and vue3.x projects. We could list @vue/composition-api as dependency as well to overcome the install issue, but we're not using anything on this package so why complicate things? 1. I've removed vue-demi altogether, replaced the only thing we've use isVue3 with simply version regexp 1. the swap-vue.js from vuelidate allow us to keep the isomorphic testing to ensure it works everything Related issues: vueuse/vue-demi#67 vueuse/vue-demi#7
a8b3def
to
59c518e
Compare
@renatodeleao thanks for the work on researching and implementing this PR. I'll create a new vue3 project on the |
@ndelvalle long time no see (read) 👋
Happen to be migrating my client's codebase to vue3, had some finally some time to dedicate to OSS :)
If you're around and have time to take a look at this let me know!
Hope you're doing alright, cheers!
Implementation Details
vue-demi
as an attempt to make this library universal. Is more handy for the universal testing part than to the actual code, since we don't use any composition-api features yet.vue3
) and corresponding@vue/test-utils
packages.test-utils.js
was added with that forward exports from the correct test package for each versionscripts/swap-vue
was copied fromvuelidate
, becausevue-demi switch
alone was not working Switching between Vue 2 and Vue 3 to run tests with Composition API vueuse/vue-demi#38bind
,update
,unbind
methods to their vue3 counterpartsbeforeMount
,updated
,unmounted
and was done in a minute.vue
requirements aspeerDependencies
, in conjunction with the aliased version mentioned above, makesnpm
install log a lot of warnings, and you'll have to pass--force
flag to proceed. Once again i'm trying to copy whatvue-demi
actually did.Closes #238