Rebuild all plugins if a shared lib changed
Summary: Some plugins import from shared directories. These directories are not plugins themselves, therefore the current plugin root searching mechanism does nto work for them. To support plugin reloading for this scenario, we start re-building all plugins if we fail to find a plugin root. Reviewed By: lblasa Differential Revision: D39693820 fbshipit-source-id: 33dd7de4121bd5665a39b0ea96adce4603dc7df0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
6889446bc5
commit
fd811db12b
@@ -18,7 +18,8 @@
|
||||
"metro": "^0.70.2",
|
||||
"metro-cache": "^0.70.2",
|
||||
"metro-minify-terser": "^0.70.2",
|
||||
"npm-packlist": "^4.0.0"
|
||||
"npm-packlist": "^4.0.0",
|
||||
"p-map": "^4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/fs-extra": "^9.0.13",
|
||||
|
||||
54
desktop/pkg-lib/src/buildDefaultPlugins.tsx
Normal file
54
desktop/pkg-lib/src/buildDefaultPlugins.tsx
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and 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 {InstalledPluginDetails} from 'flipper-common';
|
||||
import pMap from 'p-map';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import runBuild from './runBuild';
|
||||
|
||||
const defaultPluginsDir = path.join(__dirname, '../../static/defaultPlugins');
|
||||
|
||||
export async function buildDefaultPlugins(
|
||||
defaultPlugins: InstalledPluginDetails[],
|
||||
dev: boolean,
|
||||
) {
|
||||
if (process.env.FLIPPER_NO_REBUILD_PLUGINS) {
|
||||
console.log(
|
||||
`⚙️ Including ${
|
||||
defaultPlugins.length
|
||||
} plugins into the default plugins list. Skipping rebuilding because "no-rebuild-plugins" option provided. List of default plugins: ${defaultPlugins
|
||||
.map((p) => p.id)
|
||||
.join(', ')}`,
|
||||
);
|
||||
}
|
||||
await pMap(
|
||||
defaultPlugins,
|
||||
async function (plugin) {
|
||||
try {
|
||||
if (!process.env.FLIPPER_NO_REBUILD_PLUGINS) {
|
||||
console.log(
|
||||
`⚙️ Building plugin ${plugin.id} to include it into the default plugins list...`,
|
||||
);
|
||||
await runBuild(plugin.dir, dev);
|
||||
}
|
||||
await fs.ensureSymlink(
|
||||
plugin.dir,
|
||||
path.join(defaultPluginsDir, plugin.name),
|
||||
'junction',
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(`✖ Failed to build plugin ${plugin.id}`, err);
|
||||
}
|
||||
},
|
||||
{
|
||||
concurrency: 16,
|
||||
},
|
||||
);
|
||||
}
|
||||
43
desktop/pkg-lib/src/getDefaultPlugins.tsx
Normal file
43
desktop/pkg-lib/src/getDefaultPlugins.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and 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 {getSourcePlugins} from 'flipper-plugin-lib';
|
||||
|
||||
// For insiders builds we bundle top 5 popular device plugins,
|
||||
// plus top 10 popular "universal" plugins enabled by more than 100 users.
|
||||
const hardcodedPlugins = new Set<string>([
|
||||
// Popular device plugins
|
||||
'DeviceLogs',
|
||||
'CrashReporter',
|
||||
'MobileBuilds',
|
||||
'Hermesdebuggerrn',
|
||||
'React',
|
||||
// Popular client plugins
|
||||
'Inspector',
|
||||
'Network',
|
||||
'AnalyticsLogging',
|
||||
'GraphQL',
|
||||
'UIPerf',
|
||||
'MobileConfig',
|
||||
'Databases',
|
||||
'FunnelLogger',
|
||||
'Navigation',
|
||||
'Fresco',
|
||||
'Preferences',
|
||||
]);
|
||||
|
||||
export const getDefaultPlugins = async (isInsidersBuild: boolean) => {
|
||||
const sourcePlugins = await getSourcePlugins();
|
||||
const defaultPlugins = sourcePlugins
|
||||
// we only include headless plugins and a predefined set of regular plugins into insiders release
|
||||
.filter(
|
||||
(p) => !isInsidersBuild || hardcodedPlugins.has(p.id) || p.headless,
|
||||
);
|
||||
return defaultPlugins;
|
||||
};
|
||||
@@ -13,3 +13,5 @@ export {default as computePackageChecksum} from './computePackageChecksum';
|
||||
export {default as stripSourceMapComment} from './stripSourceMap';
|
||||
export {default as startWatchPlugins} from './startWatchPlugins';
|
||||
export {default as Watchman} from './watchman';
|
||||
export {buildDefaultPlugins} from './buildDefaultPlugins';
|
||||
export {getDefaultPlugins} from './getDefaultPlugins';
|
||||
|
||||
@@ -17,6 +17,8 @@ import path from 'path';
|
||||
import chalk from 'chalk';
|
||||
import runBuild from './runBuild';
|
||||
import {InstalledPluginDetails} from 'flipper-common';
|
||||
import {getDefaultPlugins} from './getDefaultPlugins';
|
||||
import {buildDefaultPlugins} from './buildDefaultPlugins';
|
||||
|
||||
async function rebuildPlugin(pluginPath: string) {
|
||||
try {
|
||||
@@ -33,6 +35,7 @@ async function rebuildPlugin(pluginPath: string) {
|
||||
}
|
||||
|
||||
export default async function startWatchPlugins(
|
||||
isInsidersBuild: boolean,
|
||||
onChanged?: (
|
||||
changedPlugins: InstalledPluginDetails[],
|
||||
) => void | Promise<void>,
|
||||
@@ -48,36 +51,46 @@ export default async function startWatchPlugins(
|
||||
delayedCompilation = undefined;
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`🕵️ Detected plugin change`);
|
||||
const changedDirs = await Promise.all(
|
||||
// https://facebook.github.io/watchman/docs/nodejs.html#subscribing-to-changes
|
||||
files.map(async (file: string) => {
|
||||
const filePathAbs = path.resolve(root, file);
|
||||
let dirPath = path.dirname(filePathAbs);
|
||||
while (
|
||||
// Stop when we reach plugin root
|
||||
!(await isPluginDir(dirPath))
|
||||
) {
|
||||
const relative = path.relative(root, dirPath);
|
||||
// Stop when we reach desktop/plugins folder
|
||||
if (!relative || relative.startsWith('..')) {
|
||||
console.warn(
|
||||
chalk.yellow('Failed to find a plugin root for path'),
|
||||
filePathAbs,
|
||||
);
|
||||
return;
|
||||
try {
|
||||
const changedDirs = await Promise.all(
|
||||
// https://facebook.github.io/watchman/docs/nodejs.html#subscribing-to-changes
|
||||
files.map(async (file: string) => {
|
||||
const filePathAbs = path.resolve(root, file);
|
||||
let dirPath = path.dirname(filePathAbs);
|
||||
while (
|
||||
// Stop when we reach plugin root
|
||||
!(await isPluginDir(dirPath))
|
||||
) {
|
||||
const relative = path.relative(root, dirPath);
|
||||
// Stop when we reach desktop/plugins folder
|
||||
if (!relative || relative.startsWith('..')) {
|
||||
console.info(
|
||||
chalk.yellow(
|
||||
'Failed to find a plugin root for path. Rebuilding all plugins',
|
||||
),
|
||||
filePathAbs,
|
||||
);
|
||||
throw new Error('REBUILD_ALL');
|
||||
}
|
||||
dirPath = path.resolve(dirPath, '..');
|
||||
}
|
||||
dirPath = path.resolve(dirPath, '..');
|
||||
}
|
||||
await rebuildPlugin(dirPath);
|
||||
return dirPath;
|
||||
}),
|
||||
);
|
||||
const changedPlugins = await Promise.all(
|
||||
changedDirs
|
||||
.filter((dirPath): dirPath is string => !!dirPath)
|
||||
.map((dirPath) => getInstalledPluginDetails(dirPath)),
|
||||
);
|
||||
onChanged?.(changedPlugins);
|
||||
await rebuildPlugin(dirPath);
|
||||
return dirPath;
|
||||
}),
|
||||
);
|
||||
const changedPlugins = await Promise.all(
|
||||
changedDirs.map((dirPath) => getInstalledPluginDetails(dirPath)),
|
||||
);
|
||||
onChanged?.(changedPlugins);
|
||||
} catch (e) {
|
||||
if (e instanceof Error && e.message === 'REBUILD_ALL') {
|
||||
const defaultPlugins = await getDefaultPlugins(isInsidersBuild);
|
||||
await buildDefaultPlugins(defaultPlugins, true);
|
||||
onChanged?.(defaultPlugins);
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}, kCompilationDelayMillis);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user