@percy/client 1.29.0 → 1.29.1-beta.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/detect-proxy.js +110 -0
- package/package.json +6 -5
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { exec } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import logger from '@percy/logger';
|
|
4
|
+
export default class DetectProxy {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.execPromise = promisify(exec);
|
|
7
|
+
this.platform = process.platform;
|
|
8
|
+
// There are sock proxies as well which we don't need
|
|
9
|
+
this.filter = ['HTTP', 'HTTPS'];
|
|
10
|
+
}
|
|
11
|
+
async getSystemProxy() {
|
|
12
|
+
if (this.platform === 'darwin') {
|
|
13
|
+
return await this.getProxyFromMac();
|
|
14
|
+
} else if (this.platform === 'win32') {
|
|
15
|
+
return await this.getProxyFromWindows();
|
|
16
|
+
} else if (this.platform !== 'linux') {
|
|
17
|
+
logger('client:detect-proxy').debug(`Not able to auto detect system proxy for ${this.platform} platform`);
|
|
18
|
+
}
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
async getProxyFromMac() {
|
|
22
|
+
// Sample output
|
|
23
|
+
/*
|
|
24
|
+
HTTPEnable : 1
|
|
25
|
+
HTTPProxy : proxy.example.com
|
|
26
|
+
HTTPPort : 8080
|
|
27
|
+
HTTPSEnable : 1
|
|
28
|
+
HTTPSProxy : secureproxy.example.com
|
|
29
|
+
HTTPSPort : 8443
|
|
30
|
+
*/
|
|
31
|
+
const {
|
|
32
|
+
stdout
|
|
33
|
+
} = await this.execPromise('scutil --proxy');
|
|
34
|
+
const dictionary = {};
|
|
35
|
+
const lines = stdout.split('\n');
|
|
36
|
+
lines.forEach(line => {
|
|
37
|
+
let [key, value] = line.split(' : ');
|
|
38
|
+
if (key && value) {
|
|
39
|
+
key = key.trim();
|
|
40
|
+
value = value.trim();
|
|
41
|
+
if (key.endsWith('Enable')) {
|
|
42
|
+
dictionary[key] = value === '1';
|
|
43
|
+
} else if (key.endsWith('Port')) {
|
|
44
|
+
dictionary[key] = parseInt(value);
|
|
45
|
+
} else {
|
|
46
|
+
dictionary[key] = value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const proxies = [];
|
|
51
|
+
for (const type of this.filter) {
|
|
52
|
+
if (dictionary[`${type}Enable`] && dictionary[`${type}Proxy`] && dictionary[`${type}Port`]) {
|
|
53
|
+
proxies.push({
|
|
54
|
+
type: type,
|
|
55
|
+
host: dictionary[`${type}Proxy`],
|
|
56
|
+
port: dictionary[`${type}Port`]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return proxies;
|
|
61
|
+
}
|
|
62
|
+
async getProxyFromWindows() {
|
|
63
|
+
// Sample output
|
|
64
|
+
/*
|
|
65
|
+
HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings
|
|
66
|
+
User Agent REG_SZ Mozilla/4.0 (compatible; MSIE 8.0; Win32)
|
|
67
|
+
IE5_UA_Backup_Flag REG_SZ 5.0
|
|
68
|
+
ZonesSecurityUpgrade REG_BINARY ABCD
|
|
69
|
+
EmailName REG_SZ User@
|
|
70
|
+
AutoConfigProxy REG_SZ wininet.dll
|
|
71
|
+
MimeExclusionListForCache REG_SZ multipart/mixed multipart/x-mixed-replace multipart/x-byteranges
|
|
72
|
+
WarnOnPost REG_BINARY 01000000
|
|
73
|
+
UseSchannelDirectly REG_BINARY 01000000
|
|
74
|
+
EnableHttp1_1 REG_DWORD 0x1
|
|
75
|
+
UrlEncoding REG_DWORD 0x0
|
|
76
|
+
SecureProtocols REG_DWORD 0xa0
|
|
77
|
+
PrivacyAdvanced REG_DWORD 0x0
|
|
78
|
+
DisableCachingOfSSLPages REG_DWORD 0x1
|
|
79
|
+
WarnonZoneCrossing REG_DWORD 0x1
|
|
80
|
+
CertificateRevocation REG_DWORD 0x1
|
|
81
|
+
EnableNegotiate REG_DWORD 0x1
|
|
82
|
+
MigrateProxy REG_DWORD 0x1
|
|
83
|
+
ProxyEnable REG_DWORD 0x0
|
|
84
|
+
*/
|
|
85
|
+
const {
|
|
86
|
+
stdout
|
|
87
|
+
} = await this.execPromise('reg query "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"');
|
|
88
|
+
const lines = stdout.split('\n');
|
|
89
|
+
const dictionary = {};
|
|
90
|
+
lines.forEach(line => {
|
|
91
|
+
const [key, type, value] = line.trim().split(/\s+/);
|
|
92
|
+
if (key && type && value) {
|
|
93
|
+
if (type === 'REG_DWORD') {
|
|
94
|
+
dictionary[key] = value === '0x1';
|
|
95
|
+
} else if (type === 'REG_SZ') {
|
|
96
|
+
dictionary[key] = value;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
if (this.filter.includes('HTTP') && dictionary.ProxyEnable && dictionary.ProxyServer) {
|
|
101
|
+
const [host, port] = dictionary.ProxyServer.split(':');
|
|
102
|
+
return [{
|
|
103
|
+
type: 'HTTP',
|
|
104
|
+
host,
|
|
105
|
+
port: parseInt(port)
|
|
106
|
+
}];
|
|
107
|
+
}
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/client",
|
|
3
|
-
"version": "1.29.0",
|
|
3
|
+
"version": "1.29.1-beta.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": "beta"
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">=14"
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"exports": {
|
|
24
24
|
".": "./dist/index.js",
|
|
25
25
|
"./utils": "./dist/utils.js",
|
|
26
|
+
"./detect-proxy": "./dist/detect-proxy.js",
|
|
26
27
|
"./test/helpers": "./test/helpers.js"
|
|
27
28
|
},
|
|
28
29
|
"scripts": {
|
|
@@ -32,9 +33,9 @@
|
|
|
32
33
|
"test:coverage": "yarn test --coverage"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
|
-
"@percy/env": "1.29.0",
|
|
36
|
-
"@percy/logger": "1.29.0",
|
|
36
|
+
"@percy/env": "1.29.1-beta.0",
|
|
37
|
+
"@percy/logger": "1.29.1-beta.0",
|
|
37
38
|
"pako": "^2.1.0"
|
|
38
39
|
},
|
|
39
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "d325b7bbe56764dbde494477d1f4f3bfdc562d6e"
|
|
40
41
|
}
|