@@ -10,9 +10,10 @@ import { Readable } from 'node:stream';
10
10
import { statSync , existsSync , readdirSync , createReadStream , readFileSync } from 'graceful-fs' ;
11
11
import * as JSZip from 'jszip' ;
12
12
import { Messages , SfError } from '@salesforce/core' ;
13
- import { baseName , parseMetadataXml } from '../utils' ;
14
- import { SourcePath } from '../common' ;
15
- import { VirtualDirectory } from './types' ;
13
+ import { isString } from '@salesforce/ts-types' ;
14
+ import { baseName , parseMetadataXml } from '../utils/path' ;
15
+ import type { SourcePath } from '../common/types' ;
16
+ import type { VirtualDirectory } from './types' ;
16
17
17
18
Messages . importMessagesDirectory ( __dirname ) ;
18
19
const messages = Messages . loadMessages ( '@salesforce/source-deploy-retrieve' , 'sdr' ) ;
@@ -241,18 +242,23 @@ export class VirtualTreeContainer extends TreeContainer {
241
242
public static fromFilePaths ( paths : string [ ] ) : VirtualTreeContainer {
242
243
// a map to reduce array iterations
243
244
const virtualDirectoryByFullPath = new Map < string , VirtualDirectory > ( ) ;
244
- paths . map ( ( filename ) => {
245
- const splits = filename . split ( sep ) ;
246
- for ( let i = 0 ; i < splits . length - 1 ; i ++ ) {
247
- const fullPathSoFar = splits . slice ( 0 , i + 1 ) . join ( sep ) ;
248
- const existing = virtualDirectoryByFullPath . get ( fullPathSoFar ) ;
249
- virtualDirectoryByFullPath . set ( fullPathSoFar , {
250
- dirPath : fullPathSoFar ,
251
- // only add to children if we don't already have it
252
- children : Array . from ( new Set ( existing ?. children ?? [ ] ) . add ( splits [ i + 1 ] ) ) ,
253
- } ) ;
254
- }
255
- } ) ;
245
+ paths
246
+ . filter (
247
+ // defending against undefined being passed in. The metadata API sometimes responds missing fileName
248
+ isString
249
+ )
250
+ . map ( ( filename ) => {
251
+ const splits = filename . split ( sep ) ;
252
+ for ( let i = 0 ; i < splits . length - 1 ; i ++ ) {
253
+ const fullPathSoFar = splits . slice ( 0 , i + 1 ) . join ( sep ) ;
254
+ const existing = virtualDirectoryByFullPath . get ( fullPathSoFar ) ;
255
+ virtualDirectoryByFullPath . set ( fullPathSoFar , {
256
+ dirPath : fullPathSoFar ,
257
+ // only add to children if we don't already have it
258
+ children : Array . from ( new Set ( existing ?. children ?? [ ] ) . add ( splits [ i + 1 ] ) ) ,
259
+ } ) ;
260
+ }
261
+ } ) ;
256
262
return new VirtualTreeContainer ( Array . from ( virtualDirectoryByFullPath . values ( ) ) ) ;
257
263
}
258
264
0 commit comments