1
+ // runtime client should be lightweight so we import only the bare minimum
2
+ // for this we also have a separate utils file for shared utils
3
+
1
4
import { fileURLToPath , pathToFileURL } from 'node:url'
2
5
import { createRequire } from 'node:module'
3
6
import { dirname , resolve } from 'node:path'
@@ -8,6 +11,7 @@ import {
8
11
CLIENT_PUBLIC_PATH ,
9
12
ENV_PUBLIC_PATH ,
10
13
VALID_ID_PREFIX ,
14
+ VITE_SOURCEMAPPING_URL ,
11
15
} from '../constants'
12
16
import {
13
17
cleanUrl ,
@@ -18,7 +22,17 @@ import {
18
22
toFilePath ,
19
23
} from '../utils/shared'
20
24
import type { FetchModuleResult } from './ssrFetchModule'
21
- import { extractSourceMap } from './ssrSourceMap'
25
+
26
+ const VITE_SOURCEMAPPING_REGEXP = new RegExp (
27
+ `//# ${ VITE_SOURCEMAPPING_URL } ;base64,(.+)` ,
28
+ )
29
+
30
+ export function extractSourceMap ( code : string ) : SourceMap | null {
31
+ const mapString = code . match ( VITE_SOURCEMAPPING_REGEXP ) ?. [ 1 ]
32
+ if ( mapString )
33
+ return JSON . parse ( Buffer . from ( mapString , 'base64' ) . toString ( 'utf-8' ) )
34
+ return null
35
+ }
22
36
23
37
// const debugExecute = createDebug('vite-runtime:client:execute')
24
38
// const debugNative = createDebug('vite-runtime:client:native')
@@ -562,7 +576,12 @@ function exportAll(exports: any, sourceModule: any) {
562
576
563
577
// we don't want to have "string" to be made into {0:"s",1:"t",2:"r",3:"i",4:"n",5:"g"}
564
578
// the same goes for arrays: [1,2,3] -> {0:1,1:2,2:3}
565
- if ( isPrimitive ( sourceModule ) || Array . isArray ( sourceModule ) ) return
579
+ if (
580
+ isPrimitive ( sourceModule ) ||
581
+ Array . isArray ( sourceModule ) ||
582
+ sourceModule instanceof Promise
583
+ )
584
+ return
566
585
567
586
for ( const key in sourceModule ) {
568
587
if ( key !== 'default' ) {
0 commit comments