Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): use hpagent in favor of proxy-agent #2513

Merged
merged 2 commits into from
Jul 25, 2023
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
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"@stoplight/types": "^13.6.0",
"chalk": "4.1.2",
"fast-glob": "~3.2.12",
"hpagent": "~1.2.0",
"lodash": "~4.17.21",
"pony-cause": "^1.0.0",
"proxy-agent": "5.0.0",
"stacktracey": "^2.1.7",
"tslib": "^2.3.0",
"yargs": "17.3.1"
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import * as yargs from 'yargs';

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

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

export default yargs
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/services/linter/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CLIError } from '../../errors';

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

const ruleset = await getRuleset(flags.ruleset);
Expand Down
8 changes: 1 addition & 7 deletions packages/cli/src/services/linter/utils/getResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createHttpAndFileResolver, Resolver } from '@stoplight/spectral-ref-res
import { isError } from 'lodash';
import { CLIError } from '../../../errors';

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

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

return createHttpAndFileResolver();
};

Expand Down
Loading