Skip to content

Commit c64ea4e

Browse files
committed
refactor: beta topic with renaming adapter
1 parent 4b868d8 commit c64ea4e

File tree

11 files changed

+166
-93
lines changed

11 files changed

+166
-93
lines changed

src/commands/force/source/pull.ts src/commands/force/source/beta/pull.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import { FlagsConfig, flags, SfdxCommand } from '@salesforce/command';
99
import { Duration } from '@salesforce/kit';
1010
import { SfdxProject, Org, Messages, SfdxError } from '@salesforce/core';
11-
import { writeConflictTable } from '../../../writeConflictTable';
12-
import { SourceTracking } from '../../../sourceTracking';
13-
import { throwIfInvalid } from '../../../compatibility';
11+
import { writeConflictTable } from '../../../../writeConflictTable';
12+
import { SourceTracking } from '../../../../sourceTracking';
13+
import { throwIfInvalid, replaceRenamedCommands } from '../../../../compatibility';
1414

1515
Messages.importMessagesDirectory(__dirname);
1616
const messages: Messages = Messages.loadMessages('@salesforce/source-tracking', 'source_pull');
@@ -43,7 +43,7 @@ export default class SourcePull extends SfdxCommand {
4343
org: this.org,
4444
projectPath: this.project.getPath(),
4545
toValidate: 'plugin-source',
46-
command: 'beta:source:pull',
46+
command: replaceRenamedCommands('force:source:pull'),
4747
});
4848

4949
this.ux.startSpinner('Loading source tracking information');

src/commands/force/source/push.ts src/commands/force/source/beta/push.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import { ProgressFormatter } from '@salesforce/plugin-source/lib/formatters/prog
2020
import { DeployProgressBarFormatter } from '@salesforce/plugin-source/lib/formatters/deployProgressBarFormatter';
2121
import { DeployProgressStatusFormatter } from '@salesforce/plugin-source/lib/formatters/deployProgressStatusFormatter';
2222

23-
import { SourceTracking } from '../../../sourceTracking';
24-
import { writeConflictTable } from '../../../writeConflictTable';
25-
import { throwIfInvalid } from '../../../compatibility';
23+
import { SourceTracking } from '../../../../sourceTracking';
24+
import { writeConflictTable } from '../../../../writeConflictTable';
25+
import { throwIfInvalid, replaceRenamedCommands } from '../../../../compatibility';
2626

2727
Messages.importMessagesDirectory(__dirname);
2828
const messages: Messages = Messages.loadMessages('@salesforce/source-tracking', 'source_push');
@@ -71,7 +71,7 @@ export default class SourcePush extends DeployCommand {
7171
org: this.org,
7272
projectPath: this.project.getPath(),
7373
toValidate: 'plugin-source',
74-
command: 'beta:source:push',
74+
command: replaceRenamedCommands('force:source:push'),
7575
});
7676
const waitDuration = this.getFlag<Duration>('wait');
7777
this.isRest = await this.isRestDeploy();

src/commands/force/source/status.ts src/commands/force/source/beta/status.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
import { EOL } from 'os';
99
import { FlagsConfig, flags, SfdxCommand } from '@salesforce/command';
1010
import { SfdxProject, Org, Messages } from '@salesforce/core';
11-
import { getKeyFromStrings } from '../../..';
1211

13-
import { ChangeResult, SourceTracking, getKeyFromObject } from '../../../sourceTracking';
14-
import { throwIfInvalid } from '../../../compatibility';
12+
import { ChangeResult, SourceTracking, getKeyFromObject, getKeyFromStrings } from '../../../../sourceTracking';
13+
import { throwIfInvalid, replaceRenamedCommands } from '../../../../compatibility';
1514

