Skip to content

Commit

Permalink
feat: core7, jsforce-node
Browse files Browse the repository at this point in the history
note: this still has some old jsforce because of apex-node.  
* chore: updates from devScripts

* test: top-level imports

* refactor: type handling for setError when class

* test: schemas

* fix: preserve error.context

---------

Co-authored-by: mshanemc <[email protected]>
  • Loading branch information
svc-cli-bot and mshanemc authored Apr 11, 2024
1 parent dcad4be commit ee1bd7e
Show file tree
Hide file tree
Showing 24 changed files with 312 additions and 170 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^3.25.2",
"@oclif/core": "^3.26.2",
"@salesforce/apex-node": "^4.0.2",
"@salesforce/core": "^6.4.4",
"@salesforce/kit": "^3.0.15",
"@salesforce/sf-plugins-core": "^8.0.3",
"@salesforce/source-deploy-retrieve": "^10.5.5",
"@salesforce/source-tracking": "^5.1.11",
"@salesforce/core": "^7.0.1",
"@salesforce/kit": "^3.1.0",
"@salesforce/sf-plugins-core": "^9.0.1",
"@salesforce/source-deploy-retrieve": "^11.0.0",
"@salesforce/source-tracking": "^6.0.0",
"@salesforce/ts-types": "^2.0.9",
"chalk": "^5.3.0",
"got": "^13.0.0",
Expand All @@ -20,16 +20,16 @@
"devDependencies": {
"@oclif/plugin-command-snapshot": "^5.1.4",
"@oclif/plugin-help": "^6.0.20",
"@salesforce/cli-plugins-testkit": "^5.1.9",
"@salesforce/dev-scripts": "^8.5.0",
"@salesforce/cli-plugins-testkit": "^5.2.0",
"@salesforce/dev-scripts": "^9.0.0",
"@salesforce/plugin-command-reference": "^3.0.70",
"@salesforce/source-testkit": "^2.1.109",
"@salesforce/ts-sinon": "1.4.19",
"@types/archiver": "^5.3.2",
"archiver": "^5.3.2",
"chai-each": "^0.0.1",
"cross-env": "^7.0.3",
"eslint-plugin-sf-plugin": "^1.17.5",
"eslint-plugin-sf-plugin": "^1.18.0",
"fast-glob": "^3.3.1",
"oclif": "^4.7.6",
"ts-node": "^10.9.2",
Expand Down
18 changes: 9 additions & 9 deletions schemas/force-source-deploy-cancel.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"MetadataApiDeployStatus": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string"
Expand Down Expand Up @@ -108,7 +109,6 @@
"status",
"success"
],
"additionalProperties": false,
"description": "Raw response returned from a checkDeployStatus call to the Metadata API"
},
"RequestStatus": {
Expand Down Expand Up @@ -154,8 +154,7 @@
"type": "object",
"properties": {
"changed": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
"$ref": "#/definitions/BooleanString"
},
"columnNumber": {
"type": "string"
Expand All @@ -164,15 +163,13 @@
"type": "string"
},
"created": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
"$ref": "#/definitions/BooleanString"
},
"createdDate": {
"type": "string"
},
"deleted": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
"$ref": "#/definitions/BooleanString"
},
"fileName": {
"type": "string"
Expand All @@ -194,13 +191,16 @@
"enum": ["Warning", "Error"]
},
"success": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
"$ref": "#/definitions/BooleanString"
}
},
"required": ["changed", "created", "createdDate", "deleted", "fileName", "fullName", "success"],
"additionalProperties": false
},
"BooleanString": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
},
"RunTestResult": {
"type": "object",
"properties": {
Expand Down
18 changes: 9 additions & 9 deletions schemas/force-source-deploy-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"MetadataApiDeployStatus": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string"
Expand Down Expand Up @@ -108,7 +109,6 @@
"status",
"success"
],
"additionalProperties": false,
"description": "Raw response returned from a checkDeployStatus call to the Metadata API"
},
"RequestStatus": {
Expand Down Expand Up @@ -154,8 +154,7 @@
"type": "object",
"properties": {
"changed": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
"$ref": "#/definitions/BooleanString"
},
"columnNumber": {
"type": "string"
Expand All @@ -164,15 +163,13 @@
"type": "string"
},
"created": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
"$ref": "#/definitions/BooleanString"
},
"createdDate": {
"type": "string"
},
"deleted": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
"$ref": "#/definitions/BooleanString"
},
"fileName": {
"type": "string"
Expand All @@ -194,13 +191,16 @@
"enum": ["Warning", "Error"]
},
"success": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
"$ref": "#/definitions/BooleanString"
}
},
"required": ["changed", "created", "createdDate", "deleted", "fileName", "fullName", "success"],
"additionalProperties": false
},
"BooleanString": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
},
"RunTestResult": {
"type": "object",
"properties": {
Expand Down
30 changes: 15 additions & 15 deletions schemas/force-source-deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@
"type": "object",
"properties": {
"changed": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
"$ref": "#/definitions/BooleanString"
},
"columnNumber": {
"type": "string"
Expand All @@ -218,15 +217,13 @@
"type": "string"
},
"created": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
"$ref": "#/definitions/BooleanString"
},
"createdDate": {
"type": "string"
},
"deleted": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
"$ref": "#/definitions/BooleanString"
},
"fileName": {
"type": "string"
Expand All @@ -248,13 +245,16 @@
"enum": ["Warning", "Error"]
},
"success": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
"$ref": "#/definitions/BooleanString"
}
},
"required": ["changed", "created", "createdDate", "deleted", "fileName", "fullName", "success"],
"additionalProperties": false
},
"BooleanString": {
"type": ["string", "boolean"],
"enum": ["true", "false", true, false]
},
"RunTestResult": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -459,6 +459,7 @@
},
"FileResponseSuccess": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand All @@ -474,11 +475,11 @@
"enum": ["Created", "Changed", "Unchanged", "Deleted"]
}
},
"required": ["fullName", "state", "type"],
"additionalProperties": false
"required": ["fullName", "state", "type"]
},
"FileResponseFailure": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand Down Expand Up @@ -507,11 +508,11 @@
"enum": ["Warning", "Error"]
}
},
"required": ["error", "fullName", "problemType", "state", "type"],
"additionalProperties": false
"required": ["error", "fullName", "problemType", "state", "type"]
},
"MetadataApiDeployStatus": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string"
Expand Down Expand Up @@ -613,11 +614,11 @@
"status",
"success"
],
"additionalProperties": false,
"description": "Raw response returned from a checkDeployStatus call to the Metadata API"
},
"DeployCommandAsyncResult": {
"type": "object",
"additionalProperties": false,
"properties": {
"done": {
"type": "boolean"
Expand Down Expand Up @@ -649,8 +650,7 @@
}
}
},
"required": ["deploys", "done", "id", "outboundFiles", "state", "status", "timedOut"],
"additionalProperties": false
"required": ["deploys", "done", "id", "outboundFiles", "state", "status", "timedOut"]
},
"DeployAsyncStatus": {
"type": "object",
Expand Down
8 changes: 4 additions & 4 deletions schemas/force-source-retrieve.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
},
"FileResponseSuccess": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand All @@ -57,11 +58,11 @@
"enum": ["Created", "Changed", "Unchanged", "Deleted"]
}
},
"required": ["fullName", "state", "type"],
"additionalProperties": false
"required": ["fullName", "state", "type"]
},
"FileResponseFailure": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand Down Expand Up @@ -90,8 +91,7 @@
"enum": ["Warning", "Error"]
}
},
"required": ["error", "fullName", "problemType", "state", "type"],
"additionalProperties": false
"required": ["error", "fullName", "problemType", "state", "type"]
},
"PackageRetrieval": {
"type": "object",
Expand Down
14 changes: 8 additions & 6 deletions src/formatters/mdapi/mdDeployResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import chalk from 'chalk';
import { getNumber } from '@salesforce/ts-types';
import { AnyJson, getNumber } from '@salesforce/ts-types';
import { Messages, SfError } from '@salesforce/core';
import {
DeployMessage,
Expand Down Expand Up @@ -103,11 +103,13 @@ export class MdDeployResultFormatter extends ResultFormatter {
}
// TODO: the toolbelt version of this is returning an SfError shape. This returns a status=1 and the result (mdapi response) but not the error name, etc
if (!this.isSuccess()) {
// Add error message directly on the DeployResult (e.g., a GACK)
const errMsg = this.getResponse()?.errorMessage ?? '';
const error = new SfError(messages.getMessage('deployFailed', [errMsg]), 'mdapiDeployFailed');
error.setData(this.result);
throw error;
throw SfError.create({
// Add error message directly on the DeployResult (e.g., a GACK)
message: messages.getMessage('deployFailed', [this.getResponse()?.errorMessage ?? '']),
name: 'mdapiDeployFailed',
// this.result is a Class, so here's the serializable portions of it
data: JSON.parse(JSON.stringify(this.result)) as AnyJson,
});
}
}

Expand Down
29 changes: 18 additions & 11 deletions src/formatters/source/pushResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,28 @@ export class PushResultFormatter extends ResultFormatter {
public getJson(): PushResponse {
// throws a particular json structure.
if (process.exitCode !== 0) {
const errorData = this.fileResponses.filter((fileResponse) => fileResponse.state === ComponentStatus.Failed);

const error = SfError.create({
context: 'Push',
name: 'DeployFailed',
exitCode: process.exitCode,
message: messages.getMessage('sourcepushFailed', ['']),
data: errorData,
});
// matching toolbelt error json. Does not match the SfError type

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const error: SfError & {
result: FileResponse[];
commandName: string;
context: string;
partialSuccess: FileResponse[];
} = new SfError(messages.getMessage('sourcepushFailed', ['']), 'DeployFailed', [], process.exitCode);
const errorData = this.fileResponses.filter((fileResponse) => fileResponse.state === ComponentStatus.Failed);
error.setData(errorData);
error['result'] = errorData;
error['commandName'] = 'Push';
error['context'] = 'Push';
error.result = errorData;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
error.commandName = 'Push';

// partial success
if (process.exitCode === 69) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
error['partialSuccess'] = this.fileResponses.filter(
(fileResponse) => fileResponse.state !== ComponentStatus.Failed
);
Expand Down
2 changes: 1 addition & 1 deletion test/commands/mdapi/cancel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { expect } from 'chai';
import { spyMethod, stubMethod } from '@salesforce/ts-sinon';
import { ConfigFile } from '@salesforce/core';
import { MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
import { MockTestOrgData, TestContext } from '@salesforce/core/lib/testSetup.js';
import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup';
import { stubSfCommandUx, stubUx } from '@salesforce/sf-plugins-core';
import { Cancel } from '../../../src/commands/force/mdapi/deploy/cancel.js';
import { DeployCancelResultFormatter } from '../../../src/formatters/deployCancelResultFormatter.js';
Expand Down
2 changes: 1 addition & 1 deletion test/commands/mdapi/retrieve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Config } from '@oclif/core';
import { ComponentSetBuilder, ComponentSetOptions, RetrieveOptions } from '@salesforce/source-deploy-retrieve';
import { Duration } from '@salesforce/kit';
import { SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { MockTestOrgData, TestContext } from '@salesforce/core/lib/testSetup.js';
import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup';
import { Retrieve } from '../../../src/commands/force/mdapi/retrieve.js';
import { Stash, StashData } from '../../../src/stash.js';
import { getRetrieveResult } from '../source/retrieveResponses.js';
Expand Down
2 changes: 1 addition & 1 deletion test/commands/mdapi/retrieveReport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Config } from '@oclif/core';

import { MetadataApiRetrieve } from '@salesforce/source-deploy-retrieve';
import { SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { MockTestOrgData, TestContext } from '@salesforce/core/lib/testSetup.js';
import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup';

import { Report } from '../../../src/commands/force/mdapi/retrieve/report.js';
import { Stash } from '../../../src/stash.js';
Expand Down
Loading

0 comments on commit ee1bd7e

Please sign in to comment.