Commit Graph

16 Commits

Author SHA1 Message Date
Alex Hunt
e7591b2a81 Set clearLogs accelerator for log-rendering plugins
Summary:
Sets a default key binding of `ctrl+l` to clear the screen within built-in Flipper plugins which display a log view.

Motivation: A small quality of life improvement for developers used to the default "clear screen" binding. This makes our log-rendering plugins consistent with other native apps such as terminals, Chrome DevTools, and many others.

Reviewed By: mweststrate

Differential Revision: D37782638

fbshipit-source-id: 0a85b930faaa0e9468d5391f15092aad7b6057ee
2022-07-13 01:38:55 -07:00
almouro
3eb53f5987 Fix desktop template tests (#3327)
Summary:
When creating a brand new Flipper desktop plugin, the tests don't pass

### To Reproduce

```
npx flipper-pkg init
cd flipper-plugin-new
yarn jest
```

The test are not passing.
It would seem that we have 2 issues since this commit: e46fcba0b2 (diff-26467a831e67f87a2bd99be5b62a71a6e3e4e7f86135c11ccede9a02e58c44feR48)

#### 1. `electronRequire` is not defined

![image](https://user-images.githubusercontent.com/4534323/150385278-29527a4d-4783-4902-aeea-986b3c634a29.png)

Adding:
```ts
// ts-ignore
global.electronRequire = require;
```
fixes the issue of course like [here](e46fcba0b2 (diff-a283d77d8667b28aec5319fe5671a91489485a683898efedf9441b816c84a447R15)) but might not be very ideal
When fixing this, we hit a second issue:

#### 2. Hooks cannot be defined inside tests

![image](https://user-images.githubusercontent.com/4534323/150385722-c0604cfc-33ef-4d8e-a8fd-d60042a87699.png)

This is because we now require `testing-library/react` on the fly: e46fcba0b2 (diff-26467a831e67f87a2bd99be5b62a71a6e3e4e7f86135c11ccede9a02e58c44feR198)
which will run `afterEach` if defined: 071a6fdc1d/src/index.js (L12)

A non ideal fix is to require `require("testing-library/react");` before running the test

## Changelog

Fix: ensure desktop plugin template tests run

Pull Request resolved: https://github.com/facebook/flipper/pull/3327

Test Plan:
I've cloned the repo and run:

```
cd flipper/desktop/pkg
yarn
cd ../../..
./flipper/desktop/pkg/bin/run init
```
I run the tests on the newly package created and they're now good

![image](https://user-images.githubusercontent.com/4534323/150391527-d834ec5b-57d8-4948-b9f3-17ade4eda79b.png)

## Side note

The fixes are not great, if you guys have better ones to suggest, really addressing the root cause of the issue, I'll happily close the PR

Also it's so easy to test desktop plugins with the awesome work you've done �, it'd be sad if the community could not totally benefit from it.
Since I had this issue before (https://github.com/facebook/flipper/pull/3039), I'd be really happy to help (if given some directions 🙏) set up a test to ensure a plugin generated is always well set up.

Reviewed By: passy

Differential Revision: D33713611

Pulled By: aigoncharov

fbshipit-source-id: 43834b30f24c2549d80923d2194487b9f9e6a1ae
2022-01-21 13:37:37 -08:00
almouro
5b603ab976 Ensure desktop plugin template tests run (#3039)
Summary:
I've decided to migrate [a desktop plugin](https://github.com/bamlab/react-native-performance) to Sandy.
When doing so, I decided to rise to the challenge from the [Flipper docs](https://fbflipper.com/docs/tutorial/js-custom#testing-plugin-logic):  `we are going to pretend that we always write unit tests first` 😅

However, I've realized that when creating a plugin with `npx flipper-pkg init`, running `yarn jest` directly after creation actually fails.

There are 3 issues solved in the different commits:
1. an absolute import seem to not be resolved, since all the other imports were relative in the file, I changed it as well

2. some dependencies are missing.
They used to be included in the `flipper` dependency but when migrating to use `flipper-plugin` instead, they're not present anymore.
I don't think this is an ideal fix, I would believe a dependency like a `flipper-dev-environment` including all of those would be more appropriate. So I'm open to suggestions to fix/remove of course

3. jest.config needs to be fixed to run in jsdom environment and ensure we can test the react component

## Changelog

Fix: ensure desktop plugin template tests run

Pull Request resolved: https://github.com/facebook/flipper/pull/3039

Test Plan:
I've cloned the repo and run:

```
cd flipper/desktop/pkg
yarn
cd ../../..
./flipper/desktop/pkg/bin/run init
```
I run the tests on the newly package created, but it actually still failed because of the first issue (since it still installed `flipper-plugin` from npm`)

However, by adding this patch, it now runs!
```patch
 diff --git a/node_modules/flipper-plugin/lib/ui/data-table/DataTable.js b/node_modules/flipper-plugin/lib/ui/data-table/DataTable.js
index 2e07ff5..ff3181d 100644
 --- a/node_modules/flipper-plugin/lib/ui/data-table/DataTable.js
+++ b/node_modules/flipper-plugin/lib/ui/data-table/DataTable.js
@@ -39,7 +39,7 @@ const useAssertStableRef_1 = require("../../utils/useAssertStableRef");
 const PluginContext_1 = require("../../plugin/PluginContext");
 const lodash_1 = require("lodash");
 const useInUnitTest_1 = require("../../utils/useInUnitTest");
-const createDataSource_1 = require("flipper-plugin/src/state/createDataSource");
+const createDataSource_1 = require("../../state/createDataSource");
 function DataTable(props) {
     var _a, _b;
     const { onRowStyle, onSelect, onCopyRows, onContextMenu } = props;
```

Reviewed By: aigoncharov

Differential Revision: D32358207

Pulled By: mweststrate

fbshipit-source-id: 7761b4150c24dd5379a24c3c1deeb78bf3dda4ee
2021-11-11 12:07:49 -08:00
Michel Weststrate
f7732ed4fd Insert a proper flipper-plugin version
Summary:
`flipper-pkg init` would always introduce `flipper-plugin` peer with version `latest`. Since that can never be checked against the current flipper version, it always generated a warning. Updated the init process to take the version the plugin was generated with as base version instead.

Note that in the test the version will always display as 0.0.0, will double check after release that the proper version will show up when running from npx, but don't see a reason why not (famous last words)

Reviewed By: nikoant, priteshrnandgaonkar

Differential Revision: D28992531

fbshipit-source-id: c32aad1650f575f790c2e04d089104b7a616d26f
2021-06-10 04:45:18 -07:00
Anton Nikolaev
68248a7c63 Device plugin management (4/n): Allow choosing "device" plugin type in "flipper-pkg init"
Summary:
Added option to bootstrap device plugin in "flipper-pkg".

Changelog: "flipper-pkg init" can now be used to bootstrap device plugins

Reviewed By: mweststrate

Differential Revision: D26389429

fbshipit-source-id: 90773011bd50289004cd747111e1787402840922
2021-02-16 10:50:19 -08:00
Michel Weststrate
2f15ef883d Improve OSS plugin template
Summary:
Based https://github.com/facebook/flipper/issues/1866 and running `npx flipper-plugin init` locally. Doesn't address the original issue

Fixes #1866

Reviewed By: passy

Differential Revision: D26147089

fbshipit-source-id: 608dc92c5ccc741b6e760ea5a5034f9444e951b7
2021-02-01 02:28:34 -08:00
Michel Weststrate
cc438e60ad Update public docs to use Sandy
Summary: This updates the docs of Flipper to use Sandy, rather than `FlipperPlugin` class. Restructured the docs a bit as a result.

Reviewed By: passy

Differential Revision: D24991285

fbshipit-source-id: 66d5760c25cf9cf3983515433dfd64348d51db3d
2020-11-16 13:10:32 -08:00
Michel Weststrate
dc82ec2885 flipper-pkg template will now use sandy
Summary:
This diff updates plugin scaffolding by using Sandy and closely following the internal Scarf templates (see D24949452, D24949452)

By using `flipper-plugin`, it is now also possible to write unit tests for a plugin, and the default infra for that is generated (babel / jest)

For now there is still a dependency on `flipper` to support fancy components not yet available in Sandy, this will be updated in the future: T79632585

Changelog: `flipper-pkg init` now uses the new Sandy plugin infrastructure ant Ant.design component system

Reviewed By: nikoant

Differential Revision: D24950080

fbshipit-source-id: afc5e7ac728b20cb84fdbbdcb76cd45968736c01
2020-11-16 13:10:32 -08:00
Michel Weststrate
49b4022228 added tests for generated template files
Summary:
Created a test that snapshots the generated files, so that we can capture accidental regressions when generating files.

Also made the package id to package name a bit more robust

Reviewed By: jknoxville

Differential Revision: D21619633

fbshipit-source-id: 88ffb127e050d840df9ccd4b15ba29a71f341975
2020-05-19 05:33:35 -07:00
Michel Weststrate
080085e788 added simple watch mode
Summary:
Added a watch mode to the bundle command of flipper plugins. This makes it easy to test develop plugins locally, even when you are using a production build of flipper, which lowers the barrier of developing / fixing plugins.

opted for `fs.watch` over watchman to avoid some overengineering:
1. pkg / pkg-lib don't have the watchman utilities that would be needed for this. I wasn't sure if I could move those over from `static` without breaking the bootstrapping process
2. watchman is often a nuisance on non FB machines that aren't set up for it. fs.watch in contrast doesn't have any further dependencies or setup requirements, and is much more likely to work ootb.
3. since we watch only the `src` folder we don't really need the watchman optimizations. (so for a package.json change people would have to restart, but I don't think that is much of a problem).

Reviewed By: jknoxville

Differential Revision: D21523814

fbshipit-source-id: b1de72b7d01c6fc50cb8ce5709f54f8019eb89e4
2020-05-19 05:33:34 -07:00
Michel Weststrate
1e309abe4f add react types to template
Summary: See previous diff, should have merged those two diffs

Reviewed By: jknoxville

Differential Revision: D21523815

fbshipit-source-id: 3db91d06d845f0764e28f0dbf3020e77812cde53
2020-05-19 05:33:34 -07:00
Michel Weststrate
8d6ad59c52 add tsconfig to template
Summary: When opening a freshly generated plugin in VScode the IDE would be full of errors, even though it can bundle correctly thanks to the defaults used by bundle. This  is fixed by diff by correctly setting up a tsconfig.

Reviewed By: jknoxville

Differential Revision: D21523817

fbshipit-source-id: 8f6b58fbfb704460ddb5b845ddfb137b28d37187
2020-05-19 05:33:33 -07:00
Michel Weststrate
47f72e3332 add build command by default
Summary: By adding a build command the flipper plugin can be picked up, even when using a production build of Flipper, as we don't require Flipper's own infrastructure anymore to compile plugins.

Reviewed By: jknoxville

Differential Revision: D21523819

fbshipit-source-id: eed935ee95a7e3bff2ace629836b4b2450b5d1ad
2020-05-19 05:33:33 -07:00
Michel Weststrate
310a76d03f Improve standard view template
Summary:
As soon as any data was send to a freshly generated plugin, the plugin would crash as React doesn't support directly rendering data. Replaced it with a poor mans rendering that simply dumps all the data we received.

Also made sure the view is scrollable now which wasn't the case before.

Reviewed By: jknoxville

Differential Revision: D21523816

fbshipit-source-id: 3e04799facdf8b66ce9d66217a47fc7826d58d43
2020-05-19 05:33:33 -07:00
Michel Weststrate
7536c0e930 Add default .gitignore file
Summary:
This stack contains a bunch of improvements I made to smoothen the demo of plugin creating in the Flipper + React Native talk.

With 98% likelihood people will manage the source code of their Flipper plugins in git. This will make sure the `.gitignore` is configured properly ootb

Reviewed By: nikoant

Differential Revision: D21523818

fbshipit-source-id: b2ed769edc8fb9fd320464b05686e817e438f21e
2020-05-19 05:33:32 -07:00
Anton Nikolaev
d08dfee018 "init" command for flipper-pkg tool
Summary: Added command "init" to "flipper-pkg" which helps to quickly initialise Flipper desktop plugin.

Reviewed By: passy

Differential Revision: D21253819

fbshipit-source-id: 85a2fbde07ecb63737d180d2a7e5cc2846b4f533
2020-04-27 17:34:12 -07:00