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'
66import { transformCjsToEsm } from '../transforms/cjs'
77import { createDebug } from '@hiogawa/utils'
88import { parseIdQuery } from './shared'
9+ import { fileURLToPath , pathToFileURL } from 'node:url'
910
1011const debug = createDebug ( 'vite-rsc:cjs' )
1112
@@ -62,6 +63,12 @@ export function cjsModuleRunnerPlugin(): Plugin[] {
6263export default module.exports;
6364export const __cjs_module_runner_transform = true;
6465` )
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+ )
6572 return {
6673 code : output . toString ( ) ,
6774 map : output . generateMap ( { hires : 'boundary' } ) ,
You can’t perform that action at this time.
0 commit comments