Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions src/app-utils/appInfoIOS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ import path from 'path';
import { plist, fs, tempDir, zip } from 'appium/support';
import { LRUCache } from 'lru-cache';
import B from 'bluebird';
import type { StringRecord } from '@appium/types';

/** @type {LRUCache<string, import('@appium/types').StringRecord>} */
const MANIFEST_CACHE = new LRUCache({
type IOSManifestPayload = StringRecord<unknown> & {
CFBundleIdentifier?: string;
CFBundleVersion?: string;
CFBundleSupportedPlatforms?: string[];
CFBundleExecutable?: string;
};

const MANIFEST_CACHE = new LRUCache<string, IOSManifestPayload>({
max: 40,
updateAgeOnHas: true,
});
Expand All @@ -22,8 +29,9 @@ export default class AppInfosCache {
this.log = log;
}

async extractManifestProperty(bundlePath: any, propertyName: any) {
const result = (await this.put(bundlePath))[propertyName];
async extractManifestProperty(bundlePath: any, propertyName: string) {
const manifest = await this.put(bundlePath);
const result = manifest[propertyName];
this.log.debug(`${propertyName}: ${JSON.stringify(result)}`);
return result;
}
Expand All @@ -50,14 +58,14 @@ export default class AppInfosCache {
return await this.extractManifestProperty(bundlePath, 'CFBundleExecutable');
}

async put(bundlePath: any) {
async put(bundlePath: any): Promise<IOSManifestPayload> {
return (await fs.stat(bundlePath)).isFile()
? await this._putIpa(bundlePath)
: await this._putApp(bundlePath);
}

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

const hash = `${entry.crc32}`;
if (MANIFEST_CACHE.has(hash)) {
manifestPayload = MANIFEST_CACHE.get(hash);
const cachedManifest = MANIFEST_CACHE.get(hash);
if (cachedManifest !== undefined) {
manifestPayload = cachedManifest;
return false;
}
const tmpRoot = await tempDir.openDir();
Expand Down Expand Up @@ -110,11 +119,12 @@ export default class AppInfosCache {
return manifestPayload;
}

async _putApp(appPath: any) {
async _putApp(appPath: any): Promise<IOSManifestPayload> {
const manifestPath = path.join(appPath, MANIFEST_FILE_NAME);
const hash = await fs.hash(manifestPath);
if (MANIFEST_CACHE.has(hash)) {
return MANIFEST_CACHE.get(hash);
const cachedManifest = MANIFEST_CACHE.get(hash);
if (cachedManifest !== undefined) {
return cachedManifest;
}
const [payload, stat] = await B.all([
this._readPlist(manifestPath, appPath),
Expand All @@ -129,9 +139,9 @@ export default class AppInfosCache {
return payload;
}

async _readPlist(plistPath: any, bundlePath: any) {
async _readPlist(plistPath: any, bundlePath: any): Promise<IOSManifestPayload> {
try {
return await plist.parsePlistFile(plistPath);
return (await plist.parsePlistFile(plistPath)) as IOSManifestPayload;
} catch (e: any) {
this.log.debug(e.stack);
throw new Error(
Expand Down
6 changes: 5 additions & 1 deletion src/app-utils/extractBundleId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@ export default async function getWDABundleID() {
await createZip();
const cache = new AppInfosCache(log);
const info = await cache.put(ipaPath);
return await info.CFBundleIdentifier;
const bundleId = info.CFBundleIdentifier;
if (!bundleId) {
throw new Error('Cannot extract CFBundleIdentifier from WDA IPA');
}
return bundleId;
}
1 change: 0 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ export function safeParseJson(jsonString: string) {
}
}


export async function registerErrorHandlers() {
process.on('unhandledRejection', (reason, p) => {
log.error('****** UnhandledRejection ******');
Expand Down
7 changes: 1 addition & 6 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ import {
setupCronUpdateDeviceList,
updateDeviceList,
} from './device-utils';
import {
hasCloudArgument,
isDeviceFarmRunning,
nodeUrl,
stripAppiumPrefixes,
} from './helpers';
import { hasCloudArgument, isDeviceFarmRunning, nodeUrl, stripAppiumPrefixes } from './helpers';
import { Dashboard } from './dashboard';
import { IDevice } from './interfaces/IDevice';
import {
Expand Down
Loading