Skip to content

Commit

Permalink
fix: replace ip package with default value and --host flag (#2299)
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/cli-hermes/README.md
#	yarn.lock
  • Loading branch information
szymonrybczak authored and thymikee committed Feb 19, 2024
1 parent 21737c9 commit e9ab4e5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
1 change: 0 additions & 1 deletion packages/cli-doctor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"envinfo": "^7.7.2",
"execa": "^1.0.0",
"hermes-profile-transformer": "^0.0.6",
"ip": "^1.1.5",
"node-stream-zip": "^1.9.1",
"ora": "^5.4.1",
"prompts": "^2.4.0",
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": "^10.2.0",
"@react-native-community/cli-tools": "^10.1.1",
"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 @@ -48,6 +48,7 @@ export async function downloadProfile(
port: string = '8081',
appId?: string,
appIdSuffix?: string,
host: string = 'localhost',
) {
try {
const androidProject = getAndroidProject(ctx);
Expand Down Expand Up @@ -90,7 +91,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

0 comments on commit e9ab4e5

Please sign in to comment.