@percy/client 1.27.6 → 1.27.7
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 +17 -6
- package/dist/utils.js +10 -0
- package/package.json +4 -4
package/dist/client.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import PercyEnv from '@percy/env';
|
|
3
3
|
import { git } from '@percy/env/utils';
|
|
4
4
|
import logger from '@percy/logger';
|
|
5
|
-
import { pool, request, sha256hash, base64encode, getPackageJSON, waitForTimeout } from './utils.js';
|
|
5
|
+
import { pool, request, formatBytes, sha256hash, base64encode, getPackageJSON, waitForTimeout } from './utils.js';
|
|
6
6
|
|
|
7
7
|
// Default client API URL can be set with an env var for API development
|
|
8
8
|
const {
|
|
@@ -269,14 +269,16 @@ export class PercyClient {
|
|
|
269
269
|
content
|
|
270
270
|
} = {}) {
|
|
271
271
|
validateId('build', buildId);
|
|
272
|
-
this.log.debug(`Uploading resource: ${url}...`);
|
|
273
272
|
if (filepath) content = await fs.promises.readFile(filepath);
|
|
273
|
+
let encodedContent = base64encode(content);
|
|
274
|
+
this.log.debug(`Uploading ${formatBytes(encodedContent.length)} resource: ${url}...`);
|
|
275
|
+
this.mayBeLogUploadSize(encodedContent.length);
|
|
274
276
|
return this.post(`builds/${buildId}/resources`, {
|
|
275
277
|
data: {
|
|
276
278
|
type: 'resources',
|
|
277
279
|
id: sha || sha256hash(content),
|
|
278
280
|
attributes: {
|
|
279
|
-
'base64-content':
|
|
281
|
+
'base64-content': encodedContent
|
|
280
282
|
}
|
|
281
283
|
}
|
|
282
284
|
});
|
|
@@ -444,16 +446,18 @@ export class PercyClient {
|
|
|
444
446
|
sha
|
|
445
447
|
} = {}) {
|
|
446
448
|
validateId('comparison', comparisonId);
|
|
447
|
-
this.log.debug(`Uploading comparison tile: ${index + 1}/${total} (${comparisonId})...`);
|
|
448
|
-
if (filepath && !content) content = await fs.promises.readFile(filepath);
|
|
449
449
|
if (sha) {
|
|
450
450
|
return await this.verify(comparisonId, sha);
|
|
451
451
|
}
|
|
452
|
+
if (filepath && !content) content = await fs.promises.readFile(filepath);
|
|
453
|
+
let encodedContent = base64encode(content);
|
|
454
|
+
this.log.debug(`Uploading ${formatBytes(encodedContent.length)} comparison tile: ${index + 1}/${total} (${comparisonId})...`);
|
|
455
|
+
this.mayBeLogUploadSize(encodedContent.length);
|
|
452
456
|
return this.post(`comparisons/${comparisonId}/tiles`, {
|
|
453
457
|
data: {
|
|
454
458
|
type: 'tiles',
|
|
455
459
|
attributes: {
|
|
456
|
-
'base64-content':
|
|
460
|
+
'base64-content': encodedContent,
|
|
457
461
|
index
|
|
458
462
|
}
|
|
459
463
|
}
|
|
@@ -526,6 +530,13 @@ export class PercyClient {
|
|
|
526
530
|
data: body
|
|
527
531
|
});
|
|
528
532
|
}
|
|
533
|
+
mayBeLogUploadSize(contentSize) {
|
|
534
|
+
if (contentSize >= 25 * 1024 * 1024) {
|
|
535
|
+
this.log.error('Uploading resource above 25MB might fail the build...');
|
|
536
|
+
} else if (contentSize >= 20 * 1024 * 1024) {
|
|
537
|
+
this.log.warn('Uploading resource above 20MB might slow the build...');
|
|
538
|
+
}
|
|
539
|
+
}
|
|
529
540
|
|
|
530
541
|
// decides project type
|
|
531
542
|
tokenType() {
|
package/dist/utils.js
CHANGED
|
@@ -4,6 +4,16 @@ import url from 'url';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import crypto from 'crypto';
|
|
6
6
|
|
|
7
|
+
// Formats a raw byte integer as a string
|
|
8
|
+
export function formatBytes(int) {
|
|
9
|
+
let units = ['kB', 'MB', 'GB'];
|
|
10
|
+
let base = 1024;
|
|
11
|
+
let u = -1;
|
|
12
|
+
if (Math.abs(int) < base) return `${int}B`;
|
|
13
|
+
while (Math.abs(int) >= base && u++ < 2) int /= base;
|
|
14
|
+
return `${int.toFixed(1)}${units[u]}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
// Returns a sha256 hash of a string.
|
|
8
18
|
export function sha256hash(content) {
|
|
9
19
|
return crypto.createHash('sha256').update(content, 'utf-8').digest('hex');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/client",
|
|
3
|
-
"version": "1.27.
|
|
3
|
+
"version": "1.27.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"test:coverage": "yarn test --coverage"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@percy/env": "1.27.
|
|
36
|
-
"@percy/logger": "1.27.
|
|
35
|
+
"@percy/env": "1.27.7",
|
|
36
|
+
"@percy/logger": "1.27.7"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "eba048142b27b317491f15364b34764371fc0670"
|
|
39
39
|
}
|