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:
Michel Weststrate
2021-12-08 04:25:28 -08:00
committed by Facebook GitHub Bot
parent de59bbedd2
commit 2a4fe77404
22 changed files with 199 additions and 135 deletions

View File

@@ -30,7 +30,7 @@ export function loadDistilleryGK(
}
export default class GK {
static init() {}
static init(_username: string) {}
static get(id: GKID): boolean {
if (process.env.NODE_ENV === 'test' && id === TEST_PASSING_GK) {

View File

@@ -11,16 +11,17 @@ export {FlipperServerImpl} from './FlipperServerImpl';
export {loadSettings} from './utils/settings';
export {loadLauncherSettings} from './utils/launcherSettings';
export {loadProcessConfig} from './utils/processConfig';
export {getEnvironmentInfo} from './utils/environmentInfo';
import GKImplementation from './fb-stubs/GK';
export {setupPrefetcher} from './fb-stubs/Prefetcher';
let loaded = false;
export function getGatekeepers(): Record<string, boolean> {
export function getGatekeepers(username: string): Record<string, boolean> {
if (!loaded) {
// this starts fetching gatekeepers, note that they will only be available on next restart!
GKImplementation.init();
GKImplementation.init(username);
loaded = true;
}
return GKImplementation.allGKs();

View File

@@ -21,7 +21,7 @@ test('config is decoded from env', () => {
});
expect(config).toEqual({
disabledPlugins: new Set(['pluginA', 'pluginB', 'pluginC']),
disabledPlugins: ['pluginA', 'pluginB', 'pluginC'],
lastWindowPosition: {x: 4, y: 8, width: 15, height: 16},
launcherMsg: 'wubba lubba dub dub',
screenCapturePath: '/my/screenshot/path',
@@ -31,7 +31,7 @@ test('config is decoded from env', () => {
test('config is decoded from env with defaults', () => {
expect(loadProcessConfig({CONFIG: '{}'})).toEqual({
disabledPlugins: new Set([]),
disabledPlugins: [],
lastWindowPosition: undefined,
launcherMsg: undefined,
screenCapturePath: undefined,

View File

@@ -0,0 +1,57 @@
/**
* 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 os from 'os';
import fs from 'fs-extra';
import path from 'path';
import {EnvironmentInfo, ReleaseChannel} from 'flipper-common';
export async function getEnvironmentInfo(
staticPath: string,
isProduction: boolean,
): Promise<EnvironmentInfo> {
const packageJson = await fs.readJSON(
path.resolve(staticPath, 'package.json'),
);
const releaseChannel: ReleaseChannel =
process.env.FLIPPER_RELEASE_CHANNEL === 'insiders'
? ReleaseChannel.INSIDERS
: process.env.FLIPPER_RELEASE_CHANNEL === 'stable'
? ReleaseChannel.STABLE
: packageJson.releaseChannel === 'insiders'
? ReleaseChannel.INSIDERS
: ReleaseChannel.STABLE;
// This is provided as part of the bundling process for headless.
const flipperReleaseRevision =
(global as any).__REVISION__ ?? packageJson.revision;
const appVersion =
process.env.FLIPPER_FORCE_VERSION ??
(isProduction ? packageJson.version : '0.0.0');
return {
processId: process.pid,
isProduction,
releaseChannel,
flipperReleaseRevision,
appVersion,
os: {
arch: process.arch,
platform: process.platform,
unixname: os.userInfo().username,
},
versions: {
electron: process.versions.electron,
node: process.versions.node,
platform: os.release(),
},
};
}

View File

@@ -12,7 +12,7 @@ import {ProcessConfig} from 'flipper-common';
export function loadProcessConfig(env: NodeJS.ProcessEnv): ProcessConfig {
const json = JSON.parse(env.CONFIG || '{}');
return {
disabledPlugins: new Set<string>(json.disabledPlugins || []),
disabledPlugins: json.disabledPlugins || [],
lastWindowPosition: json.lastWindowPosition,
launcherMsg: json.launcherMsg,
screenCapturePath: json.screenCapturePath,