Skip to content

Commit b8b3a50

Browse files
authored
Sm/ts updates (#294)
* refactor: ts fixes * chore: more ts fixes * chore: bump ts * fix: assert sourcepath as string[]
1 parent d716542 commit b8b3a50

File tree

17 files changed

+60
-54
lines changed

17 files changed

+60
-54
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"shx": "0.3.3",
5959
"sinon": "10.0.0",
6060
"ts-node": "^10.2.1",
61-
"typescript": "^4.1.3"
61+
"typescript": "^4.4.4"
6262
},
6363
"config": {
6464
"commitizen": {

src/commands/force/mdapi/describemetadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class DescribeMetadata extends SourceCommand {
9898

9999
private validateResultFile(): void {
100100
if (this.flags.resultfile) {
101-
this.targetFilePath = path.resolve(this.flags.resultfile);
101+
this.targetFilePath = path.resolve(this.getFlag('resultfile'));
102102
// Ensure path exists
103103
fs.mkdirSync(path.dirname(this.targetFilePath), { recursive: true });
104104
try {

src/commands/force/mdapi/listmetadata.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ export class ListMetadata extends SourceCommand {
8989
if (this.listResult.length) {
9090
this.ux.styledJSON(this.listResult);
9191
} else {
92-
this.ux.log(messages.getMessage('noMatchingMetadata', [this.flags.metadatatype, this.org.getUsername()]));
92+
this.ux.log(messages.getMessage('noMatchingMetadata', [this.getFlag('metadatatype'), this.org.getUsername()]));
9393
}
9494
}
9595
return this.listResult;
9696
}
9797

9898
private validateResultFile(): void {
9999
if (this.flags.resultfile) {
100-
this.targetFilePath = path.resolve(this.flags.resultfile);
100+
this.targetFilePath = path.resolve(this.getFlag('resultfile'));
101101
// Ensure path exists
102102
fs.mkdirSync(path.dirname(this.targetFilePath), { recursive: true });
103103
try {

src/commands/force/source/convert.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ export class Convert extends SourceCommand {
6969
const { sourcepath, metadata, manifest, rootdir } = this.flags;
7070

7171
if (sourcepath) {
72-
paths.push(...sourcepath);
72+
paths.push(...(sourcepath as string[]));
7373
}
7474

7575
// rootdir behaves exclusively to sourcepath, metadata, and manifest... to maintain backwards compatibility
7676
// we will check here, instead of adding the exclusive option to the flag definition so we don't break scripts
77-
if (rootdir && !sourcepath && !metadata && !manifest) {
77+
if (rootdir && !sourcepath && !metadata && !manifest && typeof rootdir === 'string') {
7878
// only rootdir option passed
7979
paths.push(rootdir);
8080
}

src/commands/force/source/delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class Delete extends DeployCommand {
8383
private aborted = false;
8484
private components: MetadataComponent[];
8585

86-
private updateDeployId = once((id) => {
86+
private updateDeployId = once((id: string) => {
8787
this.displayDeployId(id);
8888
this.setStash(id);
8989
});

src/commands/force/source/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class Deploy extends DeployCommand {
122122
private isRest = false;
123123
private asyncDeployResult: AsyncResult;
124124

125-
private updateDeployId = once((id) => {
125+
private updateDeployId = once((id: string) => {
126126
this.displayDeployId(id);
127127
this.setStash(id);
128128
});

src/commands/force/source/open.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class Open extends SourceCommand {
6060
}
6161

6262
private async doOpen(): Promise<void> {
63-
const typeName = this.getTypeNameDefinitionByFileName(path.resolve(this.flags.sourcefile));
63+
const typeName = this.getTypeNameDefinitionByFileName(path.resolve(this.flags.sourcefile as string));
6464
const openPath = typeName === 'FlexiPage' ? await this.setUpOpenPath() : await this.buildFrontdoorUrl();
6565

6666
this.openResult = await this.open(openPath);
@@ -104,7 +104,7 @@ export class Open extends SourceCommand {
104104
.getConnection()
105105
.singleRecordQuery<{ Id: string }>(
106106
`SELECT id FROM flexipage WHERE DeveloperName='${path.basename(
107-
this.flags.sourcefile,
107+
this.flags.sourcefile as string,
108108
'.flexipage-meta.xml'
109109
)}'`,
110110
{ tooling: true }

test/commands/mdapi/describemetadata.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe('force:mdapi:describemetadata', () => {
117117
expect(uxLogStub.called).to.be.true; // called but not actually written to console
118118
expect(uxStyledJsonStub.called).to.be.false;
119119
expect(fsWriteFileStub.firstCall.args[0]).to.include(resultfile);
120-
expect(JSON.parse(fsWriteFileStub.firstCall.args[1])).to.deep.equal(describeResponse);
120+
expect(JSON.parse(fsWriteFileStub.firstCall.args[1] as string)).to.deep.equal(describeResponse);
121121
});
122122

123123
it('should report to a file (display)', async () => {
@@ -130,7 +130,7 @@ describe('force:mdapi:describemetadata', () => {
130130
expect(uxLogStub.firstCall.args[0]).to.include(resultfile);
131131
expect(uxStyledJsonStub.called).to.be.false;
132132
expect(fsWriteFileStub.firstCall.args[0]).to.include(resultfile);
133-
expect(JSON.parse(fsWriteFileStub.firstCall.args[1])).to.deep.equal(describeResponse);
133+
expect(JSON.parse(fsWriteFileStub.firstCall.args[1] as string)).to.deep.equal(describeResponse);
134134
});
135135

136136
it('should report with a specific API version', async () => {

test/commands/mdapi/listmetadata.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe('force:mdapi:listmetadata', () => {
144144
expect(uxLogStub.called).to.be.true; // called but not actually written to console
145145
expect(uxStyledJsonStub.called).to.be.false;
146146
expect(fsWriteFileStub.firstCall.args[0]).to.include(resultfile);
147-
expect(JSON.parse(fsWriteFileStub.firstCall.args[1])).to.deep.equal([listResponse]);
147+
expect(JSON.parse(fsWriteFileStub.firstCall.args[1] as string)).to.deep.equal([listResponse]);
148148
});
149149

150150
it('should report to a file (display)', async () => {
@@ -157,7 +157,7 @@ describe('force:mdapi:listmetadata', () => {
157157
expect(uxLogStub.firstCall.args[0]).to.include(resultfile);
158158
expect(uxStyledJsonStub.called).to.be.false;
159159
expect(fsWriteFileStub.firstCall.args[0]).to.include(resultfile);
160-
expect(JSON.parse(fsWriteFileStub.firstCall.args[1])).to.deep.equal([listResponse]);
160+
expect(JSON.parse(fsWriteFileStub.firstCall.args[1] as string)).to.deep.equal([listResponse]);
161161
});
162162

163163
it('should report with a folder', async () => {

test/formatters/deployResultFormatter.test.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('DeployResultFormatter', () => {
2727

2828
const logger = Logger.childFromRoot('deployTestLogger').useMemoryLogging();
2929
let ux;
30+
3031
let logStub: sinon.SinonStub;
3132
let styledHeaderStub: sinon.SinonStub;
3233
let tableStub: sinon.SinonStub;
@@ -58,7 +59,7 @@ describe('DeployResultFormatter', () => {
5859
it('should return expected json for a success', async () => {
5960
const deployResponse = JSON.parse(JSON.stringify(deployResultSuccess.response)) as DeployCommandResult;
6061
const expectedSuccessResults = deployResultSuccess.response as DeployCommandResult;
61-
const formatter = new DeployResultFormatter(logger, ux, {}, deployResultSuccess);
62+
const formatter = new DeployResultFormatter(logger, ux as UX, {}, deployResultSuccess);
6263
const json = formatter.getJson();
6364

6465
expectedSuccessResults.deployedSource = deployResultSuccess.getFileResponses();
@@ -73,7 +74,7 @@ describe('DeployResultFormatter', () => {
7374
expectedFailureResults.deployedSource = deployResultFailure.getFileResponses();
7475
expectedFailureResults.outboundFiles = [];
7576
expectedFailureResults.deploys = [deployResponse];
76-
const formatter = new DeployResultFormatter(logger, ux, {}, deployResultFailure);
77+
const formatter = new DeployResultFormatter(logger, ux as UX, {}, deployResultFailure);
7778
expect(formatter.getJson()).to.deep.equal(expectedFailureResults);
7879
});
7980

@@ -83,14 +84,14 @@ describe('DeployResultFormatter', () => {
8384
expectedPartialSuccessResponse.deployedSource = deployResultPartialSuccess.getFileResponses();
8485
expectedPartialSuccessResponse.outboundFiles = [];
8586
expectedPartialSuccessResponse.deploys = [deployResponse];
86-
const formatter = new DeployResultFormatter(logger, ux, {}, deployResultPartialSuccess);
87+
const formatter = new DeployResultFormatter(logger, ux as UX, {}, deployResultPartialSuccess);
8788
expect(formatter.getJson()).to.deep.equal(expectedPartialSuccessResponse);
8889
});
8990
});
9091

9192
describe('display', () => {
9293
it('should output as expected for a success', async () => {
93-
const formatter = new DeployResultFormatter(logger, ux, {}, deployResultSuccess);
94+
const formatter = new DeployResultFormatter(logger, ux as UX, {}, deployResultSuccess);
9495
formatter.display();
9596
expect(styledHeaderStub.calledOnce).to.equal(true);
9697
expect(logStub.calledOnce).to.equal(true);
@@ -102,7 +103,7 @@ describe('DeployResultFormatter', () => {
102103
});
103104

104105
it('should output as expected for a failure and exclude duplicate information', async () => {
105-
const formatter = new DeployResultFormatter(logger, ux, {}, deployResultFailure);
106+
const formatter = new DeployResultFormatter(logger, ux as UX, {}, deployResultFailure);
106107
formatter.display();
107108
expect(styledHeaderStub.calledOnce).to.equal(true);
108109
expect(logStub.calledTwice).to.equal(true);
@@ -114,7 +115,7 @@ describe('DeployResultFormatter', () => {
114115
});
115116

116117
it('should output as expected for a test failure with verbose', async () => {
117-
const formatter = new DeployResultFormatter(logger, ux, { verbose: true }, deployResultTestFailure);
118+
const formatter = new DeployResultFormatter(logger, ux as UX, { verbose: true }, deployResultTestFailure);
118119
formatter.display();
119120
expect(styledHeaderStub.calledThrice).to.equal(true);
120121
expect(logStub.callCount).to.equal(7);
@@ -125,7 +126,7 @@ describe('DeployResultFormatter', () => {
125126
});
126127

127128
it('should output as expected for passing tests with verbose', async () => {
128-
const formatter = new DeployResultFormatter(logger, ux, { verbose: true }, deployResultTestSuccess);
129+
const formatter = new DeployResultFormatter(logger, ux as UX, { verbose: true }, deployResultTestSuccess);
129130
formatter.display();
130131
expect(styledHeaderStub.calledThrice).to.equal(true);
131132
expect(logStub.callCount).to.equal(7);
@@ -136,7 +137,12 @@ describe('DeployResultFormatter', () => {
136137
});
137138

138139
it('should output as expected for passing and failing tests with verbose', async () => {
139-
const formatter = new DeployResultFormatter(logger, ux, { verbose: true }, deployResultTestSuccessAndFailure);
140+
const formatter = new DeployResultFormatter(
141+
logger,
142+
ux as UX,
143+
{ verbose: true },
144+
deployResultTestSuccessAndFailure
145+
);
140146
formatter.display();
141147
expect(styledHeaderStub.callCount).to.equal(4);
142148
expect(logStub.callCount).to.equal(8);
@@ -148,7 +154,7 @@ describe('DeployResultFormatter', () => {
148154
});
149155

150156
it('shows success AND failures for partialSucceeded', async () => {
151-
const formatter = new DeployResultFormatter(logger, ux, { verbose: true }, deployResultPartialSuccess);
157+
const formatter = new DeployResultFormatter(logger, ux as UX, { verbose: true }, deployResultPartialSuccess);
152158
formatter.display();
153159
expect(styledHeaderStub.callCount, 'styledHeaderStub.callCount').to.equal(2);
154160
expect(logStub.callCount, 'logStub.callCount').to.equal(3);

0 commit comments

Comments
 (0)