Skip to content

Commit e9df890

Browse files
committed
fix: remove starting packager from build-* commands
1 parent b374145 commit e9df890

File tree

7 files changed

+16
-76
lines changed

7 files changed

+16
-76
lines changed

packages/cli-platform-android/src/commands/buildAndroid/index.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ import adb from '../runAndroid/adb';
1111
import getAdbPath from '../runAndroid/getAdbPath';
1212
import {getTaskNames} from '../runAndroid/getTaskNames';
1313
import {promptForTaskSelection} from '../runAndroid/listAndroidTasks';
14-
import {runPackager} from '@react-native-community/cli-plugin-metro';
1514

1615
export interface BuildFlags {
1716
mode?: string;
1817
variant?: string;
1918
activeArchOnly?: boolean;
20-
packager?: boolean;
2119
port: number;
2220
terminal?: string;
2321
tasks?: Array<string>;
@@ -89,14 +87,6 @@ async function buildAndroid(
8987
}
9088
}
9189

92-
await runPackager(
93-
args.port,
94-
config.root,
95-
config.reactNativePath,
96-
args.terminal,
97-
args.packager,
98-
);
99-
10090
return build(gradleArgs, androidProject.sourceDir);
10191
}
10292

@@ -126,10 +116,6 @@ export const options = [
126116
description:
127117
"Specify your app's build variant. Deprecated! Use 'mode' instead",
128118
},
129-
{
130-
name: '--no-packager',
131-
description: 'Do not launch packager while building',
132-
},
133119
{
134120
name: '--port <number>',
135121
default: process.env.RCT_METRO_PORT || 8081,

packages/cli-platform-android/src/commands/runAndroid/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {promptForTaskSelection} from './listAndroidTasks';
2424
import {getTaskNames} from './getTaskNames';
2525
import {checkUsers, promptForUser} from './listAndroidUsers';
2626
import {runPackager} from '@react-native-community/cli-plugin-metro';
27+
2728
export interface Flags extends BuildFlags {
2829
appId: string;
2930
appIdSuffix: string;
@@ -32,6 +33,7 @@ export interface Flags extends BuildFlags {
3233
listDevices?: boolean;
3334
binaryPath?: string;
3435
user?: number | string;
36+
packager: boolean;
3537
}
3638

3739
export type AndroidProject = NonNullable<Config['project']['android']>;
@@ -314,6 +316,10 @@ export default {
314316
description: 'Id of the User Profile you want to install the app on.',
315317
parse: Number,
316318
},
319+
{
320+
name: '--no-packager',
321+
description: 'Do not launch packager while building',
322+
},
317323
],
318324
};
319325

packages/cli-platform-ios/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,6 @@ Explicitly set device to use by name. The value is not required if you have a si
171171

172172
Explicitly set device to use by udid.
173173

174-
#### `--no-packager`
175-
176-
Do not launch packager while building.
177-
178174
#### `--verbose`
179175

180176
Do not use `xcbeautify` or `xcpretty` even if installed.

