-
Notifications
You must be signed in to change notification settings - Fork 936
feat: add invoking CLI's scripts for launching Metro in run-ios command
#2021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thymikee
merged 16 commits into
react-native-community:main
from
szymonrybczak:feat/sync-starting-bundler-implementations
Aug 11, 2023
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a0e33d1
feat: sync starting bundler implementations
szymonrybczak d8421f9
fix: remove starting packager from build-* commands
szymonrybczak e7f8e49
feat: add better request response handling
szymonrybczak 1c28857
fix: add missing options
szymonrybczak 797192e
chore: remove usage of `cli-plugin-metro` package by exposing command
szymonrybczak 91750c5
fix: remove useless dependencies
szymonrybczak 1549486
feat: merge starting bundler hooks to `start` command & add interacti…
szymonrybczak d8f091a
fix: adjust descriptions
szymonrybczak a4e0c81
chore: code review improvements
szymonrybczak 43604ae
fix: move logic to `run-ios/android` commands
szymonrybczak 8e5d088
fix: move scripts to correct directory
szymonrybczak cba278d
chore: simplify naming
szymonrybczak 9810c4c
chore: code cleaning
szymonrybczak 3b3a7b9
chore: lockfile
szymonrybczak 5277063
fix: remove unnecessary dependency
szymonrybczak 732308d
chore: unify `handlePortUnavailable`
szymonrybczak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,13 +13,22 @@ import tryRunAdbReverse from './tryRunAdbReverse'; | |
| import tryLaunchAppOnDevice from './tryLaunchAppOnDevice'; | ||
| import tryInstallAppOnDevice from './tryInstallAppOnDevice'; | ||
| import getAdbPath from './getAdbPath'; | ||
| import {logger, CLIError, link} from '@react-native-community/cli-tools'; | ||
| import { | ||
| logger, | ||
| CLIError, | ||
| link, | ||
| getDefaultUserTerminal, | ||
| isPackagerRunning, | ||
| logAlreadyRunningBundler, | ||
| startServerInNewWindow, | ||
| handlePortUnavailable, | ||
| } from '@react-native-community/cli-tools'; | ||
| import {getAndroidProject} from '../../config/getAndroidProject'; | ||
| import listAndroidDevices from './listAndroidDevices'; | ||
| import tryLaunchEmulator from './tryLaunchEmulator'; | ||
| import chalk from 'chalk'; | ||
| import path from 'path'; | ||
| import {build, runPackager, BuildFlags, options} from '../buildAndroid'; | ||
| import {build, BuildFlags, options} from '../buildAndroid'; | ||
| import {promptForTaskSelection} from './listAndroidTasks'; | ||
| import {getTaskNames} from './getTaskNames'; | ||
| import {checkUsers, promptForUser} from './listAndroidUsers'; | ||
|
|
@@ -28,6 +37,9 @@ export interface Flags extends BuildFlags { | |
| appId: string; | ||
| appIdSuffix: string; | ||
| mainActivity: string; | ||
| port: number; | ||
| terminal?: string; | ||
| packager?: boolean; | ||
| deviceId?: string; | ||
| listDevices?: boolean; | ||
| binaryPath?: string; | ||
|
|
@@ -42,6 +54,35 @@ export type AndroidProject = NonNullable<Config['project']['android']>; | |
| async function runAndroid(_argv: Array<string>, config: Config, args: Flags) { | ||
| link.setPlatform('android'); | ||
|
|
||
| let {packager, port} = args; | ||
|
|
||
| const packagerStatus = await isPackagerRunning(port); | ||
|
|
||
| if ( | ||
| typeof packagerStatus === 'object' && | ||
| packagerStatus.status === 'running' | ||
| ) { | ||
| if (packagerStatus.root === config.root) { | ||
| packager = false; | ||
| logAlreadyRunningBundler(port); | ||
| } else { | ||
| const result = await handlePortUnavailable(port, config.root, packager); | ||
| [port, packager] = [result.port, result.packager]; | ||
| } | ||
| } else if (packagerStatus === 'unrecognized') { | ||
| const result = await handlePortUnavailable(port, config.root, packager); | ||
| [port, packager] = [result.port, result.packager]; | ||
| } | ||
|
|
||
| if (packager) { | ||
| await startServerInNewWindow( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. await causes the CLI to hang indefinitely. Must be called without await. |
||
| port, | ||
| config.root, | ||
| config.reactNativePath, | ||
| args.terminal, | ||
| ); | ||
| } | ||
|
|
||
| if (config.reactNativeVersion !== 'unknown') { | ||
| link.setVersion(config.reactNativeVersion); | ||
| } | ||
|
|
@@ -66,7 +107,6 @@ async function runAndroid(_argv: Array<string>, config: Config, args: Flags) { | |
|
|
||
| const androidProject = getAndroidProject(config); | ||
|
|
||
| await runPackager(args, config); | ||
| return buildAndRun(args, androidProject); | ||
| } | ||
|
|
||
|
|
@@ -269,6 +309,21 @@ export default { | |
| func: runAndroid, | ||
| options: [ | ||
| ...options, | ||
| { | ||
| name: '--no-packager', | ||
| description: 'Do not launch packager while running the app', | ||
| }, | ||
| { | ||
| name: '--port <number>', | ||
| default: process.env.RCT_METRO_PORT || 8081, | ||
| parse: Number, | ||
| }, | ||
| { | ||
| name: '--terminal <string>', | ||
| description: | ||
| 'Launches the Metro Bundler in a new window using the specified terminal path.', | ||
| default: getDefaultUserTerminal(), | ||
| }, | ||
| { | ||
| name: '--appId <string>', | ||
| description: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.