Skip to content

Commit

Permalink
moar
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Jan 5, 2025
1 parent 464236e commit ebfdc6d
Show file tree
Hide file tree
Showing 29 changed files with 87 additions and 105 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

22 changes: 0 additions & 22 deletions .eslintrc.json

This file was deleted.

5 changes: 5 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import appiumConfig from '@appium/eslint-config-appium-ts';

export default [
...appiumConfig,
];
6 changes: 3 additions & 3 deletions lib/afc/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

import LengthBasedSplitter from '../util/transformer/length-based-splitter';
import { LengthBasedSplitter } from '../util/transformer/length-based-splitter';
import { Operations, operationCode, Errors, errorCode, FileModes } from './protocol';
import { AfcWritableFileStream, AfcReadableFileStream } from './streams';
import AfcEncoder from './transformer/afcencoder';
import AfcDecoder from './transformer/afcdecoder';
import { AfcEncoder } from './transformer/afcencoder';
import { AfcDecoder } from './transformer/afcdecoder';
import { MB } from '../constants';
import B from 'bluebird';
import path from 'path';
Expand Down
53 changes: 30 additions & 23 deletions lib/afc/streams.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable promise/prefer-await-to-then */
import stream from 'stream';
import _ from 'lodash';
import log from '../logger';
import { log } from '../logger';

