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

feat: support rolldown-vite #7509

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions examples/sveltekit/.gitignore

This file was deleted.

24 changes: 0 additions & 24 deletions examples/sveltekit/package.json

This file was deleted.

12 changes: 0 additions & 12 deletions examples/sveltekit/src/app.d.ts

This file was deleted.

12 changes: 0 additions & 12 deletions examples/sveltekit/src/app.html

This file was deleted.

8 changes: 0 additions & 8 deletions examples/sveltekit/src/lib/add.test.ts

This file was deleted.

9 changes: 0 additions & 9 deletions examples/sveltekit/src/lib/add.ts

This file was deleted.

2 changes: 0 additions & 2 deletions examples/sveltekit/src/routes/+page.svelte

This file was deleted.

Binary file removed examples/sveltekit/static/favicon.png
Binary file not shown.
18 changes: 0 additions & 18 deletions examples/sveltekit/svelte.config.js

This file was deleted.

17 changes: 0 additions & 17 deletions examples/sveltekit/tsconfig.json

This file was deleted.

6 changes: 0 additions & 6 deletions examples/sveltekit/vite.config.ts

This file was deleted.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,28 @@
"magic-string": "^0.30.17",
"pathe": "^2.0.3",
"rimraf": "^6.0.1",
"rolldown": "1.0.0-beta.3-commit.b546e53",
"rollup": "^4.34.8",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-esbuild": "^6.2.0",
"rollup-plugin-license": "^3.5.3",
"tinyglobby": "^0.2.11",
"tsx": "^4.19.2",
"typescript": "^5.7.3",
"vite": "^6.0.11",
"vite": "https://pkg.pr.new/rolldown/vite@7e5a8b6",
"vitest": "workspace:*",
"zx": "^8.3.2"
},
"pnpm": {
"overrides": {
"@types/node": "$@types/node",
"@vitest/browser": "workspace:*",
"@vitest/ui": "workspace:*",
"acorn": "8.11.3",
"esbuild": "$esbuild",
"mlly": "^1.7.4",
"rollup": "$rollup",
"tsx": "$tsx",
"vite": "$vite",
"vitest": "workspace:*"
},
Expand Down
17 changes: 9 additions & 8 deletions packages/browser/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,19 +533,20 @@ body {
config() {
return {
optimizeDeps: {
esbuildOptions: {
rollupOptions: {
plugins: [
{
name: 'test-utils-rewrite',
setup(build) {
name: 'vue-test-utils-rewrite',
resolveId: {
// test-utils: resolve to CJS instead of the browser because the browser version expects a global Vue object
// compiler-core: only CJS version allows slots as strings
build.onResolve({ filter: /^@vue\/(test-utils|compiler-core)$/ }, (args) => {
const resolved = getRequire().resolve(args.path, {
paths: [args.importer],
filter: { id: /^@vue\/(test-utils|compiler-core)$/ },
handler(source, importer) {
const resolved = getRequire().resolve(source, {
paths: [importer!],
})
return { path: resolved }
})
return resolved
},
},
},
],
Expand Down
2 changes: 0 additions & 2 deletions packages/mocker/src/node/dynamicImportPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export function dynamicImportPlugin(options: DynamicImportPluginOptions = {}): P
}

export interface DynamicImportInjectorResult {
ast: Rollup.ProgramNode
code: string
map: SourceMap
}
Expand Down Expand Up @@ -75,7 +74,6 @@ export function injectDynamicImport(
})

return {
ast,
code: s.toString(),
map: s.generateMap({ hires: 'boundary', source: id }),
}
Expand Down
3 changes: 1 addition & 2 deletions packages/mocker/src/node/esmWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type {
Property,
VariableDeclaration,
} from 'estree'
import type { Rollup } from 'vite'
import { walk as eswalk } from 'estree-walker'

export type * from 'estree'
Expand Down Expand Up @@ -61,7 +60,7 @@ export function isNodeInPattern(node: _Node): node is Property {
* Except this is using acorn AST
*/
export function esmWalker(
root: Rollup.ProgramNode,
root: any,
{ onIdentifier, onImportMeta, onDynamicImport, onCallExpression }: Visitors,
): void {
const parentStack: Node[] = []
Expand Down
5 changes: 2 additions & 3 deletions packages/mocker/src/node/hoistMocksPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ const regexpHoistable
const hashbangRE = /^#!.*\n/

export interface HoistMocksResult {
ast: Rollup.ProgramNode
code: string
map: SourceMap
}
Expand All @@ -149,7 +148,8 @@ export function hoistMocks(

const s = new MagicString(code)

let ast: Rollup.ProgramNode
// TODO: rolldown doesn't expose Rollup.Program, but exposes Rollup.PluginContext['parse'] that uses it
let ast: any
try {
ast = parse(code)
}
Expand Down Expand Up @@ -549,7 +549,6 @@ export function hoistMocks(
}

return {
ast,
code: s.toString(),
map: s.generateMap({ hires: 'boundary', source: id }),
}
Expand Down
4 changes: 3 additions & 1 deletion packages/vitest/src/node/plugins/normalizeURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export function NormalizeURLPlugin(): Plugin {

const cleanString = stripLiteral(code)
const assetImportMetaUrlRE
= /\bnew\s+URL\s*\(\s*(?:'[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*(?:,\s*)?\)/g
// vite injects new URL(path, import.meta.url) in the code
// rolldown injects new URL(path, '' + import.meta.url) in the code
= /\bnew\s+URL\s*\(\s*(?:'[^']+'|"[^"]+"|`[^`]+`)\s*,\s*(?:'' \+ )?import\.meta\.url\s*(?:,\s*)?\)/g

let updatedCode = code
let match: RegExpExecArray | null
Expand Down
Loading
Loading