Skip to content

Commit cd3d088

Browse files
committed
Add "prettier" config
1 parent 941efab commit cd3d088

File tree

20 files changed

+130
-122
lines changed

20 files changed

+130
-122
lines changed

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages/*/dist
2+
packages/degenerator/test/*

.prettierrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
"lint": "turbo run lint",
77
"test": "turbo run test",
88
"test-e2e": "turbo run test-e2e",
9-
"format": "prettier --write \"**/*.{ts,tsx,md}\""
9+
"format": "prettier --write \"**/*.{ts,js}\""
1010
},
1111
"devDependencies": {
1212
"@typescript-eslint/eslint-plugin": "^5.59.1",
1313
"@typescript-eslint/parser": "^5.59.1",
1414
"eslint": "^7.32.0",
1515
"eslint-config-prettier": "^8.8.0",
1616
"eslint-config-turbo": "^1.9.3",
17-
"prettier": "^2.5.1",
17+
"prettier": "^2.8.8",
1818
"turbo": "latest"
1919
}
2020
}

packages/agent-base/src/helpers.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
import * as http from "http";
2-
import * as https from "https";
3-
import type { Readable } from "stream";
1+
import * as http from 'http';
2+
import * as https from 'https';
3+
import type { Readable } from 'stream';
44

55
export async function toBuffer(stream: Readable): Promise<Buffer> {
6-
let length = 0;
7-
const chunks: Buffer[] = [];
8-
for await (const chunk of stream) {
9-
length += chunk.length;
10-
chunks.push(chunk);
11-
}
12-
return Buffer.concat(chunks, length);
6+
let length = 0;
7+
const chunks: Buffer[] = [];
8+
for await (const chunk of stream) {
9+
length += chunk.length;
10+
chunks.push(chunk);
11+
}
12+
return Buffer.concat(chunks, length);
1313
}
1414

1515
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1616
export async function json(stream: Readable): Promise<any> {
17-
const buf = await toBuffer(stream);
18-
return JSON.parse(buf.toString('utf8'));
17+
const buf = await toBuffer(stream);
18+
return JSON.parse(buf.toString('utf8'));
1919
}
2020

2121
export function req(
2222
url: string | URL,
2323
opts: https.RequestOptions = {}
2424
): Promise<http.IncomingMessage> {
2525
return new Promise((resolve, reject) => {
26-
const href = typeof url === 'string' ? url : url.href;
27-
(href.startsWith("https:") ? https : http)
26+
const href = typeof url === 'string' ? url : url.href;
27+
(href.startsWith('https:') ? https : http)
2828
.request(url, opts, resolve)
29-
.once("error", reject)
29+
.once('error', reject)
3030
.end();
3131
});
32-
}
32+
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */
22
module.exports = {
3-
preset: 'ts-jest',
4-
testEnvironment: 'node',
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
55
};

packages/degenerator/jest.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */
22
module.exports = {
3-
preset: 'ts-jest',
4-
testEnvironment: 'node',
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
55
};

packages/get-uri/jest.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @type {import('ts-jest').JestConfigWithTsJest} */
22
module.exports = {
3-
preset: 'ts-jest',
4-
testEnvironment: 'node',
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
55
};

packages/get-uri/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export const protocols = {
2626
export type Protocols = typeof protocols;
2727

2828
export type ProtocolsOptions = {
29-
[P in keyof Protocols]: NonNullable<Parameters<Protocols[P]>[1]>
30-
}
29+
[P in keyof Protocols]: NonNullable<Parameters<Protocols[P]>[1]>;
30+
};
3131

3232
export type ProtocolOpts<T> = {
3333
[P in keyof ProtocolsOptions]: Protocol<T> extends P

packages/http-proxy-agent/src/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Protocol<T> = T extends `${infer Protocol}:${infer _}` ? Protocol : never;
1313
type ConnectOptsMap = {
1414
http: Omit<net.TcpNetConnectOpts, 'host' | 'port'>;
1515
https: Omit<tls.ConnectionOptions, 'host' | 'port'>;
16-
}
16+
};
1717

