Move app/server to flipper-server-core
Summary: moved `app/src/server` to `flipper-server-core/src` and fixed any fallout from that (aka integration points I missed on the preparing diffs). Reviewed By: passy Differential Revision: D31541378 fbshipit-source-id: 8a7e0169ebefa515781f6e5e0f7b926415d4b7e9
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3e7a6b1b4b
commit
d88b28330a
14
desktop/flipper-common/src/GK.tsx
Normal file
14
desktop/flipper-common/src/GK.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
export const GK = {
|
||||
get(_name: string): boolean {
|
||||
return false;
|
||||
},
|
||||
};
|
||||
68
desktop/flipper-common/src/__tests__/clientUtils.node.tsx
Normal file
68
desktop/flipper-common/src/__tests__/clientUtils.node.tsx
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* 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 {deconstructClientId, buildClientId} from '../clientUtils';
|
||||
|
||||
test('client id constructed correctly', () => {
|
||||
const consoleErrorSpy = jest.spyOn(global.console, 'error');
|
||||
const clientId = buildClientId({
|
||||
app: 'Instagram',
|
||||
os: 'iOS',
|
||||
device: 'iPhone Simulator',
|
||||
device_id: 'EC431B79-69F1-4705-9FE5-9AE5D96378E1',
|
||||
});
|
||||
expect(clientId).toBe(
|
||||
'Instagram#iOS#iPhone Simulator#EC431B79-69F1-4705-9FE5-9AE5D96378E1',
|
||||
);
|
||||
expect(consoleErrorSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test('client id deconstructed correctly', () => {
|
||||
const deconstructedClientId = deconstructClientId(
|
||||
'Instagram#iOS#iPhone Simulator#EC431B79-69F1-4705-9FE5-9AE5D96378E1',
|
||||
);
|
||||
expect(deconstructedClientId).toStrictEqual({
|
||||
app: 'Instagram',
|
||||
os: 'iOS',
|
||||
device: 'iPhone Simulator',
|
||||
device_id: 'EC431B79-69F1-4705-9FE5-9AE5D96378E1',
|
||||
});
|
||||
});
|
||||
|
||||
test('client id deconstruction error logged', () => {
|
||||
const consoleErrorSpy = jest.spyOn(global.console, 'error');
|
||||
const deconstructedClientId = deconstructClientId(
|
||||
'Instagram#iPhone Simulator#EC431B79-69F1-4705-9FE5-9AE5D96378E1',
|
||||
);
|
||||
expect(deconstructedClientId).toStrictEqual({
|
||||
app: 'Instagram',
|
||||
os: 'iPhone Simulator',
|
||||
device: 'EC431B79-69F1-4705-9FE5-9AE5D96378E1',
|
||||
device_id: undefined,
|
||||
});
|
||||
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('special characters in app name handled correctly', () => {
|
||||
const consoleErrorSpy = jest.spyOn(global.console, 'error');
|
||||
|
||||
const testClient = {
|
||||
app: '#myGreat#App&',
|
||||
os: 'iOS',
|
||||
device: 'iPhone Simulator',
|
||||
device_id: 'EC431B79-69F1-4705-9FE5-9AE5D96378E1',
|
||||
};
|
||||
const clientId = buildClientId(testClient);
|
||||
|
||||
const deconstructedClientId = deconstructClientId(clientId);
|
||||
|
||||
expect(deconstructedClientId).toStrictEqual(testClient);
|
||||
|
||||
expect(consoleErrorSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
100
desktop/flipper-common/src/clientUtils.tsx
Normal file
100
desktop/flipper-common/src/clientUtils.tsx
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
/* A Client uniuely identifies an app running on some device.
|
||||
|
||||
Always use this utility to construct and parse clientId strings.
|
||||
*/
|
||||
export type ClientIdConstituents = {
|
||||
app: string;
|
||||
os: string;
|
||||
device: string;
|
||||
device_id: string;
|
||||
};
|
||||
|
||||
/* A plugin key is a string uniquely identifying an instance of a plugin.
|
||||
This can be a device plugin for a particular device, or a client plugin for a particular client (app).
|
||||
In the device plugin case, the "client" is the device it's connected to.
|
||||
In the client plugin case (normal plugins), the "client" is the app it's connected to.
|
||||
|
||||
Always use this utility to construct and parse pluginKey strings.
|
||||
*/
|
||||
type PluginKeyConstituents =
|
||||
| {
|
||||
type: 'device';
|
||||
pluginName: string;
|
||||
client: string;
|
||||
}
|
||||
| ({
|
||||
type: 'client';
|
||||
pluginName: string;
|
||||
client: string;
|
||||
} & ClientIdConstituents);
|
||||
|
||||
export function buildClientId(clientInfo: {
|
||||
app: string;
|
||||
os: string;
|
||||
device: string;
|
||||
device_id: string;
|
||||
}): string {
|
||||
// N.B.: device_id can be empty, which designates the host device
|
||||
for (const key of ['app', 'os', 'device'] as Array<
|
||||
keyof ClientIdConstituents
|
||||
>) {
|
||||
if (!clientInfo[key]) {
|
||||
console.error(
|
||||
`Attempted to build clientId with invalid ${key}: "${clientInfo[key]}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
const escapedName = escape(clientInfo.app);
|
||||
return `${escapedName}#${clientInfo.os}#${clientInfo.device}#${clientInfo.device_id}`;
|
||||
}
|
||||
|
||||
export function deconstructClientId(clientId: string): ClientIdConstituents {
|
||||
if (!clientId || clientId.split('#').length !== 4) {
|
||||
console.error(`Attempted to deconstruct invalid clientId: "${clientId}"`);
|
||||
}
|
||||
let [app, os, device, device_id] = clientId.split('#');
|
||||
app = unescape(app);
|
||||
return {
|
||||
app,
|
||||
os,
|
||||
device,
|
||||
device_id,
|
||||
};
|
||||
}
|
||||
|
||||
export function deconstructPluginKey(pluginKey: string): PluginKeyConstituents {
|
||||
const parts = pluginKey.split('#');
|
||||
if (parts.length === 2) {
|
||||
// Device plugin
|
||||
return {
|
||||
type: 'device',
|
||||
client: parts[0],
|
||||
pluginName: parts[1],
|
||||
};
|
||||
} else {
|
||||
// Client plugin
|
||||
const lastHashIndex = pluginKey.lastIndexOf('#');
|
||||
const clientId = pluginKey.slice(0, lastHashIndex);
|
||||
const pluginName = pluginKey.slice(lastHashIndex + 1);
|
||||
if (!pluginName) {
|
||||
console.error(
|
||||
`Attempted to deconstruct invalid pluginKey: "${pluginKey}"`,
|
||||
);
|
||||
}
|
||||
return {
|
||||
type: 'client',
|
||||
...deconstructClientId(clientId),
|
||||
client: clientId,
|
||||
pluginName: pluginName,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -41,3 +41,5 @@ export {
|
||||
getErrorFromErrorLike,
|
||||
} from './utils/errors';
|
||||
export * from './user-session';
|
||||
export * from './GK';
|
||||
export * from './clientUtils';
|
||||
|
||||
@@ -112,6 +112,14 @@ export type FlipperServerEvents = {
|
||||
};
|
||||
};
|
||||
|
||||
export type IOSDeviceParams = {
|
||||
udid: string;
|
||||
type: DeviceType;
|
||||
name: string;
|
||||
deviceTypeIdentifier?: string;
|
||||
state?: string;
|
||||
};
|
||||
|
||||
export type FlipperServerCommands = {
|
||||
'device-start-logging': (serial: string) => Promise<void>;
|
||||
'device-stop-logging': (serial: string) => Promise<void>;
|
||||
@@ -137,6 +145,10 @@ export type FlipperServerCommands = {
|
||||
clientId: string,
|
||||
payload: any,
|
||||
) => Promise<ClientResponseType>;
|
||||
'android-get-emulators': () => Promise<string[]>;
|
||||
'android-launch-emulator': (name: string, coldboot: boolean) => Promise<void>;
|
||||
'ios-get-simulators': (bootedOnly: boolean) => Promise<IOSDeviceParams[]>;
|
||||
'ios-launch-simulator': (udid: string) => Promise<void>;
|
||||
};
|
||||
|
||||
export interface FlipperServer {
|
||||
@@ -154,3 +166,95 @@ export interface FlipperServer {
|
||||
): ReturnType<FlipperServerCommands[Event]>;
|
||||
close(): void;
|
||||
}
|
||||
|
||||
// From xplat/js/metro/packages/metro/src/lib/reporting.js
|
||||
export type MetroBundleDetails = {
|
||||
entryFile: string;
|
||||
platform?: string;
|
||||
dev: boolean;
|
||||
minify: boolean;
|
||||
bundleType: string;
|
||||
};
|
||||
|
||||
// From xplat/js/metro/packages/metro/src/lib/reporting.js
|
||||
export type MetroGlobalCacheDisabledReason =
|
||||
| 'too_many_errors'
|
||||
| 'too_many_misses';
|
||||
|
||||
/**
|
||||
* A tagged union of all the actions that may happen and we may want to
|
||||
* report to the tool user.
|
||||
*
|
||||
* Based on xplat/js/metro/packages/metro/src/lib/TerminalReporter.js
|
||||
*/
|
||||
export type MetroReportableEvent =
|
||||
| {
|
||||
port: number;
|
||||
projectRoots: ReadonlyArray<string>;
|
||||
type: 'initialize_started';
|
||||
}
|
||||
| {type: 'initialize_done'}
|
||||
| {
|
||||
type: 'initialize_failed';
|
||||
port: number;
|
||||
error: Error;
|
||||
}
|
||||
| {
|
||||
buildID: string;
|
||||
type: 'bundle_build_done';
|
||||
}
|
||||
| {
|
||||
buildID: string;
|
||||
type: 'bundle_build_failed';
|
||||
}
|
||||
| {
|
||||
buildID: string;
|
||||
bundleDetails: MetroBundleDetails;
|
||||
type: 'bundle_build_started';
|
||||
}
|
||||
| {
|
||||
error: Error;
|
||||
type: 'bundling_error';
|
||||
}
|
||||
| {type: 'dep_graph_loading'}
|
||||
| {type: 'dep_graph_loaded'}
|
||||
| {
|
||||
buildID: string;
|
||||
type: 'bundle_transform_progressed';
|
||||
transformedFileCount: number;
|
||||
totalFileCount: number;
|
||||
}
|
||||
| {
|
||||
type: 'global_cache_error';
|
||||
error: Error;
|
||||
}
|
||||
| {
|
||||
type: 'global_cache_disabled';
|
||||
reason: MetroGlobalCacheDisabledReason;
|
||||
}
|
||||
| {type: 'transform_cache_reset'}
|
||||
| {
|
||||
type: 'worker_stdout_chunk';
|
||||
chunk: string;
|
||||
}
|
||||
| {
|
||||
type: 'worker_stderr_chunk';
|
||||
chunk: string;
|
||||
}
|
||||
| {
|
||||
type: 'hmr_client_error';
|
||||
error: Error;
|
||||
}
|
||||
| {
|
||||
type: 'client_log';
|
||||
level:
|
||||
| 'trace'
|
||||
| 'info'
|
||||
| 'warn'
|
||||
| 'log'
|
||||
| 'group'
|
||||
| 'groupCollapsed'
|
||||
| 'groupEnd'
|
||||
| 'debug';
|
||||
data: Array<any>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user