Disable plugin auto-update in dev mode
Summary: When Flipper is running in dev mode we should always use bundled version of plugin (e.g. loaded from sources) even if a newer version is installed. Otherwise it could happen that Flipper will load installed version and it will not be possible to test your changes of plugin sources. Reviewed By: passy Differential Revision: D22016564 fbshipit-source-id: fbf63d5248b60034dc61688e4faa9b54890b744e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
763853a7cf
commit
74a27aafcc
@@ -162,14 +162,16 @@ test('requirePlugin loads plugin', () => {
|
|||||||
expect(plugin!.id).toBe(TestPlugin.id);
|
expect(plugin!.id).toBe(TestPlugin.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('newest version of each plugin is taken', () => {
|
test('newest version of each plugin is used', () => {
|
||||||
const plugins: PluginDetails[] = [
|
const bundledPlugins: PluginDetails[] = [
|
||||||
{...samplePluginDetails, name: 'flipper-plugin-test1', version: '0.1.0'},
|
{...samplePluginDetails, name: 'flipper-plugin-test1', version: '0.1.0'},
|
||||||
{
|
{
|
||||||
...samplePluginDetails,
|
...samplePluginDetails,
|
||||||
name: 'flipper-plugin-test2',
|
name: 'flipper-plugin-test2',
|
||||||
version: '0.1.0-alpha.201',
|
version: '0.1.0-alpha.201',
|
||||||
},
|
},
|
||||||
|
];
|
||||||
|
const installedPlugins: PluginDetails[] = [
|
||||||
{
|
{
|
||||||
...samplePluginDetails,
|
...samplePluginDetails,
|
||||||
name: 'flipper-plugin-test2',
|
name: 'flipper-plugin-test2',
|
||||||
@@ -177,7 +179,10 @@ test('newest version of each plugin is taken', () => {
|
|||||||
},
|
},
|
||||||
{...samplePluginDetails, name: 'flipper-plugin-test1', version: '0.10.0'},
|
{...samplePluginDetails, name: 'flipper-plugin-test1', version: '0.10.0'},
|
||||||
];
|
];
|
||||||
const filteredPlugins = filterNewestVersionOfEachPlugin(plugins);
|
const filteredPlugins = filterNewestVersionOfEachPlugin(
|
||||||
|
bundledPlugins,
|
||||||
|
installedPlugins,
|
||||||
|
);
|
||||||
expect(filteredPlugins).toHaveLength(2);
|
expect(filteredPlugins).toHaveLength(2);
|
||||||
expect(filteredPlugins).toContainEqual({
|
expect(filteredPlugins).toContainEqual({
|
||||||
...samplePluginDetails,
|
...samplePluginDetails,
|
||||||
@@ -190,3 +195,42 @@ test('newest version of each plugin is taken', () => {
|
|||||||
version: '0.1.0-alpha.201',
|
version: '0.1.0-alpha.201',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('bundled versions are used when env var FLIPPER_DISABLE_PLUGIN_AUTO_UPDATE is set even if newer versions are installed', () => {
|
||||||
|
process.env.FLIPPER_DISABLE_PLUGIN_AUTO_UPDATE = 'true';
|
||||||
|
try {
|
||||||
|
const bundledPlugins: PluginDetails[] = [
|
||||||
|
{...samplePluginDetails, name: 'flipper-plugin-test1', version: '0.1.0'},
|
||||||
|
{
|
||||||
|
...samplePluginDetails,
|
||||||
|
name: 'flipper-plugin-test2',
|
||||||
|
version: '0.1.0-alpha.21',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const installedPlugins: PluginDetails[] = [
|
||||||
|
{
|
||||||
|
...samplePluginDetails,
|
||||||
|
name: 'flipper-plugin-test2',
|
||||||
|
version: '0.1.0-alpha.201',
|
||||||
|
},
|
||||||
|
{...samplePluginDetails, name: 'flipper-plugin-test1', version: '0.10.0'},
|
||||||
|
];
|
||||||
|
const filteredPlugins = filterNewestVersionOfEachPlugin(
|
||||||
|
bundledPlugins,
|
||||||
|
installedPlugins,
|
||||||
|
);
|
||||||
|
expect(filteredPlugins).toHaveLength(2);
|
||||||
|
expect(filteredPlugins).toContainEqual({
|
||||||
|
...samplePluginDetails,
|
||||||
|
name: 'flipper-plugin-test1',
|
||||||
|
version: '0.1.0',
|
||||||
|
});
|
||||||
|
expect(filteredPlugins).toContainEqual({
|
||||||
|
...samplePluginDetails,
|
||||||
|
name: 'flipper-plugin-test2',
|
||||||
|
version: '0.1.0-alpha.21',
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
delete process.env.FLIPPER_DISABLE_PLUGIN_AUTO_UPDATE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -51,10 +51,7 @@ export default (store: Store, logger: Logger) => {
|
|||||||
|
|
||||||
const initialPlugins: Array<
|
const initialPlugins: Array<
|
||||||
typeof FlipperPlugin | typeof FlipperDevicePlugin
|
typeof FlipperPlugin | typeof FlipperDevicePlugin
|
||||||
> = filterNewestVersionOfEachPlugin([
|
> = filterNewestVersionOfEachPlugin(getBundledPlugins(), getDynamicPlugins())
|
||||||
...getBundledPlugins(),
|
|
||||||
...getDynamicPlugins(),
|
|
||||||
])
|
|
||||||
.filter(checkDisabled(disabledPlugins))
|
.filter(checkDisabled(disabledPlugins))
|
||||||
.filter(checkGK(gatekeepedPlugins))
|
.filter(checkGK(gatekeepedPlugins))
|
||||||
.map(requirePlugin(failedPlugins, defaultPluginsIndex))
|
.map(requirePlugin(failedPlugins, defaultPluginsIndex))
|
||||||
@@ -80,13 +77,18 @@ export default (store: Store, logger: Logger) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function filterNewestVersionOfEachPlugin(
|
export function filterNewestVersionOfEachPlugin(
|
||||||
plugins: PluginDetails[],
|
bundledPlugins: PluginDetails[],
|
||||||
|
dynamicPlugins: PluginDetails[],
|
||||||
): PluginDetails[] {
|
): PluginDetails[] {
|
||||||
const pluginByName: {[key: string]: PluginDetails} = {};
|
const pluginByName: {[key: string]: PluginDetails} = {};
|
||||||
for (const plugin of plugins) {
|
for (const plugin of bundledPlugins) {
|
||||||
|
pluginByName[plugin.name] = plugin;
|
||||||
|
}
|
||||||
|
for (const plugin of dynamicPlugins) {
|
||||||
if (
|
if (
|
||||||
!pluginByName[plugin.name] ||
|
!pluginByName[plugin.name] ||
|
||||||
semver.gt(plugin.version, pluginByName[plugin.name].version, true)
|
(!process.env.FLIPPER_DISABLE_PLUGIN_AUTO_UPDATE &&
|
||||||
|
semver.gt(plugin.version, pluginByName[plugin.name].version, true))
|
||||||
) {
|
) {
|
||||||
pluginByName[plugin.name] = plugin;
|
pluginByName[plugin.name] = plugin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,11 @@ if (process.argv.includes('--no-embedded-plugins')) {
|
|||||||
if (process.argv.includes('--fast-refresh')) {
|
if (process.argv.includes('--fast-refresh')) {
|
||||||
process.env.FLIPPER_FAST_REFRESH = 'true';
|
process.env.FLIPPER_FAST_REFRESH = 'true';
|
||||||
}
|
}
|
||||||
|
// 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')) {
|
||||||
|
process.env.FLIPPER_DISABLE_PLUGIN_AUTO_UPDATE = 'true';
|
||||||
|
}
|
||||||
|
|
||||||
function launchElectron(port: number) {
|
function launchElectron(port: number) {
|
||||||
const entry = process.env.FLIPPER_FAST_REFRESH ? 'init-fast-refresh' : 'init';
|
const entry = process.env.FLIPPER_FAST_REFRESH ? 'init-fast-refresh' : 'init';
|
||||||
|
|||||||
Reference in New Issue
Block a user