From 1ae35bb68241db1de1af446c2ad4e5e053f63f79 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Tue, 25 Jun 2024 15:59:28 -0600 Subject: [PATCH 1/3] fix: allow purge-on-delete with mdapi dirs --- messages/deploy.metadata.md | 8 +++++ src/commands/project/deploy/start.ts | 5 +-- .../destructive/destructiveChanges.nut.ts | 35 ++++++++++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/messages/deploy.metadata.md b/messages/deploy.metadata.md index b8800e6a..7e3f0074 100644 --- a/messages/deploy.metadata.md +++ b/messages/deploy.metadata.md @@ -64,6 +64,14 @@ To deploy multiple metadata components, either set multiple --metadata fl <%= config.bin %> <%= command.id %> --metadata ApexClass --test-level RunLocalTests +- Deploy all "metadata formatted" metadata in the "MDAPI" directory: + + <%= config.bin %> <%= command.id %> --metadata-dir MDAPI + +- Deploy all "metadata formatted" metadata in the "MDAPI" directory while hard deleting any items listed in MDAPI/destructiveChangesPre.xml or MDAPI/destructiveChangesPost.xml manifests: + + <%= config.bin %> <%= command.id %> --metadata-dir MDAPI --purge-on-delete + # flags.pre-destructive-changes.summary File path for a manifest (destructiveChangesPre.xml) of components to delete before the deploy. diff --git a/src/commands/project/deploy/start.ts b/src/commands/project/deploy/start.ts index cea36046..29f0998d 100644 --- a/src/commands/project/deploy/start.ts +++ b/src/commands/project/deploy/start.ts @@ -134,8 +134,9 @@ export default class DeployMetadata extends SfCommand { }), 'purge-on-delete': Flags.boolean({ summary: messages.getMessage('flags.purge-on-delete.summary'), - dependsOn: ['manifest'], - relationships: [{ type: 'some', flags: ['pre-destructive-changes', 'post-destructive-changes'] }], + relationships: [ + { type: 'some', flags: ['pre-destructive-changes', 'manifest', 'metadata-dir', 'post-destructive-changes'] }, + ], helpGroup: destructiveFlags, }), 'pre-destructive-changes': Flags.file({ diff --git a/test/nuts/destructive/destructiveChanges.nut.ts b/test/nuts/destructive/destructiveChanges.nut.ts index 364f9d9a..59656368 100644 --- a/test/nuts/destructive/destructiveChanges.nut.ts +++ b/test/nuts/destructive/destructiveChanges.nut.ts @@ -6,8 +6,9 @@ */ import * as path from 'node:path'; -import { writeFileSync } from 'node:fs'; +import fs, { writeFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; +import { join } from 'node:path'; import { assert, expect } from 'chai'; import { execCmd } from '@salesforce/cli-plugins-testkit'; import { SourceTestkit } from '@salesforce/source-testkit'; @@ -230,6 +231,38 @@ describe('project deploy start --destructive NUTs', () => { expect(preDeleted).to.be.true; expect(postDeleted).to.be.true; }); + + it('should delete a class in metadata api format with --purge-on-delete', async () => { + const pre = createApexClass('pre').apexName; + const post = createApexClass('post').apexName; + let preDeleted = await isNameObsolete(testkit.username, 'ApexClass', pre); + let postDeleted = await isNameObsolete(testkit.username, 'ApexClass', post); + + expect(preDeleted).to.be.false; + expect(postDeleted).to.be.false; + // convert file to deploy to MDAPI format + execCmd('project:convert:source --output-dir mdapi --metadata ApexClass:GeocodingService'); + + createManifest(`ApexClass:${post}`, 'post'); + createManifest(`ApexClass:${pre}`, 'pre'); + // move the destructive changes files into the mdapi dirt + fs.copyFileSync( + join(testkit.projectDir, 'destructiveChangesPre.xml'), + join(testkit.projectDir, 'mdapi', 'destructiveChangesPre.xml') + ); + fs.copyFileSync( + join(testkit.projectDir, 'destructiveChangesPost.xml'), + join(testkit.projectDir, 'mdapi', 'destructiveChangesPost.xml') + ); + execCmd('project:deploy:start --json --metadata-dir mdapi --purge-on-delete', { + ensureExitCode: 0, + }); + + preDeleted = await isNameObsolete(testkit.username, 'ApexClass', pre); + postDeleted = await isNameObsolete(testkit.username, 'ApexClass', post); + expect(preDeleted).to.be.true; + expect(postDeleted).to.be.true; + }); }); describe('errors', () => { From e9f03ffbdc74d317c520080792d85479c0c4bcd9 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Tue, 25 Jun 2024 16:01:26 -0600 Subject: [PATCH 2/3] chore: fix fs import --- test/nuts/destructive/destructiveChanges.nut.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/nuts/destructive/destructiveChanges.nut.ts b/test/nuts/destructive/destructiveChanges.nut.ts index 59656368..c3115b17 100644 --- a/test/nuts/destructive/destructiveChanges.nut.ts +++ b/test/nuts/destructive/destructiveChanges.nut.ts @@ -6,7 +6,7 @@ */ import * as path from 'node:path'; -import fs, { writeFileSync } from 'node:fs'; +import { copyFileSync, writeFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { join } from 'node:path'; import { assert, expect } from 'chai'; @@ -246,11 +246,11 @@ describe('project deploy start --destructive NUTs', () => { createManifest(`ApexClass:${post}`, 'post'); createManifest(`ApexClass:${pre}`, 'pre'); // move the destructive changes files into the mdapi dirt - fs.copyFileSync( + copyFileSync( join(testkit.projectDir, 'destructiveChangesPre.xml'), join(testkit.projectDir, 'mdapi', 'destructiveChangesPre.xml') ); - fs.copyFileSync( + copyFileSync( join(testkit.projectDir, 'destructiveChangesPost.xml'), join(testkit.projectDir, 'mdapi', 'destructiveChangesPost.xml') ); From f4d1c635d042caf3b1d000f5275a6789ddb7ca08 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Wed, 26 Jun 2024 08:43:06 -0600 Subject: [PATCH 3/3] docs: update messages --- messages/deploy.metadata.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/messages/deploy.metadata.md b/messages/deploy.metadata.md index 7e3f0074..a35d1579 100644 --- a/messages/deploy.metadata.md +++ b/messages/deploy.metadata.md @@ -64,11 +64,11 @@ To deploy multiple metadata components, either set multiple --metadata fl <%= config.bin %> <%= command.id %> --metadata ApexClass --test-level RunLocalTests -- Deploy all "metadata formatted" metadata in the "MDAPI" directory: +- Deploy all metadata formatted files in the "MDAPI" directory: <%= config.bin %> <%= command.id %> --metadata-dir MDAPI -- Deploy all "metadata formatted" metadata in the "MDAPI" directory while hard deleting any items listed in MDAPI/destructiveChangesPre.xml or MDAPI/destructiveChangesPost.xml manifests: +- Deploy all metadata formatted files in the "MDAPI" directory; items listed in the MDAPI/destructiveChangesPre.xml and MDAPI/destructiveChangesPost.xml manifests are immediately eligible for deletion rather than stored in the Recycle Bin: <%= config.bin %> <%= command.id %> --metadata-dir MDAPI --purge-on-delete