Skip to content

feat: support rolldown-vite #7509

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

Merged
merged 60 commits into from
Jun 4, 2025

Conversation

sheremet-va
Copy link
Member

@sheremet-va sheremet-va commented Feb 17, 2025

Description

Good thing is that Vitest works with vite-rolldown for the most part (99%)

  • Removed sveltekit example for now because pnpm didn't like vite override and I don't want to deal with it 👀
  • Issues:
    • vite-rolldown doesn't expose Rollup.Program (or Rolldown.Program?)
    • rolldown doesn't support using syntax - we are transpiling the code down to node18, but it still doesn't work (although we use the esbuild field 🤔 ) - the test is skipped for now
      • there is no way to change the transform plugin if experimental.enableNativePlugin is true (the default)
      • examples/lit decorators don't seem to work correctly:

target was modified to include ES2021 because useDefineForClassFields is set to false and oxc does not support transforming useDefineForClassFields=false for ES2022+ yet

  • ✅ vite-rolldown uses '' + import.meta.url when transforming new URL to opt-out of rolldown's transform (this is an easy regexp change). Vitest also changes this transform to make the URL closer to the one that will be resolved in the browser (in node.js import.meta.url refers to a file, but we need a server URL there)
  • ✅ does optimizeDeps.rollupOptions.resolve.alias work? Browser Mode aliases vue packages to CJS versions testing-library is CJS (and it should import the same version of test-utils), and also we want to have the ability to use string slots and string templates
  • ✅ seems like I see this message even if I didn't specify any esbuildOptions (we always check for an empty stderr and this breaks some tests):

You've set "optimizeDeps.esbuildOptions" in your config. This is deprecated and vite already use rollup to optimize packages. Please use "optimizeDeps.rollupOptions" instead.

The value of esbuildOptions is { preserveSymlinks: false } and the environment name is client 🤔

This comes probably from here:

https://github.com/rolldown/vite/blob/1eee1f56ee90a08d82f465900caea6f2a618d358/packages/vite/src/node/config.ts#L1139

  • ✅ styles in the UI seem to be completely broken when built with vite-rolldown
