Add --public-build option to start an OSS like build of Flipper

Summary: This diff adds the `--public-build` option which allows run a devServer emulating the OSS version of flipper. Technical details are explained in the comments.

Reviewed By: passy, nikoant

Differential Revision: D25944966

fbshipit-source-id: 540855808179582752b8aa646f0b8afd4b78396f
This commit is contained in:
Michel Weststrate
2021-01-18 06:45:17 -08:00
committed by Facebook GitHub Bot
parent 7a1717fa87
commit 9cdb36ec0e
3 changed files with 20 additions and 0 deletions

View File

@@ -81,6 +81,11 @@ const argv = yargs
'[FB-internal only] Release channel. "stable" by default. Setting env var "FLIPPER_RELEASE_CHANNEL" is equivalent.',
choices: ['stable', 'insiders'],
},
'public-build': {
describe:
'[FB-internal only] Will force using public sources only, to be able to iterate quickly on the public version. If sources are checked out from GitHub this is already the default. Setting env var "FLIPPER_FORCE_PUBLIC_BUILD" is equivalent.',
type: 'boolean',
},
})
.version('DEV')
.help()
@@ -108,6 +113,17 @@ if (argv['fast-refresh'] === true) {
delete process.env.FLIPPER_FAST_REFRESH;
}
if (argv['public-build'] === true) {
// we use a separate env var for forced_public builds, since
// FB_FLIPPER / isFB reflects whether we are running on FB sources / infra
// so changing that will not give the desired result (e.g. incorrect resolve paths, yarn installs)
// this variable purely overrides whether imports are from `fb` or `fb-stubs`
console.log('🐬 Emulating open source build of Flipper');
process.env.FLIPPER_FORCE_PUBLIC_BUILD = 'true';
} else if (argv['public-build'] === false) {
delete process.env.FLIPPER_FORCE_PUBLIC_BUILD;
}
// By default plugin auto-update is disabled in dev mode,
// but it is possible to enable it using this command line
// argument or env var.
@@ -217,6 +233,7 @@ async function startMetroServer(app: Express, server: http.Server) {
sourceExts: ['js', 'jsx', 'ts', 'tsx', 'json', 'mjs', 'cjs'],
},
watch: true,
cacheVersion: process.env.FLIPPER_FORCE_PUBLIC_BUILD,
});
const connectMiddleware = await Metro.createConnectMiddleware(config);
app.use(connectMiddleware.middleware);