Skip to content

Commit f084fb0

Browse files
fix: pull all deleted CLs will delete file (#391)
* fix: pull all deleted CLs will delete file * refactor: remove reduce (#392) --------- Co-authored-by: Shane McLaughlin <shane.mclaughlin@salesforce.com>
1 parent e931074 commit f084fb0

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"dependencies": {
4646
"@salesforce/core": "^3.36.1",
4747
"@salesforce/kit": "^1.9.2",
48-
"@salesforce/source-deploy-retrieve": "^8.4.0",
48+
"@salesforce/source-deploy-retrieve": "^8.5.1",
4949
"fast-xml-parser": "^4.2.2",
5050
"graceful-fs": "^4.2.11",
5151
"isomorphic-git": "1.23.0",
@@ -160,4 +160,4 @@
160160
"output": []
161161
}
162162
}
163-
}
163+
}

src/sourceTracking.ts

+28-15
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
ScopedPostDeploy,
2525
RetrieveResult,
2626
RegistryAccess,
27+
FileResponseSuccess,
2728
} from '@salesforce/source-deploy-retrieve';
2829
// this is not exported by SDR (see the comments in SDR regarding its limitations)
2930
import { filePathsFromMetadataComponent } from '@salesforce/source-deploy-retrieve/lib/src/utils/filePathGenerator';
@@ -40,7 +41,7 @@ import {
4041
RemoteChangeElement,
4142
} from './shared/types';
4243
import { sourceComponentGuard } from './shared/guards';
43-
import { supportsPartialDelete, pathIsInFolder, ensureRelative } from './shared/functions';
44+
import { supportsPartialDelete, pathIsInFolder, ensureRelative, deleteCustomLabels } from './shared/functions';
4445
import { registrySupportsType } from './shared/metadataKeys';
4546
import { populateFilePaths } from './shared/populateFilePaths';
4647
import { populateTypesAndNames } from './shared/populateTypesAndNames';
@@ -348,9 +349,33 @@ export class SourceTracking extends AsyncCreatable {
348349
.filter((filename) => filename)
349350
.map((filename) => sourceComponentByFileName.set(filename, component))
350351
);
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+
351365
const filenames = Array.from(sourceComponentByFileName.keys());
352366
// 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+
);
354379

355380
// update the tracking files. We're simulating SDR-style fileResponse
356381
await Promise.all([
@@ -364,19 +389,7 @@ export class SourceTracking extends AsyncCreatable {
364389
true // skip polling because it's a pull
365390
),
366391
]);
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;
380393
}
381394

382395
/**

yarn.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@
890890
strip-ansi "6.0.1"
891891
ts-retry-promise "^0.7.0"
892892

893-
"@salesforce/core@^3.34.6", "@salesforce/core@^3.34.8", "@salesforce/core@^3.36.0", "@salesforce/core@^3.36.1":
893+
"@salesforce/core@^3.34.6", "@salesforce/core@^3.34.8", "@salesforce/core@^3.36.1":
894894
version "3.36.1"
895895
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.36.1.tgz#053a5e1079b9749b62e461e6ac3e630b5689694a"
896896
integrity sha512-kcjyr9bj35nnL8Bqv8U39xeho3CrZYXJiS/X5X1eEHVNZLd9zckrmKrh1V7z8ElCFpsJrewT989SJsdvi9kE8w==
@@ -975,12 +975,12 @@
975975
resolved "https://registry.yarnpkg.com/@salesforce/schemas/-/schemas-1.5.1.tgz#2d1bfdcf593caaa04cd4b3e6fe621097ff7f28fe"
976976
integrity sha512-MRqU+tn8w5IFvZ0Lm9YKLgxYxr2MQMI+fXXsTrwfUnijsps+ybF9IOTu6MOMxxl2vCUkO8XDjA435wXlWSLI6g==
977977

978-
"@salesforce/source-deploy-retrieve@^8.4.0":
979-
version "8.4.0"
980-
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-8.4.0.tgz#10cadb7a02dc4657c5b941161b30a5017dabd788"
981-
integrity sha512-eAOuhmbNAMoJdvhdzF1cBtqNIG/WhLR/GRCA89wevvPLidCdzMNzNGPUQWO0N+PSVWskRbbNeZG3n9ws4SV1vA==
978+
"@salesforce/source-deploy-retrieve@^8.5.1":
979+
version "8.5.1"
980+
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-8.5.1.tgz#f66f590348857aa51e11fdb69dbd9fcf1d2fba93"
981+
integrity sha512-bdbyLlpILlGiNzsqrZjOEu3rtp3pqQyPzixL2CA9UebKGytG6zT3J6+/0Br1jAVefbl62KW6dgwurAVL7bp6+w==
982982
dependencies:
983-
"@salesforce/core" "^3.36.0"
983+
"@salesforce/core" "^3.36.1"
984984
"@salesforce/kit" "^1.9.2"
985985
"@salesforce/ts-types" "^1.7.2"
986986
archiver "^5.3.1"

0 commit comments

Comments
 (0)