From 521ef9e243e4a400ae83e77668faba1360347ed3 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Fri, 24 Dec 2021 07:15:15 -0800 Subject: [PATCH] Check plugin entry points before bundling them stripped Summary: When packaging plugins into flipper-server package, we assume an idiomatic plugin structure, warn and skip if a plugin doesn't conform to it. Reviewed By: antonk52 Differential Revision: D33308367 fbshipit-source-id: fd6d1dbc66739b0867034930579429e97d9e2bfa --- desktop/scripts/build-flipper-server-release.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/desktop/scripts/build-flipper-server-release.ts b/desktop/scripts/build-flipper-server-release.ts index 78bad2290..2b3c7685d 100644 --- a/desktop/scripts/build-flipper-server-release.ts +++ b/desktop/scripts/build-flipper-server-release.ts @@ -136,6 +136,18 @@ async function copyStaticResources(outDir: string) { } const target = path.join(outDir, 'static', 'defaultPlugins', plugin); if ((await fs.stat(source)).isDirectory()) { + // Verify it safe to strip the package down, does it have the + // typical flipper plugin structure? + const packageJson = JSON.parse( + await fs.readFile(path.join(source, 'package.json'), 'utf8'), + ); + if (packageJson.main !== 'dist/bundle.js') { + console.error( + `Cannot bundle plugin '${source}', the main entry point is '${packageJson.main}', but expected 'dist/bundle.js'`, + ); + continue; + } + // for plugins, only copy package.json & dist, to keep impact minimal await fs.copy( path.join(source, 'package.json'),