From cbaf17f6400a1b1c4c4097944ad996a17dc1672b Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Wed, 24 May 2023 14:47:50 -0700 Subject: [PATCH] chore: build with typescript instead of babel --- .mocharc.js | 2 +- babel.config.json | 25 ------------- index.js | 4 ++- lib/android-helpers.js | 2 +- lib/stubs.ts | 3 ++ package.json | 35 ++++++++++++------- .../bootstrap/bootstrap-e2e-specs.js | 2 -- .../bootstrap/uiautomator-e2e-specs.js | 2 -- test/unit/bootstrap/bootstrap-specs.js | 2 -- test/unit/bootstrap/uiautomator-specs.js | 2 -- tsconfig.json | 13 +++++++ 11 files changed, 43 insertions(+), 49 deletions(-) delete mode 100644 babel.config.json create mode 100644 lib/stubs.ts create mode 100644 tsconfig.json diff --git a/.mocharc.js b/.mocharc.js index 66d4a976..40599e9d 100644 --- a/.mocharc.js +++ b/.mocharc.js @@ -1,4 +1,4 @@ module.exports = { - require: ['@babel/register'], + require: ['ts-node/register'], forbidOnly: Boolean(process.env.CI) }; diff --git a/babel.config.json b/babel.config.json deleted file mode 100644 index 048e9cf6..00000000 --- a/babel.config.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "presets": [ - [ - "@babel/preset-env", - { - "targets": { - "node": "14" - }, - "shippedProposals": true - } - ] - ], - "plugins": [ - "source-map-support", - "@babel/plugin-transform-runtime" - ], - "comments": false, - "sourceMaps": "both", - "env": { - "test": { - "retainLines": true, - "comments": true - } - } -} diff --git a/index.js b/index.js index e9c39afb..4d882878 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,7 @@ #!/usr/bin/env node -// transpile:main +import {install} from 'source-map-support'; +install(); + import * as driver from './lib/driver'; import * as androidHelperIndex from './lib/android-helpers'; import * as commandIndex from './lib/commands/index'; diff --git a/lib/android-helpers.js b/lib/android-helpers.js index bc264779..89f46537 100644 --- a/lib/android-helpers.js +++ b/lib/android-helpers.js @@ -8,7 +8,7 @@ import Bootstrap from './bootstrap'; import B from 'bluebird'; import ADB from 'appium-adb'; import { - default as unlocker, PIN_UNLOCK, PIN_UNLOCK_KEY_EVENT, + unlocker, PIN_UNLOCK, PIN_UNLOCK_KEY_EVENT, PASSWORD_UNLOCK, PATTERN_UNLOCK, FINGERPRINT_UNLOCK } from './unlock-helpers'; import { EOL } from 'os'; diff --git a/lib/stubs.ts b/lib/stubs.ts new file mode 100644 index 00000000..13f03e74 --- /dev/null +++ b/lib/stubs.ts @@ -0,0 +1,3 @@ +declare module 'appium-adb'; +declare module 'shared-preferences-builder'; +declare module 'io.appium.settings'; diff --git a/package.json b/package.json index 110a480e..72c1376b 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,6 @@ "CHANGELOG.md" ], "dependencies": { - "@babel/runtime": "^7.0.0", "appium-adb": "^9.11.2", "appium-chromedriver": "^5.2.0", "asyncbox": "^2.8.0", @@ -60,21 +59,23 @@ "moment-timezone": "^0.5.26", "portfinder": "^1.0.6", "portscanner": "2.2.0", + "semver": "^7.0.0", "shared-preferences-builder": "^0.x", "sharp": "^0.x", - "semver": "^7.0.0", "source-map-support": "^0.x", "teen_process": "^2.0.0", "ws": "^8.0.0" }, "scripts": { - "build": "rimraf build && babel --out-dir=build/lib lib && babel --out-dir=build index.js", + "build": "tsc -b", + "clean": "npm run build -- --clean", "dev": "npm run build -- --watch", "lint": "eslint .", "lint:fix": "npm run lint -- --fix", "precommit-msg": "echo 'Pre-commit checks...' && exit 0", "precommit-lint": "lint-staged", - "prepare": "npm run build", + "prepare": "npm run rebuild", + "rebuild": "npm run clean && npm run build", "test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.js\"", "e2e-test": "mocha --exit --timeout 10m \"./test/functional/**/*-specs.js\"" }, @@ -86,20 +87,27 @@ "appium": "^2.0.0-beta.40" }, "devDependencies": { - "@appium/support": "^4.0.0", "@appium/eslint-config-appium": "^6.0.0", + "@appium/support": "^4.0.0", "@appium/test-support": "^3.0.0", - "@babel/cli": "^7.18.10", - "@babel/core": "^7.18.10", - "@babel/eslint-parser": "^7.18.9", - "@babel/plugin-transform-runtime": "^7.18.10", - "@babel/preset-env": "^7.18.10", - "@babel/register": "^7.18.9", + "@appium/tsconfig": "^0.3.0", + "@appium/types": "^0.11.1", "@semantic-release/changelog": "^6.0.1", "@semantic-release/git": "^10.0.1", + "@types/bluebird": "^3.5.38", + "@types/chai": "^4.3.5", + "@types/chai-as-promised": "^7.1.5", + "@types/lodash": "^4.14.194", + "@types/mocha": "^10.0.1", + "@types/node": "^20.2.3", + "@types/portscanner": "^2.1.1", + "@types/semver": "^7.5.0", + "@types/sinon": "^10.0.15", + "@types/source-map-support": "^0.5.6", + "@types/teen_process": "^2.0.0", + "@types/ws": "^8.5.4", "@xmldom/xmldom": "^0.x", "android-apidemos": "^4.1.0", - "babel-plugin-source-map-support": "^2.2.0", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", "conventional-changelog-conventionalcommits": "^5.0.0", @@ -110,11 +118,12 @@ "eslint-plugin-promise": "^6.0.0", "lint-staged": "^13.0.3", "mocha": "^10.0.0", - "mock-fs": "^5.0.0", "pre-commit": "^1.1.3", "rimraf": "^5.0.0", "semantic-release": "^20.0.2", "sinon": "^15.0.0", + "ts-node": "^10.9.1", + "typescript": "^5.0.4", "xpath": "^0.x" } } diff --git a/test/functional/bootstrap/bootstrap-e2e-specs.js b/test/functional/bootstrap/bootstrap-e2e-specs.js index b3289e16..77b49af7 100644 --- a/test/functional/bootstrap/bootstrap-e2e-specs.js +++ b/test/functional/bootstrap/bootstrap-e2e-specs.js @@ -1,5 +1,3 @@ -// transpile :mocha - import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { AndroidBootstrap, COMMAND_TYPES } from '../../../lib/bootstrap'; diff --git a/test/functional/bootstrap/uiautomator-e2e-specs.js b/test/functional/bootstrap/uiautomator-e2e-specs.js index 282e7f12..1379ce34 100644 --- a/test/functional/bootstrap/uiautomator-e2e-specs.js +++ b/test/functional/bootstrap/uiautomator-e2e-specs.js @@ -1,5 +1,3 @@ -// transpile :mocha - import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { UiAutomator } from '../../../lib/uiautomator'; diff --git a/test/unit/bootstrap/bootstrap-specs.js b/test/unit/bootstrap/bootstrap-specs.js index 89c0ea3d..62c27ca6 100644 --- a/test/unit/bootstrap/bootstrap-specs.js +++ b/test/unit/bootstrap/bootstrap-specs.js @@ -1,5 +1,3 @@ -// transpile :mocha - import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { AndroidBootstrap, COMMAND_TYPES } from '../../../lib/bootstrap'; diff --git a/test/unit/bootstrap/uiautomator-specs.js b/test/unit/bootstrap/uiautomator-specs.js index 739d7a3d..a856f0aa 100644 --- a/test/unit/bootstrap/uiautomator-specs.js +++ b/test/unit/bootstrap/uiautomator-specs.js @@ -1,5 +1,3 @@ -// transpile :mocha - import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import sinon from 'sinon'; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..f9075ae7 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "@appium/tsconfig/tsconfig.json", + "compilerOptions": { + "outDir": "build", + "types": ["node", "mocha", "chai", "chai-as-promised", "sinon"] + }, + "include": [ + "index.js", + "lib", + "test" + ] +}