Skip to content

Commit

Permalink
chore: replace dedupe plugin with resolve.dedupe
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jun 2, 2023
1 parent 895ec17 commit fd2a057
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
16 changes: 16 additions & 0 deletions packages/vitest/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,19 @@ export const globalApis = [
'beforeEach',
'afterEach',
]

export const vitestPackages = [
'vitest',
'vite-node',
'@vitest/browser',
'@vitest/coverage-c8',
'@vitest/coverage-istanbul',
'@vitest/expect',
'@vitest/runner',
'@vitest/snapshot',
'@vitest/spy',
'@vitest/ui',
'@vitest/utils',
'@vitest/web-worker',
'@vitest/ws-client',
]
4 changes: 2 additions & 2 deletions packages/vitest/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { ensurePackageInstalled } from '../pkg'
import { resolveApiServerConfig } from '../config'
import { Vitest } from '../core'
import { generateScopedClassName } from '../../integrations/css/css-modules'
import { vitestPackages } from '../../constants'
import { EnvReplacerPlugin } from './envReplacer'
import { GlobalSetupPlugin } from './globalSetup'
import { CSSEnablerPlugin } from './cssEnabler'
import { CoverageTransform } from './coverageTransform'
import { MocksPlugin } from './mocks'
import { resolveOptimizerConfig } from './utils'
import { VitestResolver } from './vitestResolver'

export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('test')): Promise<VitePlugin[]> {
const userConfig = deepMerge({}, options) as UserConfig
Expand Down Expand Up @@ -105,6 +105,7 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t
// 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: [],
dedupe: vitestPackages,
alias: testConfig.alias,
conditions: ['node'],
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
Expand Down Expand Up @@ -209,7 +210,6 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t
? await UIPlugin()
: null,
MocksPlugin(),
VitestResolver(ctx),
]
.filter(notNullish)
}
19 changes: 0 additions & 19 deletions packages/vitest/src/node/plugins/vitestResolver.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/vitest/src/node/plugins/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { generateScopedClassName } from '../../integrations/css/css-modules'
import { deepMerge } from '../../utils/base'
import type { WorkspaceProject } from '../workspace'
import type { UserWorkspaceConfig } from '../../types'
import { vitestPackages } from '../../constants'
import { CoverageTransform } from './coverageTransform'
import { CSSEnablerPlugin } from './cssEnabler'
import { EnvReplacerPlugin } from './envReplacer'
import { GlobalSetupPlugin } from './globalSetup'
import { MocksPlugin } from './mocks'
import { resolveOptimizerConfig } from './utils'
import { VitestResolver } from './vitestResolver'

interface WorkspaceOptions extends UserWorkspaceConfig {
root?: string
Expand Down Expand Up @@ -76,6 +76,7 @@ export function WorkspaceVitestPlugin(project: WorkspaceProject, options: Worksp
// setting this option can bypass that and fallback to cjs version
mainFields: [],
alias: testConfig.alias,
dedupe: vitestPackages,
conditions: ['node'],
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
// @ts-ignore we support Vite ^3.0, but browserField is available in Vite ^3.2
Expand Down Expand Up @@ -151,6 +152,5 @@ export function WorkspaceVitestPlugin(project: WorkspaceProject, options: Worksp
CoverageTransform(project.ctx),
GlobalSetupPlugin(project, project.ctx.logger),
MocksPlugin(),
VitestResolver(project.ctx),
]
}

0 comments on commit fd2a057

Please sign in to comment.