Make sure that limited top-level exports are exposed from flipper-plugin
Summary: This prefixes APIs of `flipper-plugin`, that are used by Flipper, but should not be used by plugins directly, with `_`. Also added tests to make sure we are always intentional when extending the exposed APIs Reviewed By: passy Differential Revision: D24991700 fbshipit-source-id: ed3700efa188fca7f5a14d5c68250598cf011e42
This commit is contained in:
committed by
Facebook GitHub Bot
parent
cc438e60ad
commit
45db64f0d0
53
desktop/flipper-plugin/src/__tests__/api.node.tsx
Normal file
53
desktop/flipper-plugin/src/__tests__/api.node.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* 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 * as FlipperPluginModule from '../index';
|
||||
|
||||
test('Correct top level API exposed', () => {
|
||||
const exposedAPIs: string[] = [];
|
||||
const exposedTypes: string[] = [];
|
||||
Object.entries(FlipperPluginModule).forEach(([key, value]) => {
|
||||
if (key[0] === '_') {
|
||||
return;
|
||||
}
|
||||
if (value === undefined) {
|
||||
exposedTypes.push(key);
|
||||
} else {
|
||||
exposedAPIs.push(key);
|
||||
}
|
||||
});
|
||||
expect(exposedAPIs.sort()).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"Layout",
|
||||
"NUX",
|
||||
"TestUtils",
|
||||
"createState",
|
||||
"renderReactRoot",
|
||||
"theme",
|
||||
"usePlugin",
|
||||
"useValue",
|
||||
]
|
||||
`);
|
||||
expect(exposedTypes.sort()).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"Atom",
|
||||
"DefaultKeyboardAction",
|
||||
"Device",
|
||||
"DeviceLogEntry",
|
||||
"DeviceLogListener",
|
||||
"DevicePluginClient",
|
||||
"DeviceType",
|
||||
"FlipperLib",
|
||||
"LogLevel",
|
||||
"MenuEntry",
|
||||
"NormalizedMenuEntry",
|
||||
"PluginClient",
|
||||
]
|
||||
`);
|
||||
});
|
||||
@@ -10,31 +10,41 @@
|
||||
import './plugin/PluginBase';
|
||||
import * as TestUtilites from './test-utils/test-utils';
|
||||
|
||||
export {SandyPluginInstance, PluginClient} from './plugin/Plugin';
|
||||
export {
|
||||
SandyPluginInstance as _SandyPluginInstance,
|
||||
PluginClient,
|
||||
} from './plugin/Plugin';
|
||||
export {
|
||||
Device,
|
||||
DeviceLogEntry,
|
||||
DeviceLogListener,
|
||||
DevicePluginClient,
|
||||
LogLevel,
|
||||
SandyDevicePluginInstance,
|
||||
SandyDevicePluginInstance as _SandyDevicePluginInstance,
|
||||
DeviceType,
|
||||
} from './plugin/DevicePlugin';
|
||||
export {SandyPluginDefinition} from './plugin/SandyPluginDefinition';
|
||||
export {SandyPluginRenderer} from './plugin/PluginRenderer';
|
||||
export {SandyPluginContext, usePlugin} from './plugin/PluginContext';
|
||||
export {SandyPluginDefinition as _SandyPluginDefinition} from './plugin/SandyPluginDefinition';
|
||||
export {SandyPluginRenderer as _SandyPluginRenderer} from './plugin/PluginRenderer';
|
||||
export {
|
||||
SandyPluginContext as _SandyPluginContext,
|
||||
usePlugin,
|
||||
} from './plugin/PluginContext';
|
||||
export {createState, useValue, Atom} from './state/atom';
|
||||
export {FlipperLib} from './plugin/FlipperLib';
|
||||
export {
|
||||
MenuEntry,
|
||||
NormalizedMenuEntry,
|
||||
buildInMenuEntries,
|
||||
buildInMenuEntries as _buildInMenuEntries,
|
||||
DefaultKeyboardAction,
|
||||
} from './plugin/MenuEntry';
|
||||
|
||||
export {theme} from './ui/theme';
|
||||
export {Layout} from './ui/Layout';
|
||||
export {NUX, NuxManagerContext, createNuxManager} from './ui/NUX';
|
||||
export {
|
||||
NUX,
|
||||
NuxManagerContext as _NuxManagerContext,
|
||||
createNuxManager as _createNuxManager,
|
||||
} from './ui/NUX';
|
||||
|
||||
export {renderReactRoot} from './utils/renderReactRoot';
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
import React, {createContext, useCallback, useContext} from 'react';
|
||||
import {Badge, Tooltip, Typography, Button} from 'antd';
|
||||
import styled from '@emotion/styled';
|
||||
import {SandyPluginInstance, theme} from 'flipper-plugin';
|
||||
import {keyframes} from 'emotion';
|
||||
import reactElementToJSXString from 'react-element-to-jsx-string';
|
||||
import {SandyPluginContext} from '../plugin/PluginContext';
|
||||
@@ -20,6 +19,8 @@ import {Layout} from './Layout';
|
||||
import {BulbTwoTone} from '@ant-design/icons';
|
||||
import {createHash} from 'crypto';
|
||||
import type {TooltipPlacement} from 'antd/lib/tooltip';
|
||||
import {SandyPluginInstance} from '../plugin/Plugin';
|
||||
import {theme} from './theme';
|
||||
|
||||
const {Text} = Typography;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user