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

test rolldown-vite #673

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-server-dom-webpack": "^19.0.0",
"rollup": "^4.32.0",
"tsup": "^8.1.0",
"tsx": "^4.16.2",
"typescript": "^5.5.4",
"vite": "^6.0.11",
"vite": "https://pkg.pr.new/rolldown/vite@3f2fa15",
"vitest": "^3.0.3",
"wrangler": "^3.79.0"
},
Expand All @@ -38,6 +39,7 @@
},
"pnpm": {
"overrides": {
"rolldown": "1.0.0-beta.3-commit.7b515c0",
"vite": "$vite",
"react": "$react",
"react-dom": "$react-dom",
Expand Down
3 changes: 3 additions & 0 deletions packages/react-server-next/src/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
wrapServerPlugin,
} from "@hiogawa/react-server/plugin";
import {
rolldownPluginRollupFileUrl,
vitePluginFetchUrlImportMetaUrl,
vitePluginWasmModule,
} from "@hiogawa/vite-plugin-server-asset";
Expand Down Expand Up @@ -44,6 +45,7 @@ export default function vitePluginReactServerNext(
routeDir: options?.routeDir ?? "app",
}),
nextOgPlugin(),
rolldownPluginRollupFileUrl(),
wrapServerPlugin([
vitePluginWasmModule({
buildMode:
Expand Down Expand Up @@ -149,6 +151,7 @@ function nextJsxPlugin(): Plugin {
config: () => ({
esbuild: { jsx: "automatic" },
optimizeDeps: {
// TODO: what's the equivalent on oxc?
esbuildOptions: { jsx: "automatic", loader: { ".js": "jsx" } },
},
}),
Expand Down
6 changes: 5 additions & 1 deletion packages/react-server/examples/basic/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
wrapServerPlugin,
} from "@hiogawa/react-server/plugin";
import { vitePluginErrorOverlay } from "@hiogawa/vite-plugin-error-overlay";
import { vitePluginWasmModule } from "@hiogawa/vite-plugin-server-asset";
import {
rolldownPluginRollupFileUrl,
vitePluginWasmModule,
} from "@hiogawa/vite-plugin-server-asset";
import {
vitePluginLogger,
vitePluginSsrMiddleware,
Expand Down Expand Up @@ -56,6 +59,7 @@ export default defineConfig({
buildMode: process.env.VERCEL || process.env.CF_PAGES ? "import" : "fs",
}),
]),
rolldownPluginRollupFileUrl(),
],
build: {
ssrEmitAssets: true,
Expand Down
1 change: 1 addition & 0 deletions packages/react-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@hiogawa/transforms": "workspace:*",
"es-module-lexer": "^1.6.0",
"fast-glob": "^3.3.3",
"rollup": "^4.32.0",
"vitefu": "^1.0.5"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
transformDirectiveProxyExport,
} from "@hiogawa/transforms";
import { createDebug, memoize, tinyassert } from "@hiogawa/utils";
import { type Plugin, type ViteDevServer, parseAstAsync } from "vite";
import { parseAstAsync } from "rollup/parseAst";
// import { parseAstAsync } from "vite";
import { type Plugin, type ViteDevServer } from "vite";
import type { PluginStateManager } from "../../plugin";
import {
type CustomModuleMeta,
Expand Down
4 changes: 3 additions & 1 deletion packages/react-server/src/features/server-action/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {
transformServerActionServer,
} from "@hiogawa/transforms";
import { createDebug, tinyassert } from "@hiogawa/utils";
import { type Plugin, parseAstAsync } from "vite";
import { parseAstAsync } from "rollup/parseAst";
// import { parseAstAsync } from "vite";
import { type Plugin } from "vite";
import type { PluginStateManager } from "../../plugin";
import {
USE_SERVER,
Expand Down
23 changes: 23 additions & 0 deletions packages/react-server/vitest.config.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { transformWithEsbuild } from "vite";
import { defineConfig } from "vitest/config";

export default defineConfig({
// TODO: can oxc lower `using ...`?
oxc: {},
esbuild: {
supported: {
using: false,
Expand All @@ -12,4 +15,24 @@ export default defineConfig({
fileParallelism: false,
watch: false,
},
plugins: [
{
name: "esbuild-transform",
async transform(code, id, _options) {
if (id.endsWith(".ts") && code.includes("using")) {
const result = await transformWithEsbuild(code, id, {
sourcemap: true,
supported: {
using: false,
},
});
return {
code: result.code,
map: result.map,
};
}
return;
},
},
],
});
1 change: 1 addition & 0 deletions packages/server-asset/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { vitePluginFetchUrlImportMetaUrl } from "./import-meta-url";
export { vitePluginWasmModule } from "./wasm-module";
export { rolldownPluginRollupFileUrl } from "./rollup-file-url";
41 changes: 41 additions & 0 deletions packages/server-asset/src/rollup-file-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import path from "node:path";
import MagicString from "magic-string";
import type { Plugin } from "vite";

// import.meta.ROLLUP_FILE_URL_xxx on rolldown
// https://github.com/rolldown/rolldown/pull/1928
export function rolldownPluginRollupFileUrl(): Plugin {
return {
name: rolldownPluginRollupFileUrl.name,
renderChunk: {
order: "pre",
handler(code, chunk) {
if (!code.includes("import.meta.ROLLUP_FILE_URL_")) {
return;
}
const matches = code.matchAll(/import.meta.ROLLUP_FILE_URL_(\w+)/dg);
const output = new MagicString(code);
for (const match of matches) {
const referenceId = match[1]!;
const assetFileName = this.getFileName(referenceId);
const relativePath =
"./" +
path.relative(
path.resolve(chunk.fileName, ".."),
path.resolve(assetFileName),
);
const replacement = `new URL(${JSON.stringify(relativePath)}, import.meta.url)`;
const [start, end] = match.indices![0]!;
output.update(start, end, replacement);
}
if (output.hasChanged()) {
return {
code: output.toString(),
map: output.generateMap({ hires: "boundary" }),
};
}
return;
},
},
};
}
3 changes: 2 additions & 1 deletion packages/transforms/src/hoist.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parseAstAsync } from "vite";
import { parseAstAsync } from "rollup/parseAst";
// import { parseAstAsync } from "vite";
import { describe, expect, it } from "vitest";
import { transformHoistInlineDirective } from "./hoist";
import { debugSourceMap } from "./test-utils";
Expand Down
3 changes: 2 additions & 1 deletion packages/transforms/src/proxy-export.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parseAstAsync } from "vite";
import { parseAstAsync } from "rollup/parseAst";
// import { parseAstAsync } from "vite";
import { describe, expect, test } from "vitest";
import { transformProxyExport } from "./proxy-export";
import { transformWrapExport } from "./wrap-export";
Expand Down
3 changes: 2 additions & 1 deletion packages/transforms/src/wrap-export.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parseAstAsync } from "vite";
import { parseAstAsync } from "rollup/parseAst";
// import { parseAstAsync } from "vite";
import { describe, expect, test } from "vitest";
import { transformWrapExport } from "./wrap-export";

Expand Down
3 changes: 2 additions & 1 deletion packages/vite-plugin-simple-hmr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"release": "pnpm publish --no-git-checks --access public"
},
"dependencies": {
"magic-string": "^0.30.17"
"magic-string": "^0.30.17",
"rollup": "^4.32.0"
},
"devDependencies": {
"@types/estree": "^1.0.6"
Expand Down
3 changes: 2 additions & 1 deletion packages/vite-plugin-simple-hmr/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import MagicString from "magic-string";
import { parseAstAsync } from "vite";
import { parseAstAsync } from "rollup/parseAst";
// import { parseAstAsync } from "vite";
import { describe, expect, it } from "vitest";
import { analyzeExports, hmrTransform } from "./transform";

Expand Down
3 changes: 2 additions & 1 deletion packages/vite-plugin-simple-hmr/src/transform.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Node, Program } from "estree";
import MagicString from "magic-string";
import { parseAstAsync } from "vite";
import { parseAstAsync } from "rollup/parseAst";
// import { parseAstAsync } from "vite";
import { name as packageName } from "../package.json";

export async function hmrTransform(code: string) {
Expand Down
Loading
Loading