@argos-ci/core 2.12.0 → 3.0.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/index.js +50 -5
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -685,16 +685,61 @@ var discoverScreenshots = async (patterns, { root = process.cwd(), ignore } = {}
|
|
|
685
685
|
|
|
686
686
|
// src/optimize.ts
|
|
687
687
|
import { promisify } from "node:util";
|
|
688
|
+
import { basename } from "node:path";
|
|
688
689
|
import sharp from "sharp";
|
|
689
690
|
import tmp from "tmp";
|
|
690
691
|
var tmpFile = promisify(tmp.file);
|
|
692
|
+
var MAX_PIXELS = 8e7;
|
|
693
|
+
var DEFAULT_MAX_WIDTH = 2048;
|
|
691
694
|
var optimizeScreenshot = async (filepath) => {
|
|
692
695
|
try {
|
|
693
|
-
const resultFilePath = await
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
696
|
+
const [resultFilePath, metadata] = await Promise.all([
|
|
697
|
+
tmpFile(),
|
|
698
|
+
sharp(filepath).metadata()
|
|
699
|
+
]);
|
|
700
|
+
const { width, height } = metadata;
|
|
701
|
+
const maxDimensions = (() => {
|
|
702
|
+
if (!width || !height) {
|
|
703
|
+
return {
|
|
704
|
+
width: DEFAULT_MAX_WIDTH,
|
|
705
|
+
height: Math.floor(MAX_PIXELS / DEFAULT_MAX_WIDTH)
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
const nbPixels = width * height;
|
|
709
|
+
if (nbPixels <= MAX_PIXELS) {
|
|
710
|
+
return null;
|
|
711
|
+
}
|
|
712
|
+
if (width < height) {
|
|
713
|
+
return {
|
|
714
|
+
width: DEFAULT_MAX_WIDTH,
|
|
715
|
+
height: Math.floor(MAX_PIXELS / DEFAULT_MAX_WIDTH)
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
const scaleFactor = Math.sqrt(MAX_PIXELS / nbPixels);
|
|
719
|
+
return {
|
|
720
|
+
width: Math.floor(width * scaleFactor),
|
|
721
|
+
height: Math.floor(height * scaleFactor)
|
|
722
|
+
};
|
|
723
|
+
})();
|
|
724
|
+
let operation = sharp(filepath);
|
|
725
|
+
if (maxDimensions) {
|
|
726
|
+
operation = operation.resize(maxDimensions.width, maxDimensions.height, {
|
|
727
|
+
fit: "inside",
|
|
728
|
+
withoutEnlargement: true
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
await operation.png({ force: true }).toFile(resultFilePath);
|
|
732
|
+
if (width && height && maxDimensions) {
|
|
733
|
+
const { width: maxWidth, height: maxHeight } = maxDimensions;
|
|
734
|
+
const widthRatio = maxWidth / width;
|
|
735
|
+
const heightRatio = maxHeight / height;
|
|
736
|
+
const scaleFactor = Math.min(widthRatio, heightRatio);
|
|
737
|
+
const newWidth = Math.floor(width * scaleFactor);
|
|
738
|
+
const newHeight = Math.floor(height * scaleFactor);
|
|
739
|
+
console.warn(
|
|
740
|
+
`Image ${basename(filepath)} resized from ${width}x${height} to ${newWidth}x${newHeight}.`
|
|
741
|
+
);
|
|
742
|
+
}
|
|
698
743
|
return resultFilePath;
|
|
699
744
|
} catch (error) {
|
|
700
745
|
const message = error instanceof Error ? error.message : "Unknown Error";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/core",
|
|
3
3
|
"description": "Node.js SDK for visual testing with Argos.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"exports": {
|
|
@@ -40,25 +40,25 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@argos-ci/api-client": "0.7.
|
|
44
|
-
"@argos-ci/util": "2.2.
|
|
45
|
-
"axios": "^1.7.
|
|
43
|
+
"@argos-ci/api-client": "0.7.2",
|
|
44
|
+
"@argos-ci/util": "2.2.2",
|
|
45
|
+
"axios": "^1.7.9",
|
|
46
46
|
"convict": "^6.2.4",
|
|
47
|
-
"debug": "^4.
|
|
48
|
-
"fast-glob": "^3.3.
|
|
47
|
+
"debug": "^4.4.0",
|
|
48
|
+
"fast-glob": "^3.3.3",
|
|
49
49
|
"sharp": "^0.33.5",
|
|
50
50
|
"tmp": "^0.2.3"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@octokit/webhooks": "^13.4.
|
|
53
|
+
"@octokit/webhooks": "^13.4.2",
|
|
54
54
|
"@types/convict": "^6.1.6",
|
|
55
55
|
"@types/debug": "^4.1.12",
|
|
56
56
|
"@types/tmp": "^0.2.6",
|
|
57
|
-
"msw": "^2.
|
|
57
|
+
"msw": "^2.7.0"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "tsup && cp ./src/index.cjs ./dist",
|
|
61
61
|
"e2e": "node ./e2e/upload.cjs && node ./e2e/upload.mjs"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "0c91306ae0cb8bec5ef93db79565635e405086f7"
|
|
64
64
|
}
|