File tree 7 files changed +37
-40
lines changed 7 files changed +37
-40
lines changed Original file line number Diff line number Diff line change @@ -439,7 +439,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
439
439
const getContentWithSourcemap = async ( content : string ) => {
440
440
if ( config . css ?. devSourcemap ) {
441
441
const sourcemap = this . getCombinedSourcemap ( )
442
- if ( sourcemap . mappings && ! sourcemap . sourcesContent ) {
442
+ if ( sourcemap . mappings ) {
443
443
await injectSourcesContent ( sourcemap , cleanUrl ( id ) , config . logger )
444
444
}
445
445
return getCodeWithSourcemap ( 'css' , content , sourcemap )
Original file line number Diff line number Diff line change @@ -652,11 +652,10 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
652
652
source : chunk . fileName ,
653
653
hires : true ,
654
654
} )
655
- const map = combineSourcemaps (
656
- chunk . fileName ,
657
- [ nextMap as RawSourceMap , chunk . map as RawSourceMap ] ,
658
- false ,
659
- ) as SourceMap
655
+ const map = combineSourcemaps ( chunk . fileName , [
656
+ nextMap as RawSourceMap ,
657
+ chunk . map as RawSourceMap ,
658
+ ] ) as SourceMap
660
659
map . toUrl = ( ) => genSourceMapUrl ( map )
661
660
chunk . map = map
662
661
Original file line number Diff line number Diff line change @@ -283,7 +283,7 @@ const devHtmlHook: IndexHtmlTransformHook = async (
283
283
let content = ''
284
284
if ( result ) {
285
285
if ( result . map ) {
286
- if ( result . map . mappings && ! result . map . sourcesContent ) {
286
+ if ( result . map . mappings ) {
287
287
await injectSourcesContent (
288
288
result . map ,
289
289
proxyModulePath ,
Original file line number Diff line number Diff line change @@ -33,22 +33,29 @@ export async function injectSourcesContent(
33
33
} catch { }
34
34
35
35
const missingSources : string [ ] = [ ]
36
- map . sourcesContent = await Promise . all (
37
- map . sources . map ( ( sourcePath ) => {
36
+ const sourcesContent = map . sourcesContent || [ ]
37
+ await Promise . all (
38
+ map . sources . map ( async ( sourcePath , index ) => {
39
+ let content = null
38
40
if ( sourcePath && ! virtualSourceRE . test ( sourcePath ) ) {
39
41
sourcePath = decodeURI ( sourcePath )
40
42
if ( sourceRoot ) {
41
43
sourcePath = path . resolve ( sourceRoot , sourcePath )
42
44
}
43
- return fsp . readFile ( sourcePath , 'utf-8' ) . catch ( ( ) => {
44
- missingSources . push ( sourcePath )
45
- return null
46
- } )
45
+ // inject content from source file when sourcesContent is null
46
+ content =
47
+ sourcesContent [ index ] ??
48
+ ( await fsp . readFile ( sourcePath , 'utf-8' ) . catch ( ( ) => {
49
+ missingSources . push ( sourcePath )
50
+ return null
51
+ } ) )
47
52
}
48
- return null
53
+ sourcesContent [ index ] = content
49
54
} ) ,
50
55
)
51
56
57
+ map . sourcesContent = sourcesContent
58
+
52
59
// Use this command…
53
60
// DEBUG="vite:sourcemap" vite build
54
61
// …to log the missing sources.
Original file line number Diff line number Diff line change @@ -285,7 +285,7 @@ async function loadAndTransform(
285
285
286
286
if ( map && mod . file ) {
287
287
map = ( typeof map === 'string' ? JSON . parse ( map ) : map ) as SourceMap
288
- if ( map . mappings && ! map . sourcesContent ) {
288
+ if ( map . mappings ) {
289
289
await injectSourcesContent ( map , mod . file , logger )
290
290
}
291
291
Original file line number Diff line number Diff line change @@ -276,18 +276,14 @@ async function ssrTransformScript(
276
276
277
277
let map = s . generateMap ( { hires : true } )
278
278
if ( inMap && inMap . mappings && inMap . sources . length > 0 ) {
279
- map = combineSourcemaps (
280
- url ,
281
- [
282
- {
283
- ...map ,
284
- sources : inMap . sources ,
285
- sourcesContent : inMap . sourcesContent ,
286
- } as RawSourceMap ,
287
- inMap as RawSourceMap ,
288
- ] ,
289
- false ,
290
- ) as SourceMap
279
+ map = combineSourcemaps ( url , [
280
+ {
281
+ ...map ,
282
+ sources : inMap . sources ,
283
+ sourcesContent : inMap . sourcesContent ,
284
+ } as RawSourceMap ,
285
+ inMap as RawSourceMap ,
286
+ ] ) as SourceMap
291
287
} else {
292
288
map . sources = [ path . basename ( url ) ]
293
289
// needs to use originalCode instead of code
Original file line number Diff line number Diff line change @@ -748,7 +748,6 @@ const nullSourceMap: RawSourceMap = {
748
748
export function combineSourcemaps (
749
749
filename : string ,
750
750
sourcemapList : Array < DecodedSourceMap | RawSourceMap > ,
751
- excludeContent = true ,
752
751
) : RawSourceMap {
753
752
if (
754
753
sourcemapList . length === 0 ||
@@ -778,19 +777,15 @@ export function combineSourcemaps(
778
777
const useArrayInterface =
779
778
sourcemapList . slice ( 0 , - 1 ) . find ( ( m ) => m . sources . length !== 1 ) === undefined
780
779
if ( useArrayInterface ) {
781
- map = remapping ( sourcemapList , ( ) => null , excludeContent )
780
+ map = remapping ( sourcemapList , ( ) => null )
782
781
} else {
783
- map = remapping (
784
- sourcemapList [ 0 ] ,
785
- function loader ( sourcefile ) {
786
- if ( sourcefile === escapedFilename && sourcemapList [ mapIndex ] ) {
787
- return sourcemapList [ mapIndex ++ ]
788
- } else {
789
- return null
790
- }
791
- } ,
792
- excludeContent ,
793
- )
782
+ map = remapping ( sourcemapList [ 0 ] , function loader ( sourcefile ) {
783
+ if ( sourcefile === escapedFilename && sourcemapList [ mapIndex ] ) {
784
+ return sourcemapList [ mapIndex ++ ]
785
+ } else {
786
+ return null
787
+ }
788
+ } )
794
789
}
795
790
if ( ! map . file ) {
796
791
delete map . file
You can’t perform that action at this time.
0 commit comments