Remove default plugin entrypoints for hot-reloading
Summary: As we stopped bundling plugins in D39276249, we no longer need the entry points for the bundled plugins (these entry points are always going to be empty) Reviewed By: lblasa Differential Revision: D39307565 fbshipit-source-id: 43751fe31c8bd962677c226b27cfe52093d3f2d4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
94df830dfb
commit
642a3ebf81
@@ -24,10 +24,7 @@ import {
|
||||
} from 'flipper-pkg-lib';
|
||||
import getAppWatchFolders from './get-app-watch-folders';
|
||||
import {getSourcePlugins, getPluginSourceFolders} from 'flipper-plugin-lib';
|
||||
import type {
|
||||
BundledPluginDetails,
|
||||
InstalledPluginDetails,
|
||||
} from 'flipper-common';
|
||||
import type {InstalledPluginDetails} from 'flipper-common';
|
||||
import {
|
||||
appDir,
|
||||
staticDir,
|
||||
@@ -41,8 +38,6 @@ import pFilter from 'p-filter';
|
||||
import child from 'child_process';
|
||||
import pMap from 'p-map';
|
||||
|
||||
// eslint-disable-next-line flipper/no-relative-imports-across-packages
|
||||
const {version} = require('../package.json');
|
||||
const dev = process.env.NODE_ENV !== 'production';
|
||||
|
||||
// For insiders builds we bundle top 5 popular device plugins,
|
||||
@@ -90,7 +85,6 @@ export async function prepareDefaultPlugins(isInsidersBuild: boolean = false) {
|
||||
dereference: true,
|
||||
});
|
||||
console.log('✅ Copied the provided default plugins dir.');
|
||||
await generateDefaultPluginEntryPoints([]); // calling it here just to generate empty indexes
|
||||
} else {
|
||||
const sourcePlugins = process.env.FLIPPER_NO_DEFAULT_PLUGINS
|
||||
? []
|
||||
@@ -100,9 +94,6 @@ export async function prepareDefaultPlugins(isInsidersBuild: boolean = false) {
|
||||
.filter((p) => !isInsidersBuild || hardcodedPlugins.has(p.id));
|
||||
if (process.env.FLIPPER_NO_BUNDLED_PLUGINS) {
|
||||
await buildDefaultPlugins(defaultPlugins);
|
||||
await generateDefaultPluginEntryPoints([]); // calling it here just to generate empty indexes
|
||||
} else {
|
||||
await generateDefaultPluginEntryPoints(defaultPlugins);
|
||||
}
|
||||
}
|
||||
console.log('✅ Prepared default plugins.');
|
||||
@@ -123,69 +114,6 @@ export async function buildServerAddOns(dev: boolean) {
|
||||
await Promise.all(serverAddOns.map((p) => runBuild(p.dir, dev)));
|
||||
console.log('✅ Built plugins with server add-ons plugins.');
|
||||
}
|
||||
|
||||
function getGeneratedIndex(pluginRequires: string) {
|
||||
return `
|
||||
/* eslint-disable */
|
||||
// THIS FILE IS AUTO-GENERATED by function "generateDefaultPluginEntryPoints" in "build-utils.ts".
|
||||
|
||||
declare const require: any;
|
||||
|
||||
// This function exists to make sure that if one require fails in its module initialisation, not everything fails
|
||||
function tryRequire(module: string, fn: () => any): any {
|
||||
try {
|
||||
return fn();
|
||||
} catch (e) {
|
||||
console.error(\`Could not require \${module}: \`, e)
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export default {\n${pluginRequires}\n} as any
|
||||
`;
|
||||
}
|
||||
|
||||
async function generateDefaultPluginEntryPoints(
|
||||
defaultPlugins: InstalledPluginDetails[],
|
||||
) {
|
||||
console.log(
|
||||
`⚙️ Generating entry points for ${defaultPlugins.length} bundled plugins...`,
|
||||
);
|
||||
const bundledPlugins = defaultPlugins.map(
|
||||
(p) =>
|
||||
({
|
||||
...p,
|
||||
isBundled: true,
|
||||
version: p.version === '0.0.0' ? version : p.version,
|
||||
flipperSDKVersion:
|
||||
p.flipperSDKVersion === '0.0.0' ? version : p.flipperSDKVersion,
|
||||
dir: undefined,
|
||||
entry: undefined,
|
||||
serverAddOnEntry: undefined,
|
||||
} as BundledPluginDetails),
|
||||
);
|
||||
|
||||
const pluginRequires = bundledPlugins
|
||||
.map(
|
||||
(x) =>
|
||||
` '${x.name}': tryRequire('${x.name}', () => require('${x.name}'))`,
|
||||
)
|
||||
.join(',\n');
|
||||
const generatedIndex = getGeneratedIndex(pluginRequires);
|
||||
await fs.ensureDir(path.join(appDir, 'src', 'defaultPlugins'));
|
||||
await fs.writeFile(
|
||||
path.join(appDir, 'src', 'defaultPlugins', 'index.tsx'),
|
||||
generatedIndex,
|
||||
);
|
||||
await fs.ensureDir(path.join(browserUiDir, 'src', 'defaultPlugins'));
|
||||
await fs.writeFile(
|
||||
path.join(browserUiDir, 'src', 'defaultPlugins', 'index.tsx'),
|
||||
generatedIndex,
|
||||
);
|
||||
|
||||
console.log('✅ Generated bundled plugin entry points.');
|
||||
}
|
||||
|
||||
async function buildDefaultPlugins(defaultPlugins: InstalledPluginDetails[]) {
|
||||
if (process.env.FLIPPER_NO_REBUILD_PLUGINS) {
|
||||
console.log(
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
/* eslint-disable flipper/no-console-error-without-context */
|
||||
|
||||
import {prepareDefaultPlugins} from './build-utils';
|
||||
|
||||
prepareDefaultPlugins().catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -181,9 +181,6 @@ function createStubRenderHost(): RenderHost {
|
||||
restartFlipper() {},
|
||||
openLink() {},
|
||||
serverConfig: stubConfig,
|
||||
loadDefaultPlugins() {
|
||||
return {};
|
||||
},
|
||||
GK(gk: string) {
|
||||
return stubConfig.gatekeepers[gk] ?? false;
|
||||
},
|
||||
|
||||
35
desktop/scripts/remove-plugin-entry-points.tsx
Normal file
35
desktop/scripts/remove-plugin-entry-points.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
/* eslint-disable flipper/no-console-error-without-context */
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import {rootDir} from './paths';
|
||||
|
||||
// TODO: Remove me in 2023 when everyone who is building flipper from source have legacy plugin entry points removed by this script
|
||||
|
||||
(async () => {
|
||||
await Promise.all(
|
||||
[
|
||||
path.resolve(rootDir, 'app/src/defaultPlugins'),
|
||||
path.resolve(rootDir, 'flipper-server-companion/src/defaultPlugins'),
|
||||
path.resolve(rootDir, 'flipper-server-core/src/defaultPlugins'),
|
||||
path.resolve(rootDir, 'flipper-ui-browser/src/defaultPlugins'),
|
||||
].map((dir) =>
|
||||
fs.rm(dir, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
}),
|
||||
),
|
||||
);
|
||||
})().catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user