Skip to content

Commit 1c2a8c5

Browse files
chore: Integrate oxc and release configs (#896)
1 parent a767d41 commit 1c2a8c5

58 files changed

Lines changed: 662 additions & 1554 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
max_line_length = 120
12+
13+
[*.md]
14+
trim_trailing_whitespace = false

.github/workflows/unit-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ jobs:
2929
- run: npm run lint
3030
name: Run linter
3131
- run: npm run format:check
32-
name: Run Prettier check
32+
name: Run format check
3333
- run: npm run test
3434
name: Run unit tests

.releaserc

Lines changed: 0 additions & 37 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 0 additions & 10 deletions
This file was deleted.

lib/adb.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
import os from 'node:os';
2-
import {log} from './logger.js';
3-
import type {ADBOptions, ADBExecutable} from './types.js';
4-
import type {Logcat} from './logcat.js';
5-
import type {LogcatOpts, StringRecord} from './tools/types.js';
2+
63
import type {LRUCache} from 'lru-cache';
74
import type {ExecError} from 'teen_process';
85

9-
import * as generalCommands from './tools/general-commands.js';
6+
import type {Logcat} from './logcat.js';
7+
import {log} from './logger.js';
8+
import * as aabUtilCommands from './tools/aab-utils.js';
109
import * as manifestCommands from './tools/android-manifest.js';
11-
import * as systemCommands from './tools/system-calls.js';
1210
import * as signingCommands from './tools/apk-signing.js';
1311
import * as apkUtilCommands from './tools/apk-utils.js';
1412
import * as apksUtilCommands from './tools/apks-utils.js';
15-
import * as aabUtilCommands from './tools/aab-utils.js';
16-
import * as emuCommands from './tools/emulator-commands.js';
17-
import * as emuConstants from './tools/emu-constants.js';
18-
import * as lockManagementCommands from './tools/lockmgmt.js';
19-
import * as keyboardCommands from './tools/keyboard-commands.js';
13+
import * as appCommands from './tools/app-commands.js';
2014
import * as deviceSettingsCommands from './tools/device-settings.js';
15+
import * as emuConstants from './tools/emu-constants.js';
16+
import * as emuCommands from './tools/emulator-commands.js';
2117
import * as fsCommands from './tools/fs-commands.js';
22-
import * as appCommands from './tools/app-commands.js';
23-
import * as networkCommands from './tools/network-commands.js';
18+
import * as generalCommands from './tools/general-commands.js';
19+
import * as keyboardCommands from './tools/keyboard-commands.js';
20+
import * as lockManagementCommands from './tools/lockmgmt.js';
2421
import * as logcatCommands from './tools/logcat-commands.js';
22+
import * as networkCommands from './tools/network-commands.js';
2523
import * as processCommands from './tools/process-commands.js';
24+
import * as systemCommands from './tools/system-calls.js';
25+
import type {LogcatOpts, StringRecord} from './tools/types.js';
26+
import type {ADBOptions, ADBExecutable} from './types.js';
2627
import {
2728
DEFAULT_ADB_EXEC_TIMEOUT,
2829
cloneDeep,

lib/logcat.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
1-
import {logger, util} from '@appium/support';
21
import {EventEmitter} from 'node:events';
3-
import {SubProcess, exec} from 'teen_process';
2+
3+
import {logger, util} from '@appium/support';
44
import {LRUCache} from 'lru-cache';
5+
import {SubProcess, exec} from 'teen_process';
56
import type {ExecError} from 'teen_process';
6-
import type {ADBExecutable} from './types.js';
7+
78
import type {LogEntry, LogcatOpts as StartCaptureOptions} from './tools/types.js';
9+
import type {ADBExecutable} from './types.js';
810

911
const log = logger.getLogger('Logcat');
1012
const MAX_BUFFER_SIZE = 10000;
1113
const LOGCAT_PROC_STARTUP_TIMEOUT = 10000;
12-
const SUPPORTED_FORMATS = [
13-
'brief',
14-
'process',
15-
'tag',
16-
'thread',
17-
'raw',
18-
'time',
19-
'threadtime',
20-
'long',
21-
] as const;
14+
const SUPPORTED_FORMATS = ['brief', 'process', 'tag', 'thread', 'raw', 'time', 'threadtime', 'long'] as const;
2215
const SUPPORTED_PRIORITIES = ['v', 'd', 'i', 'w', 'e', 'f', 's'] as const;
2316
const DEFAULT_PRIORITY = 'v';
2417
const DEFAULT_TAG = '*';
@@ -139,10 +132,7 @@ export class Logcat extends EventEmitter {
139132
continue;
140133
}
141134
const [message, timestamp] = value;
142-
if (
143-
(this.logIndexSinceLastRequest && index > this.logIndexSinceLastRequest) ||
144-
!this.logIndexSinceLastRequest
145-
) {
135+
if ((this.logIndexSinceLastRequest && index > this.logIndexSinceLastRequest) || !this.logIndexSinceLastRequest) {
146136
recentLogIndex = index;
147137
result.push(toLogEntry(message, timestamp));
148138
}
@@ -215,15 +205,11 @@ function requireSpec(spec: string): string {
215205
resultTag = DEFAULT_TAG;
216206
}
217207
if (!priority) {
218-
log.info(
219-
`The priority value in spec '${spec}' is empty. Defaulting to Verbose (${DEFAULT_PRIORITY})`,
220-
);
208+
log.info(`The priority value in spec '${spec}' is empty. Defaulting to Verbose (${DEFAULT_PRIORITY})`);
221209
return `${resultTag}:${DEFAULT_PRIORITY}`;
222210
}
223211
if (!SUPPORTED_PRIORITIES.some((p) => priority.toLowerCase() === p.toLowerCase())) {
224-
log.info(
225-
`The priority value in spec '${spec}' is unknown. Supported values are: ${SUPPORTED_PRIORITIES}`,
226-
);
212+
log.info(`The priority value in spec '${spec}' is unknown. Supported values are: ${SUPPORTED_PRIORITIES}`);
227213
log.info(`Defaulting to Verbose (${DEFAULT_PRIORITY})`);
228214
return `${resultTag}:${DEFAULT_PRIORITY}`;
229215
}

lib/tools/aab-utils.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import {log} from '../logger.js';
1+
import crypto from 'node:crypto';
22
import path from 'node:path';
3+
34
import {fs, tempDir, util} from '@appium/support';
4-
import {LRUCache} from 'lru-cache';
55
import AsyncLock from 'async-lock';
6-
import crypto from 'node:crypto';
6+
import {LRUCache} from 'lru-cache';
7+
78
import type {ADB} from '../adb.js';
8-
import type {ApkCreationOptions, StringRecord} from './types.js';
9+
import {log} from '../logger.js';
910
import {unzipFile} from '../utils/index.js';
11+
import type {ApkCreationOptions, StringRecord} from './types.js';
1012

1113
const AAB_CACHE = new LRUCache<string, string>({
1214
max: 10,
@@ -21,9 +23,7 @@ process.on('exit', () => {
2123
}
2224

2325
const paths = [...AAB_CACHE.values()];
24-
log.debug(
25-
`Performing cleanup of ${paths.length} cached .aab ` + util.pluralize('package', paths.length),
26-
);
26+
log.debug(`Performing cleanup of ${paths.length} cached .aab ` + util.pluralize('package', paths.length));
2727
for (const appPath of paths) {
2828
try {
2929
// Asynchronous calls are not supported in onExit handler
@@ -45,11 +45,7 @@ process.on('exit', () => {
4545
* by default.
4646
* @throws {Error} If there was an error while creating the universal .apk
4747
*/
48-
export async function extractUniversalApk(
49-
this: ADB,
50-
aabPath: string,
51-
opts: ApkCreationOptions = {},
52-
): Promise<string> {
48+
export async function extractUniversalApk(this: ADB, aabPath: string, opts: ApkCreationOptions = {}): Promise<string> {
5349
if (!(await fs.exists(aabPath))) {
5450
throw new Error(`The file at '${aabPath}' either does not exist or is not accessible`);
5551
}
@@ -65,9 +61,7 @@ export async function extractUniversalApk(
6561
let cacheHash = aabHash;
6662
if (keystore) {
6763
if (!(await fs.exists(keystore))) {
68-
throw new Error(
69-
`The keystore file at '${keystore}' either does not exist ` + `or is not accessible`,
70-
);
64+
throw new Error(`The keystore file at '${keystore}' either does not exist or is not accessible`);
7165
}
7266
if (!keystorePassword || !keyAlias || !keyPassword) {
7367
throw new Error(

lib/tools/android-manifest.ts

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import {exec} from 'teen_process';
2-
import {log} from '../logger.js';
3-
import {fs, zip, tempDir, util} from '@appium/support';
41
import path from 'node:path';
2+
3+
import {fs, zip, tempDir, util} from '@appium/support';
4+
import {exec} from 'teen_process';
5+
56
import type {ADB} from '../adb.js';
6-
import type {APKInfo, PlatformInfo, StringRecord} from './types.js';
7+
import {log} from '../logger.js';
78
import {APKS_EXTENSION, readPackageManifest, unzipFile} from '../utils/index.js';
9+
import type {APKInfo, PlatformInfo, StringRecord} from './types.js';
810

911
/**
1012
* Extract package and main activity name from application manifest.
@@ -14,10 +16,7 @@ import {APKS_EXTENSION, readPackageManifest, unzipFile} from '../utils/index.js'
1416
* @throws {error} If there was an error while getting the data from the given
1517
* application package.
1618
*/
17-
export async function packageAndLaunchActivityFromManifest(
18-
this: ADB,
19-
appPath: string,
20-
): Promise<APKInfo> {
19+
export async function packageAndLaunchActivityFromManifest(this: ADB, appPath: string): Promise<APKInfo> {
2120
if (appPath.endsWith(APKS_EXTENSION)) {
2221
appPath = await this.extractBaseApk(appPath);
2322
}
@@ -48,10 +47,7 @@ export async function targetSdkVersionFromManifest(this: ADB, appPath: string):
4847

4948
const {targetSdkVersion} = await readPackageManifest.bind(this)(appPath);
5049
if (!targetSdkVersion) {
51-
throw new Error(
52-
`Cannot extract targetSdkVersion of '${originalAppPath}'. Does ` +
53-
`the package manifest define it?`,
54-
);
50+
throw new Error(`Cannot extract targetSdkVersion of '${originalAppPath}'. Does the package manifest define it?`);
5551
}
5652
return targetSdkVersion;
5753
}
@@ -71,9 +67,7 @@ export async function targetSdkVersionUsingPKG(
7167
): Promise<number> {
7268
const stdout = cmdOutput || (await this.shell(['dumpsys', 'package', pkg]));
7369
const targetSdkVersionMatch = new RegExp(/targetSdk=([^\s\s]+)/g).exec(stdout);
74-
return targetSdkVersionMatch && targetSdkVersionMatch.length >= 2
75-
? parseInt(targetSdkVersionMatch[1], 10)
76-
: 0;
70+
return targetSdkVersionMatch && targetSdkVersionMatch.length >= 2 ? parseInt(targetSdkVersionMatch[1], 10) : 0;
7771
}
7872

7973
/**
@@ -93,9 +87,7 @@ export async function compileManifest(
9387
): Promise<void> {
9488
const {platform, platformPath} = await getAndroidPlatformAndPath(this.sdkRoot as string);
9589
if (!platform || !platformPath) {
96-
throw new Error(
97-
'Cannot compile the manifest. The required platform does not exist (API level >= 17)',
98-
);
90+
throw new Error('Cannot compile the manifest. The required platform does not exist (API level >= 17)');
9991
}
10092
const resultPath = `${manifest}.apk`;
10193
const androidJarPath = path.resolve(platformPath, 'android.jar');
@@ -169,12 +161,7 @@ export async function compileManifest(
169161
* @param dstApk - Full path to the resulting package.
170162
* The file will be overridden if it already exists.
171163
*/
172-
export async function insertManifest(
173-
this: ADB,
174-
manifest: string,
175-
srcApk: string,
176-
dstApk: string,
177-
): Promise<void> {
164+
export async function insertManifest(this: ADB, manifest: string, srcApk: string, dstApk: string): Promise<void> {
178165
log.debug(`Inserting manifest '${manifest}', src: '${srcApk}', dst: '${dstApk}'`);
179166
await zip.assertValidZip(srcApk);
180167
await unzipFile(`${manifest}.apk`);
@@ -221,10 +208,7 @@ export async function insertManifest(
221208
* @param appPath - The full path to .apk(s) package.
222209
* @return True if the manifest requires Internet access permission.
223210
*/
224-
export async function hasInternetPermissionFromManifest(
225-
this: ADB,
226-
appPath: string,
227-
): Promise<boolean> {
211+
export async function hasInternetPermissionFromManifest(this: ADB, appPath: string): Promise<boolean> {
228212
log.debug(`Checking if '${appPath}' requires internet access permission in the manifest`);
229213
if (appPath.endsWith(APKS_EXTENSION)) {
230214
appPath = await this.extractBaseApk(appPath);

0 commit comments

Comments
 (0)