Skip to content

Commit 9b2d347

Browse files
authored
feat(cli): use hpagent (stoplightio#2513)
1 parent ed6b65c commit 9b2d347

File tree

5 files changed

+30
-282
lines changed

5 files changed

+30
-282
lines changed

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
"@stoplight/types": "^13.6.0",
4545
"chalk": "4.1.2",
4646
"fast-glob": "~3.2.12",
47+
"hpagent": "~1.2.0",
4748
"lodash": "~4.17.21",
4849
"pony-cause": "^1.0.0",
49-
"proxy-agent": "5.0.0",
5050
"stacktracey": "^2.1.7",
5151
"tslib": "^2.3.0",
5252
"yargs": "17.3.1"

packages/cli/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import * as yargs from 'yargs';
44

55
import { DEFAULT_REQUEST_OPTIONS } from '@stoplight/spectral-runtime';
66
import lintCommand from './commands/lint';
7-
import type * as Agent from 'proxy-agent';
87

98
if (typeof process.env.PROXY === 'string') {
9+
const { protocol } = new URL(process.env.PROXY);
1010
// eslint-disable-next-line @typescript-eslint/no-var-requires
11-
const ProxyAgent = require('proxy-agent') as typeof Agent['default'];
12-
DEFAULT_REQUEST_OPTIONS.agent = new ProxyAgent(process.env.PROXY);
11+
const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent') as typeof import('hpagent');
12+
DEFAULT_REQUEST_OPTIONS.agent = new (protocol === 'https:' ? HttpsProxyAgent : HttpProxyAgent)({
13+
proxy: process.env.PROXY,
14+
});
1315
}
1416

1517
export default yargs

packages/cli/src/services/linter/linter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { CLIError } from '../../errors';
99

1010
export async function lint(documents: Array<number | string>, flags: ILintConfig): Promise<IRuleResult[]> {
1111
const spectral = new Spectral({
12-
resolver: getResolver(flags.resolver, process.env.PROXY),
12+
resolver: getResolver(flags.resolver),
1313
});
1414

1515
const ruleset = await getRuleset(flags.ruleset);

packages/cli/src/services/linter/utils/getResolver.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createHttpAndFileResolver, Resolver } from '@stoplight/spectral-ref-res
44
import { isError } from 'lodash';
55
import { CLIError } from '../../../errors';
66

7-
export const getResolver = (resolver: Optional<string>, proxy: Optional<string>): Resolver => {
7+
export const getResolver = (resolver: Optional<string>): Resolver => {
88
if (resolver !== void 0) {
99
try {
1010
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
@@ -14,12 +14,6 @@ export const getResolver = (resolver: Optional<string>, proxy: Optional<string>)
1414
}
1515
}
1616

17-
if (typeof proxy === 'string') {
18-
// eslint-disable-next-line @typescript-eslint/no-var-requires
19-
const ProxyAgent = require('proxy-agent') as typeof import('proxy-agent');
20-
return createHttpAndFileResolver({ agent: new ProxyAgent(process.env.PROXY) });
21-
}
22-
2317
return createHttpAndFileResolver();
2418
};
2519

0 commit comments

Comments
 (0)