Skip to content

Commit

Permalink
fix: bump proxy-agent to new major version (#429)
Browse files Browse the repository at this point in the history
* fix: bump proxy-agent to new major version

* style: reduce eslint comments

---------

Co-authored-by: mshanemc <[email protected]>
  • Loading branch information
shetzel and mshanemc authored Jun 12, 2023
1 parent 4edadfd commit 20b0680
Show file tree
Hide file tree
Showing 12 changed files with 1,380 additions and 1,100 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"marked": "^4.3.0",
"marked-terminal": "^4.2.0",
"open": "^8.4.2",
"proxy-agent": "^5.0.0",
"proxy-from-env": "^1.1.0",
"proxy-agent": "^6.2.1",
"semver": "^7.5.0",
"tslib": "^2"
},
Expand All @@ -31,7 +30,6 @@
"@types/fs-extra": "^9.0.13",
"@types/marked": "^4.0.8",
"@types/marked-terminal": "^3.1.3",
"@types/proxy-from-env": "^1.0.1",
"@types/semver": "^7.5.0",
"@types/sinon-chai": "^3.2.9",
"@typescript-eslint/eslint-plugin": "^5.59.8",
Expand Down Expand Up @@ -233,4 +231,4 @@
"output": []
}
}
}
}
8 changes: 3 additions & 5 deletions src/commands/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { Flags, loglevel, SfCommand } from '@salesforce/sf-plugins-core';
import { Lifecycle, Messages, SfError } from '@salesforce/core';
import * as open from 'open';
import got from 'got';
import * as ProxyAgent from 'proxy-agent';
import { getProxyForUrl } from 'proxy-from-env';
import { ProxyAgent } from 'proxy-agent';
import { Doctor as SFDoctor, SfDoctor, SfDoctorDiagnosis } from '../doctor';
import { DiagnosticStatus } from '../diagnostics';

