Skip to content

Commit

Permalink
Fork React Native renderer into FB and OSS bundles (facebook#12625)
Browse files Browse the repository at this point in the history
* Added new "native-fb" and "native-fabric-fb" bundles.
* Split RN_DEV and RN_PROD bundle types into RN_OSS_DEV, RN_OSS_PROD, RN_FB_DEV, and RN_FB_PROD. (This is a bit redundant but it seemed the least intrusive way of supporting a forked feature flags file for these bundles.)
* Renamed FB_DEV and FB_PROD bundle types to be more explicitly for www (FB_WWW_DEV and FB_WWW_PROD)
* Removed Haste @providesModule headers from the RB-specific RN renderer bundles to avoid a duplicate name conflicts.
* Remove dynamic values from OSS RN feature flags. (Leave them in FB RN feature flags.)
* Updated the sync script(s) to account for new renderer type.
* Move ReactFeatureFlags.js shim to FB bundle only (since OSS bundle no longer needs dynamic values).
  • Loading branch information
bvaughn authored and rhagigi committed Apr 19, 2018
1 parent 9859399 commit cd21a24
Show file tree
Hide file tree
Showing 14 changed files with 349 additions and 99 deletions.
Expand Up @@ -17,7 +17,7 @@ let UIManager;
let FabricUIManager;

jest.mock('shared/ReactFeatureFlags', () =>
require('shared/forks/ReactFeatureFlags.native-fabric'),
require('shared/forks/ReactFeatureFlags.native-fabric-oss'),
);

describe('ReactFabric', () => {
Expand Down
Expand Up @@ -21,7 +21,7 @@ describe('ReactFabric', () => {
ReactNative = require('react-native-renderer');
jest.resetModules();
jest.mock('shared/ReactFeatureFlags', () =>
require('shared/forks/ReactFeatureFlags.native-fabric'),
require('shared/forks/ReactFeatureFlags.native-fabric-oss'),
);

React = require('react');
Expand Down
Expand Up @@ -10,7 +10,7 @@
import invariant from 'fbjs/lib/invariant';

import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
import typeof * as FabricFeatureFlagsType from './ReactFeatureFlags.native-fabric';
import typeof * as FabricFeatureFlagsType from './ReactFeatureFlags.native-fabric-fb';

export const debugRenderPhaseSideEffects = false;
export const debugRenderPhaseSideEffectsForStrictMode = false;
Expand Down
37 changes: 37 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import invariant from 'fbjs/lib/invariant';

import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
import typeof * as FabricFeatureFlagsType from './ReactFeatureFlags.native-fabric-oss';

export const debugRenderPhaseSideEffects = false;
export const debugRenderPhaseSideEffectsForStrictMode = false;
export const enableUserTimingAPI = __DEV__;
export const enableGetDerivedStateFromCatch = false;
export const warnAboutDeprecatedLifecycles = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;

// React Fabric uses persistent reconciler.
export const enableMutatingReconciler = false;
export const enableNoopReconciler = false;
export const enablePersistentReconciler = true;
export const alwaysUseRequestIdleCallbackPolyfill = false;

// Only used in www builds.
export function addUserTimingListener() {
invariant(false, 'Not implemented.');
}

// Flow magic to verify the exports of this file match the original version.
// eslint-disable-next-line no-unused-vars
type Check<_X, Y: _X, X: Y = _X> = null;
// eslint-disable-next-line no-unused-expressions
(null: Check<FabricFeatureFlagsType, FeatureFlagsType>);
Expand Up @@ -10,7 +10,7 @@
import invariant from 'fbjs/lib/invariant';

import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
import typeof * as FeatureFlagsShimType from './ReactFeatureFlags.native';
import typeof * as FeatureFlagsShimType from './ReactFeatureFlags.native-fb';

// Re-export dynamic flags from the fbsource version.
export const {
Expand Down
35 changes: 35 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.native-oss.js
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import invariant from 'fbjs/lib/invariant';

import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
import typeof * as FeatureFlagsShimType from './ReactFeatureFlags.native-oss';

export const alwaysUseRequestIdleCallbackPolyfill = false;
export const debugRenderPhaseSideEffects = false;
export const debugRenderPhaseSideEffectsForStrictMode = false;
export const enableGetDerivedStateFromCatch = false;
export const enableMutatingReconciler = true;
export const enableNoopReconciler = false;
export const enablePersistentReconciler = false;
export const enableUserTimingAPI = __DEV__;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const warnAboutDeprecatedLifecycles = false;

// Only used in www builds.
export function addUserTimingListener() {
invariant(false, 'Not implemented.');
}

// Flow magic to verify the exports of this file match the original version.
// eslint-disable-next-line no-unused-vars
type Check<_X, Y: _X, X: Y = _X> = null;
// eslint-disable-next-line no-unused-expressions
(null: Check<FeatureFlagsShimType, FeatureFlagsType>);
76 changes: 45 additions & 31 deletions scripts/rollup/build.js
Expand Up @@ -39,10 +39,12 @@ const {
UMD_PROD,
NODE_DEV,
NODE_PROD,
FB_DEV,
FB_PROD,
RN_DEV,
RN_PROD,
FB_WWW_DEV,
FB_WWW_PROD,
RN_OSS_DEV,
RN_OSS_PROD,
RN_FB_DEV,
RN_FB_PROD,
} = Bundles.bundleTypes;

const requestedBundleTypes = (argv.type || '')
Expand Down Expand Up @@ -81,8 +83,8 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
options = updateBabelOptions(options);
}
switch (bundleType) {
case FB_DEV:
case FB_PROD:
case FB_WWW_DEV:
case FB_WWW_PROD:
return Object.assign({}, options, {
plugins: options.plugins.concat([
// Minify invariant messages
Expand All @@ -91,8 +93,10 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
require('../babel/wrap-warning-with-env-check'),
]),
});
case RN_DEV:
case RN_PROD:
case RN_OSS_DEV:
case RN_OSS_PROD:
case RN_FB_DEV:
case RN_FB_PROD:
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 @@ -139,10 +143,12 @@ function getFormat(bundleType) {
return `umd`;
case NODE_DEV:
case NODE_PROD:
case FB_DEV:
case FB_PROD:
case RN_DEV:
case RN_PROD:
case FB_WWW_DEV:
case FB_WWW_PROD:
case RN_OSS_DEV:
case RN_OSS_PROD:
case RN_FB_DEV:
case RN_FB_PROD:
return `cjs`;
}
}
Expand All @@ -159,11 +165,13 @@ function getFilename(name, globalName, bundleType) {
return `${name}.development.js`;
case NODE_PROD:
return `${name}.production.min.js`;
case FB_DEV:
case RN_DEV:
case FB_WWW_DEV:
case RN_OSS_DEV:
case RN_FB_DEV:
return `${globalName}-dev.js`;
case FB_PROD:
case RN_PROD:
case FB_WWW_PROD:
case RN_OSS_PROD:
case RN_FB_PROD:
return `${globalName}-prod.js`;
}
}
Expand All @@ -172,13 +180,15 @@ function isProductionBundleType(bundleType) {
switch (bundleType) {
case UMD_DEV:
case NODE_DEV:
case FB_DEV:
case RN_DEV:
case FB_WWW_DEV:
case RN_OSS_DEV:
case RN_FB_DEV:
return false;
case UMD_PROD:
case NODE_PROD:
case FB_PROD:
case RN_PROD:
case FB_WWW_PROD:
case RN_OSS_PROD:
case RN_FB_PROD:
return true;
default:
throw new Error(`Unknown type: ${bundleType}`);
Expand All @@ -200,8 +210,12 @@ function getPlugins(
const forks = Modules.getForks(bundleType, entry);
const isProduction = isProductionBundleType(bundleType);
const isInGlobalScope = bundleType === UMD_DEV || bundleType === UMD_PROD;
const isFBBundle = bundleType === FB_DEV || bundleType === FB_PROD;
const isRNBundle = bundleType === RN_DEV || bundleType === RN_PROD;
const isFBBundle = bundleType === FB_WWW_DEV || bundleType === FB_WWW_PROD;
const isRNBundle =
bundleType === RN_OSS_DEV ||
bundleType === RN_OSS_PROD ||
bundleType === RN_FB_DEV ||
bundleType === RN_FB_PROD;
const shouldStayReadable = isFBBundle || isRNBundle || forcePrettyOutput;
return [
// Extract error codes from invariant() messages into a file.
Expand Down Expand Up @@ -329,7 +343,7 @@ async function createBundle(bundle, bundleType) {
const packageName = Packaging.getPackageName(bundle.entry);

let resolvedEntry = require.resolve(bundle.entry);
if (bundleType === FB_DEV || bundleType === FB_PROD) {
if (bundleType === FB_WWW_DEV || bundleType === FB_WWW_PROD) {
const resolvedFBEntry = resolvedEntry.replace('.js', '.fb.js');
if (fs.existsSync(resolvedFBEntry)) {
resolvedEntry = resolvedFBEntry;
Expand Down Expand Up @@ -379,7 +393,7 @@ async function createBundle(bundle, bundleType) {
bundle.modulesToStub
),
// We can't use getters in www.
legacy: bundleType === FB_DEV || bundleType === FB_PROD,
legacy: bundleType === FB_WWW_DEV || bundleType === FB_WWW_PROD,
};
const [mainOutputPath, ...otherOutputPaths] = Packaging.getBundleOutputPaths(
bundleType,
Expand Down Expand Up @@ -478,19 +492,19 @@ async function buildEverything() {
await createBundle(bundle, UMD_PROD);
await createBundle(bundle, NODE_DEV);
await createBundle(bundle, NODE_PROD);
await createBundle(bundle, FB_DEV);
await createBundle(bundle, FB_PROD);
await createBundle(bundle, RN_DEV);
await createBundle(bundle, RN_PROD);
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_FB_DEV);
await createBundle(bundle, RN_FB_PROD);
}

await Packaging.copyAllShims();
await Packaging.prepareNpmPackages();

if (syncFBSourcePath) {
await Sync.syncReactNative('build/react-native', syncFBSourcePath);
await Sync.syncReactNativeRT('build/react-rt', syncFBSourcePath);
await Sync.syncReactNativeCS('build/react-cs', syncFBSourcePath);
await Sync.syncReactNative(syncFBSourcePath);
} else if (syncWWWPath) {
await Sync.syncReactDom('build/facebook-www', syncWWWPath);
}
Expand Down

0 comments on commit cd21a24

Please sign in to comment.