From 755ecdfa3b9f03864367bf32434aaa2836a4d6e1 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 16 Jan 2025 20:29:22 +0100 Subject: [PATCH] Revert "fix: re-apply default conditions if using vite 6 or later (#7071)" (#7271) --- .../vitest/src/node/plugins/conditions.ts | 16 ------------- packages/vitest/src/node/plugins/index.ts | 7 ++---- packages/vitest/src/node/plugins/workspace.ts | 7 ++---- pnpm-lock.yaml | 8 ------- .../deps/test-dep-conditions/default.js | 1 - .../config/deps/test-dep-conditions/module.js | 1 - test/config/deps/test-dep-conditions/node.js | 1 - .../deps/test-dep-conditions/package.json | 12 ---------- .../fixtures/conditions-subpackage/module.js | 1 - .../default-conditions.test.js | 6 ----- .../default-conditions/vitest.config.ts | 3 --- test/config/package.json | 1 - test/config/test/default-conditions.test.ts | 23 ------------------- 13 files changed, 4 insertions(+), 83 deletions(-) delete mode 100644 packages/vitest/src/node/plugins/conditions.ts delete mode 100644 test/config/deps/test-dep-conditions/default.js delete mode 100644 test/config/deps/test-dep-conditions/module.js delete mode 100644 test/config/deps/test-dep-conditions/node.js delete mode 100644 test/config/deps/test-dep-conditions/package.json delete mode 100644 test/config/fixtures/conditions-subpackage/module.js delete mode 100644 test/config/fixtures/default-conditions/default-conditions.test.js delete mode 100644 test/config/fixtures/default-conditions/vitest.config.ts delete mode 100644 test/config/test/default-conditions.test.ts diff --git a/packages/vitest/src/node/plugins/conditions.ts b/packages/vitest/src/node/plugins/conditions.ts deleted file mode 100644 index 8684cc0ba867..000000000000 --- a/packages/vitest/src/node/plugins/conditions.ts +++ /dev/null @@ -1,16 +0,0 @@ -import * as vite from 'vite' - -type Vite6Options = typeof vite & Partial<{ - defaultServerConditions?: string[] -}> - -/** - * In Vite 6+, providing a value for resolve.conditions overrides the defaults - * In Vite 5, passing ["node"] will be merged with the defaults - * - * @returns the appropriate conditions array depending on the vite version - * - */ -export function getDefaultServerConditions() { - return (vite as Vite6Options).defaultServerConditions ?? ['node'] -} diff --git a/packages/vitest/src/node/plugins/index.ts b/packages/vitest/src/node/plugins/index.ts index aa1794de80d0..1bc182c542b5 100644 --- a/packages/vitest/src/node/plugins/index.ts +++ b/packages/vitest/src/node/plugins/index.ts @@ -12,7 +12,6 @@ import { generateScopedClassName } from '../../integrations/css/css-modules' import { resolveApiServerConfig } from '../config/resolveConfig' import { Vitest } from '../core' import { createViteLogger, silenceImportViteIgnoreWarning } from '../viteLogger' -import { getDefaultServerConditions } from './conditions' import { CoverageTransform } from './coverageTransform' import { CSSEnablerPlugin } from './cssEnabler' import { MocksPlugins } from './mocks' @@ -74,8 +73,6 @@ export async function VitestPlugin( open = testConfig.uiBase ?? '/__vitest__/' } - const conditions = getDefaultServerConditions() - const config: ViteConfig = { root: viteConfig.test?.root || options.root, esbuild: @@ -93,7 +90,7 @@ export async function VitestPlugin( // setting this option can bypass that and fallback to cjs version mainFields: [], alias: testConfig.alias, - conditions, + conditions: ['node'], }, server: { ...testConfig.api, @@ -122,7 +119,7 @@ export async function VitestPlugin( // by default Vite resolves `module` field, which not always a native ESM module // setting this option can bypass that and fallback to cjs version mainFields: [], - conditions, + conditions: ['node'], }, }, }, diff --git a/packages/vitest/src/node/plugins/workspace.ts b/packages/vitest/src/node/plugins/workspace.ts index 3af3fda5edf0..a3e91bdcf29e 100644 --- a/packages/vitest/src/node/plugins/workspace.ts +++ b/packages/vitest/src/node/plugins/workspace.ts @@ -7,7 +7,6 @@ import { basename, dirname, relative, resolve } from 'pathe' import { configDefaults } from '../../defaults' import { generateScopedClassName } from '../../integrations/css/css-modules' import { createViteLogger, silenceImportViteIgnoreWarning } from '../viteLogger' -import { getDefaultServerConditions } from './conditions' import { CoverageTransform } from './coverageTransform' import { CSSEnablerPlugin } from './cssEnabler' import { MocksPlugins } from './mocks' @@ -63,8 +62,6 @@ export function WorkspaceVitestPlugin( } } - const conditions = getDefaultServerConditions() - const config: ViteConfig = { root, resolve: { @@ -72,7 +69,7 @@ export function WorkspaceVitestPlugin( // setting this option can bypass that and fallback to cjs version mainFields: [], alias: testConfig.alias, - conditions, + conditions: ['node'], }, esbuild: viteConfig.esbuild === false ? false @@ -107,7 +104,7 @@ export function WorkspaceVitestPlugin( // by default Vite resolves `module` field, which not always a native ESM module // setting this option can bypass that and fallback to cjs version mainFields: [], - conditions, + conditions: ['node'], }, }, }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7b34818427a0..213419c68faf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1123,9 +1123,6 @@ importers: test/config: devDependencies: - '@vitest/test-dep-conditions': - specifier: file:./deps/test-dep-conditions - version: file:test/config/deps/test-dep-conditions tinyexec: specifier: ^0.3.2 version: 0.3.2 @@ -4122,9 +4119,6 @@ packages: '@vitest/test-dep-cjs@file:test/core/deps/dep-cjs': resolution: {directory: test/core/deps/dep-cjs, type: directory} - '@vitest/test-dep-conditions@file:test/config/deps/test-dep-conditions': - resolution: {directory: test/config/deps/test-dep-conditions, type: directory} - '@vitest/test-dep1@file:test/core/deps/dep1': resolution: {directory: test/core/deps/dep1, type: directory} @@ -12770,8 +12764,6 @@ snapshots: '@vitest/test-dep-cjs@file:test/core/deps/dep-cjs': {} - '@vitest/test-dep-conditions@file:test/config/deps/test-dep-conditions': {} - '@vitest/test-dep1@file:test/core/deps/dep1': {} '@vitest/test-dep2@file:test/core/deps/dep2': diff --git a/test/config/deps/test-dep-conditions/default.js b/test/config/deps/test-dep-conditions/default.js deleted file mode 100644 index 4f7ee4f8e9fa..000000000000 --- a/test/config/deps/test-dep-conditions/default.js +++ /dev/null @@ -1 +0,0 @@ -export default 'default' diff --git a/test/config/deps/test-dep-conditions/module.js b/test/config/deps/test-dep-conditions/module.js deleted file mode 100644 index 3734dc62953b..000000000000 --- a/test/config/deps/test-dep-conditions/module.js +++ /dev/null @@ -1 +0,0 @@ -export default 'module' diff --git a/test/config/deps/test-dep-conditions/node.js b/test/config/deps/test-dep-conditions/node.js deleted file mode 100644 index aabc41e65094..000000000000 --- a/test/config/deps/test-dep-conditions/node.js +++ /dev/null @@ -1 +0,0 @@ -export default 'node' diff --git a/test/config/deps/test-dep-conditions/package.json b/test/config/deps/test-dep-conditions/package.json deleted file mode 100644 index 165383748017..000000000000 --- a/test/config/deps/test-dep-conditions/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "@vitest/test-dep-conditions", - "type": "module", - "private": true, - "exports": { - ".": { - "module": "./module.js", - "node": "./node.js", - "default": "./default.js" - } - } -} diff --git a/test/config/fixtures/conditions-subpackage/module.js b/test/config/fixtures/conditions-subpackage/module.js deleted file mode 100644 index 3734dc62953b..000000000000 --- a/test/config/fixtures/conditions-subpackage/module.js +++ /dev/null @@ -1 +0,0 @@ -export default 'module' diff --git a/test/config/fixtures/default-conditions/default-conditions.test.js b/test/config/fixtures/default-conditions/default-conditions.test.js deleted file mode 100644 index 7210b272f141..000000000000 --- a/test/config/fixtures/default-conditions/default-conditions.test.js +++ /dev/null @@ -1,6 +0,0 @@ -import { test, expect } from 'vitest'; -import condition from '@vitest/test-dep-conditions'; - -test('condition is correct', () => { - expect(condition).toBe('module') -}) diff --git a/test/config/fixtures/default-conditions/vitest.config.ts b/test/config/fixtures/default-conditions/vitest.config.ts deleted file mode 100644 index abed6b2116e1..000000000000 --- a/test/config/fixtures/default-conditions/vitest.config.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { defineConfig } from 'vitest/config' - -export default defineConfig({}) diff --git a/test/config/package.json b/test/config/package.json index dd7c8c7b2d1a..c59161d0a6b0 100644 --- a/test/config/package.json +++ b/test/config/package.json @@ -6,7 +6,6 @@ "test": "vitest --typecheck.enabled" }, "devDependencies": { - "@vitest/test-dep-conditions": "file:./deps/test-dep-conditions", "tinyexec": "^0.3.2", "vite": "latest", "vitest": "workspace:*" diff --git a/test/config/test/default-conditions.test.ts b/test/config/test/default-conditions.test.ts deleted file mode 100644 index 0de3acb42ed6..000000000000 --- a/test/config/test/default-conditions.test.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { expect, test } from 'vitest' -import { runVitest } from '../../test-utils' - -test('"module" condition for external dep', async () => { - const { stderr } = await runVitest({ - root: 'fixtures/default-conditions', - }) - - expect(stderr).toBe('') -}) - -test('"module" condition for inline dep', async () => { - const { stderr } = await runVitest({ - root: 'fixtures/default-conditions', - server: { - deps: { - inline: ['@vitest/test-dep-conditions'], - }, - }, - }) - - expect(stderr).toBe('') -})