Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use oclif/core v4 and sf-plugins-core v10 #1038

Merged
merged 4 commits into from
Jun 6, 2024
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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^3.26.6",
"@oclif/core": "^4",
"@salesforce/apex-node": "^6.0.0",
"@salesforce/core": "^7.3.9",
"@salesforce/kit": "^3.1.2",
"@salesforce/plugin-info": "^3.3.4",
"@salesforce/sf-plugins-core": "^9.1.0",
"@salesforce/source-deploy-retrieve": "^11.6.3",
"@salesforce/source-tracking": "^6.3.2",
"@salesforce/sf-plugins-core": "^10.0.0",
"@salesforce/source-deploy-retrieve": "^11.6.5",
"@salesforce/source-tracking": "^6.3.4",
"@salesforce/ts-types": "^2.0.9",
"chalk": "^5.3.0"
},
Expand Down
4 changes: 3 additions & 1 deletion src/formatters/asyncDeployCancelResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { ux } from '@oclif/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { AsyncDeployResultJson, DeployResultJson, Formatter } from '../utils/types.js';

const ux = new Ux();

export class AsyncDeployCancelResultFormatter implements Formatter<AsyncDeployResultJson> {
public constructor(private id: string) {}

Expand Down
4 changes: 3 additions & 1 deletion src/formatters/asyncDeployResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { ux } from '@oclif/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { AsyncDeployResultJson, Formatter } from '../utils/types.js';

const ux = new Ux();

export class AsyncDeployResultFormatter implements Formatter<AsyncDeployResultJson> {
public constructor(private id: string) {}

Expand Down
24 changes: 12 additions & 12 deletions src/formatters/deleteResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { ux } from '@oclif/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { DeployResult, FileResponse, FileResponseSuccess, RequestStatus } from '@salesforce/source-deploy-retrieve';
import { ensureArray } from '@salesforce/kit';
import chalk from 'chalk';
Expand All @@ -18,6 +18,8 @@ import {
} from '../utils/output.js';
import { TestResultsFormatter } from '../formatters/testResultsFormatter.js';

const ux = new Ux();

export class DeleteResultFormatter extends TestResultsFormatter implements Formatter<DeleteSourceJson> {
public constructor(
protected result: DeployResult,
Expand Down Expand Up @@ -99,20 +101,18 @@ export class DeleteResultFormatter extends TestResultsFormatter implements Forma
const failures = ensureArray(this.result.response.details.componentFailures);
if (!failures.length) return;

const columns = {
problemType: { header: 'Type' },
fullName: { header: 'Name' },
error: { header: 'Problem' },
};
const options: ux.Table.table.Options = {
title: StandardColors.error(chalk.bold(`Component Failures [${failures.length}]`)),
'no-truncate': true,
};
ux.log();
ux.table(
failures.map((f) => ({ problemType: f.problemType, fullName: f.fullName, error: f.problem })),
columns,
options
{
problemType: { header: 'Type' },
fullName: { header: 'Name' },
error: { header: 'Problem' },
},
{
title: StandardColors.error(chalk.bold(`Component Failures [${failures.length}]`)),
'no-truncate': true,
}
);
}
}
7 changes: 5 additions & 2 deletions src/formatters/deployCancelResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { ux } from '@oclif/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { error } from '@oclif/core/ux';
import { DeployResult, RequestStatus } from '@salesforce/source-deploy-retrieve';
import { DeployResultJson, Formatter } from '../utils/types.js';

const ux = new Ux();

export class DeployCancelResultFormatter implements Formatter<DeployResultJson> {
public constructor(protected result: DeployResult) {}

Expand All @@ -20,7 +23,7 @@ export class DeployCancelResultFormatter implements Formatter<DeployResultJson>
if (this.result.response.status === RequestStatus.Canceled) {
ux.log(`Successfully canceled ${this.result.response.id}`);
} else {
ux.error(`Could not cancel ${this.result.response.id}`);
error(`Could not cancel ${this.result.response.id}`);
}
}
}
4 changes: 3 additions & 1 deletion src/formatters/deployReportResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { ux } from '@oclif/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { RequestStatus } from '@salesforce/source-deploy-retrieve';
import { StandardColors } from '@salesforce/sf-plugins-core';
import { Duration } from '@salesforce/kit';
import { tableHeader } from '../utils/output.js';
import { DeployResultFormatter } from './deployResultFormatter.js';

const ux = new Ux();

export class DeployReportResultFormatter extends DeployResultFormatter {
public display(): void {
ux.log(`${this.result.response.id}... ${this.result.response.status}`);
Expand Down
8 changes: 5 additions & 3 deletions src/formatters/deployResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as path from 'node:path';
import path from 'node:path';
import { EOL } from 'node:os';
import * as fs from 'node:fs';
import fs from 'node:fs';
import { join } from 'node:path';
import { ux } from '@oclif/core';
import { Ux } from '@salesforce/sf-plugins-core';
import {
ComponentStatus,
DeployResult,
Expand Down Expand Up @@ -51,6 +51,8 @@ import {
} from '../utils/output.js';
import { TestResultsFormatter } from '../formatters/testResultsFormatter.js';

const ux = new Ux();

export class DeployResultFormatter extends TestResultsFormatter implements Formatter<DeployResultJson> {
private readonly relativeFiles: FileResponse[];
private readonly absoluteFiles: FileResponse[];
Expand Down
6 changes: 4 additions & 2 deletions src/formatters/metadataConvertResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as path from 'node:path';
import { ux } from '@oclif/core';
import path from 'node:path';
import { Ux } from '@salesforce/sf-plugins-core';
import { ConvertResult } from '@salesforce/source-deploy-retrieve';
import { Formatter, ConvertMdapiJson } from '../utils/types.js';

const ux = new Ux();

export class MetadataConvertResultFormatter implements Formatter<ConvertMdapiJson> {
private convertResults!: ConvertMdapiJson;
public constructor(private result: ConvertResult) {}
Expand Down
4 changes: 3 additions & 1 deletion src/formatters/metadataRetrieveResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
*/
import { join, parse } from 'node:path';

import { ux } from '@oclif/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { FileResponse, RetrieveResult } from '@salesforce/source-deploy-retrieve';
import { Messages } from '@salesforce/core';
import { Formatter, MetadataRetrieveResultJson } from '../utils/types.js';
import { fileResponseSortFn, makePathRelative } from '../utils/output.js';

const ux = new Ux();

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
export const retrieveMessages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'retrieve.start');

Expand Down
2 changes: 1 addition & 1 deletion src/formatters/retrieveResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as path from 'node:path';
import path from 'node:path';
import { Ux } from '@salesforce/sf-plugins-core';
import { FileResponse, RetrieveMessage, RetrieveResult } from '@salesforce/source-deploy-retrieve';
import { NamedPackageDir, SfProject } from '@salesforce/core';
Expand Down
4 changes: 3 additions & 1 deletion src/formatters/sourceConvertResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
*/
import { resolve } from 'node:path';

import { ux } from '@oclif/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { ConvertResult } from '@salesforce/source-deploy-retrieve';
import { SfError, Messages } from '@salesforce/core';
import { ConvertResultJson, Formatter } from '../utils/types.js';
import { exitCodeAsNumber } from '../utils/output.js';

const ux = new Ux();

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
export const convertMessages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'convert.source');

Expand Down
6 changes: 4 additions & 2 deletions src/formatters/testResultsFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as os from 'node:os';
import { ux } from '@oclif/core';
import os from 'node:os';
import { Ux } from '@salesforce/sf-plugins-core';
import chalk from 'chalk';
import {
CodeCoverage,
Expand All @@ -21,6 +21,8 @@ import { TestLevel, Verbosity } from '../utils/types.js';
import { tableHeader, error, success, check } from '../utils/output.js';
import { coverageOutput } from '../utils/coverage.js';

const ux = new Ux();

export class TestResultsFormatter {
public testLevel: TestLevel | undefined;
public verbosity: Verbosity;
Expand Down
4 changes: 3 additions & 1 deletion src/utils/conflicts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { ux } from '@oclif/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { ConflictResponse } from '@salesforce/source-tracking';

const ux = new Ux();

export const writeConflictTable = (conflicts?: ConflictResponse[]): void => {
if (!conflicts || conflicts.length === 0) {
return;
Expand Down
4 changes: 3 additions & 1 deletion src/utils/previewOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { isAbsolute, relative, resolve } from 'node:path';

import { ux } from '@oclif/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { StandardColors } from '@salesforce/sf-plugins-core';
import chalk from 'chalk';
import { Messages } from '@salesforce/core';
Expand All @@ -25,6 +25,8 @@ import { filePathsFromMetadataComponent } from '@salesforce/source-deploy-retrie
import { SourceTracking } from '@salesforce/source-tracking';
import { isSourceComponentWithXml } from './types.js';

const ux = new Ux();

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'previewMessages');

Expand Down
7 changes: 4 additions & 3 deletions src/utils/progressBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { envVars as env, EnvironmentVariable, Lifecycle, Messages } from '@salesforce/core';
import { envVars as env, EnvironmentVariable, Lifecycle, Messages, Logger } from '@salesforce/core';
import { MetadataApiDeploy, MetadataApiDeployStatus } from '@salesforce/source-deploy-retrieve';
import { Progress } from '@salesforce/sf-plugins-core';
import { SourceMemberPollingEvent } from '@salesforce/source-tracking';
import { ux } from '@oclif/core';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const mdTransferMessages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'metadata.transfer');
Expand All @@ -18,6 +17,8 @@ const showBar = Boolean(
process.env.TERM !== 'dumb' && process.stdin.isTTY && env.getBoolean(EnvironmentVariable.SF_USE_PROGRESS_BAR, true)
);

const logger = await Logger.child('deploy-progress');

export class DeployProgress extends Progress {
private static OPTIONS = {
title: 'Status',
Expand Down Expand Up @@ -88,7 +89,7 @@ export class DeployProgress extends Progress {
try {
status = mdTransferMessages.getMessage(data.status);
} catch (e) {
ux.debug(`data.status message lookup failed for: ${data.status}`);
logger.debug(`data.status message lookup failed for: ${data.status}`);
status = 'Waiting';
}
this.update(0, { errorInfo, testInfo, status });
Expand Down
14 changes: 10 additions & 4 deletions test/commands/convert/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
*/

import { join, resolve, sep } from 'node:path';
import fs from 'node:fs/promises';
import { Stats } from 'node:fs';
import { ComponentSetBuilder, ComponentSetOptions, MetadataConverter } from '@salesforce/source-deploy-retrieve';
import sinon from 'sinon';
import { expect } from 'chai';
import { stubMethod } from '@salesforce/ts-sinon';
import { stubMethod, stubInterface } from '@salesforce/ts-sinon';
import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup';
import { stubSfCommandUx } from '@salesforce/sf-plugins-core';
import oclifUtils from '@oclif/core/lib/util/fs.js';
import { SfProject } from '@salesforce/core';
import { Source } from '../../../src/commands/project/convert/source.js';

Expand Down Expand Up @@ -50,8 +51,13 @@ describe('project convert source', () => {
SfProject.instances.clear();
stubSfCommandUx($$.SANDBOX);
// the 2 oclif flags should act as if the dir/file is there and ok
$$.SANDBOX.stub(oclifUtils, 'fileExists').callsFake((path: string) => Promise.resolve(path));
$$.SANDBOX.stub(oclifUtils, 'dirExists').callsFake((path: string) => Promise.resolve(path));
$$.SANDBOX.stub(fs, 'stat').resolves(
stubInterface<Stats>($$.SANDBOX, {
isDirectory: () => true,
isFile: () => true,
})
);

$$.setConfigStubContents('SfProjectJson', {
contents: {
packageDirectories: [{ path: defaultDir, default: true }],
Expand Down
13 changes: 9 additions & 4 deletions test/commands/retrieve/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import { resolve } from 'node:path';

import fs from 'node:fs/promises';
import { Stats } from 'node:fs';
import sinon from 'sinon';
import { expect } from 'chai';
import {
Expand All @@ -19,10 +21,9 @@ import {
RetrieveOptions,
} from '@salesforce/source-deploy-retrieve';
import { Messages, SfProject } from '@salesforce/core';
import { stubMethod } from '@salesforce/ts-sinon';
import { stubMethod, stubInterface } from '@salesforce/ts-sinon';
import { stubSfCommandUx, stubSpinner, stubUx } from '@salesforce/sf-plugins-core';
import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup';
import oclifUtils from '@oclif/core/lib/util/fs.js';
import { RetrieveResultFormatter } from '../../../src/formatters/retrieveResultFormatter.js';
import { getRetrieveResult } from '../../utils/retrieveResponse.js';
import { RetrieveResultJson } from '../../../src/utils/types.js';
Expand Down Expand Up @@ -62,8 +63,12 @@ describe('project retrieve start', () => {
await $$.stubConfig({ 'target-org': testOrg.username });

// the 2 oclif flags should act as if the dir/file is there and ok
$$.SANDBOX.stub(oclifUtils, 'fileExists').callsFake((p: string) => Promise.resolve(p));
$$.SANDBOX.stub(oclifUtils, 'dirExists').callsFake((p: string) => Promise.resolve(p));
$$.SANDBOX.stub(fs, 'stat').resolves(
stubInterface<Stats>($$.SANDBOX, {
isDirectory: () => true,
isFile: () => true,
})
);

sfCommandUxStubs = stubSfCommandUx($$.SANDBOX);
stubUx($$.SANDBOX);
Expand Down
8 changes: 4 additions & 4 deletions test/utils/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as path from 'node:path';
import path from 'node:path';
import { assert, expect, config } from 'chai';
import sinon from 'sinon';
import { DeployMessage, DeployResult, FileResponse } from '@salesforce/source-deploy-retrieve';
import { ux } from '@oclif/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { getCoverageFormattersOptions } from '../../src/utils/coverage.js';
import { DeployResultFormatter } from '../../src/formatters/deployResultFormatter.js';
import { getDeployResult } from './deployResponses.js';
Expand All @@ -27,7 +27,7 @@ describe('deployResultFormatter', () => {
let tableStub: sinon.SinonStub;

beforeEach(() => {
tableStub = sandbox.stub(ux, 'table');
tableStub = sandbox.stub(Ux.prototype, 'table');
});

it('prints file responses, and messages from server', () => {
Expand Down Expand Up @@ -125,7 +125,7 @@ describe('deployResultFormatter', () => {
it('will warn when code coverage warning present from server', () => {
const deployResult = getDeployResult('codeCoverageWarning');
const formatter = new DeployResultFormatter(deployResult, {});
const warnStub = sandbox.stub(ux, 'warn');
const warnStub = sandbox.stub(Ux.prototype, 'warn');
formatter.display();
expect(warnStub.callCount).to.equal(1);
expect(warnStub.firstCall.args[0]).to.equal(
Expand Down
Loading
Loading