Skip to content

Commit bf3e49b

Browse files
feat: Migrate the module to typescript
1 parent f3305c2 commit bf3e49b

17 files changed

+679
-711
lines changed
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
const path = require('path');
2-
const { asyncify } = require('asyncbox');
3-
const { logger, fs } = require('@appium/support');
4-
const { exec } = require('teen_process');
5-
const xcode = require('appium-xcode');
1+
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
import { asyncify } from 'asyncbox';
4+
import { logger, fs } from '@appium/support';
5+
import { exec } from 'teen_process';
6+
import xcode from 'appium-xcode';
7+
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = path.dirname(__filename);
10+
const isMainModule = process.argv[1] && path.resolve(process.argv[1]) === __filename;
611

712
const LOG = new logger.getLogger('WDABuild');
813
const ROOT_DIR = path.resolve(__dirname, '..');
@@ -72,8 +77,9 @@ async function buildWebDriverAgent (xcodeVersion) {
7277
LOG.info(`Zip bundled at "${appBundleZipPath}"`);
7378
}
7479

75-
if (require.main === module) {
80+
if (isMainModule) {
7681
asyncify(buildWebDriverAgent);
7782
}
7883

79-
module.exports = buildWebDriverAgent;
84+
export default buildWebDriverAgent;
85+
Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
const path = require('path');
2-
const axios = require('axios');
3-
const { asyncify } = require('asyncbox');
4-
const { logger, fs, mkdirp, net } = require('@appium/support');
5-
const _ = require('lodash');
6-
const B = require('bluebird');
1+
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
import { readFileSync } from 'node:fs';
4+
import axios from 'axios';
5+
import { asyncify } from 'asyncbox';
6+
import { logger, fs, mkdirp, net } from '@appium/support';
7+
import _ from 'lodash';
8+
import B from 'bluebird';
9+
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = path.dirname(__filename);
12+
const isMainModule = process.argv[1] && path.resolve(process.argv[1]) === __filename;
713

814
const log = logger.getLogger('WDA');
915

1016
async function fetchPrebuiltWebDriverAgentAssets () {
11-
const tag = require('../package.json').version;
17+
const packageJson = JSON.parse(readFileSync(path.resolve(__dirname, '..', 'package.json'), 'utf8'));
18+
const tag = packageJson.version;
1219
log.info(`Getting links to webdriveragent release ${tag}`);
1320
const downloadUrl = `https://api.github.com/repos/appium/webdriveragent/releases/tags/v${tag}`;
1421
log.info(`Getting WDA release ${downloadUrl}`);
@@ -54,8 +61,9 @@ async function fetchPrebuiltWebDriverAgentAssets () {
5461
return await B.all(agentsDownloading);
5562
}
5663

57-
if (require.main === module) {
64+
if (isMainModule) {
5865
asyncify(fetchPrebuiltWebDriverAgentAssets);
5966
}
6067

61-
module.exports = fetchPrebuiltWebDriverAgentAssets;
68+
export default fetchPrebuiltWebDriverAgentAssets;
69+
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
const {plist, logger} = require('@appium/support');
2-
const path = require('node:path');
3-
const semver = require('semver');
1+
import {plist, logger} from '@appium/support';
2+
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
import semver from 'semver';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
48

59
const log = logger.getLogger('Versioner');
610

@@ -39,3 +43,4 @@ async function updateWdaVersion() {
3943
}
4044

4145
(async () => await updateWdaVersion())();
46+

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { checkForDependencies, bundleWDASim } from './lib/check-dependencies';
1+
export { bundleWDASim } from './lib/check-dependencies';
22
export { NoSessionProxy } from './lib/no-session-proxy';
33
export { WebDriverAgent } from './lib/webdriveragent';
44
export { WDA_BASE_URL, WDA_RUNNER_BUNDLE_ID, PROJECT_FILE } from './lib/constants';
Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {
55
WDA_SCHEME, SDK_SIMULATOR, WDA_RUNNER_APP
66
} from './constants';
77
import { BOOTSTRAP_PATH } from './utils';
8-
import log from './logger';
8+
import type { XcodeBuild } from './xcodebuild';
99

10-
async function buildWDASim () {
10+
async function buildWDASim (): Promise<void> {
1111
const args = [
1212
'-project', path.join(BOOTSTRAP_PATH, 'WebDriverAgent.xcodeproj'),
1313
'-scheme', WDA_SCHEME,
@@ -19,17 +19,7 @@ async function buildWDASim () {
1919
await exec('xcodebuild', args);
2020
}
2121

22-
export async function checkForDependencies () {
23-
log.debug('Dependencies are up to date');
24-
return false;
25-
}
26-
27-
/**
28-
*
29-
* @param {import('./xcodebuild').XcodeBuild} xcodebuild
30-
* @returns {Promise<string>}
31-
*/
32-
export async function bundleWDASim (xcodebuild) {
22+
export async function bundleWDASim (xcodebuild: XcodeBuild): Promise<string> {
3323
const derivedDataPath = await xcodebuild.retrieveDerivedDataPath();
3424
if (!derivedDataPath) {
3525
throw new Error('Cannot retrieve the path to the Xcode derived data folder');
@@ -41,3 +31,4 @@ export async function bundleWDASim (xcodebuild) {
4131
await buildWDASim();
4232
return wdaBundlePath;
4333
}
34+

lib/constants.js

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

lib/constants.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import path from 'node:path';
2+
3+
export const DEFAULT_TEST_BUNDLE_SUFFIX = '.xctrunner';
4+
export const WDA_RUNNER_BUNDLE_ID = 'com.facebook.WebDriverAgentRunner';
5+
export const WDA_RUNNER_BUNDLE_ID_FOR_XCTEST = `${WDA_RUNNER_BUNDLE_ID}${DEFAULT_TEST_BUNDLE_SUFFIX}`;
6+
export const WDA_RUNNER_APP = 'WebDriverAgentRunner-Runner.app';
7+
export const WDA_SCHEME = 'WebDriverAgentRunner';
8+
export const PROJECT_FILE = 'project.pbxproj';
9+
export const WDA_BASE_URL = 'http://127.0.0.1';
10+
11+
export const PLATFORM_NAME_TVOS = 'tvOS';
12+
export const PLATFORM_NAME_IOS = 'iOS';
13+
14+
export const SDK_SIMULATOR = 'iphonesimulator';
15+
export const SDK_DEVICE = 'iphoneos';
16+
17+
export const WDA_UPGRADE_TIMESTAMP_PATH = path.join('.appium', 'webdriveragent', 'upgrade.time');
18+

lib/logger.js

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

lib/logger.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { logger } from '@appium/support';
2+
3+
export const log = logger.getLogger('WebDriverAgent');
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { JWProxy } from '@appium/base-driver';
2+
import type { ProxyOptions } from '@appium/types';
23

34

4-
class NoSessionProxy extends JWProxy {
5-
constructor (opts = {}) {
5+
export class NoSessionProxy extends JWProxy {
6+
constructor (opts: ProxyOptions = {}) {
67
super(opts);
78
}
89

9-
getUrlForProxy (url) {
10+
override getUrlForProxy (url: string): string {
1011
if (url === '') {
1112
url = '/';
1213
}
@@ -22,5 +23,3 @@ class NoSessionProxy extends JWProxy {
2223
}
2324
}
2425

25-
export { NoSessionProxy };
26-
export default NoSessionProxy;

0 commit comments

Comments
 (0)