Skip to content

Commit

Permalink
fix: replace ip package with default value and --host flag (#2301)
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonrybczak authored Feb 19, 2024
1 parent 730f92a commit e2e28dd
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 13 deletions.
1 change: 0 additions & 1 deletion packages/cli-doctor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"envinfo": "^7.10.0",
"execa": "^5.0.0",
"hermes-profile-transformer": "^0.0.6",
"ip": "^1.1.5",
"node-stream-zip": "^1.9.1",
"ora": "^5.4.1",
"semver": "^7.5.2",
Expand Down
6 changes: 6 additions & 0 deletions packages/cli-hermes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ Specify an `applicationId` to launch after build. If not specified, `package` fr

Specify an `applicationIdSuffix` to launch after build.

#### `--host <string>`

The host of the packager.

> default: localhost
### Notes on source map

This step is recommended in order for the source map to be generated:
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-hermes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"@react-native-community/cli-platform-android": "12.3.5",
"@react-native-community/cli-tools": "12.3.5",
"chalk": "^4.1.2",
"hermes-profile-transformer": "^0.0.6",
"ip": "^1.1.5"
"hermes-profile-transformer": "^0.0.6"
},
"files": [
"build",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli-hermes/src/profileHermes/downloadProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export async function downloadProfile(
port: string = '8081',
appId?: string,
appIdSuffix?: string,
host: string = 'localhost',
) {
try {
const androidProject = getAndroidProject(ctx);
Expand Down Expand Up @@ -101,7 +102,7 @@ export async function downloadProfile(
`adb shell run-as ${packageNameWithSuffix} cat cache/${file} > ${tempFilePath}`,
);

const bundleOptions = getMetroBundleOptions(tempFilePath);
const bundleOptions = getMetroBundleOptions(tempFilePath, host);

// If path to source map is not given
if (!sourcemapPath) {
Expand Down
7 changes: 7 additions & 0 deletions packages/cli-hermes/src/profileHermes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Options = {
port: string;
appId?: string;
appIdSuffix?: string;
host?: string;
};

async function profileHermes(
Expand All @@ -34,6 +35,7 @@ async function profileHermes(
options.port,
options.appId,
options.appIdSuffix,
options.host,
);
} catch (err) {
throw err as CLIError;
Expand Down Expand Up @@ -78,6 +80,11 @@ export default {
name: '--appIdSuffix <string>',
description: 'Specify an applicationIdSuffix to launch after build.',
},
{
name: '--host <string>',
description: 'The host of the packager.',
default: 'localhost',
},
],
examples: [
{
Expand Down
3 changes: 3 additions & 0 deletions packages/cli-hermes/src/profileHermes/metroBundleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ export interface MetroBundleOptions {
platform: string;
dev: boolean;
minify: boolean;
host: string;
}

export function getMetroBundleOptions(
downloadedProfileFilePath: string,
host: string,
): MetroBundleOptions {
let options: MetroBundleOptions = {
platform: 'android',
dev: true,
minify: false,
host,
};

try {
Expand Down
6 changes: 2 additions & 4 deletions packages/cli-hermes/src/profileHermes/sourcemapUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import fs from 'fs';
import path from 'path';
import os from 'os';
import {SourceMap} from 'hermes-profile-transformer';
import ip from 'ip';
import {MetroBundleOptions} from './metroBundleOptions';

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

async function getSourcemapFromServer(
port: string,
{platform, dev, minify}: MetroBundleOptions,
{platform, dev, minify, host}: MetroBundleOptions,
): Promise<SourceMap | undefined> {
logger.debug('Getting source maps from Metro packager server');
const IP_ADDRESS = ip.address();

const requestURL = `http://${IP_ADDRESS}:${port}/index.map?platform=${platform}&dev=${dev}&minify=${minify}`;
const requestURL = `http://${host}:${port}/index.map?platform=${platform}&dev=${dev}&minify=${minify}`;
logger.debug(`Downloading from ${requestURL}`);
try {
const {data} = await fetch(requestURL);
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6788,11 +6788,6 @@ ip-regex@^2.1.0:
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-2.1.0.tgz#fa78bf5d2e6913c911ce9f819ee5146bb6d844e9"
integrity sha1-+ni/XS5pE8kRzp+BnuUUa7bYROk=

ip@^1.1.5:
version "1.1.5"
resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.5.tgz#bdded70114290828c0a039e72ef25f5aaec4354a"
integrity sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo=

ip@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ip/-/ip-2.0.0.tgz#4cf4ab182fee2314c75ede1276f8c80b479936da"
Expand Down

0 comments on commit e2e28dd

Please sign in to comment.