Skip to content

Commit

Permalink
#182 Update NPM dependencies 05-2023 (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
GRiMe2D authored May 29, 2023
1 parent 6f64815 commit abfa064
Show file tree
Hide file tree
Showing 12 changed files with 1,570 additions and 1,610 deletions.
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- run: docker run --entrypoint sh -v "$(realpath .):/data" buildkite/puppeteer:latest /data/demo/render_using_catage.sh
- run: npm ci && dist/index.js collect . && dist/index.js generate-diff
- run: npm ci && dist/index.mjs collect . && dist/index.mjs generate-diff
env:
SWATCHER_S3_SECRET_KEY: ${{ secrets.SWATCHER_S3_SECRET_KEY }}
SWATCHER_S3_REGION: ${{ secrets.SWATCHER_S3_REGION }}
Expand Down
4 changes: 4 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-runtime']
}
66 changes: 32 additions & 34 deletions dist/index.js → dist/index.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#!/usr/bin/env node
'use strict';

var commander = require('commander');
var sjson = require('secure-json-parse');
var fs = require('fs');
var util = require('util');
var clientS3 = require('@aws-sdk/client-s3');
var nodeDownloaderHelper = require('node-downloader-helper');
var tmpPromise = require('tmp-promise');
var pathModule = require('path');
var rfc4648 = require('rfc4648');
var os = require('os');
var looksSame = require('looks-same');
var imageSize = require('image-size');
var nodeFetch = require('node-fetch');

var swatcherVersion = '1.5.1';
import { program } from 'commander';
import sjson from 'secure-json-parse';
import fs from 'fs';
import { promisify } from 'util';
import { S3Client, ListObjectsV2Command, PutObjectCommand } from '@aws-sdk/client-s3';
import { DownloaderHelper } from 'node-downloader-helper';
import tmpPromise from 'tmp-promise';
import pathModule from 'path';
import { base32 } from 'rfc4648';
import os from 'os';
import looksSame from 'looks-same';
import imageSize from 'image-size';
import nodeFetch from 'node-fetch';

var swatcherVersion = '1.6.0';