1615
export interface StatusResult {
1716
state: string;
@@ -25,7 +24,7 @@ const messages: Messages = Messages.loadMessages('@salesforce/source-tracking',
2524

2625
export default class SourceStatus extends SfdxCommand {
2726
public static description = messages.getMessage('statusCommandCliDescription');
28-
public static readonly examples = messages.getMessage('examples').split(EOL);
27+
public static readonly examples = replaceRenamedCommands(messages.getMessage('examples')).split(EOL);
2928
protected static flagsConfig: FlagsConfig = {
3029
all: flags.boolean({
3130
char: 'a',
@@ -55,7 +54,7 @@ export default class SourceStatus extends SfdxCommand {
5554
org: this.org,
5655
projectPath: this.project.getPath(),
5756
toValidate: 'plugin-source',
58-
command: 'beta:source:status',
57+
command: replaceRenamedCommands('force:source:status'),
5958
});
6059
const wantsLocal =
6160
(this.flags.local as boolean) || (this.flags.all as boolean) || (!this.flags.remote && !this.flags.all);

src/commands/force/source/tracking/clear.ts src/commands/force/source/beta/tracking/clear.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
99
import { Messages, Org, SfdxProject } from '@salesforce/core';
1010
import * as chalk from 'chalk';
11-
import { SourceTracking } from '../../../../../src/sourceTracking';
12-
import { throwIfInvalid } from '../../../../compatibility';
11+
import { SourceTracking } from '../../../../../sourceTracking';
12+
import { throwIfInvalid, replaceRenamedCommands } from '../../../../../compatibility';
1313

1414
Messages.importMessagesDirectory(__dirname);
1515
const messages: Messages = Messages.loadMessages('@salesforce/source-tracking', 'source_tracking');
@@ -19,7 +19,7 @@ export type SourceTrackingClearResult = {
1919
};
2020

2121
export class SourceTrackingClearCommand extends SfdxCommand {
22-
public static readonly description = messages.getMessage('clearDescription');
22+
public static readonly description = replaceRenamedCommands(messages.getMessage('clearDescription'));
2323

2424
public static readonly requiresProject = true;
2525
public static readonly requiresUsername = true;
@@ -41,10 +41,13 @@ export class SourceTrackingClearCommand extends SfdxCommand {
4141
org: this.org,
4242
projectPath: this.project.getPath(),
4343
toValidate: 'plugin-source',
44-
command: 'beta:source:tracking:clear',
44+
command: replaceRenamedCommands('force:source:tracking:clear'),
4545
});
4646
let clearedFiles: string[] = [];
47-
if (this.flags.noprompt || (await this.ux.confirm(chalk.dim(messages.getMessage('promptMessage'))))) {
47+
if (
48+
this.flags.noprompt ||
49+
(await this.ux.confirm(chalk.dim(replaceRenamedCommands(messages.getMessage('promptMessage')))))
50+
) {
4851
const sourceTracking = await SourceTracking.create({
4952
project: this.project,
5053
org: this.org,

src/commands/force/source/tracking/reset.ts src/commands/force/source/beta/tracking/reset.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
99
import { Messages, Org, SfdxProject } from '@salesforce/core';
1010
import * as chalk from 'chalk';
11-
import { SourceTracking } from '../../../../sourceTracking';
12-
import { throwIfInvalid } from '../../../../compatibility';
11+
import { SourceTracking } from '../../../../../sourceTracking';
12+
import { throwIfInvalid, replaceRenamedCommands } from '../../../../../compatibility';
1313

1414
Messages.importMessagesDirectory(__dirname);
1515
const messages: Messages = Messages.loadMessages('@salesforce/source-tracking', 'source_tracking');
@@ -20,7 +20,7 @@ export type SourceTrackingResetResult = {
2020
};
2121

2222
export class SourceTrackingResetCommand extends SfdxCommand {
23-
public static readonly description = messages.getMessage('resetDescription');
23+
public static readonly description = replaceRenamedCommands(messages.getMessage('resetDescription'));
2424

2525
public static readonly requiresProject = true;
2626
public static readonly requiresUsername = true;
@@ -46,10 +46,13 @@ export class SourceTrackingResetCommand extends SfdxCommand {
4646
org: this.org,
4747
projectPath: this.project.getPath(),
4848
toValidate: 'plugin-source',
49-
command: 'beta:source:tracking:reset',
49+
command: replaceRenamedCommands('force:source:tracking:clear'),
5050
});
5151

52-
if (this.flags.noprompt || (await this.ux.confirm(chalk.dim(messages.getMessage('promptMessage'))))) {
52+
if (
53+
this.flags.noprompt ||
54+
(await this.ux.confirm(chalk.dim(replaceRenamedCommands(messages.getMessage('promptMessage')))))
55+
) {
5356
const sourceTracking = await SourceTracking.create({
5457
project: this.project,
5558
org: this.org,

src/compatibility.ts

+23-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import * as fs from 'fs';
88
import * as path from 'path';
99
import { Org, SfdxError } from '@salesforce/core';
1010

11-
const newTopic = 'beta'; // change to 'force' when plugin-source becomes default
12-
const oldTopic = 'force'; // change to 'legacy' when plugin-source becomes default
11+
const newTopic = 'beta';
1312

1413
type TrackingFileVersion = 'plugin-source' | 'toolbelt' | 'none';
1514
/**
@@ -65,8 +64,11 @@ export const throwIfInvalid = ({
6564
'This command uses a new version of source tracking files.',
6665
'SourceTrackingFileVersionMismatch',
6766
[
68-
`Use the new version of the command ${command.replace(oldTopic, newTopic)} (preserve the tracking files)`,
69-
`Clear the tracking files by running "sfdx ${newTopic}:source:tracking:clear"`,
67+
`Use the new version of the command ${command.replace(
68+
'source:',
69+
`source:${newTopic}`
70+
)} (preserves the tracking files)`,
71+
'Clear the tracking files by running "sfdx force:source:tracking:clear"',
7072
]
7173
);
7274
}
@@ -76,9 +78,24 @@ export const throwIfInvalid = ({
7678
'This command uses the old version of source tracking files.',
7779
'SourceTrackingFileVersionMismatch',
7880
[
79-
`Use the old version of the command ${command.replace(newTopic, oldTopic)} (preserve the tracking files)`,
80-
`Clear the tracking files by running "sfdx ${oldTopic}:source:tracking:clear"`,
81+
`Use the old version of the command ${command.replace(`${newTopic}:`, '')} (preserves the tracking files)`,
82+
`Clear the tracking files by running "sfdx force:source:tracking:${newTopic}:clear"`,
8183
]
8284
);
8385
}
8486
};
87+
88+
export const replaceRenamedCommands = (input: string): string => {
89+
renames.forEach((value, key) => {
90+
input = input.replace(key, value);
91+
});
92+
return input;
93+
};
94+
95+
export const renames = new Map([
96+
['force:source:status', 'force:source:beta:status'],
97+
['force:source:status', 'force:source:beta:status'],
98+
['force:source:pull', 'force:source:beta:pull'],
99+
['force:source:tracking:reset', 'force:source:beta:tracking:reset'],
100+
['force:source:tracking:clear', 'force:source:beta:tracking:clear'],
101+
]);

test/nuts/commands/basics.nut.ts

+33-17
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import { ensureString } from '@salesforce/ts-types';
1717
import { ComponentStatus } from '@salesforce/source-deploy-retrieve';
1818

1919
import { DeployCommandResult } from '@salesforce/plugin-source/lib/formatters/deployResultFormatter';
20-
import { StatusResult } from '../../../src/commands/force/source/status';
20+
import { StatusResult } from '../../../src/commands/force/source/beta/status';
2121
import { PullResponse } from '../../../src/shared/types';
22+
import { replaceRenamedCommands } from '../../../src/compatibility';
2223

2324
let session: TestSession;
2425
let hubUsername: string;
@@ -42,13 +43,17 @@ describe('end-to-end-test for tracking with an org (single packageDir)', () => {
4243

4344
describe('basic status and pull', () => {
4445
it('detects the initial metadata status', () => {
45-
const result = execCmd<StatusResult[]>('force:source:status --json', { ensureExitCode: 0 }).jsonOutput.result;
46+
const result = execCmd<StatusResult[]>(replaceRenamedCommands('force:source:status --json'), {
47+
ensureExitCode: 0,
48+
}).jsonOutput.result;
4649
expect(result).to.be.an.instanceof(Array);
4750
// the fields should be populated
4851
expect(result.every((row) => row.type && row.fullName)).to.equal(true);
4952
});
5053
it('pushes the initial metadata to the org', () => {
51-
const result = execCmd<DeployCommandResult>('force:source:push --json', { ensureExitCode: 0 }).jsonOutput.result;
54+
const result = execCmd<DeployCommandResult>(replaceRenamedCommands('force:source:push --json'), {
55+
ensureExitCode: 0,
56+
}).jsonOutput.result;
5257
expect(result.deployedSource).to.be.an.instanceof(Array);
5358
expect(result.deployedSource, JSON.stringify(result)).to.have.lengthOf(234);
5459
expect(
@@ -57,23 +62,29 @@ describe('end-to-end-test for tracking with an org (single packageDir)', () => {
5762
).to.equal(true);
5863
});
5964
it('sees no local changes (all were committed from push), but profile updated in remote', () => {
60-
const localResult = execCmd<StatusResult[]>('force:source:status --json --local', { ensureExitCode: 0 })
61-
.jsonOutput.result;
65+
const localResult = execCmd<StatusResult[]>(replaceRenamedCommands('force:source:status --json --local'), {
66+
ensureExitCode: 0,
67+
}).jsonOutput.result;
6268
expect(localResult).to.deep.equal([]);
6369

64-
const remoteResult = execCmd<StatusResult[]>('force:source:status --json --remote', { ensureExitCode: 0 })
65-
.jsonOutput.result;
70+
const remoteResult = execCmd<StatusResult[]>(replaceRenamedCommands('force:source:status --json --remote'), {
71+
ensureExitCode: 0,
72+
}).jsonOutput.result;
6673
expect(remoteResult.length).to.equal(1);
6774
expect(remoteResult.some((item) => item.type === 'Profile')).to.equal(true);
6875
});
6976

7077
it('can pull the remote profile', () => {
71-
const pullResult = execCmd<PullResponse[]>('force:source:pull --json', { ensureExitCode: 0 }).jsonOutput.result;
78+
const pullResult = execCmd<PullResponse[]>(replaceRenamedCommands('force:source:pull --json'), {
79+
ensureExitCode: 0,
80+
}).jsonOutput.result;
7281
expect(pullResult.some((item) => item.type === 'Profile')).to.equal(true);
7382
});
7483

7584
it('sees no local or remote changes', () => {
76-
const result = execCmd<StatusResult[]>('force:source:status --json', { ensureExitCode: 0 }).jsonOutput.result;
85+
const result = execCmd<StatusResult[]>(replaceRenamedCommands('force:source:status --json'), {
86+
ensureExitCode: 0,
87+
}).jsonOutput.result;
7788
expect(result).to.have.length(0);
7889
});
7990

@@ -83,8 +94,9 @@ describe('end-to-end-test for tracking with an org (single packageDir)', () => {
8394
fs.promises.unlink(path.join(classDir, 'TestOrderController.cls')),
8495
fs.promises.unlink(path.join(classDir, 'TestOrderController.cls-meta.xml')),
8596
]);
86-
const result = execCmd<StatusResult[]>('force:source:status --json --local', { ensureExitCode: 0 }).jsonOutput
87-
.result;
97+
const result = execCmd<StatusResult[]>(replaceRenamedCommands('force:source:status --json --local'), {
98+
ensureExitCode: 0,
99+
}).jsonOutput.result;
88100
expect(result).to.deep.equal([
89101
{
90102
type: 'ApexClass',
@@ -101,26 +113,30 @@ describe('end-to-end-test for tracking with an org (single packageDir)', () => {
101113
]);
102114
});
103115
it('does not see any change in remote status', () => {
104-
const result = execCmd<StatusResult[]>('force:source:status --json --remote', { ensureExitCode: 0 }).jsonOutput
105-
.result;
116+
const result = execCmd<StatusResult[]>(replaceRenamedCommands('force:source:status --json --remote'), {
117+
ensureExitCode: 0,
118+
}).jsonOutput.result;
106119
expect(result).to.have.length(0);
107120
});
108121

109122
it('pushes the local delete to the org', () => {
110-
const result = execCmd<DeployCommandResult>('force:source:push --json', { ensureExitCode: 0 }).jsonOutput.result;
123+
const result = execCmd<DeployCommandResult>(replaceRenamedCommands('force:source:push --json'), {
124+
ensureExitCode: 0,
125+
}).jsonOutput.result;
111126
expect(result.deployedSource).to.be.an.instanceof(Array).with.length(2);
112127
});
113128
it('sees no local changes', () => {
114-
const result = execCmd<StatusResult[]>('force:source:status --json --local', { ensureExitCode: 0 }).jsonOutput
115-
.result;
129+
const result = execCmd<StatusResult[]>(replaceRenamedCommands('force:source:status --json --local'), {
130+
ensureExitCode: 0,
131+
}).jsonOutput.result;
116132
expect(result).to.be.an.instanceof(Array).with.length(0);
117133
});
118134
});
119135

120136
describe('non-successes', () => {
121137
it('should throw an err when attempting to pull from a non scratch-org', () => {
122138
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
123-
const failure = execCmd(`force:source:status -u ${hubUsername} --remote --json`, {
139+
const failure = execCmd(replaceRenamedCommands(`force:source:status -u ${hubUsername} --remote --json`), {
124140
ensureExitCode: 1,
125141
}).jsonOutput;
126142
expect(failure.name).to.equal('NonSourceTrackedOrgError');

test/nuts/commands/conflicts.nut.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
1717
import { Connection, AuthInfo } from '@salesforce/core';
1818
import { ComponentStatus } from '@salesforce/source-deploy-retrieve';
1919
import { DeployCommandResult } from '@salesforce/plugin-source/lib/formatters/DeployResultFormatter';
20-
import { StatusResult } from '../../../src/commands/force/source/status';
20+
import { StatusResult } from '../../../src/commands/force/source/beta/status';
2121
import { PullResponse } from '../../../src/shared/types';
22+
import { replaceRenamedCommands } from '../../../src/compatibility';
2223

2324
let session: TestSession;
24-
2525
describe('conflict detection and resolution', () => {
2626
before(async () => {
2727
session = await TestSession.create({
@@ -39,8 +39,9 @@ describe('conflict detection and resolution', () => {
3939

4040
it('pushes to initiate the remote', () => {
4141
// This would go in setupCommands but we want it to use the bin/run version
42-
const pushResult = execCmd<DeployCommandResult>('force:source:push --json', { ensureExitCode: 0 }).jsonOutput
43-
.result;
42+
const pushResult = execCmd<DeployCommandResult>(replaceRenamedCommands('force:source:push --json'), {
43+
ensureExitCode: 0,
44+
}).jsonOutput.result;
4445
expect(pushResult.deployedSource, JSON.stringify(pushResult)).to.have.lengthOf(234);
4546
expect(
4647
pushResult.deployedSource.every((r) => r.state !== ComponentStatus.Failed),
@@ -67,8 +68,9 @@ describe('conflict detection and resolution', () => {
6768
description: 'modified',
6869
},
6970
});
70-
const result = execCmd<StatusResult[]>('force:source:status --json --remote', { ensureExitCode: 0 }).jsonOutput
71-
.result;
71+
const result = execCmd<StatusResult[]>(replaceRenamedCommands('force:source:status --json --remote'), {
72+
ensureExitCode: 0,
73+
}).jsonOutput.result;
7274
// profile and customApplication
7375
expect(result).to.have.lengthOf(2);
7476
});
@@ -87,18 +89,21 @@ describe('conflict detection and resolution', () => {
8789
);
8890
});
8991
it('can see the conflict in status', () => {
90-
const result = execCmd<StatusResult[]>('force:source:status --json', { ensureExitCode: 0 }).jsonOutput.result;
92+
const result = execCmd<StatusResult[]>(replaceRenamedCommands('force:source:status --json'), { ensureExitCode: 0 })
93+
.jsonOutput.result;
9194
expect(result).to.have.lengthOf(3);
9295
result.filter((app) => app.type === 'CustomApplication').map((app) => expect(app.state).to.include('(Conflict)'));
9396
});
9497

9598
it('gets conflict error on push', () => {
96-
execCmd<DeployCommandResult>('force:source:push --json', { ensureExitCode: 1 });
99+
execCmd<DeployCommandResult>(replaceRenamedCommands('force:source:push --json'), { ensureExitCode: 1 });
97100
});
98101
it('gets conflict error on pull', () => {
99-
execCmd<PullResponse>('force:source:pull --json', { ensureExitCode: 1 });
102+
execCmd<PullResponse>(replaceRenamedCommands('force:source:pull --json'), { ensureExitCode: 1 });
100103
});
101104
it('can push with forceoverwrite', () => {
102-
execCmd<DeployCommandResult[]>('force:source:push --json --forceoverwrite', { ensureExitCode: 0 });
105+
execCmd<DeployCommandResult[]>(replaceRenamedCommands('force:source:push --json --forceoverwrite'), {
106+
ensureExitCode: 0,
107+
});
103108
});
104109
});

0 commit comments

Comments
 (0)