Commit Graph

20 Commits

Author SHA1 Message Date
Andrey Goncharov
8716761cb3 Fix require monkey-patching in electron build
Summary:
In D39311893 (094c5bdfdd) we started monkey-patching `require` to resolve global dependencies in the plugins. Apparently, patching `globalThis.require` did not work in the electron env. On my local machine it kept working because I had the experimental `flipper-server` feature enabled which embeds flipper-server into the electron build. In flipper-server we properly patch `require` via `Module.prototype.require` which affected the global require in electron.
With this fix we now properly patch require in electron via Module.prototype.require all the time

Changelog: Fix plugin loading with experimental flipper-server disabled

Reviewed By: nikoant

Differential Revision: D39633821

fbshipit-source-id: 9554f643c625620d116075ae87f573d8447850f6
2022-09-20 01:36:56 -07:00
Andrey Goncharov
ed93dfe978 Refine prod and dev deps
Summary: Move flipper local deps to prod deps, so yarn installs them later when we build a bundle

Reviewed By: lblasa

Differential Revision: D39475545

fbshipit-source-id: 5b61d15b45ee315c3b35d8e6836c114b90503b1a
2022-09-15 10:02:19 -07:00
Andrey Goncharov
094c5bdfdd Provide external modules to plugins
Summary: esbuild references external modules via `require`. We wrap `require` to point the references to built-in modules to global variables

Reviewed By: lblasa

Differential Revision: D39311893

fbshipit-source-id: a99480161c082f4095d78c22271f114532f32c16
2022-09-15 10:02:19 -07:00
Andrey Goncharov
650ff4bcfb Remove plugin bundling
Summary: Remove the notion of bundled plugins

Reviewed By: lblasa

Differential Revision: D39308888

fbshipit-source-id: aa88ddbf2801ad1da95f89e4c761259b697b0d66
2022-09-15 10:02:19 -07:00
Andrey Goncharov
642a3ebf81 Remove default plugin entrypoints for hot-reloading
Summary: As we stopped bundling plugins in D39276249, we no longer need the entry points for the bundled plugins (these entry points are always going to be empty)

Reviewed By: lblasa

Differential Revision: D39307565

fbshipit-source-id: 43751fe31c8bd962677c226b27cfe52093d3f2d4
2022-09-15 10:02:19 -07:00
Andrey Goncharov
a888e6affa Simplify bundled plugin setup
Summary: Stop bundling plugins into Flipper Server bundles. In later diffs, we will start building all plugins even in dev mode which removes the need to bundle them.

Reviewed By: lblasa

Differential Revision: D39276249

fbshipit-source-id: 091405cfcf58aa7e1bd2b382da40f8d9841ae6b1
2022-09-15 10:02:19 -07:00
Andrey Goncharov
a67a4e5d0f Remove babel transforms for flipper-server
Summary: Flipper server itself requires no babel transforms. We applied extra transforms only for the bundled plugins. However, we pack and ship all plugins in the /static folder. They are always available on the FS. Therefore we could stop bundling any plugins into flipper-server's source code.

Reviewed By: lblasa

Differential Revision: D38910251

fbshipit-source-id: b3e9fe5ae2ab69ce5579b01b6793ebf7e88baf66
2022-09-15 10:02:19 -07:00
Andrey Goncharov
97b8b8a1c4 Split flipper-plugin package
Summary:
flipper-server-companion depends on flipper-plugin. flipper-plugin includes dependencies that run only in a browser. Splitting flipper-plugin into core and browser packages helps to avoid including browser-only dependencies into flipper-server bundle.
As a result, bundle size could be cut in half. Subsequently, RSS usage drops as there is twice as less code to process for V8.

Note: it currently breaks external flipper-data-source package. It will be restored in subsequent diffs

Reviewed By: lblasa

Differential Revision: D38658285

fbshipit-source-id: 751b11fa9f3a2d938ce166687b8310ba8b059dee
2022-09-15 10:02:19 -07:00
Lorenzo Blasa
c01df31459 Handle disconnection events whilst executing requests
Summary:
If there's a device client disconnect during request execution, no response is ever given back to the client (flipperd).

This change effectively subscribes to client disconnect events and notifies flipperd of any disconnection during request processing.

Reviewed By: passy

Differential Revision: D37787986