class GithubActionsEnvironment {
constructor (githubPayload) {
Expand Down Expand Up @@ -44,7 +42,7 @@ async function CI () {
const eventPath = process.env.GITHUB_EVENT_PATH;
if (!eventPath) throw new Error('process.env.GITHUB_EVENT_PATH returned falsy value')

const payload = sjson.parse(await util.promisify(fs.readFile)(eventPath, 'utf8'));
const payload = sjson.parse(await promisify(fs.readFile)(eventPath, 'utf8'));
return new GithubActionsEnvironment(payload)
}

Expand Down Expand Up @@ -91,7 +89,7 @@ class S3 {
this._credentials = new S3credentials();
if (!this._credentials.isConfigReady) throw new Error('S3 config isn\'t ready')

this._awsS3 = new clientS3.S3Client({
this._awsS3 = new S3Client({
credentials: {
accessKeyId: this._credentials.accessKey,
secretAccessKey: this._credentials.secretKey
Expand All @@ -109,7 +107,7 @@ class S3 {
async download (fullKey) {
const folder = (await temporaryDir()).path;
return new Promise((resolve, reject) => {
const dl = new nodeDownloaderHelper.DownloaderHelper(this.url(fullKey), folder, { override: true });
const dl = new DownloaderHelper(this.url(fullKey), folder, { override: true });
dl.on('end', downloadInfo => {
resolve(downloadInfo.filePath);
});
Expand All @@ -119,7 +117,7 @@ class S3 {
}

async _paginatedList (prefix, nextMarker) {
const output = await this._awsS3.send(new clientS3.ListObjectsV2Command({
const output = await this._awsS3.send(new ListObjectsV2Command({
Bucket: this._credentials.bucketName,
Delimiter: '/',
ContinuationToken: nextMarker,
Expand Down Expand Up @@ -154,8 +152,8 @@ class S3 {
}

async upload (filePath, key, contentType) {
await this._awsS3.send(new clientS3.PutObjectCommand({
Body: await (util.promisify(fs.readFile)(filePath)),
await this._awsS3.send(new PutObjectCommand({
Body: await (promisify(fs.readFile)(filePath)),
ContentType: contentType,
Key: key,
ACL: 'public-read',
Expand Down Expand Up @@ -282,8 +280,8 @@ const safeSplit = path => (

const removeSlashes = path => path.replace(/\//g, '');

const safeBase32Encode = path => safeSplit(rfc4648.base32.stringify(Buffer.from(path, 'utf8')));
const safeBase32Decode = path => Buffer.from(rfc4648.base32.parse(removeSlashes(path))).toString('utf8');
const safeBase32Encode = path => safeSplit(base32.stringify(Buffer.from(path, 'utf8')));
const safeBase32Decode = path => Buffer.from(base32.parse(removeSlashes(path))).toString('utf8');

const clusterize = array => array.reduce(
(acc, value) => {
Expand Down Expand Up @@ -332,7 +330,7 @@ const asyncMap$1 = async (array, closure) => await Promise.all(array.map(closure

var temporaryFile = async postfix => {
const { fd, path, cleanup } = await tmpPromise.file({ postfix });
await util.promisify(fs.close)(fd); // we dont need file descriptor
await promisify(fs.close)(fd); // we dont need file descriptor

return { path, cleanup }
};
Expand All @@ -358,8 +356,8 @@ async function comparePNGs (pngBefore, pngAfter, outputPath, filePixelRatio) {
const { equal, diffClusters } = await looksSame(pngBefore, pngAfter, looksSameOptions);
if (equal) return { equal }

const dimensions = await util.promisify(imageSize)(pngBefore);
if (diffClusters.length !== 0 && areDimensionsSame(dimensions, await util.promisify(imageSize)(pngAfter))) {
const dimensions = await promisify(imageSize)(pngBefore);
if (diffClusters.length !== 0 && areDimensionsSame(dimensions, await promisify(imageSize)(pngAfter))) {
dimensions.width /= pixelRatio;
dimensions.height /= pixelRatio;

Expand Down Expand Up @@ -491,7 +489,7 @@ const checkIfCanComment = async () => {
token: checkEnvVariableAndReturn('SWATCHER_GITHUB_API_TOKEN'),
apiURL: checkEnvVariableAndReturn('GITHUB_API_URL'),
eventName: checkEnvVariableAndReturn('GITHUB_EVENT_NAME'),
eventPayload: await sjson.parse(await util.promisify(fs.readFile)(checkEnvVariableAndReturn('GITHUB_EVENT_PATH'), 'utf8'))
eventPayload: await sjson.parse(await promisify(fs.readFile)(checkEnvVariableAndReturn('GITHUB_EVENT_PATH'), 'utf8'))
}
};

Expand Down Expand Up @@ -608,7 +606,7 @@ var diffLocalCommand = async (fileA, fileB, outputFile) => {
}
};

commander
program
.version(swatcherVersion)
.name('Swatcher - track UI changes like a git history')
.description(
Expand All @@ -620,24 +618,24 @@ commander
'testing, this is history of the each screen\'s snapshot.'
);

commander
program
.command('collect <dir> [other_dirs...]')
.description('Collect screenshots from specified directory')
.action(collectCommand);

commander
program
.command('generate-diff')
.description('Generate diffs for already collected screenshots')
.action(generateDiffCommand);

commander
program
.command('diff-local <A_png> <B_png> <output_png>')
.description('Create a diff file for locally available files')
.action(diffLocalCommand);

async function main () {
try {
await commander.parseAsync();
await program.parseAsync();
} catch (error) {
console.error(error.name, error.message);
process.exit(1);
Expand Down
8 changes: 4 additions & 4 deletions e2e/collect_and_generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export GITHUB_EVENT_PATH='/tmp/github_payload.json'

cp "${PROJECT_DIR}/e2e/fixtures/ipad-1.png" "$TEMP_DIR/ipad_home.png"
cp "${PROJECT_DIR}/e2e/fixtures/ipad-3.png" "$TEMP_DIR/ipad_apps.png"
"${PROJECT_DIR}/dist/index.js" collect "$TEMP_DIR"
"${PROJECT_DIR}/dist/index.js" generate-diff
"${PROJECT_DIR}/dist/index.mjs" collect "$TEMP_DIR"
"${PROJECT_DIR}/dist/index.mjs" generate-diff

## clean the pushed commit
find "$TEMP_DIR" -mindepth 1 -delete
Expand All @@ -68,8 +68,8 @@ EOF

cp "${PROJECT_DIR}/e2e/fixtures/ipad-2.png" "$TEMP_DIR/ipad_home.png"
cp "${PROJECT_DIR}/e2e/fixtures/ipad-4.png" "$TEMP_DIR/ipad_settings.png"
"${PROJECT_DIR}/dist/index.js" collect "$TEMP_DIR"
"${PROJECT_DIR}/dist/index.js" generate-diff
"${PROJECT_DIR}/dist/index.mjs" collect "$TEMP_DIR"
"${PROJECT_DIR}/dist/index.mjs" generate-diff

curl -H "Authorization: token $SWATCHER_GITHUB_API_TOKEN" "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/1/comments"

Expand Down
10 changes: 10 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
const forcePackagesToBeTransformed = [
'node-fetch',
'data-uri-to-buffer',
'fetch-blob',
'formdata-polyfill'
]

module.exports = {
collectCoverage: true,
testPathIgnorePatterns: [
'/node_modules/',
'src/__tests__/test-utils.js'
],
transformIgnorePatterns: [
`<rootDir>/node_modules/(?!(${forcePackagesToBeTransformed.join('|')})/)`
]
}
Loading

0 comments on commit abfa064

Please sign in to comment.