Make sure plugin loading works in NPX builds

Summary: Make sure non-bundled plugins load correctly . Note that sourcemaps don't load yet

Reviewed By: nikoant

Differential Revision: D33278639

fbshipit-source-id: 9951286ec6df65f33149e4687261a43e6c072c31
This commit is contained in:
Michel Weststrate
2021-12-24 02:15:25 -08:00
committed by Facebook GitHub Bot
parent 86b6d2c99d
commit b1d960e4c4
3 changed files with 14 additions and 16 deletions

View File

@@ -61,8 +61,11 @@ export function initializeRenderHost(
async requirePlugin(path) { async requirePlugin(path) {
// TODO: use `await import(path)`? // TODO: use `await import(path)`?
const source = await flipperServer.exec('plugin-source', path); const source = await flipperServer.exec('plugin-source', path);
// eslint-disable-next-line no-eval // eslint-disable-next-line no-new-func
return eval(source); const cjsLoader = new Function('module', source);
const theModule = {exports: {}};
cjsLoader(theModule);
return theModule.exports;
}, },
getStaticResourceUrl(path): string { getStaticResourceUrl(path): string {
// the 'static' folder is mounted as static middleware in Express at the root // the 'static' folder is mounted as static middleware in Express at the root

View File

@@ -46,6 +46,11 @@ const argv = yargs
type: 'boolean', type: 'boolean',
default: true, default: true,
}, },
'enabled-plugins': {
describe:
'Load only specified plugins and skip loading rest. This is useful when you are developing only one or few plugins. Plugins to load can be specified as a comma-separated list with either plugin id or name used as identifier, e.g. "--enabled-plugins network,inspector". The flag is not provided by default which means that all plugins loaded.',
type: 'array',
},
}) })
.version('DEV') .version('DEV')
.help() .help()
@@ -76,6 +81,10 @@ if (argv['public-build'] === true) {
delete process.env.FLIPPER_FORCE_PUBLIC_BUILD; delete process.env.FLIPPER_FORCE_PUBLIC_BUILD;
} }
if (argv['enabled-plugins'] !== undefined) {
process.env.FLIPPER_ENABLED_PLUGINS = argv['enabled-plugins'].join(',');
}
(async () => { (async () => {
console.log(`⚙️ Starting build-flipper-server-release`); console.log(`⚙️ Starting build-flipper-server-release`);

View File

@@ -57,26 +57,12 @@
</div> </div>
<script src="/socket.io/socket.io.js"></script>
<script> <script>
(function() { (function() {
// FIXME: needed to make Metro work // FIXME: needed to make Metro work
window.global = window; window.global = window;
let suppressErrors = false; let suppressErrors = false;
const socket = io(location.origin);
socket.on('refresh', () => {
location.reload();
});
socket.on('hasErrors', (html) => {
openError(html);
suppressErrors = true;
});
function openError(text) { function openError(text) {
if (suppressErrors) { if (suppressErrors) {
return; return;