Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/commands/project/delete/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { resolveApi, validateTests } from '../../../utils/deploy.js';
import { DeployResultFormatter } from '../../../formatters/deployResultFormatter.js';
import { DeleteResultFormatter } from '../../../formatters/deleteResultFormatter.js';
import { DeployCache } from '../../../utils/deployCache.js';
import { testLevelFlag, testsFlag } from '../../../utils/flags.js';
import { isPseudoType, testLevelFlag, testsFlag } from '../../../utils/flags.js';
const testFlags = 'Test';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
Expand Down Expand Up @@ -163,8 +163,10 @@ export class Source extends SfCommand<DeleteSourceJson> {
}
}

// eslint-disable-next-line complexity
protected async delete(): Promise<void> {
const sourcepaths = this.flags['source-dir'];
const resolveFromOrg = this.flags.metadata?.some(isPseudoType) ? this.flags['target-org'].getUsername() : undefined;

this.componentSet = await ComponentSetBuilder.build({
apiversion: this.flags['api-version'],
Expand All @@ -177,7 +179,18 @@ export class Source extends SfCommand<DeleteSourceJson> {
}
: undefined,
projectDir: this.project?.getPath(),
...(resolveFromOrg ? { org: { username: resolveFromOrg, exclude: [] } } : {}),
});

// If we built a component set from an org connection, we have to resolve
// components from the project.
if (resolveFromOrg) {
this.componentSet = ComponentSet.fromSource({
fsPaths: await getPackageDirs(),
include: this.componentSet,
});
}

if (this.flags['track-source'] && !this.flags['force-overwrite']) {
await this.filterConflictsByComponentSet();
}
Expand Down
4 changes: 1 addition & 3 deletions src/commands/project/retrieve/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { SourceTracking, SourceConflictError } from '@salesforce/source-tracking
import { Duration } from '@salesforce/kit';
import { Interfaces } from '@oclif/core';

import { DEFAULT_ZIP_FILE_NAME, ensuredDirFlag, zipFileFlag } from '../../../utils/flags.js';
import { DEFAULT_ZIP_FILE_NAME, ensuredDirFlag, isPseudoType, zipFileFlag } from '../../../utils/flags.js';
import { RetrieveResultFormatter } from '../../../formatters/retrieveResultFormatter.js';
import { MetadataRetrieveResultFormatter } from '../../../formatters/metadataRetrieveResultFormatter.js';
import { getOptionalProject, getPackageDirs } from '../../../utils/project.js';
Expand Down Expand Up @@ -512,5 +512,3 @@ const isRegexMatch = (mdEntry: string): boolean => {
const mdName = mdEntry.split(':')[1];
return mdName?.includes('*') && mdName?.length > 1 && !mdName?.includes('.*');
};

const isPseudoType = (mdEntry: string): boolean => mdEntry.split(':')[0] === 'Agent';
6 changes: 6 additions & 0 deletions src/utils/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,9 @@ const commaWarningForMultipleFlags = async (input: string, warningText: string):
}
return input;
};

/**
* Returns `true` if the metadata entry (e.g., --metadata) contains a pseudo type
* such as "Agent" or "Agent:My_Agent".
*/
export const isPseudoType = (mdEntry: string): boolean => mdEntry.split(':')[0] === 'Agent';
22 changes: 22 additions & 0 deletions test/commands/delete/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ describe('project delete source', () => {
let lifecycleEmitStub: sinon.SinonStub;
let resolveProjectConfigStub: sinon.SinonStub;
let rmStub: sinon.SinonStub;
let compSetFromSourceStub: sinon.SinonStub;

class TestDelete extends Source {
public async runIt() {
Expand Down Expand Up @@ -167,6 +168,10 @@ describe('project delete source', () => {
});
const lifecycle = Lifecycle.getInstance();
lifecycleEmitStub = $$.SANDBOX.stub(lifecycle, 'emit');

compSetFromSourceStub = stubMethod($$.SANDBOX, ComponentSet, 'fromSource').returns({
toArray: () => [new SourceComponent(exampleSourceComponent)],
});
});

afterEach(() => {
Expand Down Expand Up @@ -228,6 +233,23 @@ describe('project delete source', () => {
ensureHookArgs();
});

it('should pass along metadata and org for pseudo-type matching', async () => {
const metadata = ['Agent:My_Agent'];
await runDeleteCmd(['--metadata', metadata[0], '--json']);
ensureCreateComponentSetArgs({
metadata: {
metadataEntries: metadata,
directoryPaths: [defaultPackagePath],
},
org: {
username: testOrg.username,
exclude: [],
},
});
ensureHookArgs();
expect(compSetFromSourceStub.calledOnce).to.be.true;
});

it('should pass along apiversion', async () => {
const metadata = ['ApexClass:MyClass'];

Expand Down
Loading