fbshipit-source-id: 31737a50b83b0cbe4141ce814064aebef7e09bfc
2022-07-12 12:55:19 -07:00
Lorenzo Blasa
18854ce5fc Install plugin from marketplace if not available
Summary: For the Flipper Server Companion, if a plugin is being requested which is not yet installed, try to install it first from the marketplace.

Reviewed By: passy

Differential Revision: D37716962

fbshipit-source-id: d618fbc597f82b540dbb02e8ffc296dcee9e1eb9
2022-07-11 07:04:55 -07:00
Lorenzo Blasa
1778ce4f46 HeadlessPluginInitialiser install plugin
Summary:
Allow adding plugins after initialisation. Effectively:
- Load the plugin creates the SandyPluginDefinition
- Add the definition to the existing loaded plugins

Reviewed By: passy

Differential Revision: D37749811

fbshipit-source-id: ea834b9e6105cf605fc906a794022f61807ce1d8
2022-07-11 07:04:55 -07:00
Andrey Goncharov
692b861ee4 Increase verbosity of flipper server companion logging
Summary: Log Flipper server companion requests and replies

Reviewed By: passy

Differential Revision: D37456027

fbshipit-source-id: 59ce3219b1f278237f1285e032272facdcf930e8
2022-06-27 08:13:01 -07:00
Andrey Goncharov
4f9ceb2e22 Implement subscribing to data updates for Flipper Server Companion
Summary: Allow subscribing to state updates from the plugin in headless mode

Reviewed By: passy

Differential Revision: D36516754

fbshipit-source-id: 14db51243e1d91332a7327c1792412149339f907
2022-05-23 03:38:23 -07:00
Andrey Goncharov
1f2f799772 Setup globals and initialize flipper-server-companion
Summary:
We want Flipper plugins to share imports with Flipper:
- They must share the same React otherwise different Reacts could conflict with each other
- Other common modules are shared to decrease the bundle size for each plugin.

`setGlobalObject` provides shared modules to Flipper Plugins by adding them to the global context (window or process or global this).

In the headless context, we do not have React and other DOM-related libraries, so we provide stubs instead.

Reviewed By: passy

Differential Revision: D36130161

fbshipit-source-id: d30c59a6c3ae02e7f9244bc0bb5790079b771107
2022-05-10 05:13:24 -07:00
Andrey Goncharov
c1dc1788a5 Initialize flipper lib and render host in headless mode
Reviewed By: mweststrate

Differential Revision: D36130158

fbshipit-source-id: cfdd22456bd4674e027dbcf83e67bf52cd757cf7
2022-05-10 05:13:24 -07:00
Andrey Goncharov
98dde53cda Add companion logging
Summary: Add top-level error logging to flipper-server. Use the top-level logging mechanism in flipper-companion.

Reviewed By: lblasa

Differential Revision: D36252218

fbshipit-source-id: 58d22b3b9bd51e597b5250478640f54d10277861
2022-05-10 05:13:24 -07:00
Andrey Goncharov
e218b79de2 Implement companion
Summary: Add Flipper Server Companion implementation. It extends the list of commands handled by Flipper Server by adding commands to interact with device or app Flipper plugins.

Reviewed By: mweststrate

Differential Revision: D36130159

fbshipit-source-id: 2eb6ba0fbae0fa850eadb7d417aa476240994bd5
2022-05-10 05:13:24 -07:00
Andrey Goncharov
ecb92c195c Implement HeadlessPluginInitializer
Reviewed By: lblasa

Differential Revision: D36130160

fbshipit-source-id: 6edff1c54bf5bf8cb85387bc2877788f947f97a6
2022-05-10 05:13:24 -07:00
Andrey Goncharov
deaf2359b1 Implement HeadlessClient
Reviewed By: lblasa

Differential Revision: D36130082

fbshipit-source-id: 00f9709d9a4f245063ae428521031afe74a521d6
2022-05-10 05:13:24 -07:00
Andrey Goncharov
5d346b4991 Add flipper-server-companion
Summary: Flipper Server Companion starts headless plugins and exposes them over the wire

Reviewed By: passy

Differential Revision: D36098170

fbshipit-source-id: 3b1b077d1fa4adca5c340ad4475b80b229586e1b
2022-05-10 05:13:24 -07:00