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
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"node": ">=12.0.0"
},
"dependencies": {
"@salesforce/core": "^2.35.0",
"@salesforce/kit": "^1.5.32",
"@salesforce/ts-types": "^1.4.2",
"@salesforce/core": "^3.7.9",
"@salesforce/kit": "^1.5.34",
"@salesforce/ts-types": "^1.5.20",
"archiver": "^5.3.0",
"fast-xml-parser": "^3.17.4",
"graceful-fs": "^4.2.8",
Expand All @@ -36,13 +36,13 @@
"xmldom-sfdx-encoding": "^0.1.29"
},
"devDependencies": {
"@salesforce/dev-config": "^2.1.3",
"@salesforce/dev-scripts": "^1.0.2",
"jsforce": "2.0.0-beta.7",
"@salesforce/dev-config": "^3.0.1",
"@salesforce/dev-scripts": "^2.0.1",
"@salesforce/prettier-config": "^0.0.2",
"@salesforce/ts-sinon": "^1.1.2",
"@types/archiver": "^5.1.1",
"@types/deep-equal-in-any-order": "^1.0.1",
"@types/jsforce": "^1.9.38",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's pretty exciting!

"@types/mime": "2.0.3",
"@types/mkdirp": "0.5.2",
"@types/shelljs": "^0.8.9",
Expand All @@ -66,7 +66,7 @@
"got": "^11.8.2",
"husky": "^7.0.4",
"lint-staged": "^10.2.11",
"mocha": "^8.4.0",
"mocha": "^9.1.3",
"mocha-junit-reporter": "^1.23.3",
"nyc": "^15.1.0",
"prettier": "^2.0.5",
Expand Down
16 changes: 7 additions & 9 deletions src/client/deployStrategies/baseDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import { sep } from 'path';
import { Connection } from '@salesforce/core';
import { readFileSync } from 'graceful-fs';
import { SaveResult } from 'jsforce';
import { DeployError } from '../../errors';
import { SourceComponent } from '../../resolve';
import { SourceDeployResult, ToolingCreateResult } from '../types';
import { SourceDeployResult } from '../types';

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
const DOMParser = require('xmldom-sfdx-encoding').DOMParser;
Expand Down Expand Up @@ -55,18 +56,15 @@ export abstract class BaseDeploy {

// If bundle already exists then use Id and update existing
// else, create a new bundle
public async upsertBundle(Id?: string): Promise<ToolingCreateResult> {
public async upsertBundle(Id?: string): Promise<SaveResult> {
const metadataContent = readFileSync(this.component.xml, 'utf8');
const metadataField = this.buildMetadataField(metadataContent);

let bundleResult: ToolingCreateResult;
let bundleResult: SaveResult;
if (Id) {
const bundleObject = { Id, Metadata: metadataField };

bundleResult = (await this.connection.tooling.update(
this.component.type.name,
bundleObject
)) as ToolingCreateResult;
bundleResult = await this.connection.tooling.update(this.component.type.name, bundleObject);
} else {
const bundleObject = {
FullName: this.component.fullName,
Expand All @@ -83,8 +81,8 @@ export abstract class BaseDeploy {
return bundleResult;
}

protected async toolingCreate(type: string, record: Record<string, unknown>): Promise<ToolingCreateResult> {
return (await this.connection.tooling.create(type, record)) as ToolingCreateResult;
protected async toolingCreate(type: string, record: Record<string, unknown>): Promise<SaveResult> {
return await this.connection.tooling.create(type, record);
}

protected getFormattedPaths(filepath: string): string[] {
Expand Down
11 changes: 4 additions & 7 deletions src/client/deployStrategies/containerDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { readFileSync } from 'graceful-fs';
import { sleep } from '@salesforce/kit';

import { SaveResult } from 'jsforce';
import { deployTypes } from '../toolingApi';
import { DeployError } from '../../errors';
import {
Expand All @@ -17,7 +18,6 @@ import {
QueryResult,
RecordId,
SourceDeployResult,
ToolingCreateResult,
ToolingDeployStatus,
} from '../types';
import { baseName } from '../../utils/path';
Expand All @@ -41,7 +41,7 @@ export class ContainerDeploy extends BaseDeploy {
return this.buildSourceDeployResult(containerRequestStatus);
}

public async createMetadataContainer(): Promise<ToolingCreateResult> {
public async createMetadataContainer(): Promise<SaveResult> {
const metadataContainer = await this.toolingCreate(ContainerDeploy.METADATA_CONTAINER, {
Name: `Deploy_MDC_${Date.now()}`,
});
Expand All @@ -52,10 +52,7 @@ export class ContainerDeploy extends BaseDeploy {
return metadataContainer;
}

public async createContainerMember(
outboundFiles: string[],
container: ToolingCreateResult
): Promise<ToolingCreateResult> {
public async createContainerMember(outboundFiles: string[], container: SaveResult): Promise<SaveResult> {
const id = container.id;
const metadataContent = readFileSync(outboundFiles[1], 'utf8');
const metadataField = this.buildMetadataField(metadataContent);
Expand Down Expand Up @@ -92,7 +89,7 @@ export class ContainerDeploy extends BaseDeploy {
return queryResult && queryResult.records.length === 1 ? queryResult.records[0].Id : undefined;
}

public async createContainerAsyncRequest(container: ToolingCreateResult): Promise<ToolingCreateResult> {
public async createContainerAsyncRequest(container: SaveResult): Promise<SaveResult> {
const contAsyncRequest = await this.toolingCreate(ContainerDeploy.CONTAINER_ASYNC_REQUEST, {
MetadataContainerId: container.id,
});
Expand Down
1 change: 0 additions & 1 deletion src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export {
VFRecord,
AuraRecord,
LWCRecord,
ToolingCreateResult,
AuraDefinition,
LightningComponentResource,
} from './types';
13 changes: 3 additions & 10 deletions src/client/metadataApiDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
MetadataTransferResult,
} from './types';
import { DiagnosticUtil } from './diagnosticUtil';

export class DeployResult implements MetadataTransferResult {
public readonly response: MetadataApiDeployStatus;
public readonly components: ComponentSet;
Expand Down Expand Up @@ -312,19 +313,11 @@ export class MetadataApiDeploy extends MetadataTransfer<MetadataApiDeployStatus,

await new Promise((resolve, reject) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,no-underscore-dangle
connection.metadata
void connection.metadata
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore _invoke is private on the jsforce metadata object, and cancelDeploy is not an exposed method
._invoke('cancelDeploy', { id: this.id })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make a WI to

  1. add a proper cancel method to the metadata class
  2. update this code to use it instead of this nastiness

.thenCall((result: unknown) => {
// this does not return CancelDeployResult as documented in the API.
// a null result seems to indicate the request was successful
if (result) {
reject(result);
} else {
resolve(result);
}
});
.then((result) => (result ? reject(result) : resolve(result)));
});
}

Expand Down
7 changes: 3 additions & 4 deletions src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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 { SaveResult } from 'jsforce';
import { ComponentSet } from '../collections';
import { PackageTypeMembers } from '../collections/types';
import { SourcePath } from '../common/types';
Expand Down Expand Up @@ -446,13 +447,11 @@ export interface ListMetadataQuery {
folder?: string;
}

export interface ToolingCreateResult {
export type ToolingCreateResult = SaveResult & {
id: string;
success: boolean;
errors: string[];
name: string;
message: string;
}
};

export interface AuraDefinition {
FilePath: string;
Expand Down
8 changes: 4 additions & 4 deletions src/collections/componentSetBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/* eslint complexity: ["error", 22] */

import * as path from 'path';
import { Aliases, Logger, SfdxError } from '@salesforce/core';
import { GlobalInfo, Logger, SfError } from '@salesforce/core';
import * as fs from 'graceful-fs';
import { ComponentSet } from '../collections';
import { RegistryAccess } from '../registry';
Expand Down Expand Up @@ -59,7 +59,7 @@ export class ComponentSetBuilder {
logger.debug(`Building ComponentSet from sourcepath: ${sourcepath.join(', ')}`);
const fsPaths: string[] = sourcepath.map((filepath) => {
if (!fs.existsSync(filepath)) {
throw new SfdxError(`The sourcepath "${filepath}" is not a valid source file path.`);
throw new SfError(`The sourcepath "${filepath}" is not a valid source file path.`);
}
return path.resolve(filepath);
});
Expand Down Expand Up @@ -123,7 +123,7 @@ export class ComponentSetBuilder {
logger.debug(`Building ComponentSet from targetUsername: ${org.username}`);
const fromConnection = await ComponentSet.fromConnection({
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
usernameOrConnection: (await Aliases.fetch(org.username)) || org.username,
usernameOrConnection: (await GlobalInfo.getInstance()).aliases.getUsername(org.username) || org.username,
// exclude components based on the results of componentFilter function
// components with namespacePrefix where org.exclude includes manageableState (to exclude managed packages)
// components with namespacePrefix where manageableState equals undefined (to exclude components e.g. InstalledPackage)
Expand All @@ -140,7 +140,7 @@ export class ComponentSetBuilder {
// to remain generic to catch missing metadata types regardless of parameters, split on '
// example message : Missing metadata type definition in registry for id 'NonExistentType'
const issueType = (e as Error).message.split("'")[1];
throw new SfdxError(`The specified metadata type is unsupported: [${issueType}]`);
throw new SfError(`The specified metadata type is unsupported: [${issueType}]`);
} else {
throw e;
}
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export {
VFRecord,
AuraRecord,
LWCRecord,
ToolingCreateResult,
AuraDefinition,
LightningComponentResource,
} from './client';
Expand Down
31 changes: 18 additions & 13 deletions test/client/deployStrategies/auraDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { AuthInfo, Connection } from '@salesforce/core';
import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup';
import { expect } from 'chai';
import * as fs from 'graceful-fs';
import { RecordResult } from 'jsforce';
import { SaveError, SaveResult } from 'jsforce';
import { createSandbox, SinonSandbox } from 'sinon';
import { AnyJson } from '@salesforce/ts-types';
import { nls } from '../../../src/i18n';
import { ToolingDeployStatus, ComponentStatus } from '../../../src/client';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there an eslint rule for alphabetizing imports that we can turn on to have less of this happen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is... but I couldn't get it working to match what my IDE did. I'll turn off that setting

import { ComponentStatus, ToolingDeployStatus } from '../../../src/client';
import { AuraDeploy } from '../../../src/client/deployStrategies';
import { ToolingCreateResult, AuraDefinition } from '../../../src/client/types';
import { auraContents, auraComponent, auraFiles, testAuraList } from './auraDeployMocks';
import { AuraDefinition, ToolingCreateResult } from '../../../src/client/types';
import { auraComponent, auraContents, auraFiles, testAuraList } from './auraDeployMocks';

const $$ = testSetup();

Expand All @@ -36,9 +37,13 @@ describe('Aura Deploy Strategy', () => {

beforeEach(async () => {
sandboxStub = createSandbox();
$$.setConfigStubContents('AuthInfoConfig', {
contents: await testData.getConfig(),
});
$$.configStubs.GlobalInfo = {
contents: {
orgs: Object.assign($$.configStubs.GlobalInfo?.contents?.orgs || {}, {
[testData.username]: testData as unknown as AnyJson,
}),
},
};
mockConnection = await Connection.create({
authInfo: await AuthInfo.create({
username: testData.username,
Expand Down Expand Up @@ -74,7 +79,7 @@ describe('Aura Deploy Strategy', () => {
success: true,
id: '1dcxxx000000060',
errors: [],
} as RecordResult);
} as SaveResult);

const auraDeploy = new AuraDeploy(mockConnection);
auraDeploy.component = auraComponent;
Expand Down Expand Up @@ -162,7 +167,7 @@ describe('Aura Deploy Strategy', () => {
success: true,
id: '1dcxxx000000034',
errors: [],
} as RecordResult);
} as SaveResult);

sandboxStub.stub(AuraDeploy.prototype, 'buildMetadataField').returns(testMetadataField);
const auraDeploy = new AuraDeploy(mockConnection);
Expand All @@ -183,7 +188,7 @@ describe('Aura Deploy Strategy', () => {
success: true,
id: '1dcxxx000000034',
errors: [],
} as RecordResult);
} as SaveResult);

sandboxStub.stub(AuraDeploy.prototype, 'buildMetadataField').returns(testMetadataField);
const auraDeploy = new AuraDeploy(mockConnection);
Expand All @@ -202,8 +207,8 @@ describe('Aura Deploy Strategy', () => {
sandboxStub.stub(mockConnection.tooling, 'create').resolves({
success: false,
id: '',
errors: ['Unexpected error while creating record'],
} as RecordResult);
errors: [{ message: 'Unexpected error while creating record', errorCode: '1' } as SaveError],
} as SaveResult);

sandboxStub.stub(AuraDeploy.prototype, 'buildMetadataField').returns(testMetadataField);
const auraDeploy = new AuraDeploy(mockConnection);
Expand All @@ -223,7 +228,7 @@ describe('Aura Deploy Strategy', () => {
success: true,
id: '1dcxxx000000034',
errors: [],
} as RecordResult);
} as SaveResult);

sandboxStub.stub(AuraDeploy.prototype, 'buildMetadataField').returns(testMetadataField);

Expand Down
12 changes: 9 additions & 3 deletions test/client/deployStrategies/baseDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup';
import { assert, expect } from 'chai';
import * as fs from 'graceful-fs';
import { createSandbox, SinonSandbox } from 'sinon';
import { AnyJson } from '@salesforce/ts-types';
import { ContainerDeploy } from '../../../src/client/deployStrategies';
import { nls } from '../../../src/i18n';

Expand All @@ -27,14 +28,19 @@ describe('Base Deploy Strategy', () => {

beforeEach(async () => {
sandboxStub = createSandbox();
$$.setConfigStubContents('AuthInfoConfig', {
contents: await testData.getConfig(),
});
$$.configStubs.GlobalInfo = {
contents: {
orgs: Object.assign($$.configStubs.GlobalInfo?.contents?.orgs || {}, {
[testData.username]: testData as unknown as AnyJson,
}),
},
};
mockConnection = await Connection.create({
authInfo: await AuthInfo.create({
username: testData.username,
}),
});

const mockFS = sandboxStub.stub(fs, 'readFileSync');
mockFS.withArgs('file/path/one.cls', 'utf8').returns('public with sharing class TestAPI {}');

Expand Down
Loading