diff --git a/.oxfmtrc.jsonc b/.oxfmtrc.jsonc new file mode 100644 index 000000000..548d21889 --- /dev/null +++ b/.oxfmtrc.jsonc @@ -0,0 +1,35 @@ +{ + "$schema": "./node_modules/oxfmt/configuration_schema.json", + // "printWidth": 120, + "singleQuote": true, + "semi": false, + "experimentalSortImports": {} + // "ignorePatterns": [ + // "tasks/transform_conformance/tests/**", + // "tasks/coverage/node-compat-table", + // "tasks/coverage/misc", + // "**/tests/**", + // "**/fixtures/**", + // "**/*.snap.*", + // "**/CHANGELOG.md", + // "pnpm-workspace.yaml", + // "pnpm-lock.yaml", + // "apps/oxlint/src-js/bindings.js", + // "apps/oxlint/src-js/bindings.d.ts", + // "!apps/oxlint/test/fixtures/**", + // "apps/oxlint/test/fixtures/**/*.snap.md", + // "napi/{transform,minify,playground}/index.js", + // "napi/{parser,transform,minify,playground}/**/index.d.ts", + // "napi/{parser,transform,minify,playground}/**/*.wasi-browser.js", + // "napi/{parser,transform,minify,playground}/**/*.wasi.cjs", + // "napi/{parser,transform,minify,playground}/**/wasi-worker-browser.mjs", + // "napi/{parser,transform,minify,playground}/**/wasi-worker.mjs", + // "napi/{parser,transform,minify,playground}/**/browser.js", + // "napi/parser/src-js/bindings.js", + // "npm/*/package.json", + // "npm/oxlint/configuration_schema.json", + // "npm/oxc-wasm/**", + // "npm/runtime/src", + // ".github/generated/ast_changes_watch_list.yml" + // ] +} diff --git a/eslint.config.js b/eslint.config.js index 1b2ff21dc..4db396442 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,11 +1,11 @@ -// @ts-check -import { builtinModules } from 'node:module' import eslint from '@eslint/js' -import pluginN from 'eslint-plugin-n' import pluginImportX from 'eslint-plugin-import-x' +import pluginN from 'eslint-plugin-n' import pluginRegExp from 'eslint-plugin-regexp' -import tseslint from 'typescript-eslint' import globals from 'globals' +// @ts-check +import { builtinModules } from 'node:module' +import tseslint from 'typescript-eslint' export default tseslint.config( { @@ -103,17 +103,17 @@ export default tseslint.config( { allow: builtinModules.map((mod) => `node:${mod}`) }, ], 'import-x/no-duplicates': 'error', - 'import-x/order': 'error', - 'sort-imports': [ - 'error', - { - ignoreCase: false, - ignoreDeclarationSort: true, - ignoreMemberSort: false, - memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'], - allowSeparatedGroups: false, - }, - ], + // "import-x/order": "error", + // "sort-imports": [ + // "error", + // { + // ignoreCase: false, + // ignoreDeclarationSort: true, + // ignoreMemberSort: false, + // memberSyntaxSortOrder: ["none", "all", "multiple", "single"], + // allowSeparatedGroups: false, + // }, + // ], 'regexp/prefer-regexp-exec': 'error', 'regexp/prefer-regexp-test': 'error', diff --git a/package.json b/package.json index d4f626e2d..86650515b 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "scripts": { "preinstall": "npx only-allow pnpm", "postinstall": "simple-git-hooks", - "format": "prettier --write --cache .", + "format": "oxfmt", "lint": "eslint --cache .", "typecheck": "tsc -p scripts && tsc -p playground && tsc -p packages/plugin-react", "test": "pnpm run test-unit && pnpm run test-serve && pnpm run test-build && pnpm --filter ./packages/plugin-react-swc run test", @@ -44,6 +44,7 @@ "fs-extra": "^11.3.2", "globals": "^16.4.0", "lint-staged": "^16.2.4", + "oxfmt": "^0.8.0", "picocolors": "^1.1.1", "playwright-chromium": "^1.56.1", "prettier": "^3.6.2", @@ -59,7 +60,7 @@ }, "lint-staged": { "*": [ - "prettier --write --cache --ignore-unknown" + "oxfmt" ], "packages/*/{src,types}/**/*.ts": [ "eslint --cache --fix" diff --git a/packages/common/refresh-utils.ts b/packages/common/refresh-utils.ts index ef9dc00f6..ddd34c633 100644 --- a/packages/common/refresh-utils.ts +++ b/packages/common/refresh-utils.ts @@ -1,5 +1,5 @@ -import type { Plugin } from 'vite' import { exactRegex } from '@rolldown/pluginutils' +import type { Plugin } from 'vite' export const runtimePublicPath = '/@react-refresh' diff --git a/packages/plugin-react-oxc/src/index.ts b/packages/plugin-react-oxc/src/index.ts index e42b7356a..d4d02b918 100644 --- a/packages/plugin-react-oxc/src/index.ts +++ b/packages/plugin-react-oxc/src/index.ts @@ -1,14 +1,14 @@ -import { dirname, join } from 'node:path' -import { fileURLToPath } from 'node:url' -import { readFileSync } from 'node:fs' -import type { BuildOptions, Plugin } from 'vite' +import { exactRegex } from '@rolldown/pluginutils' import { addRefreshWrapper, getPreambleCode, runtimePublicPath, silenceUseClientWarning, } from '@vitejs/react-common' -import { exactRegex } from '@rolldown/pluginutils' +import { readFileSync } from 'node:fs' +import { dirname, join } from 'node:path' +import { fileURLToPath } from 'node:url' +import type { BuildOptions, Plugin } from 'vite' const _dirname = dirname(fileURLToPath(import.meta.url)) const refreshRuntimePath = join(_dirname, 'refresh-runtime.js') diff --git a/packages/plugin-react-swc/playground/base-path/__tests__/base-path.spec.ts b/packages/plugin-react-swc/playground/base-path/__tests__/base-path.spec.ts index 715eb7a7c..cbbb621ee 100644 --- a/packages/plugin-react-swc/playground/base-path/__tests__/base-path.spec.ts +++ b/packages/plugin-react-swc/playground/base-path/__tests__/base-path.spec.ts @@ -1,5 +1,5 @@ -import { expect, test } from '@playwright/test' import { setupDevServer, setupWaitForLogs } from '../../utils.ts' +import { expect, test } from '@playwright/test' test('Base path HMR', async ({ page }) => { const { testUrl, server, editFile } = await setupDevServer('base-path') diff --git a/packages/plugin-react-swc/playground/base-path/src/index.tsx b/packages/plugin-react-swc/playground/base-path/src/index.tsx index 5e7046ce2..e62507a76 100644 --- a/packages/plugin-react-swc/playground/base-path/src/index.tsx +++ b/packages/plugin-react-swc/playground/base-path/src/index.tsx @@ -1,6 +1,6 @@ +import { App } from './App.tsx' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import { App } from './App.tsx' createRoot(document.getElementById('root')!).render( diff --git a/packages/plugin-react-swc/playground/base-path/vite.config.ts b/packages/plugin-react-swc/playground/base-path/vite.config.ts index 7bc60be8f..867d42f32 100644 --- a/packages/plugin-react-swc/playground/base-path/vite.config.ts +++ b/packages/plugin-react-swc/playground/base-path/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' +import { defineConfig } from 'vite' export default defineConfig({ plugins: [react()], diff --git a/packages/plugin-react-swc/playground/class-components/__tests__/class-components.spec.ts b/packages/plugin-react-swc/playground/class-components/__tests__/class-components.spec.ts index 14424e927..4582b41dd 100644 --- a/packages/plugin-react-swc/playground/class-components/__tests__/class-components.spec.ts +++ b/packages/plugin-react-swc/playground/class-components/__tests__/class-components.spec.ts @@ -1,5 +1,5 @@ -import { expect, test } from '@playwright/test' import { setupDevServer, setupWaitForLogs } from '../../utils.ts' +import { expect, test } from '@playwright/test' test('Class component HMR', async ({ page }) => { const { testUrl, server, editFile } = await setupDevServer('class-components') diff --git a/packages/plugin-react-swc/playground/class-components/src/App.tsx b/packages/plugin-react-swc/playground/class-components/src/App.tsx index 2b2cb5558..1e26173a6 100644 --- a/packages/plugin-react-swc/playground/class-components/src/App.tsx +++ b/packages/plugin-react-swc/playground/class-components/src/App.tsx @@ -1,5 +1,5 @@ -import { Component } from 'react' import { getGetting } from './utils.tsx' +import { Component } from 'react' export class App extends Component { render() { diff --git a/packages/plugin-react-swc/playground/class-components/src/index.tsx b/packages/plugin-react-swc/playground/class-components/src/index.tsx index 5e7046ce2..e62507a76 100644 --- a/packages/plugin-react-swc/playground/class-components/src/index.tsx +++ b/packages/plugin-react-swc/playground/class-components/src/index.tsx @@ -1,6 +1,6 @@ +import { App } from './App.tsx' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import { App } from './App.tsx' createRoot(document.getElementById('root')!).render( diff --git a/packages/plugin-react-swc/playground/class-components/vite.config.ts b/packages/plugin-react-swc/playground/class-components/vite.config.ts index 7af9f6f97..9808d13cf 100644 --- a/packages/plugin-react-swc/playground/class-components/vite.config.ts +++ b/packages/plugin-react-swc/playground/class-components/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' +import { defineConfig } from 'vite' export default defineConfig({ plugins: [react()], diff --git a/packages/plugin-react-swc/playground/decorators/__tests__/decorators.spec.ts b/packages/plugin-react-swc/playground/decorators/__tests__/decorators.spec.ts index 89783fc2b..4eb26a6a5 100644 --- a/packages/plugin-react-swc/playground/decorators/__tests__/decorators.spec.ts +++ b/packages/plugin-react-swc/playground/decorators/__tests__/decorators.spec.ts @@ -1,5 +1,5 @@ -import { expect, test } from '@playwright/test' import { setupBuildAndPreview, setupDevServer } from '../../utils.ts' +import { expect, test } from '@playwright/test' test('Decorators build', async ({ page }) => { const { testUrl, server } = await setupBuildAndPreview('decorators') diff --git a/packages/plugin-react-swc/playground/decorators/src/index.tsx b/packages/plugin-react-swc/playground/decorators/src/index.tsx index 5e7046ce2..e62507a76 100644 --- a/packages/plugin-react-swc/playground/decorators/src/index.tsx +++ b/packages/plugin-react-swc/playground/decorators/src/index.tsx @@ -1,6 +1,6 @@ +import { App } from './App.tsx' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import { App } from './App.tsx' createRoot(document.getElementById('root')!).render( diff --git a/packages/plugin-react-swc/playground/decorators/vite.config.ts b/packages/plugin-react-swc/playground/decorators/vite.config.ts index a2d1b8860..6a8ef0460 100644 --- a/packages/plugin-react-swc/playground/decorators/vite.config.ts +++ b/packages/plugin-react-swc/playground/decorators/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' +import { defineConfig } from 'vite' export default defineConfig({ plugins: [react({ tsDecorators: true })], diff --git a/packages/plugin-react-swc/playground/emotion-plugin/__tests__/emotion-plugin.spec.ts b/packages/plugin-react-swc/playground/emotion-plugin/__tests__/emotion-plugin.spec.ts index 9fcdd8be8..510e185d9 100644 --- a/packages/plugin-react-swc/playground/emotion-plugin/__tests__/emotion-plugin.spec.ts +++ b/packages/plugin-react-swc/playground/emotion-plugin/__tests__/emotion-plugin.spec.ts @@ -1,10 +1,10 @@ -import { expect, test } from '@playwright/test' import { expectColor, setupBuildAndPreview, setupDevServer, setupWaitForLogs, } from '../../utils.ts' +import { expect, test } from '@playwright/test' test('Emotion plugin build', async ({ page }) => { const { testUrl, server } = await setupBuildAndPreview('emotion-plugin') diff --git a/packages/plugin-react-swc/playground/emotion-plugin/src/Button.jsx b/packages/plugin-react-swc/playground/emotion-plugin/src/Button.jsx index 56c363572..ebc90a14e 100644 --- a/packages/plugin-react-swc/playground/emotion-plugin/src/Button.jsx +++ b/packages/plugin-react-swc/playground/emotion-plugin/src/Button.jsx @@ -1,5 +1,5 @@ -import styled from '@emotion/styled' import { css } from '@emotion/react' +import styled from '@emotion/styled' import { useState } from 'react' // Ensure HMR of styled component alongside other components diff --git a/packages/plugin-react-swc/playground/emotion-plugin/src/index.jsx b/packages/plugin-react-swc/playground/emotion-plugin/src/index.jsx index 67f3599ee..9b09a50bb 100644 --- a/packages/plugin-react-swc/playground/emotion-plugin/src/index.jsx +++ b/packages/plugin-react-swc/playground/emotion-plugin/src/index.jsx @@ -1,6 +1,6 @@ +import { App } from './App.jsx' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import { App } from './App.jsx' import './index.css' createRoot(document.getElementById('root')).render( diff --git a/packages/plugin-react-swc/playground/emotion-plugin/vite.config.js b/packages/plugin-react-swc/playground/emotion-plugin/vite.config.js index 98ac529c9..a9376b589 100644 --- a/packages/plugin-react-swc/playground/emotion-plugin/vite.config.js +++ b/packages/plugin-react-swc/playground/emotion-plugin/vite.config.js @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' +import { defineConfig } from 'vite' export default defineConfig({ plugins: [ diff --git a/packages/plugin-react-swc/playground/emotion/__tests__/emotion.spec.ts b/packages/plugin-react-swc/playground/emotion/__tests__/emotion.spec.ts index 455fab7ba..4aa1088ff 100644 --- a/packages/plugin-react-swc/playground/emotion/__tests__/emotion.spec.ts +++ b/packages/plugin-react-swc/playground/emotion/__tests__/emotion.spec.ts @@ -1,10 +1,10 @@ -import { expect, test } from '@playwright/test' import { expectColor, setupBuildAndPreview, setupDevServer, setupWaitForLogs, } from '../../utils.ts' +import { expect, test } from '@playwright/test' test('Emotion build', async ({ page }) => { const { testUrl, server } = await setupBuildAndPreview('emotion') diff --git a/packages/plugin-react-swc/playground/emotion/src/Button.tsx b/packages/plugin-react-swc/playground/emotion/src/Button.tsx index 8bd3ad6e3..98c3318d8 100644 --- a/packages/plugin-react-swc/playground/emotion/src/Button.tsx +++ b/packages/plugin-react-swc/playground/emotion/src/Button.tsx @@ -1,5 +1,5 @@ -import styled from '@emotion/styled' import { css } from '@emotion/react' +import styled from '@emotion/styled' import { useState } from 'react' // Ensure HMR of styled component alongside other components diff --git a/packages/plugin-react-swc/playground/emotion/src/index.tsx b/packages/plugin-react-swc/playground/emotion/src/index.tsx index ee852372c..67290e867 100644 --- a/packages/plugin-react-swc/playground/emotion/src/index.tsx +++ b/packages/plugin-react-swc/playground/emotion/src/index.tsx @@ -1,6 +1,6 @@ +import { App } from './App.tsx' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import { App } from './App.tsx' import './index.css' createRoot(document.getElementById('root')!).render( diff --git a/packages/plugin-react-swc/playground/emotion/vite.config.ts b/packages/plugin-react-swc/playground/emotion/vite.config.ts index cfb4c0283..7f1088171 100644 --- a/packages/plugin-react-swc/playground/emotion/vite.config.ts +++ b/packages/plugin-react-swc/playground/emotion/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' +import { defineConfig } from 'vite' export default defineConfig({ plugins: [react({ jsxImportSource: '@emotion/react' })], diff --git a/packages/plugin-react-swc/playground/hmr/__tests__/hmr.spec.ts b/packages/plugin-react-swc/playground/hmr/__tests__/hmr.spec.ts index 714bf8a5d..ca7ae0a75 100644 --- a/packages/plugin-react-swc/playground/hmr/__tests__/hmr.spec.ts +++ b/packages/plugin-react-swc/playground/hmr/__tests__/hmr.spec.ts @@ -1,9 +1,9 @@ -import { expect, test } from '@playwright/test' import { setupBuildAndPreview, setupDevServer, setupWaitForLogs, } from '../../utils.ts' +import { expect, test } from '@playwright/test' test('Default build', async ({ page }) => { const { testUrl, server } = await setupBuildAndPreview('hmr') diff --git a/packages/plugin-react-swc/playground/hmr/src/App.tsx b/packages/plugin-react-swc/playground/hmr/src/App.tsx index b97d2d061..33d937819 100644 --- a/packages/plugin-react-swc/playground/hmr/src/App.tsx +++ b/packages/plugin-react-swc/playground/hmr/src/App.tsx @@ -1,7 +1,7 @@ -import { useState } from 'react' import reactLogo from './react.svg' -import './App.css' import { TitleWithExport, framework } from './TitleWithExport.tsx' +import './App.css' +import { useState } from 'react' export const App = () => { const [count, setCount] = useState(0) diff --git a/packages/plugin-react-swc/playground/hmr/src/index.tsx b/packages/plugin-react-swc/playground/hmr/src/index.tsx index ee852372c..67290e867 100644 --- a/packages/plugin-react-swc/playground/hmr/src/index.tsx +++ b/packages/plugin-react-swc/playground/hmr/src/index.tsx @@ -1,6 +1,6 @@ +import { App } from './App.tsx' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import { App } from './App.tsx' import './index.css' createRoot(document.getElementById('root')!).render( diff --git a/packages/plugin-react-swc/playground/hmr/vite.config.ts b/packages/plugin-react-swc/playground/hmr/vite.config.ts index 7af9f6f97..9808d13cf 100644 --- a/packages/plugin-react-swc/playground/hmr/vite.config.ts +++ b/packages/plugin-react-swc/playground/hmr/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' +import { defineConfig } from 'vite' export default defineConfig({ plugins: [react()], diff --git a/packages/plugin-react-swc/playground/mdx/__tests__/mdx.spec.ts b/packages/plugin-react-swc/playground/mdx/__tests__/mdx.spec.ts index 41562b946..1bc08076c 100644 --- a/packages/plugin-react-swc/playground/mdx/__tests__/mdx.spec.ts +++ b/packages/plugin-react-swc/playground/mdx/__tests__/mdx.spec.ts @@ -1,9 +1,9 @@ -import { expect, test } from '@playwright/test' import { setupBuildAndPreview, setupDevServer, setupWaitForLogs, } from '../../utils.ts' +import { expect, test } from '@playwright/test' test('MDX build', async ({ page }) => { const { testUrl, server } = await setupBuildAndPreview('mdx') diff --git a/packages/plugin-react-swc/playground/mdx/src/index.tsx b/packages/plugin-react-swc/playground/mdx/src/index.tsx index 952de6f5c..8ca2dbea1 100644 --- a/packages/plugin-react-swc/playground/mdx/src/index.tsx +++ b/packages/plugin-react-swc/playground/mdx/src/index.tsx @@ -1,6 +1,6 @@ +import Hello from './hello.mdx' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import Hello from './hello.mdx' createRoot(document.getElementById('root')!).render( diff --git a/packages/plugin-react-swc/playground/mdx/vite.config.ts b/packages/plugin-react-swc/playground/mdx/vite.config.ts index ff4f655ad..b441f3033 100644 --- a/packages/plugin-react-swc/playground/mdx/vite.config.ts +++ b/packages/plugin-react-swc/playground/mdx/vite.config.ts @@ -1,6 +1,6 @@ -import { defineConfig } from 'vite' import mdx from '@mdx-js/rollup' import react from '@vitejs/plugin-react-swc' +import { defineConfig } from 'vite' export default defineConfig({ plugins: [mdx(), react()], diff --git a/packages/plugin-react-swc/playground/react-18/__tests__/react-18.spec.ts b/packages/plugin-react-swc/playground/react-18/__tests__/react-18.spec.ts index 2902307fc..f7a4d680f 100644 --- a/packages/plugin-react-swc/playground/react-18/__tests__/react-18.spec.ts +++ b/packages/plugin-react-swc/playground/react-18/__tests__/react-18.spec.ts @@ -1,9 +1,9 @@ -import { expect, test } from '@playwright/test' import { setupBuildAndPreview, setupDevServer, setupWaitForLogs, } from '../../utils.ts' +import { expect, test } from '@playwright/test' test('Default build', async ({ page }) => { const { testUrl, server } = await setupBuildAndPreview('react-18') diff --git a/packages/plugin-react-swc/playground/react-18/src/App.tsx b/packages/plugin-react-swc/playground/react-18/src/App.tsx index b97d2d061..33d937819 100644 --- a/packages/plugin-react-swc/playground/react-18/src/App.tsx +++ b/packages/plugin-react-swc/playground/react-18/src/App.tsx @@ -1,7 +1,7 @@ -import { useState } from 'react' import reactLogo from './react.svg' -import './App.css' import { TitleWithExport, framework } from './TitleWithExport.tsx' +import './App.css' +import { useState } from 'react' export const App = () => { const [count, setCount] = useState(0) diff --git a/packages/plugin-react-swc/playground/react-18/src/index.tsx b/packages/plugin-react-swc/playground/react-18/src/index.tsx index ee852372c..67290e867 100644 --- a/packages/plugin-react-swc/playground/react-18/src/index.tsx +++ b/packages/plugin-react-swc/playground/react-18/src/index.tsx @@ -1,6 +1,6 @@ +import { App } from './App.tsx' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import { App } from './App.tsx' import './index.css' createRoot(document.getElementById('root')!).render( diff --git a/packages/plugin-react-swc/playground/react-18/vite.config.ts b/packages/plugin-react-swc/playground/react-18/vite.config.ts index 7af9f6f97..9808d13cf 100644 --- a/packages/plugin-react-swc/playground/react-18/vite.config.ts +++ b/packages/plugin-react-swc/playground/react-18/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' +import { defineConfig } from 'vite' export default defineConfig({ plugins: [react()], diff --git a/packages/plugin-react-swc/playground/shadow-export/__tests__/shadow-export.spec.ts b/packages/plugin-react-swc/playground/shadow-export/__tests__/shadow-export.spec.ts index b1aadffb9..7eb7d1fd6 100644 --- a/packages/plugin-react-swc/playground/shadow-export/__tests__/shadow-export.spec.ts +++ b/packages/plugin-react-swc/playground/shadow-export/__tests__/shadow-export.spec.ts @@ -1,5 +1,5 @@ -import { expect, test } from '@playwright/test' import { setupDevServer, setupWaitForLogs } from '../../utils.ts' +import { expect, test } from '@playwright/test' test('Shadow export HMR', async ({ page }) => { const { testUrl, server, editFile } = await setupDevServer('shadow-export') diff --git a/packages/plugin-react-swc/playground/shadow-export/src/index.tsx b/packages/plugin-react-swc/playground/shadow-export/src/index.tsx index 5e7046ce2..e62507a76 100644 --- a/packages/plugin-react-swc/playground/shadow-export/src/index.tsx +++ b/packages/plugin-react-swc/playground/shadow-export/src/index.tsx @@ -1,6 +1,6 @@ +import { App } from './App.tsx' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import { App } from './App.tsx' createRoot(document.getElementById('root')!).render( diff --git a/packages/plugin-react-swc/playground/shadow-export/vite.config.ts b/packages/plugin-react-swc/playground/shadow-export/vite.config.ts index 7af9f6f97..9808d13cf 100644 --- a/packages/plugin-react-swc/playground/shadow-export/vite.config.ts +++ b/packages/plugin-react-swc/playground/shadow-export/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' +import { defineConfig } from 'vite' export default defineConfig({ plugins: [react()], diff --git a/packages/plugin-react-swc/playground/styled-components/__tests__/styled-components.spec.ts b/packages/plugin-react-swc/playground/styled-components/__tests__/styled-components.spec.ts index da8e44713..4ce6d4f44 100644 --- a/packages/plugin-react-swc/playground/styled-components/__tests__/styled-components.spec.ts +++ b/packages/plugin-react-swc/playground/styled-components/__tests__/styled-components.spec.ts @@ -1,10 +1,10 @@ -import { expect, test } from '@playwright/test' import { expectColor, setupBuildAndPreview, setupDevServer, setupWaitForLogs, } from '../../utils.ts' +import { expect, test } from '@playwright/test' test('styled-components build', async ({ page }) => { const { testUrl, server } = await setupBuildAndPreview('styled-components') diff --git a/packages/plugin-react-swc/playground/styled-components/src/Button.tsx b/packages/plugin-react-swc/playground/styled-components/src/Button.tsx index 44be3f5bf..5a5030867 100644 --- a/packages/plugin-react-swc/playground/styled-components/src/Button.tsx +++ b/packages/plugin-react-swc/playground/styled-components/src/Button.tsx @@ -1,5 +1,5 @@ -import styled, { css } from 'styled-components' import { useState } from 'react' +import styled, { css } from 'styled-components' // Ensure HMR of styled component alongside other components export const StyledCode = styled.code` diff --git a/packages/plugin-react-swc/playground/styled-components/src/index.tsx b/packages/plugin-react-swc/playground/styled-components/src/index.tsx index ee852372c..67290e867 100644 --- a/packages/plugin-react-swc/playground/styled-components/src/index.tsx +++ b/packages/plugin-react-swc/playground/styled-components/src/index.tsx @@ -1,6 +1,6 @@ +import { App } from './App.tsx' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import { App } from './App.tsx' import './index.css' createRoot(document.getElementById('root')!).render( diff --git a/packages/plugin-react-swc/playground/styled-components/vite.config.ts b/packages/plugin-react-swc/playground/styled-components/vite.config.ts index f852b23ee..c47750bab 100644 --- a/packages/plugin-react-swc/playground/styled-components/vite.config.ts +++ b/packages/plugin-react-swc/playground/styled-components/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' +import { defineConfig } from 'vite' export default defineConfig({ plugins: [react({ plugins: [['@swc/plugin-styled-components', {}]] })], diff --git a/packages/plugin-react-swc/playground/ts-lib/__tests__/ts-lib.spec.ts b/packages/plugin-react-swc/playground/ts-lib/__tests__/ts-lib.spec.ts index 7f3357908..0c245f7a2 100644 --- a/packages/plugin-react-swc/playground/ts-lib/__tests__/ts-lib.spec.ts +++ b/packages/plugin-react-swc/playground/ts-lib/__tests__/ts-lib.spec.ts @@ -1,5 +1,5 @@ -import { type Page, expect, test } from '@playwright/test' import { setupBuildAndPreview, setupDevServer } from '../../utils.ts' +import { type Page, expect, test } from '@playwright/test' test('TS lib build', async ({ page }) => { const { testUrl, server } = await setupBuildAndPreview('ts-lib') diff --git a/packages/plugin-react-swc/playground/ts-lib/src/index.tsx b/packages/plugin-react-swc/playground/ts-lib/src/index.tsx index c0e262737..7fb772846 100644 --- a/packages/plugin-react-swc/playground/ts-lib/src/index.tsx +++ b/packages/plugin-react-swc/playground/ts-lib/src/index.tsx @@ -1,6 +1,6 @@ +import App from './app' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import App from './app' createRoot(document.getElementById('root')!).render( diff --git a/packages/plugin-react-swc/playground/ts-lib/vite.config.ts b/packages/plugin-react-swc/playground/ts-lib/vite.config.ts index 7af9f6f97..9808d13cf 100644 --- a/packages/plugin-react-swc/playground/ts-lib/vite.config.ts +++ b/packages/plugin-react-swc/playground/ts-lib/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' +import { defineConfig } from 'vite' export default defineConfig({ plugins: [react()], diff --git a/packages/plugin-react-swc/playground/utils.ts b/packages/plugin-react-swc/playground/utils.ts index 751b22f79..033412ba8 100644 --- a/packages/plugin-react-swc/playground/utils.ts +++ b/packages/plugin-react-swc/playground/utils.ts @@ -1,5 +1,5 @@ -import { readFileSync, writeFileSync } from 'node:fs' import { type Locator, type Page, expect } from '@playwright/test' +import { readFileSync, writeFileSync } from 'node:fs' import { build, createServer, diff --git a/packages/plugin-react-swc/playground/worker/__tests__/worker.spec.ts b/packages/plugin-react-swc/playground/worker/__tests__/worker.spec.ts index b0c7b2ce0..73e72ac67 100644 --- a/packages/plugin-react-swc/playground/worker/__tests__/worker.spec.ts +++ b/packages/plugin-react-swc/playground/worker/__tests__/worker.spec.ts @@ -1,9 +1,9 @@ -import { test } from '@playwright/test' import { setupBuildAndPreview, setupDevServer, setupWaitForLogs, } from '../../utils.ts' +import { test } from '@playwright/test' test('Worker build', async ({ page }) => { const { testUrl, server } = await setupBuildAndPreview('worker') diff --git a/packages/plugin-react-swc/playground/worker/src/App.tsx b/packages/plugin-react-swc/playground/worker/src/App.tsx index 055838c28..f77526ddc 100644 --- a/packages/plugin-react-swc/playground/worker/src/App.tsx +++ b/packages/plugin-react-swc/playground/worker/src/App.tsx @@ -1,5 +1,5 @@ -import { useState } from 'react' import MyWorker from './worker-via-import.ts?worker&inline' +import { useState } from 'react' new MyWorker() diff --git a/packages/plugin-react-swc/playground/worker/src/index.tsx b/packages/plugin-react-swc/playground/worker/src/index.tsx index 317caffbd..f3a9a1abe 100644 --- a/packages/plugin-react-swc/playground/worker/src/index.tsx +++ b/packages/plugin-react-swc/playground/worker/src/index.tsx @@ -1,6 +1,6 @@ +import { App } from './App.tsx' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import { App } from './App.tsx' new Worker(new URL('./worker-via-url.ts', import.meta.url), { type: 'module' }) diff --git a/packages/plugin-react-swc/playground/worker/vite.config.ts b/packages/plugin-react-swc/playground/worker/vite.config.ts index 7af9f6f97..9808d13cf 100644 --- a/packages/plugin-react-swc/playground/worker/vite.config.ts +++ b/packages/plugin-react-swc/playground/worker/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' +import { defineConfig } from 'vite' export default defineConfig({ plugins: [react()], diff --git a/packages/plugin-react-swc/playwright.config.ts b/packages/plugin-react-swc/playwright.config.ts index d7c8ae487..83f53183d 100644 --- a/packages/plugin-react-swc/playwright.config.ts +++ b/packages/plugin-react-swc/playwright.config.ts @@ -1,6 +1,6 @@ -import { fileURLToPath } from 'node:url' import { type PlaywrightTestConfig, devices } from '@playwright/test' import fs from 'fs-extra' +import { fileURLToPath } from 'node:url' const tempDir = fileURLToPath(new URL('playground-temp', import.meta.url)) fs.ensureDirSync(tempDir) diff --git a/packages/plugin-react-swc/src/index.ts b/packages/plugin-react-swc/src/index.ts index 242501818..76e5053cd 100644 --- a/packages/plugin-react-swc/src/index.ts +++ b/packages/plugin-react-swc/src/index.ts @@ -1,6 +1,4 @@ -import { readFileSync } from 'node:fs' -import { join } from 'node:path' -import { createRequire } from 'node:module' +import { exactRegex } from '@rolldown/pluginutils' import { type JscTarget, type Output, @@ -9,7 +7,6 @@ import { type Options as SWCOptions, transform, } from '@swc/core' -import type { Plugin } from 'vite' import { addRefreshWrapper, getPreambleCode, @@ -17,8 +14,11 @@ import { silenceUseClientWarning, virtualPreamblePlugin, } from '@vitejs/react-common' +import { readFileSync } from 'node:fs' +import { createRequire } from 'node:module' +import { join } from 'node:path' +import type { Plugin } from 'vite' import * as vite from 'vite' -import { exactRegex } from '@rolldown/pluginutils' const resolve = createRequire(import.meta.url).resolve diff --git a/packages/plugin-react-swc/tsdown.config.ts b/packages/plugin-react-swc/tsdown.config.ts index 4c2080beb..a8b93d581 100644 --- a/packages/plugin-react-swc/tsdown.config.ts +++ b/packages/plugin-react-swc/tsdown.config.ts @@ -1,6 +1,6 @@ +import packageJSON from './package.json' with { type: 'json' } import { writeFileSync } from 'node:fs' import { defineConfig } from 'tsdown' -import packageJSON from './package.json' with { type: 'json' } export default defineConfig({ entry: 'src/index.ts', diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index 6557e0e88..f13906d9a 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -1,11 +1,9 @@ -import { dirname, join } from 'node:path' -import { fileURLToPath } from 'node:url' -import { readFileSync } from 'node:fs' import type * as babelCore from '@babel/core' import type { ParserOptions, TransformOptions } from '@babel/core' -import { createFilter } from 'vite' -import * as vite from 'vite' -import type { Plugin, ResolvedConfig } from 'vite' +import { + exactRegex, + makeIdFiltersToMatchWithQuery, +} from '@rolldown/pluginutils' import { addRefreshWrapper, getPreambleCode, @@ -14,10 +12,12 @@ import { silenceUseClientWarning, virtualPreamblePlugin, } from '@vitejs/react-common' -import { - exactRegex, - makeIdFiltersToMatchWithQuery, -} from '@rolldown/pluginutils' +import { readFileSync } from 'node:fs' +import { dirname, join } from 'node:path' +import { fileURLToPath } from 'node:url' +import { createFilter } from 'vite' +import * as vite from 'vite' +import type { Plugin, ResolvedConfig } from 'vite' const _dirname = dirname(fileURLToPath(import.meta.url)) const refreshRuntimePath = join(_dirname, 'refresh-runtime.js') diff --git a/packages/plugin-react/tests/rolldown.test.ts b/packages/plugin-react/tests/rolldown.test.ts index e62e7cb53..168077af5 100644 --- a/packages/plugin-react/tests/rolldown.test.ts +++ b/packages/plugin-react/tests/rolldown.test.ts @@ -1,7 +1,7 @@ +import pluginReact, { type Options } from '../src/index.ts' import path from 'node:path' -import { expect, test } from 'vitest' import { type Plugin, rolldown } from 'rolldown' -import pluginReact, { type Options } from '../src/index.ts' +import { expect, test } from 'vitest' test('HMR related code should not be included when using rolldown', async () => { const { output } = await bundleWithRolldown() diff --git a/packages/plugin-rsc/e2e/base.test.ts b/packages/plugin-rsc/e2e/base.test.ts index 1f651b9d0..6025ef405 100644 --- a/packages/plugin-rsc/e2e/base.test.ts +++ b/packages/plugin-rsc/e2e/base.test.ts @@ -1,6 +1,6 @@ -import { expect, test } from '@playwright/test' import { setupInlineFixture, useFixture, type Fixture } from './fixture' import { defineStarterTest } from './starter' +import { expect, test } from '@playwright/test' test.describe(() => { const root = 'examples/e2e/temp/base' diff --git a/packages/plugin-rsc/e2e/basic.test.ts b/packages/plugin-rsc/e2e/basic.test.ts index 1306ee314..427000bb6 100644 --- a/packages/plugin-rsc/e2e/basic.test.ts +++ b/packages/plugin-rsc/e2e/basic.test.ts @@ -1,6 +1,3 @@ -import { createHash } from 'node:crypto' -import { readFileSync } from 'node:fs' -import { type Page, expect, test } from '@playwright/test' import { type Fixture, useCreateEditor, useFixture } from './fixture' import { expectNoPageError, @@ -8,9 +5,12 @@ import { testNoJs, waitForHydration, } from './helper' +import { type Page, expect, test } from '@playwright/test' +import { createHash } from 'node:crypto' +import { readFileSync } from 'node:fs' +import path from 'node:path' import { x } from 'tinyexec' import { normalizePath, type Rollup } from 'vite' -import path from 'node:path' test.describe('dev-default', () => { const f = useFixture({ root: 'examples/basic', mode: 'dev' }) diff --git a/packages/plugin-rsc/e2e/browser-mode.test.ts b/packages/plugin-rsc/e2e/browser-mode.test.ts index 84280fd14..ad56f6b3d 100644 --- a/packages/plugin-rsc/e2e/browser-mode.test.ts +++ b/packages/plugin-rsc/e2e/browser-mode.test.ts @@ -1,6 +1,6 @@ -import { expect, test, type Page } from '@playwright/test' import { useFixture } from './fixture' import { defineStarterTest } from './starter' +import { expect, test, type Page } from '@playwright/test' // Webkit fails by // > TypeError: ReadableByteStreamController is not implemented diff --git a/packages/plugin-rsc/e2e/browser.test.ts b/packages/plugin-rsc/e2e/browser.test.ts index 3b5898047..52ca79d41 100644 --- a/packages/plugin-rsc/e2e/browser.test.ts +++ b/packages/plugin-rsc/e2e/browser.test.ts @@ -1,8 +1,8 @@ -import { expect, test } from '@playwright/test' import { useFixture } from './fixture' import { defineStarterTest } from './starter' -import path from 'node:path' +import { expect, test } from '@playwright/test' import fs from 'node:fs' +import path from 'node:path' // Webkit fails by // > TypeError: ReadableByteStreamController is not implemented diff --git a/packages/plugin-rsc/e2e/build-app.test.ts b/packages/plugin-rsc/e2e/build-app.test.ts index d4b831cf8..f99e5af20 100644 --- a/packages/plugin-rsc/e2e/build-app.test.ts +++ b/packages/plugin-rsc/e2e/build-app.test.ts @@ -1,7 +1,7 @@ -import { test, expect } from '@playwright/test' import { setupInlineFixture, useFixture } from './fixture' -import { x } from 'tinyexec' import { waitForHydration } from './helper' +import { test, expect } from '@playwright/test' +import { x } from 'tinyexec' test.describe('buildApp hook', () => { const root = 'examples/e2e/temp/buildApp' diff --git a/packages/plugin-rsc/e2e/cloudflare.test.ts b/packages/plugin-rsc/e2e/cloudflare.test.ts index 0f26214fe..9e416a909 100644 --- a/packages/plugin-rsc/e2e/cloudflare.test.ts +++ b/packages/plugin-rsc/e2e/cloudflare.test.ts @@ -1,6 +1,6 @@ -import { test } from '@playwright/test' import { useFixture } from './fixture' import { defineStarterTest } from './starter' +import { test } from '@playwright/test' test.describe('dev-cloudflare', () => { const f = useFixture({ root: 'examples/starter-cf-single', mode: 'dev' }) diff --git a/packages/plugin-rsc/e2e/error.test.ts b/packages/plugin-rsc/e2e/error.test.ts index ea2b63b11..ace45872c 100644 --- a/packages/plugin-rsc/e2e/error.test.ts +++ b/packages/plugin-rsc/e2e/error.test.ts @@ -1,5 +1,5 @@ -import { test, expect } from '@playwright/test' import { setupInlineFixture } from './fixture' +import { test, expect } from '@playwright/test' import { x } from 'tinyexec' test.describe('invalid directives', () => { diff --git a/packages/plugin-rsc/e2e/fixture.ts b/packages/plugin-rsc/e2e/fixture.ts index a34d298da..b61ed3f31 100644 --- a/packages/plugin-rsc/e2e/fixture.ts +++ b/packages/plugin-rsc/e2e/fixture.ts @@ -1,9 +1,9 @@ +import test from '@playwright/test' import assert from 'node:assert' import { type SpawnOptions, spawn } from 'node:child_process' import fs from 'node:fs' import path from 'node:path' import { stripVTControlCharacters, styleText } from 'node:util' -import test from '@playwright/test' import { x } from 'tinyexec' function runCli(options: { command: string; label?: string } & SpawnOptions) { diff --git a/packages/plugin-rsc/e2e/isolated.test.ts b/packages/plugin-rsc/e2e/isolated.test.ts index d67a91be4..ac9ef4847 100644 --- a/packages/plugin-rsc/e2e/isolated.test.ts +++ b/packages/plugin-rsc/e2e/isolated.test.ts @@ -1,11 +1,11 @@ -import { expect, test, type Page } from '@playwright/test' import { setupIsolatedFixture, useFixture } from './fixture' +import { waitForHydration } from './helper' import { defineStarterTest } from './starter' -import path from 'node:path' +import { expect, test, type Page } from '@playwright/test' import os from 'node:os' -import * as vite from 'vite' -import { waitForHydration } from './helper' +import path from 'node:path' import { x } from 'tinyexec' +import * as vite from 'vite' test.describe(() => { // use RUNNER_TEMP on Github Actions diff --git a/packages/plugin-rsc/e2e/middleware-mode.test.ts b/packages/plugin-rsc/e2e/middleware-mode.test.ts index 12b75e0ef..713496403 100644 --- a/packages/plugin-rsc/e2e/middleware-mode.test.ts +++ b/packages/plugin-rsc/e2e/middleware-mode.test.ts @@ -1,6 +1,6 @@ -import { test } from '@playwright/test' import { setupInlineFixture, useFixture } from './fixture' import { defineStarterTest } from './starter' +import { test } from '@playwright/test' test.describe(() => { const root = 'examples/e2e/temp/middleware-mode' diff --git a/packages/plugin-rsc/e2e/module-runner.test.ts b/packages/plugin-rsc/e2e/module-runner.test.ts index 382495acb..dfd946727 100644 --- a/packages/plugin-rsc/e2e/module-runner.test.ts +++ b/packages/plugin-rsc/e2e/module-runner.test.ts @@ -1,6 +1,6 @@ -import { test } from '@playwright/test' import { setupInlineFixture, useFixture } from './fixture' import { defineStarterTest } from './starter' +import { test } from '@playwright/test' test.describe(() => { const root = 'examples/e2e/temp/module-runner-hmr-false' diff --git a/packages/plugin-rsc/e2e/no-ssr.test.ts b/packages/plugin-rsc/e2e/no-ssr.test.ts index 16e814162..a155675b4 100644 --- a/packages/plugin-rsc/e2e/no-ssr.test.ts +++ b/packages/plugin-rsc/e2e/no-ssr.test.ts @@ -1,8 +1,8 @@ -import { expect, test } from '@playwright/test' import { useFixture } from './fixture' import { defineStarterTest } from './starter' -import path from 'node:path' +import { expect, test } from '@playwright/test' import fs from 'node:fs' +import path from 'node:path' test.describe('dev-no-ssr', () => { const f = useFixture({ root: 'examples/no-ssr', mode: 'dev' }) diff --git a/packages/plugin-rsc/e2e/react-compiler.test.ts b/packages/plugin-rsc/e2e/react-compiler.test.ts index 2c36e24b5..edd385bea 100644 --- a/packages/plugin-rsc/e2e/react-compiler.test.ts +++ b/packages/plugin-rsc/e2e/react-compiler.test.ts @@ -1,7 +1,7 @@ -import { expect, test } from '@playwright/test' import { setupInlineFixture, useFixture } from './fixture' -import { defineStarterTest } from './starter' import { waitForHydration } from './helper' +import { defineStarterTest } from './starter' +import { expect, test } from '@playwright/test' test.describe(() => { const root = 'examples/e2e/temp/react-compiler' diff --git a/packages/plugin-rsc/e2e/react-router.test.ts b/packages/plugin-rsc/e2e/react-router.test.ts index 0807e2aaf..5cefb7c63 100644 --- a/packages/plugin-rsc/e2e/react-router.test.ts +++ b/packages/plugin-rsc/e2e/react-router.test.ts @@ -1,7 +1,7 @@ -import { createHash } from 'node:crypto' -import { expect, test } from '@playwright/test' import { type Fixture, useFixture } from './fixture' import { expectNoReload, testNoJs, waitForHydration } from './helper' +import { expect, test } from '@playwright/test' +import { createHash } from 'node:crypto' import { readFileSync } from 'node:fs' import React from 'react' diff --git a/packages/plugin-rsc/e2e/render-built-url.test.ts b/packages/plugin-rsc/e2e/render-built-url.test.ts index e9e70e6d6..84afdd8b5 100644 --- a/packages/plugin-rsc/e2e/render-built-url.test.ts +++ b/packages/plugin-rsc/e2e/render-built-url.test.ts @@ -1,7 +1,7 @@ -import { expect, test } from '@playwright/test' import { setupInlineFixture, useFixture } from './fixture' -import { defineStarterTest } from './starter' import { expectNoPageError, waitForHydration } from './helper' +import { defineStarterTest } from './starter' +import { expect, test } from '@playwright/test' import fs from 'node:fs' import type { RenderBuiltAssetUrl } from 'vite' diff --git a/packages/plugin-rsc/e2e/root.test.ts b/packages/plugin-rsc/e2e/root.test.ts index ae59a95de..526556b4d 100644 --- a/packages/plugin-rsc/e2e/root.test.ts +++ b/packages/plugin-rsc/e2e/root.test.ts @@ -1,6 +1,6 @@ -import { test } from '@playwright/test' import { setupInlineFixture, useFixture } from './fixture' import { defineStarterTest } from './starter' +import { test } from '@playwright/test' import fs from 'node:fs' import path from 'node:path' diff --git a/packages/plugin-rsc/e2e/ssg.test.ts b/packages/plugin-rsc/e2e/ssg.test.ts index b1b7d4fb1..fe1f4d9d0 100644 --- a/packages/plugin-rsc/e2e/ssg.test.ts +++ b/packages/plugin-rsc/e2e/ssg.test.ts @@ -1,6 +1,6 @@ -import { expect, test } from '@playwright/test' import { type Fixture, useFixture } from './fixture' import { waitForHydration } from './helper' +import { expect, test } from '@playwright/test' test.describe('dev', () => { const f = useFixture({ diff --git a/packages/plugin-rsc/e2e/ssr-thenable.test.ts b/packages/plugin-rsc/e2e/ssr-thenable.test.ts index 7bf9e14e4..0146394e0 100644 --- a/packages/plugin-rsc/e2e/ssr-thenable.test.ts +++ b/packages/plugin-rsc/e2e/ssr-thenable.test.ts @@ -1,9 +1,9 @@ -import { test } from '@playwright/test' import { setupInlineFixture, type Fixture, useFixture } from './fixture' import { expectNoPageError, waitForHydration as waitForHydration_, } from './helper' +import { test } from '@playwright/test' test.describe(() => { const root = 'examples/e2e/temp/ssr-thenable' diff --git a/packages/plugin-rsc/e2e/starter.test.ts b/packages/plugin-rsc/e2e/starter.test.ts index 1caff94db..b3c71f369 100644 --- a/packages/plugin-rsc/e2e/starter.test.ts +++ b/packages/plugin-rsc/e2e/starter.test.ts @@ -1,7 +1,7 @@ -import { expect, test } from '@playwright/test' import { setupInlineFixture, useFixture, type Fixture } from './fixture' -import { defineStarterTest } from './starter' import { expectNoPageError, waitForHydration } from './helper' +import { defineStarterTest } from './starter' +import { expect, test } from '@playwright/test' import { x } from 'tinyexec' test.describe('dev-default', () => { diff --git a/packages/plugin-rsc/e2e/starter.ts b/packages/plugin-rsc/e2e/starter.ts index 3f2e02378..a887d9e04 100644 --- a/packages/plugin-rsc/e2e/starter.ts +++ b/packages/plugin-rsc/e2e/starter.ts @@ -1,4 +1,3 @@ -import { expect, test } from '@playwright/test' import { type Fixture } from './fixture' import { expectNoPageError, @@ -6,6 +5,7 @@ import { testNoJs, waitForHydration as waitForHydration_, } from './helper' +import { expect, test } from '@playwright/test' export function defineStarterTest( f: Fixture, diff --git a/packages/plugin-rsc/e2e/syntax-error.test.ts b/packages/plugin-rsc/e2e/syntax-error.test.ts index a44980d95..23bcc5f54 100644 --- a/packages/plugin-rsc/e2e/syntax-error.test.ts +++ b/packages/plugin-rsc/e2e/syntax-error.test.ts @@ -1,6 +1,6 @@ -import { test, expect } from '@playwright/test' import { setupInlineFixture, useFixture } from './fixture' import { waitForHydration, expectNoReload } from './helper' +import { test, expect } from '@playwright/test' test.describe(() => { const root = 'examples/e2e/temp/syntax-error' diff --git a/packages/plugin-rsc/e2e/validate-imports.test.ts b/packages/plugin-rsc/e2e/validate-imports.test.ts index e87bcb536..dd1bca48e 100644 --- a/packages/plugin-rsc/e2e/validate-imports.test.ts +++ b/packages/plugin-rsc/e2e/validate-imports.test.ts @@ -1,7 +1,7 @@ -import { test, expect } from '@playwright/test' import { setupInlineFixture, useFixture, type Fixture } from './fixture' -import { x } from 'tinyexec' import { expectNoPageError, waitForHydration } from './helper' +import { test, expect } from '@playwright/test' +import { x } from 'tinyexec' test.describe('validate imports', () => { test.describe('valid imports', () => { diff --git a/packages/plugin-rsc/examples/basic/src/framework/entry.browser.tsx b/packages/plugin-rsc/examples/basic/src/framework/entry.browser.tsx index 551f4aac9..611c6f0f3 100644 --- a/packages/plugin-rsc/examples/basic/src/framework/entry.browser.tsx +++ b/packages/plugin-rsc/examples/basic/src/framework/entry.browser.tsx @@ -1,3 +1,4 @@ +import type { RscPayload } from './entry.rsc' import { createFromReadableStream, createFromFetch, @@ -8,7 +9,6 @@ import { import React from 'react' import { hydrateRoot } from 'react-dom/client' import { rscStream } from 'rsc-html-stream/client' -import type { RscPayload } from './entry.rsc' async function main() { // stash `setPayload` function to trigger re-rendering diff --git a/packages/plugin-rsc/examples/basic/src/framework/entry.rsc.tsx b/packages/plugin-rsc/examples/basic/src/framework/entry.rsc.tsx index b98c4433f..a354c6969 100644 --- a/packages/plugin-rsc/examples/basic/src/framework/entry.rsc.tsx +++ b/packages/plugin-rsc/examples/basic/src/framework/entry.rsc.tsx @@ -6,8 +6,8 @@ import { decodeAction, decodeFormState, } from '@vitejs/plugin-rsc/rsc' -import type { ReactFormState } from 'react-dom/client' import type React from 'react' +import type { ReactFormState } from 'react-dom/client' // The schema of payload which is serialized into RSC stream on rsc environment // and deserialized on ssr/client environments. diff --git a/packages/plugin-rsc/examples/basic/src/framework/entry.ssr.tsx b/packages/plugin-rsc/examples/basic/src/framework/entry.ssr.tsx index e5c539923..bc09a0782 100644 --- a/packages/plugin-rsc/examples/basic/src/framework/entry.ssr.tsx +++ b/packages/plugin-rsc/examples/basic/src/framework/entry.ssr.tsx @@ -1,9 +1,9 @@ +import type { RscPayload } from './entry.rsc' import { createFromReadableStream } from '@vitejs/plugin-rsc/ssr' import React from 'react' import type { ReactFormState } from 'react-dom/client' import { renderToReadableStream } from 'react-dom/server.edge' import { injectRSCPayload } from 'rsc-html-stream/server' -import type { RscPayload } from './entry.rsc' export async function renderHTML( rscStream: ReadableStream, diff --git a/packages/plugin-rsc/examples/basic/src/routes/action-from-client/client.tsx b/packages/plugin-rsc/examples/basic/src/routes/action-from-client/client.tsx index 8f0bc2368..fa548cc8f 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/action-from-client/client.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/action-from-client/client.tsx @@ -1,7 +1,7 @@ 'use client' -import React from 'react' import { testAction, testAction2, testActionState } from './action' +import React from 'react' export function TestActionFromClient() { return ( diff --git a/packages/plugin-rsc/examples/basic/src/routes/css-queries/client.tsx b/packages/plugin-rsc/examples/basic/src/routes/css-queries/client.tsx index 682e3ebca..eb490ecbc 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/css-queries/client.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/css-queries/client.tsx @@ -1,8 +1,8 @@ 'use client' -import cssUrl from './client-url.css?url' import cssInline from './client-inline.css?inline' import cssRaw from './client-raw.css?raw' +import cssUrl from './client-url.css?url' import React from 'react' export function TestCssQueriesClient(props: { diff --git a/packages/plugin-rsc/examples/basic/src/routes/css-queries/server.tsx b/packages/plugin-rsc/examples/basic/src/routes/css-queries/server.tsx index 49ed52ee1..1c6f1dce9 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/css-queries/server.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/css-queries/server.tsx @@ -1,7 +1,7 @@ -import cssUrl from './server-url.css?url' +import { TestCssQueriesClient } from './client' import cssInline from './server-inline.css?inline' import cssRaw from './server-raw.css?raw' -import { TestCssQueriesClient } from './client' +import cssUrl from './server-url.css?url' export function TestCssQueries() { return ( diff --git a/packages/plugin-rsc/examples/basic/src/routes/deps/client-in-server/server.tsx b/packages/plugin-rsc/examples/basic/src/routes/deps/client-in-server/server.tsx index cb029357e..03af5129a 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/deps/client-in-server/server.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/deps/client-in-server/server.tsx @@ -1,8 +1,8 @@ +import { TestContextValueIndirect } from './client' // @ts-ignore import { TestClientInServerDep } from '@vitejs/test-dep-client-in-server/server' // @ts-ignore import { TestContextProviderInServer } from '@vitejs/test-dep-client-in-server2/server' -import { TestContextValueIndirect } from './client' export function TestClientInServer() { return ( diff --git a/packages/plugin-rsc/examples/basic/src/routes/deps/transitive-cjs/client.tsx b/packages/plugin-rsc/examples/basic/src/routes/deps/transitive-cjs/client.tsx index 10c2a1e44..340ccff51 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/deps/transitive-cjs/client.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/deps/transitive-cjs/client.tsx @@ -2,7 +2,6 @@ // @ts-ignore import { TestClient } from '@vitejs/test-dep-transitive-cjs/client' - // @ts-ignore import { TestClient as TestClient2 } from '@vitejs/test-dep-transitive-use-sync-external-store/client' diff --git a/packages/plugin-rsc/examples/basic/src/routes/hmr-client-dep/client.tsx b/packages/plugin-rsc/examples/basic/src/routes/hmr-client-dep/client.tsx index 3c2500fbe..9c195363c 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/hmr-client-dep/client.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/hmr-client-dep/client.tsx @@ -1,7 +1,7 @@ 'use client' -import React from 'react' import { ClientDep } from './client-dep' +import React from 'react' export function TestHmrClientDep(props: { url: Pick }) { const [count, setCount] = React.useState(0) diff --git a/packages/plugin-rsc/examples/basic/src/routes/hmr-client-dep2/client.tsx b/packages/plugin-rsc/examples/basic/src/routes/hmr-client-dep2/client.tsx index 8bee6cdbc..a458e3a9b 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/hmr-client-dep2/client.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/hmr-client-dep2/client.tsx @@ -1,7 +1,7 @@ 'use client' -import React from 'react' import { clientDep } from './client-dep' +import React from 'react' export function TestHmrClientDep2(props: { url: Pick }) { const [count, setCount] = React.useState(0) diff --git a/packages/plugin-rsc/examples/basic/src/routes/hmr-client-dep3/client-a.tsx b/packages/plugin-rsc/examples/basic/src/routes/hmr-client-dep3/client-a.tsx index c4154575c..9fcc64819 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/hmr-client-dep3/client-a.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/hmr-client-dep3/client-a.tsx @@ -1,8 +1,8 @@ 'use client' -import React from 'react' import { clientDep } from './client-dep' import { ClientDepComp } from './client-dep-comp' +import React from 'react' export function TestHmrClientDepA() { const [count, setCount] = React.useState(0) diff --git a/packages/plugin-rsc/examples/basic/src/routes/hmr-shared/atomic/client.tsx b/packages/plugin-rsc/examples/basic/src/routes/hmr-shared/atomic/client.tsx index 76dcff0b2..cb6c0e038 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/hmr-shared/atomic/client.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/hmr-shared/atomic/client.tsx @@ -1,7 +1,7 @@ 'use client' -import React from 'react' import { testShared } from './shared' +import React from 'react' export function TestClient({ testSharedFromServer, diff --git a/packages/plugin-rsc/examples/basic/src/routes/root.tsx b/packages/plugin-rsc/examples/basic/src/routes/root.tsx index 429518744..38627534d 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/root.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/root.tsx @@ -1,4 +1,3 @@ -import React from 'react' import { TestServerActionBindAction, TestServerActionBindClient, @@ -12,40 +11,41 @@ import { } from './action-from-client/client' import { TestActionStateServer } from './action-state/server' import { ServerCounter } from './action/server' +import { TestAssetsServer } from './assets/server' +import { TestBrowserOnly } from './browser-only/client' +import { TestClientChunkServer } from './chunk/server' +import { TestChunk2 } from './chunk2/server' import { ClientCounter, Hydrated } from './client' +import { TestCssQueries } from './css-queries/server' import { TestClientInServer } from './deps/client-in-server/server' import { TestServerInClient } from './deps/server-in-client/client' import { TestServerInServer } from './deps/server-in-server/server' +import { TestTransitiveCjsClient } from './deps/transitive-cjs/client' import { TestHmrClientDep } from './hmr-client-dep/client' +import { TestHmrClientDep2 } from './hmr-client-dep2/client' +import { TestHmrClientDep3 } from './hmr-client-dep3/server' +import { TestHmrSharedAtomic } from './hmr-shared/atomic/server' +import { TestHmrSharedClient } from './hmr-shared/client' +import { TestHmrSharedServer } from './hmr-shared/server' +import { TestHmrSwitchClient } from './hmr-switch/client' +import { TestHmrSwitchServer } from './hmr-switch/server' +import { TestHydrationMismatch } from './hydration-mismatch/server' +import { TestImportMetaGlob } from './import-meta-glob/server' import { TestModuleInvalidationServer } from './module-invalidation/server' import { TestPayloadServer } from './payload/server' +import { TestReactCache } from './react-cache/server' import { TestSerializationServer } from './serialization/server' import { TestCssClientNoSsr } from './style-client-no-ssr/server' import { TestStyleClient } from './style-client/client' import { TestStyleServer } from './style-server/server' +import { TestTailwind } from './tailwind' import { TestTemporaryReference } from './temporary-reference/client' -import { TestUseCache } from './use-cache/server' -import { TestReactCache } from './react-cache/server' -import { TestHydrationMismatch } from './hydration-mismatch/server' -import { TestBrowserOnly } from './browser-only/client' -import { TestTransitiveCjsClient } from './deps/transitive-cjs/client' -import TestDepCssInServer from '@vitejs/test-dep-css-in-server/server' -import { TestHmrSharedServer } from './hmr-shared/server' -import { TestHmrSharedClient } from './hmr-shared/client' -import { TestHmrSharedAtomic } from './hmr-shared/atomic/server' -import { TestCssQueries } from './css-queries/server' -import { TestImportMetaGlob } from './import-meta-glob/server' -import { TestAssetsServer } from './assets/server' -import { TestHmrSwitchServer } from './hmr-switch/server' -import { TestHmrSwitchClient } from './hmr-switch/client' import { TestTreeShakeServer } from './tree-shake/server' import { TestTreeShake2 } from './tree-shake2/server' -import { TestClientChunkServer } from './chunk/server' -import { TestTailwind } from './tailwind' -import { TestHmrClientDep2 } from './hmr-client-dep2/client' -import { TestHmrClientDep3 } from './hmr-client-dep3/server' -import { TestChunk2 } from './chunk2/server' +import { TestUseCache } from './use-cache/server' import { TestUseId } from './use-id/server' +import TestDepCssInServer from '@vitejs/test-dep-css-in-server/server' +import React from 'react' export function Root(props: { url: URL }) { return ( diff --git a/packages/plugin-rsc/examples/basic/src/routes/serialization/server.tsx b/packages/plugin-rsc/examples/basic/src/routes/serialization/server.tsx index ffb7b9699..899257b1b 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/serialization/server.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/serialization/server.tsx @@ -1,9 +1,9 @@ +import { testSerializationAction } from './action' +import { TestSerializationClient } from './client' import { createFromReadableStream, renderToReadableStream, } from '@vitejs/plugin-rsc/rsc' -import { testSerializationAction } from './action' -import { TestSerializationClient } from './client' export function TestSerializationServer() { const original = diff --git a/packages/plugin-rsc/examples/basic/src/routes/style-client/client.tsx b/packages/plugin-rsc/examples/basic/src/routes/style-client/client.tsx index 53a7c1289..56de4a5e2 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/style-client/client.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/style-client/client.tsx @@ -2,8 +2,8 @@ import './client.css' import { TestClientDep } from './client-dep' -import styles from './client.module.css' import styleUrl from './client-url.css?url' +import styles from './client.module.css' export function TestStyleClient() { return ( diff --git a/packages/plugin-rsc/examples/basic/src/routes/style-server/server.tsx b/packages/plugin-rsc/examples/basic/src/routes/style-server/server.tsx index a7132153c..02ecfaaac 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/style-server/server.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/style-server/server.tsx @@ -1,6 +1,6 @@ import './server.css' -import styles from './server.module.css' import styleUrl from './server-url.css?url' +import styles from './server.module.css' export function TestStyleServer() { return ( diff --git a/packages/plugin-rsc/examples/basic/src/routes/temporary-reference/client.tsx b/packages/plugin-rsc/examples/basic/src/routes/temporary-reference/client.tsx index 69dd7e9fa..0ced5f511 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/temporary-reference/client.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/temporary-reference/client.tsx @@ -1,7 +1,7 @@ 'use client' -import React from 'react' import { action } from './action' +import React from 'react' export function TestTemporaryReference() { const [result, setResult] = React.useState('(none)') diff --git a/packages/plugin-rsc/examples/basic/src/routes/use-id/server.tsx b/packages/plugin-rsc/examples/basic/src/routes/use-id/server.tsx index a97edefcf..d5e59ac2e 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/use-id/server.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/use-id/server.tsx @@ -1,5 +1,5 @@ -import { useId } from 'react' import { TestUseIdClient } from './client' +import { useId } from 'react' export function TestUseId() { return ( diff --git a/packages/plugin-rsc/examples/basic/test-dep/client-in-server/server.js b/packages/plugin-rsc/examples/basic/test-dep/client-in-server/server.js index e145d3c52..829f97909 100644 --- a/packages/plugin-rsc/examples/basic/test-dep/client-in-server/server.js +++ b/packages/plugin-rsc/examples/basic/test-dep/client-in-server/server.js @@ -1,5 +1,5 @@ -import React from 'react' import { TestClient } from './client.js' +import React from 'react' export async function TestClientInServerDep() { return React.createElement(TestClient) diff --git a/packages/plugin-rsc/examples/basic/test-dep/client-in-server2/server.js b/packages/plugin-rsc/examples/basic/test-dep/client-in-server2/server.js index 323d0e03f..041f9630b 100644 --- a/packages/plugin-rsc/examples/basic/test-dep/client-in-server2/server.js +++ b/packages/plugin-rsc/examples/basic/test-dep/client-in-server2/server.js @@ -1,5 +1,5 @@ -import React from 'react' import { TestContextProvider } from './client.js' +import React from 'react' export function TestContextProviderInServer(props) { return React.createElement( diff --git a/packages/plugin-rsc/examples/basic/test-dep/server-in-client/client.js b/packages/plugin-rsc/examples/basic/test-dep/server-in-client/client.js index bdb6c4596..0a2487c2c 100644 --- a/packages/plugin-rsc/examples/basic/test-dep/server-in-client/client.js +++ b/packages/plugin-rsc/examples/basic/test-dep/server-in-client/client.js @@ -1,7 +1,7 @@ 'use client' -import React from 'react' import { changeCounter } from './server.js' +import React from 'react' const h = React.createElement diff --git a/packages/plugin-rsc/examples/basic/test-dep/transitive-cjs/client.js b/packages/plugin-rsc/examples/basic/test-dep/transitive-cjs/client.js index 87aa08e69..4c3b6dc84 100644 --- a/packages/plugin-rsc/examples/basic/test-dep/transitive-cjs/client.js +++ b/packages/plugin-rsc/examples/basic/test-dep/transitive-cjs/client.js @@ -1,8 +1,7 @@ 'use client' -import React from 'react' - import { ok } from '@vitejs/test-dep-cjs' +import React from 'react' const h = React.createElement diff --git a/packages/plugin-rsc/examples/basic/test-dep/transitive-use-sync-external-store/client.js b/packages/plugin-rsc/examples/basic/test-dep/transitive-use-sync-external-store/client.js index 1ac3e0cc1..1079d08cb 100644 --- a/packages/plugin-rsc/examples/basic/test-dep/transitive-use-sync-external-store/client.js +++ b/packages/plugin-rsc/examples/basic/test-dep/transitive-use-sync-external-store/client.js @@ -1,7 +1,6 @@ 'use client' import React from 'react' - // similar to // https://github.com/vercel/swr/blob/063fe55dddb95f0b6c3f1637a935c43d732ded78/src/index/use-swr.ts#L3 // https://github.com/TanStack/store/blob/1d1323283e79059821d6c731eaaee60e4143dbc2/packages/react-store/src/index.ts#L1 diff --git a/packages/plugin-rsc/examples/basic/vite.config.ts b/packages/plugin-rsc/examples/basic/vite.config.ts index 61ba86430..2f516d421 100644 --- a/packages/plugin-rsc/examples/basic/vite.config.ts +++ b/packages/plugin-rsc/examples/basic/vite.config.ts @@ -1,8 +1,11 @@ -import assert from 'node:assert' -import rsc from '@vitejs/plugin-rsc' -import { transformHoistInlineDirective } from '@vitejs/plugin-rsc/transforms' import tailwindcss from '@tailwindcss/vite' import react from '@vitejs/plugin-react' +import rsc from '@vitejs/plugin-rsc' +import { transformHoistInlineDirective } from '@vitejs/plugin-rsc/transforms' +import assert from 'node:assert' +import fs from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' import { type Plugin, type Rollup, @@ -10,9 +13,6 @@ import { normalizePath, parseAstAsync, } from 'vite' -import path from 'node:path' -import fs from 'node:fs' -import { fileURLToPath } from 'node:url' export default defineConfig({ clearScreen: false, diff --git a/packages/plugin-rsc/examples/browser-mode/src/action-from-client/client.tsx b/packages/plugin-rsc/examples/browser-mode/src/action-from-client/client.tsx index aca850f2f..c778ecfbd 100644 --- a/packages/plugin-rsc/examples/browser-mode/src/action-from-client/client.tsx +++ b/packages/plugin-rsc/examples/browser-mode/src/action-from-client/client.tsx @@ -1,7 +1,7 @@ 'use client' -import React from 'react' import { testActionState } from './action' +import React from 'react' export function TestUseActionState() { const [state, formAction] = React.useActionState(testActionState, 0) diff --git a/packages/plugin-rsc/examples/browser-mode/src/framework/entry.browser.tsx b/packages/plugin-rsc/examples/browser-mode/src/framework/entry.browser.tsx index b5a85a034..2713391f4 100644 --- a/packages/plugin-rsc/examples/browser-mode/src/framework/entry.browser.tsx +++ b/packages/plugin-rsc/examples/browser-mode/src/framework/entry.browser.tsx @@ -1,5 +1,4 @@ -import * as React from 'react' -import { createRoot } from 'react-dom/client' +import type { RscPayload } from './entry.rsc' import { createFromFetch, setRequireModule, @@ -7,7 +6,8 @@ import { createTemporaryReferenceSet, encodeReply, } from '@vitejs/plugin-rsc/react/browser' -import type { RscPayload } from './entry.rsc' +import * as React from 'react' +import { createRoot } from 'react-dom/client' import buildClientReferences from 'virtual:vite-rsc-browser-mode/build-client-references' let fetchServer: typeof import('./entry.rsc').fetchServer diff --git a/packages/plugin-rsc/examples/browser-mode/src/framework/entry.rsc.tsx b/packages/plugin-rsc/examples/browser-mode/src/framework/entry.rsc.tsx index 3cbc83a99..3c48890a4 100644 --- a/packages/plugin-rsc/examples/browser-mode/src/framework/entry.rsc.tsx +++ b/packages/plugin-rsc/examples/browser-mode/src/framework/entry.rsc.tsx @@ -1,3 +1,4 @@ +import { Root } from '../root' import { setRequireModule, renderToReadableStream, @@ -8,7 +9,6 @@ import { decodeFormState, } from '@vitejs/plugin-rsc/react/rsc' import type React from 'react' -import { Root } from '../root' import type { ReactFormState } from 'react-dom/client' import buildServerReferences from 'virtual:vite-rsc-browser-mode/build-server-references' diff --git a/packages/plugin-rsc/examples/browser-mode/src/root.tsx b/packages/plugin-rsc/examples/browser-mode/src/root.tsx index e8d912527..32c0c4c24 100644 --- a/packages/plugin-rsc/examples/browser-mode/src/root.tsx +++ b/packages/plugin-rsc/examples/browser-mode/src/root.tsx @@ -1,10 +1,10 @@ import './index.css' -import viteLogo from '/vite.svg' +import { TestActionBind } from './action-bind/server.tsx' +import { TestUseActionState } from './action-from-client/client.tsx' import { getServerCounter, updateServerCounter } from './action.tsx' import reactLogo from './assets/react.svg' import { ClientCounter } from './client.tsx' -import { TestUseActionState } from './action-from-client/client.tsx' -import { TestActionBind } from './action-bind/server.tsx' +import viteLogo from '/vite.svg' export function Root() { return diff --git a/packages/plugin-rsc/examples/browser-mode/vite.config.ts b/packages/plugin-rsc/examples/browser-mode/vite.config.ts index 4bb65e5a5..e5b689878 100644 --- a/packages/plugin-rsc/examples/browser-mode/vite.config.ts +++ b/packages/plugin-rsc/examples/browser-mode/vite.config.ts @@ -1,9 +1,9 @@ -import { defaultClientConditions, defineConfig, type Plugin } from 'vite' import { vitePluginRscMinimal, getPluginApi, type PluginApi, } from '@vitejs/plugin-rsc/plugin' +import { defaultClientConditions, defineConfig, type Plugin } from 'vite' export default defineConfig({ plugins: [ diff --git a/packages/plugin-rsc/examples/browser/src/framework/entry.browser.tsx b/packages/plugin-rsc/examples/browser/src/framework/entry.browser.tsx index ee086c8b1..510a2cff8 100644 --- a/packages/plugin-rsc/examples/browser/src/framework/entry.browser.tsx +++ b/packages/plugin-rsc/examples/browser/src/framework/entry.browser.tsx @@ -1,13 +1,13 @@ -import React from 'react' -import { createRoot } from 'react-dom/client' +import { loadEntryRsc } from '../../lib/runtime' +import type { RscPayload } from './entry.rsc' import { createFromFetch, setServerCallback, createTemporaryReferenceSet, encodeReply, } from '@vitejs/plugin-rsc/browser' -import type { RscPayload } from './entry.rsc' -import { loadEntryRsc } from '../../lib/runtime' +import React from 'react' +import { createRoot } from 'react-dom/client' async function fetchRsc(request: Request): Promise { const module = await loadEntryRsc() diff --git a/packages/plugin-rsc/examples/browser/src/framework/entry.rsc.tsx b/packages/plugin-rsc/examples/browser/src/framework/entry.rsc.tsx index 8d0195b9f..1b71ddc49 100644 --- a/packages/plugin-rsc/examples/browser/src/framework/entry.rsc.tsx +++ b/packages/plugin-rsc/examples/browser/src/framework/entry.rsc.tsx @@ -1,3 +1,4 @@ +import { Root } from '../root.tsx' import { renderToReadableStream, createTemporaryReferenceSet, @@ -7,7 +8,6 @@ import { decodeFormState, } from '@vitejs/plugin-rsc/rsc' import type { ReactFormState } from 'react-dom/client' -import { Root } from '../root.tsx' export type RscPayload = { root: React.ReactNode diff --git a/packages/plugin-rsc/examples/browser/src/root.tsx b/packages/plugin-rsc/examples/browser/src/root.tsx index 9baa7b9c2..7a88a0f24 100644 --- a/packages/plugin-rsc/examples/browser/src/root.tsx +++ b/packages/plugin-rsc/examples/browser/src/root.tsx @@ -1,8 +1,8 @@ import './index.css' // css import is automatically injected in exported server components -import viteLogo from '/vite.svg' import { getServerCounter, updateServerCounter } from './action.tsx' import reactLogo from './assets/react.svg' import { ClientCounter } from './client.tsx' +import viteLogo from '/vite.svg' export function Root() { return diff --git a/packages/plugin-rsc/examples/browser/vite.config.ts b/packages/plugin-rsc/examples/browser/vite.config.ts index 47e029848..752a28edf 100644 --- a/packages/plugin-rsc/examples/browser/vite.config.ts +++ b/packages/plugin-rsc/examples/browser/vite.config.ts @@ -1,7 +1,7 @@ -import { defineConfig } from 'vite' +import rscBrowser from './lib/plugin' import react from '@vitejs/plugin-react' import rsc from '@vitejs/plugin-rsc' -import rscBrowser from './lib/plugin' +import { defineConfig } from 'vite' export default defineConfig({ plugins: [ diff --git a/packages/plugin-rsc/examples/e2e/middleware-mode.ts b/packages/plugin-rsc/examples/e2e/middleware-mode.ts index 2b0c38cd4..5d11fcc6f 100644 --- a/packages/plugin-rsc/examples/e2e/middleware-mode.ts +++ b/packages/plugin-rsc/examples/e2e/middleware-mode.ts @@ -1,8 +1,8 @@ -import path from 'node:path' -import { pathToFileURL } from 'node:url' +import { createRequestListener } from '@remix-run/node-fetch-server' // @ts-ignore import connect from 'connect' -import { createRequestListener } from '@remix-run/node-fetch-server' +import path from 'node:path' +import { pathToFileURL } from 'node:url' import sirv from 'sirv' import type { Connect } from 'vite' diff --git a/packages/plugin-rsc/examples/no-ssr/src/framework/entry.browser.tsx b/packages/plugin-rsc/examples/no-ssr/src/framework/entry.browser.tsx index f33a65500..8413c2921 100644 --- a/packages/plugin-rsc/examples/no-ssr/src/framework/entry.browser.tsx +++ b/packages/plugin-rsc/examples/no-ssr/src/framework/entry.browser.tsx @@ -1,3 +1,4 @@ +import type { RscPayload } from './entry.rsc' import { createFromFetch, setServerCallback, @@ -6,7 +7,6 @@ import { } from '@vitejs/plugin-rsc/browser' import React from 'react' import { createRoot } from 'react-dom/client' -import type { RscPayload } from './entry.rsc' async function main() { // stash `setPayload` function to trigger re-rendering diff --git a/packages/plugin-rsc/examples/no-ssr/src/framework/entry.rsc.tsx b/packages/plugin-rsc/examples/no-ssr/src/framework/entry.rsc.tsx index 27a5ce931..84d3a6664 100644 --- a/packages/plugin-rsc/examples/no-ssr/src/framework/entry.rsc.tsx +++ b/packages/plugin-rsc/examples/no-ssr/src/framework/entry.rsc.tsx @@ -1,3 +1,4 @@ +import { Root } from '../root.tsx' import { renderToReadableStream, createTemporaryReferenceSet, @@ -7,7 +8,6 @@ import { decodeFormState, } from '@vitejs/plugin-rsc/rsc' import type { ReactFormState } from 'react-dom/client' -import { Root } from '../root.tsx' export type RscPayload = { root: React.ReactNode diff --git a/packages/plugin-rsc/examples/no-ssr/src/root.tsx b/packages/plugin-rsc/examples/no-ssr/src/root.tsx index 9baa7b9c2..7a88a0f24 100644 --- a/packages/plugin-rsc/examples/no-ssr/src/root.tsx +++ b/packages/plugin-rsc/examples/no-ssr/src/root.tsx @@ -1,8 +1,8 @@ import './index.css' // css import is automatically injected in exported server components -import viteLogo from '/vite.svg' import { getServerCounter, updateServerCounter } from './action.tsx' import reactLogo from './assets/react.svg' import { ClientCounter } from './client.tsx' +import viteLogo from '/vite.svg' export function Root() { return diff --git a/packages/plugin-rsc/examples/no-ssr/vite.config.ts b/packages/plugin-rsc/examples/no-ssr/vite.config.ts index ce349c6e9..9bf4ac1ac 100644 --- a/packages/plugin-rsc/examples/no-ssr/vite.config.ts +++ b/packages/plugin-rsc/examples/no-ssr/vite.config.ts @@ -1,7 +1,7 @@ -import rsc from '@vitejs/plugin-rsc' import react from '@vitejs/plugin-react' -import { defineConfig, type Plugin } from 'vite' +import rsc from '@vitejs/plugin-rsc' import fsp from 'node:fs/promises' +import { defineConfig, type Plugin } from 'vite' export default defineConfig({ plugins: [ diff --git a/packages/plugin-rsc/examples/react-router/app/root.tsx b/packages/plugin-rsc/examples/react-router/app/root.tsx index 75b019e9f..176d7d4b9 100644 --- a/packages/plugin-rsc/examples/react-router/app/root.tsx +++ b/packages/plugin-rsc/examples/react-router/app/root.tsx @@ -1,7 +1,7 @@ import './styles.css' -import { Link, Outlet } from 'react-router' import { TestClientState, TestHydrated } from './routes/client' import { DumpError, GlobalNavigationLoadingBar } from './routes/root.client' +import { Link, Outlet } from 'react-router' export function Layout({ children }: { children: React.ReactNode }) { console.log('[debug] root - Layout') diff --git a/packages/plugin-rsc/examples/react-router/cf/vite.config.ts b/packages/plugin-rsc/examples/react-router/cf/vite.config.ts index 96b91e749..27ebb6b76 100644 --- a/packages/plugin-rsc/examples/react-router/cf/vite.config.ts +++ b/packages/plugin-rsc/examples/react-router/cf/vite.config.ts @@ -1,7 +1,7 @@ import { cloudflare } from '@cloudflare/vite-plugin' -import rsc from '@vitejs/plugin-rsc' import tailwindcss from '@tailwindcss/vite' import react from '@vitejs/plugin-react' +import rsc from '@vitejs/plugin-rsc' import { defineConfig } from 'vite' export default defineConfig({ diff --git a/packages/plugin-rsc/examples/react-router/react-router-vite/entry.rsc.tsx b/packages/plugin-rsc/examples/react-router/react-router-vite/entry.rsc.tsx index 847211bfd..fc4d5e830 100644 --- a/packages/plugin-rsc/examples/react-router/react-router-vite/entry.rsc.tsx +++ b/packages/plugin-rsc/examples/react-router/react-router-vite/entry.rsc.tsx @@ -1,3 +1,4 @@ +import { routes } from '../app/routes' import { createTemporaryReferenceSet, decodeAction, @@ -7,7 +8,6 @@ import { renderToReadableStream, } from '@vitejs/plugin-rsc/rsc' import { unstable_matchRSCServerRequest as matchRSCServerRequest } from 'react-router' -import { routes } from '../app/routes' export function fetchServer(request: Request) { return matchRSCServerRequest({ diff --git a/packages/plugin-rsc/examples/react-router/vite.config.ts b/packages/plugin-rsc/examples/react-router/vite.config.ts index 4bea05c1b..0746928d7 100644 --- a/packages/plugin-rsc/examples/react-router/vite.config.ts +++ b/packages/plugin-rsc/examples/react-router/vite.config.ts @@ -1,6 +1,6 @@ -import rsc from '@vitejs/plugin-rsc' import tailwindcss from '@tailwindcss/vite' import react from '@vitejs/plugin-react' +import rsc from '@vitejs/plugin-rsc' import { defineConfig } from 'vite' export default defineConfig({ diff --git a/packages/plugin-rsc/examples/ssg/src/framework/entry.browser.tsx b/packages/plugin-rsc/examples/ssg/src/framework/entry.browser.tsx index 381be8dc5..ba971fe7e 100644 --- a/packages/plugin-rsc/examples/ssg/src/framework/entry.browser.tsx +++ b/packages/plugin-rsc/examples/ssg/src/framework/entry.browser.tsx @@ -1,3 +1,4 @@ +import { RSC_POSTFIX, type RscPayload } from './shared' import { createFromFetch, createFromReadableStream, @@ -5,7 +6,6 @@ import { import React from 'react' import { hydrateRoot } from 'react-dom/client' import { rscStream } from 'rsc-html-stream/client' -import { RSC_POSTFIX, type RscPayload } from './shared' async function hydrate(): Promise { async function onNavigation() { diff --git a/packages/plugin-rsc/examples/ssg/src/framework/entry.rsc.tsx b/packages/plugin-rsc/examples/ssg/src/framework/entry.rsc.tsx index 7b87fdc18..6735a952d 100644 --- a/packages/plugin-rsc/examples/ssg/src/framework/entry.rsc.tsx +++ b/packages/plugin-rsc/examples/ssg/src/framework/entry.rsc.tsx @@ -1,6 +1,6 @@ -import { renderToReadableStream } from '@vitejs/plugin-rsc/rsc' import { Root, getStaticPaths } from '../root' import { RSC_POSTFIX, type RscPayload } from './shared' +import { renderToReadableStream } from '@vitejs/plugin-rsc/rsc' export { getStaticPaths } diff --git a/packages/plugin-rsc/examples/ssg/src/framework/entry.ssr.tsx b/packages/plugin-rsc/examples/ssg/src/framework/entry.ssr.tsx index b20eaf42b..6480e88ec 100644 --- a/packages/plugin-rsc/examples/ssg/src/framework/entry.ssr.tsx +++ b/packages/plugin-rsc/examples/ssg/src/framework/entry.ssr.tsx @@ -1,9 +1,9 @@ +import type { RscPayload } from './shared' import { createFromReadableStream } from '@vitejs/plugin-rsc/ssr' import React from 'react' import { renderToReadableStream } from 'react-dom/server.edge' import { prerender } from 'react-dom/static.edge' import { injectRSCPayload } from 'rsc-html-stream/server' -import type { RscPayload } from './shared' export async function renderHtml( rscStream: ReadableStream, diff --git a/packages/plugin-rsc/examples/ssg/vite.config.ts b/packages/plugin-rsc/examples/ssg/vite.config.ts index 4dc4a2744..00bc5a065 100644 --- a/packages/plugin-rsc/examples/ssg/vite.config.ts +++ b/packages/plugin-rsc/examples/ssg/vite.config.ts @@ -1,12 +1,12 @@ +import { RSC_POSTFIX } from './src/framework/shared' +import mdx from '@mdx-js/rollup' +import react from '@vitejs/plugin-react' +import rsc from '@vitejs/plugin-rsc' import fs from 'node:fs' import path from 'node:path' import { Readable } from 'node:stream' import { pathToFileURL } from 'node:url' -import rsc from '@vitejs/plugin-rsc' -import mdx from '@mdx-js/rollup' -import react from '@vitejs/plugin-react' import { type Plugin, type ResolvedConfig, defineConfig } from 'vite' -import { RSC_POSTFIX } from './src/framework/shared' export default defineConfig({ plugins: [ diff --git a/packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.browser.tsx b/packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.browser.tsx index c4c0e4ade..dfcb316f2 100644 --- a/packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.browser.tsx +++ b/packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.browser.tsx @@ -1,3 +1,4 @@ +import type { RscPayload } from './entry.rsc' import { createFromReadableStream, createFromFetch, @@ -8,7 +9,6 @@ import { import React from 'react' import { hydrateRoot } from 'react-dom/client' import { rscStream } from 'rsc-html-stream/client' -import type { RscPayload } from './entry.rsc' async function main() { // stash `setPayload` function to trigger re-rendering diff --git a/packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.rsc.tsx b/packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.rsc.tsx index 767164f1e..42ce6d38a 100644 --- a/packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.rsc.tsx +++ b/packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.rsc.tsx @@ -1,3 +1,4 @@ +import { Root } from '../root.tsx' import { renderToReadableStream, createTemporaryReferenceSet, @@ -7,7 +8,6 @@ import { decodeFormState, } from '@vitejs/plugin-rsc/rsc' import type { ReactFormState } from 'react-dom/client' -import { Root } from '../root.tsx' export type RscPayload = { root: React.ReactNode diff --git a/packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.ssr.tsx b/packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.ssr.tsx index f015dac85..f86a2156d 100644 --- a/packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.ssr.tsx +++ b/packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.ssr.tsx @@ -1,9 +1,9 @@ +import type { RscPayload } from './entry.rsc' import { createFromReadableStream } from '@vitejs/plugin-rsc/ssr' import React from 'react' import type { ReactFormState } from 'react-dom/client' import { renderToReadableStream } from 'react-dom/server.edge' import { injectRSCPayload } from 'rsc-html-stream/server' -import type { RscPayload } from './entry.rsc' export type RenderHTML = typeof renderHTML diff --git a/packages/plugin-rsc/examples/starter-cf-single/src/root.tsx b/packages/plugin-rsc/examples/starter-cf-single/src/root.tsx index 694d3fe7d..db47c4ae7 100644 --- a/packages/plugin-rsc/examples/starter-cf-single/src/root.tsx +++ b/packages/plugin-rsc/examples/starter-cf-single/src/root.tsx @@ -1,8 +1,8 @@ import './index.css' -import viteLogo from '/vite.svg' import { getServerCounter, updateServerCounter } from './action.tsx' import reactLogo from './assets/react.svg' import { ClientCounter } from './client.tsx' +import viteLogo from '/vite.svg' export function Root() { return ( diff --git a/packages/plugin-rsc/examples/starter-cf-single/vite.config.ts b/packages/plugin-rsc/examples/starter-cf-single/vite.config.ts index e93d3b493..adef8cab5 100644 --- a/packages/plugin-rsc/examples/starter-cf-single/vite.config.ts +++ b/packages/plugin-rsc/examples/starter-cf-single/vite.config.ts @@ -1,6 +1,6 @@ import { cloudflare } from '@cloudflare/vite-plugin' -import rsc from '@vitejs/plugin-rsc' import react from '@vitejs/plugin-react' +import rsc from '@vitejs/plugin-rsc' import { defineConfig } from 'vite' export default defineConfig({ diff --git a/packages/plugin-rsc/examples/starter/src/framework/entry.browser.tsx b/packages/plugin-rsc/examples/starter/src/framework/entry.browser.tsx index c4c0e4ade..dfcb316f2 100644 --- a/packages/plugin-rsc/examples/starter/src/framework/entry.browser.tsx +++ b/packages/plugin-rsc/examples/starter/src/framework/entry.browser.tsx @@ -1,3 +1,4 @@ +import type { RscPayload } from './entry.rsc' import { createFromReadableStream, createFromFetch, @@ -8,7 +9,6 @@ import { import React from 'react' import { hydrateRoot } from 'react-dom/client' import { rscStream } from 'rsc-html-stream/client' -import type { RscPayload } from './entry.rsc' async function main() { // stash `setPayload` function to trigger re-rendering diff --git a/packages/plugin-rsc/examples/starter/src/framework/entry.rsc.tsx b/packages/plugin-rsc/examples/starter/src/framework/entry.rsc.tsx index ab5a55a24..bcca25a98 100644 --- a/packages/plugin-rsc/examples/starter/src/framework/entry.rsc.tsx +++ b/packages/plugin-rsc/examples/starter/src/framework/entry.rsc.tsx @@ -1,3 +1,4 @@ +import { Root } from '../root.tsx' import { renderToReadableStream, createTemporaryReferenceSet, @@ -7,7 +8,6 @@ import { decodeFormState, } from '@vitejs/plugin-rsc/rsc' import type { ReactFormState } from 'react-dom/client' -import { Root } from '../root.tsx' // The schema of payload which is serialized into RSC stream on rsc environment // and deserialized on ssr/client environments. diff --git a/packages/plugin-rsc/examples/starter/src/framework/entry.ssr.tsx b/packages/plugin-rsc/examples/starter/src/framework/entry.ssr.tsx index a510db376..86ae19c16 100644 --- a/packages/plugin-rsc/examples/starter/src/framework/entry.ssr.tsx +++ b/packages/plugin-rsc/examples/starter/src/framework/entry.ssr.tsx @@ -1,9 +1,9 @@ +import type { RscPayload } from './entry.rsc' import { createFromReadableStream } from '@vitejs/plugin-rsc/ssr' import React from 'react' import type { ReactFormState } from 'react-dom/client' import { renderToReadableStream } from 'react-dom/server.edge' import { injectRSCPayload } from 'rsc-html-stream/server' -import type { RscPayload } from './entry.rsc' export async function renderHTML( rscStream: ReadableStream, diff --git a/packages/plugin-rsc/examples/starter/src/root.tsx b/packages/plugin-rsc/examples/starter/src/root.tsx index c6a649706..7d9093c2f 100644 --- a/packages/plugin-rsc/examples/starter/src/root.tsx +++ b/packages/plugin-rsc/examples/starter/src/root.tsx @@ -1,8 +1,8 @@ import './index.css' // css import is automatically injected in exported server components -import viteLogo from '/vite.svg' import { getServerCounter, updateServerCounter } from './action.tsx' import reactLogo from './assets/react.svg' import { ClientCounter } from './client.tsx' +import viteLogo from '/vite.svg' export function Root(props: { url: URL }) { return ( diff --git a/packages/plugin-rsc/examples/starter/vite.config.ts b/packages/plugin-rsc/examples/starter/vite.config.ts index 6319f33f6..9b9c9e014 100644 --- a/packages/plugin-rsc/examples/starter/vite.config.ts +++ b/packages/plugin-rsc/examples/starter/vite.config.ts @@ -1,5 +1,5 @@ -import rsc from '@vitejs/plugin-rsc' import react from '@vitejs/plugin-react' +import rsc from '@vitejs/plugin-rsc' import { defineConfig } from 'vite' export default defineConfig({ diff --git a/packages/plugin-rsc/src/browser.ts b/packages/plugin-rsc/src/browser.ts index 0892a8879..34bb5cba8 100644 --- a/packages/plugin-rsc/src/browser.ts +++ b/packages/plugin-rsc/src/browser.ts @@ -1,5 +1,5 @@ -import * as clientReferences from 'virtual:vite-rsc/client-references' import { setRequireModule } from './core/browser' +import * as clientReferences from 'virtual:vite-rsc/client-references' export * from './react/browser' diff --git a/packages/plugin-rsc/src/core/browser.ts b/packages/plugin-rsc/src/core/browser.ts index d0f5e649f..25e1069b3 100644 --- a/packages/plugin-rsc/src/core/browser.ts +++ b/packages/plugin-rsc/src/core/browser.ts @@ -1,5 +1,5 @@ -import { memoize } from '@hiogawa/utils' import { removeReferenceCacheTag, setInternalRequire } from './shared' +import { memoize } from '@hiogawa/utils' let init = false diff --git a/packages/plugin-rsc/src/core/rsc.ts b/packages/plugin-rsc/src/core/rsc.ts index d00452555..876fa3f01 100644 --- a/packages/plugin-rsc/src/core/rsc.ts +++ b/packages/plugin-rsc/src/core/rsc.ts @@ -1,4 +1,3 @@ -import { memoize, tinyassert } from '@hiogawa/utils' import type { BundlerConfig, ImportManifestEntry, ModuleMap } from '../types' import { SERVER_DECODE_CLIENT_PREFIX, @@ -7,7 +6,7 @@ import { removeReferenceCacheTag, setInternalRequire, } from './shared' - +import { memoize, tinyassert } from '@hiogawa/utils' // @ts-ignore import * as ReactServer from '@vitejs/plugin-rsc/vendor/react-server-dom/server.edge' diff --git a/packages/plugin-rsc/src/core/ssr.ts b/packages/plugin-rsc/src/core/ssr.ts index 68a847a36..f5f2d63b2 100644 --- a/packages/plugin-rsc/src/core/ssr.ts +++ b/packages/plugin-rsc/src/core/ssr.ts @@ -1,6 +1,6 @@ -import { memoize } from '@hiogawa/utils' import type { ServerConsumerManifest } from '../types' import { removeReferenceCacheTag, setInternalRequire } from './shared' +import { memoize } from '@hiogawa/utils' let init = false diff --git a/packages/plugin-rsc/src/plugin.ts b/packages/plugin-rsc/src/plugin.ts index 4851bbabd..008da7e0d 100644 --- a/packages/plugin-rsc/src/plugin.ts +++ b/packages/plugin-rsc/src/plugin.ts @@ -1,11 +1,45 @@ +import vitePluginRscCore from './core/plugin' +import { cjsModuleRunnerPlugin } from './plugins/cjs' +import { vitePluginFindSourceMapURL } from './plugins/find-source-map-url' +import { scanBuildStripPlugin } from './plugins/scan' +import { parseCssVirtual, toCssVirtual, parseIdQuery } from './plugins/shared' +import { + createVirtualPlugin, + getEntrySource, + hashString, + normalizeRelativePath, + getFetchHandlerExport, + sortObject, + withRollupError, +} from './plugins/utils' +import { validateImportPlugin } from './plugins/validate-import' +import { + cleanUrl, + directRequestRE, + evalValue, + normalizeViteImportAnalysisUrl, + prepareError, +} from './plugins/vite-utils' +import { + type TransformWrapExportFilter, + hasDirective, + transformDirectiveProxyExport, + transformServerActionServer, + transformWrapExport, + findDirectives, +} from './transforms' +import { generateEncryptionKey, toBase64 } from './utils/encryption-utils' +import { createRpcServer } from './utils/rpc' +import { createDebug } from '@hiogawa/utils' +import { createRequestListener } from '@remix-run/node-fetch-server' +import * as esModuleLexer from 'es-module-lexer' +import MagicString from 'magic-string' import assert from 'node:assert' import fs from 'node:fs' import { createRequire } from 'node:module' import path from 'node:path' import { pathToFileURL } from 'node:url' -import { createRequestListener } from '@remix-run/node-fetch-server' -import * as esModuleLexer from 'es-module-lexer' -import MagicString from 'magic-string' +import { stripLiteral } from 'strip-literal' import * as vite from 'vite' import { type BuilderOptions, @@ -22,40 +56,6 @@ import { parseAstAsync, } from 'vite' import { crawlFrameworkPkgs } from 'vitefu' -import vitePluginRscCore from './core/plugin' -import { - type TransformWrapExportFilter, - hasDirective, - transformDirectiveProxyExport, - transformServerActionServer, - transformWrapExport, - findDirectives, -} from './transforms' -import { generateEncryptionKey, toBase64 } from './utils/encryption-utils' -import { createRpcServer } from './utils/rpc' -import { - cleanUrl, - directRequestRE, - evalValue, - normalizeViteImportAnalysisUrl, - prepareError, -} from './plugins/vite-utils' -import { cjsModuleRunnerPlugin } from './plugins/cjs' -import { - createVirtualPlugin, - getEntrySource, - hashString, - normalizeRelativePath, - getFetchHandlerExport, - sortObject, - withRollupError, -} from './plugins/utils' -import { createDebug } from '@hiogawa/utils' -import { scanBuildStripPlugin } from './plugins/scan' -import { validateImportPlugin } from './plugins/validate-import' -import { vitePluginFindSourceMapURL } from './plugins/find-source-map-url' -import { parseCssVirtual, toCssVirtual, parseIdQuery } from './plugins/shared' -import { stripLiteral } from 'strip-literal' const isRolldownVite = 'rolldownVersion' in vite diff --git a/packages/plugin-rsc/src/plugins/cjs.ts b/packages/plugin-rsc/src/plugins/cjs.ts index 73315615a..4194c43da 100644 --- a/packages/plugin-rsc/src/plugins/cjs.ts +++ b/packages/plugin-rsc/src/plugins/cjs.ts @@ -1,11 +1,11 @@ -import { parseAstAsync, type Plugin } from 'vite' -import { findClosestPkgJsonPath } from 'vitefu' -import path from 'node:path' -import fs from 'node:fs' -import * as esModuleLexer from 'es-module-lexer' import { transformCjsToEsm } from '../transforms/cjs' -import { createDebug } from '@hiogawa/utils' import { parseIdQuery } from './shared' +import { createDebug } from '@hiogawa/utils' +import * as esModuleLexer from 'es-module-lexer' +import fs from 'node:fs' +import path from 'node:path' +import { parseAstAsync, type Plugin } from 'vite' +import { findClosestPkgJsonPath } from 'vitefu' const debug = createDebug('vite-rsc:cjs') diff --git a/packages/plugin-rsc/src/plugins/find-source-map-url.ts b/packages/plugin-rsc/src/plugins/find-source-map-url.ts index 04bf49415..5fb40c88f 100644 --- a/packages/plugin-rsc/src/plugins/find-source-map-url.ts +++ b/packages/plugin-rsc/src/plugins/find-source-map-url.ts @@ -1,6 +1,6 @@ +import fs from 'node:fs' import { fileURLToPath } from 'node:url' import type { EnvironmentModuleNode, Plugin, ViteDevServer } from 'vite' -import fs from 'node:fs' // // support findSourceMapURL diff --git a/packages/plugin-rsc/src/plugins/scan.test.ts b/packages/plugin-rsc/src/plugins/scan.test.ts index f56737329..d14ea3736 100644 --- a/packages/plugin-rsc/src/plugins/scan.test.ts +++ b/packages/plugin-rsc/src/plugins/scan.test.ts @@ -1,5 +1,5 @@ -import { describe, expect, it } from 'vitest' import { transformScanBuildStrip } from './scan' +import { describe, expect, it } from 'vitest' describe(transformScanBuildStrip, () => { it('basic', async () => { diff --git a/packages/plugin-rsc/src/plugins/scan.ts b/packages/plugin-rsc/src/plugins/scan.ts index be1a60a1e..a62bd9b5b 100644 --- a/packages/plugin-rsc/src/plugins/scan.ts +++ b/packages/plugin-rsc/src/plugins/scan.ts @@ -1,7 +1,7 @@ +import type { RscPluginManager } from '../plugin' import * as esModuleLexer from 'es-module-lexer' -import { parseAstAsync, type Plugin } from 'vite' import { walk } from 'estree-walker' -import type { RscPluginManager } from '../plugin' +import { parseAstAsync, type Plugin } from 'vite' // During scan build, we strip all code but imports to // traverse module graph faster and just discover client/server references. diff --git a/packages/plugin-rsc/src/plugins/vite-utils.ts b/packages/plugin-rsc/src/plugins/vite-utils.ts index afa780b11..511785658 100644 --- a/packages/plugin-rsc/src/plugins/vite-utils.ts +++ b/packages/plugin-rsc/src/plugins/vite-utils.ts @@ -2,8 +2,8 @@ import fs from 'node:fs' import path from 'node:path' -import type { DevEnvironment, ErrorPayload, Rollup } from 'vite' import { stripVTControlCharacters as strip } from 'node:util' +import type { DevEnvironment, ErrorPayload, Rollup } from 'vite' export const VALID_ID_PREFIX = `/@id/` diff --git a/packages/plugin-rsc/src/react/browser.ts b/packages/plugin-rsc/src/react/browser.ts index 2d0bded73..0cf99d1a5 100644 --- a/packages/plugin-rsc/src/react/browser.ts +++ b/packages/plugin-rsc/src/react/browser.ts @@ -1,6 +1,6 @@ +import type { CallServerCallback } from '../types' // @ts-ignore import * as ReactClient from '@vitejs/plugin-rsc/vendor/react-server-dom/client.browser' -import type { CallServerCallback } from '../types' export { setRequireModule } from '../core/browser' diff --git a/packages/plugin-rsc/src/react/rsc.ts b/packages/plugin-rsc/src/react/rsc.ts index 260cd820f..c71f7e068 100644 --- a/packages/plugin-rsc/src/react/rsc.ts +++ b/packages/plugin-rsc/src/react/rsc.ts @@ -1,13 +1,13 @@ -// @ts-ignore -import * as ReactClient from '@vitejs/plugin-rsc/vendor/react-server-dom/client.edge' -// @ts-ignore -import * as ReactServer from '@vitejs/plugin-rsc/vendor/react-server-dom/server.edge' -import type { ReactFormState } from 'react-dom/client' import { createClientManifest, createServerDecodeClientManifest, createServerManifest, } from '../core/rsc' +// @ts-ignore +import * as ReactClient from '@vitejs/plugin-rsc/vendor/react-server-dom/client.edge' +// @ts-ignore +import * as ReactServer from '@vitejs/plugin-rsc/vendor/react-server-dom/server.edge' +import type { ReactFormState } from 'react-dom/client' export { loadServerAction, setRequireModule } from '../core/rsc' diff --git a/packages/plugin-rsc/src/react/ssr.ts b/packages/plugin-rsc/src/react/ssr.ts index caa325750..04f53c340 100644 --- a/packages/plugin-rsc/src/react/ssr.ts +++ b/packages/plugin-rsc/src/react/ssr.ts @@ -1,6 +1,6 @@ +import { createServerConsumerManifest } from '../core/ssr' // @ts-ignore import * as ReactClient from '@vitejs/plugin-rsc/vendor/react-server-dom/client.edge' -import { createServerConsumerManifest } from '../core/ssr' export { setRequireModule } from '../core/ssr' diff --git a/packages/plugin-rsc/src/rsc.tsx b/packages/plugin-rsc/src/rsc.tsx index 801fea4c0..781c0aba5 100644 --- a/packages/plugin-rsc/src/rsc.tsx +++ b/packages/plugin-rsc/src/rsc.tsx @@ -1,5 +1,5 @@ -import serverReferences from 'virtual:vite-rsc/server-references' import { setRequireModule } from './core/rsc' +import serverReferences from 'virtual:vite-rsc/server-references' export { createClientManifest, diff --git a/packages/plugin-rsc/src/ssr.tsx b/packages/plugin-rsc/src/ssr.tsx index b03e7327e..ec2c44b03 100644 --- a/packages/plugin-rsc/src/ssr.tsx +++ b/packages/plugin-rsc/src/ssr.tsx @@ -1,9 +1,9 @@ -import assetsManifest from 'virtual:vite-rsc/assets-manifest' -import * as clientReferences from 'virtual:vite-rsc/client-references' -import * as ReactDOM from 'react-dom' import { setRequireModule } from './core/ssr' import type { ResolvedAssetDeps } from './plugin' import { toCssVirtual } from './plugins/shared' +import * as ReactDOM from 'react-dom' +import assetsManifest from 'virtual:vite-rsc/assets-manifest' +import * as clientReferences from 'virtual:vite-rsc/client-references' export { createServerConsumerManifest } from './core/ssr' diff --git a/packages/plugin-rsc/src/transforms/cjs.test.ts b/packages/plugin-rsc/src/transforms/cjs.test.ts index d14d29fd8..84f281633 100644 --- a/packages/plugin-rsc/src/transforms/cjs.test.ts +++ b/packages/plugin-rsc/src/transforms/cjs.test.ts @@ -1,8 +1,8 @@ -import { createServer, createServerModuleRunner, parseAstAsync } from 'vite' -import { describe, expect, it } from 'vitest' -import { debugSourceMap } from './test-utils' import { transformCjsToEsm } from './cjs' +import { debugSourceMap } from './test-utils' import path from 'node:path' +import { createServer, createServerModuleRunner, parseAstAsync } from 'vite' +import { describe, expect, it } from 'vitest' describe(transformCjsToEsm, () => { async function testTransform(input: string) { diff --git a/packages/plugin-rsc/src/transforms/cjs.ts b/packages/plugin-rsc/src/transforms/cjs.ts index c5781fec7..bd50aef37 100644 --- a/packages/plugin-rsc/src/transforms/cjs.ts +++ b/packages/plugin-rsc/src/transforms/cjs.ts @@ -1,9 +1,9 @@ import type { Program, Node } from 'estree' -import MagicString from 'magic-string' -import { analyze } from 'periscopic' import { walk } from 'estree-walker' -import { fileURLToPath, pathToFileURL } from 'node:url' +import MagicString from 'magic-string' import path from 'node:path' +import { fileURLToPath, pathToFileURL } from 'node:url' +import { analyze } from 'periscopic' // TODO: // replacing require("xxx") into import("xxx") affects Vite's resolution. diff --git a/packages/plugin-rsc/src/transforms/fixtures/cjs/entry.mjs b/packages/plugin-rsc/src/transforms/fixtures/cjs/entry.mjs index 63c854c5a..191b45b89 100644 --- a/packages/plugin-rsc/src/transforms/fixtures/cjs/entry.mjs +++ b/packages/plugin-rsc/src/transforms/fixtures/cjs/entry.mjs @@ -1,11 +1,11 @@ import depDefault from './dep1.cjs' import * as depNamespace from './dep2.cjs' -import depFn from './function.cjs' -import depPrimitive from './primitive.cjs' +import dualLib from './dual-lib.cjs' import depExports from './exports.cjs' import depFnRequire from './function-require.cjs' -import dualLib from './dual-lib.cjs' +import depFn from './function.cjs' import cjsGlobals from './globals.cjs' +import depPrimitive from './primitive.cjs' export { depDefault, depNamespace, diff --git a/packages/plugin-rsc/src/transforms/hoist.test.ts b/packages/plugin-rsc/src/transforms/hoist.test.ts index 22742a470..635e890f6 100644 --- a/packages/plugin-rsc/src/transforms/hoist.test.ts +++ b/packages/plugin-rsc/src/transforms/hoist.test.ts @@ -1,7 +1,7 @@ -import { parseAstAsync } from 'vite' -import { describe, expect, it } from 'vitest' import { transformHoistInlineDirective } from './hoist' import { debugSourceMap } from './test-utils' +import { parseAstAsync } from 'vite' +import { describe, expect, it } from 'vitest' describe(transformHoistInlineDirective, () => { async function testTransform( diff --git a/packages/plugin-rsc/src/transforms/proxy-export.test.ts b/packages/plugin-rsc/src/transforms/proxy-export.test.ts index 4be88ac00..e4130ced2 100644 --- a/packages/plugin-rsc/src/transforms/proxy-export.test.ts +++ b/packages/plugin-rsc/src/transforms/proxy-export.test.ts @@ -1,8 +1,8 @@ -import { parseAstAsync } from 'vite' -import { describe, expect, test } from 'vitest' import { transformProxyExport } from './proxy-export' import { debugSourceMap } from './test-utils' import { transformWrapExport } from './wrap-export' +import { parseAstAsync } from 'vite' +import { describe, expect, test } from 'vitest' async function testTransform(input: string, options?: { keep?: boolean }) { const ast = await parseAstAsync(input) diff --git a/packages/plugin-rsc/src/transforms/proxy-export.ts b/packages/plugin-rsc/src/transforms/proxy-export.ts index f08a05701..0b37684b7 100644 --- a/packages/plugin-rsc/src/transforms/proxy-export.ts +++ b/packages/plugin-rsc/src/transforms/proxy-export.ts @@ -1,8 +1,8 @@ +import { hasDirective } from './utils' import { tinyassert } from '@hiogawa/utils' import type { Node, Program } from 'estree' import MagicString from 'magic-string' import { extract_names } from 'periscopic' -import { hasDirective } from './utils' export type TransformProxyExportOptions = { /** Required for source map and `keep` options */ diff --git a/packages/plugin-rsc/src/transforms/server-action.ts b/packages/plugin-rsc/src/transforms/server-action.ts index a7e3b83a1..63f5c6e17 100644 --- a/packages/plugin-rsc/src/transforms/server-action.ts +++ b/packages/plugin-rsc/src/transforms/server-action.ts @@ -1,8 +1,8 @@ -import type { Program } from 'estree' -import type MagicString from 'magic-string' import { transformHoistInlineDirective } from './hoist' import { hasDirective } from './utils' import { transformWrapExport } from './wrap-export' +import type { Program } from 'estree' +import type MagicString from 'magic-string' // TODO // source map for `options.runtime` (registerServerReference) call diff --git a/packages/plugin-rsc/src/transforms/test-utils.ts b/packages/plugin-rsc/src/transforms/test-utils.ts index 31818b9a2..88ee0e5dd 100644 --- a/packages/plugin-rsc/src/transforms/test-utils.ts +++ b/packages/plugin-rsc/src/transforms/test-utils.ts @@ -1,7 +1,7 @@ -import { dirname } from 'path' import { hashString } from '@hiogawa/utils' import { mkdir, writeFile } from 'fs/promises' import type MagicString from 'magic-string' +import { dirname } from 'path' export async function debugSourceMap(output: MagicString): Promise { // load it directly to https://evanw.github.io/source-map-visualization diff --git a/packages/plugin-rsc/src/transforms/waku.test.ts b/packages/plugin-rsc/src/transforms/waku.test.ts index a89d6bbda..def0483b4 100644 --- a/packages/plugin-rsc/src/transforms/waku.test.ts +++ b/packages/plugin-rsc/src/transforms/waku.test.ts @@ -1,8 +1,8 @@ -import { parseAstAsync } from 'vite' -import { describe, expect, test } from 'vitest' import { transformDirectiveProxyExport } from './proxy-export' import { transformServerActionServer } from './server-action' import { debugSourceMap } from './test-utils' +import { parseAstAsync } from 'vite' +import { describe, expect, test } from 'vitest' // copied from // https://github.com/wakujs/waku/blob/55cc5fb3c74b1cd9fa5dac5b20b8626c4d5043ff/packages/waku/tests/vite-plugin-rsc-transform-internals.test.ts diff --git a/packages/plugin-rsc/src/transforms/wrap-export.test.ts b/packages/plugin-rsc/src/transforms/wrap-export.test.ts index 28dfa19a4..fd0dc1500 100644 --- a/packages/plugin-rsc/src/transforms/wrap-export.test.ts +++ b/packages/plugin-rsc/src/transforms/wrap-export.test.ts @@ -1,10 +1,10 @@ -import { parseAstAsync } from 'vite' -import { describe, expect, test } from 'vitest' import { debugSourceMap } from './test-utils' import { type TransformWrapExportOptions, transformWrapExport, } from './wrap-export' +import { parseAstAsync } from 'vite' +import { describe, expect, test } from 'vitest' async function testTransform( input: string, diff --git a/packages/plugin-rsc/src/utils/encryption-runtime.ts b/packages/plugin-rsc/src/utils/encryption-runtime.ts index 84b307ce0..31b63797b 100644 --- a/packages/plugin-rsc/src/utils/encryption-runtime.ts +++ b/packages/plugin-rsc/src/utils/encryption-runtime.ts @@ -1,5 +1,3 @@ -import encryptionKeySource from 'virtual:vite-rsc/encryption-key' -import { once } from '@hiogawa/utils' import { createFromReadableStream, renderToReadableStream } from '../react/rsc' import { arrayToStream, @@ -8,6 +6,8 @@ import { encryptBuffer, fromBase64, } from './encryption-utils' +import { once } from '@hiogawa/utils' +import encryptionKeySource from 'virtual:vite-rsc/encryption-key' // based on // https://github.com/parcel-bundler/parcel/blob/9855f558a69edde843b1464f39a6010f6b421efe/packages/transformers/js/src/rsc-utils.js diff --git a/playground/class-components/src/App.tsx b/playground/class-components/src/App.tsx index 7340ce4a8..110d8cdd2 100644 --- a/playground/class-components/src/App.tsx +++ b/playground/class-components/src/App.tsx @@ -1,5 +1,5 @@ -import { Component } from 'react' import { getGetting } from './utils' +import { Component } from 'react' export class App extends Component { render() { diff --git a/playground/class-components/src/index.tsx b/playground/class-components/src/index.tsx index 607cf4b4e..f2913507f 100644 --- a/playground/class-components/src/index.tsx +++ b/playground/class-components/src/index.tsx @@ -1,6 +1,6 @@ +import { App } from './App' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import { App } from './App' createRoot(document.getElementById('root')!).render( diff --git a/playground/class-components/vite.config.ts b/playground/class-components/vite.config.ts index c9a13540c..2d8605e26 100644 --- a/playground/class-components/vite.config.ts +++ b/playground/class-components/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +import { defineConfig } from 'vite' export default defineConfig({ server: { port: 8908 /* Should be unique */ }, diff --git a/playground/compiler-react-18/src/main.tsx b/playground/compiler-react-18/src/main.tsx index 813e3d764..a3587bb25 100644 --- a/playground/compiler-react-18/src/main.tsx +++ b/playground/compiler-react-18/src/main.tsx @@ -1,6 +1,6 @@ +import { App } from './App' import React from 'react' import ReactDOM from 'react-dom/client' -import { App } from './App' import './index.css' ReactDOM.createRoot(document.getElementById('root')!).render( diff --git a/playground/compiler-react-18/vite.config.ts b/playground/compiler-react-18/vite.config.ts index ec85482a1..08987b47a 100644 --- a/playground/compiler-react-18/vite.config.ts +++ b/playground/compiler-react-18/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +import { defineConfig } from 'vite' // https://vite.dev/config/ export default defineConfig(({ command }) => { diff --git a/playground/compiler/src/App.tsx b/playground/compiler/src/App.tsx index 07f8d0add..6d3bc2474 100644 --- a/playground/compiler/src/App.tsx +++ b/playground/compiler/src/App.tsx @@ -1,6 +1,6 @@ -import { useState } from 'react' -import './App.css' import { ClassComponent } from './ClassComponent' +import './App.css' +import { useState } from 'react' export function App() { const [count, setCount] = useState(0) diff --git a/playground/compiler/src/main.tsx b/playground/compiler/src/main.tsx index 813e3d764..a3587bb25 100644 --- a/playground/compiler/src/main.tsx +++ b/playground/compiler/src/main.tsx @@ -1,6 +1,6 @@ +import { App } from './App' import React from 'react' import ReactDOM from 'react-dom/client' -import { App } from './App' import './index.css' ReactDOM.createRoot(document.getElementById('root')!).render( diff --git a/playground/compiler/vite.config.ts b/playground/compiler/vite.config.ts index a8bffc7a0..5593e05a5 100644 --- a/playground/compiler/vite.config.ts +++ b/playground/compiler/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +import { defineConfig } from 'vite' // https://vite.dev/config/ export default defineConfig(({ command }) => { diff --git a/playground/hmr-false/src/main.tsx b/playground/hmr-false/src/main.tsx index 056386a7d..315e02673 100644 --- a/playground/hmr-false/src/main.tsx +++ b/playground/hmr-false/src/main.tsx @@ -1,4 +1,4 @@ -import ReactDOM from 'react-dom/client' import App from './App.jsx' +import ReactDOM from 'react-dom/client' ReactDOM.createRoot(document.getElementById('app')!).render() diff --git a/playground/hook-with-jsx/src/index.tsx b/playground/hook-with-jsx/src/index.tsx index 5e7046ce2..e62507a76 100644 --- a/playground/hook-with-jsx/src/index.tsx +++ b/playground/hook-with-jsx/src/index.tsx @@ -1,6 +1,6 @@ +import { App } from './App.tsx' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import { App } from './App.tsx' createRoot(document.getElementById('root')!).render( diff --git a/playground/hook-with-jsx/vite.config.ts b/playground/hook-with-jsx/vite.config.ts index 6e5b8e40a..3f6f653fd 100644 --- a/playground/hook-with-jsx/vite.config.ts +++ b/playground/hook-with-jsx/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +import { defineConfig } from 'vite' export default defineConfig({ server: { port: 8909 /* Should be unique */ }, diff --git a/playground/include-node-modules/vite.config.ts b/playground/include-node-modules/vite.config.ts index 28c3dd518..27d0da02b 100644 --- a/playground/include-node-modules/vite.config.ts +++ b/playground/include-node-modules/vite.config.ts @@ -1,6 +1,6 @@ -import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react' import type { PluginItem as BabelPlugin } from '@babel/core' +import react from '@vitejs/plugin-react' +import { defineConfig } from 'vite' export default defineConfig({ plugins: [ diff --git a/playground/mdx/src/main.tsx b/playground/mdx/src/main.tsx index 2d7788204..c2ab4328c 100644 --- a/playground/mdx/src/main.tsx +++ b/playground/mdx/src/main.tsx @@ -1,7 +1,7 @@ -import React from 'react' -import ReactDOM from 'react-dom/client' import Demo from './demo.mdx' import Demo2 from './demo2.md' +import React from 'react' +import ReactDOM from 'react-dom/client' ReactDOM.createRoot(document.getElementById('root')!).render( diff --git a/playground/mdx/vite.config.ts b/playground/mdx/vite.config.ts index 4cee7a4ea..d2ef28345 100644 --- a/playground/mdx/vite.config.ts +++ b/playground/mdx/vite.config.ts @@ -1,6 +1,6 @@ -import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react' import mdx from '@mdx-js/rollup' +import react from '@vitejs/plugin-react' +import { defineConfig } from 'vite' // https://vite.dev/config/ export default defineConfig({ diff --git a/playground/react-classic/App.jsx b/playground/react-classic/App.jsx index bb59d3864..e8318d14f 100644 --- a/playground/react-classic/App.jsx +++ b/playground/react-classic/App.jsx @@ -1,5 +1,5 @@ -import React, { useState } from 'react' import WithQuery from './components/WithQuery?qs-should-not-break-plugin-react' +import React, { useState } from 'react' function App() { const [count, setCount] = useState(0) diff --git a/playground/react-emotion/src/App.tsx b/playground/react-emotion/src/App.tsx index 09300fd8d..3903badc1 100644 --- a/playground/react-emotion/src/App.tsx +++ b/playground/react-emotion/src/App.tsx @@ -1,6 +1,6 @@ +import { Counter, StyledCode } from './Counter.tsx' import { useState } from 'react' import _Switch from 'react-switch' -import { Counter, StyledCode } from './Counter.tsx' const Switch = (_Switch as any).default || _Switch diff --git a/playground/react-emotion/src/Counter.tsx b/playground/react-emotion/src/Counter.tsx index d7d88f2c4..f4394d3e5 100644 --- a/playground/react-emotion/src/Counter.tsx +++ b/playground/react-emotion/src/Counter.tsx @@ -1,5 +1,5 @@ -import styled from '@emotion/styled' import { css } from '@emotion/react' +import styled from '@emotion/styled' import { useState } from 'react' // Ensure HMR of styled component alongside other components diff --git a/playground/react-emotion/src/main.tsx b/playground/react-emotion/src/main.tsx index 1f5976c1d..ee8dba565 100644 --- a/playground/react-emotion/src/main.tsx +++ b/playground/react-emotion/src/main.tsx @@ -1,4 +1,4 @@ -import ReactDOM from 'react-dom/client' import App from './App.tsx' +import ReactDOM from 'react-dom/client' ReactDOM.createRoot(document.getElementById('app')!).render() diff --git a/playground/react-sourcemap/main.jsx b/playground/react-sourcemap/main.jsx index b53aa9526..5eb4232c8 100644 --- a/playground/react-sourcemap/main.jsx +++ b/playground/react-sourcemap/main.jsx @@ -1,6 +1,6 @@ +import App from './App.jsx' import React from 'react' import ReactDOM from 'react-dom/client' -import App from './App.jsx' ReactDOM.createRoot(document.getElementById('app')).render( React.createElement(App), diff --git a/playground/react/App.jsx b/playground/react/App.jsx index b2e66b30d..488ac28b7 100644 --- a/playground/react/App.jsx +++ b/playground/react/App.jsx @@ -1,14 +1,14 @@ -import { useState } from 'react' -import Button from 'jsx-entry' -import WithQuery from './components/WithQuery?qs-should-not-break-plugin-react' import { Accordion } from './components/Accordion' -import Parent from './hmr/parent' +import WithQuery from './components/WithQuery?qs-should-not-break-plugin-react' +import { ContextButton } from './context/ContextButton' +import { CountProvider } from './context/CountProvider' import InjectExportsLater from './hmr/inject-exports-later' import { JsxImportRuntime } from './hmr/jsx-import-runtime' -import { CountProvider } from './context/CountProvider' -import { ContextButton } from './context/ContextButton' +import Parent from './hmr/parent' import { TestImportAttributes } from './import-attributes/test' import { TEST_NON_JSX, TestNonJsx } from './non-jsx/test' +import Button from 'jsx-entry' +import { useState } from 'react' function App() { const [count, setCount] = useState(0) diff --git a/playground/react/context/ContextButton.jsx b/playground/react/context/ContextButton.jsx index 92c6d0bd2..75bd40c41 100644 --- a/playground/react/context/ContextButton.jsx +++ b/playground/react/context/ContextButton.jsx @@ -1,5 +1,5 @@ -import { useContext } from 'react' import { CountContext } from './CountProvider' +import { useContext } from 'react' export function ContextButton() { const { count, setCount } = useContext(CountContext) diff --git a/playground/ssr-react/src/entry-client.jsx b/playground/ssr-react/src/entry-client.jsx index 62b8418e0..536cd4b03 100644 --- a/playground/ssr-react/src/entry-client.jsx +++ b/playground/ssr-react/src/entry-client.jsx @@ -1,6 +1,6 @@ import '@vitejs/plugin-react/preamble' -import ReactDOM from 'react-dom/client' import { App } from './App' +import ReactDOM from 'react-dom/client' ReactDOM.hydrateRoot( document.getElementById('app'), diff --git a/playground/ssr-react/src/entry-server.jsx b/playground/ssr-react/src/entry-server.jsx index 091b32a69..b9688a648 100644 --- a/playground/ssr-react/src/entry-server.jsx +++ b/playground/ssr-react/src/entry-server.jsx @@ -1,5 +1,5 @@ -import ReactDOMServer from 'react-dom/server' import { App } from './App' +import ReactDOMServer from 'react-dom/server' export function render(url) { return ReactDOMServer.renderToString( diff --git a/playground/ssr-react/vite.config.js b/playground/ssr-react/vite.config.js index d5074ecd5..ce55fc9dc 100644 --- a/playground/ssr-react/vite.config.js +++ b/playground/ssr-react/vite.config.js @@ -1,8 +1,8 @@ +import react from '@vitejs/plugin-react' import fs from 'node:fs' import path from 'node:path' import url from 'node:url' import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react' const _dirname = path.dirname(url.fileURLToPath(import.meta.url)) diff --git a/playground/test-utils.ts b/playground/test-utils.ts index 558a4b30a..82b703105 100644 --- a/playground/test-utils.ts +++ b/playground/test-utils.ts @@ -1,3 +1,4 @@ +import { page, testDir } from './vitestSetup' // test utils used in e2e tests for playgrounds. // `import { getColor } from '~utils'` @@ -5,7 +6,6 @@ import fs from 'node:fs' import path from 'node:path' import type { ConsoleMessage, ElementHandle } from 'playwright-chromium' import { expect } from 'vitest' -import { page, testDir } from './vitestSetup' export * from './vitestSetup' diff --git a/playground/tsconfig-jsx-preserve/src/main.tsx b/playground/tsconfig-jsx-preserve/src/main.tsx index 056386a7d..315e02673 100644 --- a/playground/tsconfig-jsx-preserve/src/main.tsx +++ b/playground/tsconfig-jsx-preserve/src/main.tsx @@ -1,4 +1,4 @@ -import ReactDOM from 'react-dom/client' import App from './App.jsx' +import ReactDOM from 'react-dom/client' ReactDOM.createRoot(document.getElementById('app')!).render() diff --git a/playground/vitestGlobalSetup.ts b/playground/vitestGlobalSetup.ts index 508ec0f0a..bc89edc08 100644 --- a/playground/vitestGlobalSetup.ts +++ b/playground/vitestGlobalSetup.ts @@ -1,8 +1,8 @@ -import path from 'node:path' import fs from 'fs-extra' -import type { TestProject } from 'vitest/node' +import path from 'node:path' import type { BrowserServer } from 'playwright-chromium' import { chromium } from 'playwright-chromium' +import type { TestProject } from 'vitest/node' let browserServer: BrowserServer | undefined diff --git a/playground/vitestSetup.ts b/playground/vitestSetup.ts index 0638b88a5..04473b83f 100644 --- a/playground/vitestSetup.ts +++ b/playground/vitestSetup.ts @@ -1,7 +1,8 @@ +import fs from 'fs-extra' import type * as http from 'node:http' import path, { dirname, resolve } from 'node:path' -import fs from 'fs-extra' import { chromium } from 'playwright-chromium' +import type { Browser, Page } from 'playwright-chromium' import type { ConfigEnv, InlineConfig, @@ -12,9 +13,6 @@ import type { UserConfig, ViteDevServer, } from 'vite' -import type { Browser, Page } from 'playwright-chromium' -import type { RunnerTestFile } from 'vitest' -import { beforeAll, inject } from 'vitest' import { build, createBuilder, @@ -23,6 +21,8 @@ import { mergeConfig, preview, } from 'vite' +import type { RunnerTestFile } from 'vitest' +import { beforeAll, inject } from 'vitest' // #region env diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 886392989..8862f3159 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -50,6 +50,9 @@ importers: lint-staged: specifier: ^16.2.4 version: 16.2.4 + oxfmt: + specifier: ^0.8.0 + version: 0.8.0 picocolors: specifier: ^1.1.1 version: 1.1.1 @@ -1749,6 +1752,46 @@ packages: '@oxc-project/types@0.95.0': resolution: {integrity: sha512-vACy7vhpMPhjEJhULNxrdR0D943TkA/MigMpJCHmBHvMXxRStRi/dPtTlfQ3uDwWSzRpT8z+7ImjZVf8JWBocQ==} + '@oxfmt/darwin-arm64@0.8.0': + resolution: {integrity: sha512-rJBnT0JMrKb+MfuF9Kw5v6jQqCwdJv85C+++ZtZVe1zWlbrS2nNjGapcdtaocRxkOMb22axHQOrygGsSvsoWqg==} + cpu: [arm64] + os: [darwin] + + '@oxfmt/darwin-x64@0.8.0': + resolution: {integrity: sha512-vtXjkHv6x2PY+3C0DS8hMjMuzd9/hI4xmSGOucVCo61bQW5NSJCCoxGLtQYqwvguZhQP6tGYZKvieUx1q9Lwkg==} + cpu: [x64] + os: [darwin] + + '@oxfmt/linux-arm64-gnu@0.8.0': + resolution: {integrity: sha512-7WmWsOq38Uh2gPj8I0q+z+zsmCkh9+TUtaYzeNdOxBDKdIW/stYZ4RxHSwF3fBBAEyoUCMDpE7+6XFxWQ/vEBw==} + cpu: [arm64] + os: [linux] + + '@oxfmt/linux-arm64-musl@0.8.0': + resolution: {integrity: sha512-7aUH1nnGIxHoJ9YLBZPuiN+t5VSgW3EahakYfLMY8lLQETXxhM9ScA7PQWL9g4PipMqk0+9DmOZOZMZQlijvMg==} + cpu: [arm64] + os: [linux] + + '@oxfmt/linux-x64-gnu@0.8.0': + resolution: {integrity: sha512-Td/wqHiwMGnuFiQLXab0NqAQraWI6IsU/u3Yjw8rbVE+LSGaLt+XquZ9xDZdjgjtLp6bUaNZEgOYQFkVVjeDZw==} + cpu: [x64] + os: [linux] + + '@oxfmt/linux-x64-musl@0.8.0': + resolution: {integrity: sha512-YB8KmXx7vNPVz8lRGYqhEpH40oXGWx5+FSSE6pr81LW4DqsjIE4MaBrrbcf0z0mMJD3/1dsWE4a2DsCsSeOl0g==} + cpu: [x64] + os: [linux] + + '@oxfmt/win32-arm64@0.8.0': + resolution: {integrity: sha512-rbP7qAP8CtCPgb7qITSmoezXISI/fCHrWlshCHxGNsiusqcE+q4TjStRlMW8gABcorGlWYhDcjAiK9gy1OciZA==} + cpu: [arm64] + os: [win32] + + '@oxfmt/win32-x64@0.8.0': + resolution: {integrity: sha512-naUwl9pvVxDw3D8qEZ+timkO6Z7EdkVKJO5OUA07f8MElQog7ODqDUGt4QH2fAajPVd9OYh7b3AJw3nPlr5+bA==} + cpu: [x64] + os: [win32] + '@playwright/test@1.56.1': resolution: {integrity: sha512-vSMYtL/zOcFpvJCW71Q/OEGQb7KYBPAdKh35WNSkaZA75JlAO8ED8UN6GUNTm3drWomcbcqRPFqQbLae8yBTdg==} engines: {node: '>=18'} @@ -3882,6 +3925,11 @@ packages: resolution: {integrity: sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==} engines: {node: '>= 0.8.0'} + oxfmt@0.8.0: + resolution: {integrity: sha512-apqVXMgg4sO6+f51kn3oNBUXflgQ1SxmcKtq/XpRYLi7BDwsl06kkY7fkxDwxyPRDWikd/0/2gX72eT0E0mseg==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + p-limit@3.1.0: resolution: {integrity: sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==} engines: {node: '>=10'} @@ -5449,6 +5497,30 @@ snapshots: '@oxc-project/types@0.95.0': {} + '@oxfmt/darwin-arm64@0.8.0': + optional: true + + '@oxfmt/darwin-x64@0.8.0': + optional: true + + '@oxfmt/linux-arm64-gnu@0.8.0': + optional: true + + '@oxfmt/linux-arm64-musl@0.8.0': + optional: true + + '@oxfmt/linux-x64-gnu@0.8.0': + optional: true + + '@oxfmt/linux-x64-musl@0.8.0': + optional: true + + '@oxfmt/win32-arm64@0.8.0': + optional: true + + '@oxfmt/win32-x64@0.8.0': + optional: true + '@playwright/test@1.56.1': dependencies: playwright: 1.56.1 @@ -7583,6 +7655,17 @@ snapshots: prelude-ls: 1.2.1 type-check: 0.4.0 + oxfmt@0.8.0: + optionalDependencies: + '@oxfmt/darwin-arm64': 0.8.0 + '@oxfmt/darwin-x64': 0.8.0 + '@oxfmt/linux-arm64-gnu': 0.8.0 + '@oxfmt/linux-arm64-musl': 0.8.0 + '@oxfmt/linux-x64-gnu': 0.8.0 + '@oxfmt/linux-x64-musl': 0.8.0 + '@oxfmt/win32-arm64': 0.8.0 + '@oxfmt/win32-x64': 0.8.0 + p-limit@3.1.0: dependencies: yocto-queue: 0.1.0 diff --git a/scripts/release.ts b/scripts/release.ts index 4a71b452c..ce40e5e55 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -1,5 +1,5 @@ -import { readFileSync, writeFileSync } from 'node:fs' import { generateChangelog, release } from '@vitejs/release-scripts' +import { readFileSync, writeFileSync } from 'node:fs' import colors from 'picocolors' const nextH2RE = /^## /gm