Make plugin loading async
Summary: This diff makes plugin loading async, which we'd need in a browser env (either because we'd use `import()` or we need to fetch the source and than eval it), and deals with all the fallout of that Reviewed By: timur-valiev Differential Revision: D32669995 fbshipit-source-id: 73babf38a6757c451b8200c3b320409f127b8b5b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
64747dc417
commit
de59bbedd2
@@ -25,6 +25,7 @@ export {
|
||||
reportPlatformFailures,
|
||||
reportUsage,
|
||||
reportPluginFailures,
|
||||
tryCatchReportPluginFailuresAsync,
|
||||
tryCatchReportPlatformFailures,
|
||||
tryCatchReportPluginFailures,
|
||||
UnsupportedError,
|
||||
|
||||
@@ -169,6 +169,7 @@ export type FlipperServerCommands = {
|
||||
'plugin-start-download': (
|
||||
plugin: DownloadablePluginDetails,
|
||||
) => Promise<InstalledPluginDetails>;
|
||||
'plugin-source': (path: string) => Promise<string>;
|
||||
'plugins-install-from-npm': (name: string) => Promise<InstalledPluginDetails>;
|
||||
'plugins-install-from-file': (
|
||||
path: string,
|
||||
|
||||
@@ -134,6 +134,29 @@ export function tryCatchReportPluginFailures<T>(
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Wraps a closure, preserving it's functionality but logging the success or
|
||||
failure state of it.
|
||||
*/
|
||||
export async function tryCatchReportPluginFailuresAsync<T>(
|
||||
closure: () => Promise<T>,
|
||||
name: string,
|
||||
plugin: string,
|
||||
): Promise<T> {
|
||||
try {
|
||||
const result = await closure();
|
||||
logPluginSuccessRate(name, plugin, {kind: 'success'});
|
||||
return result;
|
||||
} catch (e) {
|
||||
logPluginSuccessRate(name, plugin, {
|
||||
kind: 'failure',
|
||||
supportedOperation: !(e instanceof UnsupportedError),
|
||||
error: e,
|
||||
});
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Track usage of a feature.
|
||||
* @param action Unique name for the action performed. E.g. captureScreenshot
|
||||
|
||||
Reference in New Issue
Block a user