Unshare global types

Summary:
This diff adds `types` fields on the compiler config for every project. This way we can make sure that for example node types and packages are not available in flipper-ui-core. Without an explicit types field, all types would be shared between all packages, and implicitly included into the compilation of everything. For the same reason `types/index.d.ts` has been removed, we want to be intentional on which types are being used in which package.

This diff does most of the work, the next diff will fine tune the globals, and do some further cleanup.

As an alternative solution I first tried a `nohoist: **/node_modules/types/**` and make sure every package list explicitly the types used in package json, which works but is much more error prone, as for example two different react types versions in two packages will cause the most unreadable compiler error due to the types not being shared and not literally the same.

Reviewed By: lawrencelomax

Differential Revision: D33124441

fbshipit-source-id: c2b9d768f845ac28005d8331ef5fa1066c7e4cd7
This commit is contained in:
Michel Weststrate
2021-12-17 07:34:41 -08:00
committed by Facebook GitHub Bot
parent af3757dcae
commit 5df34a337c
69 changed files with 406 additions and 561 deletions

View File

@@ -79,8 +79,7 @@
"@types/uuid": "^8.3.1",
"flipper-test-utils": "0.0.0",
"mock-fs": "^5.1.2",
"redux-mock-store": "^1.0.1",
"ts-jest": "^26.5.6"
"redux-mock-store": "^1.0.1"
},
"scripts": {
"reset": "rimraf lib *.tsbuildinfo",

View File

@@ -1,25 +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
*/
module.exports = {
remote: {
process: {
env: {},
},
app: {
getPath: (path: string) => `/${path}`,
getAppPath: process.cwd,
getVersion: () => '0.9.99',
relaunch: () => {},
exit: () => {},
},
getCurrentWindow: () => ({isFocused: () => true}),
},
ipcRenderer: {},
};

View File

@@ -74,11 +74,11 @@ test('Plugin container can render plugin and receive updates', async () => {
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"
@@ -176,11 +176,11 @@ test('PluginContainer can render Sandy plugins', async () => {
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"
@@ -216,11 +216,11 @@ test('PluginContainer can render Sandy plugins', async () => {
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"
@@ -296,11 +296,11 @@ test('PluginContainer can render Sandy plugins', async () => {
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"
@@ -561,11 +561,11 @@ test('PluginContainer + Sandy plugin supports deeplink', async () => {
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"
@@ -605,11 +605,11 @@ test('PluginContainer + Sandy plugin supports deeplink', async () => {
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"
@@ -748,11 +748,11 @@ test('PluginContainer can render Sandy device plugins', async () => {
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"
@@ -793,11 +793,11 @@ test('PluginContainer can render Sandy device plugins', async () => {
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"
@@ -909,11 +909,11 @@ test('PluginContainer + Sandy device plugin supports deeplink', async () => {
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"
@@ -955,11 +955,11 @@ test('PluginContainer + Sandy device plugin supports deeplink', async () => {
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"
@@ -1247,11 +1247,11 @@ test('PluginContainer can render Sandy plugins for archived devices', async () =
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"
@@ -1325,11 +1325,11 @@ test('PluginContainer can render Sandy plugins for archived devices', async () =
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"

View File

@@ -65,11 +65,11 @@ test('Triggering a deeplink will work', async () => {
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"

View File

@@ -14,7 +14,7 @@ import {State as Store} from '../reducers';
import {flush} from '../utils/persistor';
import ToggledSection from './settings/ToggledSection';
import {isEqual} from 'lodash';
import {reportUsage, Settings} from 'flipper-common';
import {Platform, reportUsage, Settings} from 'flipper-common';
import {Modal, Button} from 'antd';
import {Layout, withTrackingScope, _NuxManagerContext} from 'flipper-plugin';
import {getRenderHostInstance} from '../RenderHost';
@@ -23,7 +23,7 @@ const WIZARD_FINISHED_LOCAL_STORAGE_KEY = 'platformSelectWizardFinished';
type OwnProps = {
onHide: () => void;
platform: NodeJS.Platform;
platform: Platform;
};
type StateFromProps = {

View File

@@ -22,7 +22,12 @@ import {FilePathConfigField, ConfigText} from './settings/configFields';
import KeyboardShortcutInput from './settings/KeyboardShortcutInput';
import {isEqual, isMatch, isEmpty} from 'lodash';
import LauncherSettingsPanel from '../fb-stubs/LauncherSettingsPanel';
import {LauncherSettings, reportUsage, Settings} from 'flipper-common';
import {
LauncherSettings,
Platform,
reportUsage,
Settings,
} from 'flipper-common';
import {Modal, message, Button} from 'antd';
import {Layout, withTrackingScope, _NuxManagerContext} from 'flipper-plugin';
import {getRenderHostInstance} from '../RenderHost';
@@ -30,7 +35,7 @@ import {loadTheme} from '../utils/loadTheme';
type OwnProps = {
onHide: () => void;
platform: NodeJS.Platform;
platform: Platform;
noModal?: boolean; // used for testing
};

View File

@@ -2,7 +2,7 @@
exports[`ShareSheetPendingDialog is rendered with status update 1`] = `
<div
className="css-gzchr8-Container e1hsqii15"
className="css-gzchr8-Container e1k65efv0"
style={
Object {
"textAlign": "center",
@@ -51,7 +51,7 @@ exports[`ShareSheetPendingDialog is rendered with status update 1`] = `
</strong>
</span>
<div
className="css-1knrt0j-SandySplitContainer e1hsqii10"
className="css-1knrt0j-SandySplitContainer e148ues30"
>
<div />
<button
@@ -69,7 +69,7 @@ exports[`ShareSheetPendingDialog is rendered with status update 1`] = `
exports[`ShareSheetPendingDialog is rendered without status update 1`] = `
<div
className="css-gzchr8-Container e1hsqii15"
className="css-gzchr8-Container e1k65efv0"
style={
Object {
"textAlign": "center",
@@ -118,7 +118,7 @@ exports[`ShareSheetPendingDialog is rendered without status update 1`] = `
</strong>
</span>
<div
className="css-1knrt0j-SandySplitContainer e1hsqii10"
className="css-1knrt0j-SandySplitContainer e148ues30"
>
<div />
<button

View File

@@ -3,7 +3,7 @@
exports[`load PluginInstaller list 1`] = `
<div>
<div
class="css-1v0y38i-Container e1hsqii15"
class="css-1v0y38i-Container e1k65efv0"
height="500"
>
<div
@@ -166,7 +166,7 @@ exports[`load PluginInstaller list 1`] = `
width="0"
>
<div
class="css-s1wsbn-Container-Horizontal e1hsqii14"
class="css-s1wsbn-Container-Horizontal e1hsqii12"
>
<span
class="ant-typography ant-typography-ellipsis ant-typography-single-line ant-typography-ellipsis-single-line"
@@ -233,7 +233,7 @@ exports[`load PluginInstaller list 1`] = `
width="0"
>
<div
class="css-s1wsbn-Container-Horizontal e1hsqii14"
class="css-s1wsbn-Container-Horizontal e1hsqii12"
>
<span
class="ant-typography ant-typography-ellipsis ant-typography-single-line ant-typography-ellipsis-single-line"
@@ -379,7 +379,7 @@ exports[`load PluginInstaller list 1`] = `
exports[`load PluginInstaller list with one plugin installed 1`] = `
<div>
<div
class="css-1v0y38i-Container e1hsqii15"
class="css-1v0y38i-Container e1k65efv0"
height="500"
>
<div
@@ -542,7 +542,7 @@ exports[`load PluginInstaller list with one plugin installed 1`] = `
width="0"
>
<div
class="css-s1wsbn-Container-Horizontal e1hsqii14"
class="css-s1wsbn-Container-Horizontal e1hsqii12"
>
<span
class="ant-typography ant-typography-ellipsis ant-typography-single-line ant-typography-ellipsis-single-line"
@@ -609,7 +609,7 @@ exports[`load PluginInstaller list with one plugin installed 1`] = `
width="0"
>
<div
class="css-s1wsbn-Container-Horizontal e1hsqii14"
class="css-s1wsbn-Container-Horizontal e1hsqii12"
>
<span
class="ant-typography ant-typography-ellipsis ant-typography-single-line ant-typography-ellipsis-single-line"

View File

@@ -141,7 +141,7 @@ const KeyboardShortcutInput = (props: {
}, [isShortcutValid, pressedKeys, props]);
const inputRef = useRef<HTMLInputElement>(null);
let typingTimeout: NodeJS.Timeout;
let typingTimeout: any;
const handleFocusInput = () => {
if (inputRef.current !== null) {

View File

@@ -9,7 +9,6 @@
import BaseDevice from './BaseDevice';
import type {DeviceOS, DeviceType} from 'flipper-plugin';
import {DeviceShell} from './BaseDevice';
import {SupportFormRequestDetailsState} from '../reducers/supportForm';
export default class ArchivedDevice extends BaseDevice {
@@ -62,10 +61,6 @@ export default class ArchivedDevice extends BaseDevice {
supportRequestDetails?: SupportFormRequestDetailsState;
spawnShell(): DeviceShell | undefined | null {
return null;
}
getArchivedScreenshotHandle(): string | null {
return this.archivedScreenshotHandle;
}

View File

@@ -7,7 +7,6 @@
* @format
*/
import stream from 'stream';
import {
Device,
_SandyDevicePluginInstance,
@@ -28,12 +27,6 @@ import {DeviceSpec, PluginDetails} from 'flipper-common';
import {getPluginKey} from '../utils/pluginKey';
import {Base64} from 'js-base64';
export type DeviceShell = {
stdout: stream.Readable;
stderr: stream.Readable;
stdin: stream.Writable;
};
type PluginDefinition = _SandyPluginDefinition;
type PluginMap = Map<string, PluginDefinition>;

View File

@@ -113,11 +113,11 @@ test('Triggering a deeplink will work', async () => {
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"
@@ -225,11 +225,11 @@ test('triggering a deeplink without applicable device can wait for a device', as
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"
@@ -309,11 +309,11 @@ test('triggering a deeplink without applicable client can wait for a device', as
<body>
<div>
<div
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
class="css-1x2cmzz-SandySplitContainer e148ues30"
>
<div />
<div
class="css-1knrt0j-SandySplitContainer e1hsqii10"
class="css-1knrt0j-SandySplitContainer e148ues30"
>
<div
class="css-1woty6b-Container"

View File

@@ -48,17 +48,20 @@ import isPluginVersionMoreRecent from '../utils/isPluginVersionMoreRecent';
import {createSandyPluginWrapper} from '../utils/createSandyPluginWrapper';
import {getRenderHostInstance} from '../RenderHost';
import pMap from 'p-map';
import * as deprecatedExports from '../deprecated-exports';
let defaultPluginsIndex: any = null;
export default async (store: Store, _logger: Logger) => {
// expose Flipper and exact globally for dynamically loaded plugins
const globalObject: any = typeof window === 'undefined' ? global : window;
const globalObject = (function (this: any) {
return this;
})();
// this list should match `replace-flipper-requires.tsx` and the `builtInModules` in `desktop/.eslintrc`
globalObject.React = React;
globalObject.ReactDOM = ReactDOM;
globalObject.Flipper = require('../deprecated-exports');
globalObject.Flipper = deprecatedExports;
globalObject.FlipperPlugin = FlipperPluginSDK;
globalObject.Immer = Immer;
globalObject.antd = antd;

View File

@@ -20,6 +20,7 @@ import {logPlatformSuccessRate} from 'flipper-common';
export const SUPPORT_FORM_PREFIX = 'support-form-v2';
import {getExportablePlugins} from '../selectors/connections';
import {DeviceOS} from 'flipper-plugin';
import SupportRequestFormV2 from '../fb-stubs/SupportRequestFormV2';
const {DEFAULT_SUPPORT_GROUP} = constants;
@@ -113,9 +114,7 @@ export class Group {
source: 'deeplink',
group: this.name,
});
store.dispatch(
setStaticView(require('../fb-stubs/SupportRequestFormV2').default),
);
store.dispatch(setStaticView(SupportRequestFormV2));
const selectedAppId = store.getState().connections.selectedAppId;
const selectedClient = store
.getState()

View File

@@ -178,7 +178,8 @@ export default function Tabs(props: {
classic?: boolean;
}) {
let tabsContainer = useContext(TabsContext);
const scope = useContext((global as any).FlipperTrackingScopeContext);
// @ts-ignore
const scope = useContext(global.FlipperTrackingScopeContext);
if (props.classic === true) {
tabsContainer = false;
}

View File

@@ -128,7 +128,7 @@ export const TooltipContext = createContext<TooltipManager>(undefined as any);
const TooltipProvider: React.FC<{}> = memo(function TooltipProvider({
children,
}) {
const timeoutID = useRef<NodeJS.Timeout>();
const timeoutID = useRef<any>();
const [tooltip, setTooltip] = useState<TooltipObject | undefined>(undefined);
const tooltipManager = useMemo(
() => ({

View File

@@ -38,6 +38,7 @@ import ShareSheetExportFile from '../chrome/ShareSheetExportFile';
import ExportDataPluginSheet from '../chrome/ExportDataPluginSheet';
import {getRenderHostInstance} from '../RenderHost';
import {uploadFlipperMedia} from '../fb-stubs/user';
import SupportRequestDetails from '../fb-stubs/SupportRequestDetails';
export const IMPORT_FLIPPER_TRACE_EVENT = 'import-flipper-trace';
export const EXPORT_FLIPPER_TRACE_EVENT = 'export-flipper-trace';
@@ -580,7 +581,7 @@ export function importDataToStore(source: string, data: string, store: Store) {
if (supportRequestDetails) {
store.dispatch(
// Late require to avoid circular dependency issue
setStaticView(require('../fb-stubs/SupportRequestDetails').default),
setStaticView(SupportRequestDetails),
);
}
}

View File

@@ -41,7 +41,7 @@ export function sideEffect<
let scheduled = false;
let lastRun = -1;
let lastSelectedValue: V = selector(store.getState());
let timeout: NodeJS.Timeout;
let timeout: any;
function run() {
scheduled = false;

View File

@@ -5,7 +5,8 @@
"rootDir": "src",
"esModuleInterop": true,
"emitDeclarationOnly": true,
"lib": ["dom"]
"lib": ["dom", "es2019"],
"types": ["../types/ReactDebounceRender"]
},
"references": [
{