class AfcReadableFileStream extends stream.Readable {
export class AfcReadableFileStream extends stream.Readable {

constructor (fileHandle, afcService, options) {
super(options);
Expand All @@ -14,19 +13,20 @@ class AfcReadableFileStream extends stream.Readable {
}

_read (size) {
this._afcService.readFile(this._fileHandle, size)
.then((data) => {
(async () => {
try {
const data = await this._afcService.readFile(this._fileHandle, size);
if (!this._destroyed) {
this.push(_.isEmpty(data) ? null : data);
}
})
.catch((e) => {
} catch (e) {
if (this._autoDestroy) {
this.destroy(e);
} else {
this.emit('error', e);
}
});
}
})();
}

_destroy (err, done) {
Expand All @@ -35,20 +35,23 @@ class AfcReadableFileStream extends stream.Readable {
}
this._destroyed = true;
this.push(null);
this._afcService.closeFileHandle(this._fileHandle)
.then(() => done(err))
.catch((e) => {
(async () => {
try {
await this._afcService.closeFileHandle(this._fileHandle);
done(err);
} catch (e) {
if (err) {
log.debug(e);
} else {
err = e;
}
done(err);
});
}
})();
}
}

class AfcWritableFileStream extends stream.Writable {
export class AfcWritableFileStream extends stream.Writable {

constructor (fileHandle, afcService, options) {
super(options);
Expand All @@ -59,32 +62,36 @@ class AfcWritableFileStream extends stream.Writable {
}

_write (chunk, encoding, next) {
this._afcService.writeFile(this._fileHandle, chunk)
.then(() => next())
.catch((e) => {
(async () => {
try {
await this._afcService.writeFile(this._fileHandle, chunk);
next();
} catch (e) {
if (this._autoDestroy) {
this.destroy(e);
}
next(e);
});
}
})();
}

_destroy (err, done) {
if (this._destroyed) {
return;
}
this._destroyed = true;
this._afcService.closeFileHandle(this._fileHandle)
.then(() => done(err))
.catch((e) => {
(async () => {
try {
await this._afcService.closeFileHandle(this._fileHandle);
done(err);
} catch (e) {
if (err) {
log.debug(e);
} else {
err = e;
}
done(err);
});
}
})();
}
}

export { AfcReadableFileStream, AfcWritableFileStream };
8 changes: 4 additions & 4 deletions lib/house-arrest/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import PlistServiceDecoder from '../plist-service/transformer/plist-service-decoder';
import PlistServiceEncoder from '../plist-service/transformer/plist-service-encoder';
import LengthBasedSplitter from '../util/transformer/length-based-splitter';
import { PlistServiceDecoder } from '../plist-service/transformer/plist-service-decoder';
import { PlistServiceEncoder } from '../plist-service/transformer/plist-service-encoder';
import { LengthBasedSplitter } from '../util/transformer/length-based-splitter';
import { KB } from '../constants';
import AfcService from '../afc';
import { AfcService } from '../afc';
import B from 'bluebird';
import { BaseServiceSocket } from '../base-service';

Expand Down
2 changes: 1 addition & 1 deletion lib/imagemounter/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseServicePlist } from '../base-service';
import { fs } from '@appium/support';
import B from 'bluebird';
import log from '../logger';
import { log } from '../logger';
const { lstat, readFile, createReadStream } = fs;

const MOBILE_IMAGE_MOUNTER_SERVICE_NAME = 'com.apple.mobile.mobile_image_mounter';
Expand Down
2 changes: 1 addition & 1 deletion lib/imagemounter/utils/list_developer_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash';
import { zip, net, env, fs } from '@appium/support';
import { join as joinPath } from 'path';
import axios from 'axios';
import log from '../../logger';
import { log } from '../../logger';

const { exists, readdir, mkdir, rimraf } = fs;
/**
Expand Down
3 changes: 1 addition & 2 deletions lib/instrument/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ class DTXMessage {
flags: this._flags,
auxLength: aux.length,
// need to convert to bigint in any case
// eslint-disable-next-line no-undef
totalLength: BigInt(aux.length + sel.length),
});

Expand Down Expand Up @@ -428,7 +427,7 @@ class DTXMessage {
try {
ret.selector = fun(data);
break;
} catch (e) {
} catch {
ret.selector = new InstrumentRPCParseError(data);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/instrument/transformer/dtx-decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
DTX_MESSAGE_HEADER_LENGTH, DTX_MESSAGE_HEADER_MAGIC, DTX_MESSAGE_HEADER_MAGIC_LEN,
DTXMessageHeader, DTXMessage,
} from '../headers';
import log from '../../logger';
import { log } from '../../logger';

class DTXDecoder extends Stream.Transform {

Expand Down
4 changes: 2 additions & 2 deletions lib/instrument/transformer/nskeyed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import bplistCreate from 'bplist-creator';
import { parse as uuidParse, stringify as uuidStringify } from 'uuid';
import _ from 'lodash';
import { format as stringFormat } from 'node:util';
import log from '../../logger';
import { log } from '../../logger';

const NSKEYED_ARCHIVE_VERSION = 100_000;
// @ts-ignore UID is not exposed to typedefs
Expand Down Expand Up @@ -375,7 +375,7 @@ class Unarchive {
const createPlistIssue = (/** @type {string} */ message) => {
try {
log.debug(`Source plist: ${_.truncate(JSON.stringify(plist), {length: 250})}`);
} catch (ign) {}
} catch {}
return new Error(message);
};
if (plist.$archiver !== NSKEYEDARCHIVER) {
Expand Down
4 changes: 1 addition & 3 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { logger } from '@appium/support';

const log = logger.getLogger('ios-device');

export default log;
export const log = logger.getLogger('ios-device');
6 changes: 3 additions & 3 deletions lib/notification-proxy/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PlistServiceEncoder from '../plist-service/transformer/plist-service-encoder';
import PlistServiceDecoder from '../plist-service/transformer/plist-service-decoder';
import LengthBasedSplitter from '../util/transformer/length-based-splitter';
import { PlistServiceEncoder } from '../plist-service/transformer/plist-service-encoder';
import { PlistServiceDecoder } from '../plist-service/transformer/plist-service-decoder';
import { LengthBasedSplitter } from '../util/transformer/length-based-splitter';
import { KB } from '../constants';
import _ from 'lodash';
import { BaseServiceSocket } from '../base-service';
Expand Down
6 changes: 3 additions & 3 deletions lib/plist-service/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import B from 'bluebird';
import { upgradeToSSL } from '../ssl-helper';
import PlistServiceEncoder from './transformer/plist-service-encoder';
import PlistServiceDecoder from './transformer/plist-service-decoder';
import LengthBasedSplitter from '../util/transformer/length-based-splitter';
import { PlistServiceEncoder } from './transformer/plist-service-encoder';
import { PlistServiceDecoder } from './transformer/plist-service-decoder';
import { LengthBasedSplitter } from '../util/transformer/length-based-splitter';
import { BaseServiceSocket } from '../base-service';
import { MB } from '../constants';

Expand Down
4 changes: 2 additions & 2 deletions lib/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { InstrumentService, INSTRUMENT_SERVICE_NAME_VERSION_14, INSTRUMENT_SERVI
import { TestmanagerdService, TESTMANAGERD_SERVICE_NAME_VERSION_14, TESTMANAGERD_SERVICE_NAME } from './testmanagerd';
import { MCInstallProxyService, MC_INSTALL_SERVICE_NAME } from './mcinstall';
import { ImageMounter, MOBILE_IMAGE_MOUNTER_SERVICE_NAME } from './imagemounter';
import PlistService from './plist-service';
import semver from 'semver';
import { PlistService } from './plist-service';
import * as semver from 'semver';


const CRASH_LOG_SERVICE_NAME = 'com.apple.crashreportcopymobile';
Expand Down
2 changes: 1 addition & 1 deletion lib/syslog/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SyslogDecoder from './transformer/syslog-decoder';
import { SyslogDecoder } from './transformer/syslog-decoder';
import { KB } from '../constants';
import { BaseServiceSocket } from '../base-service';

Expand Down
14 changes: 7 additions & 7 deletions lib/usbmux/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import os from 'os';
import _ from 'lodash';
import B from 'bluebird';
import { plist, fs } from '@appium/support';
import LengthBasedSplitter from '../util/transformer/length-based-splitter';
import UsbmuxDecoder from './transformer/usbmux-decoder.js';
import UsbmuxEncoder from './transformer/usbmux-encoder.js';
import { LengthBasedSplitter } from '../util/transformer/length-based-splitter';
import { UsbmuxDecoder } from './transformer/usbmux-decoder.js';
import { UsbmuxEncoder } from './transformer/usbmux-encoder.js';
import path from 'path';
import PlistService from '../plist-service';
import { PlistService } from '../plist-service';
import { Lockdown, LOCKDOWN_PORT } from '../lockdown';
import { BaseServiceSocket } from '../base-service';
import { MB } from '../constants';
import log from '../logger';
import { log } from '../logger';


const MAX_FRAME_SIZE = 1 * MB;
Expand All @@ -27,7 +27,7 @@ let name, version;
try {
// first try assuming this is in the `build` folder
({ name, version } = require(path.resolve(__dirname, '..', '..', '..', 'package.json')));
} catch (err) {
} catch {
// then try assuming it is not
({ name, version } = require(path.resolve(__dirname, '..', '..', 'package.json')));
}
Expand Down Expand Up @@ -171,7 +171,7 @@ class Usbmux extends BaseServiceSocket {
}
try {
return plist.parsePlist(data.payload.PairRecordData);
} catch (err) {
} catch {
throw new Error(`Unexpected data: ${JSON.stringify(data)}`);
}
});
Expand Down
5 changes: 2 additions & 3 deletions lib/util/transformer/length-based-splitter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Stream from 'stream';
import log from '../../logger';
import { log } from '../../logger';

class LengthBasedSplitter extends Stream.Transform {
export class LengthBasedSplitter extends Stream.Transform {
constructor (opts) {
super();

Expand Down Expand Up @@ -108,5 +108,4 @@ class LengthBasedSplitter extends Stream.Transform {
}
}

export { LengthBasedSplitter};
export default LengthBasedSplitter;
5 changes: 2 additions & 3 deletions lib/util/transformer/stream-logger.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Stream from 'stream';
import _ from 'lodash';
import log from '../../logger';
import { log } from '../../logger';


const MIN_PRINTABLE_CHAR = 32;
const MAX_PRINTABLE_CHAR = 126;

const CHARACTERS_PER_LINE = 19;

class StreamLogger extends Stream.Transform {
export class StreamLogger extends Stream.Transform {
constructor (direction, verbose = false) {
super({ objectMode: true });

Expand Down Expand Up @@ -64,5 +64,4 @@ class StreamLogger extends Stream.Transform {
StreamLogger.SEND = 0;
StreamLogger.RECEIVE = 1;

export { StreamLogger };
export default StreamLogger;
4 changes: 2 additions & 2 deletions lib/utilities.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Usbmux, { getDefaultSocket } from './usbmux';
import { Usbmux, getDefaultSocket } from './usbmux';
import { upgradeToSSL, enableSSLHandshakeOnly } from './ssl-helper';
import _ from 'lodash';
import log from './logger';
import { log } from './logger';
import { findDeveloperImage } from './imagemounter/utils/list_developer_image';

// https://github.com/samdmarshall/iOS-Internals/blob/master/lockbot/lockbot/lockdown_keys.h
Expand Down
14 changes: 7 additions & 7 deletions lib/webinspector/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import WebInspectorDecoder from './transformer/webinspector-decoder';
import WebInspectorEncoder from './transformer/webinspector-encoder';
import PlistServiceDecoder from '../plist-service/transformer/plist-service-decoder';
import PlistServiceEncoder from '../plist-service/transformer/plist-service-encoder';
import LengthBasedSplitter from '../util/transformer/length-based-splitter';
import StreamLogger from '../util/transformer/stream-logger';
import { WebInspectorDecoder } from './transformer/webinspector-decoder';
import { WebInspectorEncoder } from './transformer/webinspector-encoder';
import { PlistServiceDecoder } from '../plist-service/transformer/plist-service-decoder';
import { PlistServiceEncoder } from '../plist-service/transformer/plist-service-encoder';
import { LengthBasedSplitter } from '../util/transformer/length-based-splitter';
import { StreamLogger } from '../util/transformer/stream-logger';
import _ from 'lodash';
import { util } from '@appium/support';
import { MB } from '../constants';
import log from '../logger';
import { log } from '../logger';
import { BaseServiceSocket } from '../base-service';


Expand Down
2 changes: 1 addition & 1 deletion lib/xctest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NSUUID, XCTestConfiguration } from './instrument/transformer/nskeyed';
import { TESTMANAGERD_CHANNEL } from './testmanagerd';
import { util } from '@appium/support';
import { getOSVersion } from './utilities';
import log from './logger';
import { log } from './logger';
import B from 'bluebird';

const { DAEMON_CONNECTION_INTERFACE } = TESTMANAGERD_CHANNEL;
Expand Down
Loading

0 comments on commit ebfdc6d

Please sign in to comment.