Skip to content

Commit

Permalink
refactor: devScripts update (#799)
Browse files Browse the repository at this point in the history
* chore: updates from devScripts

* chore: linter changes

* chore: enum comparison (lint)

---------

Co-authored-by: mshanemc <[email protected]>
  • Loading branch information
svc-cli-bot and mshanemc authored Nov 6, 2023
1 parent 41f98e9 commit 919e03a
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 284 deletions.
24 changes: 2 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,24 @@
"devDependencies": {
"@oclif/plugin-command-snapshot": "^4.0.12",
"@salesforce/cli-plugins-testkit": "^4.4.12",
"@salesforce/dev-config": "^4.1.0",
"@salesforce/dev-scripts": "^5.12.2",
"@salesforce/dev-scripts": "^6.0.3",
"@salesforce/plugin-command-reference": "^3.0.40",
"@salesforce/plugin-settings": "^1.4.37",
"@salesforce/plugin-source": "^2.10.30",
"@salesforce/plugin-templates": "^55.5.17",
"@salesforce/plugin-user": "^2.3.32",
"@salesforce/prettier-config": "^0.0.3",
"@salesforce/source-testkit": "^2.1.60",
"@salesforce/ts-sinon": "1.4.15",
"@salesforce/ts-types": "^2.0.8",
"@swc/core": "1.3.39",
"@types/shelljs": "^0.8.14",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"chai": "^4.3.10",
"cross-env": "^7.0.3",
"eslint": "^8.52.0",
"eslint-config-prettier": "^8.10.0",
"eslint-config-salesforce": "^2.0.1",
"eslint-config-salesforce-license": "^0.2.0",
"eslint-config-salesforce-typescript": "^2.0.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-jsdoc": "^46.8.2",
"eslint-plugin-sf-plugin": "^1.16.13",
"husky": "^7.0.4",
"jsforce": "^2.0.0-beta.28",
"mocha": "^10.1.0",
"nyc": "^15.1.0",
"oclif": "^3.16.0",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.3",
"shx": "0.3.4",
"sinon": "11.1.2",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"wireit": "^0.14.1"
"typescript": "^5.2.2"
},
"config": {},
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/project/delete/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
SfCommand,
} from '@salesforce/sf-plugins-core';
import * as chalk from 'chalk';
import { DeleteSourceJson, isSourceComponent } from '../../../utils/types';
import { API, DeleteSourceJson, isSourceComponent } from '../../../utils/types';
import { getPackageDirs, getSourceApiVersion } from '../../../utils/project';
import { resolveApi, validateTests } from '../../../utils/deploy';
import { DeployResultFormatter } from '../../../formatters/deployResultFormatter';
Expand Down Expand Up @@ -230,7 +230,7 @@ export class Source extends SfCommand<DeleteSourceJson> {

// fire predeploy event for the delete
await Lifecycle.getInstance().emit('predeploy', this.components);
this.isRest = (await resolveApi()) === 'REST';
this.isRest = (await resolveApi()) === API['REST'];
this.log(`*** Deleting with ${this.isRest ? 'REST' : 'SOAP'} API ***`);

const deploy = await this.componentSet.deploy({
Expand Down
6 changes: 3 additions & 3 deletions src/commands/project/deploy/quick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { DeployCache } from '../../../utils/deployCache';
import { DEPLOY_STATUS_CODES_DESCRIPTIONS } from '../../../utils/errorCodes';
import { AsyncDeployResultFormatter } from '../../../formatters/asyncDeployResultFormatter';
import { DeployResultFormatter } from '../../../formatters/deployResultFormatter';
import { DeployResultJson } from '../../../utils/types';
import { API, DeployResultJson } from '../../../utils/types';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'deploy.metadata.quick');
Expand Down Expand Up @@ -94,11 +94,11 @@ export default class DeployMetadataQuick extends SfCommand<DeployResultJson> {
usernameOrConnection: org.getConnection(flags['api-version']),
id: jobId,
apiOptions: {
rest: api === 'REST',
rest: api === API['REST'],
},
});
// This is the ID of the deploy (of the validated metadata)
const deployId = await mdapiDeploy.deployRecentValidation(api === 'REST');
const deployId = await mdapiDeploy.deployRecentValidation(api === API['REST']);
this.log(`Deploy ID: ${bold(deployId)}`);

if (flags.async) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/project/deploy/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { buildComponentSet } from '../../../utils/deploy';
import { DeployProgress } from '../../../utils/progressBar';
import { DeployCache } from '../../../utils/deployCache';
import { DeployReportResultFormatter } from '../../../formatters/deployReportResultFormatter';
import { DeployResultJson } from '../../../utils/types';
import { API, DeployResultJson } from '../../../utils/types';
import { coverageFormattersFlag } from '../../../utils/flags';

Messages.importMessagesDirectory(__dirname);
Expand Down Expand Up @@ -100,7 +100,7 @@ export default class DeployMetadataReport extends SfCommand<DeployResultJson> {
id: jobId,
components: componentSet,
apiOptions: {
rest: deployOpts.api === 'REST',
rest: deployOpts.api === API['REST'],
},
});