Screenshot 2025-02-17 at 16 07 07
  • source maps sometimes are not correct. See test/config/unhandled-rejections.test.ts - the column should be 42 (this MIGHT BE an issue with custom Vitest plugins, but it was not a problem before):
  ❯ setup-unhandled-rejections.ts:2:41
       1| export function setup() {
       2|   void new Promise((_, reject) => reject(new Error('intentional unhand…
        |                                         ^ (this is incorrect position)
        |                                          ^ (it should be here where new Error starts)
       3| }

Note

Seems like we always had "Re-optimizing dependencies because vite config has changed" because of incorrect usage of cacheDir

Copy link

netlify bot commented Feb 17, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 5fcae89
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/683f8ed3d5787000080bc0d2
😎 Deploy Preview https://deploy-preview-7509--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@hi-ogawa
Copy link
Contributor

Good thing is that Vitest works with vite-rolldown for the most part (99%)

Awesome progress already! 🎉

rolldown doesn't support using syntax - we are transpiling the code down to node18, but it still doesn't work (although we use the esbuild field 🤔 ) - the test is skipped for now

  • ...
  • examples/lit decorators don't seem to work correctly:

These two are oxc transform issues and they are tracked in oxc-project/oxc#9168 and oxc-project/oxc#9129.

styles in the UI seem to be completely broken when built with vite-rolldown

Probably this is because of unocss plugin not working unocss/unocss#4403.

@sapphi-red
Copy link
Contributor

sapphi-red commented Feb 18, 2025

Great!

  • does optimizeDeps.rollupOptions.resolve.alias work? Browser Mode aliases vue packages to CJS versions testing-library is CJS (and it should import the same version of test-utils), and also we want to have the ability to use string slots and string templates

I've fixed that yesterday so maybe it'll work if you upgrade rolldown-vite.
vitejs/rolldown-vite@1eee1f5

  • seems like I see this message even if I didn't specify any esbuildOptions (we always check for an empty stderr and this breaks some tests):

You've set "optimizeDeps.esbuildOptions" in your config. This is deprecated and vite already use rollup to optimize packages. Please use "optimizeDeps.rollupOptions" instead.

I'll take a look this one.

  • optimizer unexpectedly re-optimizes dependencies with a message:

Is it actually re-optimized? or is it just the message? Ah, ok, it noticed that this message is shown by the scanner.

@sapphi-red
Copy link
Contributor

I've fixed the things related to warnings.

I also took a look the sourcemap one. I found that the sourcemaps output by OXC are slightly different from esbuild (oxc-project/oxc#9187). But I'm not sure if that's the reason.
I extracted the result here

const code = `${codeDefinition}${transformed}\n}}`

and tried to reproduce it minimally by doing

// run.mjs
import 'source-map-support/register.js'
globalThis.__vite_ssr_exports__ = {}
await import('./run2.mjs')
globalThis.__vite_ssr_exports__.setup()

// ---------------------------
// run2.mjs
'use strict';function setup() {
	void new Promise((_, reject) => reject(new Error("intentional unhandled rejection")));
}
Object.defineProperty(__vite_ssr_exports__, "setup", { enumerable: true, configurable: true, get(){ return setup }});

//# sourceMappingSource=vite-node
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6IkFBQU8sU0FBUyxRQUFRO0FBQ3RCLE1BQUssSUFBSSxRQUFRLENBQUMsR0FBRyxXQUFXLE9BQU8sSUFBSSxNQUFNLG1DQUFtQztBQUNyRiIsIm5hbWVzIjpbXSwiaWdub3JlTGlzdCI6W10sInNvdXJjZXMiOlsic2V0dXAtdW5oYW5kbGVkLXJlamVjdGlvbnMudHMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGZ1bmN0aW9uIHNldHVwKCkge1xuICB2b2lkIG5ldyBQcm9taXNlKChfLCByZWplY3QpID0+IHJlamVjdChuZXcgRXJyb3IoJ2ludGVudGlvbmFsIHVuaGFuZGxlZCByZWplY3Rpb24nKSkpXG59XG4iXSwiZmlsZSI6IkQ6L2RvY3VtZW50cy9HaXRIdWIvdml0ZXN0L3Rlc3QvY29uZmlnL2ZpeHR1cmVzL3VuaGFuZGxlZC1yZWplY3Rpb25zL3NldHVwLXVuaGFuZGxlZC1yZWplY3Rpb25zLnRzIn0=

But the error message showed setup-unhandled-rejections.ts:2:42.

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Feb 18, 2025

Ah, I should've mentioned earlier. Source map for global setup is not supported due to Vitest side #7101. The current assertion setup-unhandled-rejections.ts:2:42 works because transform output miraculously matched original source.

@sapphi-red
Copy link
Contributor

Ah, I see.

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Feb 18, 2025

@sheremet-va How did you run this PR locally? If I added rolldown-vite overrides, some dts build is failing, for example:

$ pnpm -C packages/vite-node build
src/source-map.ts(36,37): error TS7006: Parameter 'source' implicitly has an 'any' type.

[!] (plugin dts) RollupError: [plugin dts] src/source-map.ts: Failed to compile. Check the logs above.
src/source-map.ts

(The odd thing is that I don't see type error red squiggles on vscode and I have no idea what's the issue)

@sheremet-va
Copy link
Member Author

@sheremet-va How did you run this PR locally? If I added rolldown-vite overrides, some dts build is failing, for example:

$ pnpm -C packages/vite-node build

src/source-map.ts(36,37): error TS7006: Parameter 'source' implicitly has an 'any' type.



[!] (plugin dts) RollupError: [plugin dts] src/source-map.ts: Failed to compile. Check the logs above.

src/source-map.ts

(The odd thing is that I don't see type error red squiggles on vscode and I have no idea what's the issue)

I added link: override manually to overrides in the top level package.json

Did you build vite package?

@hi-ogawa
Copy link
Contributor

Hmm, I was using file: and that was failing. Switched to link: and now it's working on Vitest 👍 I can continue with this, but it might come back when using released package 🤔

@sheremet-va
Copy link
Member Author

Ah, I should've mentioned earlier. Source map for global setup is not supported due to Vitest side #7101. The current assertion setup-unhandled-rejections.ts:2:42 works because transform output miraculously matched original source.

There is another difference with source maps. I am not sure if it's correct or not, I think it is caused by a difference in boundaries. This code previously had a different column:

test.each([1, 2])('custom %s', () => {
//                ^ previously returned this column
//               ^ now returns this column
})

Raw JavaScript returns the column that Rolldown returns. We had to do column-1 to get the correct column here, now this code is gone.

@sheremet-va
Copy link
Member Author

sheremet-va commented Feb 18, 2025

I've fixed that yesterday so maybe it'll work if you upgrade rolldown-vite.

I used the same version yesterday. Still doesn't work (tried again today). I also tried ^@vue/test-utils$ alias, but it still doesn't seem to work. I am testing in this repo - https://github.com/vitest-dev/vitest-browser-vue (the last test expects template to work)

@sapphi-red
Copy link
Contributor

I've fixed that yesterday so maybe it'll work if you upgrade rolldown-vite.

I used the same version yesterday. Still doesn't work (tried again today). I also tried ^@vue/test-utils$ alias, but it still doesn't seem to work. I am testing in this repo - https://github.com/vitest-dev/vitest-browser-vue (the last test expects template to work)

I think the value needs to be a resolved path instead of a unresolved specifier here.
https://github.com/vitest-dev/vitest/pull/7509/files#diff-929cb96abb1c2e297c6711af0875db4ecdc700c54b824cc4ce7e0716657b28aeR537-R543
But given that the importer is not static, I guess it needs to be a plugin like it was in esbuild.
It's confusing that resolve.alias of rolldown works differently from vite or plugin-alias's resolve.alias. I'll make a feedback to them.

@sapphi-red
Copy link
Contributor

Ah, no, it's not that resolve.alias working differently, it's because Vite's internal plugin runs before resolve.alias. I think the workaround for now would be to be using a plugin instead as the custom plugins runs before the internal plugin.

@sheremet-va
Copy link
Member Author

Ah, no, it's not that resolve.alias working differently, it's because Vite's internal plugin runs before resolve.alias. I think the workaround for now would be to be using a plugin instead as the custom plugins runs before the internal plugin.

A rolldown plugin seems to work correctly.

@sapphi-red
Copy link
Contributor

I merged vitejs/rolldown-vite#82 now, so the UI should be working now.

@sheremet-va
Copy link
Member Author

I merged rolldown/vite#82 now, so the UI should be working now.

Can confirm it does work now:

Screenshot 2025-02-19 at 15 08 52

@sheremet-va
Copy link
Member Author

sheremet-va commented Feb 19, 2025

I merged rolldown/vite#82 now, so the UI should be working now.

Is there a way to specify rolldown-vite as a dependency in this PR so CI can run with it? Ok, I see it supports pkg.pr.new

@sheremet-va
Copy link
Member Author

sheremet-va commented Jun 3, 2025

Seems like there is a small issue with Vue coverage again, could you help with that, @AriPerkkio?

@AriPerkkio
Copy link
Member

Seems like there is a small issue with Vue coverage again, could you help with that, @AriPerkkio?

Looks like this is failing only on the old v8 provider. Some generated code is increasing function and branch coverages. I think it's fine to leave as is, as we are planning to remove whole old v8-to-istanbul in next major.

You can just update the snapshots from the tests.

@sheremet-va
Copy link
Member Author

sheremet-va commented Jun 3, 2025

rolldown-vite now passes all tests, I am changing the dependency back to 6.3.5 and making it work there 😄

hi-ogawa
hi-ogawa previously approved these changes Jun 4, 2025
Copy link
Contributor

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

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

Looks good! I did a minor cleanup of package.json.

Copy link
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

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

We have couple of places where we use parseAst and parseAstAsync from Vite. Are those now using oxc-parser or the SWC parser via rollup?

@sapphi-red
Copy link
Contributor

We have couple of places where we use parseAst and parseAstAsync from Vite. Are those now using oxc-parser or the SWC parser via rollup?

parseAst and parseAstAsync exposed from rolldown-vite uses Oxc's parser.

@sheremet-va sheremet-va marked this pull request as ready for review June 4, 2025 06:40
@sheremet-va
Copy link
Member Author

sheremet-va commented Jun 4, 2025

Should we add a separate CI pipeline for rolldown-vite?

@sheremet-va sheremet-va merged commit c8d6264 into vitest-dev:main Jun 4, 2025
23 of 24 checks passed
@sheremet-va sheremet-va deleted the feat/rolldown-support branch June 4, 2025 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants