Skip to content

Commit 5d20820

Browse files
committed
fix: address lint typing errors
1 parent 6367a60 commit 5d20820

2 files changed

Lines changed: 29 additions & 15 deletions

File tree

src/app-utils/appInfoIOS.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@ import path from 'path';
33
import { plist, fs, tempDir, zip } from 'appium/support';
44
import { LRUCache } from 'lru-cache';
55
import B from 'bluebird';
6+
import type { StringRecord } from '@appium/types';
67

7-
/** @type {LRUCache<string, import('@appium/types').StringRecord>} */
8-
const MANIFEST_CACHE = new LRUCache({
8+
type IOSManifestPayload = StringRecord<unknown> & {
9+
CFBundleIdentifier?: string;
10+
CFBundleVersion?: string;
11+
CFBundleSupportedPlatforms?: string[];
12+
CFBundleExecutable?: string;
13+
};
14+
15+
const MANIFEST_CACHE = new LRUCache<string, IOSManifestPayload>({
916
max: 40,
1017
updateAgeOnHas: true,
1118
});
@@ -22,8 +29,9 @@ export default class AppInfosCache {
2229
this.log = log;
2330
}
2431

25-
async extractManifestProperty(bundlePath: any, propertyName: any) {
26-
const result = (await this.put(bundlePath))[propertyName];
32+
async extractManifestProperty(bundlePath: any, propertyName: string) {
33+
const manifest = await this.put(bundlePath);
34+
const result = manifest[propertyName];
2735
this.log.debug(`${propertyName}: ${JSON.stringify(result)}`);
2836
return result;
2937
}
@@ -50,14 +58,14 @@ export default class AppInfosCache {
5058
return await this.extractManifestProperty(bundlePath, 'CFBundleExecutable');
5159
}
5260

53-
async put(bundlePath: any) {
61+
async put(bundlePath: any): Promise<IOSManifestPayload> {
5462
return (await fs.stat(bundlePath)).isFile()
5563
? await this._putIpa(bundlePath)
5664
: await this._putApp(bundlePath);
5765
}
5866

59-
async _putIpa(ipaPath: any) {
60-
let manifestPayload;
67+
async _putIpa(ipaPath: any): Promise<IOSManifestPayload> {
68+
let manifestPayload: IOSManifestPayload | undefined;
6169
let lastError;
6270
try {
6371
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -68,8 +76,9 @@ export default class AppInfosCache {
6876
}
6977

7078
const hash = `${entry.crc32}`;
71-
if (MANIFEST_CACHE.has(hash)) {
72-
manifestPayload = MANIFEST_CACHE.get(hash);
79+
const cachedManifest = MANIFEST_CACHE.get(hash);
80+
if (cachedManifest !== undefined) {
81+
manifestPayload = cachedManifest;
7382
return false;
7483
}
7584
const tmpRoot = await tempDir.openDir();
@@ -110,11 +119,12 @@ export default class AppInfosCache {
110119
return manifestPayload;
111120
}
112121

113-
async _putApp(appPath: any) {
122+
async _putApp(appPath: any): Promise<IOSManifestPayload> {
114123
const manifestPath = path.join(appPath, MANIFEST_FILE_NAME);
115124
const hash = await fs.hash(manifestPath);
116-
if (MANIFEST_CACHE.has(hash)) {
117-
return MANIFEST_CACHE.get(hash);
125+
const cachedManifest = MANIFEST_CACHE.get(hash);
126+
if (cachedManifest !== undefined) {
127+
return cachedManifest;
118128
}
119129
const [payload, stat] = await B.all([
120130
this._readPlist(manifestPath, appPath),
@@ -129,9 +139,9 @@ export default class AppInfosCache {
129139
return payload;
130140
}
131141

132-
async _readPlist(plistPath: any, bundlePath: any) {
142+
async _readPlist(plistPath: any, bundlePath: any): Promise<IOSManifestPayload> {
133143
try {
134-
return await plist.parsePlistFile(plistPath);
144+
return (await plist.parsePlistFile(plistPath)) as IOSManifestPayload;
135145
} catch (e: any) {
136146
this.log.debug(e.stack);
137147
throw new Error(

src/app-utils/extractBundleId.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,9 @@ export default async function getWDABundleID() {
4444
await createZip();
4545
const cache = new AppInfosCache(log);
4646
const info = await cache.put(ipaPath);
47-
return await info.CFBundleIdentifier;
47+
const bundleId = info.CFBundleIdentifier;
48+
if (!bundleId) {
49+
throw new Error('Cannot extract CFBundleIdentifier from WDA IPA');
50+
}
51+
return bundleId;
4852
}

0 commit comments

Comments
 (0)