Remove support for plugin format v1

Summary:
Do not list plugins packaged with format v1 in Plugin Manager.

Changelog: removed support for plugins packaged using legacy format (v1), so they won't appear in Plugin Manager anymore.

Reviewed By: passy

Differential Revision: D23681402

fbshipit-source-id: 1c9496ba6b739069d67228a0f4250f2f01aabd4d
This commit is contained in:
Anton Nikolaev
2020-09-16 06:30:20 -07:00
committed by Facebook GitHub Bot
parent e48707151a
commit 75e7261d1e
3 changed files with 6 additions and 90 deletions

View File

@@ -20,7 +20,7 @@ import {
addDisabledPlugins, addDisabledPlugins,
addFailedPlugins, addFailedPlugins,
} from '../reducers/plugins'; } from '../reducers/plugins';
import {ipcRenderer, shell} from 'electron'; import {ipcRenderer} from 'electron';
import GK from '../fb-stubs/GK'; import GK from '../fb-stubs/GK';
import {FlipperBasePlugin} from '../plugin'; import {FlipperBasePlugin} from '../plugin';
import {setupMenuBar} from '../MenuBar'; import {setupMenuBar} from '../MenuBar';
@@ -31,8 +31,6 @@ import {notNull} from '../utils/typeUtils';
import {sideEffect} from '../utils/sideEffect'; import {sideEffect} from '../utils/sideEffect';
import semver from 'semver'; import semver from 'semver';
import {PluginDetails} from 'flipper-plugin-lib'; import {PluginDetails} from 'flipper-plugin-lib';
import {addNotification} from '../reducers/notifications';
import styled from '@emotion/styled';
import {tryCatchReportPluginFailures, reportUsage} from '../utils/metrics'; import {tryCatchReportPluginFailures, reportUsage} from '../utils/metrics';
import * as FlipperPluginSDK from 'flipper-plugin'; import * as FlipperPluginSDK from 'flipper-plugin';
import Immer from 'immer'; import Immer from 'immer';
@@ -41,10 +39,6 @@ import Immer from 'immer';
import getPluginIndex from '../utils/getDefaultPluginsIndex'; import getPluginIndex from '../utils/getDefaultPluginsIndex';
import {SandyPluginDefinition} from 'flipper-plugin'; import {SandyPluginDefinition} from 'flipper-plugin';
const Paragraph = styled.p({
marginBottom: '0.1em',
});
export default (store: Store, logger: Logger) => { export default (store: Store, logger: Logger) => {
// expose Flipper and exact globally for dynamically loaded plugins // expose Flipper and exact globally for dynamically loaded plugins
const globalObject: any = typeof window === 'undefined' ? global : window; const globalObject: any = typeof window === 'undefined' ? global : window;
@@ -75,72 +69,6 @@ export default (store: Store, logger: Logger) => {
store.dispatch(addDisabledPlugins(disabledPlugins)); store.dispatch(addDisabledPlugins(disabledPlugins));
store.dispatch(addFailedPlugins(failedPlugins)); store.dispatch(addFailedPlugins(failedPlugins));
store.dispatch(registerPlugins(initialPlugins)); store.dispatch(registerPlugins(initialPlugins));
const deprecatedSpecPlugins = initialPlugins.filter(
(p) => !p.isDefault && p.details.specVersion === 1,
);
for (const plugin of deprecatedSpecPlugins) {
store.dispatch(
addNotification({
pluginId: plugin.id,
client: null,
notification: {
id: `plugin-spec-v1-deprecation-${plugin.packageName}`,
title: `Plugin "${plugin.title}" will stop working after version 0.48 of Flipper released, because it is packaged using the deprecated format.`,
message: (
<>
<Paragraph>
Please try to install a newer version of this plugin packaged
using "Install Plugins" tab on "Manage Plugins" form.
</Paragraph>
<Paragraph>
If the latest version of the plugin is still packaged in the old
format, please contact the author and consider raising a pull
request for upgrading the plugin. You can find contact details
on the package page&nbsp;
<a
href={`#`}
onClick={() =>
shell.openExternal(
`https://www.npmjs.com/package/${plugin.packageName}`,
)
}>
https://www.npmjs.com/package/{plugin.packageName}
</a>
.
</Paragraph>
<Paragraph>
If you are the author of this plugin, please migrate your plugin
to the new format, and publish new version of it. See&nbsp;
<a
href={`#`}
onClick={() =>
shell.openExternal(
'https://fbflipper.com/docs/extending/js-setup#migration-to-the-new-plugin-specification',
)
}>
https://fbflipper.com/docs/extending/js-setup#migration-to-the-new-plugin-specification
</a>
&nbsp;on how to migrate the plugin. See&nbsp;
<a
href={`#`}
onClick={() =>
shell.openExternal(
'https://fbflipper.com/docs/extending/js-setup#package-format',
)
}>
https://fbflipper.com/docs/extending/js-setup#package-format
</a>
&nbsp;for details on plugin package format.
</Paragraph>
</>
),
severity: 'error',
timestamp: Date.now(),
category: `Plugin Spec V1 Deprecation`,
},
}),
);
}
sideEffect( sideEffect(
store, store,

View File

@@ -91,6 +91,9 @@ export async function getUpdatablePlugins(): Promise<UpdatablePluginDetails[]> {
getPluginInstallationDir(notInstalledPlugin.name), getPluginInstallationDir(notInstalledPlugin.name),
pkg, pkg,
); );
if (npmPluginDetails.specVersion === 1) {
return null;
}
return { return {
...npmPluginDetails, ...npmPluginDetails,
updateStatus: { updateStatus: {

View File

@@ -25,12 +25,6 @@ import semver from 'semver';
const getTmpDir = promisify(tmp.dir) as () => Promise<string>; const getTmpDir = promisify(tmp.dir) as () => Promise<string>;
function providePluginManager(): PM {
return new PM({
ignoredDependencies: [/^flipper$/, /^react$/, /^react-dom$/, /^@types\//],
});
}
function providePluginManagerNoDependencies(): PM { function providePluginManagerNoDependencies(): PM {
return new PM({ignoredDependencies: [/.*/]}); return new PM({ignoredDependencies: [/.*/]});
} }
@@ -70,18 +64,9 @@ async function installPluginFromTempDir(
const destinationDir = getPluginPendingInstallationDir(name, version); const destinationDir = getPluginPendingInstallationDir(name, version);
if (pluginDetails.specVersion == 1) { if (pluginDetails.specVersion == 1) {
// For first version of spec we need to install dependencies throw new Error(
const pluginManager = providePluginManager(); `Cannot install plugin ${pluginDetails.name} because it is packaged using the unsupported format v1. Please encourage the plugin author to update to v2, following the instructions on https://fbflipper.com/docs/extending/js-setup#migration-to-the-new-plugin-specification`,
// install the plugin dependencies into node_modules
const nodeModulesDir = path.join(
await getTmpDir(),
`${name}-${version}-modules`,
); );
pluginManager.options.pluginsPath = nodeModulesDir;
await pluginManager.installFromPath(sourceDir);
// live-plugin-manager also installs plugin itself into the target dir, it's better remove it
await fs.remove(path.join(nodeModulesDir, name));
await fs.move(nodeModulesDir, path.join(sourceDir, 'node_modules'));
} }
try { try {