diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 4b5a89ada9..b8fa95cf73 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -246,6 +246,10 @@ jobs: vp run type-check:tsgo vp run build vp run test navigation-utils.test.ts real-browser-flicker.test.tsx workflow-parallel-limit.test.tsx + - name: viteplus-ws-repro + node-version: 24 + command: | + vp test run exclude: # frm-stack uses Docker (testcontainers) which doesn't work the same way on Windows - os: windows-latest diff --git a/ecosystem-ci/patch-project.ts b/ecosystem-ci/patch-project.ts index 7b3350c666..9215eae5dd 100644 --- a/ecosystem-ci/patch-project.ts +++ b/ecosystem-ci/patch-project.ts @@ -21,6 +21,18 @@ const cwd = directory ? join(repoRoot, directory) : repoRoot; // run vp migrate const cli = process.env.VITE_PLUS_CLI_BIN ?? 'vp'; +// Projects that already have vite-plus need it removed before migration so +// vp migrate treats them as fresh and applies tgz overrides. Without this, +// vp migrate detects "already using Vite+" and skips override injection. +const forceFreshMigration = 'forceFreshMigration' in repoConfig && repoConfig.forceFreshMigration; +if (forceFreshMigration) { + const pkgPath = join(cwd, 'package.json'); + const pkg = JSON.parse(await readFile(pkgPath, 'utf-8')); + delete pkg.devDependencies?.['vite-plus']; + delete pkg.dependencies?.['vite-plus']; + await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf-8'); +} + if (project === 'rollipop') { const oxfmtrc = await readFile(join(repoRoot, '.oxfmtrc.json'), 'utf-8'); await writeFile( diff --git a/ecosystem-ci/repo.json b/ecosystem-ci/repo.json index 7a64745f08..e1aa9fc242 100644 --- a/ecosystem-ci/repo.json +++ b/ecosystem-ci/repo.json @@ -54,5 +54,11 @@ "repository": "https://github.com/fengmk2/vite-vue-vercel.git", "branch": "main", "hash": "f2bf9fc40880c6a80f5d89bff70641c2eeaf77ef" + }, + "viteplus-ws-repro": { + "repository": "https://github.com/Charles5277/viteplus-ws-repro.git", + "branch": "main", + "hash": "451925ad7c07750a23de1d6ed454825d0eb14092", + "forceFreshMigration": true } } diff --git a/packages/test/build.ts b/packages/test/build.ts index 8def7e6465..4ed27b0039 100644 --- a/packages/test/build.ts +++ b/packages/test/build.ts @@ -302,9 +302,18 @@ async function mergePackageJson(pluginExports: Array<{ exportPath: string; shimF // browser-provider exports. Browser code uses index.js which is safe. // This separation prevents Node.js-only code (like __vite__injectQuery) from being // loaded in the browser, which would cause "Identifier already declared" errors. + // + // IMPORTANT: The 'browser' condition must come BEFORE 'node' because vitest passes + // custom --conditions (like 'browser') to worker processes when frameworks like Nuxt + // set edge/cloudflare presets. Without the 'browser' condition here, Node.js would + // match 'node' first, loading index-node.js which imports @vitest/browser/index.js, + // which imports 'ws'. With --conditions browser active, 'ws' resolves to its browser + // stub (ws/browser.js) that doesn't export WebSocketServer, causing a SyntaxError. + // See: https://github.com/voidzero-dev/vite-plus/issues/831 if (destPkg.exports['.'] && destPkg.exports['.'].import) { destPkg.exports['.'].import = { types: destPkg.exports['.'].import.types, + browser: destPkg.exports['.'].import.default, node: './dist/index-node.js', default: destPkg.exports['.'].import.default, }; diff --git a/packages/test/package.json b/packages/test/package.json index 5d2c8d0641..6a96280eef 100644 --- a/packages/test/package.json +++ b/packages/test/package.json @@ -37,6 +37,7 @@ ".": { "import": { "types": "./dist/index.d.ts", + "browser": "./dist/index.js", "node": "./dist/index-node.js", "default": "./dist/index.js" },