@@ -15,16 +15,34 @@ type SourceMap struct {
1515 SourcesContent []string `json:"sourcesContent"`
1616}
1717
18+ func filenamifyOpts (options * filenamify.Options ) {
19+ options .Replacement = "_"
20+ }
21+
22+ func pathify (path string ) (string , error ) {
23+ var result string
24+ for _ , part := range strings .Split (filepath .Clean (path ), string (os .PathSeparator )) {
25+ filename , err := filenamify .FilenamifyV2 (part , filenamifyOpts )
26+ if err != nil {
27+ return "" , err
28+ }
29+
30+ result = filepath .Join (result , filename )
31+ }
32+
33+ return result , nil
34+ }
35+
1836func fromSourceMap (ctx Context , res * http.Response ) {
19- info (ctx .Depth , "Processing source map..." )
37+ Info (ctx .Depth , "Processing source map..." )
2038
2139 var sourceMap SourceMap
2240 if err := json .NewDecoder (res .Body ).Decode (& sourceMap ); err != nil {
23- error (ctx .Depth , "Failed to parse source map:" , err )
41+ Error (ctx .Depth , "Failed to parse source map:" , err )
2442 return
2543 }
2644
27- info (ctx .Depth , "Unpacking" , len (sourceMap .Sources ), "sources..." )
45+ Info (ctx .Depth , "Unpacking" , len (sourceMap .Sources ), "sources..." )
2846 ctx .Depth ++
2947
3048 for index , source := range sourceMap .Sources {
@@ -45,26 +63,22 @@ func fromSourceMap(ctx Context, res *http.Response) {
4563 }
4664
4765 // remove reserved characters
48- source , err := filenamify .FilenamifyV2 (source , func (options * filenamify.Options ) {
49- options .Replacement = "_"
50- })
51-
66+ relPath , err := pathify (source )
5267 if err != nil {
53- error (ctx .Depth , "Failed to filenamify source :" , err )
68+ Error (ctx .Depth , "Failed to normalize pathname :" , err )
5469 continue
5570 }
5671
57- path := filepath .Join (filepath . Clean ( ctx .Dir ), source )
72+ path := filepath .Join (ctx .Dir , relPath )
5873 dir := filepath .Dir (path )
59-
6074 if err := os .MkdirAll (dir , os .ModePerm ); err != nil {
61- error (ctx .Depth , "Failed to create source directory:" , err )
75+ Error (ctx .Depth , "Failed to create source directory:" , err )
6276 continue
6377 }
6478
6579 content := sourceMap .SourcesContent [index ]
6680 if err := os .WriteFile (path , []byte (content ), os .ModePerm ); err != nil {
67- error (ctx .Depth , "Failed to write source file:" , err )
81+ Error (ctx .Depth , "Failed to write source file:" , err )
6882 continue
6983 }
7084 }
0 commit comments