Skip to content
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
8 changes: 8 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,14 @@ The running metro server port number

> default: 8081

#### `--appId <string>`

Specify an `applicationId` to launch after build. If not specified, `package` from AndroidManifest.xml will be used.

#### `--appIdSuffix <string>`

Specify an `applicationIdSuffix` to launch after build.

### Notes on source map

This step is recommended in order for the source map to be generated:
Expand Down
23 changes: 16 additions & 7 deletions packages/cli-hermes/src/profileHermes/downloadProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {
} from '@react-native-community/cli-platform-android';
/**
* Get the last modified hermes profile
* @param packageName
* @param packageNameWithSuffix
*/
function getLatestFile(packageName: string): string {
function getLatestFile(packageNameWithSuffix: string): string {
try {
const file = execSync(`adb shell run-as ${packageName} ls cache/ -tp | grep -v /$ | grep -E '.cpuprofile' | head -1
const file = execSync(`adb shell run-as ${packageNameWithSuffix} ls cache/ -tp | grep -v /$ | grep -E '.cpuprofile' | head -1
`);
return file.toString().trim();
} catch (e) {
Expand All @@ -37,6 +37,8 @@ function execSyncWithLog(command: string) {
* @param sourceMapPath
* @param raw
* @param generateSourceMap
* @param appId
* @param appIdSuffix
*/
export async function downloadProfile(
ctx: Config,
Expand All @@ -46,13 +48,20 @@ export async function downloadProfile(
raw?: boolean,
shouldGenerateSourcemap?: boolean,
port?: string,
appId?: string,
appIdSuffix?: string,
) {
try {
const androidProject = getAndroidProject(ctx);
const packageName = getPackageName(androidProject);
const packageNameWithSuffix = [
appId || getPackageName(androidProject),
appIdSuffix,
]
.filter(Boolean)
.join('.');

// If file name is not specified, pull the latest file from device
const file = filename || getLatestFile(packageName);
const file = filename || getLatestFile(packageNameWithSuffix);
if (!file) {
throw new CLIError(
'There is no file in the cache/ directory. Did you record a profile from the developer menu?',
Expand All @@ -69,7 +78,7 @@ export async function downloadProfile(
// If --raw, pull the hermes profile to dstPath
if (raw) {
execSyncWithLog(
`adb shell run-as ${packageName} cat cache/${file} > ${dstPath}/${file}`,
`adb shell run-as ${packageNameWithSuffix} cat cache/${file} > ${dstPath}/${file}`,
);
logger.success(`Successfully pulled the file to ${dstPath}/${file}`);
}
Expand All @@ -80,7 +89,7 @@ export async function downloadProfile(
const tempFilePath = path.join(osTmpDir, file);

execSyncWithLog(
`adb shell run-as ${packageName} cat cache/${file} > ${tempFilePath}`,
`adb shell run-as ${packageNameWithSuffix} cat cache/${file} > ${tempFilePath}`,
);
// If path to source map is not given
if (!sourcemapPath) {
Expand Down
13 changes: 13 additions & 0 deletions packages/cli-hermes/src/profileHermes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type Options = {
sourcemapPath?: string;
generateSourcemap?: boolean;
port: string;
appId?: string;
appIdSuffix?: string;
};

async function profileHermes(
Expand All @@ -30,6 +32,8 @@ async function profileHermes(
options.raw,
options.generateSourcemap,
options.port,
options.appId,
options.appIdSuffix,
);
} catch (err) {
throw err as CLIError;
Expand Down Expand Up @@ -65,6 +69,15 @@ export default {
name: '--port <number>',
default: `${process.env.RCT_METRO_PORT || 8081}`,
},
{
name: '--appId <string>',
description:
'Specify an applicationId to launch after build. If not specified, `package` from AndroidManifest.xml will be used.',
},
{
name: '--appIdSuffix <string>',
description: 'Specify an applicationIdSuffix to launch after build.',
},
],
examples: [
{
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-hermes/src/profileHermes/sourcemapUtils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {Config} from '@react-native-community/cli-types';
import {logger, CLIError} from '@react-native-community/cli-tools';
import {logger, CLIError, fetch} from '@react-native-community/cli-tools';
import fs from 'fs';
import path from 'path';
import os from 'os';
import {SourceMap} from 'hermes-profile-transformer';
import ip from 'ip';
import {fetch} from '@react-native-community/cli-tools';

function getTempFilePath(filename: string) {
return path.join(os.tmpdir(), filename);
Expand Down