From e1aefadb32b7c2d100854b5493cfb6e73523bd0d Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Wed, 4 Sep 2019 11:24:10 -0700 Subject: [PATCH] [Scheduler] Add "combined" www build The Scheduler module in www is loaded before most of our other infra: too early to conditionally load a separate build in production versus development. Which means we're currently sending both a prod and dev bundle to every single user. We should fix this on the Facebook infra side, but in the meantime, this updates the build script to generate a new type of bundle, `FB_WWW_COMBINED`, which preserves __DEV__ conditions. --- .../src/forks/SchedulerFeatureFlags.www.js | 3 +- scripts/rollup/build.js | 29 +++++++++++++++---- scripts/rollup/bundles.js | 19 +++--------- scripts/rollup/forks.js | 9 +++--- scripts/rollup/packaging.js | 2 ++ scripts/rollup/wrappers.js | 14 +++++++++ 6 files changed, 48 insertions(+), 28 deletions(-) diff --git a/packages/scheduler/src/forks/SchedulerFeatureFlags.www.js b/packages/scheduler/src/forks/SchedulerFeatureFlags.www.js index 360be98e603f..c2479caf8096 100644 --- a/packages/scheduler/src/forks/SchedulerFeatureFlags.www.js +++ b/packages/scheduler/src/forks/SchedulerFeatureFlags.www.js @@ -12,6 +12,5 @@ export const { requestIdleCallbackBeforeFirstFrame, requestTimerEventBeforeFirstFrame, enableMessageLoopImplementation, + enableProfiling, } = require('SchedulerFeatureFlags'); - -export const enableProfiling = __PROFILE__; diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index af98240c927d..fa684a40aa02 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -45,6 +45,7 @@ const { FB_WWW_DEV, FB_WWW_PROD, FB_WWW_PROFILING, + FB_WWW_COMBINED, RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING, @@ -111,6 +112,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) { case FB_WWW_DEV: case FB_WWW_PROD: case FB_WWW_PROFILING: + case FB_WWW_COMBINED: return Object.assign({}, options, { plugins: options.plugins.concat([ // Minify invariant messages @@ -192,6 +194,7 @@ function getFormat(bundleType) { case FB_WWW_DEV: case FB_WWW_PROD: case FB_WWW_PROFILING: + case FB_WWW_COMBINED: case RN_OSS_DEV: case RN_OSS_PROD: case RN_OSS_PROFILING: @@ -230,6 +233,8 @@ function getFilename(name, globalName, bundleType) { case RN_FB_PROFILING: case RN_OSS_PROFILING: return `${globalName}-profiling.js`; + case FB_WWW_COMBINED: + return `${globalName}-combined.js`; } } @@ -238,6 +243,7 @@ function isProductionBundleType(bundleType) { case UMD_DEV: case NODE_DEV: case FB_WWW_DEV: + case FB_WWW_COMBINED: case RN_OSS_DEV: case RN_FB_DEV: return false; @@ -261,6 +267,7 @@ function isProfilingBundleType(bundleType) { switch (bundleType) { case FB_WWW_DEV: case FB_WWW_PROD: + case FB_WWW_COMBINED: case NODE_DEV: case NODE_PROD: case RN_FB_DEV: @@ -326,6 +333,20 @@ function getPlugins( bundleType === RN_FB_PROD || bundleType === RN_FB_PROFILING; const shouldStayReadable = isFBBundle || isRNBundle || forcePrettyOutput; + + const replaceConfig = { + __PROFILE__: isProfiling || !isProduction ? 'true' : 'false', + __UMD__: isUMDBundle ? 'true' : 'false', + 'process.env.NODE_ENV': isProduction ? "'production'" : "'development'", + }; + + if (bundleType !== FB_WWW_COMBINED) { + // Turn __DEV__ and process.env checks into constants so the dev-only + // branches can be dead code eliminated in the prod bundles. Except for the + // FB_WWW_COMBINED bundle type, which runs in both dev and prod. + replaceConfig.__DEV__ = isProduction ? 'false' : 'true'; + } + return [ // Extract error codes from invariant() messages into a file. shouldExtractErrors && { @@ -355,12 +376,7 @@ function getPlugins( }, }, // Turn __DEV__ and process.env checks into constants. - replace({ - __DEV__: isProduction ? 'false' : 'true', - __PROFILE__: isProfiling || !isProduction ? 'true' : 'false', - __UMD__: isUMDBundle ? 'true' : 'false', - 'process.env.NODE_ENV': isProduction ? "'production'" : "'development'", - }), + replace(replaceConfig), // We still need CommonJS for external deps like object-assign. commonjs(), // Apply dead code elimination and/or minification. @@ -648,6 +664,7 @@ async function buildEverything() { [bundle, FB_WWW_DEV], [bundle, FB_WWW_PROD], [bundle, FB_WWW_PROFILING], + [bundle, FB_WWW_COMBINED], [bundle, RN_OSS_DEV], [bundle, RN_OSS_PROD], [bundle, RN_OSS_PROFILING], diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index 0c9c659f6ee2..8a764f872a8a 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -10,6 +10,7 @@ const bundleTypes = { FB_WWW_DEV: 'FB_WWW_DEV', FB_WWW_PROD: 'FB_WWW_PROD', FB_WWW_PROFILING: 'FB_WWW_PROFILING', + FB_WWW_COMBINED: 'FB_WWW_COMBINED', RN_OSS_DEV: 'RN_OSS_DEV', RN_OSS_PROD: 'RN_OSS_PROD', RN_OSS_PROFILING: 'RN_OSS_PROFILING', @@ -28,6 +29,7 @@ const { FB_WWW_DEV, FB_WWW_PROD, FB_WWW_PROFILING, + FB_WWW_COMBINED, RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING, @@ -411,13 +413,7 @@ const bundles = [ /******* React Scheduler (experimental) *******/ { - bundleTypes: [ - NODE_DEV, - NODE_PROD, - FB_WWW_DEV, - FB_WWW_PROD, - FB_WWW_PROFILING, - ], + bundleTypes: [NODE_DEV, NODE_PROD, FB_WWW_COMBINED], moduleType: ISOMORPHIC, entry: 'scheduler', global: 'Scheduler', @@ -426,14 +422,7 @@ const bundles = [ /******* React Scheduler Mock (experimental) *******/ { - bundleTypes: [ - UMD_DEV, - UMD_PROD, - NODE_DEV, - NODE_PROD, - FB_WWW_DEV, - FB_WWW_PROD, - ], + bundleTypes: [UMD_DEV, UMD_PROD, NODE_DEV, NODE_PROD, FB_WWW_COMBINED], moduleType: ISOMORPHIC, entry: 'scheduler/unstable_mock', global: 'SchedulerMock', diff --git a/scripts/rollup/forks.js b/scripts/rollup/forks.js index ac217405dbbf..01d6d8359745 100644 --- a/scripts/rollup/forks.js +++ b/scripts/rollup/forks.js @@ -10,6 +10,7 @@ const UMD_PROFILING = bundleTypes.UMD_PROFILING; const FB_WWW_DEV = bundleTypes.FB_WWW_DEV; const FB_WWW_PROD = bundleTypes.FB_WWW_PROD; const FB_WWW_PROFILING = bundleTypes.FB_WWW_PROFILING; +const FB_WWW_COMBINED = bundleTypes.FB_WWW_COMBINED; const RN_OSS_DEV = bundleTypes.RN_OSS_DEV; const RN_OSS_PROD = bundleTypes.RN_OSS_PROD; const RN_OSS_PROFILING = bundleTypes.RN_OSS_PROFILING; @@ -158,11 +159,7 @@ const forks = Object.freeze({ }, 'scheduler/src/SchedulerFeatureFlags': (bundleType, entry, dependencies) => { - if ( - bundleType === FB_WWW_DEV || - bundleType === FB_WWW_PROD || - bundleType === FB_WWW_PROFILING - ) { + if (bundleType === FB_WWW_COMBINED) { return 'scheduler/src/forks/SchedulerFeatureFlags.www.js'; } return 'scheduler/src/SchedulerFeatureFlags'; @@ -186,6 +183,7 @@ const forks = Object.freeze({ case FB_WWW_DEV: case FB_WWW_PROD: case FB_WWW_PROFILING: + case FB_WWW_COMBINED: return 'shared/forks/lowPriorityWarning.www.js'; default: return null; @@ -198,6 +196,7 @@ const forks = Object.freeze({ case FB_WWW_DEV: case FB_WWW_PROD: case FB_WWW_PROFILING: + case FB_WWW_COMBINED: return 'shared/forks/warningWithoutStack.www.js'; default: return null; diff --git a/scripts/rollup/packaging.js b/scripts/rollup/packaging.js index 840e290f23c1..1fe1f9a85b7a 100644 --- a/scripts/rollup/packaging.js +++ b/scripts/rollup/packaging.js @@ -19,6 +19,7 @@ const { FB_WWW_DEV, FB_WWW_PROD, FB_WWW_PROFILING, + FB_WWW_COMBINED, RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING, @@ -50,6 +51,7 @@ function getBundleOutputPaths(bundleType, filename, packageName) { case FB_WWW_DEV: case FB_WWW_PROD: case FB_WWW_PROFILING: + case FB_WWW_COMBINED: return [`build/facebook-www/${filename}`]; case RN_OSS_DEV: case RN_OSS_PROD: diff --git a/scripts/rollup/wrappers.js b/scripts/rollup/wrappers.js index b80e77121fb8..63e808898ea4 100644 --- a/scripts/rollup/wrappers.js +++ b/scripts/rollup/wrappers.js @@ -12,6 +12,7 @@ const NODE_PROFILING = Bundles.bundleTypes.NODE_PROFILING; const FB_WWW_DEV = Bundles.bundleTypes.FB_WWW_DEV; const FB_WWW_PROD = Bundles.bundleTypes.FB_WWW_PROD; const FB_WWW_PROFILING = Bundles.bundleTypes.FB_WWW_PROFILING; +const FB_WWW_COMBINED = Bundles.bundleTypes.FB_WWW_COMBINED; const RN_OSS_DEV = Bundles.bundleTypes.RN_OSS_DEV; const RN_OSS_PROD = Bundles.bundleTypes.RN_OSS_PROD; const RN_OSS_PROFILING = Bundles.bundleTypes.RN_OSS_PROFILING; @@ -167,6 +168,19 @@ ${license} * @preserve-invariant-messages */ +${source}`; + }, + + /****************** FB_WWW_COMBINED ******************/ + [FB_WWW_COMBINED](source, globalName, filename, moduleType) { + return `/** +${license} + * + * @noflow + * @preventMunge + * @preserve-invariant-messages + */ + ${source}`; },