11import type { WorkerGlobalState } from '../../types/worker'
22import { pathToFileURL } from 'node:url'
3+ import { splitFileAndPostfix } from '@vitest/utils/helpers'
34import { join , normalize } from 'pathe'
45import { distDir } from '../../paths'
56
@@ -25,9 +26,10 @@ export function getCachedVitestImport(
2526 const root = state ( ) . config . root
2627 const relativeRoot = relativeIds [ root ] ?? ( relativeIds [ root ] = normalizedDistDir . slice ( root . length ) )
2728 if ( id . includes ( distDir ) || id . includes ( normalizedDistDir ) ) {
29+ const { file, postfix } = splitFileAndPostfix ( id )
2830 const externalize = id . startsWith ( 'file://' )
2931 ? id
30- : pathToFileURL ( id ) . toString ( )
32+ : ` ${ pathToFileURL ( file ) } ${ postfix } `
3133 externalizeMap . set ( id , externalize )
3234 return { externalize, type : 'module' }
3335 }
@@ -36,8 +38,9 @@ export function getCachedVitestImport(
3638 // /node_modules/.pnpm/vitest/dist
3739 ( relativeRoot && relativeRoot !== '/' && id . startsWith ( relativeRoot ) )
3840 ) {
39- const path = join ( root , id )
40- const externalize = pathToFileURL ( path ) . toString ( )
41+ const { file, postfix } = splitFileAndPostfix ( id )
42+ const path = join ( root , file )
43+ const externalize = `${ pathToFileURL ( path ) } ${ postfix } `
4144 externalizeMap . set ( id , externalize )
4245 return { externalize, type : 'module' }
4346 }
0 commit comments