Expand Down
4 changes: 2 additions & 2 deletions src/commands/project/deploy/resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { DeployResult, MetadataApiDeploy } from '@salesforce/source-deploy-retri
import { Duration } from '@salesforce/kit';
import { DeployResultFormatter } from '../../../formatters/deployResultFormatter';
import { DeployProgress } from '../../../utils/progressBar';
import { DeployResultJson } from '../../../utils/types';
import { API, DeployResultJson } from '../../../utils/types';
import { buildComponentSet, determineExitCode, executeDeploy, isNotResumable } from '../../../utils/deploy';
import { DeployCache } from '../../../utils/deployCache';
import { DEPLOY_STATUS_CODES_DESCRIPTIONS } from '../../../utils/errorCodes';
Expand Down Expand Up @@ -100,7 +100,7 @@ export default class DeployMetadataResume extends SfCommand<DeployResultJson> {
id: jobId,
components: componentSet,
apiOptions: {
rest: deployOpts.api === 'REST',
rest: deployOpts.api === API['REST'],
},
});
const deployStatus = await mdapiDeploy.checkStatus();
Expand Down
5 changes: 3 additions & 2 deletions src/commands/project/retrieve/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
FileResponse,
MetadataApiRetrieveStatus,
RegistryAccess,
RequestStatus,
} from '@salesforce/source-deploy-retrieve';
import { SfCommand, toHelpSection, Flags, Ux } from '@salesforce/sf-plugins-core';
import { getString } from '@salesforce/ts-types';
Expand Down Expand Up @@ -170,7 +171,7 @@ export default class RetrieveMetadata extends SfCommand<RetrieveResultJson> {
flags,
format
);
if (flags.manifest || flags.metadata) {
if (Boolean(flags.manifest) || Boolean(flags.metadata)) {
const access = new RegistryAccess();
if (wantsToRetrieveCustomFields(componentSetFromNonDeletes, access)) {
this.warn(messages.getMessage('wantsToRetrieveCustomFields'));
Expand Down Expand Up @@ -239,7 +240,7 @@ export default class RetrieveMetadata extends SfCommand<RetrieveResultJson> {
// in the case where we didn't retrieve anything, check if we have any deletes
if (
!this.retrieveResult.response.status ||
this.retrieveResult.response.status === 'Succeeded' ||
this.retrieveResult.response.status === RequestStatus['Succeeded'] ||
fileResponsesFromDelete.length !== 0
) {
await formatter.display();
Expand Down
2 changes: 1 addition & 1 deletion src/configMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default [
description: messages.getMessage(ConfigVars.ORG_METADATA_REST_DEPLOY),
hidden: true,
input: {
validator: (value: ConfigValue): boolean => value != null && ['true', 'false'].includes(value.toString()),
validator: (value: ConfigValue): boolean => typeof value === 'string' && ['true', 'false'].includes(value),
failedMessage: messages.getMessage('error.invalidBooleanConfigValue'),
},
},
Expand Down
10 changes: 5 additions & 5 deletions src/formatters/deployResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as path from 'node:path';
import { EOL } from 'node:os';
import * as fs from 'node:fs';
import { ux } from '@oclif/core';
import { DeployResult, FileResponse, RequestStatus } from '@salesforce/source-deploy-retrieve';
import { ComponentStatus, DeployResult, FileResponse, RequestStatus } from '@salesforce/source-deploy-retrieve';
import { Org, SfError, Lifecycle } from '@salesforce/core';
import { Duration, ensureArray, sortBy } from '@salesforce/kit';
import {
Expand Down Expand Up @@ -63,7 +63,7 @@ export class DeployResultFormatter extends TestResultsFormatter implements Forma
// only generate reports if test results are presented
if (
(!this.result.response?.numberTestsTotal && !this.flags['test-level']) ||
this.flags['test-level'] === 'NoTestRun'
this.flags['test-level'] === TestLevel['NoTestRun']
) {
const testsWarn = (
this.coverageOptions.reportFormats?.length ? ['`--coverage-formatters` was specified but no tests ran.'] : []
Expand Down Expand Up @@ -93,7 +93,7 @@ export class DeployResultFormatter extends TestResultsFormatter implements Forma
componentFailures: this.result.response.details.componentFailures,
runTestResult: this.result.response.details.runTestResult,
},
files: this.absoluteFiles.filter((f) => f.state === 'Failed'),
files: this.absoluteFiles.filter(isSdrFailure),
};
} else {
return {
Expand Down Expand Up @@ -239,7 +239,7 @@ export class DeployResultFormatter extends TestResultsFormatter implements Forma
}

private displaySuccesses(): void {
const successes = this.relativeFiles.filter((f) => f.state !== 'Failed');
const successes = this.relativeFiles.filter(isSdrSuccess);

if (!successes.length || this.result.response.status === RequestStatus.Failed) return;

Expand Down Expand Up @@ -287,7 +287,7 @@ export class DeployResultFormatter extends TestResultsFormatter implements Forma
}

private displayDeletes(): void {
const deletions = this.relativeFiles.filter(isSdrSuccess).filter((f) => f.state === 'Deleted');
const deletions = this.relativeFiles.filter(isSdrSuccess).filter((f) => f.state === ComponentStatus['Deleted']);

if (!deletions.length) return;

Expand Down
4 changes: 2 additions & 2 deletions src/utils/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export async function executeDeploy(
});
componentSet = await buildComponentSet(opts, stl);
if (componentSet.size === 0) {
if (opts['source-dir'] || opts.manifest || opts.metadata || throwOnEmpty) {
if (Boolean(opts['source-dir']) ?? Boolean(opts.manifest) ?? Boolean(opts.metadata) ?? throwOnEmpty) {
// the user specified something to deploy, but there isn't anything
throw new SfError(
deployMessages.getMessage('error.nothingToDeploy'),
Expand Down Expand Up @@ -232,7 +232,7 @@ export const isNotResumable = (status?: RequestStatus): boolean =>
const buildApiOptions = (opts: Partial<DeployOptions>): MetadataApiDeployOptions['apiOptions'] => ({
checkOnly: opts['dry-run'] ?? false,
ignoreWarnings: opts['ignore-warnings'] ?? false,
rest: opts.api === 'REST',
rest: opts.api === API['REST'],
rollbackOnError: !opts['ignore-errors'] || false,
...(opts.tests ? { runTests: opts.tests } : {}),
...(opts['test-level'] ? { testLevel: opts['test-level'] } : {}),
Expand Down
5 changes: 3 additions & 2 deletions test/nuts/retrieve/partialBundleDelete.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ComponentSet,
ComponentSetBuilder,
ComponentSetOptions,
ComponentStatus,
MetadataApiRetrieve,
RetrieveSetOptions,
} from '@salesforce/source-deploy-retrieve';
Expand Down Expand Up @@ -148,7 +149,7 @@ describe('Partial Bundle Delete Retrieves', () => {
expect(files).to.be.an('array').with.length.greaterThan(0);

// find the deleted entry for testFile.css
const deletedFileResponse = files.find((fr) => fr.state === 'Deleted');
const deletedFileResponse = files.find((fr) => fr.state === ComponentStatus['Deleted']);
expect(deletedFileResponse).to.deep.equal({
fullName: 'pageTemplate_2_7_3',
type: 'AuraDefinitionBundle',
Expand Down Expand Up @@ -181,7 +182,7 @@ describe('Partial Bundle Delete Retrieves', () => {
assert(files);
expect(files).to.be.an('array').with.length.greaterThan(0);
// find the deleted entry for testFile.css
const deletedFileResponse = files.find((fr) => fr.state === 'Deleted');
const deletedFileResponse = files.find((fr) => fr.state === ComponentStatus['Deleted']);
expect(deletedFileResponse).to.deep.equal({
fullName: 'propertyTile',
type: 'LightningComponentBundle',
Expand Down
17 changes: 7 additions & 10 deletions test/nuts/tracking/basics.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { expect, assert } from 'chai';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { ComponentStatus } from '@salesforce/source-deploy-retrieve';
import { StatusResult } from '@salesforce/plugin-source/lib/formatters/source/statusFormatter';
import { DeployResultJson, RetrieveResultJson } from '../../../src/utils/types';
import { DeployResultJson, RetrieveResultJson, isSdrFailure } from '../../../src/utils/types';
import { PreviewResult } from '../../../src/utils/previewOutput';
import { eBikesDeployResultCount } from './constants';
const filterIgnored = (r: StatusResult): boolean => r.ignored !== true;
Expand Down Expand Up @@ -269,15 +269,12 @@ describe('end-to-end-test for tracking with an org (single packageDir)', () => {
}).jsonOutput;
assert(failure && 'status' in failure);
expect(failure).to.have.property('status', 1);
expect(
failure.result.files.every((r) => r.type === 'ApexClass' && r.state === 'Failed' && r.problemType === 'Error')
).to.equal(true);
failure.result.files.forEach((f) => {
if (f.state === 'Failed') {
expect(f.lineNumber).to.exist;
expect(f.columnNumber).to.exist;
expect(f.error).to.be.a('string');
}
const failureFiles = failure.result.files.filter(isSdrFailure);
expect(failureFiles.every((r) => r.type === 'ApexClass' && r.problemType === 'Error')).to.equal(true);
failureFiles.forEach((f) => {
expect(f.lineNumber).to.exist;
expect(f.columnNumber).to.exist;
expect(f.error).to.be.a('string');
});
});
describe('classes that failed to deploy are still in local status', () => {
Expand Down
5 changes: 3 additions & 2 deletions test/nuts/tracking/lwc.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as fs from 'node:fs';
import { assert, expect } from 'chai';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { StatusResult } from '@salesforce/plugin-source/lib/formatters/source/statusFormatter';
import { ComponentStatus } from '@salesforce/source-deploy-retrieve';
import { PreviewResult } from '../../../src/utils/previewOutput';
import { DeployResultJson } from '../../../src/utils/types';

Expand Down Expand Up @@ -130,7 +131,7 @@ describe('lwc', () => {
// expect(bundleMembers, JSON.stringify(bundleMembers)).to.have.length(4);
// expect(bundleMembers.filter((r) => r.state === 'Deleted')).to.have.length(1);
expect(bundleMembers, JSON.stringify(bundleMembers)).to.have.length(3);
expect(bundleMembers?.filter((r) => r.state === 'Changed')).to.have.length(3);
expect(bundleMembers?.filter((r) => r.state === ComponentStatus['Changed'])).to.have.length(3);
});

it('sees no local changes', () => {
Expand Down Expand Up @@ -181,7 +182,7 @@ describe('lwc', () => {
const bundleMembers = result?.filter((r) => r.fullName === 'heroDetails');
expect(bundleMembers).to.have.length(3);
expect(
bundleMembers?.every((r) => r.state === 'Deleted'),
bundleMembers?.every((r) => r.state === ComponentStatus['Deleted']),
JSON.stringify(bundleMembers, undefined, 2)
).to.be.true;
});
Expand Down
Loading

0 comments on commit 919e03a

Please sign in to comment.