@@ -5,8 +5,8 @@ import type { Traces } from '../../utils/traces'
55import type { ExternalModulesExecutor } from '../external-executor'
66import type { CreateImportMeta } from './moduleRunner'
77import fs from 'node:fs'
8- import { isBuiltin } from 'node:module'
98import { isBareImport } from '@vitest/utils/helpers'
9+ import { isBrowserExternal , isBuiltin , toBuiltin } from '../../utils/modules'
1010import { getCachedVitestImport } from './cachedResolver'
1111import { listenForErrors } from './errorCatcher'
1212import { unwrapId , VitestModuleEvaluator } from './moduleEvaluator'
@@ -15,9 +15,6 @@ import { VitestModuleRunner } from './moduleRunner'
1515
1616const { readFileSync } = fs
1717
18- const browserExternalId = '__vite-browser-external'
19- const browserExternalLength = browserExternalId . length + 1 // 1 is ":"
20-
2118export const VITEST_VM_CONTEXT_SYMBOL : string = '__vitest_vm_context__'
2219
2320export interface ContextModuleRunnerOptions {
@@ -124,7 +121,11 @@ export function startVitestModuleRunner(options: ContextModuleRunnerOptions): Vi
124121 }
125122 }
126123
127- if ( isBuiltin ( rawId ) || rawId . startsWith ( browserExternalId ) ) {
124+ if ( isBuiltin ( rawId ) ) {
125+ return { externalize : rawId , type : 'builtin' }
126+ }
127+
128+ if ( isBrowserExternal ( rawId ) ) {
128129 return { externalize : toBuiltin ( rawId ) , type : 'builtin' }
129130 }
130131
@@ -184,14 +185,3 @@ export function startVitestModuleRunner(options: ContextModuleRunnerOptions): Vi
184185
185186 return moduleRunner
186187}
187-
188- export function toBuiltin ( id : string ) : string {
189- if ( id . startsWith ( browserExternalId ) ) {
190- id = id . slice ( browserExternalLength )
191- }
192-
193- if ( ! id . startsWith ( 'node:' ) ) {
194- id = `node:${ id } `
195- }
196- return id
197- }
0 commit comments