feat: add invoking CLI's scripts for launching Metro in run-ios command#2021
Conversation
| } "${chalk.bold(xcodeProject.name)}"`, | ||
| ); | ||
|
|
||
| await runPackager( |
There was a problem hiding this comment.
We should be able to disable this with --no-packager.
Unrelated: I was actually hoping we could remove the packager from the run-android command instead :P
There was a problem hiding this comment.
We should be able to disable this with --no-packager.
We're already able to this :) See here:
cli/packages/cli-platform-ios/src/commands/runIOS/index.ts
Lines 609 to 612 in ba362e6
And in function body I check for this:
cli/packages/cli-plugin-metro/src/commands/start/runPackager.ts
Lines 11 to 13 in b374145
There was a problem hiding this comment.
Question is, maybe we should consider disabling running packager by default? I think this would require a poll on how people use it in the wild. I myself run the server myself in a terminal tab that suits me. But I've also seen devs relying on automatic opening of dev server and not sure if they would even realize it's missing
There was a problem hiding this comment.
Other options that comes to my mind is to run the packager in the same window where we start run-ios/android command.
There was a problem hiding this comment.
I think this would require a poll on how people use it in the wild
FYI I'm up for this, and/or making the most informed decision. Originally I was with @tido64 in thinking we'd drop the behaviour on Android to align. But @szymonrybczak's changes, with an opt-out flag, look pretty useful to me.
While this item of feedback is still unresolved, I'd like to push for this PR to be merged and released anyway, since it is a direct dependency for facebook/react-native#38944 and incoming Debugging functionality in React Native. These are all alpha releases, and we can follow up on enhancing this behaviour in a follow-up PR.|
cc @thymikee
run/build-ios commandsrun-ios commands
run-ios commandsrun-ios command
packages/cli-platform-ios/src/commands/buildIOS/buildProject.ts
Outdated
Show resolved
Hide resolved
e9df890 to
75e3ee1
Compare
|
✅ Endorsed! |
packages/cli-plugin-metro/src/commands/start/startServerInNewWindow.ts
Outdated
Show resolved
Hide resolved
| name: '--terminal <string>', | ||
| description: | ||
| 'Launches packager in a new window using the specified terminal path.', |
There was a problem hiding this comment.
Main feedback ⬇️
Interesting, can we merge this all into the start command — aligning with your proposal in react-native-community/discussions-and-proposals#613? Specifically:
- The improved error message behaviour when
start(RN CLIstart) is called and something is already on the configured Metro port. react-native start --terminalswitches modes to integrate thestartServerInNewWindow.jsbehaviour.
Then, we only expose startCommand and it can be used by doctor, run-android, run-ios.
cc @thymikee Does this seem feasible?
|
👋, update from my side. I implemented whole feedback, and I added features discussed under this RFC. I changed implementation of handling keystrokes. Before it wasn't possible to pause interactivity (to show the prompt), but right now it was possible. Without this change, after showing prompt in watch mode the user wouldn't be able to handle any keystroke. Rigth now flow looks like now:
Note When starting Android or iOS app from watchMode it runs also Added interactive part 👀
CleanShot.2023-08-01.at.13.39.09.mp4
CleanShot.2023-08-01.at.13.41.13.mp4Also added log to inform user about on which port Metro bundler is running: Important This change is backward compatible, previously |
There was a problem hiding this comment.
This is awesome work 💯
High-level feedback
- 1/ We can probably achieve a better organisation of responsibilities here.
- Maybe
--terminalon thestartcommand is the wrong place to do full-on process management (my bad). It would be really good to keepcli-plugin-metro's responsibilities as clean as possible. - Therefore:
cli-plugin-metro: Let's reduce thestartcommand to starting the server only, and erroring generically to say "Could not start dev server: The specified port was taken".cli-plugin-android/iosLet's do process detection here, and move the background terminal creation logic here (likely shared viacli-tools) also. Therefore it's these commands which will wrapstart, which doesn't need to know where it's running.
- Maybe
- 2/ Being able to kill another process is probably not surface area we want to add to CLI (being mindful of when we introduce user expectations). For the
run-android/run-ioscommands, bailing from starting Metro when the port is taken (with an informational log message) is most likely adequate. - 3/ I'd suggest separating the improved
KeyPressHandlerlogic into a new PR — potentially this should live incli-tools.
packages/cli-plugin-metro/src/commands/start/startServerInNewWindow.ts
Outdated
Show resolved
Hide resolved
Hm, I'm thinking about this solution, and it is slightly better that doing this whole logic behind
Okay, let's leave just prompt with proposition port change.
#2041 - I will rebase on top of this PR once will be merged 👍 |
Sure, let's move as much logic as necessary into
I think yes for now — or perhaps in the root |
|
@huntie So I moved some logic into |
5c3b84b to
691c96a
Compare
huntie
left a comment
There was a problem hiding this comment.
Looks good to me. Might be some tidying we can do in future, but I'm keen to unblock the move of cli-plugin-metro. Huge thanks for this! 🙌🏻
| import chalk from 'chalk'; | ||
| import {Config} from '@react-native-community/cli-types'; | ||
| import {KeyPressHandler} from '../../tools/KeyPressHandler'; | ||
| import {addInteractionListener} from '@react-native-community/cli-tools'; |
There was a problem hiding this comment.
nit: Merge with existing '@react-native-community/cli-tools' import.
There was a problem hiding this comment.
yeah, I will do it after #2041 will be merged 👍
| reactNativePath: string, | ||
| terminal?: string, | ||
| ) { | ||
| if (!terminal) { |
There was a problem hiding this comment.
This check is preventing android build on windows. On windows - so far we did not need any terminal value. It always used to fall back to default cmd.exe ( line no 106 )
In this case I think the proper fix should be fixing the getDefaultUserTerminal which currently doesn't have any default terminal for windows.
There was a problem hiding this comment.
Or only apply this check on platforms other than windows.
| } | ||
|
|
||
| if (packager) { | ||
| await startServerInNewWindow( |
There was a problem hiding this comment.
await causes the CLI to hang indefinitely. Must be called without await.
Check existing comment at https://github.com/szymonrybczak/cli/blob/732308dfe47cf05d7f5c869fcef08a8fe96ecc7c/packages/cli-tools/src/startServerInNewWindow.ts#L105

Summary:
Recently @huntie removed "Start packager" phase from template, which means that right now when running
run-ioscommand, packager won't be started. I synced implementations between platforms (run-androidcommand was using CLI's script for some time).This change also fixes problem with starting Metro in monorepos setups (see #1799).
Test Plan:
run-ios- Should start Metro from script located innode_modules/.bin/launchPackager.command✅TODO:
Checklist