Commit Graph

8879 Commits

Author SHA1 Message Date
Christopher Hiller 06a605420d feat(appium): generate declaration files (#16597)
* feat(appium): generate declaration files

Configure TS to generate declaration files for `appium` package.

Most of these changes are just types getting added or changed via docstrings; in other places, typechecking has caught problems and I had to refactor code to address them.

- Removed `// @ts-check` pragma from all files in `lib/`, since now `checkJs: true` is in `tsconfig.json`.  It needs to stay in place elsewhere (I think) because only sources in `lib` have declarations generated.
- The `install`, `uninstall`, `update` and `run` functions in the base `ExtensionCommand` class were renamed and prefixed with a `_`; TS does not allow overridden functions with differing signatures.   It no longer exports a default.
- Removed `type` prop of options for `DriverCommand` and `PluginCommand` constructors, respectively (this value is derived from the `ExtensionConfig` `config` parameter instead)
- `AppiumDriver` now extends `DriverCore` instead of `BaseDriver`, since some of its function signatures differ from `BaseDriver`'s.
- Small refactor of `deleteSession` to make typechecker happy.
- `executeCommand` now calls to `BaseDriver` directly if `isUmbrellaCmd` is truthy.  This is one place where inheritance just kind of breaks, since `BaseDriver#executeCommand` returns something entirely different than `AppiumDriver#executeCommand` would otherwise.
- Removed `--delete-dir-on-start` from build command, since it may blast generated declarations.
- Reorganize declarations in `types/`; moved some of them out of `@typedef`s. `types.d.ts` becomes `index.d.ts`
- Note that this contains the declarations for `PluginClass` and `DriverClass`, which correspond to the types of extension "main" classes. This differs from the interfaces provided in `@appium/types` (e.g., `Driver`, `ExternalDriver`) in that these aren't just objects; they are classes with constructors and static members. I may end up moving some of this stuff into `@appium/types`, but I'm not sure how useful it will be.  Will see when I add types to `@appium/fake-driver`.

* chore(appium): remove transpile directives
this was ostensibly for gulp-babel

* chore(appium): remove redundant type declaration

* fix(appium): avoid potential unhandled rejections

- make types more readable

* chore(appium): fix capabilities types

- move `scripts/generate*` elsewhere
- add reference to `@appium/types` in `tsconfig.json`

* chore(appium): review updates for legibility
2022-03-25 14:54:45 -07:00
Christopher Hiller 164bedb2f1 feat(base-driver): generate declaration files
This was not as easy as the other two.  The main issue involves the `BaseDriver` class and is threefold:

1. `BaseDriver` and a valid external subclass thereof (a `Driver`) are not the same, because the former is essentially _abstract_. There is no notion of an abstract class in JS nor in TS for JS.
2. Splitting `BaseDriver` into several modules and "mixing in" some modules is just not well-understood by TS.
3. `AppiumDriver` inherits _most_ of `BaseDriver`, but overrides some functions with differing signatures. This is unsupported by TS.

To work around these problems, I had to:

1. Move the `Driver` interface into `@appium/types`, since other packages may depend on it.  We do not want circular dependencies, which is likely to occur otherwise.  Further, there is no way to tell TS for JS that a class _implements_ an interface or type.
2. Refactor the mixins (in `basedriver/commands/`) into "mixin classes", as understood by typescript. These are dynamic classes returned by functions which accept a class parameter, and _extend_ that class. The result is marginally better, but the implementation is ... well, see for yourself.  It is not possible to use declaration merging to just "trick" TS into thinking that `BaseDriver` has all of these extra methods; classes cannot be merged, and even if you could, you can't use declaration merging to "add" methods afaict.
3. `BaseDriver` is now an empty class which inherits from all mixins applied to `DriverCore`.  Due to syntactic restrictions, it must be a `class` statement in order to use the `@implements` tag, which causes TS to check that the result fully implements `Driver`.  `AppiumDriver` _also_ inherits from `DriverCore`, since it does not override `BaseDriver` "properly".  `BaseDriverCore` itself is pretty small, containing only those functions which `AppiumDriver` defines as differing.

Otherwise:

- `BaseDriver` does not inherit from `Protocol`, which is just an empty class. `Protocol` was removed.
- All of the error classes are exported from `protocol/errors`, because TS cannot see them otherwise.
- Exported missing `GET_STATUS_COMMAND` from `protocol/index`
- Re-exported `normalizeBasePath` from `server` instead of `protocol`, since that's where it's defined
- Removed `index.d.ts`
- Mixins use `@implements` as well. Note that `@implements` does not support `import('..')` syntax.

chore(base-driver): attempted to make types for mixins less awful

fixed a couple issues in the types in `driver.js`

core(base-driver): add capabilities types

- also move the bluebird config into the index
- fix references to `DriverOpts`
- add `assignServer()` to `BaseDriverCore`, used by `AppiumDriver`

chore(base-driver): fix more types

add missing reference to `@appium/types` in `tsconfig.json`

fix(base-driver): ensure getLogEvents is async

fix(base-driver): add some more type checks and fix logCustomEvent to be async

chore(base-driver): reformat
2022-03-25 14:54:45 -07:00
Christopher Hiller 326b7b4e06 feat(support): generate declaration files
Most of these changes are the addition of types.  There are a few places in which the typechecker found weirdness, and I have addressed those.

- In `logging.js`, `parseInt()` was being called on props of `process.env`; this is not allowed, because `parseInt()` only accepts a string, and props may be `undefined`.
- In `log-internal.js`, I had to remove the `raiseError()` function because TypeScript is unable to understand that a function, when called, will always throw.  The fix was just to replace with `throw new Error...`
- Introduced a var in `mjpeg.js` to avoid repeated casting
- Added some type guards to `net.js`. as function parameters, union types kind of suck. This is definitely one place TS would have helped, since it allows function overloads.  Also dropped use of deprecated `url` module in lieu of W3C `URL`.
- Removed some old-node-version cruft from `util.js`.

Non-code changes:

- Needed to use an override for `type-fest`, as it's included as a transitive dependency, but otherwise is only present in the devdeps of the monorepo root `package.json`. This means, due to version conflicts, a `support/node_modules/type-fest` would be created with an old, incompatible version, which would be preferred over the monorepo one due to Node's resolution algorithm.  This needs npm v8.3+ to work properly, but is only a problem for contributors (not consumers).
- Pinned type of `opencvv-bindings`.
- No longer deleting `build` dir before transpilation since it may contain generated declarations!
2022-03-25 14:54:45 -07:00
Christopher Hiller 72085caa0a feat(types): add new @appium/types package
This changes the TS configuration to to a) emit declarations for supported packages, and b) build declarations incrementally by package.

