From 9cdb36ec0ed8e82ebc00d9cd68fc34a6ba4d1d7d Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 18 Jan 2021 06:45:17 -0800 Subject: [PATCH] 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 --- desktop/babel-transformer/src/fb-stubs.ts | 1 + desktop/scripts/start-dev-server.ts | 17 +++++++++++++++++ docs/extending/dev-setup.mdx | 2 ++ 3 files changed, 20 insertions(+) diff --git a/desktop/babel-transformer/src/fb-stubs.ts b/desktop/babel-transformer/src/fb-stubs.ts index ac21a005a..fda2c1f66 100644 --- a/desktop/babel-transformer/src/fb-stubs.ts +++ b/desktop/babel-transformer/src/fb-stubs.ts @@ -22,6 +22,7 @@ module.exports = () => ({ visitor: { CallExpression(path: NodePath, state: any) { if ( + process.env.FLIPPER_FORCE_PUBLIC_BUILD !== 'true' && path.node.type === 'CallExpression' && path.node.callee.type === 'Identifier' && path.node.callee.name === 'require' && diff --git a/desktop/scripts/start-dev-server.ts b/desktop/scripts/start-dev-server.ts index 146ebd9f8..fccb95130 100644 --- a/desktop/scripts/start-dev-server.ts +++ b/desktop/scripts/start-dev-server.ts @@ -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); diff --git a/docs/extending/dev-setup.mdx b/docs/extending/dev-setup.mdx index 749950b84..6b9120008 100644 --- a/docs/extending/dev-setup.mdx +++ b/docs/extending/dev-setup.mdx @@ -86,6 +86,8 @@ yarn start Tip: start with `yarn start --fast-refresh` for experimental fast refresh. +Tip: start wih `yarn start --public-build` to preview changes for public builds. + Run `code-fb .` in the same directory to open an IDE to hack on Flipper.