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
This commit is contained in:
Michel Weststrate
2021-12-24 07:15:15 -08:00
committed by Facebook GitHub Bot
parent a3500c453b
commit 521ef9e243

View File

@@ -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'),