Description
Bug Report
Capacitor Version
Capacitor Doctor
Latest Dependencies:
@capacitor/cli: 5.4.2
@capacitor/core: 5.4.2
@capacitor/android: 5.4.2
@capacitor/ios: 5.4.2
Installed Dependencies:
@capacitor/android: not installed
@capacitor/ios: not installed
@capacitor/core: 5.4.2
@capacitor/cli: 5.4.2
Platform(s)
- @capacitor-community/electron": "^5.0.1"
- maybe other non default platforms
Current Behavior
capacitor commands for non default platforms are not executed
Expected Behavior
commands should be executed
Code Reproduction
Example Code Base: https://github.com/richardliebmann/capacitor-electron-platform-command-problem
- create-nx-workspace (angular, integrated-monorepo)
- nx build cap-sync-error
- cd apps/cap-sync-error
- npx cap init
- change webDir to '../../dist/apps/cap-sync-error'
- npm install @capacitor-community/electron --save
- cap add @capacitor-community/electron
The command does nothing
Code cause:
For non default platforms (isValidPlatform) capacitor searches for the platformDir and find it unter node_modules (e.g. "D:\Repos\andi-ui\node_modules@capacitor-community\electron"). Code:
capacitor/cli/src/tasks/add.ts
Lines 45 to 70 in e50e56c
The runPlatformHook checks if we are in a nx monorepo and overrides the package.json path to the project root folder (D:\Repos\andi-u) instead of the platform root folder (D:\Repos\andi-ui\node_modules@capacitor-community\electron).
Lines 165 to 200 in e50e56c
The required hook (capacitor:add) defined in the script section of the package.json of the platform therefor is not found in the project root package.json.
The code change was done with feat.Better support monorepos #6811
Other Technical Details
npm --version
output: 8.17.0
node --version
output: v18.16.1
pod --version
output (iOS issues only):