File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed
packages/plugin-rsc/src/plugins Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import * as esModuleLexer from 'es-module-lexer'
6
6
import { transformCjsToEsm } from '../transforms/cjs'
7
7
import { createDebug } from '@hiogawa/utils'
8
8
import { parseIdQuery } from './shared'
9
+ import { fileURLToPath , pathToFileURL } from 'node:url'
9
10
10
11
const debug = createDebug ( 'vite-rsc:cjs' )
11
12
@@ -62,6 +63,12 @@ export function cjsModuleRunnerPlugin(): Plugin[] {
62
63
export default module.exports;
63
64
export const __cjs_module_runner_transform = true;
64
65
` )
66
+ // https://github.com/vitest-dev/vitest/blob/965cefc19722a6c899cd1d3decb3cc33e72af696/packages/vite-node/src/client.ts#L548-L554
67
+ const __filename = fileURLToPath ( pathToFileURL ( id ) . href )
68
+ const __dirname = path . dirname ( __filename )
69
+ output . prepend (
70
+ `let __filename = ${ JSON . stringify ( __filename ) } ; let __dirname = ${ JSON . stringify ( __dirname ) } ;\n` ,
71
+ )
65
72
return {
66
73
code : output . toString ( ) ,
67
74
map : output . generateMap ( { hires : 'boundary' } ) ,
You can’t perform that action at this time.
0 commit comments