Skip to content
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

fix: replace ip package with default value and --host flag #2299

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/cli-doctor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"envinfo": "^7.10.0",
"execa": "^5.0.0",
"hermes-profile-transformer": "^0.0.6",
"ip": "^1.1.5",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it was in package.json, was it used anywhere in the doctor command?

Copy link
Collaborator Author

@szymonrybczak szymonrybczak Feb 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, i guess it was a leftover after some package refactors.

"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": "13.5.2",
"@react-native-community/cli-tools": "13.5.2",
"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 @@ -6798,11 +6798,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
Loading