Skip to content

Commit eb87eb7

Browse files
committed
feat: delete handling public for pull
1 parent c83bd7e commit eb87eb7

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

src/sourceTracking.ts

+44-44
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,50 @@ export class SourceTracking extends AsyncCreatable {
300300
return [];
301301
}
302302

303+
/**
304+
*
305+
* returns immediately if there are no changesToDelete
306+
*
307+
* @param changesToDelete array of SourceComponent
308+
*/
309+
public async deleteFilesAndUpdateTracking(changesToDelete: SourceComponent[]): Promise<FileResponse[]> {
310+
if (changesToDelete.length === 0) {
311+
return [];
312+
}
313+
314+
const sourceComponentByFileName = new Map<string, SourceComponent>();
315+
changesToDelete.flatMap((component) =>
316+
[component.xml as string, ...component.walkContent()]
317+
.filter((filename) => filename)
318+
.map((filename) => sourceComponentByFileName.set(filename, component))
319+
);
320+
const filenames = Array.from(sourceComponentByFileName.keys());
321+
// delete the files
322+
await Promise.all(filenames.map((filename) => fs.promises.unlink(filename)));
323+
324+
// update the tracking files. We're simulating SDR-style fileResponse
325+
await Promise.all([
326+
this.updateLocalTracking({ deletedFiles: filenames }),
327+
this.updateRemoteTracking(
328+
changesToDelete.map((component) => ({
329+
type: component.type.name,
330+
fullName: component.fullName,
331+
state: ComponentStatus.Deleted,
332+
})),
333+
true // skip polling because it's a pull
334+
),
335+
]);
336+
return filenames.map(
337+
(filename) =>
338+
({
339+
state: 'Deleted',
340+
filename,
341+
type: sourceComponentByFileName.get(filename)?.type.name,
342+
fullName: sourceComponentByFileName.get(filename)?.fullName,
343+
} as unknown as FileResponse)
344+
);
345+
}
346+
303347
/**
304348
* Update tracking for the options passed.
305349
*
@@ -578,50 +622,6 @@ export class SourceTracking extends AsyncCreatable {
578622
const projectConfig = await this.project.resolveProjectConfig();
579623
return getString(projectConfig, 'sourceApiVersion') ?? undefined;
580624
}
581-
582-
/**
583-
*
584-
* returns immediately if there are no changesToDelete
585-
*
586-
* @param changesToDelete array of SourceComponent
587-
*/
588-
private async deleteFilesAndUpdateTracking(changesToDelete: SourceComponent[]): Promise<FileResponse[]> {
589-
if (changesToDelete.length === 0) {
590-
return [];
591-
}
592-
593-
const sourceComponentByFileName = new Map<string, SourceComponent>();
594-
changesToDelete.flatMap((component) =>
595-
[component.xml as string, ...component.walkContent()]
596-
.filter((filename) => filename)
597-
.map((filename) => sourceComponentByFileName.set(filename, component))
598-
);
599-
const filenames = Array.from(sourceComponentByFileName.keys());
600-
// delete the files
601-
await Promise.all(filenames.map((filename) => fs.promises.unlink(filename)));
602-
603-
// update the tracking files. We're simulating SDR-style fileResponse
604-
await Promise.all([
605-
this.updateLocalTracking({ deletedFiles: filenames }),
606-
this.updateRemoteTracking(
607-
changesToDelete.map((component) => ({
608-
type: component.type.name,
609-
fullName: component.fullName,
610-
state: ComponentStatus.Deleted,
611-
})),
612-
true // skip polling because it's a pull
613-
),
614-
]);
615-
return filenames.map(
616-
(filename) =>
617-
({
618-
state: 'Deleted',
619-
filename,
620-
type: sourceComponentByFileName.get(filename)?.type.name,
621-
fullName: sourceComponentByFileName.get(filename)?.fullName,
622-
} as unknown as FileResponse)
623-
);
624-
}
625625
}
626626

627627
export const stringGuard = (input: string | undefined): input is string => {

0 commit comments

Comments
 (0)