Skip to content

Commit e2e28dd

Browse files
fix: replace ip package with default value and --host flag (#2301)
1 parent 730f92a commit e2e28dd

File tree

8 files changed

+21
-13
lines changed

8 files changed

+21
-13
lines changed

packages/cli-doctor/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"envinfo": "^7.10.0",
1919
"execa": "^5.0.0",
2020
"hermes-profile-transformer": "^0.0.6",
21-
"ip": "^1.1.5",
2221
"node-stream-zip": "^1.9.1",
2322
"ora": "^5.4.1",
2423
"semver": "^7.5.2",

packages/cli-hermes/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ Specify an `applicationId` to launch after build. If not specified, `package` fr
5757

5858
Specify an `applicationIdSuffix` to launch after build.
5959

60+
#### `--host <string>`
61+
62+
The host of the packager.
63+
64+
> default: localhost
65+
6066
### Notes on source map
6167

6268
This step is recommended in order for the source map to be generated:

packages/cli-hermes/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"@react-native-community/cli-platform-android": "12.3.5",
1212
"@react-native-community/cli-tools": "12.3.5",
1313
"chalk": "^4.1.2",
14-
"hermes-profile-transformer": "^0.0.6",
15-
"ip": "^1.1.5"
14+
"hermes-profile-transformer": "^0.0.6"
1615
},
1716
"files": [
1817
"build",

packages/cli-hermes/src/profileHermes/downloadProfile.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export async function downloadProfile(
5959
port: string = '8081',
6060
appId?: string,
6161
appIdSuffix?: string,
62+
host: string = 'localhost',
6263
) {
6364
try {
6465
const androidProject = getAndroidProject(ctx);
@@ -101,7 +102,7 @@ export async function downloadProfile(
101102
`adb shell run-as ${packageNameWithSuffix} cat cache/${file} > ${tempFilePath}`,
102103
);
103104

104-
const bundleOptions = getMetroBundleOptions(tempFilePath);
105+
const bundleOptions = getMetroBundleOptions(tempFilePath, host);
105106

106107
// If path to source map is not given
107108
if (!sourcemapPath) {

packages/cli-hermes/src/profileHermes/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type Options = {
1010
port: string;
1111
appId?: string;
1212
appIdSuffix?: string;
13+
host?: string;
1314
};
1415

1516
async function profileHermes(
@@ -34,6 +35,7 @@ async function profileHermes(
3435
options.port,
3536
options.appId,
3637
options.appIdSuffix,
38+
options.host,
3739
);
3840
} catch (err) {
3941
throw err as CLIError;
@@ -78,6 +80,11 @@ export default {
7880
name: '--appIdSuffix <string>',
7981
description: 'Specify an applicationIdSuffix to launch after build.',
8082
},
83+
{
84+
name: '--host <string>',
85+
description: 'The host of the packager.',
86+
default: 'localhost',
87+
},
8188
],
8289
examples: [
8390
{

packages/cli-hermes/src/profileHermes/metroBundleOptions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ export interface MetroBundleOptions {
66
platform: string;
77
dev: boolean;
88
minify: boolean;
9+
host: string;
910
}
1011

1112
export function getMetroBundleOptions(
1213
downloadedProfileFilePath: string,
14+
host: string,
1315
): MetroBundleOptions {
1416
let options: MetroBundleOptions = {
1517
platform: 'android',
1618
dev: true,
1719
minify: false,
20+
host,
1821
};
1922

2023
try {

packages/cli-hermes/src/profileHermes/sourcemapUtils.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import fs from 'fs';
44
import path from 'path';
55
import os from 'os';
66
import {SourceMap} from 'hermes-profile-transformer';
7-
import ip from 'ip';
87
import {MetroBundleOptions} from './metroBundleOptions';
98

109
function getTempFilePath(filename: string) {
@@ -31,12 +30,11 @@ function writeJsonSync(targetPath: string, data: any) {
3130

3231
async function getSourcemapFromServer(
3332
port: string,
34-
{platform, dev, minify}: MetroBundleOptions,
33+
{platform, dev, minify, host}: MetroBundleOptions,
3534
): Promise<SourceMap | undefined> {
3635
logger.debug('Getting source maps from Metro packager server');
37-
const IP_ADDRESS = ip.address();
3836

39-
const requestURL = `http://${IP_ADDRESS}:${port}/index.map?platform=${platform}&dev=${dev}&minify=${minify}`;
37+
const requestURL = `http://${host}:${port}/index.map?platform=${platform}&dev=${dev}&minify=${minify}`;
4038
logger.debug(`Downloading from ${requestURL}`);
4139
try {
4240
const {data} = await fetch(requestURL);

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6788,11 +6788,6 @@ ip-regex@^2.1.0:
67886788
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-2.1.0.tgz#fa78bf5d2e6913c911ce9f819ee5146bb6d844e9"
67896789
integrity sha1-+ni/XS5pE8kRzp+BnuUUa7bYROk=
67906790

6791-
ip@^1.1.5:
6792-
version "1.1.5"
6793-
resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.5.tgz#bdded70114290828c0a039e72ef25f5aaec4354a"
6794-
integrity sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo=
6795-
67966791
ip@^2.0.0:
67976792
version "2.0.0"
67986793
resolved "https://registry.yarnpkg.com/ip/-/ip-2.0.0.tgz#4cf4ab182fee2314c75ede1276f8c80b479936da"

0 commit comments

Comments
 (0)