@percy/client 1.29.1-alpha.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/client.js CHANGED
@@ -315,7 +315,7 @@ export class PercyClient {
315
315
  // Uploads a single resource to the active build. If `filepath` is provided,
316
316
  // `content` is read from the filesystem. The sha is optional and will be
317
317
  // created from `content` if one is not provided.
318
- async uploadResource(buildId, snapshotId, {
318
+ async uploadResource(buildId, {
319
319
  url,
320
320
  sha,
321
321
  filepath,
@@ -329,7 +329,7 @@ export class PercyClient {
329
329
  }
330
330
  }
331
331
  let encodedContent = base64encode(content);
332
- this.log.debug(`Uploading ${formatBytes(encodedContent.length)} resource for snapshotId ${snapshotId}: ${url}...`);
332
+ this.log.debug(`Uploading ${formatBytes(encodedContent.length)} resource: ${url}...`);
333
333
  this.mayBeLogUploadSize(encodedContent.length);
334
334
  return this.post(`builds/${buildId}/resources`, {
335
335
  data: {
@@ -343,12 +343,12 @@ export class PercyClient {
343
343
  }
344
344
 
345
345
  // Uploads resources to the active build concurrently, two at a time.
346
- async uploadResources(buildId, snapshotId, resources) {
346
+ async uploadResources(buildId, resources) {
347
347
  validateId('build', buildId);
348
- this.log.debug(`Uploading resources for BuildId: ${buildId} and SnapshotId: ${snapshotId}...`);
348
+ this.log.debug(`Uploading resources for ${buildId}...`);
349
349
  return pool(function* () {
350
350
  for (let resource of resources) {
351
- yield this.uploadResource(buildId, snapshotId, resource);
351
+ yield this.uploadResource(buildId, resource);
352
352
  }
353
353
  }, this, 2);
354
354
  }
@@ -428,15 +428,12 @@ export class PercyClient {
428
428
  async sendSnapshot(buildId, options) {
429
429
  var _snapshot$data$relati, _snapshot$data$relati2;
430
430
  let snapshot = await this.createSnapshot(buildId, options);
431
- let snapshotId = snapshot.data.id;
432
- this.log.debug(`Created snapshot with Id: ${snapshotId}...`);
433
431
  let missing = (_snapshot$data$relati = snapshot.data.relationships) === null || _snapshot$data$relati === void 0 ? void 0 : (_snapshot$data$relati2 = _snapshot$data$relati['missing-resources']) === null || _snapshot$data$relati2 === void 0 ? void 0 : _snapshot$data$relati2.data;
434
- this.log.debug(`Found ${missing === null || missing === void 0 ? void 0 : missing.length} missing resources for snapshotId: ${snapshotId}...`);
435
432
  if (missing !== null && missing !== void 0 && missing.length) {
436
433
  let resources = options.resources.reduce((acc, r) => Object.assign(acc, {
437
434
  [r.sha]: r
438
435
  }), {});
439
- await this.uploadResources(buildId, snapshotId, missing.map(({
436
+ await this.uploadResources(buildId, missing.map(({
440
437
  id
441
438
  }) => resources[id]));
442
439
  }
@@ -538,7 +535,7 @@ export class PercyClient {
538
535
 
539
536
  // Convenience method for verifying if tile is present
540
537
  async verify(comparisonId, sha) {
541
- let retries = 10;
538
+ let retries = 20;
542
539
  let success = null;
543
540
  do {
544
541
  await waitForTimeout(500);
@@ -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.1-alpha.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": "alpha"
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.1-alpha.0",
36
- "@percy/logger": "1.29.1-alpha.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": "5044adb5caa7507fdec629eda8f33d6ddde07997"
40
+ "gitHead": "d325b7bbe56764dbde494477d1f4f3bfdc562d6e"
40
41
  }