capacitor-updater icon indicating copy to clipboard operation
capacitor-updater copied to clipboard

bug: Capgo not working properly in nx monorepo

Open phal0r opened this issue 1 year ago • 3 comments

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.

phal0r avatar Oct 04 '24 14:10 phal0r

Thanks for the report we will look into that

riderx avatar Oct 12 '24 02:10 riderx

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.

WcaleNieWolny avatar Oct 13 '24 04:10 WcaleNieWolny

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

phal0r avatar Oct 17 '24 15:10 phal0r

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.

phal0r avatar Nov 12 '24 17:11 phal0r

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

riderx avatar Nov 15 '24 10:11 riderx

You can now use --package-json [path,] with as many file you want, and same with --node-modules [path,] this should allow any workspace, monorepo and any other setup.

riderx avatar Jan 07 '25 17:01 riderx