@@ -27,7 +27,9 @@ export const getShortestUniqueFilePaths = (originalFilePaths: string[]): string[
2727 // Split each original file path into path segments and store the mapping from file
2828 // path to path segments for O(1) lookup. Since we only deal with the BrowserFS file
2929 // system, the path separator will always be '/'.
30- const filePathSegments : Record < string , string [ ] > = originalFilePaths . reduce (
30+ const filePathSegments : Record < string , string [ ] > = originalFilePaths . reduce <
31+ typeof filePathSegments
32+ > (
3133 ( segments , filePath ) => ( {
3234 ...segments ,
3335 // It is necessary to remove empty segments to deal with the very first '/' in
@@ -48,15 +50,18 @@ export const getShortestUniqueFilePaths = (originalFilePaths: string[]): string[
4850 // to any original file path which transforms into it.
4951 const shortenedToOriginalFilePaths : Record < string , string [ ] > = Object . entries (
5052 filePathSegments
51- ) . reduce ( ( filePaths , [ originalFilePath , filePathSegments ] ) => {
52- // Note that if there are fewer path segments than the number being sliced,
53- // all of the path segments will be returned without error.
54- const shortenedFilePath = '/' + filePathSegments . slice ( - numOfPathSegments ) . join ( '/' ) ;
55- return {
56- ...filePaths ,
57- [ shortenedFilePath ] : ( filePaths [ shortenedFilePath ] ?? [ ] ) . concat ( originalFilePath )
58- } ;
59- } , { } ) ;
53+ ) . reduce < typeof shortenedToOriginalFilePaths > (
54+ ( filePaths , [ originalFilePath , filePathSegments ] ) => {
55+ // Note that if there are fewer path segments than the number being sliced,
56+ // all of the path segments will be returned without error.
57+ const shortenedFilePath = '/' + filePathSegments . slice ( - numOfPathSegments ) . join ( '/' ) ;
58+ return {
59+ ...filePaths ,
60+ [ shortenedFilePath ] : ( filePaths [ shortenedFilePath ] ?? [ ] ) . concat ( originalFilePath )
61+ } ;
62+ } ,
63+ { }
64+ ) ;
6065 // Each shortened file path that only has a single corresponding original file
6166 // path is added to the unique shortened file paths record and their entry in
6267 // the file path segments record is removed to prevent further processing.
0 commit comments