To begin, we are targeting `appium`, `@appium/base-driver` and `@appium/support` for declarations; these three are intended to be published with declarations generated via their JS.

Both `@appium/support` and `appium` are fully typechecked (sans implicit `any` types), but `@appium/base-driver` is mostly not.  Regardless, declarations are generated for all three.

Each package will have its own `tsconfig.json` which "inherits" from `config/tsconfig.base.json`.  Each will also need to declare relative paths to dependencies. e.g., the `appium` package must configure its `tsconfig.json` so that it depends on the declarations of `@appium/support` and also where to find `@appium/support`. Essentially, a small dependency tree gets built, and those at the "root" get their declarations built first; then the consumers use those declarations.

Also reorganized some scripts and added `npm-run-all` to help and added a "typecheck" job to CI.

Since `npm install` will build, it's pretty inconvenient to have `npm` abort installation if the build fails.  In that case, if any of the build steps fail (see `build:loose`) the installation will continue.  Added a `prepublishOnly` which runs a build in "strict" mode where everything must pass.

_Note: there's still a strong coupling of "what `BaseDriver` provides" and "what an external driver *may* provide".  It's unclear to me if this is a problem, though there seem to be a handful of methods that external drivers *must* implement.  The easiest way to get around this would probably be to extract these required properties and methods into their own interface (duplication) if we cannot otherwise declare methods as "abstract".  As it stands, the `Driver` is basically just `BaseDriver`._

Also:

- Moved some configuration types out of `appium` and into here, since they are used both by `appium` and `base-driver` via `DriverOpts`
- Split `Driver` type into "the thing that BaseDriver is" and "all the other methods external drivers can implement"
- Added missing `proxyCommand` method
- Better generics for `LogType`
- Remove unused `Constructor` type
- Better types for `getSession`/`getSessions`
- Added util `Class` type
- Added many missing typings from DefinitelyTyped
- Added `ts-node` for `@wdio/types` (I need to send a PR to webdriver to eliminate this dependency)
- Type checks in their CI step
2022-03-25 14:54:45 -07:00
Renovate Bot 4ff63e2425 chore(): update dependency serve-static to v1.15.0 2022-03-25 14:43:56 +00:00
Renovate Bot a4229f9382 chore(doctor): update dependency inquirer to v8.2.2 2022-03-25 12:09:52 +00:00
Renovate Bot 075eaeb8ce chore(): update dependency typescript to v4.6.3 2022-03-25 09:30:00 +00:00
Renovate Bot 523301199a chore(support): update dependency plist to v3.0.5 2022-03-24 11:48:16 +00:00
Renovate Bot 6cf9c63da2 chore(appium): update dependency lilconfig to v2.0.5 2022-03-24 10:02:20 +00:00
Jonathan Lipps 6d35def9ed Publish
- appium@2.0.0-beta.27
 - @appium/base-driver@8.3.1
 - @appium/doctor@1.16.11
 - @appium/fake-driver@3.2.6
 - @appium/support@2.56.1
 - @appium/test-support@1.3.13