1818
export type HttpProxyAgentOptions<T> = {
1919
[P in keyof ConnectOptsMap]: Protocol<T> extends P
@@ -53,7 +53,10 @@ export class HttpProxyAgent<Uri extends string> extends Agent {
5353
debug('Creating new HttpProxyAgent instance: %o', this.proxy.href);
5454

5555
// Trim off the brackets from IPv6 addresses
56-
const host = (this.proxy.hostname || this.proxy.host).replace(/^\[|\]$/g, '');
56+
const host = (this.proxy.hostname || this.proxy.host).replace(
57+
/^\[|\]$/g,
58+
''
59+
);
5760
const port = this.proxy.port
5861
? parseInt(this.proxy.port, 10)
5962
: this.secureProxy

packages/http-proxy-agent/test/test.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ describe('HttpProxyAgent', () => {
105105
assert.equal(false, agent.secureProxy);
106106
});
107107
it('should be `true` when "https:" protocol is used', () => {
108-
let agent = new HttpProxyAgent(`https://127.0.0.1:${proxyPort}`);
108+
let agent = new HttpProxyAgent(
109+
`https://127.0.0.1:${proxyPort}`
110+
);
109111
assert.equal(true, agent.secureProxy);
110112
});
111113
});
@@ -200,7 +202,7 @@ describe('HttpProxyAgent', () => {
200202
});
201203
it('should receive the 407 authorization code on the `http.ClientResponse`', (done) => {
202204
// reject all requests
203-
proxy.authenticate = () => false
205+
proxy.authenticate = () => false;
204206

205207
let proxyUri = `http://127.0.0.1:${proxyPort}`;
206208
let agent = new HttpProxyAgent(proxyUri);
@@ -222,7 +224,9 @@ describe('HttpProxyAgent', () => {
222224
// set a proxy authentication function for this test
223225
proxy.authenticate = (req) => {
224226
// username:password is "foo:bar"
225-
return req.headers['proxy-authorization'] === 'Basic Zm9vOmJhcg=='
227+
return (
228+
req.headers['proxy-authorization'] === 'Basic Zm9vOmJhcg=='
229+
);
226230
};
227231

228232
// set HTTP "request" event handler for this test

packages/https-proxy-agent/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
6969
this.connectOpts = {
7070
// Attempt to negotiate http/1.1 for proxy servers that support http/2
7171
ALPNProtocols: ['http/1.1'],
72-
...(opts ? omit(opts, "headers") : null),
72+
...(opts ? omit(opts, 'headers') : null),
7373
host,
7474
port,
7575
};

packages/pac-proxy-agent/src/index.ts

+42-42
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
getUri,
1515
protocols as gProtocols,
1616
ProtocolOpts as GetUriOptions,
17-
} from "get-uri";
17+
} from 'get-uri';
1818
import {
1919
createPacResolver,
2020
FindProxyForURL,
@@ -28,8 +28,8 @@ type Protocols = keyof typeof gProtocols;
2828
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2929
type Protocol<T> = T extends `pac+${infer P}:${infer _}`
3030
? P
31-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
32-
: T extends `${infer P}:${infer _}`
31+
: // eslint-disable-next-line @typescript-eslint/no-unused-vars
32+
T extends `${infer P}:${infer _}`
3333
? P
3434
: never;
3535

@@ -55,11 +55,11 @@ export type PacProxyAgentOptions<T> = PacResolverOptions &
5555
*/
5656
export class PacProxyAgent<Uri extends string> extends Agent {
5757
static readonly protocols: `pac-${Protocols}`[] = [
58-
"pac-data",
59-
"pac-file",
60-
"pac-ftp",
61-
"pac-http",
62-
"pac-https",
58+
'pac-data',
59+
'pac-file',
60+
'pac-ftp',
61+
'pac-http',
62+
'pac-https',
6363
];
6464

6565
uri: URL;
@@ -73,16 +73,16 @@ export class PacProxyAgent<Uri extends string> extends Agent {
7373
super();
7474

7575
// Strip the "pac+" prefix
76-
const uriStr = typeof uri === "string" ? uri : uri.href;
77-
this.uri = new URL(uriStr.replace(/^pac\+/i, ""));
76+
const uriStr = typeof uri === 'string' ? uri : uri.href;
77+
this.uri = new URL(uriStr.replace(/^pac\+/i, ''));
7878

79-
debug("Creating PacProxyAgent with URI %o", this.uri.href);
79+
debug('Creating PacProxyAgent with URI %o', this.uri.href);
8080

8181
// @ts-expect-error Not sure why TS is complaining here…
8282
this.opts = { ...opts };
8383
this.cache = undefined;
8484
this.resolver = undefined;
85-
this.resolverHash = "";
85+
this.resolverHash = '';
8686
this.resolverPromise = undefined;
8787

8888
// For `PacResolver`
@@ -118,17 +118,17 @@ export class PacProxyAgent<Uri extends string> extends Agent {
118118
const code = await this.loadPacFile();
119119

120120
// Create a sha1 hash of the JS code
121-
const hash = crypto.createHash("sha1").update(code).digest("hex");
121+
const hash = crypto.createHash('sha1').update(code).digest('hex');
122122

123123
if (this.resolver && this.resolverHash === hash) {
124124
debug(
125-
"Same sha1 hash for code - contents have not changed, reusing previous proxy resolver"
125+
'Same sha1 hash for code - contents have not changed, reusing previous proxy resolver'
126126
);
127127
return this.resolver;
128128
}
129129

130130
// Cache the resolver
131-
debug("Creating new proxy resolver instance");
131+
debug('Creating new proxy resolver instance');
132132
this.resolver = createPacResolver(code, this.opts);
133133

134134
// Store that sha1 hash for future comparison purposes
@@ -138,10 +138,10 @@ export class PacProxyAgent<Uri extends string> extends Agent {
138138
} catch (err: unknown) {
139139
if (
140140
this.resolver &&
141-
(err as NodeJS.ErrnoException).code === "ENOTMODIFIED"
141+
(err as NodeJS.ErrnoException).code === 'ENOTMODIFIED'
142142
) {
143143
debug(
144-
"Got ENOTMODIFIED response, reusing previous proxy resolver"
144+
'Got ENOTMODIFIED response, reusing previous proxy resolver'
145145
);
146146
return this.resolver;
147147
}
@@ -155,16 +155,16 @@ export class PacProxyAgent<Uri extends string> extends Agent {
155155
* @api private
156156
*/
157157
private async loadPacFile(): Promise<string> {
158-
debug("Loading PAC file: %o", this.uri);
158+
debug('Loading PAC file: %o', this.uri);
159159

160160
const rs = await getUri(this.uri, { ...this.opts, cache: this.cache });
161-
debug("Got `Readable` instance for URI");
161+
debug('Got `Readable` instance for URI');
162162
this.cache = rs;
163163

164164
const buf = await toBuffer(rs);
165-
debug("Read %o byte PAC file from URI", buf.length);
165+
debug('Read %o byte PAC file from URI', buf.length);
166166

167-
return buf.toString("utf8");
167+
return buf.toString('utf8');
168168
}
169169

170170
/**
@@ -184,15 +184,15 @@ export class PacProxyAgent<Uri extends string> extends Agent {
184184
const defaultPort = secureEndpoint ? 443 : 80;
185185
let path = req.path;
186186
let search: string | null = null;
187-
const firstQuestion = path.indexOf("?");
187+
const firstQuestion = path.indexOf('?');
188188
if (firstQuestion !== -1) {
189189
search = path.substring(firstQuestion);
190190
path = path.substring(0, firstQuestion);
191191
}
192192

193193
const urlOpts = {
194194
...opts,
195-
protocol: secureEndpoint ? "https:" : "http:",
195+
protocol: secureEndpoint ? 'https:' : 'http:',
196196
pathname: path,
197197
search,
198198

@@ -206,47 +206,47 @@ export class PacProxyAgent<Uri extends string> extends Agent {
206206
};
207207
const url = format(urlOpts);
208208

209-
debug("url: %o", url);
209+
debug('url: %o', url);
210210
let result = await resolver(url);
211211

212212
// Default to "DIRECT" if a falsey value was returned (or nothing)
213213
if (!result) {
214-
result = "DIRECT";
214+
result = 'DIRECT';
215215
}
216216

217217
const proxies = String(result)
218218
.trim()
219219
.split(/\s*;\s*/g)
220220
.filter(Boolean);
221221

222-
if (this.opts.fallbackToDirect && !proxies.includes("DIRECT")) {
223-
proxies.push("DIRECT");
222+
if (this.opts.fallbackToDirect && !proxies.includes('DIRECT')) {
223+
proxies.push('DIRECT');
224224
}
225225

226226
for (const proxy of proxies) {
227227
let agent: Agent | null = null;
228228
let socket: net.Socket | null = null;
229229
const [type, target] = proxy.split(/\s+/);
230-
debug("Attempting to use proxy: %o", proxy);
230+
debug('Attempting to use proxy: %o', proxy);
231231

232-
if (type === "DIRECT") {
232+
if (type === 'DIRECT') {
233233
// Direct connection to the destination endpoint
234234
socket = secureEndpoint ? tls.connect(opts) : net.connect(opts);
235-
} else if (type === "SOCKS" || type === "SOCKS5") {
235+
} else if (type === 'SOCKS' || type === 'SOCKS5') {
236236
// Use a SOCKSv5h proxy
237237
agent = new SocksProxyAgent(`socks://${target}`, this.opts);
238-
} else if (type === "SOCKS4") {
238+
} else if (type === 'SOCKS4') {
239239
// Use a SOCKSv4a proxy
240240
agent = new SocksProxyAgent(`socks4a://${target}`, this.opts);
241241
} else if (
242-
type === "PROXY" ||
243-
type === "HTTP" ||
244-
type === "HTTPS"
242+
type === 'PROXY' ||
243+
type === 'HTTP' ||
244+
type === 'HTTPS'
245245
) {
246246
// Use an HTTP or HTTPS proxy
247247
// http://dev.chromium.org/developers/design-documents/secure-web-proxy
248248
const proxyURL = `${
249-
type === "HTTPS" ? "https" : "http"
249+
type === 'HTTPS' ? 'https' : 'http'
250250
}://${target}`;
251251
if (secureEndpoint) {
252252
agent = new HttpsProxyAgent(proxyURL, this.opts);
@@ -258,24 +258,24 @@ export class PacProxyAgent<Uri extends string> extends Agent {
258258
try {
259259
if (socket) {
260260
// "DIRECT" connection, wait for connection confirmation
261-
await once(socket, "connect");
262-
req.emit("proxy", { proxy, socket });
261+
await once(socket, 'connect');
262+
req.emit('proxy', { proxy, socket });
263263
return socket;
264264
}
265265
if (agent) {
266266
const s = await agent.connect(req, opts);
267267
if (!(s instanceof net.Socket)) {
268268
throw new Error(
269-
"Expected a `net.Socket` to be returned from agent"
269+
'Expected a `net.Socket` to be returned from agent'
270270
);
271271
}
272-
req.emit("proxy", { proxy, socket: s });
272+
req.emit('proxy', { proxy, socket: s });
273273
return s;
274274
}
275275
throw new Error(`Could not determine proxy type for: ${proxy}`);
276276
} catch (err) {
277-
debug("Got error for proxy %o: %o", proxy, err);
278-
req.emit("proxy", { proxy, error: err });
277+
debug('Got error for proxy %o: %o', proxy, err);
278+
req.emit('proxy', { proxy, error: err });
279279
}
280280
}
281281

@@ -285,4 +285,4 @@ export class PacProxyAgent<Uri extends string> extends Agent {
285285
)}`
286286
);
287287
}
288-
}
288+
}

0 commit comments

Comments
 (0)