nxext / nx-extensions

Nx Extensions for Stencil, Svelte, SolidJS, Preact, Ionic, and Capacitor
MIT License
466 stars 102 forks source link

Capacitor: run executors runs the incorrect cap #915

Open distante opened 1 year ago

distante commented 1 year ago

Describe the bug Running @nxext/capacitor:cap:run will try to install package=@capacitor/cli instead of using the one found on node_modules

To Reproduce call @nxext/capacitor:cap run

Expected behavior Run should call the existing @capacitor/cli from node_modules

Additional context The problem was introduced by https://github.com/nxext/nx-extensions/pull/817

borgoat commented 1 year ago

It took me longer than I care to admit to debug this while attempting to update to Capacitor 5...

In the end, I reverted back to plain nx:run-commands in my executors:

    "update": {
      "executor": "nx:run-commands",
      "options": {
        "cwd": "apps/mobile",
        "command": "cap update"
      },
      "configurations": {
        "ios": {
          "ios": {
            "command": "cap update ios"
          },
          "android": {
            "command": "cap update android"
          }
        }
      }
    },

I believe this plugin should do the same in fact, and not even invoke npx. It should let Nx do its thing, and avoid forcing another version of users. We can expect quite some troubles when version 5 will be in general availability, and npx will default to that.

muuvmuuv commented 1 year ago

@borgoat how do you invoke the configuration? You nested ios.android because..?

muuvmuuv commented 1 year ago

Ok so we migrated to this and I think this is enough:

"capacitor": {
      "executor": "nx:run-commands",
      "options": {
        "cwd": "apps/project",
        "commands": [
          {
            "command": "capacitor",
            "forwardAllArgs": true
          }
        ]
      }
    }
pnpm nx run project:capacitor copy ios
borgoat commented 1 year ago

@borgoat how do you invoke the configuration? You nested ios.android because..?

Sorry, you can ignore that part... a copy-paste mistake I guess. I think we wrongly copied it from other tasks such as "open" and "run" to do platform specific things, but for sync we always invoke just 1 command for both platforms: nx sync mobile.

muuvmuuv commented 1 year ago

btw. if you dont want to run this long NX command, you can install npm-run-all and shorten it to just pnpm cap copy ios with:

"cap": "npm-run-all \"nx run project:capacitor {@}\" --",