@@ -24,6 +24,7 @@ import {
24
24
ScopedPostDeploy ,
25
25
RetrieveResult ,
26
26
RegistryAccess ,
27
+ FileResponseSuccess ,
27
28
} from '@salesforce/source-deploy-retrieve' ;
28
29
// this is not exported by SDR (see the comments in SDR regarding its limitations)
29
30
import { filePathsFromMetadataComponent } from '@salesforce/source-deploy-retrieve/lib/src/utils/filePathGenerator' ;
@@ -40,7 +41,7 @@ import {
40
41
RemoteChangeElement ,
41
42
} from './shared/types' ;
42
43
import { sourceComponentGuard } from './shared/guards' ;
43
- import { supportsPartialDelete , pathIsInFolder , ensureRelative } from './shared/functions' ;
44
+ import { supportsPartialDelete , pathIsInFolder , ensureRelative , deleteCustomLabels } from './shared/functions' ;
44
45
import { registrySupportsType } from './shared/metadataKeys' ;
45
46
import { populateFilePaths } from './shared/populateFilePaths' ;
46
47
import { populateTypesAndNames } from './shared/populateTypesAndNames' ;
@@ -348,9 +349,33 @@ export class SourceTracking extends AsyncCreatable {
348
349
. filter ( ( filename ) => filename )
349
350
. map ( ( filename ) => sourceComponentByFileName . set ( filename , component ) )
350
351
) ;
352
+
353
+ // calculate what to return before we delete any files and .walkContent is no longer valid
354
+ const changedToBeDeleted = changesToDelete . flatMap ( ( component ) =>
355
+ [ ...component . walkContent ( ) , component . xml ] . map (
356
+ ( file ) : FileResponseSuccess => ( {
357
+ state : ComponentStatus . Deleted ,
358
+ filePath : file ,
359
+ type : component . type . name ,
360
+ fullName : component . fullName ,
361
+ } )
362
+ )
363
+ ) ;
364
+
351
365
const filenames = Array . from ( sourceComponentByFileName . keys ( ) ) ;
352
366
// delete the files
353
- await Promise . all ( filenames . map ( ( filename ) => fs . promises . unlink ( filename ) ) ) ;
367
+ await Promise . all (
368
+ filenames . map ( async ( filename ) => {
369
+ if ( sourceComponentByFileName . get ( filename ) ?. type . id === 'customlabel' ) {
370
+ await deleteCustomLabels (
371
+ filename ,
372
+ changesToDelete . filter ( ( c ) => c . type . id === 'customlabel' )
373
+ ) ;
374
+ } else {
375
+ return fs . promises . unlink ( filename ) ;
376
+ }
377
+ } )
378
+ ) ;
354
379
355
380
// update the tracking files. We're simulating SDR-style fileResponse
356
381
await Promise . all ( [
@@ -364,19 +389,7 @@ export class SourceTracking extends AsyncCreatable {
364
389
true // skip polling because it's a pull
365
390
) ,
366
391
] ) ;
367
- return filenames . reduce < FileResponse [ ] > ( ( result , filename ) => {
368
- const component = sourceComponentByFileName . get ( filename ) ;
369
- if ( component ) {
370
- result . push ( {
371
- state : ComponentStatus . Deleted ,
372
- filePath : filename ,
373
- type : component . type . name ,
374
- fullName : component . fullName ,
375
- } ) ;
376
- }
377
-
378
- return result ;
379
- } , [ ] ) ;
392
+ return changedToBeDeleted ;
380
393
}
381
394
382
395
/**
0 commit comments