From 2b41fba7046fecc05213e5c6d4b546a7369c60b8 Mon Sep 17 00:00:00 2001 From: Anton Nikolaev Date: Tue, 11 May 2021 17:02:24 -0700 Subject: [PATCH] Change Flipper version retrieving Summary: Changed retrieving of Flipper version. Now it will be always retrieved from package.json. Before this change we used "remote.app.getVersion()" API which instead returned electron version for dev builds, e.g. "11.2.3". This is not convenient, because we now use Flipper version to check plugin compatibility and unrelated Electron version here makes things more complicated. After this change, if version is not properly bumped then "0.0.0" will be used: 1) when running using "yarn start", 2) when local building with "yarn build --mac" without setting new version, 3) when running tests "yarn test". In addition to that I added a new command-line argument and env var which allow overriding version number for Flipper. This is useful for testing plugin updates, because compatibility between plugins and Flipper is checked by comparing Flipper version with the min version set in the plugin metadata. Reviewed By: passy Differential Revision: D28287354 fbshipit-source-id: 2f9482080e3612b95a24300050d98150c6db6cb7 --- desktop/app/src/utils/info.tsx | 17 +++++++---------- desktop/scripts/start-dev-server.ts | 9 +++++++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/desktop/app/src/utils/info.tsx b/desktop/app/src/utils/info.tsx index fec79c43c..a236df464 100644 --- a/desktop/app/src/utils/info.tsx +++ b/desktop/app/src/utils/info.tsx @@ -8,7 +8,7 @@ */ import os from 'os'; -import {remote} from 'electron'; +import {isTest} from './isProduction'; export type Info = { arch: string; @@ -36,15 +36,12 @@ export function getInfo(): Info { }; } -let APP_VERSION: string | undefined = undefined; -// Prefer using this function over manually calling `remote.app.getVersion()` -// as calls to the remote object go over IPC and can be slow. -export function getAppVersion(): string | undefined { - if (APP_VERSION === undefined && remote) { - APP_VERSION = remote.app.getVersion(); - } - - return APP_VERSION; +let APP_VERSION: string | undefined; +export function getAppVersion(): string { + return (APP_VERSION = + APP_VERSION ?? + process.env.FLIPPER_FORCE_VERSION ?? + (isTest() ? '0.0.0' : require('../../package.json').version ?? '0.0.0')); } export function stringifyInfo(info: Info): string { diff --git a/desktop/scripts/start-dev-server.ts b/desktop/scripts/start-dev-server.ts index 3b8fa4571..711e7482b 100644 --- a/desktop/scripts/start-dev-server.ts +++ b/desktop/scripts/start-dev-server.ts @@ -85,6 +85,11 @@ const argv = yargs '[FB-internal only] Will force using public sources only, to be able to iterate quickly on the public version. If sources are checked out from GitHub this is already the default. Setting env var "FLIPPER_FORCE_PUBLIC_BUILD" is equivalent.', type: 'boolean', }, + 'force-version': { + describe: + 'Will force using the given value as Flipper version, to be able to test logic which is version-dependent. Setting env var "FLIPPER_FORCE_VERSION" is equivalent.', + type: 'string', + }, }) .version('DEV') .help() @@ -152,6 +157,10 @@ if (argv.channel !== undefined) { process.env.FLIPPER_RELEASE_CHANNEL = argv.channel; } +if (argv['force-version']) { + process.env.FLIPPER_FORCE_VERSION = argv['force-version']; +} + function looksLikeDevServer(): boolean { const hn = hostname(); if (/^devvm.*\.facebook\.com$/.test(hn)) {