diff --git a/desktop/app/src/dispatcher/plugins.tsx b/desktop/app/src/dispatcher/plugins.tsx index 304381664..d93cef3dd 100644 --- a/desktop/app/src/dispatcher/plugins.tsx +++ b/desktop/app/src/dispatcher/plugins.tsx @@ -158,21 +158,34 @@ export const checkGK = (gatekeepedPlugins: Array) => ( return result; }; -export const checkDisabled = (disabledPlugins: Array) => ( - plugin: PluginDetails, -): boolean => { +export const checkDisabled = (disabledPlugins: Array) => { + const enabledList = process.env.FLIPPER_ENABLED_PLUGINS + ? new Set(process.env.FLIPPER_ENABLED_PLUGINS.split(',')) + : null; let disabledList: Set = new Set(); try { disabledList = config().disabledPlugins; } catch (e) { console.error(e); } - - if (disabledList.has(plugin.name)) { - disabledPlugins.push(plugin); - } - - return !disabledList.has(plugin.name); + return (plugin: PluginDetails): boolean => { + if (disabledList.has(plugin.name)) { + disabledPlugins.push(plugin); + return false; + } + if ( + enabledList && + !( + enabledList.has(plugin.name) || + enabledList.has(plugin.id) || + enabledList.has(plugin.name.replace('flipper-plugin-', '')) + ) + ) { + disabledPlugins.push(plugin); + return false; + } + return true; + }; }; export const createRequirePluginFunction = ( diff --git a/desktop/package.json b/desktop/package.json index 1a1eb3397..b66eb95d9 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -224,7 +224,7 @@ "ts-node": "^8.8.1", "typescript": "^4.0.3", "uuid": "^8.3.0", - "yargs": "^15.4.1", + "yargs": "^16.1.0", "yazl": "^2.5.1" }, "scripts": { @@ -251,6 +251,7 @@ "build:dev": "cross-env NODE_ENV=development ./ts-node scripts/build-release.ts $@", "prebuild-headless": "yarn build:pkg", "build-headless": "cross-env NODE_ENV=production ./ts-node scripts/build-headless.ts $@", + "build-headless:dev": "cross-env NODE_ENV=development ./ts-node scripts/build-headless.ts $@", "build-plugin": "./ts-node scripts/build-plugin.ts", "resolve-plugin-dir": "./ts-node scripts/resolve-plugin-dir.ts", "list-plugins": "./ts-node scripts/list-plugins.ts", diff --git a/desktop/plugin-lib/src/getSourcePlugins.ts b/desktop/plugin-lib/src/getSourcePlugins.ts index 2daf105ba..d925cf2cd 100644 --- a/desktop/plugin-lib/src/getSourcePlugins.ts +++ b/desktop/plugin-lib/src/getSourcePlugins.ts @@ -29,7 +29,21 @@ export async function getSourcePlugins(): Promise { entryPoints[key] = p[key]; }); } - return Object.values(entryPoints); + const allPlugins = Object.values(entryPoints); + if (process.env.FLIPPER_ENABLED_PLUGINS) { + const pluginNames = new Set( + process.env.FLIPPER_ENABLED_PLUGINS.split(',').map((x) => + x.toLowerCase(), + ), + ); + return allPlugins.filter( + (x) => + pluginNames.has(x.name) || + pluginNames.has(x.id) || + pluginNames.has(x.name.replace('flipper-plugin-', '')), + ); + } + return allPlugins; } async function entryPointForPluginFolder( pluginsDir: string, diff --git a/desktop/scripts/start-dev-server.ts b/desktop/scripts/start-dev-server.ts index a41f4bd94..b24b19c60 100644 --- a/desktop/scripts/start-dev-server.ts +++ b/desktop/scripts/start-dev-server.ts @@ -29,6 +29,46 @@ import getAppWatchFolders from './get-app-watch-folders'; import {getPluginSourceFolders} from 'flipper-plugin-lib'; import ensurePluginFoldersWatchable from './ensurePluginFoldersWatchable'; import startWatchPlugins from './startWatchPlugins'; +import yargs from 'yargs'; + +const argv = yargs + .usage('yarn start [args]') + .options({ + 'embedded-plugins': { + describe: + 'Enables embedding of plugins into Flipper bundle. If it disabled then only installed plugins are loaded. The flag is enabled by default. Env var FLIPPER_NO_EMBEDDED_PLUGINS is equivalent to the command-line option "--no-embedded-plugins".', + type: 'boolean', + }, + 'fast-refresh': { + describe: + 'Enable Fast Refresh - quick reload of UI component changes without restarting Flipper. The flag is disabled by default. Env var FLIPPER_FAST_REFRESH is equivalent to the command-line option "--fast-refresh".', + type: 'boolean', + }, + 'plugin-auto-update': { + describe: + '[FB-internal only] Enable plugin auto-updates. The flag is disabled by default in dev mode. Env var FLIPPER_NO_PLUGIN_AUTO_UPDATE is equivalent to the command-line option "--no-plugin-auto-update"', + type: 'boolean', + }, + 'enabled-plugins': { + describe: + 'Load only specified plugins and skip loading rest. This is useful when you are developing only one or few plugins. Plugins to load can be specified as a comma-separated list with either plugin id or name used as identifier, e.g. "--enabled-plugins network,inspector". The flag is not provided by default which means that all plugins loaded.', + type: 'array', + }, + 'open-dev-tools': { + describe: + 'Open Dev Tools window on startup. The flag is disabled by default. Env var FLIPPER_OPEN_DEV_TOOLS is equivalent to the command-line option "--open-dev-tools".', + type: 'boolean', + }, + 'dev-server-port': { + describe: + 'Dev server port. 3000 by default. Env var "PORT=3001" is equivalent to the command-line option "--dev-server-port 3001".', + default: 3000, + type: 'number', + }, + }) + .version('DEV') + .help() + .parse(process.argv.slice(1)); const ansiToHtmlConverter = new AnsiToHtmlConverter(); @@ -36,21 +76,34 @@ const DEFAULT_PORT = (process.env.PORT || 3000) as number; let shutdownElectron: (() => void) | undefined = undefined; -if (isFB && process.env.FLIPPER_FB === undefined) { +if (isFB) { process.env.FLIPPER_FB = 'true'; } -if (process.argv.includes('--no-embedded-plugins')) { + +if (argv['embedded-plugins'] === true) { + delete process.env.FLIPPER_NO_EMBEDDED_PLUGINS; +} else if (argv['embedded-plugins'] === false) { process.env.FLIPPER_NO_EMBEDDED_PLUGINS = 'true'; } -if (process.argv.includes('--fast-refresh')) { + +if (argv['fast-refresh'] === true) { process.env.FLIPPER_FAST_REFRESH = 'true'; +} else if (argv['fast-refresh'] === false) { + delete process.env.FLIPPER_FAST_REFRESH; } + // By default plugin auto-update is disabled in dev mode, // but it is possible to enable it using this command line argument. -if (!process.argv.includes('--plugin-auto-update')) { +if (argv['plugin-auto-update'] === true) { + delete process.env.FLIPPER_DISABLE_PLUGIN_AUTO_UPDATE; +} else { process.env.FLIPPER_DISABLE_PLUGIN_AUTO_UPDATE = 'true'; } +if (argv['enabled-plugins'] !== undefined) { + process.env.FLIPPER_ENABLED_PLUGINS = argv['enabled-plugins'].join(','); +} + function looksLikeDevServer(): boolean { const hn = hostname(); if (/^devvm.*\.facebook\.com$/.test(hn)) { diff --git a/desktop/static/package.json b/desktop/static/package.json index 702f36f67..8e6f2505c 100644 --- a/desktop/static/package.json +++ b/desktop/static/package.json @@ -12,6 +12,6 @@ "node-fetch": "^2.6.1", "ws": "^7.3.0", "xdg-basedir": "^4.0.0", - "yargs": "^15.4.1" + "yargs": "^16.1.0" } } diff --git a/desktop/yarn.lock b/desktop/yarn.lock index d3c0c901c..54d62bae6 100644 --- a/desktop/yarn.lock +++ b/desktop/yarn.lock @@ -4050,6 +4050,15 @@ cliui@^6.0.0: strip-ansi "^6.0.0" wrap-ansi "^6.2.0" +cliui@^7.0.2: + version "7.0.3" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.3.tgz#ef180f26c8d9bff3927ee52428bfec2090427981" + integrity sha512-Gj3QHTkVMPKqwP3f7B4KPkBZRMR9r4rfi5bXFpg1a+Svvj8l7q5CnkBkVQzfxT5DFSsGk2+PascOgL0JYkL2kw== + dependencies: + string-width "^4.2.0" + strip-ansi "^6.0.0" + wrap-ansi "^7.0.0" + clone-deep@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/clone-deep/-/clone-deep-4.0.1.tgz#c19fd9bdbbf85942b4fd979c84dcf7d5f07c2387" @@ -5310,7 +5319,7 @@ es6-error@^4.1.1: resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.1.1.tgz#9e3af407459deed47e9a91f9b885a84eb05c561d" integrity sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg== -escalade@^3.1.0: +escalade@^3.1.0, escalade@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" integrity sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw== @@ -6272,7 +6281,7 @@ gensync@^1.0.0-beta.1: resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.1.tgz#58f4361ff987e5ff6e1e7a210827aa371eaac269" integrity sha512-r8EC6NO1sngH/zdD9fiRDLdcgnbayXah+mLgManTaIZJqEC1MZstmnox8KpnI2/fxQwrp5OpCOYWLp4rBl4Jcg== -get-caller-file@^2.0.1: +get-caller-file@^2.0.1, get-caller-file@^2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== @@ -13138,6 +13147,15 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" @@ -13236,6 +13254,11 @@ y18n@^4.0.0: resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b" integrity sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w== +y18n@^5.0.2: + version "5.0.4" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.4.tgz#0ab2db89dd5873b5ec4682d8e703e833373ea897" + integrity sha512-deLOfD+RvFgrpAmSZgfGdWYE+OKyHcVHaRQ7NphG/63scpRvTHHeQMAxGGvaLVGJ+HYVcCXlzcTK0ZehFf+eHQ== + yaku@^0.16.6: version "0.16.7" resolved "https://registry.yarnpkg.com/yaku/-/yaku-0.16.7.tgz#1d195c78aa9b5bf8479c895b9504fd4f0847984e" @@ -13269,6 +13292,11 @@ yargs-parser@^18.1.2: camelcase "^5.0.0" decamelize "^1.2.0" +yargs-parser@^20.2.2: + version "20.2.3" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.3.tgz#92419ba867b858c868acf8bae9bf74af0dd0ce26" + integrity sha512-emOFRT9WVHw03QSvN5qor9QQT9+sw5vwxfYweivSMHTcAXPefwVae2FjO7JJjj8hCE4CzPOPeFM83VwT29HCww== + yargs@^15.3.1, yargs@^15.4.1: version "15.4.1" resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.4.1.tgz#0d87a16de01aee9d8bec2bfbf74f67851730f4f8" @@ -13286,6 +13314,19 @@ yargs@^15.3.1, yargs@^15.4.1: y18n "^4.0.0" yargs-parser "^18.1.2" +yargs@^16.1.0: + version "16.1.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.1.0.tgz#fc333fe4791660eace5a894b39d42f851cd48f2a" + integrity sha512-upWFJOmDdHN0syLuESuvXDmrRcWd1QafJolHskzaw79uZa7/x53gxQKiR07W59GWY1tFhhU/Th9DrtSfpS782g== + dependencies: + cliui "^7.0.2" + escalade "^3.1.1" + get-caller-file "^2.0.5" + require-directory "^2.1.1" + string-width "^4.2.0" + y18n "^5.0.2" + yargs-parser "^20.2.2" + yauzl@^2.10.0, yauzl@^2.4.2: version "2.10.0" resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9"