Extract environment config initialisation to server-core
Summary: This diff makes most stuff that is read from the `os` package, and version info etc available from the `serverConfig` object, so that flipper-ui-core no longer needs the `os` package. Reviewed By: passy Differential Revision: D32694848 fbshipit-source-id: 93af1e95d898da9aaf351a6970b5a7652ee835c8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
de59bbedd2
commit
2a4fe77404
@@ -44,8 +44,6 @@ type ChildProcessEvents = {
|
||||
* Utilities provided by the render host, e.g. Electron, the Browser, etc
|
||||
*/
|
||||
export interface RenderHost {
|
||||
readonly processId: number;
|
||||
readonly isProduction: boolean;
|
||||
readTextFromClipboard(): string | undefined;
|
||||
writeTextToClipboard(text: string): void;
|
||||
/**
|
||||
|
||||
@@ -77,7 +77,7 @@ test('checkDisabled', () => {
|
||||
try {
|
||||
hostConfig.processConfig = {
|
||||
...orig,
|
||||
disabledPlugins: new Set([disabledPlugin]),
|
||||
disabledPlugins: [disabledPlugin],
|
||||
};
|
||||
const disabled = checkDisabled([]);
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ export const checkDisabled = (
|
||||
config.env.FLIPPER_ENABLED_PLUGINS.split(','),
|
||||
);
|
||||
}
|
||||
disabledList = config.processConfig.disabledPlugins;
|
||||
disabledList = new Set(config.processConfig.disabledPlugins);
|
||||
} catch (e) {
|
||||
console.error('Failed to compute enabled/disabled plugins', e);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,8 @@ export default (store: Store, logger: Logger) => {
|
||||
|
||||
const oldExitData = loadExitData();
|
||||
if (oldExitData) {
|
||||
const isReload = renderHost.processId === oldExitData.pid;
|
||||
const isReload =
|
||||
renderHost.serverConfig.environmentInfo.processId === oldExitData.pid;
|
||||
const timeSinceLastStartup =
|
||||
Date.now() - parseInt(oldExitData.lastSeen, 10);
|
||||
// console.log(isReload ? 'reload' : 'restart', oldExitData);
|
||||
@@ -370,7 +371,7 @@ export function persistExitData(
|
||||
? deconstructClientId(state.selectedAppId).app
|
||||
: '',
|
||||
cleanExit,
|
||||
pid: getRenderHostInstance().processId,
|
||||
pid: getRenderHostInstance().serverConfig.environmentInfo.processId,
|
||||
};
|
||||
window.localStorage.setItem(
|
||||
flipperExitDataKey,
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {readCurrentRevision} from '../packageMetadata';
|
||||
|
||||
test('readCurrentRevision does not return something meaningful in dev mode', async () => {
|
||||
const ret = await readCurrentRevision();
|
||||
expect(ret).toBeUndefined();
|
||||
});
|
||||
@@ -23,7 +23,6 @@ import {default as BaseDevice} from '../devices/BaseDevice';
|
||||
import {default as ArchivedDevice} from '../devices/ArchivedDevice';
|
||||
import fs from 'fs-extra';
|
||||
import {v4 as uuidv4} from 'uuid';
|
||||
import {readCurrentRevision} from './packageMetadata';
|
||||
import {tryCatchReportPlatformFailures} from 'flipper-common';
|
||||
import {TestIdler} from './Idler';
|
||||
import {setStaticView} from '../reducers/connections';
|
||||
@@ -243,7 +242,8 @@ async function addSaltToDeviceSerial({
|
||||
}
|
||||
return {...notif, client: notif.client.replace(serial, newSerial)};
|
||||
});
|
||||
const revision: string | undefined = await readCurrentRevision();
|
||||
const revision: string | undefined =
|
||||
getRenderHostInstance().serverConfig.environmentInfo.flipperReleaseRevision;
|
||||
return {
|
||||
fileVersion: getAppVersion() || 'unknown',
|
||||
flipperReleaseRevision: revision,
|
||||
|
||||
@@ -10,13 +10,10 @@
|
||||
// Use of sync methods is cached.
|
||||
/* eslint-disable node/no-sync */
|
||||
|
||||
import os from 'os';
|
||||
import isProduction from './isProduction';
|
||||
import fs from 'fs-extra';
|
||||
import {getStaticPath} from './pathUtils';
|
||||
import type {State, Store} from '../reducers/index';
|
||||
import {sideEffect} from './sideEffect';
|
||||
import {Logger, isTest, deconstructClientId} from 'flipper-common';
|
||||
import {Logger, deconstructClientId} from 'flipper-common';
|
||||
import {getRenderHostInstance} from '../RenderHost';
|
||||
|
||||
type PlatformInfo = {
|
||||
arch: string;
|
||||
@@ -83,15 +80,13 @@ export default (store: Store, _logger: Logger) => {
|
||||
*/
|
||||
export function getInfo(): Info {
|
||||
if (!platformInfo) {
|
||||
const envInfo = getRenderHostInstance().serverConfig.environmentInfo;
|
||||
|
||||
platformInfo = {
|
||||
arch: process.arch,
|
||||
platform: process.platform,
|
||||
unixname: os.userInfo().username,
|
||||
versions: {
|
||||
electron: process.versions.electron,
|
||||
node: process.versions.node,
|
||||
platform: os.release(),
|
||||
},
|
||||
arch: envInfo.os.arch,
|
||||
platform: envInfo.os.platform,
|
||||
unixname: envInfo.os.unixname,
|
||||
versions: envInfo.versions,
|
||||
};
|
||||
}
|
||||
return {
|
||||
@@ -100,18 +95,8 @@ export function getInfo(): Info {
|
||||
};
|
||||
}
|
||||
|
||||
let APP_VERSION: string | undefined;
|
||||
export function getAppVersion(): string {
|
||||
return (APP_VERSION =
|
||||
APP_VERSION ??
|
||||
process.env.FLIPPER_FORCE_VERSION ??
|
||||
(isTest()
|
||||
? '0.0.0'
|
||||
: (isProduction()
|
||||
? fs.readJsonSync(getStaticPath('package.json'), {
|
||||
throws: false,
|
||||
})?.version
|
||||
: require('../../package.json').version) ?? '0.0.0'));
|
||||
return getRenderHostInstance().serverConfig.environmentInfo.appVersion;
|
||||
}
|
||||
|
||||
export function stringifyInfo(info: Info): string {
|
||||
|
||||
@@ -10,5 +10,5 @@
|
||||
import {getRenderHostInstance} from '../RenderHost';
|
||||
|
||||
export default function isProduction() {
|
||||
return getRenderHostInstance().isProduction;
|
||||
return getRenderHostInstance().serverConfig.environmentInfo.isProduction;
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import lodash from 'lodash';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import {promisify} from 'util';
|
||||
import {getRenderHostInstance} from '../RenderHost';
|
||||
|
||||
const getPackageJSON = async () => {
|
||||
const base = getRenderHostInstance().serverConfig.paths.appPath;
|
||||
const content = await promisify(fs.readFile)(
|
||||
path.join(base, 'package.json'),
|
||||
'utf-8',
|
||||
);
|
||||
return JSON.parse(content);
|
||||
};
|
||||
|
||||
export const readCurrentRevision: () => Promise<string | undefined> =
|
||||
lodash.memoize(async () => {
|
||||
// This is provided as part of the bundling process for headless.
|
||||
if (global.__REVISION__) {
|
||||
return global.__REVISION__;
|
||||
}
|
||||
const json = await getPackageJSON();
|
||||
return json.revision;
|
||||
});
|
||||
Reference in New Issue
Block a user