packages/cli-platform-ios/src/commands/buildIOS/buildProject.ts

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import child_process, {
2-
ChildProcess,
3-
SpawnOptionsWithoutStdio,
4-
} from 'child_process';
1+
import child_process, {ChildProcess} from 'child_process';
52
import chalk from 'chalk';
63
import {IOSProjectInfo} from '@react-native-community/cli-types';
74
import {
@@ -14,7 +11,6 @@ import {
1411
export type BuildFlags = {
1512
mode: string;
1613
target: string;
17-
packager: boolean;
1814
verbose: boolean;
1915
xcconfig?: string;
2016
buildFolder?: string;
@@ -72,11 +68,7 @@ export function buildProject(
7268
});
7369
}
7470
}
75-
const buildProcess = child_process.spawn(
76-
'xcodebuild',
77-
xcodebuildArgs,
78-
getProcessOptions(args),
79-
);
71+
const buildProcess = child_process.spawn('xcodebuild', xcodebuildArgs);
8072
let buildOutput = '';
8173
let errorOutput = '';
8274
buildProcess.stdout.on('data', (data: Buffer) => {
@@ -149,31 +141,3 @@ function xcprettyAvailable() {
149141
}
150142
return true;
151143
}
152-
153-
function getProcessOptions({
154-
packager,
155-
terminal,
156-
port,
157-
}: {
158-
packager: boolean;
159-
terminal?: string;
160-
port: number;
161-
}): SpawnOptionsWithoutStdio {
162-
if (packager) {
163-
return {
164-
env: {
165-
...process.env,
166-
RCT_TERMINAL: terminal,
167-
RCT_METRO_PORT: port.toString(),
168-
},
169-
};
170-
}
171-
172-
return {
173-
env: {
174-
...process.env,
175-
RCT_TERMINAL: terminal,
176-
RCT_NO_LAUNCH_PACKAGER: 'true',
177-
},
178-
};
179-
}

packages/cli-platform-ios/src/commands/buildIOS/index.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {getProjectInfo} from '../../tools/getProjectInfo';
2222
import {checkIfConfigurationExists} from '../../tools/checkIfConfigurationExists';
2323
import {getConfigurationScheme} from '../../tools/getConfigurationScheme';
2424
import listIOSDevices from '../../tools/listIOSDevices';
25-
import {runPackager} from '@react-native-community/cli-plugin-metro';
2625

2726
export interface FlagsT extends BuildFlags {
2827
configuration?: string;
@@ -96,23 +95,10 @@ async function buildIOS(_: Array<string>, ctx: Config, args: FlagsT) {
9695
} "${chalk.bold(xcodeProject.name)}"`,
9796
);
9897

99-
await runPackager(
100-
args.port,
101-
ctx.root,
102-
ctx.reactNativePath,
103-
args.terminal,
104-
args.packager,
105-
);
106-
107-
const extendedArgs = {
108-
...modifiedArgs,
109-
packager: false,
110-
};
111-
11298
// // No need to load all available devices
11399
if (!args.device && !args.udid) {
114100
if (!args.simulator) {
115-
return buildProject(xcodeProject, undefined, scheme, extendedArgs);
101+
return buildProject(xcodeProject, undefined, scheme, modifiedArgs);
116102
}
117103

118104
/**
@@ -135,7 +121,7 @@ async function buildIOS(_: Array<string>, ctx: Config, args: FlagsT) {
135121
xcodeProject,
136122
selectedSimulator.udid,
137123
scheme,
138-
extendedArgs,
124+
modifiedArgs,
139125
);
140126
}
141127

@@ -157,12 +143,12 @@ async function buildIOS(_: Array<string>, ctx: Config, args: FlagsT) {
157143
);
158144
}
159145

160-
return buildProject(xcodeProject, device.udid, scheme, extendedArgs);
146+
return buildProject(xcodeProject, device.udid, scheme, modifiedArgs);
161147
} else {
162148
const physicalDevices = devices.filter((d) => d.type !== 'simulator');
163149
const device = matchingDevice(physicalDevices, args.device);
164150
if (device) {
165-
return buildProject(xcodeProject, device.udid, scheme, extendedArgs);
151+
return buildProject(xcodeProject, device.udid, scheme, modifiedArgs);
166152
}
167153
}
168154
}

packages/cli-platform-ios/src/commands/runIOS/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface FlagsT extends BuildFlags {
3434
udid?: string;
3535
binaryPath?: string;
3636
listDevices?: boolean;
37+
packager: boolean;
3738
}
3839

3940
async function runIOS(_: Array<string>, ctx: Config, args: FlagsT) {

packages/cli-plugin-metro/src/commands/start/runPackager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ export async function runPackager(
1111
if (!packager) {
1212
return;
1313
}
14+
1415
const result = await isPackagerRunning(port);
16+
1517
if (result === 'running') {
1618
logger.info('JS server already running.');
1719
} else if (result === 'unrecognized') {
1820
logger.warn('JS server not recognized, continuing with build...');
19-
} else {
20-
// result == 'not_running'
21+
} else if (result === 'not_running') {
2122
logger.info('Starting JS server...');
2223

2324
try {

0 commit comments

Comments
 (0)