Skip to content
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

Support vite 5 #85

Closed
wants to merge 7 commits into from
Closed

Support vite 5 #85

wants to merge 7 commits into from

Conversation

susnux
Copy link
Contributor

@susnux susnux commented Dec 18, 2023

This is a bit more complex, the obvious changes:

  • Support vite 4.x and 5.x
  • Update some dependencies for supporting rollup 4 + vite 5

But there are some other changes required to do so:
Needed to bundle the package as tsc will fail because vite 5 now uses some dependencies that use Node16 module resolution. Therefor we need moduleResolution node16 but this will fail due to a lot of dependency issues.
So the only solution that worked for me was using moduleResolution: Bundler and using vite for bundling the package.
This causes some test issues because now the local vite config would be used for testing, so I needed to adjust the tests a bit.

Verified

This commit was signed with the committer’s verified signature.
susnux Ferdinand Thiessen
This is required as vite 5 uses Node16 resolved dependencies, Typescript can not use those without `moduleResolution: node16` but that will break
a lot of other dependencies. So we need to go with module resolution bundler.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>

Verified

This commit was signed with the committer’s verified signature.
susnux Ferdinand Thiessen
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>

Verified

This commit was signed with the committer’s verified signature.
susnux Ferdinand Thiessen
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>

Verified

This commit was signed with the committer’s verified signature.
susnux Ferdinand Thiessen
…template

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>

Verified

This commit was signed with the committer’s verified signature.
susnux Ferdinand Thiessen
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@susnux susnux requested review from skjnldsv and ShGKme December 18, 2023 18:40
@susnux susnux added the 3. to review Ready to review label Dec 18, 2023

Verified

This commit was signed with the committer’s verified signature.
susnux Ferdinand Thiessen
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>

Verified

This commit was signed with the committer’s verified signature.
susnux Ferdinand Thiessen
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Copy link

codecov bot commented Dec 18, 2023

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (026b470) 81.69% compared to head (c520659) 81.13%.

Files Patch % Lines
lib/index.ts 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #85      +/-   ##
==========================================
- Coverage   81.69%   81.13%   -0.57%     
==========================================
  Files           8        8              
  Lines         579      583       +4     
  Branches       48       48              
==========================================
  Hits          473      473              
- Misses         58       62       +4     
  Partials       48       48              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@ShGKme ShGKme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I understand correctly that adding bundling with Vite here is needed, because this import

import type { PluginConfiguration as VitePluginInjectCSSOptions } from 'vite-plugin-css-injected-by-js/dist/esm/declarations/interface.d.ts'

is not allowed because it is not exported by package.json?

We can grab this type as

type VitePluginInjectCSSOptions = Parameters<typeof injectCSSPlugin>[0]

(Or propose the lib author to export all the types)

lib/libConfig.ts Show resolved Hide resolved
tsconfig.json Show resolved Hide resolved
@susnux
Copy link
Contributor Author

susnux commented Dec 18, 2023

Did I understand correctly that adding bundling with Vite here is needed, because this import ...

No not only, the main problem is vite 5 importing rollup/parseAst from rollup 4. This is a Node16 import and thus failed for Typescript when set to moduleResolution: node.
But moduleResolution: node16 also fails because that requires extensions in relative imports which failes for some dependencies...

@susnux
Copy link
Contributor Author

susnux commented Dec 18, 2023

But I would really appreciate any solution :)

@ShGKme
Copy link
Contributor

ShGKme commented Dec 19, 2023

Did I understand correctly that adding bundling with Vite here is needed, because this import ...

No not only, the main problem is vite 5 importing rollup/parseAst from rollup 4. This is a Node16 import and thus failed for Typescript when set to moduleResolution: node. But moduleResolution: node16 also fails because that requires extensions in relative imports which failes for some dependencies...

Why not moduleResolution: Bundler? It should work as node16 but allows missing extensions

@ShGKme
Copy link
Contributor

ShGKme commented Dec 19, 2023

But I would really appreciate any solution :)

I've just tried this type instead of import and build via TSC seems to work fine on top of this PR, and all tests have passed.

type VitePluginInjectCSSOptions = Parameters<typeof injectCSSPlugin>[0]

@susnux
Copy link
Contributor Author

susnux commented Dec 19, 2023

Why not moduleResolution: Bundler? It should work as node16 but allows missing extensions

Because that does not work with Typescript (tsc) 😢

@ShGKme
Copy link
Contributor

ShGKme commented Dec 19, 2023

Why not moduleResolution: Bundler? It should work as node16 but allows missing extensions

Because that does not work with Typescript (tsc) 😢

Could you add more details on what doesn't work?

It works for me, tested on building @nextcloud/vue + server on top.

(After replacing invalid import)

@susnux susnux mentioned this pull request Dec 19, 2023
@susnux susnux closed this Dec 19, 2023
@susnux susnux deleted the enh/support-vite-5 branch December 19, 2023 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Ready to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants