Skip to content

Commit

Permalink
Add PROFILE bundles for www+DOM and fbsource+RN/RF (#13112)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn authored Jun 26, 2018
1 parent 71a60dd commit 6d6de60
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const enableSuspense = false;
export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = __DEV__;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const enableProfilerTimer = __DEV__;
export const enableProfilerTimer = __PROFILE__;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export const {
debugRenderPhaseSideEffectsForStrictMode,
warnAboutDeprecatedLifecycles,
replayFailedUnitOfWorkWithInvokeGuardedCallback,
enableProfilerTimer,
} = require('ReactFeatureFlags');

// The rest of the flags are static for better dead code elimination.
export const enableUserTimingAPI = __DEV__;
export const warnAboutLegacyContextAPI = __DEV__;
export const enableProfilerTimer = __PROFILE__;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.persistent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const {
enableGetDerivedStateFromCatch,
replayFailedUnitOfWorkWithInvokeGuardedCallback,
warnAboutDeprecatedLifecycles,
enableProfilerTimer,
} = require('ReactFeatureFlags');

// The rest of the flags are static for better dead code elimination.
Expand All @@ -32,6 +31,8 @@ export const warnAboutLegacyContextAPI = __DEV__;
// as long as there is more than a single listener.
export let enableUserTimingAPI = __DEV__;

export const enableProfilerTimer = __PROFILE__;

let refCount = 0;
export function addUserTimingListener() {
if (__DEV__) {
Expand Down
33 changes: 29 additions & 4 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ const {
NODE_PROFILING,
FB_WWW_DEV,
FB_WWW_PROD,
FB_WWW_PROFILING,
RN_OSS_DEV,
RN_OSS_PROD,
RN_OSS_PROFILING,
RN_FB_DEV,
RN_FB_PROD,
RN_FB_PROFILING,
} = Bundles.bundleTypes;

const requestedBundleTypes = (argv.type || '')
Expand Down Expand Up @@ -87,6 +89,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
switch (bundleType) {
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
return Object.assign({}, options, {
plugins: options.plugins.concat([
// Minify invariant messages
Expand All @@ -100,6 +103,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
case RN_OSS_PROFILING:
case RN_FB_DEV:
case RN_FB_PROD:
case RN_FB_PROFILING:
return Object.assign({}, options, {
plugins: options.plugins.concat([
// Wrap warning() calls in a __DEV__ check so they are stripped from production.
Expand Down Expand Up @@ -159,11 +163,13 @@ function getFormat(bundleType) {
case NODE_PROFILING:
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
case RN_OSS_DEV:
case RN_OSS_PROD:
case RN_OSS_PROFILING:
case RN_FB_DEV:
case RN_FB_PROD:
case RN_FB_PROFILING:
return `cjs`;
}
}
Expand All @@ -190,6 +196,8 @@ function getFilename(name, globalName, bundleType) {
case RN_OSS_PROD:
case RN_FB_PROD:
return `${globalName}-prod.js`;
case FB_WWW_PROFILING:
case RN_FB_PROFILING:
case RN_OSS_PROFILING:
return `${globalName}-profiling.js`;
}
Expand All @@ -207,9 +215,11 @@ function isProductionBundleType(bundleType) {
case NODE_PROD:
case NODE_PROFILING:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
case RN_OSS_PROD:
case RN_OSS_PROFILING:
case RN_FB_PROD:
case RN_FB_PROFILING:
return true;
default:
throw new Error(`Unknown type: ${bundleType}`);
Expand All @@ -229,7 +239,9 @@ function isProfilingBundleType(bundleType) {
case UMD_DEV:
case UMD_PROD:
return false;
case FB_WWW_PROFILING:
case NODE_PROFILING:
case RN_FB_PROFILING:
case RN_OSS_PROFILING:
return true;
default:
Expand Down Expand Up @@ -267,13 +279,17 @@ function getPlugins(
const isProduction = isProductionBundleType(bundleType);
const isProfiling = isProfilingBundleType(bundleType);
const isUMDBundle = bundleType === UMD_DEV || bundleType === UMD_PROD;
const isFBBundle = bundleType === FB_WWW_DEV || bundleType === FB_WWW_PROD;
const isFBBundle =
bundleType === FB_WWW_DEV ||
bundleType === FB_WWW_PROD ||
bundleType === FB_WWW_PROFILING;
const isRNBundle =
bundleType === RN_OSS_DEV ||
bundleType === RN_OSS_PROD ||
bundleType === RN_OSS_PROFILING ||
bundleType === RN_FB_DEV ||
bundleType === RN_FB_PROD;
bundleType === RN_FB_PROD ||
bundleType === RN_FB_PROFILING;
const shouldStayReadable = isFBBundle || isRNBundle || forcePrettyOutput;
return [
// Extract error codes from invariant() messages into a file.
Expand Down Expand Up @@ -404,7 +420,11 @@ async function createBundle(bundle, bundleType) {
const packageName = Packaging.getPackageName(bundle.entry);

let resolvedEntry = require.resolve(bundle.entry);
if (bundleType === FB_WWW_DEV || bundleType === FB_WWW_PROD) {
if (
bundleType === FB_WWW_DEV ||
bundleType === FB_WWW_PROD ||
bundleType === FB_WWW_PROFILING
) {
const resolvedFBEntry = resolvedEntry.replace('.js', '.fb.js');
if (fs.existsSync(resolvedFBEntry)) {
resolvedEntry = resolvedFBEntry;
Expand Down Expand Up @@ -451,7 +471,10 @@ async function createBundle(bundle, bundleType) {
bundle.modulesToStub
),
// We can't use getters in www.
legacy: bundleType === FB_WWW_DEV || bundleType === FB_WWW_PROD,
legacy:
bundleType === FB_WWW_DEV ||
bundleType === FB_WWW_PROD ||
bundleType === FB_WWW_PROFILING,
};
const [mainOutputPath, ...otherOutputPaths] = Packaging.getBundleOutputPaths(
bundleType,
Expand Down Expand Up @@ -563,11 +586,13 @@ async function buildEverything() {
await createBundle(bundle, NODE_PROFILING);
await createBundle(bundle, FB_WWW_DEV);
await createBundle(bundle, FB_WWW_PROD);
await createBundle(bundle, FB_WWW_PROFILING);
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);
await createBundle(bundle, RN_FB_PROFILING);
}

await Packaging.copyAllShims();
Expand Down
9 changes: 7 additions & 2 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ const bundleTypes = {
NODE_PROFILING: 'NODE_PROFILING',
FB_WWW_DEV: 'FB_WWW_DEV',
FB_WWW_PROD: 'FB_WWW_PROD',
FB_WWW_PROFILING: 'FB_WWW_PROFILING',
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',
RN_FB_PROFILING: 'RN_FB_PROFILING',
};

const UMD_DEV = bundleTypes.UMD_DEV;
Expand All @@ -22,11 +24,13 @@ 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 FB_WWW_PROFILING = bundleTypes.FB_WWW_PROFILING;
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 RN_FB_PROFILING = bundleTypes.RN_FB_PROFILING;

const moduleTypes = {
ISOMORPHIC: 'ISOMORPHIC',
Expand Down Expand Up @@ -76,6 +80,7 @@ const bundles = [
NODE_PROFILING,
FB_WWW_DEV,
FB_WWW_PROD,
FB_WWW_PROFILING,
],
moduleType: RENDERER,
entry: 'react-dom',
Expand Down Expand Up @@ -160,7 +165,7 @@ const bundles = [
/******* React Native *******/
{
label: 'native-fb',
bundleTypes: [RN_FB_DEV, RN_FB_PROD],
bundleTypes: [RN_FB_DEV, RN_FB_PROD, RN_FB_PROFILING],
moduleType: RENDERER,
entry: 'react-native-renderer',
global: 'ReactNativeRenderer',
Expand Down Expand Up @@ -201,7 +206,7 @@ const bundles = [
/******* React Native Fabric *******/
{
label: 'native-fabric-fb',
bundleTypes: [RN_FB_DEV, RN_FB_PROD],
bundleTypes: [RN_FB_DEV, RN_FB_PROD, RN_FB_PROFILING],
moduleType: RENDERER,
entry: 'react-native-renderer/fabric',
global: 'ReactFabric',
Expand Down
14 changes: 14 additions & 0 deletions scripts/rollup/forks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ const UMD_DEV = bundleTypes.UMD_DEV;
const UMD_PROD = bundleTypes.UMD_PROD;
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 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 RN_FB_PROFILING = bundleTypes.RN_FB_PROFILING;
const RENDERER = moduleTypes.RENDERER;
const RECONCILER = moduleTypes.RECONCILER;

Expand Down Expand Up @@ -43,6 +45,7 @@ const forks = Object.freeze({
switch (bundleType) {
case RN_FB_DEV:
case RN_FB_PROD:
case RN_FB_PROFILING:
return 'shared/forks/ReactFeatureFlags.native-fb.js';
case RN_OSS_DEV:
case RN_OSS_PROD:
Expand All @@ -57,6 +60,7 @@ const forks = Object.freeze({
switch (bundleType) {
case RN_FB_DEV:
case RN_FB_PROD:
case RN_FB_PROFILING:
return 'shared/forks/ReactFeatureFlags.native-fabric-fb.js';
case RN_OSS_DEV:
case RN_OSS_PROD:
Expand All @@ -75,6 +79,7 @@ const forks = Object.freeze({
switch (bundleType) {
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
return 'shared/forks/ReactFeatureFlags.www.js';
}
}
Expand All @@ -85,6 +90,7 @@ const forks = Object.freeze({
switch (bundleType) {
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
return 'shared/forks/ReactScheduler.www.js';
default:
return null;
Expand All @@ -96,6 +102,7 @@ const forks = Object.freeze({
switch (bundleType) {
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
return 'shared/forks/invariant.www.js';
default:
return null;
Expand All @@ -107,6 +114,7 @@ const forks = Object.freeze({
switch (bundleType) {
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
return 'shared/forks/lowPriorityWarning.www.js';
default:
return null;
Expand All @@ -118,6 +126,7 @@ const forks = Object.freeze({
switch (bundleType) {
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
return 'shared/forks/warning.www.js';
default:
return null;
Expand All @@ -130,6 +139,7 @@ const forks = Object.freeze({
switch (bundleType) {
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
return 'react/src/forks/ReactCurrentOwner.www.js';
default:
return null;
Expand All @@ -141,6 +151,7 @@ const forks = Object.freeze({
switch (bundleType) {
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
return 'shared/forks/invokeGuardedCallback.www.js';
default:
return null;
Expand All @@ -152,13 +163,15 @@ const forks = Object.freeze({
switch (bundleType) {
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
// Use the www fork which shows an error dialog.
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:
case RN_FB_PROFILING:
switch (entry) {
case 'react-native-renderer':
case 'react-native-renderer/fabric':
Expand Down Expand Up @@ -204,6 +217,7 @@ const forks = Object.freeze({
switch (bundleType) {
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
// Use the www fork which is integrated with TimeSlice profiling.
return 'react-dom/src/events/forks/EventListener-www.js';
default:
Expand Down
4 changes: 4 additions & 0 deletions scripts/rollup/packaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ const {
NODE_PROFILING,
FB_WWW_DEV,
FB_WWW_PROD,
FB_WWW_PROFILING,
RN_OSS_DEV,
RN_OSS_PROD,
RN_OSS_PROFILING,
RN_FB_DEV,
RN_FB_PROD,
RN_FB_PROFILING,
} = Bundles.bundleTypes;

function getPackageName(name) {
Expand All @@ -45,6 +47,7 @@ function getBundleOutputPaths(bundleType, filename, packageName) {
];
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
return [`build/facebook-www/${filename}`];
case RN_OSS_DEV:
case RN_OSS_PROD:
Expand All @@ -57,6 +60,7 @@ function getBundleOutputPaths(bundleType, filename, packageName) {
}
case RN_FB_DEV:
case RN_FB_PROD:
case RN_FB_PROFILING:
switch (packageName) {
case 'react-native-renderer':
return [`build/react-native/fb/${filename}`];
Expand Down
Loading

0 comments on commit 6d6de60

Please sign in to comment.