From 1563b6fac5a3576c6ef6842310a759f171156112 Mon Sep 17 00:00:00 2001 From: Brendon Sled Date: Thu, 18 Mar 2021 14:54:39 -0600 Subject: [PATCH 1/7] Added appId and appIdSuffix options --- .../src/profileHermes/downloadProfile.ts | 9 +++++++-- packages/cli-hermes/src/profileHermes/index.ts | 16 ++++++++++++++++ .../src/profileHermes/sourcemapUtils.ts | 3 +-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/cli-hermes/src/profileHermes/downloadProfile.ts b/packages/cli-hermes/src/profileHermes/downloadProfile.ts index b4756a9ec..4b7b0c5e0 100644 --- a/packages/cli-hermes/src/profileHermes/downloadProfile.ts +++ b/packages/cli-hermes/src/profileHermes/downloadProfile.ts @@ -46,13 +46,18 @@ 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 || packageName, 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?', @@ -67,7 +72,7 @@ export async function downloadProfile( logger.debug('Internal commands run to pull the file:'); // Copy the file from device's data to sdcard, then pull the file to a temp directory - execSyncWithLog(`adb shell run-as ${packageName} cp cache/${file} /sdcard`); + execSyncWithLog(`adb shell run-as ${packageNameWithSuffix} cp cache/${file} /sdcard`); // If --raw, pull the hermes profile to dstPath if (raw) { diff --git a/packages/cli-hermes/src/profileHermes/index.ts b/packages/cli-hermes/src/profileHermes/index.ts index 9fa7727f7..01638c0c7 100644 --- a/packages/cli-hermes/src/profileHermes/index.ts +++ b/packages/cli-hermes/src/profileHermes/index.ts @@ -1,3 +1,4 @@ +// @ts-ignore import {logger, CLIError} from '@react-native-community/cli-tools'; import {Config} from '@react-native-community/cli-types'; import {downloadProfile} from './downloadProfile'; @@ -8,6 +9,8 @@ type Options = { sourcemapPath?: string; generateSourcemap?: boolean; port: string; + appId?: string; + appIdSuffix?: string; }; async function profileHermes( @@ -30,6 +33,8 @@ async function profileHermes( options.raw, options.generateSourcemap, options.port, + options.appId, + options.appIdSuffix, ); } catch (err) { throw err as CLIError; @@ -65,6 +70,17 @@ export default { name: '--port ', default: `${process.env.RCT_METRO_PORT || 8081}`, }, + { + name: '--appId ', + description: + 'Specify an applicationId to launch after build. If not specified, `package` from AndroidManifest.xml will be used.', + default: '', + }, + { + name: '--appIdSuffix ', + description: 'Specify an applicationIdSuffix to launch after build.', + default: '', + }, ], examples: [ { diff --git a/packages/cli-hermes/src/profileHermes/sourcemapUtils.ts b/packages/cli-hermes/src/profileHermes/sourcemapUtils.ts index b1f3ee3df..6320f7851 100644 --- a/packages/cli-hermes/src/profileHermes/sourcemapUtils.ts +++ b/packages/cli-hermes/src/profileHermes/sourcemapUtils.ts @@ -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); From 769c64f426e09109b01ae8a593f99e3e8e18e6f9 Mon Sep 17 00:00:00 2001 From: Brendon Sled Date: Thu, 18 Mar 2021 15:09:46 -0600 Subject: [PATCH 2/7] PR request fixes --- packages/cli-hermes/src/profileHermes/downloadProfile.ts | 2 ++ packages/cli-hermes/src/profileHermes/index.ts | 1 - packages/cli-hermes/src/profileHermes/sourcemapUtils.ts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cli-hermes/src/profileHermes/downloadProfile.ts b/packages/cli-hermes/src/profileHermes/downloadProfile.ts index 4b7b0c5e0..2963eba6d 100644 --- a/packages/cli-hermes/src/profileHermes/downloadProfile.ts +++ b/packages/cli-hermes/src/profileHermes/downloadProfile.ts @@ -37,6 +37,8 @@ function execSyncWithLog(command: string) { * @param sourceMapPath * @param raw * @param generateSourceMap + * @param appId + * @param appIdSuffix */ export async function downloadProfile( ctx: Config, diff --git a/packages/cli-hermes/src/profileHermes/index.ts b/packages/cli-hermes/src/profileHermes/index.ts index 01638c0c7..58256d733 100644 --- a/packages/cli-hermes/src/profileHermes/index.ts +++ b/packages/cli-hermes/src/profileHermes/index.ts @@ -1,4 +1,3 @@ -// @ts-ignore import {logger, CLIError} from '@react-native-community/cli-tools'; import {Config} from '@react-native-community/cli-types'; import {downloadProfile} from './downloadProfile'; diff --git a/packages/cli-hermes/src/profileHermes/sourcemapUtils.ts b/packages/cli-hermes/src/profileHermes/sourcemapUtils.ts index 6320f7851..484f3913b 100644 --- a/packages/cli-hermes/src/profileHermes/sourcemapUtils.ts +++ b/packages/cli-hermes/src/profileHermes/sourcemapUtils.ts @@ -1,5 +1,5 @@ import {Config} from '@react-native-community/cli-types'; -import {logger, CLIError,fetch} 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'; From 9e9f994bbe3c8f442301fb2ef78a2200e5e7c2cc Mon Sep 17 00:00:00 2001 From: Brendon Sled Date: Thu, 18 Mar 2021 15:10:47 -0600 Subject: [PATCH 3/7] Yarn lint fix --- packages/cli-hermes/src/profileHermes/downloadProfile.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/cli-hermes/src/profileHermes/downloadProfile.ts b/packages/cli-hermes/src/profileHermes/downloadProfile.ts index 2963eba6d..15947e34c 100644 --- a/packages/cli-hermes/src/profileHermes/downloadProfile.ts +++ b/packages/cli-hermes/src/profileHermes/downloadProfile.ts @@ -74,7 +74,9 @@ export async function downloadProfile( logger.debug('Internal commands run to pull the file:'); // Copy the file from device's data to sdcard, then pull the file to a temp directory - execSyncWithLog(`adb shell run-as ${packageNameWithSuffix} cp cache/${file} /sdcard`); + execSyncWithLog( + `adb shell run-as ${packageNameWithSuffix} cp cache/${file} /sdcard`, + ); // If --raw, pull the hermes profile to dstPath if (raw) { From a6ea23c0864aa9fa1228f814617fcdbeeb523f8d Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 24 Jan 2022 17:39:10 +0100 Subject: [PATCH 4/7] chore: update naming and reduce number of calls --- .../cli-hermes/src/profileHermes/downloadProfile.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/cli-hermes/src/profileHermes/downloadProfile.ts b/packages/cli-hermes/src/profileHermes/downloadProfile.ts index ac94a06fb..3e5001f88 100644 --- a/packages/cli-hermes/src/profileHermes/downloadProfile.ts +++ b/packages/cli-hermes/src/profileHermes/downloadProfile.ts @@ -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) { @@ -53,8 +53,7 @@ export async function downloadProfile( ) { try { const androidProject = getAndroidProject(ctx); - const packageName = getPackageName(androidProject); - const packageNameWithSuffix = [appId || packageName, appIdSuffix] + const packageNameWithSuffix = [appId || getPackageName(androidProject), appIdSuffix] .filter(Boolean) .join('.'); @@ -87,7 +86,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) { From 73174919724798a5836654c6c92631a7eab77fd5 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 24 Jan 2022 17:43:35 +0100 Subject: [PATCH 5/7] chore: update documentation --- docs/commands.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/commands.md b/docs/commands.md index 5902949d3..e36588124 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -600,6 +600,14 @@ The running metro server port number > default: 8081 +#### `--appId ` + +Specify an `applicationId` to launch after build. If not specified, `package` from AndroidManifest.xml will be used. + +#### `--appIdSuffix ` + +Specify an `applicationIdSuffix` to launch after build. + ### Notes on source map This step is recommended in order for the source map to be generated: From 82c330f9bda5d5b88dfe7f6a75a60554d4eaa3b0 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 24 Jan 2022 17:46:52 +0100 Subject: [PATCH 6/7] chore: do not provide empty default values --- packages/cli-hermes/src/profileHermes/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/cli-hermes/src/profileHermes/index.ts b/packages/cli-hermes/src/profileHermes/index.ts index 58256d733..845e95f97 100644 --- a/packages/cli-hermes/src/profileHermes/index.ts +++ b/packages/cli-hermes/src/profileHermes/index.ts @@ -73,12 +73,10 @@ export default { name: '--appId ', description: 'Specify an applicationId to launch after build. If not specified, `package` from AndroidManifest.xml will be used.', - default: '', }, { name: '--appIdSuffix ', description: 'Specify an applicationIdSuffix to launch after build.', - default: '', }, ], examples: [ From 7476348dbd03ab58466bdd099cfa4dca4e51f737 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 24 Jan 2022 17:48:14 +0100 Subject: [PATCH 7/7] chore: lint --- packages/cli-hermes/src/profileHermes/downloadProfile.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/cli-hermes/src/profileHermes/downloadProfile.ts b/packages/cli-hermes/src/profileHermes/downloadProfile.ts index 3e5001f88..d28d9515b 100644 --- a/packages/cli-hermes/src/profileHermes/downloadProfile.ts +++ b/packages/cli-hermes/src/profileHermes/downloadProfile.ts @@ -53,7 +53,10 @@ export async function downloadProfile( ) { try { const androidProject = getAndroidProject(ctx); - const packageNameWithSuffix = [appId || getPackageName(androidProject), appIdSuffix] + const packageNameWithSuffix = [ + appId || getPackageName(androidProject), + appIdSuffix, + ] .filter(Boolean) .join('.');