Option for "yarn start" and "yarn build" scripts to pre-install default plugin packages instead of bundling them

Summary:
Sorry for long diff! I can try to split it if necessary, but many changes here are 1-1 replacements / renames.

**Preambule**
Currently we bundle default plugins into the Flipper main bundle. This helps us to reduce bundle size, because of plugin dependencies re-use. E.g. if multiple plugins use "lodash" when they are bundled together, only one copy of "lodash" added. When they are bundled separately, the same dependency might be added to each of them. However as we're not going to include most of plugins into Flipper distributive anymore and going to rely on Marketplace instead, this bundling doesn't provide significant size benefits anymore. In addition to that, bundling makes it impossible to differentiate whether thrown errors are originated from Flipper core or one of its plugins.

Why don't we remove plugin bundling at all? Because for "dev mode" it actually quite useful. It makes dev build start much faster and also enables using of Fast Refresh for plugin development (fast refresh won't work for plugins loaded from disk).

**Changes**
This diff introduces new option "no-bundled-plugins" for "yarn start" and "yarn build" commands. For now, by default, we will continue bundling default plugins into the Flipper main bundle, but if this option provided then we will build each default plugin separately and include their packages into the Flipper distributive as "pre-installed" to be able to load them from disk even without access to Marketplace.

For "yarn start", we're adding symlinks to plugin folders in "static/defaultPlugins" and then they are loaded by Flipper. For "yarn build" we are dereferencing these symlinks to include physical files of plugins into folder "defaultPlugins" of the produced distributive. Folder "defaultPlugins" is excluded from asar, because loading of plugins from asar archive might introduce some unexpected issues depending on their implementation.

Reviewed By: mweststrate

Differential Revision: D28431838

fbshipit-source-id: f7757e9f5ba9183ed918d70252de3ce0e823177d
This commit is contained in:
Anton Nikolaev
2021-05-18 08:06:07 -07:00
committed by Facebook GitHub Bot
parent 706b3cfca8
commit a4eb2a56d6
23 changed files with 332 additions and 206 deletions

View File

@@ -14,6 +14,7 @@ import {EOL} from 'os';
import pmap from 'p-map';
import {rootDir} from './paths';
import yargs from 'yargs';
import {isPluginJson} from 'flipper-plugin-lib';
const argv = yargs
.usage('yarn tsc-plugins [args]')
@@ -107,7 +108,7 @@ async function findAffectedPlugins(errors: string[]) {
depsByName.set(name, getDependencies(name));
}
for (const pkg of allPackages) {
if (!pkg.json?.keywords?.includes('flipper-plugin')) {
if (!isPluginJson(pkg.json)) {
continue;
}
const logFile = path.join(pkg.dir, 'tsc-error.log');