Include default plugins into app bundle (#998)
Summary: Pull Request resolved: https://github.com/facebook/flipper/pull/998 After this diff all the default plugins (which are distributed with Flipper) will be included into the main app bundle instead of bundling each of them separately and then loading from file system. This is done by auto-generating plugins index in build-time and importing it from Flipper app bundle, so Metro can follow these imports and bundle all the plugins to the app bundle. This provides several benefits: 1) reduced Flipper bundle size (~10% reduction of zipped Flipper archive), because Metro bundles each of re-used dependencies only once instead of bundling them for each plugin where such dependency used. 2) Faster Flipper startup because of reduced bundle and the fact that we don't need to load each plugin bundle from disk - just need to load the single bundle where everything is already included. 3) Metro dev server for plugins works in the same way as for Flipper app itself, e.g. simple refresh automatically recompiles bundled plugins too if there are changes. This also potentially should allow us to enable "fast refresh" for quicker iterations while developing plugins. 4) Faster build ("yarn build --mac" is 2 times faster on my machine after this change) Potential downsides: 1) Currently all the plugins are identically loaded from disk. After this change some of plugins will be bundled, and some of them (third-party) will be loaded from disk. 2) In future when it will be possible to publish new versions of default plugins separately, installing new version of such plugin (e.g. with some urgent fix) will mean the "default" pre-built version will still be bundled (we cannot "unbundle" it :)), but we'll skip it and instead load new version from disk. Changelog: Internals: include default plugins into the main bundle instead producing separate bundles for them. Reviewed By: passy Differential Revision: D20864002 fbshipit-source-id: 2968f3b786cdd1767d6223996090143d03894b92
This commit is contained in:
committed by
Facebook GitHub Bot
parent
cc96fc984c
commit
553c54b63e
@@ -12,3 +12,5 @@ website/build
|
|||||||
react-native/ReactNativeFlipperExample
|
react-native/ReactNativeFlipperExample
|
||||||
scripts/generate-changelog.js
|
scripts/generate-changelog.js
|
||||||
static/index.js
|
static/index.js
|
||||||
|
static/defaultPlugins/index.json
|
||||||
|
app/src/defaultPlugins/index.tsx
|
||||||
|
|||||||
2
desktop/.gitignore
vendored
2
desktop/.gitignore
vendored
@@ -1,3 +1,5 @@
|
|||||||
lib/
|
lib/
|
||||||
node_modules/
|
node_modules/
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
|
/static/defaultPlugins/index.json
|
||||||
|
/app/src/defaultPlugins/index.tsx
|
||||||
|
|||||||
10
desktop/app/src/defaultPlugins/__mocks__/index.tsx
Normal file
10
desktop/app/src/defaultPlugins/__mocks__/index.tsx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default {} as any;
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
import {FlipperPlugin} from 'flipper';
|
import {FlipperPlugin} from 'flipper';
|
||||||
|
|
||||||
export default class extends FlipperPlugin {
|
export default class extends FlipperPlugin<any, any, any> {
|
||||||
static id = 'Static ID';
|
static id = 'Static ID';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7,23 +7,28 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
jest.mock('../../defaultPlugins/index');
|
||||||
|
|
||||||
import dispatcher, {
|
import dispatcher, {
|
||||||
getDynamicPlugins,
|
getDynamicPlugins,
|
||||||
checkDisabled,
|
checkDisabled,
|
||||||
checkGK,
|
checkGK,
|
||||||
requirePlugin,
|
requirePlugin,
|
||||||
} from '../plugins.tsx';
|
} from '../plugins';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {ipcRenderer, remote} from 'electron';
|
import {ipcRenderer, remote} from 'electron';
|
||||||
import {FlipperPlugin} from 'flipper';
|
import {FlipperPlugin} from 'flipper';
|
||||||
import reducers from '../../reducers/index.tsx';
|
import reducers, {State} from '../../reducers/index';
|
||||||
import {init as initLogger} from '../../fb-stubs/Logger.tsx';
|
import {init as initLogger} from '../../fb-stubs/Logger';
|
||||||
import configureStore from 'redux-mock-store';
|
import configureStore from 'redux-mock-store';
|
||||||
import {TEST_PASSING_GK, TEST_FAILING_GK} from '../../fb-stubs/GK.tsx';
|
import {TEST_PASSING_GK, TEST_FAILING_GK} from '../../fb-stubs/GK';
|
||||||
import TestPlugin from './TestPlugin';
|
import TestPlugin from './TestPlugin';
|
||||||
import {resetConfigForTesting} from '../../utils/processConfig.tsx';
|
import {resetConfigForTesting} from '../../utils/processConfig';
|
||||||
|
import {PluginDefinition} from '../../reducers/pluginManager';
|
||||||
|
|
||||||
const mockStore = configureStore([])(reducers(undefined, {type: 'INIT'}));
|
const mockStore = configureStore<State, {}>([])(
|
||||||
|
reducers(undefined, {type: 'INIT'}),
|
||||||
|
);
|
||||||
const logger = initLogger(mockStore);
|
const logger = initLogger(mockStore);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -37,18 +42,20 @@ test('dispatcher dispatches REGISTER_PLUGINS', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('getDynamicPlugins returns empty array on errors', () => {
|
test('getDynamicPlugins returns empty array on errors', () => {
|
||||||
ipcRenderer.sendSync = jest.fn();
|
const sendSyncMock = jest.fn();
|
||||||
ipcRenderer.sendSync.mockImplementation(() => {
|
sendSyncMock.mockImplementation(() => {
|
||||||
throw new Error('ooops');
|
throw new Error('ooops');
|
||||||
});
|
});
|
||||||
|
ipcRenderer.sendSync = sendSyncMock;
|
||||||
const res = getDynamicPlugins();
|
const res = getDynamicPlugins();
|
||||||
expect(res).toEqual([]);
|
expect(res).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getDynamicPlugins from main process via ipc', () => {
|
test('getDynamicPlugins from main process via ipc', () => {
|
||||||
const plugins = [{name: 'test'}];
|
const plugins = [{name: 'test'}];
|
||||||
ipcRenderer.sendSync = jest.fn();
|
const sendSyncMock = jest.fn();
|
||||||
ipcRenderer.sendSync.mockReturnValue(plugins);
|
sendSyncMock.mockReturnValue(plugins);
|
||||||
|
ipcRenderer.sendSync = sendSyncMock;
|
||||||
const res = getDynamicPlugins();
|
const res = getDynamicPlugins();
|
||||||
expect(res).toEqual(plugins);
|
expect(res).toEqual(plugins);
|
||||||
});
|
});
|
||||||
@@ -94,7 +101,7 @@ test('checkGK for passing plugin', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('checkGK for failing plugin', () => {
|
test('checkGK for failing plugin', () => {
|
||||||
const gatekeepedPlugins = [];
|
const gatekeepedPlugins: PluginDefinition[] = [];
|
||||||
const name = 'pluginID';
|
const name = 'pluginID';
|
||||||
const plugins = checkGK(gatekeepedPlugins)({
|
const plugins = checkGK(gatekeepedPlugins)({
|
||||||
name,
|
name,
|
||||||
@@ -118,14 +125,11 @@ test('requirePlugin returns null for invalid requires', () => {
|
|||||||
|
|
||||||
test('requirePlugin loads plugin', () => {
|
test('requirePlugin loads plugin', () => {
|
||||||
const name = 'pluginID';
|
const name = 'pluginID';
|
||||||
const homepage = 'https://fb.workplace.com/groups/flippersupport/';
|
|
||||||
const requireFn = requirePlugin([], require);
|
const requireFn = requirePlugin([], require);
|
||||||
const plugin = requireFn({
|
const plugin = requireFn({
|
||||||
name,
|
name,
|
||||||
homepage,
|
out: path.join(__dirname, 'TestPlugin'),
|
||||||
out: path.join(__dirname, 'TestPlugin.js'),
|
|
||||||
});
|
});
|
||||||
expect(plugin.prototype).toBeInstanceOf(FlipperPlugin);
|
expect(plugin!.prototype).toBeInstanceOf(FlipperPlugin);
|
||||||
expect(plugin.homepage).toBe(homepage);
|
expect(plugin!.id).toBe(TestPlugin.id);
|
||||||
expect(plugin.id).toBe(TestPlugin.id);
|
|
||||||
});
|
});
|
||||||
@@ -30,6 +30,9 @@ import isProduction from '../utils/isProduction';
|
|||||||
import {notNull} from '../utils/typeUtils';
|
import {notNull} from '../utils/typeUtils';
|
||||||
import {sideEffect} from '../utils/sideEffect';
|
import {sideEffect} from '../utils/sideEffect';
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/no-unresolved
|
||||||
|
import {default as defaultPluginsIndex} from '../defaultPlugins/index';
|
||||||
|
|
||||||
export type PluginDefinition = {
|
export type PluginDefinition = {
|
||||||
id?: string;
|
id?: string;
|
||||||
name: string;
|
name: string;
|
||||||
@@ -77,31 +80,31 @@ export default (store: Store, _logger: Logger) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function getBundledPlugins(): Array<PluginDefinition> {
|
function getBundledPlugins(): Array<PluginDefinition> {
|
||||||
if (!isProduction() || process.env.FLIPPER_NO_EMBEDDED_PLUGINS) {
|
|
||||||
// Plugins are only bundled in production builds
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultPlugins that are included in the bundle.
|
// DefaultPlugins that are included in the bundle.
|
||||||
// List of defaultPlugins is written at build time
|
// List of defaultPlugins is written at build time
|
||||||
const pluginPath =
|
const pluginPath =
|
||||||
process.env.BUNDLED_PLUGIN_PATH || path.join(__dirname, 'defaultPlugins');
|
process.env.BUNDLED_PLUGIN_PATH ||
|
||||||
|
(isProduction()
|
||||||
|
? path.join(__dirname, 'defaultPlugins')
|
||||||
|
: './defaultPlugins/index.json');
|
||||||
|
|
||||||
let bundledPlugins: Array<PluginDefinition> = [];
|
let bundledPlugins: Array<PluginDefinition> = [];
|
||||||
try {
|
try {
|
||||||
bundledPlugins = global.electronRequire(
|
bundledPlugins = global.electronRequire(pluginPath);
|
||||||
path.join(pluginPath, 'index.json'),
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bundledPlugins
|
return bundledPlugins
|
||||||
.filter((plugin) => notNull(plugin.out))
|
.filter((plugin) => notNull(plugin.out))
|
||||||
.map((plugin) => ({
|
.map(
|
||||||
...plugin,
|
(plugin) =>
|
||||||
out: path.join(pluginPath, plugin.out!),
|
({
|
||||||
}));
|
...plugin,
|
||||||
|
out: path.join(pluginPath, plugin.out!),
|
||||||
|
} as PluginDefinition),
|
||||||
|
)
|
||||||
|
.concat(bundledPlugins.filter((plugin) => !plugin.out));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDynamicPlugins() {
|
export function getDynamicPlugins() {
|
||||||
@@ -152,7 +155,9 @@ export const requirePlugin = (
|
|||||||
pluginDefinition: PluginDefinition,
|
pluginDefinition: PluginDefinition,
|
||||||
): typeof FlipperPlugin | typeof FlipperDevicePlugin | null => {
|
): typeof FlipperPlugin | typeof FlipperDevicePlugin | null => {
|
||||||
try {
|
try {
|
||||||
let plugin = reqFn(pluginDefinition.out);
|
let plugin = pluginDefinition.out
|
||||||
|
? reqFn(pluginDefinition.out)
|
||||||
|
: defaultPluginsIndex[pluginDefinition.name];
|
||||||
if (plugin.default) {
|
if (plugin.default) {
|
||||||
plugin = plugin.default;
|
plugin = plugin.default;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ afterEach(() => {
|
|||||||
test('config is decoded from env', () => {
|
test('config is decoded from env', () => {
|
||||||
process.env.CONFIG = JSON.stringify({
|
process.env.CONFIG = JSON.stringify({
|
||||||
disabledPlugins: ['pluginA', 'pluginB', 'pluginC'],
|
disabledPlugins: ['pluginA', 'pluginB', 'pluginC'],
|
||||||
pluginPaths: ['/a/path', 'b/path'],
|
|
||||||
lastWindowPosition: {x: 4, y: 8, width: 15, height: 16},
|
lastWindowPosition: {x: 4, y: 8, width: 15, height: 16},
|
||||||
launcherMsg: 'wubba lubba dub dub',
|
launcherMsg: 'wubba lubba dub dub',
|
||||||
updaterEnabled: false,
|
updaterEnabled: false,
|
||||||
@@ -26,7 +25,6 @@ test('config is decoded from env', () => {
|
|||||||
|
|
||||||
expect(config()).toEqual({
|
expect(config()).toEqual({
|
||||||
disabledPlugins: new Set(['pluginA', 'pluginB', 'pluginC']),
|
disabledPlugins: new Set(['pluginA', 'pluginB', 'pluginC']),
|
||||||
pluginPaths: ['/a/path', 'b/path'],
|
|
||||||
lastWindowPosition: {x: 4, y: 8, width: 15, height: 16},
|
lastWindowPosition: {x: 4, y: 8, width: 15, height: 16},
|
||||||
launcherMsg: 'wubba lubba dub dub',
|
launcherMsg: 'wubba lubba dub dub',
|
||||||
updaterEnabled: false,
|
updaterEnabled: false,
|
||||||
@@ -40,7 +38,6 @@ test('config is decoded from env with defaults', () => {
|
|||||||
|
|
||||||
expect(config()).toEqual({
|
expect(config()).toEqual({
|
||||||
disabledPlugins: new Set([]),
|
disabledPlugins: new Set([]),
|
||||||
pluginPaths: [],
|
|
||||||
lastWindowPosition: undefined,
|
lastWindowPosition: undefined,
|
||||||
launcherMsg: undefined,
|
launcherMsg: undefined,
|
||||||
updaterEnabled: false,
|
updaterEnabled: false,
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import {remote} from 'electron';
|
|||||||
|
|
||||||
export type ProcessConfig = {
|
export type ProcessConfig = {
|
||||||
disabledPlugins: Set<string>;
|
disabledPlugins: Set<string>;
|
||||||
pluginPaths: Array<string>;
|
|
||||||
lastWindowPosition: {
|
lastWindowPosition: {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
@@ -33,7 +32,6 @@ export default function config(): ProcessConfig {
|
|||||||
);
|
);
|
||||||
configObj = {
|
configObj = {
|
||||||
disabledPlugins: new Set(json.disabledPlugins || []),
|
disabledPlugins: new Set(json.disabledPlugins || []),
|
||||||
pluginPaths: json.pluginPaths || [],
|
|
||||||
lastWindowPosition: json.lastWindowPosition,
|
lastWindowPosition: json.lastWindowPosition,
|
||||||
launcherMsg: json.launcherMsg,
|
launcherMsg: json.launcherMsg,
|
||||||
// TODO(T64836070): The built-in updater is disabled as we don't have a strategy for signing prod builds right now.
|
// TODO(T64836070): The built-in updater is disabled as we don't have a strategy for signing prod builds right now.
|
||||||
|
|||||||
@@ -28,9 +28,15 @@ export default function transform({
|
|||||||
presets = presets ?? [require('@babel/preset-react')];
|
presets = presets ?? [require('@babel/preset-react')];
|
||||||
plugins = plugins ?? [];
|
plugins = plugins ?? [];
|
||||||
const isTypeScript = filename.endsWith('.tsx') || filename.endsWith('.ts');
|
const isTypeScript = filename.endsWith('.tsx') || filename.endsWith('.ts');
|
||||||
|
const commonJs = [
|
||||||
|
require('@babel/plugin-transform-modules-commonjs'),
|
||||||
|
{
|
||||||
|
strictMode: false,
|
||||||
|
},
|
||||||
|
];
|
||||||
if (!isTypeScript) {
|
if (!isTypeScript) {
|
||||||
plugins.unshift(
|
plugins.unshift(
|
||||||
require('@babel/plugin-transform-modules-commonjs'),
|
commonJs,
|
||||||
require('@babel/plugin-proposal-object-rest-spread'),
|
require('@babel/plugin-proposal-object-rest-spread'),
|
||||||
require('@babel/plugin-proposal-class-properties'),
|
require('@babel/plugin-proposal-class-properties'),
|
||||||
require('@babel/plugin-transform-flow-strip-types'),
|
require('@babel/plugin-transform-flow-strip-types'),
|
||||||
@@ -42,7 +48,7 @@ export default function transform({
|
|||||||
plugins.unshift(
|
plugins.unshift(
|
||||||
require('@babel/plugin-transform-typescript'),
|
require('@babel/plugin-transform-typescript'),
|
||||||
require('@babel/plugin-proposal-class-properties'),
|
require('@babel/plugin-proposal-class-properties'),
|
||||||
require('@babel/plugin-transform-modules-commonjs'),
|
commonJs,
|
||||||
require('@babel/plugin-proposal-optional-chaining'),
|
require('@babel/plugin-proposal-optional-chaining'),
|
||||||
require('@babel/plugin-proposal-nullish-coalescing-operator'),
|
require('@babel/plugin-proposal-nullish-coalescing-operator'),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -189,7 +189,7 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"preinstall": "node scripts/prepare-watchman-config.js && yarn config set ignore-engines",
|
"preinstall": "node scripts/prepare-watchman-config.js && yarn config set ignore-engines",
|
||||||
"postinstall": "patch-package && ./ts-node scripts/yarn-install-fb-plugins.ts",
|
"postinstall": "patch-package && ./ts-node scripts/yarn-install-fb-plugins.ts && ./ts-node scripts/generate-plugin-entry-points.ts",
|
||||||
"rm-dist": "rimraf ../dist",
|
"rm-dist": "rimraf ../dist",
|
||||||
"rm-modules": "rimraf **/*/node_modules node_modules",
|
"rm-modules": "rimraf **/*/node_modules node_modules",
|
||||||
"rm-temp": "rimraf $TMPDIR/jest* $TMPDIR/react-native-packager*",
|
"rm-temp": "rimraf $TMPDIR/jest* $TMPDIR/react-native-packager*",
|
||||||
@@ -208,7 +208,7 @@
|
|||||||
"build:dev": "cross-env NODE_ENV=development ./ts-node scripts/build-release.ts $@",
|
"build:dev": "cross-env NODE_ENV=development ./ts-node scripts/build-release.ts $@",
|
||||||
"prebuild-headless": "yarn build:babel-transformer",
|
"prebuild-headless": "yarn build:babel-transformer",
|
||||||
"build-headless": "cross-env NODE_ENV=production ./ts-node scripts/build-headless.ts $@",
|
"build-headless": "cross-env NODE_ENV=production ./ts-node scripts/build-headless.ts $@",
|
||||||
"open-dist": "open ../dist/mac/Flipper.app --args --launcher=false",
|
"open-dist": "open ../dist/mac/Flipper.app --args --launcher=false --inspect=9229",
|
||||||
"fix": "eslint . --fix --ext .js,.ts,.tsx",
|
"fix": "eslint . --fix --ext .js,.ts,.tsx",
|
||||||
"test": "yarn build:babel-transformer && jest --env=jest-environment-jsdom-sixteen --testPathPattern=\"node\\.(js|ts|tsx)$\" --no-cache",
|
"test": "yarn build:babel-transformer && jest --env=jest-environment-jsdom-sixteen --testPathPattern=\"node\\.(js|ts|tsx)$\" --no-cache",
|
||||||
"test:debug": "yarn build:babel-transformer && node --inspect node_modules/.bin/jest --runInBand --env=jest-environment-jsdom-sixteen",
|
"test:debug": "yarn build:babel-transformer && node --inspect node_modules/.bin/jest --runInBand --env=jest-environment-jsdom-sixteen",
|
||||||
|
|||||||
@@ -15,15 +15,13 @@ const {exec: createBinary} = require('pkg');
|
|||||||
import {
|
import {
|
||||||
buildFolder,
|
buildFolder,
|
||||||
compileHeadless,
|
compileHeadless,
|
||||||
compileDefaultPlugins,
|
|
||||||
getVersionNumber,
|
getVersionNumber,
|
||||||
genMercurialRevision,
|
genMercurialRevision,
|
||||||
|
generatePluginEntryPoints,
|
||||||
} from './build-utils';
|
} from './build-utils';
|
||||||
import isFB from './isFB';
|
import isFB from './isFB';
|
||||||
import {distDir} from './paths';
|
import {distDir} from './paths';
|
||||||
|
|
||||||
const PLUGINS_FOLDER_NAME = 'plugins';
|
|
||||||
|
|
||||||
function preludeBundle(
|
function preludeBundle(
|
||||||
dir: string,
|
dir: string,
|
||||||
versionNumber: string,
|
versionNumber: string,
|
||||||
@@ -52,15 +50,6 @@ async function createZip(buildDir: string, distDir: string, targets: string[]) {
|
|||||||
zip.addFile(path.join(buildDir, binary), binary);
|
zip.addFile(path.join(buildDir, binary), binary);
|
||||||
});
|
});
|
||||||
|
|
||||||
// add plugins
|
|
||||||
const pluginDir = path.join(buildDir, PLUGINS_FOLDER_NAME);
|
|
||||||
fs.readdirSync(pluginDir).forEach((file) => {
|
|
||||||
zip.addFile(
|
|
||||||
path.join(pluginDir, file),
|
|
||||||
path.join(PLUGINS_FOLDER_NAME, file),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// write zip file
|
// write zip file
|
||||||
zip.outputStream
|
zip.outputStream
|
||||||
.pipe(fs.createWriteStream(path.join(distDir, 'Flipper-headless.zip')))
|
.pipe(fs.createWriteStream(path.join(distDir, 'Flipper-headless.zip')))
|
||||||
@@ -94,22 +83,15 @@ async function createZip(buildDir: string, distDir: string, targets: string[]) {
|
|||||||
// platformPostfix is automatically added by pkg
|
// platformPostfix is automatically added by pkg
|
||||||
platformPostfix = '';
|
platformPostfix = '';
|
||||||
}
|
}
|
||||||
// Compiling all plugins takes a long time. Use this flag for quicker
|
|
||||||
// developement iteration by not including any plugins.
|
|
||||||
const skipPlugins = process.argv.indexOf('--no-plugins') > -1;
|
|
||||||
|
|
||||||
process.env.FLIPPER_HEADLESS = 'true';
|
process.env.FLIPPER_HEADLESS = 'true';
|
||||||
const buildDir = await buildFolder();
|
const buildDir = await buildFolder();
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('Created build directory', buildDir);
|
console.log('Created build directory', buildDir);
|
||||||
|
await generatePluginEntryPoints();
|
||||||
await compileHeadless(buildDir);
|
await compileHeadless(buildDir);
|
||||||
const versionNumber = getVersionNumber();
|
const versionNumber = getVersionNumber();
|
||||||
const buildRevision = await genMercurialRevision();
|
const buildRevision = await genMercurialRevision();
|
||||||
await preludeBundle(buildDir, versionNumber, buildRevision);
|
await preludeBundle(buildDir, versionNumber, buildRevision);
|
||||||
await compileDefaultPlugins(
|
|
||||||
path.join(buildDir, PLUGINS_FOLDER_NAME),
|
|
||||||
skipPlugins,
|
|
||||||
);
|
|
||||||
await createBinary([
|
await createBinary([
|
||||||
path.join(buildDir, 'bundle.js'),
|
path.join(buildDir, 'bundle.js'),
|
||||||
'--output',
|
'--output',
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ import {
|
|||||||
compileRenderer,
|
compileRenderer,
|
||||||
compileMain,
|
compileMain,
|
||||||
die,
|
die,
|
||||||
compileDefaultPlugins,
|
|
||||||
getVersionNumber,
|
getVersionNumber,
|
||||||
genMercurialRevision,
|
genMercurialRevision,
|
||||||
|
generatePluginEntryPoints,
|
||||||
} from './build-utils';
|
} from './build-utils';
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import {getIcons, buildLocalIconPath, getIconURL} from '../app/src/utils/icons';
|
import {getIcons, buildLocalIconPath, getIconURL} from '../app/src/utils/icons';
|
||||||
@@ -126,7 +126,9 @@ async function buildDist(buildFolder: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function copyStaticFolder(buildFolder: string) {
|
async function copyStaticFolder(buildFolder: string) {
|
||||||
|
console.log(`⚙️ Copying static package with dependencies...`);
|
||||||
await copyPackageWithDependencies(staticDir, buildFolder);
|
await copyPackageWithDependencies(staticDir, buildFolder);
|
||||||
|
console.log('✅ Copied static package with dependencies.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadIcons(buildFolder: string) {
|
function downloadIcons(buildFolder: string) {
|
||||||
@@ -184,11 +186,9 @@ function downloadIcons(buildFolder: string) {
|
|||||||
console.log('Created build directory', dir);
|
console.log('Created build directory', dir);
|
||||||
|
|
||||||
await compileMain();
|
await compileMain();
|
||||||
|
await generatePluginEntryPoints();
|
||||||
await copyStaticFolder(dir);
|
await copyStaticFolder(dir);
|
||||||
await downloadIcons(dir);
|
await downloadIcons(dir);
|
||||||
if (!process.argv.includes('--no-embedded-plugins')) {
|
|
||||||
await compileDefaultPlugins(path.join(dir, 'defaultPlugins'));
|
|
||||||
}
|
|
||||||
await compileRenderer(dir);
|
await compileRenderer(dir);
|
||||||
const versionNumber = getVersionNumber();
|
const versionNumber = getVersionNumber();
|
||||||
const hgRevision = await genMercurialRevision();
|
const hgRevision = await genMercurialRevision();
|
||||||
|
|||||||
@@ -8,64 +8,53 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Metro from 'metro';
|
import Metro from 'metro';
|
||||||
import compilePlugins from '../static/compilePlugins';
|
|
||||||
import util from 'util';
|
|
||||||
import tmp from 'tmp';
|
import tmp from 'tmp';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import {spawn} from 'promisify-child-process';
|
import {spawn} from 'promisify-child-process';
|
||||||
import recursiveReaddir from 'recursive-readdir';
|
|
||||||
import getWatchFolders from '../static/getWatchFolders';
|
import getWatchFolders from '../static/getWatchFolders';
|
||||||
import getAppWatchFolders from './get-app-watch-folders';
|
import getAppWatchFolders from './get-app-watch-folders';
|
||||||
|
import getPlugins from '../static/getPlugins';
|
||||||
import {
|
import {
|
||||||
appDir,
|
appDir,
|
||||||
staticDir,
|
staticDir,
|
||||||
pluginsDir,
|
defaultPluginsIndexDir,
|
||||||
headlessDir,
|
headlessDir,
|
||||||
babelTransformationsDir,
|
babelTransformationsDir,
|
||||||
} from './paths';
|
} from './paths';
|
||||||
|
import getPluginFolders from '../static/getPluginFolders';
|
||||||
|
|
||||||
const dev = process.env.NODE_ENV !== 'production';
|
const dev = process.env.NODE_ENV !== 'production';
|
||||||
|
|
||||||
async function mostRecentlyChanged(
|
|
||||||
dir: string,
|
|
||||||
ignores: string[],
|
|
||||||
): Promise<Date> {
|
|
||||||
const files = await util.promisify<string, string[], string[]>(
|
|
||||||
recursiveReaddir,
|
|
||||||
)(dir, ignores);
|
|
||||||
return files
|
|
||||||
.map((f) => fs.lstatSync(f).ctime)
|
|
||||||
.reduce((a, b) => (a > b ? a : b), new Date(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function die(err: Error) {
|
export function die(err: Error) {
|
||||||
console.error(err.stack);
|
console.error(err.stack);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function compileDefaultPlugins(
|
export async function generatePluginEntryPoints() {
|
||||||
defaultPluginDir: string,
|
console.log('⚙️ Generating plugin entry points...');
|
||||||
skipAll: boolean = false,
|
const pluginEntryPoints = await getPlugins();
|
||||||
) {
|
if (await fs.pathExists(defaultPluginsIndexDir)) {
|
||||||
return compilePlugins(
|
await fs.remove(defaultPluginsIndexDir);
|
||||||
null,
|
}
|
||||||
skipAll ? [] : [pluginsDir, path.join(pluginsDir, 'fb')],
|
await fs.mkdirp(defaultPluginsIndexDir);
|
||||||
defaultPluginDir,
|
await fs.writeJSON(
|
||||||
{force: true, failSilently: false, recompileOnChanges: false},
|
path.join(defaultPluginsIndexDir, 'index.json'),
|
||||||
)
|
pluginEntryPoints.map((plugin) => plugin.manifest),
|
||||||
.then((defaultPlugins) =>
|
);
|
||||||
fs.writeFileSync(
|
const pluginRequres = pluginEntryPoints
|
||||||
path.join(defaultPluginDir, 'index.json'),
|
.map((x) => ` '${x.name}': require('${x.name}')`)
|
||||||
JSON.stringify(
|
.join(',\n');
|
||||||
defaultPlugins.map(({entry, rootDir, out, ...plugin}) => ({
|
const generatedIndex = `
|
||||||
...plugin,
|
// THIS FILE IS AUTO-GENERATED by function "generatePluginEntryPoints" in "build-utils.ts".
|
||||||
out: path.parse(out).base,
|
export default {\n${pluginRequres}\n} as any
|
||||||
})),
|
`;
|
||||||
),
|
await fs.ensureDir(path.join(appDir, 'src', 'defaultPlugins'));
|
||||||
),
|
await fs.writeFile(
|
||||||
)
|
path.join(appDir, 'src', 'defaultPlugins', 'index.tsx'),
|
||||||
.catch(die);
|
generatedIndex,
|
||||||
|
);
|
||||||
|
console.log('✅ Generated plugin entry points.');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function compile(
|
async function compile(
|
||||||
@@ -89,6 +78,7 @@ async function compile(
|
|||||||
resolver: {
|
resolver: {
|
||||||
resolverMainFields: ['flipper:source', 'module', 'main'],
|
resolverMainFields: ['flipper:source', 'module', 'main'],
|
||||||
blacklistRE: /\.native\.js$/,
|
blacklistRE: /\.native\.js$/,
|
||||||
|
sourceExts: ['js', 'jsx', 'ts', 'tsx', 'json', 'mjs'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -108,6 +98,7 @@ export async function compileHeadless(buildFolder: string) {
|
|||||||
headlessDir,
|
headlessDir,
|
||||||
...(await getWatchFolders(staticDir)),
|
...(await getWatchFolders(staticDir)),
|
||||||
...(await getAppWatchFolders()),
|
...(await getAppWatchFolders()),
|
||||||
|
...(await getPluginFolders()),
|
||||||
]
|
]
|
||||||
.filter((value, index, self) => self.indexOf(value) === index)
|
.filter((value, index, self) => self.indexOf(value) === index)
|
||||||
.filter(fs.pathExistsSync);
|
.filter(fs.pathExistsSync);
|
||||||
@@ -126,7 +117,10 @@ export async function compileHeadless(buildFolder: string) {
|
|||||||
|
|
||||||
export async function compileRenderer(buildFolder: string) {
|
export async function compileRenderer(buildFolder: string) {
|
||||||
console.log(`⚙️ Compiling renderer bundle...`);
|
console.log(`⚙️ Compiling renderer bundle...`);
|
||||||
const watchFolders = await getAppWatchFolders();
|
const watchFolders = [
|
||||||
|
...(await getAppWatchFolders()),
|
||||||
|
...(await getPluginFolders()),
|
||||||
|
];
|
||||||
try {
|
try {
|
||||||
await compile(
|
await compile(
|
||||||
buildFolder,
|
buildFolder,
|
||||||
@@ -143,15 +137,6 @@ export async function compileRenderer(buildFolder: string) {
|
|||||||
export async function compileMain() {
|
export async function compileMain() {
|
||||||
const out = path.join(staticDir, 'main.bundle.js');
|
const out = path.join(staticDir, 'main.bundle.js');
|
||||||
process.env.FLIPPER_ELECTRON_VERSION = require('electron/package.json').version;
|
process.env.FLIPPER_ELECTRON_VERSION = require('electron/package.json').version;
|
||||||
// check if main needs to be compiled
|
|
||||||
if (await fs.pathExists(out)) {
|
|
||||||
const staticDirCtime = await mostRecentlyChanged(staticDir, ['*.bundle.*']);
|
|
||||||
const bundleCtime = (await fs.lstat(out)).ctime;
|
|
||||||
if (staticDirCtime < bundleCtime) {
|
|
||||||
console.log(`🥫 Using cached version of main bundle...`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log('⚙️ Compiling main bundle...');
|
console.log('⚙️ Compiling main bundle...');
|
||||||
try {
|
try {
|
||||||
const config = Object.assign({}, await Metro.loadConfig(), {
|
const config = Object.assign({}, await Metro.loadConfig(), {
|
||||||
|
|||||||
15
desktop/scripts/generate-plugin-entry-points.ts
Normal file
15
desktop/scripts/generate-plugin-entry-points.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* 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 {generatePluginEntryPoints} from './build-utils';
|
||||||
|
|
||||||
|
generatePluginEntryPoints().catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
@@ -12,6 +12,7 @@ import path from 'path';
|
|||||||
export const rootDir = path.resolve(__dirname, '..');
|
export const rootDir = path.resolve(__dirname, '..');
|
||||||
export const appDir = path.join(rootDir, 'app');
|
export const appDir = path.join(rootDir, 'app');
|
||||||
export const staticDir = path.join(rootDir, 'static');
|
export const staticDir = path.join(rootDir, 'static');
|
||||||
|
export const defaultPluginsIndexDir = path.join(staticDir, 'defaultPlugins');
|
||||||
export const pluginsDir = path.join(rootDir, 'plugins');
|
export const pluginsDir = path.join(rootDir, 'plugins');
|
||||||
export const headlessDir = path.join(rootDir, 'headless');
|
export const headlessDir = path.join(rootDir, 'headless');
|
||||||
export const distDir = path.resolve(rootDir, '..', 'dist');
|
export const distDir = path.resolve(rootDir, '..', 'dist');
|
||||||
|
|||||||
@@ -18,13 +18,16 @@ import chalk from 'chalk';
|
|||||||
import http from 'http';
|
import http from 'http';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import {compileMain} from './build-utils';
|
import {compileMain, generatePluginEntryPoints} from './build-utils';
|
||||||
import Watchman from '../static/watchman';
|
import Watchman from '../static/watchman';
|
||||||
import Metro from 'metro';
|
import Metro from 'metro';
|
||||||
import MetroResolver from 'metro-resolver';
|
import MetroResolver from 'metro-resolver';
|
||||||
import getAppWatchFolders from './get-app-watch-folders';
|
|
||||||
import {staticDir, appDir, babelTransformationsDir} from './paths';
|
import {staticDir, appDir, babelTransformationsDir} from './paths';
|
||||||
import isFB from './isFB';
|
import isFB from './isFB';
|
||||||
|
import getAppWatchFolders from './get-app-watch-folders';
|
||||||
|
import getPlugins from '../static/getPlugins';
|
||||||
|
import getPluginFolders from '../static/getPluginFolders';
|
||||||
|
import startWatchPlugins from '../static/startWatchPlugins';
|
||||||
|
|
||||||
const ansiToHtmlConverter = new AnsiToHtmlConverter();
|
const ansiToHtmlConverter = new AnsiToHtmlConverter();
|
||||||
|
|
||||||
@@ -81,7 +84,9 @@ function launchElectron({
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function startMetroServer(app: Express) {
|
async function startMetroServer(app: Express) {
|
||||||
const watchFolders = await getAppWatchFolders();
|
const watchFolders = (await getAppWatchFolders()).concat(
|
||||||
|
await getPluginFolders(),
|
||||||
|
);
|
||||||
const metroBundlerServer = await Metro.runMetro({
|
const metroBundlerServer = await Metro.runMetro({
|
||||||
projectRoot: appDir,
|
projectRoot: appDir,
|
||||||
watchFolders,
|
watchFolders,
|
||||||
@@ -101,6 +106,7 @@ async function startMetroServer(app: Express) {
|
|||||||
platform,
|
platform,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
sourceExts: ['js', 'jsx', 'ts', 'tsx', 'json', 'mjs'],
|
||||||
},
|
},
|
||||||
watch: true,
|
watch: true,
|
||||||
});
|
});
|
||||||
@@ -170,7 +176,7 @@ async function addWebsocket(server: http.Server) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// refresh the app on changes to the src folder
|
// refresh the app on changes
|
||||||
// this can be removed once metroServer notifies us about file changes
|
// this can be removed once metroServer notifies us about file changes
|
||||||
try {
|
try {
|
||||||
const watchman = new Watchman(path.resolve(__dirname, '..'));
|
const watchman = new Watchman(path.resolve(__dirname, '..'));
|
||||||
@@ -188,6 +194,10 @@ async function addWebsocket(server: http.Server) {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
const plugins = await getPlugins();
|
||||||
|
await startWatchPlugins(plugins, () => {
|
||||||
|
io.emit('refresh');
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(
|
console.error(
|
||||||
'Failed to start watching for changes using Watchman, continue without hot reloading',
|
'Failed to start watching for changes using Watchman, continue without hot reloading',
|
||||||
@@ -258,6 +268,7 @@ function outputScreen(socket?: socketIo.Server) {
|
|||||||
await startMetroServer(app);
|
await startMetroServer(app);
|
||||||
outputScreen(socket);
|
outputScreen(socket);
|
||||||
await compileMain();
|
await compileMain();
|
||||||
|
await generatePluginEntryPoints();
|
||||||
shutdownElectron = launchElectron({
|
shutdownElectron = launchElectron({
|
||||||
devServerURL: `http://localhost:${port}`,
|
devServerURL: `http://localhost:${port}`,
|
||||||
bundleURL: `http://localhost:${port}/src/init.bundle`,
|
bundleURL: `http://localhost:${port}/src/init.bundle`,
|
||||||
|
|||||||
@@ -15,12 +15,8 @@ import recursiveReaddir from 'recursive-readdir';
|
|||||||
import pMap from 'p-map';
|
import pMap from 'p-map';
|
||||||
import {homedir} from 'os';
|
import {homedir} from 'os';
|
||||||
import getWatchFolders from './getWatchFolders';
|
import getWatchFolders from './getWatchFolders';
|
||||||
import {
|
import {default as getPlugins, PluginManifest, PluginInfo} from './getPlugins';
|
||||||
default as getPluginEntryPoints,
|
import startWatchPlugins from './startWatchPlugins';
|
||||||
PluginManifest,
|
|
||||||
PluginInfo,
|
|
||||||
} from './getPluginEntryPoints';
|
|
||||||
import watchPlugins from './watchPlugins';
|
|
||||||
|
|
||||||
const HOME_DIR = homedir();
|
const HOME_DIR = homedir();
|
||||||
|
|
||||||
@@ -43,46 +39,53 @@ export type CompiledPluginInfo = PluginManifest & {out: string};
|
|||||||
|
|
||||||
export default async function (
|
export default async function (
|
||||||
reloadCallback: (() => void) | null,
|
reloadCallback: (() => void) | null,
|
||||||
pluginPaths: string[],
|
|
||||||
pluginCache: string,
|
pluginCache: string,
|
||||||
options: CompileOptions = DEFAULT_COMPILE_OPTIONS,
|
options: CompileOptions = DEFAULT_COMPILE_OPTIONS,
|
||||||
) {
|
) {
|
||||||
options = Object.assign({}, DEFAULT_COMPILE_OPTIONS, options);
|
options = Object.assign({}, DEFAULT_COMPILE_OPTIONS, options);
|
||||||
const plugins = getPluginEntryPoints(pluginPaths);
|
const defaultPlugins = (
|
||||||
if (!(await fs.pathExists(pluginCache))) {
|
await fs.readJson(path.join(__dirname, 'defaultPlugins', 'index.json'))
|
||||||
await fs.mkdir(pluginCache);
|
).map((p: any) => p.name) as string[];
|
||||||
}
|
const dynamicPlugins = (await getPlugins(true)).filter(
|
||||||
|
(p) => !defaultPlugins.includes(p.name),
|
||||||
|
);
|
||||||
|
await fs.ensureDir(pluginCache);
|
||||||
if (options.recompileOnChanges) {
|
if (options.recompileOnChanges) {
|
||||||
await startWatchChanges(plugins, reloadCallback, pluginCache, options);
|
await startWatchChanges(
|
||||||
|
dynamicPlugins,
|
||||||
|
reloadCallback,
|
||||||
|
pluginCache,
|
||||||
|
options,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const compilations = pMap(
|
const compilations = pMap(
|
||||||
Object.values(plugins),
|
dynamicPlugins,
|
||||||
(plugin) => {
|
(plugin) => {
|
||||||
return compilePlugin(plugin, pluginCache, options);
|
return compilePlugin(plugin, pluginCache, options);
|
||||||
},
|
},
|
||||||
{concurrency: 4},
|
{concurrency: 4},
|
||||||
);
|
);
|
||||||
|
|
||||||
const dynamicPlugins = (await compilations).filter(
|
const compiledDynamicPlugins = (await compilations).filter(
|
||||||
(c) => c !== null,
|
(c) => c !== null,
|
||||||
) as CompiledPluginInfo[];
|
) as CompiledPluginInfo[];
|
||||||
console.log('✅ Compiled all plugins.');
|
console.log('✅ Compiled all plugins.');
|
||||||
return dynamicPlugins;
|
return compiledDynamicPlugins;
|
||||||
}
|
}
|
||||||
async function startWatchChanges(
|
async function startWatchChanges(
|
||||||
plugins: {[key: string]: PluginInfo},
|
plugins: PluginInfo[],
|
||||||
reloadCallback: (() => void) | null,
|
reloadCallback: (() => void) | null,
|
||||||
pluginCache: string,
|
pluginCache: string,
|
||||||
options: CompileOptions = DEFAULT_COMPILE_OPTIONS,
|
options: CompileOptions = DEFAULT_COMPILE_OPTIONS,
|
||||||
) {
|
) {
|
||||||
const filteredPlugins = Object.values(plugins)
|
const filteredPlugins = plugins
|
||||||
// no hot reloading for plugins in .flipper folder. This is to prevent
|
// no hot reloading for plugins in .flipper folder. This is to prevent
|
||||||
// Flipper from reloading, while we are doing changes on thirdparty plugins.
|
// Flipper from reloading, while we are doing changes on thirdparty plugins.
|
||||||
.filter(
|
.filter(
|
||||||
(plugin) => !plugin.rootDir.startsWith(path.join(HOME_DIR, '.flipper')),
|
(plugin) => !plugin.rootDir.startsWith(path.join(HOME_DIR, '.flipper')),
|
||||||
);
|
);
|
||||||
const watchOptions = Object.assign(options, {force: true});
|
const watchOptions = Object.assign({}, options, {force: true});
|
||||||
await watchPlugins(filteredPlugins, (plugin) =>
|
await startWatchPlugins(filteredPlugins, (plugin) =>
|
||||||
compilePlugin(plugin, pluginCache, watchOptions).then(
|
compilePlugin(plugin, pluginCache, watchOptions).then(
|
||||||
reloadCallback ?? (() => {}),
|
reloadCallback ?? (() => {}),
|
||||||
),
|
),
|
||||||
|
|||||||
32
desktop/static/getPluginFolders.ts
Normal file
32
desktop/static/getPluginFolders.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/**
|
||||||
|
* 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 path from 'path';
|
||||||
|
import fs from 'fs-extra';
|
||||||
|
import expandTilde from 'expand-tilde';
|
||||||
|
import {homedir} from 'os';
|
||||||
|
|
||||||
|
export default async function getPluginFolders(
|
||||||
|
includeThirdparty: boolean = false,
|
||||||
|
) {
|
||||||
|
const pluginFolders: string[] = [];
|
||||||
|
if (includeThirdparty) {
|
||||||
|
pluginFolders.push(path.join(homedir(), '.flipper', 'thirdparty'));
|
||||||
|
}
|
||||||
|
const flipperConfigPath = path.join(homedir(), '.flipper', 'config.json');
|
||||||
|
if (await fs.pathExists(flipperConfigPath)) {
|
||||||
|
const config = await fs.readJson(flipperConfigPath);
|
||||||
|
if (config.pluginPaths) {
|
||||||
|
pluginFolders.push(...config.pluginPaths);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pluginFolders.push(path.resolve(__dirname, '..', 'plugins'));
|
||||||
|
pluginFolders.push(path.resolve(__dirname, '..', 'plugins', 'fb'));
|
||||||
|
return pluginFolders.map(expandTilde).filter(fs.existsSync);
|
||||||
|
}
|
||||||
@@ -10,9 +10,7 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import expandTilde from 'expand-tilde';
|
import expandTilde from 'expand-tilde';
|
||||||
import {homedir} from 'os';
|
import getPluginFolders from './getPluginFolders';
|
||||||
|
|
||||||
const HOME_DIR = homedir();
|
|
||||||
|
|
||||||
export type PluginManifest = {
|
export type PluginManifest = {
|
||||||
version: string;
|
version: string;
|
||||||
@@ -29,19 +27,16 @@ export type PluginInfo = {
|
|||||||
manifest: PluginManifest;
|
manifest: PluginManifest;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function getPluginEntryPoints(additionalPaths: string[] = []) {
|
export default async function getPlugins(includeThirdparty: boolean = false) {
|
||||||
const defaultPluginPath = path.join(HOME_DIR, '.flipper', 'node_modules');
|
const pluginFolders = await getPluginFolders(includeThirdparty);
|
||||||
const entryPoints = entryPointForPluginFolder(defaultPluginPath);
|
const entryPoints: {[key: string]: PluginInfo} = {};
|
||||||
if (typeof additionalPaths === 'string') {
|
pluginFolders.forEach((additionalPath) => {
|
||||||
additionalPaths = [additionalPaths];
|
|
||||||
}
|
|
||||||
additionalPaths.forEach((additionalPath) => {
|
|
||||||
const additionalPlugins = entryPointForPluginFolder(additionalPath);
|
const additionalPlugins = entryPointForPluginFolder(additionalPath);
|
||||||
Object.keys(additionalPlugins).forEach((key) => {
|
Object.keys(additionalPlugins).forEach((key) => {
|
||||||
entryPoints[key] = additionalPlugins[key];
|
entryPoints[key] = additionalPlugins[key];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return entryPoints;
|
return Object.values(entryPoints);
|
||||||
}
|
}
|
||||||
function entryPointForPluginFolder(pluginPath: string) {
|
function entryPointForPluginFolder(pluginPath: string) {
|
||||||
pluginPath = expandTilde(pluginPath);
|
pluginPath = expandTilde(pluginPath);
|
||||||
@@ -62,6 +57,9 @@ function entryPointForPluginFolder(pluginPath: string) {
|
|||||||
if (packageJSON) {
|
if (packageJSON) {
|
||||||
try {
|
try {
|
||||||
const json = JSON.parse(packageJSON);
|
const json = JSON.parse(packageJSON);
|
||||||
|
if (json.workspaces) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!json.keywords || !json.keywords.includes('flipper-plugin')) {
|
if (!json.keywords || !json.keywords.includes('flipper-plugin')) {
|
||||||
console.log(
|
console.log(
|
||||||
`Skipping package "${json.name}" as its "keywords" field does not contain tag "flipper-plugin"`,
|
`Skipping package "${json.name}" as its "keywords" field does not contain tag "flipper-plugin"`,
|
||||||
@@ -27,7 +27,6 @@ import compilePlugins from './compilePlugins';
|
|||||||
import setup from './setup';
|
import setup from './setup';
|
||||||
import isFB from './fb-stubs/isFB';
|
import isFB from './fb-stubs/isFB';
|
||||||
import delegateToLauncher from './launcher';
|
import delegateToLauncher from './launcher';
|
||||||
import expandTilde from 'expand-tilde';
|
|
||||||
import yargs from 'yargs';
|
import yargs from 'yargs';
|
||||||
|
|
||||||
const VERSION: string = (global as any).__VERSION__;
|
const VERSION: string = (global as any).__VERSION__;
|
||||||
@@ -90,25 +89,7 @@ if (isFB && process.env.FLIPPER_FB === undefined) {
|
|||||||
process.env.FLIPPER_FB = 'true';
|
process.env.FLIPPER_FB = 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
const skipLoadingEmbeddedPlugins = process.env.FLIPPER_NO_EMBEDDED_PLUGINS;
|
process.env.CONFIG = JSON.stringify(config);
|
||||||
|
|
||||||
const pluginPaths = (config.pluginPaths ?? [])
|
|
||||||
.concat([
|
|
||||||
path.join(configPath, '..', 'thirdparty'),
|
|
||||||
...(skipLoadingEmbeddedPlugins
|
|
||||||
? []
|
|
||||||
: [
|
|
||||||
path.join(__dirname, '..', 'plugins'),
|
|
||||||
path.join(__dirname, '..', 'plugins', 'fb'),
|
|
||||||
]),
|
|
||||||
])
|
|
||||||
.map(expandTilde)
|
|
||||||
.filter(fs.existsSync);
|
|
||||||
|
|
||||||
process.env.CONFIG = JSON.stringify({
|
|
||||||
...config,
|
|
||||||
pluginPaths,
|
|
||||||
});
|
|
||||||
|
|
||||||
// possible reference to main app window
|
// possible reference to main app window
|
||||||
let win: BrowserWindow;
|
let win: BrowserWindow;
|
||||||
@@ -124,15 +105,11 @@ setInterval(() => {
|
|||||||
}
|
}
|
||||||
}, 60 * 1000);
|
}, 60 * 1000);
|
||||||
|
|
||||||
compilePlugins(
|
compilePlugins(() => {
|
||||||
() => {
|
if (win) {
|
||||||
if (win) {
|
win.reload();
|
||||||
win.reload();
|
}
|
||||||
}
|
}, path.join(flipperDir, 'plugins')).then((dynamicPlugins) => {
|
||||||
},
|
|
||||||
pluginPaths,
|
|
||||||
path.join(flipperDir, 'plugins'),
|
|
||||||
).then((dynamicPlugins) => {
|
|
||||||
ipcMain.on('get-dynamic-plugins', (event) => {
|
ipcMain.on('get-dynamic-plugins', (event) => {
|
||||||
event.returnValue = dynamicPlugins;
|
event.returnValue = dynamicPlugins;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import Watchman from './watchman';
|
import Watchman from './watchman';
|
||||||
import {PluginInfo} from './getPluginEntryPoints';
|
import {PluginInfo} from './getPlugins';
|
||||||
|
|
||||||
export default async function watchPlugins(
|
export default async function startWatchPlugins(
|
||||||
plugins: PluginInfo[],
|
plugins: PluginInfo[],
|
||||||
compilePlugin: (plugin: PluginInfo) => void | Promise<void>,
|
compilePlugin: (plugin: PluginInfo) => void | Promise<void>,
|
||||||
) {
|
) {
|
||||||
Reference in New Issue
Block a user