@appium/base-driver@8.3.1 @appium/doctor@1.16.11 @appium/fake-driver@3.2.6 @appium/support@2.56.1 @appium/test-support@1.3.13 appium@2.0.0-beta.27
2022-03-23 11:50:58 -07:00
Christopher Hiller 77727dc913 fix(support): add missing resolve-from dependency
see https://github.com/appium/java-client/issues/1667
2022-03-23 11:44:51 -07:00
Mykola Mokhnach bbfc7ef51d fix(base-driver): Use WeakRef to reference the driver instance in the log prefix generator (#16636) 2022-03-23 18:48:33 +01:00
Renovate Bot 21d337f976 chore(appium): update dependency ajv to v8.11.0 2022-03-23 13:36:43 +00:00
Renovate Bot 1a73ac0b75 chore(): update dependency finalhandler to v1.2.0 2022-03-23 10:34:34 +00:00
Christopher Hiller 35d9dc7ebc chore(base-driver): ungulpify
This PR removes Gulp from `@appium/base-driver` and reorganizes the test files.

The build needs to be a little different since other modules depend on its `build/test/basedriver` module.  IMO this should probably get moved elsewhere, but this does not break compatibility.
2022-03-22 18:12:02 -07:00
Christopher Hiller 2877f90981 chore(fake-driver): gulp is dead, long live scripts
This PR removes Gulp from `@appium/fake-driver` as already done in a couple other packages.

Also: moved `screen.png` into `lib/` since `@babel/cli` can just copy it over into `build/`.
2022-03-22 18:11:37 -07:00
Jonathan Lipps f5cce0f29d Publish
- appium@2.0.0-beta.26
 - @appium/base-driver@8.3.0
 - @appium/doctor@1.16.10
 - @appium/eslint-config-appium@5.0.2
 - @appium/fake-driver@3.2.5
 - @appium/gulp-plugins@6.0.2
 - @appium/opencv@1.0.2
 - @appium/support@2.56.0
 - @appium/test-support@1.3.12
@appium/base-driver@8.3.0 @appium/doctor@1.16.10 @appium/eslint-config-appium@5.0.2 @appium/fake-driver@3.2.5 @appium/gulp-plugins@6.0.2 @appium/opencv@1.0.2 @appium/support@2.56.0 @appium/test-support@1.3.12 appium@2.0.0-beta.26
2022-03-22 13:41:57 -07:00
Renovate Bot 96fd7782eb chore(support): update dependency read-pkg to v5.2.0 2022-03-22 17:30:52 +00:00
Renovate Bot 56f5c87d91 chore(support): update dependency axios to v0.26.1 2022-03-22 16:27:35 +00:00
Renovate Bot 9fb03950d6 chore(gulp-plugins): update dependency mocha to v9.2.2 2022-03-22 14:08:48 +00:00
Renovate Bot 7f6d9f54fc chore(gulp-plugins): update dependency yargs to v17.4.0 2022-03-22 11:22:05 +00:00
Kazuaki Matsuo 3ee93ba5bd fix: revert 15809 (#16621)
* fix: revert 15809

* change comment
2022-03-21 10:10:35 -07:00
Renovate Bot c1054c7996 chore(gulp-plugins): update dependency globby to v11.1.0 2022-03-21 15:22:00 +00:00
Renovate Bot c5164f7743 chore(fake-driver): update dependency @xmldom/xmldom to v0.8.1 2022-03-21 12:37:19 +00:00
Renovate Bot 6ca1191bb2 chore(doctor): update dependency appium-adb to v8.18.0 2022-03-20 16:46:34 +00:00
Renovate Bot f947828e9b chore(base-driver): update dependency lru-cache to v7.7.1 2022-03-20 14:51:43 +00:00
Renovate Bot 0ebdd0ed78 chore(base-driver): update dependency http-status-codes to v2.2.0 2022-03-20 13:08:38 +00:00
Renovate Bot 840e5a767c chore(appium): update dependency winston to v3.6.0 2022-03-20 11:05:08 +00:00
Renovate Bot a2fc58cd93 chore(appium): update dependency ajv to v8.10.0 2022-03-19 18:06:19 +00:00
Renovate Bot c8ee934718 chore(): update dependency type-fest to v2.12.1 2022-03-19 15:24:03 +00:00
Renovate Bot 0b4dad2f4c chore(): update dependency eslint-find-rules to v4.1.0 2022-03-19 14:06:16 +00:00
Renovate Bot 799fb87be3 chore(gulp-plugins): update babel monorepo to v7.17.8 2022-03-19 11:13:48 +00:00
Renovate Bot 970017b208 chore(gulp-plugins): update dependency yargs to v17.3.1 2022-03-18 18:15:57 +00:00
Renovate Bot 43d36bb60c chore(): update dependency lint-staged to v12.3.7 2022-03-18 15:17:24 +00:00
Renovate Bot 06a8fe467c chore(gulp-plugins): update dependency node-notifier to v10.0.1 2022-03-17 16:38:06 +00:00
Renovate Bot ad0814532b chore(): update dependency @types/json-schema to v7.0.10 2022-03-17 12:35:15 +00:00
Renovate Bot 3add8c0906 chore(gulp-plugins): update dependency eslint-plugin-import to v2.25.4 2022-03-16 18:14:37 +00:00
Renovate Bot 3648ed017b chore(gulp-plugins): update dependency @types/node to v16.11.26 2022-03-16 16:43:48 +00:00
Renovate Bot 37c25e4546 chore(doctor): update dependency inquirer to v8.2.1 2022-03-16 16:13:41 +00:00
Renovate Bot 11fb7c1a2e chore(): update dependency lint-staged to v12.3.6 2022-03-16 13:29:50 +00:00
Renovate Bot 297a307725 chore(gulp-plugins): update babel monorepo to v7.17.7 2022-03-16 10:55:01 +00:00
Renovate Bot 1cc5a9e2cc chore(base-driver): update dependency ws to v7.5.7 2022-03-15 16:56:39 +00:00
Renovate Bot 7b6159cf2f chore(base-driver): update dependency express to v4.17.3 2022-03-15 14:12:16 +00:00
Renovate Bot 28a14da729 chore(base-driver): update dependency body-parser to v1.19.2 2022-03-15 11:44:51 +00:00
Renovate Bot 54b1f5276a chore(base-driver): update dependency async-lock to v1.3.1 2022-03-14 20:26:14 +00:00
Renovate Bot 8c3cca06e5 chore(appium): update dependency @appium/base-plugin to v1.8.1 2022-03-14 17:22:42 +00:00
Renovate Bot 84eb71fb0f chore(): update dependency serve-static to v1.14.2 2022-03-14 14:26:50 +00:00
Renovate Bot d1e0043e37 chore(): update dependency lint-staged to v12.3.5 2022-03-14 11:13:28 +00:00
Renovate Bot b57115b2f0 chore(): update dependency chai to v4.3.6 2022-03-13 16:37:42 +00:00
Renovate Bot 3a6b3c7788 chore(): update dependency appium-base-driver to v7.11.3 2022-03-13 14:34:57 +00:00