diff --git a/.eslintrc.js b/.eslintrc.js index e4b8d27b29e13..27147d2d0ef0c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -81,5 +81,6 @@ module.exports = { spyOnDev: true, spyOnDevAndProd: true, spyOnProd: true, + __PROFILE__: true, }, }; diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index 91ebce8c09d87..31aad39f146b6 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -37,7 +37,7 @@ export const warnAboutDeprecatedLifecycles = false; export const warnAboutLegacyContextAPI = false; // Gather advanced timing metrics for Profiler subtrees. -export const enableProfilerTimer = __DEV__; +export const enableProfilerTimer = __PROFILE__; // Fires getDerivedStateFromProps for state *or* props changes export const fireGetDerivedStateFromPropsOnStateUpdates = true; diff --git a/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js b/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js index f80827ef0223f..b4cb4e54b19ab 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js @@ -20,7 +20,7 @@ export const enableSuspense = false; export const warnAboutDeprecatedLifecycles = false; export const warnAboutLegacyContextAPI = false; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__; -export const enableProfilerTimer = false; +export const enableProfilerTimer = __PROFILE__; export const fireGetDerivedStateFromPropsOnStateUpdates = true; // Only used in www builds. diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index 0eb9c58b4e01a..254aab1dfc3c1 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -20,7 +20,7 @@ export const enableUserTimingAPI = __DEV__; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__; export const warnAboutDeprecatedLifecycles = false; export const warnAboutLegacyContextAPI = false; -export const enableProfilerTimer = __DEV__; +export const enableProfilerTimer = __PROFILE__; export const fireGetDerivedStateFromPropsOnStateUpdates = true; // Only used in www builds. diff --git a/scripts/flow/environment.js b/scripts/flow/environment.js index e7f477360e98b..8cb7e7192dca6 100644 --- a/scripts/flow/environment.js +++ b/scripts/flow/environment.js @@ -9,6 +9,8 @@ /* eslint-disable */ +declare var __PROFILE__: boolean; + declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: any; /*?{ inject: ?((stuff: Object) => void) };*/ diff --git a/scripts/jest/setupEnvironment.js b/scripts/jest/setupEnvironment.js index 36013adf19a91..2b6fd8bd842d9 100644 --- a/scripts/jest/setupEnvironment.js +++ b/scripts/jest/setupEnvironment.js @@ -5,6 +5,7 @@ if (NODE_ENV !== 'development' && NODE_ENV !== 'production') { throw new Error('NODE_ENV must either be set to development or production.'); } global.__DEV__ = NODE_ENV === 'development'; +global.__PROFILE__ = NODE_ENV === 'development'; global.requestAnimationFrame = function(callback) { setTimeout(callback); diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index ba1ee434f6308..cafea350e872d 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -39,10 +39,12 @@ const { UMD_PROD, NODE_DEV, NODE_PROD, + NODE_PROFILING, FB_WWW_DEV, FB_WWW_PROD, RN_OSS_DEV, RN_OSS_PROD, + RN_OSS_PROFILING, RN_FB_DEV, RN_FB_PROD, } = Bundles.bundleTypes; @@ -95,6 +97,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) { }); case RN_OSS_DEV: case RN_OSS_PROD: + case RN_OSS_PROFILING: case RN_FB_DEV: case RN_FB_PROD: return Object.assign({}, options, { @@ -107,6 +110,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) { case UMD_PROD: case NODE_DEV: case NODE_PROD: + case NODE_PROFILING: return Object.assign({}, options, { plugins: options.plugins.concat([ // Use object-assign polyfill in open source @@ -152,10 +156,12 @@ function getFormat(bundleType) { return `umd`; case NODE_DEV: case NODE_PROD: + case NODE_PROFILING: case FB_WWW_DEV: case FB_WWW_PROD: case RN_OSS_DEV: case RN_OSS_PROD: + case RN_OSS_PROFILING: case RN_FB_DEV: case RN_FB_PROD: return `cjs`; @@ -174,6 +180,8 @@ function getFilename(name, globalName, bundleType) { return `${name}.development.js`; case NODE_PROD: return `${name}.production.min.js`; + case NODE_PROFILING: + return `${name}.profiling.min.js`; case FB_WWW_DEV: case RN_OSS_DEV: case RN_FB_DEV: @@ -182,6 +190,8 @@ function getFilename(name, globalName, bundleType) { case RN_OSS_PROD: case RN_FB_PROD: return `${globalName}-prod.js`; + case RN_OSS_PROFILING: + return `${globalName}-profiling.js`; } } @@ -195,8 +205,10 @@ function isProductionBundleType(bundleType) { return false; case UMD_PROD: case NODE_PROD: + case NODE_PROFILING: case FB_WWW_PROD: case RN_OSS_PROD: + case RN_OSS_PROFILING: case RN_FB_PROD: return true; default: @@ -204,6 +216,27 @@ function isProductionBundleType(bundleType) { } } +function isProfilingBundleType(bundleType) { + switch (bundleType) { + case FB_WWW_DEV: + case FB_WWW_PROD: + case NODE_DEV: + case NODE_PROD: + case RN_FB_DEV: + case RN_FB_PROD: + case RN_OSS_DEV: + case RN_OSS_PROD: + case UMD_DEV: + case UMD_PROD: + return false; + case NODE_PROFILING: + case RN_OSS_PROFILING: + return true; + default: + throw new Error(`Unknown type: ${bundleType}`); + } +} + function getPlugins( entry, externals, @@ -218,11 +251,13 @@ function getPlugins( const findAndRecordErrorCodes = extractErrorCodes(errorCodeOpts); const forks = Modules.getForks(bundleType, entry, moduleType); const isProduction = isProductionBundleType(bundleType); + const isProfiling = isProfilingBundleType(bundleType); const isInGlobalScope = bundleType === UMD_DEV || bundleType === UMD_PROD; const isFBBundle = bundleType === FB_WWW_DEV || bundleType === FB_WWW_PROD; const isRNBundle = bundleType === RN_OSS_DEV || bundleType === RN_OSS_PROD || + bundleType === RN_OSS_PROFILING || bundleType === RN_FB_DEV || bundleType === RN_FB_PROD; const shouldStayReadable = isFBBundle || isRNBundle || forcePrettyOutput; @@ -255,6 +290,7 @@ function getPlugins( // Turn __DEV__ and process.env checks into constants. replace({ __DEV__: isProduction ? 'false' : 'true', + __PROFILE__: isProfiling || !isProduction ? 'true' : 'false', 'process.env.NODE_ENV': isProduction ? "'production'" : "'development'", }), // We still need CommonJS for external deps like object-assign. @@ -508,10 +544,12 @@ async function buildEverything() { await createBundle(bundle, UMD_PROD); await createBundle(bundle, NODE_DEV); await createBundle(bundle, NODE_PROD); + await createBundle(bundle, NODE_PROFILING); await createBundle(bundle, FB_WWW_DEV); await createBundle(bundle, FB_WWW_PROD); await createBundle(bundle, RN_OSS_DEV); await createBundle(bundle, RN_OSS_PROD); + await createBundle(bundle, RN_OSS_PROFILING); await createBundle(bundle, RN_FB_DEV); await createBundle(bundle, RN_FB_PROD); } diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index da2c1fc1ce7fb..a9fc687f75197 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -5,10 +5,12 @@ const bundleTypes = { UMD_PROD: 'UMD_PROD', NODE_DEV: 'NODE_DEV', NODE_PROD: 'NODE_PROD', + NODE_PROFILING: 'NODE_PROFILING', FB_WWW_DEV: 'FB_WWW_DEV', FB_WWW_PROD: 'FB_WWW_PROD', RN_OSS_DEV: 'RN_OSS_DEV', RN_OSS_PROD: 'RN_OSS_PROD', + RN_OSS_PROFILING: 'RN_OSS_PROFILING', RN_FB_DEV: 'RN_FB_DEV', RN_FB_PROD: 'RN_FB_PROD', }; @@ -17,10 +19,12 @@ const UMD_DEV = bundleTypes.UMD_DEV; const UMD_PROD = bundleTypes.UMD_PROD; const NODE_DEV = bundleTypes.NODE_DEV; const NODE_PROD = bundleTypes.NODE_PROD; +const NODE_PROFILING = bundleTypes.NODE_PROFILING; const FB_WWW_DEV = bundleTypes.FB_WWW_DEV; const FB_WWW_PROD = bundleTypes.FB_WWW_PROD; const RN_OSS_DEV = bundleTypes.RN_OSS_DEV; const RN_OSS_PROD = bundleTypes.RN_OSS_PROD; +const RN_OSS_PROFILING = bundleTypes.RN_OSS_PROFILING; const RN_FB_DEV = bundleTypes.RN_FB_DEV; const RN_FB_PROD = bundleTypes.RN_FB_PROD; @@ -69,6 +73,7 @@ const bundles = [ UMD_PROD, NODE_DEV, NODE_PROD, + NODE_PROFILING, FB_WWW_DEV, FB_WWW_PROD, ], @@ -175,7 +180,7 @@ const bundles = [ { label: 'native', - bundleTypes: [RN_OSS_DEV, RN_OSS_PROD], + bundleTypes: [RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING], moduleType: RENDERER, entry: 'react-native-renderer', global: 'ReactNativeRenderer', @@ -217,7 +222,7 @@ const bundles = [ { label: 'native-fabric', - bundleTypes: [RN_OSS_DEV, RN_OSS_PROD], + bundleTypes: [RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING], moduleType: RENDERER, entry: 'react-native-renderer/fabric', global: 'ReactFabric', diff --git a/scripts/rollup/forks.js b/scripts/rollup/forks.js index d6fcdb4d18d9b..ed047100a0e85 100644 --- a/scripts/rollup/forks.js +++ b/scripts/rollup/forks.js @@ -10,6 +10,7 @@ const FB_WWW_DEV = bundleTypes.FB_WWW_DEV; const FB_WWW_PROD = bundleTypes.FB_WWW_PROD; const RN_OSS_DEV = bundleTypes.RN_OSS_DEV; const RN_OSS_PROD = bundleTypes.RN_OSS_PROD; +const RN_OSS_PROFILING = bundleTypes.RN_OSS_PROFILING; const RN_FB_DEV = bundleTypes.RN_FB_DEV; const RN_FB_PROD = bundleTypes.RN_FB_PROD; const RENDERER = moduleTypes.RENDERER; @@ -45,6 +46,7 @@ const forks = Object.freeze({ return 'shared/forks/ReactFeatureFlags.native-fb.js'; case RN_OSS_DEV: case RN_OSS_PROD: + case RN_OSS_PROFILING: return 'shared/forks/ReactFeatureFlags.native-oss.js'; default: throw Error( @@ -58,6 +60,7 @@ const forks = Object.freeze({ return 'shared/forks/ReactFeatureFlags.native-fabric-fb.js'; case RN_OSS_DEV: case RN_OSS_PROD: + case RN_OSS_PROFILING: return 'shared/forks/ReactFeatureFlags.native-fabric-oss.js'; default: throw Error( @@ -143,6 +146,7 @@ const forks = Object.freeze({ return 'react-reconciler/src/forks/ReactFiberErrorDialog.www.js'; case RN_OSS_DEV: case RN_OSS_PROD: + case RN_OSS_PROFILING: case RN_FB_DEV: case RN_FB_PROD: switch (entry) { diff --git a/scripts/rollup/packaging.js b/scripts/rollup/packaging.js index 3e59041f3f314..507b0d48cf8d8 100644 --- a/scripts/rollup/packaging.js +++ b/scripts/rollup/packaging.js @@ -14,10 +14,12 @@ const { UMD_PROD, NODE_DEV, NODE_PROD, + NODE_PROFILING, FB_WWW_DEV, FB_WWW_PROD, RN_OSS_DEV, RN_OSS_PROD, + RN_OSS_PROFILING, RN_FB_DEV, RN_FB_PROD, } = Bundles.bundleTypes; @@ -33,6 +35,7 @@ function getBundleOutputPaths(bundleType, filename, packageName) { switch (bundleType) { case NODE_DEV: case NODE_PROD: + case NODE_PROFILING: return [`build/node_modules/${packageName}/cjs/${filename}`]; case UMD_DEV: case UMD_PROD: @@ -45,6 +48,7 @@ function getBundleOutputPaths(bundleType, filename, packageName) { return [`build/facebook-www/${filename}`]; case RN_OSS_DEV: case RN_OSS_PROD: + case RN_OSS_PROFILING: switch (packageName) { case 'react-native-renderer': return [`build/react-native/oss/${filename}`]; diff --git a/scripts/rollup/wrappers.js b/scripts/rollup/wrappers.js index b195b8b25c8ef..36bae238d038e 100644 --- a/scripts/rollup/wrappers.js +++ b/scripts/rollup/wrappers.js @@ -7,10 +7,12 @@ const UMD_DEV = Bundles.bundleTypes.UMD_DEV; const UMD_PROD = Bundles.bundleTypes.UMD_PROD; const NODE_DEV = Bundles.bundleTypes.NODE_DEV; const NODE_PROD = Bundles.bundleTypes.NODE_PROD; +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 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; const RN_FB_DEV = Bundles.bundleTypes.RN_FB_DEV; const RN_FB_PROD = Bundles.bundleTypes.RN_FB_PROD; @@ -91,6 +93,25 @@ ${ ${source}`; }, + /***************** NODE_PROFILING *****************/ + [NODE_PROFILING](source, globalName, filename, moduleType) { + return `/** @license React v${reactVersion} + * ${filename} + * +${license} + */ +${ + globalName === 'ReactNoopRenderer' || + globalName === 'ReactNoopRendererPersistent' + ? // React Noop needs regenerator runtime because it uses + // generators but GCC doesn't handle them in the output. + // So we use Babel for them. + `const regeneratorRuntime = require("regenerator-runtime");` + : `` + } +${source}`; + }, + /****************** FB_WWW_DEV ******************/ [FB_WWW_DEV](source, globalName, filename, moduleType) { return `/** @@ -154,6 +175,20 @@ ${license} * ${'@gen' + 'erated'} */ +${source}`; + }, + + /****************** RN_OSS_PROFILING ******************/ + [RN_OSS_PROFILING](source, globalName, filename, moduleType) { + return `/** +${license} + * + * @noflow + * @providesModule ${globalName}-profiling + * @preventMunge + * ${'@gen' + 'erated'} + */ + ${source}`; },