From 2e7d7cf90726246115931425116db709ba344f9c Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Wed, 26 Jun 2024 12:12:26 +0300 Subject: [PATCH 01/21] feat: release-profiler on web --- config/webpack/webpack.dev.ts | 4 ++++ .../BaseProfilingToolMenu.tsx | 20 +++++++++---------- .../ProfilingToolMenu/RNFS/index.ts | 3 +++ .../ProfilingToolMenu/RNFS/index.web.ts | 18 +++++++++++++++++ .../ProfilingToolMenu/Share/index.ts | 3 +++ .../ProfilingToolMenu/Share/index.web.ts | 5 +++++ src/components/ProfilingToolMenu/index.tsx | 10 +++++++++- 7 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 src/components/ProfilingToolMenu/RNFS/index.ts create mode 100644 src/components/ProfilingToolMenu/RNFS/index.web.ts create mode 100644 src/components/ProfilingToolMenu/Share/index.ts create mode 100644 src/components/ProfilingToolMenu/Share/index.web.ts diff --git a/config/webpack/webpack.dev.ts b/config/webpack/webpack.dev.ts index 7a196da6b691..1be311d15c37 100644 --- a/config/webpack/webpack.dev.ts +++ b/config/webpack/webpack.dev.ts @@ -53,6 +53,10 @@ const getConfiguration = (environment: Environment): Promise => cert: path.join(__dirname, 'certificate.pem'), }, }, + headers: { + // eslint-disable-next-line @typescript-eslint/naming-convention + 'Document-Policy': 'js-profiling', + }, }, plugins: [ new DefinePlugin({ diff --git a/src/components/ProfilingToolMenu/BaseProfilingToolMenu.tsx b/src/components/ProfilingToolMenu/BaseProfilingToolMenu.tsx index 5593ad627e92..cabe990a7122 100644 --- a/src/components/ProfilingToolMenu/BaseProfilingToolMenu.tsx +++ b/src/components/ProfilingToolMenu/BaseProfilingToolMenu.tsx @@ -1,10 +1,8 @@ import React, {useCallback, useEffect, useState} from 'react'; import DeviceInfo from 'react-native-device-info'; -import RNFS from 'react-native-fs'; import {withOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; import {startProfiling, stopProfiling} from 'react-native-release-profiler'; -import Share from 'react-native-share'; import Button from '@components/Button'; import Switch from '@components/Switch'; import TestToolRow from '@components/TestToolRow'; @@ -17,6 +15,8 @@ import Log from '@libs/Log'; import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import RNFS from './RNFS'; +import Share from './Share'; import pkg from '../../../package.json'; type BaseProfilingToolMenuOnyxProps = { @@ -49,7 +49,7 @@ const newFileName = `Profile_trace_for_${pkg.version}.cpuprofile`; function BaseProfilingToolMenu({isProfilingInProgress = false, pathToBeUsed, displayPath}: BaseProfilingToolMenuProps) { const styles = useThemeStyles(); - const [pathIOS, setPathIOS] = useState(''); + const [filePath, setFilePath] = useState(''); const [sharePath, setSharePath] = useState(''); const [totalMemory, setTotalMemory] = useState(0); const [usedMemory, setUsedMemory] = useState(0); @@ -57,8 +57,8 @@ function BaseProfilingToolMenu({isProfilingInProgress = false, pathToBeUsed, dis // eslint-disable-next-line @lwc/lwc/no-async-await const stop = useCallback(async () => { - const path = await stopProfiling(getPlatform() === CONST.PLATFORM.IOS); - setPathIOS(path); + const path = await stopProfiling(getPlatform() === CONST.PLATFORM.IOS || getPlatform() === CONST.PLATFORM.WEB); + setFilePath(path); const amountOfTotalMemory = await DeviceInfo.getTotalMemory(); const amountOfUsedMemory = await DeviceInfo.getUsedMemory(); @@ -92,7 +92,7 @@ function BaseProfilingToolMenu({isProfilingInProgress = false, pathToBeUsed, dis ); useEffect(() => { - if (!pathIOS) { + if (!filePath) { return; } @@ -112,7 +112,7 @@ function BaseProfilingToolMenu({isProfilingInProgress = false, pathToBeUsed, dis } // Copy the file to a new location with the desired filename - await RNFS.copyFile(pathIOS, newFilePath) + await RNFS.copyFile(filePath, newFilePath) .then(() => { Log.hmmm('[ProfilingToolMenu] file copied successfully'); }) @@ -124,7 +124,7 @@ function BaseProfilingToolMenu({isProfilingInProgress = false, pathToBeUsed, dis }; rename(); - }, [pathIOS, pathToBeUsed]); + }, [filePath, pathToBeUsed]); const onDownloadProfiling = useCallback(() => { // eslint-disable-next-line @lwc/lwc/no-async-await @@ -158,9 +158,9 @@ function BaseProfilingToolMenu({isProfilingInProgress = false, pathToBeUsed, dis onToggle={onToggleProfiling} /> - {!!pathIOS && ( + {!!filePath && ( <> - {`path: ${displayPath}/${newFileName}`} + {`path: ${displayPath}/${getPlatform() === CONST.PLATFORM.WEB ? filePath : newFileName}`}