Expand Down Expand Up @@ -63,10 +62,9 @@ export default class Doctor extends SfCommand<SfDoctorDiagnosis> {

this.outputDir = path.resolve(flags['output-dir'] ?? process.cwd());

// eslint-disable-next-line @typescript-eslint/require-await
lifecycle.on<DiagnosticStatus>('Doctor:diagnostic', async (data) => {
this.log(`${data.status} - ${data.testName}`);
this.doctor.addDiagnosticStatus(data);
return Promise.resolve(this.doctor.addDiagnosticStatus(data));
});

if (flags.command) {
Expand Down Expand Up @@ -120,7 +118,7 @@ export default class Doctor extends SfCommand<SfDoctorDiagnosis> {
const raw = 'https://raw.githubusercontent.com/forcedotcom/cli/main/.github/ISSUE_TEMPLATE/bug_report.md';
const ghIssue = await got(raw, {
throwHttpErrors: false,
agent: { https: ProxyAgent(getProxyForUrl(raw)) },
agent: { https: new ProxyAgent() },
});

const title = (
Expand Down
3 changes: 0 additions & 3 deletions src/commands/info/releasenotes/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

// Needed this to ensure the "helpers" were declared before read in examples
/* eslint-disable @typescript-eslint/member-ordering */

import * as os from 'os';
import { marked } from 'marked';
import * as TerminalRenderer from 'marked-terminal';
Expand Down
33 changes: 15 additions & 18 deletions src/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class Doctor implements SfDoctor {
*/
public writeFileSync(filePath: string, contents: string): string {
const fullPath = this.getDoctoredFilePath(filePath);
this.createOutputDir(fullPath);
createOutputDir(fullPath);
this.diagnosis.logFilePaths.push(fullPath);
fs.writeFileSync(fullPath, contents);
return fullPath;
Expand All @@ -209,26 +209,26 @@ export class Doctor implements SfDoctor {
if (!this.stdoutWriteStream) {
throw new SfError(messages.getMessage('doctorNotInitializedError'), 'SfDoctorInitError');
}
return this.writeFile(this.stdoutWriteStream, contents);
return writeFile(this.stdoutWriteStream, contents);
}

public writeStderr(contents: string): Promise<boolean> {
if (!this.stderrWriteStream) {
throw new SfError(messages.getMessage('doctorNotInitializedError'), 'SfDoctorInitError');
}
return this.writeFile(this.stderrWriteStream, contents);
return writeFile(this.stderrWriteStream, contents);
}

public createStdoutWriteStream(fullPath: string): void {
if (!this.stdoutWriteStream) {
this.createOutputDir(fullPath);
createOutputDir(fullPath);
this.stdoutWriteStream = fs.createWriteStream(fullPath);
}
}

public createStderrWriteStream(fullPath: string): void {
if (!this.stderrWriteStream) {
this.createOutputDir(fullPath);
createOutputDir(fullPath);
this.stderrWriteStream = fs.createWriteStream(path.join(fullPath));
}
}
Expand All @@ -254,19 +254,6 @@ export class Doctor implements SfDoctor {
public setExitCode(code: string | number): void {
this.diagnosis.commandExitCode = code;
}

// eslint-disable-next-line class-methods-use-this
private writeFile(stream: fs.WriteStream, contents: string): Promise<boolean> {
return Promise.resolve(stream.write(contents));
}

// eslint-disable-next-line class-methods-use-this
private createOutputDir(fullPath: string): void {
const dir = path.dirname(fullPath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
}
}

export function formatPlugins(config: Interfaces.Config, plugins: Record<string, PluginVersionDetail>): string[] {
Expand All @@ -286,3 +273,13 @@ export function formatPlugins(config: Interfaces.Config, plugins: Record<string,
}`.trim()
);
}

const createOutputDir = (fullPath: string): void => {
const dir = path.dirname(fullPath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
};

const writeFile = (stream: fs.WriteStream, contents: string): Promise<boolean> =>
Promise.resolve(stream.write(contents));
5 changes: 2 additions & 3 deletions src/shared/getDistTagVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/

import got from 'got';
import * as ProxyAgent from 'proxy-agent';
import { getProxyForUrl } from 'proxy-from-env';
import { ProxyAgent } from 'proxy-agent';
import { SFDX_RELEASE_NOTES_TIMEOUT } from '../constants';

export type DistTagJson = {
Expand All @@ -18,7 +17,7 @@ export type DistTagJson = {
const getDistTagVersion = async (url: string, distTag: string): Promise<string> => {
// TODO: Could use npm instead here. That way private cli repos could auth with .npmrc
// -- could utilize this: https://github.com/salesforcecli/plugin-trust/blob/0393b906a30e8858816625517eda5db69377c178/src/lib/npmCommand.ts
const options = { timeout: SFDX_RELEASE_NOTES_TIMEOUT, agent: { https: ProxyAgent(getProxyForUrl(url)) } };
const options = { timeout: SFDX_RELEASE_NOTES_TIMEOUT, agent: { https: new ProxyAgent() } };

const body = await got(url, options).json<DistTagJson>();

Expand Down
5 changes: 2 additions & 3 deletions src/shared/getReleaseNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import got from 'got';
import { major } from 'semver';
import { getProxyForUrl } from 'proxy-from-env';
import * as ProxyAgent from 'proxy-agent';
import { ProxyAgent } from 'proxy-agent';
import { SFDX_RELEASE_NOTES_TIMEOUT } from '../constants';

const getReleaseNotes = async (base: string, filename: string, version: string): Promise<string> => {
Expand All @@ -19,7 +18,7 @@ const getReleaseNotes = async (base: string, filename: string, version: string):
const options = {
timeout: SFDX_RELEASE_NOTES_TIMEOUT,
throwHttpErrors: false,
agent: { https: ProxyAgent(getProxyForUrl(rawBase)) },
agent: { https: new ProxyAgent() },
};

const getPromises = [
Expand Down
1 change: 0 additions & 1 deletion test/commands/info/releasenotes/display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import * as getDistTagVersion from '../../../../src/shared/getDistTagVersion';
import * as parseReleaseNotes from '../../../../src/shared/parseReleaseNotes';
import Display from '../../../../src/commands/info/releasenotes/display';

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
chaiUse(SinonChai);

describe('sfdx info:releasenotes:display', () => {
Expand Down
8 changes: 3 additions & 5 deletions test/shared/getDistTagVersion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import got from 'got';
import { expect, use as chaiUse } from 'chai';
import * as Sinon from 'sinon';
import * as SinonChai from 'sinon-chai';
import { ProxyAgent } from 'proxy-agent';
import { stubMethod } from '@salesforce/ts-sinon';
import { getDistTagVersion, DistTagJson } from '../../src/shared/getDistTagVersion';

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
chaiUse(SinonChai);

describe('getDistTagVersion tests', () => {
Expand Down Expand Up @@ -44,10 +44,8 @@ describe('getDistTagVersion tests', () => {
await getDistTagVersion(url, 'latest');

expect(gotStub.args[0][0]).to.equal(url);
expect(JSON.parse(JSON.stringify(gotStub.args[0][1])), JSON.stringify(gotStub.args[0][1])).to.deep.equal({
agent: { https: {} },
timeout: 3000,
});
expect(gotStub.args[0][1]).to.have.property('timeout', 3000);
expect(gotStub.args[0][1]).to.have.property('agent').and.to.have.property('https').and.be.instanceOf(ProxyAgent);
});

it('returns rc if version is "latest-rc"', async () => {
Expand Down
9 changes: 3 additions & 6 deletions test/shared/getInfoConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@

import * as pathPkg from 'path';
import * as fs from 'fs';
import { expect, use as chaiUse } from 'chai';
import { expect, use as chaiUse, assert } from 'chai';
import * as Sinon from 'sinon';
import * as SinonChai from 'sinon-chai';
import { stubMethod, spyMethod } from '@salesforce/ts-sinon';
import { shouldThrow } from '@salesforce/core/lib/testSetup';
import { getInfoConfig, PjsonWithInfo } from '../../src/shared/getInfoConfig';

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
chaiUse(SinonChai);

describe('getInfoConfig tests', () => {
Expand Down Expand Up @@ -70,8 +69,6 @@ describe('getInfoConfig tests', () => {

it('info config is extracted from package.json', async () => {
const info = await getInfoConfig(path);

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(info).to.deep.equal(pjsonMock.oclif.info);
});

Expand All @@ -81,8 +78,8 @@ describe('getInfoConfig tests', () => {
try {
await shouldThrow(getInfoConfig(path));
} catch (err) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect((err as Error).message).to.equal('getInfoConfig() failed to find pjson.oclif.info config');
assert(err instanceof Error);
expect(err.message).to.equal('getInfoConfig() failed to find pjson.oclif.info config');
}
});
});
24 changes: 13 additions & 11 deletions test/shared/getReleaseNotes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import * as Sinon from 'sinon';
import * as semver from 'semver';
import { stubMethod, spyMethod } from '@salesforce/ts-sinon';
import * as SinonChai from 'sinon-chai';
import { ProxyAgent } from 'proxy-agent';
import { getReleaseNotes } from '../../src/shared/getReleaseNotes';
import { SFDX_RELEASE_NOTES_TIMEOUT } from '../../src/constants';

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
chaiUse(SinonChai);

type gotResponse = {
Expand All @@ -32,7 +32,6 @@ describe('getReleaseNotes tests', () => {
let rawPath: string;
let version: string;
let filename: string;
let options: Record<string, unknown>;
let versionedResponse: gotResponse;
let readmeResponse: gotResponse;

Expand All @@ -41,11 +40,6 @@ describe('getReleaseNotes tests', () => {
rawPath = 'https://raw.githubusercontent.com/forcedotcom/cli/main/releasenotes/sfdx';
version = '1.2.3';
filename = 'readme.md';
options = {
agent: { https: {} },
timeout: SFDX_RELEASE_NOTES_TIMEOUT,
throwHttpErrors: false,
};
versionedResponse = {
statusCode: 200,
body: 'versioned response body',
Expand Down Expand Up @@ -82,17 +76,25 @@ describe('getReleaseNotes tests', () => {
it('makes versioned GET request with correct args', async () => {
await getReleaseNotes(path, filename, version);

const expected = [`${rawPath}/v1.md`, options];
// const expected = [`${rawPath}/v1.md`, options];

expect(JSON.parse(JSON.stringify(gotStub.args[0]))).to.deep.equal(expected);
// expect(JSON.parse(JSON.stringify(gotStub.args[0]))).to.deep.equal(expected);
expect(gotStub.args[0][0]).to.equal(`${rawPath}/v1.md`);
expect(gotStub.args[0][1]).to.have.property('timeout').and.equal(SFDX_RELEASE_NOTES_TIMEOUT);
expect(gotStub.args[0][1]).to.have.property('throwHttpErrors').and.equal(false);
expect(gotStub.args[0][1]).to.have.property('agent').and.to.have.property('https').and.be.instanceOf(ProxyAgent);
});

it('makes readme GET request with correct args', async () => {
await getReleaseNotes(path, filename, version);

const expected = [`${rawPath}/${filename}`, { ...options, throwHttpErrors: true }];
// const expected = [`${rawPath}/${filename}`, { ...options, throwHttpErrors: true }];

expect(JSON.parse(JSON.stringify(gotStub.args[1]))).to.deep.equal(expected);
// expect(JSON.parse(JSON.stringify(gotStub.args[1]))).to.deep.equal(expected);
expect(gotStub.args[1][0]).to.equal(`${rawPath}/${filename}`);
expect(gotStub.args[1][1]).to.have.property('timeout').and.equal(SFDX_RELEASE_NOTES_TIMEOUT);
expect(gotStub.args[1][1]).to.have.property('throwHttpErrors').and.equal(true);
expect(gotStub.args[1][1]).to.have.property('agent').and.to.have.property('https').and.be.instanceOf(ProxyAgent);
});

it('returns versioned markdown if found', async () => {
Expand Down
11 changes: 5 additions & 6 deletions test/shared/parseReleaseNotes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
*/

import * as fs from 'fs';
import { expect, use as chaiUse } from 'chai';
import { expect, use as chaiUse, assert } from 'chai';
import * as Sinon from 'sinon';
import * as SinonChai from 'sinon-chai';
import { spyMethod } from '@salesforce/ts-sinon';
import { marked } from 'marked';
import { parseReleaseNotes } from '../../src/shared/parseReleaseNotes';

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
chaiUse(SinonChai);

describe('parseReleaseNotes tests', () => {
Expand Down Expand Up @@ -54,8 +53,8 @@ describe('parseReleaseNotes tests', () => {
try {
parseReleaseNotes(notes, '1.2.3', baseUrl);
} catch (err) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect((err as Error).message).to.equal(`Didn't find version '1.2.3'. View release notes online at: ${baseUrl}`);
assert(err instanceof Error);
expect(err.message).to.equal(`Didn't find version '1.2.3'. View release notes online at: ${baseUrl}`);
}
});

Expand All @@ -71,8 +70,8 @@ describe('parseReleaseNotes tests', () => {
// Won't find partial version (3.3.1 is part of 13.3.1)
parseReleaseNotes(notes, '3.3.1', baseUrl);
} catch (err) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect((err as Error).message).to.equal(`Didn't find version '3.3.1'. View release notes online at: ${baseUrl}`);
assert(err instanceof Error);
expect(err.message).to.equal(`Didn't find version '3.3.1'. View release notes online at: ${baseUrl}`);
}
});

Expand Down
Loading

0 comments on commit 20b0680

Please sign in to comment.