run-ios command ignores the verbose option
Environment
info Fetching system and libraries information...
System:
OS: macOS 10.15.7
CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Memory: 1.47 GB / 16.00 GB
Shell: 5.8 - /usr/local/bin/zsh
Binaries:
Node: 10.24.0 - /var/folders/h6/g6rldscd6h389g9w42_7k_jm0swv2d/T/yarn--1617537855315-0.38815081056993295/node
Yarn: 1.22.10 - /var/folders/h6/g6rldscd6h389g9w42_7k_jm0swv2d/T/yarn--1617537855315-0.38815081056993295/yarn
npm: 6.14.11 - ~/.nvm/versions/node/v10.24.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.0 - /Users/liam.jones/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
Android SDK:
API Levels: 23, 25, 26, 27, 28, 29
Build Tools: 27.0.3, 28.0.3, 29.0.2, 29.0.3, 30.0.3, 31.0.0
System Images: android-21 | Google APIs Intel x86 Atom, android-25 | Google APIs Intel x86 Atom, android-25 | Google Play Intel x86 Atom, android-26 | Google Play Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-30 | Google Play Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 4.1.3 4.1.3
Xcode: 12.4/12D4e - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_282 - /usr/bin/javac
Python: 3.9.2 - /usr/local/opt/python/libexec/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.4 => 0.63.4
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Description
run-ios detects the presence of xcpretty and uses it if installed. The command-line help for the run-ios command states:
--verbose Do not use xcpretty even if installed
However, when run with the verbose option, xcpretty is still used.
I've dug into this a little, it looks like the verbose option is checked for in buildProject(), here: https://github.com/react-native-community/cli/blob/v4.14.0/packages/platform-ios/src/commands/runIOS/index.ts#L307
However, if I debug the command as it's running, verbose is undefined.
The issue seems to be coming from Command.prototype.opts() inside commander. Here it copies the values from properties on this (the Command) into result[key]: https://github.com/tj/commander.js/blob/v2.20.3/index.js#L779. This works for other options like packager (set via --no-packager). I can see packager, etc exist on this for the working properties but for some reason this.verbose doesn't.
I've not been able to work out why this happens yet (nor if it's a problem in the cli or commander).
I've also created a fresh RN 0.64.0 project to check the behaviour is the same (and it is).
Reproducible Demo
- Install xcpretty
- Create RN project
- Run
run-iosand note xcpretty formatted output - Run
run-ios --verboseand note xcpretty formatted output is still present
Okay, I now understand what's going on. Essentially, with commander ^2.19.0 you cannot have the same option name on a subcommand as the parent. In this instance, both react-native and react-native run-ios have the option --verbose. react-native will essentially consume the verbose option so it's not visible to run-ios. This behaviour is changeable in v7 via the options added in this PR https://github.com/tj/commander.js/pull/1427.
Potential options I can see;
- Upgrade commander - I'm assuming going from v2 to v7 is going to be a lot of work.
- Change the run-ios --verbose option to a different name so it no longer collides with react-native's --verbose option (also check there are no other option collisions on other commands)
I'm going to have a look at doing the second option as a starting point.
I see the project already has a workaround for this in the init command: https://github.com/react-native-community/cli/blob/master/packages/cli/src/commands/init/init.ts#L208.
Would another workaround in run-ios be preferable to option 2 above?
I would imagine we can pass commander.verbose https://github.com/react-native-community/cli/blob/641b21f583c97e3d48ce87d5fe804f42db92fa5c/packages/cli/src/index.ts#L28-L30 to here https://github.com/react-native-community/cli/blob/641b21f583c97e3d48ce87d5fe804f42db92fa5c/packages/cli/src/index.ts#L138
{...passedOptions, verbose: commander.verbose()}
We have tried upgrading to a newer version, but that was quite a challenge. I would say for now, the easiest workaround is to pass it this way, or provide a utility function isVerboseMode() that would check process.argv itself, like the init workaround you have linked.
Either way, I'd be happy to accept this as a PR!
Hi, I faced a similar issue on React Native version 0.68.0-rc.2.
Oh, I forgot to come back to this one. I'll see about doing a PR
There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.
Still waiting on PR #1571 to be approved and merged to fix this.
There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.
PR conversation stalled, I'll resurrect it.
There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.