@percy/client 1.30.2 → 1.30.3-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/proxy.js +41 -3
- package/dist/utils.js +3 -1
- package/package.json +6 -5
package/dist/proxy.js
CHANGED
|
@@ -4,9 +4,26 @@ import http from 'http';
|
|
|
4
4
|
import https from 'https';
|
|
5
5
|
import logger from '@percy/logger';
|
|
6
6
|
import { stripQuotesAndSpaces } from '@percy/env/utils';
|
|
7
|
+
import { PacProxyAgent } from 'pac-proxy-agent';
|
|
7
8
|
const CRLF = '\r\n';
|
|
8
9
|
const STATUS_REG = /^HTTP\/1.[01] (\d*)/;
|
|
9
10
|
|
|
11
|
+
// function to create PAC proxy agent
|
|
12
|
+
function createPacAgent(pacUrl, options = {}) {
|
|
13
|
+
pacUrl = stripQuotesAndSpaces(pacUrl);
|
|
14
|
+
try {
|
|
15
|
+
const agent = new PacProxyAgent(pacUrl, {
|
|
16
|
+
keepAlive: true,
|
|
17
|
+
...options
|
|
18
|
+
});
|
|
19
|
+
logger('client:proxy').info(`Successfully loaded PAC file from: ${pacUrl}`);
|
|
20
|
+
return agent;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
logger('client:proxy').error(`Failed to load PAC file, error message: ${error.message}, stack: ${error.stack}`);
|
|
23
|
+
throw new Error(`Failed to initialize PAC proxy: ${error.message}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
10
27
|
// Returns true if the URL hostname matches any patterns
|
|
11
28
|
export function hostnameMatches(patterns, url) {
|
|
12
29
|
let subject = new URL(url);
|
|
@@ -196,8 +213,29 @@ export function proxyAgentFor(url, options) {
|
|
|
196
213
|
hostname
|
|
197
214
|
} = new URL(url);
|
|
198
215
|
let cachekey = `${protocol}//${hostname}`;
|
|
199
|
-
|
|
200
|
-
|
|
216
|
+
|
|
217
|
+
// If we already have a cached agent, return it
|
|
218
|
+
if (cache.has(cachekey)) {
|
|
219
|
+
return cache.get(cachekey);
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
let agent;
|
|
223
|
+
const pacUrl = process.env.PERCY_PAC_FILE_URL;
|
|
224
|
+
|
|
225
|
+
// If PAC URL is provided, use PAC proxy
|
|
226
|
+
if (pacUrl) {
|
|
227
|
+
logger('client:proxy').info(`Using PAC file from: ${pacUrl}`);
|
|
228
|
+
agent = createPacAgent(pacUrl, options);
|
|
229
|
+
} else {
|
|
230
|
+
// Fall back to other proxy configuration
|
|
231
|
+
agent = protocol === 'https:' ? new ProxyHttpsAgent(options) : new ProxyHttpAgent(options);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Cache the created agent
|
|
235
|
+
cache.set(cachekey, agent);
|
|
236
|
+
return agent;
|
|
237
|
+
} catch (error) {
|
|
238
|
+
logger('client:proxy').error(`Failed to create proxy agent: ${error.message}`);
|
|
239
|
+
throw error;
|
|
201
240
|
}
|
|
202
|
-
return cache.get(cachekey);
|
|
203
241
|
}
|
package/dist/utils.js
CHANGED
|
@@ -141,9 +141,11 @@ export async function request(url, options = {}, callback) {
|
|
|
141
141
|
} = new URL(url);
|
|
142
142
|
|
|
143
143
|
// reference the default export so tests can mock it
|
|
144
|
+
// bundling cli inside electron (LCNC) fails if we import it like
|
|
145
|
+
// this: await import(protocol === 'https:' ? 'https' : 'http');
|
|
144
146
|
let {
|
|
145
147
|
default: http
|
|
146
|
-
} =
|
|
148
|
+
} = protocol === 'https:' ? await import('https') : await import('http');
|
|
147
149
|
let {
|
|
148
150
|
proxyAgentFor
|
|
149
151
|
} = await import('./proxy.js');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/client",
|
|
3
|
-
"version": "1.30.
|
|
3
|
+
"version": "1.30.3-alpha.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public",
|
|
12
|
-
"tag": "
|
|
12
|
+
"tag": "alpha"
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">=14"
|
|
@@ -33,9 +33,10 @@
|
|
|
33
33
|
"test:coverage": "yarn test --coverage"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@percy/env": "1.30.
|
|
37
|
-
"@percy/logger": "1.30.
|
|
36
|
+
"@percy/env": "1.30.3-alpha.0",
|
|
37
|
+
"@percy/logger": "1.30.3-alpha.0",
|
|
38
|
+
"pac-proxy-agent": "^7.0.2",
|
|
38
39
|
"pako": "^2.1.0"
|
|
39
40
|
},
|
|
40
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "3d149589bee147703e4e884d4cac689eaaad805d"
|
|
41
42
|
}
|