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: Capgo not working properly in nx monorepo #463

Open
phal0r opened this issue Oct 4, 2024 · 5 comments
Open

bug: Capgo not working properly in nx monorepo #463

phal0r opened this issue Oct 4, 2024 · 5 comments

Comments

@phal0r
Copy link

phal0r commented Oct 4, 2024

Bug Report

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 6.1.2
  @capacitor/core: 6.1.2
  @capacitor/android: 6.1.2
  @capacitor/ios: 6.1.2

Installed Dependencies:

  @capacitor/ios: 6.1.1
  @capacitor/cli: 6.1.1
  @capacitor/core: 6.1.1
  @capacitor/android: 6.1.1

[success] iOS looking great! 👌
[success] Android looking great! 👌

Plugin Version

▲   💊   Capgo Doctor  💊
│
●   App Name: 
│
●   App ID: 
│
●   App Version: 0.0.0
│
●   Web Dir: 
│
●   OS: darwin Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:00 PDT 2024; root:xnu-10063.141.2~1/RELEASE_X86_64
│
●   Node: v20.13.1
│
●   Installed Dependencies:
│
●     @capgo/cli: 4.20.7
│
◇  Latest Dependencies:
│
●     @capgo/cli: 4.20.7
│
◆  ✅ All dependencies are up to date

Current Behavior

Consider a nx monorepo with one package.json (and node_modules) in the root folder and the actual app residing in apps/my-app. The app itself does not have a package.json, because dependencies are shared in the monorepo.

Capacitor itself supports nx and has functions to find the correct package.json in the root path. However, if I run npx @capgo/cli bundle upload it complains, that no package.json exist.

If I create a dummy package.json, the command runs, but then cap commands fail, because the capacitor plugins are in the root node_modules folder and thus no plugins are added on the native side.

Since it works with a dummy package.json, there seems nothing important to be read from package.json, so why is it necessary at all?

Expected Behavior

It should be aligned with capacitor in monorepos and run successfully in nx environments.

@riderx
Copy link
Collaborator

riderx commented Oct 12, 2024

Thanks for the report we will look into that

@WcaleNieWolny
Copy link
Contributor

Hello, I have attempted to reproduce the behavior, however I don't think I fully understand your setup.

First, how are you able to have an app without a package.json?
Second, what package manager do you use?
Last, in which directory do you run npx @capgo/cli bundle upload

I really do not understand the setup that you use. I attempted to reproduce:
image

However, without a package.json in apps/myApp neither NPM or PNPM was able to detect my app.

I do believe that there might a bug in the CLI related to reading package.json but without a minimal reproducible example in a repo I cannot fix it.

@phal0r
Copy link
Author

phal0r commented Oct 17, 2024

Ok, I will clarify my setup. I just need a little bit of time.

@phal0r
Copy link
Author

phal0r commented Nov 12, 2024

Sorry for the late answer. Here are more details:

I created a shell script using nx:run-commands runner. The working directory is apps/myApp (to stick with your example).

First, how are you able to have an app without a package.json?

I only have the root package.json as nx in monorepo mode does not create a package.json in apps/myApp, only the global one in root.

Second, what package manager do you use?

I am using npm

I was digging in the sourcecode and located the problematic line: https://github.com/Cap-go/CLI/blob/main/src/bundle/upload.ts#L63

It will always read a package.json, even if the bundle number is taken from somewhere else. I found a workaround by adding --package-json '../../package.json' to provide the alternative path.

I still think it's a bug, because in https://github.com/Cap-go/CLI/blob/main/src/utils.ts#L116 the default for finding the root is to check for monorepos, but the call in upload.ts adds an empty string and therefor the default is not being used.

@riderx
Copy link
Collaborator

riderx commented Nov 15, 2024

hey @phal0r thanks for the feedback we updated the way we get the appId everywhere to get with consistency.
We also added --node-module option to provide where your deps are for meta check feature.
All should work for you with both options.
try with latest CLI

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

No branches or pull requests

3 participants