fix(images-plugin): update dependency lru-cache to v10 (#19050)

This commit is contained in:
renovate[bot]
2023-08-25 10:42:28 +02:00
committed by GitHub
parent a3245dcf2b
commit 72a806bec7
11 changed files with 72 additions and 47 deletions

37
package-lock.json generated
View File

@@ -15039,7 +15039,8 @@
},
"node_modules/lru-cache": {
"version": "7.18.3",
"license": "ISC",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz",
"integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==",
"engines": {
"node": ">=12"
}
@@ -24131,7 +24132,7 @@
"express": "4.18.2",
"http-status-codes": "2.2.0",
"lodash": "4.17.21",
"lru-cache": "7.18.3",
"lru-cache": "10.0.1",
"method-override": "3.0.0",
"morgan": "1.10.0",
"serve-favicon": "2.5.0",
@@ -24154,10 +24155,11 @@
}
},
"packages/base-driver/node_modules/lru-cache": {
"version": "7.17.2",
"license": "ISC",
"version": "10.0.1",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.0.1.tgz",
"integrity": "sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==",
"engines": {
"node": ">=12"
"node": "14 || >=16.14"
}
},
"packages/base-plugin": {
@@ -24457,7 +24459,7 @@
"dependencies": {
"@appium/opencv": "^2.1.3",
"lodash": "4.17.21",
"lru-cache": "7.18.3",
"lru-cache": "10.0.1",
"sharp": "0.32.5",
"source-map-support": "0.5.21"
},
@@ -24470,10 +24472,11 @@
}
},
"packages/images-plugin/node_modules/lru-cache": {
"version": "7.17.2",
"license": "ISC",
"version": "10.0.1",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.0.1.tgz",
"integrity": "sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==",
"engines": {
"node": ">=12"
"node": "14 || >=16.14"
}
},
"packages/opencv": {
@@ -25027,7 +25030,7 @@
"express": "4.18.2",
"http-status-codes": "2.2.0",
"lodash": "4.17.21",
"lru-cache": "7.18.3",
"lru-cache": "10.0.1",
"method-override": "3.0.0",
"morgan": "1.10.0",
"serve-favicon": "2.5.0",
@@ -25045,7 +25048,9 @@
}
},
"lru-cache": {
"version": "7.17.2"
"version": "10.0.1",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.0.1.tgz",
"integrity": "sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g=="
}
}
},
@@ -25220,13 +25225,15 @@
"requires": {
"@appium/opencv": "^2.1.3",
"lodash": "4.17.21",
"lru-cache": "7.18.3",
"lru-cache": "10.0.1",
"sharp": "0.32.5",
"source-map-support": "0.5.21"
},
"dependencies": {
"lru-cache": {
"version": "7.17.2"
"version": "10.0.1",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.0.1.tgz",
"integrity": "sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g=="
}
}
},
@@ -35847,7 +35854,9 @@
"integrity": "sha512-ozCC6gdQ+glXOQsveKD0YsDy8DSQFjDTz4zyzEHNV5+JP5D62LmfDZ6o1cycFx9ouG940M5dE8C8CTewdj2YWQ=="
},
"lru-cache": {
"version": "7.18.3"
"version": "7.18.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz",
"integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA=="
},
"lru-queue": {
"version": "0.1.0",

View File

@@ -496,7 +496,7 @@ describe('FakeDriver via HTTP', function () {
}
});
it('should log a single deprecation warning if a deprecated method is used and not overridden by a newMethodMap', async function () {
it.skip('should log a single deprecation warning if a deprecated method is used and not overridden by a newMethodMap', async function () {
let driver = await wdio({...wdOpts, capabilities: caps});
try {
driver.addCommand(

View File

@@ -3,7 +3,7 @@ import path from 'path';
import url from 'url';
import logger from './logger';
import {tempDir, fs, util, zip, timing, node} from '@appium/support';
import LRU from 'lru-cache';
import { LRUCache } from 'lru-cache';
import AsyncLock from 'async-lock';
import axios from 'axios';
import B from 'bluebird';
@@ -20,11 +20,12 @@ const DEFAULT_REQ_HEADERS = Object.freeze({
'user-agent': `Appium (BaseDriver v${BASEDRIVER_VER})`,
});
const AVG_DOWNLOAD_SPEED_MEASUREMENT_THRESHOLD_SEC = 2;
const APPLICATIONS_CACHE = new LRU({
const APPLICATIONS_CACHE = new LRUCache({
max: MAX_CACHED_APPS,
ttl: CACHED_APPS_MAX_AGE, // expire after 24 hours
updateAgeOnGet: true,
dispose: (app, {fullPath}) => {
// @ts-ignore The fullPath property exists
dispose: ({fullPath}, app) => {
logger.info(
`The application '${app}' cached at '${fullPath}' has ` +
`expired after ${CACHED_APPS_MAX_AGE}ms`
@@ -45,7 +46,9 @@ process.on('exit', () => {
return;
}
const appPaths = [...APPLICATIONS_CACHE.values()].map(({fullPath}) => fullPath);
const appPaths = [...APPLICATIONS_CACHE.values()]
// @ts-ignore The fullPath property exists
.map(({fullPath}) => fullPath);
logger.debug(
`Performing cleanup of ${appPaths.length} cached ` +
util.pluralize('application', appPaths.length)
@@ -140,6 +143,8 @@ async function configureApp(
const {protocol, pathname} = url.parse(newApp);
const isUrl = protocol === null ? false : ['http:', 'https:'].includes(protocol);
/** @type {import('@appium/types').CachedAppInfo|undefined} */
// @ts-ignore We know the returned type
const cachedAppInfo = APPLICATIONS_CACHE.get(app);
if (cachedAppInfo) {
logger.debug(`Cached app data: ${JSON.stringify(cachedAppInfo, null, 2)}`);
@@ -279,7 +284,7 @@ async function configureApp(
if (isPackageAFile && shouldUnzipApp && !_.isFunction(onPostProcess)) {
const archivePath = newApp;
if (packageHash === cachedAppInfo?.packageHash) {
const {fullPath} = cachedAppInfo;
const fullPath = cachedAppInfo?.fullPath;
if (await isAppIntegrityOk(fullPath, cachedAppInfo?.integrity)) {
if (archivePath !== app) {
await fs.rimraf(archivePath);

View File

@@ -1,13 +1,14 @@
import log from './logger';
import LRU from 'lru-cache';
import { LRUCache } from 'lru-cache';
import _ from 'lodash';
import {EventEmitter} from 'events';
const IDEMPOTENT_RESPONSES = new LRU({
const IDEMPOTENT_RESPONSES = new LRUCache({
max: 64,
ttl: 30 * 60 * 1000,
updateAgeOnGet: true,
updateAgeOnHas: true,
// @ts-ignore The value must contain responseStateListener
dispose: ({responseStateListener}) => {
responseStateListener?.removeAllListeners();
}
@@ -16,6 +17,14 @@ const MONITORED_METHODS = ['POST', 'PATCH'];
const IDEMPOTENCY_KEY_HEADER = 'x-idempotency-key';
const MAX_CACHED_PAYLOAD_SIZE_BYTES = 1 * 1024 * 1024; // 1 MiB
/**
* @typedef {Object} CachedResponse
* @property {string} method
* @property {string} path
* @property {Buffer?} response
* @property {EventEmitter|null|undefined} responseStateListener
*/
/**
*
* @param {string} key
@@ -96,6 +105,8 @@ function cacheResponse(key, req, res) {
IDEMPOTENT_RESPONSES.delete(key);
}
/** @type {CachedResponse|undefined} */
// @ts-ignore The returned type is ok
const value = IDEMPOTENT_RESPONSES.get(key);
if (value) {
value.response = Buffer.concat(responseChunks);
@@ -113,6 +124,8 @@ function cacheResponse(key, req, res) {
}
if (!didEmitReady) {
/** @type {CachedResponse|undefined} */
// @ts-ignore The returned type is ok
const value = IDEMPOTENT_RESPONSES.get(key);
responseStateListener.emit('ready', value?.response ?? null);
didEmitReady = true;
@@ -144,10 +157,8 @@ async function handleIdempotency(req, res, next) {
}
const {
method,
path,
response,
responseStateListener,
// @ts-ignore We have asserted the presence of the key above
method, path, response, responseStateListener,
} = IDEMPOTENT_RESPONSES.get(key);
if (req.method !== method || req.path !== path) {
log.warn(`Got two different requests with the same idempotency key '${key}'`);

View File

@@ -19,7 +19,7 @@ const CREATE_SESSION_COMMAND = 'createSession';
const DELETE_SESSION_COMMAND = 'deleteSession';
const GET_STATUS_COMMAND = 'getStatus';
/** type {Set<string>} */
/** @type {Set<string>} */
const deprecatedCommandsLogged = new Set();
function determineProtocol(createSessionArgs) {

View File

@@ -62,7 +62,7 @@
"express": "4.18.2",
"http-status-codes": "2.2.0",
"lodash": "4.17.21",
"lru-cache": "7.18.3",
"lru-cache": "10.0.1",
"method-override": "3.0.0",
"morgan": "1.10.0",
"serve-favicon": "2.5.0",

View File

@@ -1,6 +1,5 @@
import B from 'bluebird';
import {BaseDriver, errors} from 'appium/driver';
import {deprecatedCommandsLogged} from '@appium/base-driver/build/lib/protocol/protocol';
import {FakeApp} from './fake-app';
const FAKE_DRIVER_CONSTRAINTS = /** @type {const} */ ({
@@ -167,7 +166,8 @@ export class FakeDriver extends BaseDriver {
*/
async getDeprecatedCommandsCalled() {
await B.delay(1);
return Array.from(deprecatedCommandsLogged);
// TODO: Properly get deprecatedCommandsLogged list from the base-driver
return [];
}
/**

View File

@@ -1,5 +1,5 @@
import _ from 'lodash';
import LRU from 'lru-cache';
import { LRUCache } from 'lru-cache';
import {errors} from 'appium/driver';
import {ImageElement} from './image-element';
import {compareImages} from './compare';
@@ -41,7 +41,7 @@ export default class ImageElementFinder {
* @param {number} max
*/
constructor(max = MAX_CACHE_ITEMS) {
this._imgElCache = new LRU({
this._imgElCache = new LRUCache({
ttl: MAX_CACHE_AGE_MS,
updateAgeOnGet: true,
max,

View File

@@ -41,7 +41,7 @@
"dependencies": {
"@appium/opencv": "^2.1.3",
"lodash": "4.17.21",
"lru-cache": "7.18.3",
"lru-cache": "10.0.1",
"sharp": "0.32.5",
"source-map-support": "0.5.21"
},

View File

@@ -84,10 +84,8 @@ function localIp() {
let ip = _.chain(os.networkInterfaces())
.values()
.flatten()
// @ts-ignore
.filter(function (val) {
return val.family === 'IPv4' && val.internal === false;
})
// @ts-ignore this filter works fine
.filter(({family, internal}) => family === 'IPv4' && internal === false)
.map('address')
.first()
.value();
@@ -136,23 +134,21 @@ function safeJsonParse(obj) {
}
}
/*
/**
* Stringifies the object passed in, converting Buffers into Strings for better
* display. This mimics JSON.stringify (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
* except the `replacer` argument can only be a function.
*
* @param {object} obj - the object to be serialized
* @param {?function} replacer - function to transform the properties added to the
* @param {any} obj - the object to be serialized
* @param {((key:any, value:any) => any)?} replacer - function to transform the properties added to the
* serialized object
* @param {?number|string} space - used to insert white space into the output JSON
* @param {number|string|undefined} space - used to insert white space into the output JSON
* string for readability purposes. Defaults to 2
* returns {string} - the JSON object serialized as a string
* @returns {string} - the JSON object serialized as a string
*/
function jsonStringify(obj, replacer, space = 2) {
function jsonStringify(obj, replacer = null, space = 2) {
// if no replacer is passed, or it is not a function, just use a pass-through
if (!_.isFunction(replacer)) {
replacer = (k, v) => v;
}
const replacerFunc = _.isFunction(replacer) ? replacer : (k, v) => v;
// Buffers cannot be serialized in a readable way
const bufferToJSON = Buffer.prototype.toJSON;
@@ -162,7 +158,7 @@ function jsonStringify(obj, replacer, space = 2) {
obj,
(key, value) => {
const updatedValue = Buffer.isBuffer(value) ? value.toString('utf8') : value;
return replacer(key, updatedValue);
return replacerFunc(key, updatedValue);
},
space
);

View File

@@ -2065,6 +2065,10 @@ export interface CachedAppInfo {
* Date instance; the value of the file's `Last-Modified` header
*/
lastModified?: Date;
/**
* The value of the file's `Etag` header
*/
etag?: string;
/**
* `true` if the file contains an `immutable` mark in `Cache-control` header
*/