Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: appium driver list --installed is unable to find drivers in monorepo #19819

Open
3 tasks done
tido64 opened this issue Feb 22, 2024 · 4 comments
Open
3 tasks done
Labels

Comments

@tido64
Copy link

tido64 commented Feb 22, 2024

Do I have the most recent component updates?

  • I use the most recent available driver/plugin and server versions

Is the component officially supported by the Appium team?

  • I have verified the component repository is present under the Appium organization in GitHub

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

appium driver list --installed lists no drivers in a monorepo when drivers are hoisted to the root workspace. Example:

monorepo
├── node_modules
│   ├── appium
│   ├── appium-uiautomator2-driver  <-- drivers were installed here
│   └── appium-xcuitest-driver      <-- drivers were installed here
├── package.json
└── packages
    └── my-app
        ├── node_modules  <-- no drivers here; they were hoisted to root
        ├── package.json  <-- drivers were requested here
        └── src

Expected Behavior

appium driver list --installed should list installed drivers

Minimal Reproducible Example

If you have drivers installed globally, move them elsewhere before running the following commands:

git clone https://github.com/microsoft/react-native-test-app.git
cd react-native-test-app
git reset --hard 329f07c5e580c792b549b9a19c90f7e79f4f062c
yarn
cd example
yarn appium driver list --installed

Environment

  • Operating system: macOS 14.3.1
  • Appium server version (output of appium --version): 2.5.1
  • Appium driver(s) and their version(s):
    • appium-uiautomator2-driver 3.0.0
    • appium-xcuitest-driver 7.1.0
  • Appium plugin(s) and their version(s): n/a
  • Node.js version (output of node --version): v18.19.1
  • npm version (output of npm --version): 10.2.4
  • Last component(s) version which did not exhibit the problem: n/a
  • Platform and version under test: ?
  • Real device or emulator/simulator: emulator/simulator

Link to Appium Logs

n/a

Further Information

We've worked around this issue with the following patch:

diff --git a/build/lib/extension/manifest.js b/build/lib/extension/manifest.js
index 5b650a6ff4dbe737ffdf8821e255e9e4e3d89da3..6179965231285c3ae1d3cddee0c45c57ab3fba03 100644
--- a/build/lib/extension/manifest.js
+++ b/build/lib/extension/manifest.js
@@ -195,12 +195,14 @@ class Manifest {
             onMatch(path_1.default.join(__classPrivateFieldGet(this, _Manifest_appiumHome, "f"), 'package.json'), true),
         ];
         // add dependencies to the queue
-        const filepaths = await support_1.fs.glob('node_modules/{*,@*/*}/package.json', {
-            cwd: __classPrivateFieldGet(this, _Manifest_appiumHome, "f"),
-            absolute: true,
-        });
-        for (const filepath of filepaths) {
-            queue.push(onMatch(filepath));
+        const appPkgPath = path_1.default.join(process.cwd(), 'package.json');
+        const appPkg = JSON.parse(await support_1.fs.readFile(appPkgPath, 'utf8'));
+        for (const name of Object.keys(appPkg.devDependencies)) {
+          try {
+            queue.push(onMatch(require.resolve(name + "/package.json")));
+          } catch (_) {
+            // Ignore packages that don't export `./package.json`
+          }
         }
         // wait for everything to finish
         await bluebird_1.default.all(queue);
@tido64 tido64 added Bug a problem that needs fixing Needs Triage bugs which are not yet confirmed labels Feb 22, 2024
@jlipps
Copy link
Member

jlipps commented Feb 23, 2024

I wonder if we should add something like a --ext-search-root flag where you could simply tell Appium the directory to start its hunt for extension packages. That way you could simply run appium --ext-search-root=$MONOREPO_ROOT

@tido64
Copy link
Author

tido64 commented Feb 24, 2024

With hoisting in general, I don't think you can reliably set a single path for globbing. Since it's based on popularity, you never really know when the next set of package updates might move things around. You will have to check both the current workspace as well as the root workspace. I'm also not sure globbing is the best solution here since you might find extensions that the current workspace don't have an explicit dependency on.

@jlipps
Copy link
Member

jlipps commented Feb 26, 2024

Yes, fair point. I think what I meant was to use an approach like you do here, but instead of relying on process.cwd(), allowing the user to specify a path.

@mykola-mokhnach mykola-mokhnach added Enhancement feature and removed Bug a problem that needs fixing Needs Triage bugs which are not yet confirmed labels Feb 27, 2024
@szarlatan
Copy link

@tido64, I had pretty much the same problem and solution for that was quite simple with just a slight overhead.

Please try to add drivers' packages also as a devDependencies in your root monorepro package.json file. That solved the problem for me but each time I bump drivers versions I have to update 2 package.json files instead of one. Still that's a low cost IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants