Load either installed or bundled version of plugin depending on which is newer
Summary: Load either installed or bundled version of plugin depending on which is newer. Reviewed By: mweststrate Differential Revision: D21858965 fbshipit-source-id: aa46eafe0b5137134fadad827749672441f2c9e5
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e31ddbc648
commit
e65b355fb6
@@ -15,6 +15,7 @@ import dispatcher, {
|
|||||||
checkDisabled,
|
checkDisabled,
|
||||||
checkGK,
|
checkGK,
|
||||||
requirePlugin,
|
requirePlugin,
|
||||||
|
filterNewestVersionOfEachPlugin,
|
||||||
} from '../plugins';
|
} from '../plugins';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {ipcRenderer, remote} from 'electron';
|
import {ipcRenderer, remote} from 'electron';
|
||||||
@@ -140,3 +141,22 @@ test('requirePlugin loads plugin', () => {
|
|||||||
expect(plugin!.prototype).toBeInstanceOf(FlipperPlugin);
|
expect(plugin!.prototype).toBeInstanceOf(FlipperPlugin);
|
||||||
expect(plugin!.id).toBe(TestPlugin.id);
|
expect(plugin!.id).toBe(TestPlugin.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('newest version of each plugin is taken', () => {
|
||||||
|
const plugins: PluginDefinition[] = [
|
||||||
|
{name: 'flipper-plugin-test1', version: '0.1.0'},
|
||||||
|
{name: 'flipper-plugin-test2', version: '0.1.0-alpha.201'},
|
||||||
|
{name: 'flipper-plugin-test2', version: '0.1.0-alpha.21'},
|
||||||
|
{name: 'flipper-plugin-test1', version: '0.10.0'},
|
||||||
|
];
|
||||||
|
const filteredPlugins = filterNewestVersionOfEachPlugin(plugins);
|
||||||
|
expect(filteredPlugins).toHaveLength(2);
|
||||||
|
expect(filteredPlugins).toContainEqual({
|
||||||
|
name: 'flipper-plugin-test1',
|
||||||
|
version: '0.10.0',
|
||||||
|
});
|
||||||
|
expect(filteredPlugins).toContainEqual({
|
||||||
|
name: 'flipper-plugin-test2',
|
||||||
|
version: '0.1.0-alpha.201',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import {default as config} from '../utils/processConfig';
|
|||||||
import isProduction from '../utils/isProduction';
|
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';
|
||||||
|
import semver from 'semver';
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-unresolved
|
// eslint-disable-next-line import/no-unresolved
|
||||||
import getPluginIndex from '../utils/getDefaultPluginsIndex';
|
import getPluginIndex from '../utils/getDefaultPluginsIndex';
|
||||||
@@ -58,7 +59,10 @@ export default (store: Store, logger: Logger) => {
|
|||||||
|
|
||||||
const initialPlugins: Array<
|
const initialPlugins: Array<
|
||||||
typeof FlipperPlugin | typeof FlipperDevicePlugin
|
typeof FlipperPlugin | typeof FlipperDevicePlugin
|
||||||
> = [...getBundledPlugins(), ...getDynamicPlugins()]
|
> = filterNewestVersionOfEachPlugin([
|
||||||
|
...getBundledPlugins(),
|
||||||
|
...getDynamicPlugins(),
|
||||||
|
])
|
||||||
.filter(checkDisabled(disabledPlugins))
|
.filter(checkDisabled(disabledPlugins))
|
||||||
.filter(checkGK(gatekeepedPlugins))
|
.filter(checkGK(gatekeepedPlugins))
|
||||||
.map(requirePlugin(failedPlugins, defaultPluginsIndex))
|
.map(requirePlugin(failedPlugins, defaultPluginsIndex))
|
||||||
@@ -83,6 +87,21 @@ export default (store: Store, logger: Logger) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function filterNewestVersionOfEachPlugin(
|
||||||
|
plugins: PluginDefinition[],
|
||||||
|
): PluginDefinition[] {
|
||||||
|
const pluginByName: {[key: string]: PluginDefinition} = {};
|
||||||
|
for (const plugin of plugins) {
|
||||||
|
if (
|
||||||
|
!pluginByName[plugin.name] ||
|
||||||
|
semver.gt(plugin.version, pluginByName[plugin.name].version, true)
|
||||||
|
) {
|
||||||
|
pluginByName[plugin.name] = plugin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Object.values(pluginByName);
|
||||||
|
}
|
||||||
|
|
||||||
function getBundledPlugins(): Array<PluginDefinition> {
|
function getBundledPlugins(): Array<PluginDefinition> {
|
||||||
// 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
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import fs from 'fs-extra';
|
|||||||
import {spawn} from 'promisify-child-process';
|
import {spawn} from 'promisify-child-process';
|
||||||
import {getWatchFolders} from 'flipper-pkg-lib';
|
import {getWatchFolders} from 'flipper-pkg-lib';
|
||||||
import getAppWatchFolders from './get-app-watch-folders';
|
import getAppWatchFolders from './get-app-watch-folders';
|
||||||
import getPlugins from '../static/getPlugins';
|
import {getSourcePlugins} from '../static/getPlugins';
|
||||||
import {
|
import {
|
||||||
appDir,
|
appDir,
|
||||||
staticDir,
|
staticDir,
|
||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
headlessDir,
|
headlessDir,
|
||||||
babelTransformationsDir,
|
babelTransformationsDir,
|
||||||
} from './paths';
|
} from './paths';
|
||||||
import getPluginFolders from '../static/getPluginFolders';
|
import {getPluginSourceFolders} from '../static/getPluginFolders';
|
||||||
|
|
||||||
const dev = process.env.NODE_ENV !== 'production';
|
const dev = process.env.NODE_ENV !== 'production';
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ export function die(err: Error) {
|
|||||||
|
|
||||||
export async function generatePluginEntryPoints() {
|
export async function generatePluginEntryPoints() {
|
||||||
console.log('⚙️ Generating plugin entry points...');
|
console.log('⚙️ Generating plugin entry points...');
|
||||||
const plugins = await getPlugins();
|
const plugins = await getSourcePlugins();
|
||||||
if (await fs.pathExists(defaultPluginsIndexDir)) {
|
if (await fs.pathExists(defaultPluginsIndexDir)) {
|
||||||
await fs.remove(defaultPluginsIndexDir);
|
await fs.remove(defaultPluginsIndexDir);
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ export async function compileHeadless(buildFolder: string) {
|
|||||||
headlessDir,
|
headlessDir,
|
||||||
...(await getWatchFolders(staticDir)),
|
...(await getWatchFolders(staticDir)),
|
||||||
...(await getAppWatchFolders()),
|
...(await getAppWatchFolders()),
|
||||||
...(await getPluginFolders()),
|
...(await getPluginSourceFolders()),
|
||||||
]
|
]
|
||||||
.filter((value, index, self) => self.indexOf(value) === index)
|
.filter((value, index, self) => self.indexOf(value) === index)
|
||||||
.filter(fs.pathExistsSync);
|
.filter(fs.pathExistsSync);
|
||||||
@@ -128,7 +128,7 @@ export async function compileRenderer(buildFolder: string) {
|
|||||||
console.log(`⚙️ Compiling renderer bundle...`);
|
console.log(`⚙️ Compiling renderer bundle...`);
|
||||||
const watchFolders = [
|
const watchFolders = [
|
||||||
...(await getAppWatchFolders()),
|
...(await getAppWatchFolders()),
|
||||||
...(await getPluginFolders()),
|
...(await getPluginSourceFolders()),
|
||||||
];
|
];
|
||||||
try {
|
try {
|
||||||
await compile(
|
await compile(
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import MetroResolver from 'metro-resolver';
|
|||||||
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 getAppWatchFolders from './get-app-watch-folders';
|
||||||
import getPlugins from '../static/getPlugins';
|
import {getSourcePlugins} from '../static/getPlugins';
|
||||||
import getPluginFolders from '../static/getPluginFolders';
|
import {getPluginSourceFolders} from '../static/getPluginFolders';
|
||||||
import startWatchPlugins from '../static/startWatchPlugins';
|
import startWatchPlugins from '../static/startWatchPlugins';
|
||||||
import ensurePluginFoldersWatchable from '../static/ensurePluginFoldersWatchable';
|
import ensurePluginFoldersWatchable from '../static/ensurePluginFoldersWatchable';
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ function launchElectron(port: number) {
|
|||||||
|
|
||||||
async function startMetroServer(app: Express, server: http.Server) {
|
async function startMetroServer(app: Express, server: http.Server) {
|
||||||
const watchFolders = (await getAppWatchFolders()).concat(
|
const watchFolders = (await getAppWatchFolders()).concat(
|
||||||
await getPluginFolders(),
|
await getPluginSourceFolders(),
|
||||||
);
|
);
|
||||||
const baseConfig = await Metro.loadConfig();
|
const baseConfig = await Metro.loadConfig();
|
||||||
const config = Object.assign({}, baseConfig, {
|
const config = Object.assign({}, baseConfig, {
|
||||||
@@ -206,7 +206,7 @@ async function startWatchChanges(io: socketIo.Server) {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
const plugins = await getPlugins();
|
const plugins = await getSourcePlugins();
|
||||||
await startWatchPlugins(plugins, () => {
|
await startWatchPlugins(plugins, () => {
|
||||||
io.emit('refresh');
|
io.emit('refresh');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import recursiveReaddir from 'recursive-readdir';
|
|||||||
import pMap from 'p-map';
|
import pMap from 'p-map';
|
||||||
import {homedir} from 'os';
|
import {homedir} from 'os';
|
||||||
import {runBuild, PluginDetails} from 'flipper-pkg-lib';
|
import {runBuild, PluginDetails} from 'flipper-pkg-lib';
|
||||||
import getPlugins from './getPlugins';
|
import {getSourcePlugins, getInstalledPlugins} from './getPlugins';
|
||||||
import startWatchPlugins from './startWatchPlugins';
|
import startWatchPlugins from './startWatchPlugins';
|
||||||
import ensurePluginFoldersWatchable from './ensurePluginFoldersWatchable';
|
import ensurePluginFoldersWatchable from './ensurePluginFoldersWatchable';
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ export default async function (
|
|||||||
): Promise<CompiledPluginDetails[]> {
|
): Promise<CompiledPluginDetails[]> {
|
||||||
if (process.env.FLIPPER_FAST_REFRESH) {
|
if (process.env.FLIPPER_FAST_REFRESH) {
|
||||||
console.log(
|
console.log(
|
||||||
'🥫 Skipping loading of third-party plugins because Fast Refresh is enabled',
|
'🥫 Skipping loading of installed plugins because Fast Refresh is enabled',
|
||||||
);
|
);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -50,9 +50,12 @@ export default async function (
|
|||||||
const defaultPlugins = (
|
const defaultPlugins = (
|
||||||
await fs.readJson(path.join(__dirname, 'defaultPlugins', 'index.json'))
|
await fs.readJson(path.join(__dirname, 'defaultPlugins', 'index.json'))
|
||||||
).map((p: any) => p.name) as string[];
|
).map((p: any) => p.name) as string[];
|
||||||
const dynamicPlugins = (await getPlugins(true)).filter(
|
const dynamicPlugins = [
|
||||||
|
...(await getInstalledPlugins()),
|
||||||
|
...(await getSourcePlugins()).filter(
|
||||||
(p) => !defaultPlugins.includes(p.name),
|
(p) => !defaultPlugins.includes(p.name),
|
||||||
);
|
),
|
||||||
|
];
|
||||||
await fs.ensureDir(pluginCache);
|
await fs.ensureDir(pluginCache);
|
||||||
if (options.recompileOnChanges) {
|
if (options.recompileOnChanges) {
|
||||||
await startWatchChanges(
|
await startWatchChanges(
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import getPluginFolders from './getPluginFolders';
|
import {getPluginSourceFolders} from './getPluginFolders';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
|
|
||||||
const watchmanconfigName = '.watchmanconfig';
|
const watchmanconfigName = '.watchmanconfig';
|
||||||
@@ -15,7 +15,7 @@ const watchmanconfigName = '.watchmanconfig';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
export default async function ensurePluginFoldersWatchable() {
|
export default async function ensurePluginFoldersWatchable() {
|
||||||
const pluginFolders = await getPluginFolders();
|
const pluginFolders = await getPluginSourceFolders();
|
||||||
for (const pluginFolder of pluginFolders) {
|
for (const pluginFolder of pluginFolders) {
|
||||||
if (!(await hasParentWithWatchmanConfig(pluginFolder))) {
|
if (!(await hasParentWithWatchmanConfig(pluginFolder))) {
|
||||||
// If no watchman config found in the plugins folder or any its parent, we need to create it.
|
// If no watchman config found in the plugins folder or any its parent, we need to create it.
|
||||||
|
|||||||
@@ -12,13 +12,12 @@ import fs from 'fs-extra';
|
|||||||
import expandTilde from 'expand-tilde';
|
import expandTilde from 'expand-tilde';
|
||||||
import {homedir} from 'os';
|
import {homedir} from 'os';
|
||||||
|
|
||||||
export default async function getPluginFolders(
|
export function getPluginsInstallationFolder(): string {
|
||||||
includeThirdparty: boolean = false,
|
return path.join(homedir(), '.flipper', 'thirdparty');
|
||||||
) {
|
}
|
||||||
|
|
||||||
|
export async function getPluginSourceFolders(): Promise<string[]> {
|
||||||
const pluginFolders: string[] = [];
|
const pluginFolders: string[] = [];
|
||||||
if (includeThirdparty) {
|
|
||||||
pluginFolders.push(path.join(homedir(), '.flipper', 'thirdparty'));
|
|
||||||
}
|
|
||||||
if (process.env.FLIPPER_NO_EMBEDDED_PLUGINS === 'true') {
|
if (process.env.FLIPPER_NO_EMBEDDED_PLUGINS === 'true') {
|
||||||
console.log(
|
console.log(
|
||||||
'🥫 Skipping embedded plugins because "--no-embedded-plugins" flag provided',
|
'🥫 Skipping embedded plugins because "--no-embedded-plugins" flag provided',
|
||||||
|
|||||||
@@ -10,15 +10,23 @@
|
|||||||
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 getPluginFolders from './getPluginFolders';
|
import {
|
||||||
|
getPluginsInstallationFolder,
|
||||||
|
getPluginSourceFolders,
|
||||||
|
} from './getPluginFolders';
|
||||||
import {PluginDetails, getPluginDetails} from 'flipper-pkg-lib';
|
import {PluginDetails, getPluginDetails} from 'flipper-pkg-lib';
|
||||||
import pmap from 'p-map';
|
import pmap from 'p-map';
|
||||||
import pfilter from 'p-filter';
|
import pfilter from 'p-filter';
|
||||||
|
|
||||||
export default async function getPlugins(
|
export async function getSourcePlugins(): Promise<PluginDetails[]> {
|
||||||
includeThirdparty: boolean = false,
|
return await getPluginsFromFolders(await getPluginSourceFolders());
|
||||||
|
}
|
||||||
|
export async function getInstalledPlugins(): Promise<PluginDetails[]> {
|
||||||
|
return await getPluginsFromFolders([getPluginsInstallationFolder()]);
|
||||||
|
}
|
||||||
|
async function getPluginsFromFolders(
|
||||||
|
pluginFolders: string[],
|
||||||
): Promise<PluginDetails[]> {
|
): Promise<PluginDetails[]> {
|
||||||
const pluginFolders = await getPluginFolders(includeThirdparty);
|
|
||||||
const entryPoints: {[key: string]: PluginDetails} = {};
|
const entryPoints: {[key: string]: PluginDetails} = {};
|
||||||
const additionalPlugins = await pmap(pluginFolders, (path) =>
|
const additionalPlugins = await pmap(pluginFolders, (path) =>
|
||||||
entryPointForPluginFolder(path),
|
entryPointForPluginFolder(path),
|
||||||
|
|||||||
Reference in New Issue
Block a user