Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
11b01fa
Stashing
May 5, 2017
4d1d517
Stashing
May 5, 2017
3c4ead6
Split ReactNativeFiber into separate ReactNativeFiberRenderer module
May 5, 2017
5f4a56b
Split findNodeHandle into findNodeHandleFiber + findNodeHandleStack
May 5, 2017
e65a4a3
Un-forked findNodeHandle in favor of just inlining the findNode funct…
May 5, 2017
5612ce0
takeSnapshot no longer requires/depends-on ReactNative for findNodeHa…
May 5, 2017
21337e4
NativeMethodsMixin requires findNodeHandler wrapper(s) directly rathe…
May 5, 2017
7d1e82f
Re-added SyntheticEvent shim to ReactNative renderers
May 5, 2017
e1d683d
Reverted changes to results.json
May 5, 2017
50aabf6
Renamed findNodeHandler stack/fiber RN wrapper
May 5, 2017
94a5631
Add RN_* build targets to hash-finle-name check
May 8, 2017
a12bd55
Strip @providesModule annotations from headers for RN_* builds
May 8, 2017
1f56050
Merge branch 'master' into react-native-flat-bundles
May 10, 2017
89f159f
Prettier and lint
May 10, 2017
fb6f494
Removed createReactNativeComponentClass from RN bundle externals
May 10, 2017
e97da7f
Added process.env.REACT_NATIVE_USE_FIBER to ReactNativeFeatureFlags
May 11, 2017
7533d38
Merge branch 'master' into react-native-flat-bundles
May 12, 2017
0553103
Moved a couple of SECRET exports to dev-only. Removed SyntheticEvent …
May 12, 2017
9f59c4c
Split NativeMethodsMixins interface and object-type
May 23, 2017
4540e2c
Add @noflow header to flat-bundle template to avoid triggering Flow p…
May 23, 2017
c002642
NativeMethodsMixin and ReactNativeFiberHostComponent now share the sa…
May 23, 2017
fe00c57
Collocated (externally exposed) ReactTypes and ReactNativeTypes into …
May 24, 2017
bddfdf3
Build script syncs RN types and PooledClass automatically
May 24, 2017
a9125b7
Added optional sync-RN step to Rollup build script
May 24, 2017
5d844c5
Merged master
May 24, 2017
37920d7
Added results.json for new RN bundles
May 24, 2017
22afd0e
ReactNativeFiber and ReactNativeStack use ReactNativeType Flow type
May 24, 2017
d34f9a7
RN sync script now accepts fbsource path and logs
May 24, 2017
ff597d5
Added RN feature flags shim
May 24, 2017
e9aad99
Added ReactNative shim
May 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 85 additions & 12 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Bundles = require('./bundles');
const propertyMangleWhitelist = require('./mangle').propertyMangleWhitelist;
const sizes = require('./plugins/sizes-plugin');
const Stats = require('./stats');
const syncReactNative = require('./sync').syncReactNative;
const Packaging = require('./packaging');
const Header = require('./header');

Expand All @@ -37,6 +38,7 @@ const requestedBundleTypes = (argv.type || '')
const requestedBundleNames = (argv._[0] || '')
.split(',')
.map(type => type.toLowerCase());
const syncFbsource = argv['sync-fbsource'];

// used for when we property mangle with uglify/gcc
const mangleRegex = new RegExp(
Expand All @@ -46,6 +48,32 @@ const mangleRegex = new RegExp(
'g'
);

function getHeaderSanityCheck(bundleType, hasteName) {
switch (bundleType) {
case FB_DEV:
case FB_PROD:
case RN_DEV:
case RN_PROD:
let hasteFinalName = hasteName;
switch (bundleType) {
case FB_DEV:
case RN_DEV:
hasteFinalName += '-dev';
break;
case FB_PROD:
case RN_PROD:
hasteFinalName += '-prod';
break;
}
return hasteFinalName;
case UMD_DEV:
case UMD_PROD:
return reactVersion;
default:
return null;
}
}

function getBanner(bundleType, hasteName, filename) {
switch (bundleType) {
case FB_DEV:
Expand All @@ -55,9 +83,11 @@ function getBanner(bundleType, hasteName, filename) {
let hasteFinalName = hasteName;
switch (bundleType) {
case FB_DEV:
case RN_DEV:
hasteFinalName += '-dev';
break;
case FB_PROD:
case RN_PROD:
hasteFinalName += '-prod';
break;
}
Expand Down Expand Up @@ -122,6 +152,12 @@ function updateBundleConfig(config, filename, format, bundleType, hasteName) {
});
}

function setReactNativeUseFiberEnvVariable(useFiber) {
return {
'process.env.REACT_NATIVE_USE_FIBER': useFiber,
};
}

function stripEnvVariables(production) {
return {
__DEV__: production ? 'false' : 'true',
Expand Down Expand Up @@ -165,7 +201,13 @@ function getFilename(name, hasteName, bundleType) {
}
}

function uglifyConfig(mangle, manglePropertiesOnProd, preserveVersionHeader) {
function uglifyConfig({
mangle,
manglePropertiesOnProd,
preserveVersionHeader,
removeComments,
headerSanityCheck,
}) {
return {
warnings: false,
compress: {
Expand All @@ -186,7 +228,10 @@ function uglifyConfig(mangle, manglePropertiesOnProd, preserveVersionHeader) {
comments(node, comment) {
if (preserveVersionHeader && comment.pos === 0 && comment.col === 0) {
// Keep the very first comment (the bundle header) in prod bundles.
if (comment.value.indexOf(reactVersion) === -1) {
if (
headerSanityCheck &&
comment.value.indexOf(headerSanityCheck) === -1
) {
// Sanity check: this doesn't look like the bundle header!
throw new Error(
'Expected the first comment to be the file header but got: ' +
Expand All @@ -195,8 +240,7 @@ function uglifyConfig(mangle, manglePropertiesOnProd, preserveVersionHeader) {
}
return true;
}
// Keep all comments in FB bundles.
return !mangle;
return !removeComments;
},
},
mangleProperties: mangle && manglePropertiesOnProd
Expand Down Expand Up @@ -242,8 +286,10 @@ function getPlugins(
paths,
filename,
bundleType,
hasteName,
isRenderer,
manglePropertiesOnProd
manglePropertiesOnProd,
useFiber
) {
const plugins = [
babel(updateBabelConfig(babelOpts, bundleType)),
Expand All @@ -259,11 +305,12 @@ function getPlugins(
plugins.unshift(replace(replaceModules));
}

const headerSanityCheck = getHeaderSanityCheck(bundleType, hasteName);

switch (bundleType) {
case UMD_DEV:
case NODE_DEV:
case FB_DEV:
case RN_DEV:
plugins.push(
replace(stripEnvVariables(false)),
// needs to happen after strip env
Expand All @@ -273,17 +320,36 @@ function getPlugins(
case UMD_PROD:
case NODE_PROD:
case FB_PROD:
case RN_PROD:
plugins.push(
replace(stripEnvVariables(true)),
// needs to happen after strip env
commonjs(getCommonJsConfig(bundleType)),
uglify(
uglifyConfig(
bundleType !== FB_PROD,
uglifyConfig({
mangle: bundleType !== FB_PROD,
manglePropertiesOnProd,
bundleType === UMD_PROD
)
preserveVersionHeader: bundleType === UMD_PROD,
removeComments: bundleType === FB_PROD,
headerSanityCheck,
})
)
);
break;
case RN_DEV:
case RN_PROD:
plugins.push(
replace(stripEnvVariables(bundleType === RN_PROD)),
replace(setReactNativeUseFiberEnvVariable(useFiber)),
// needs to happen after strip env
commonjs(getCommonJsConfig(bundleType)),
uglify(
uglifyConfig({
mangle: false,
manglePropertiesOnProd,
preserveVersionHeader: true,
removeComments: true,
headerSanityCheck,
})
)
);
break;
Expand Down Expand Up @@ -349,8 +415,10 @@ function createBundle(bundle, bundleType) {
bundle.paths,
filename,
bundleType,
bundle.hasteName,
bundle.isRenderer,
bundle.manglePropertiesOnProd
bundle.manglePropertiesOnProd,
bundle.useFiber
),
})
.then(result =>
Expand Down Expand Up @@ -406,6 +474,11 @@ rimraf('build', () => {
() => createBundle(bundle, RN_PROD)
);
}
if (syncFbsource) {
tasks.push(() =>
syncReactNative(join('build', 'react-native'), syncFbsource)
);
}
// rather than run concurently, opt to run them serially
// this helps improve console/warning/error output
// and fixes a bunch of IO failures that sometimes occured
Expand Down
16 changes: 8 additions & 8 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const NODE_DEV = bundleTypes.NODE_DEV;
const NODE_PROD = bundleTypes.NODE_PROD;
const FB_DEV = bundleTypes.FB_DEV;
const FB_PROD = bundleTypes.FB_PROD;
// const RN_DEV = bundleTypes.RN_DEV;
// const RN_PROD = bundleTypes.RN_PROD;
const RN_DEV = bundleTypes.RN_DEV;
const RN_PROD = bundleTypes.RN_PROD;

const babelOptsReact = {
exclude: 'node_modules/**',
Expand Down Expand Up @@ -284,9 +284,7 @@ const bundles = [
/******* React Native *******/
{
babelOpts: babelOptsReact,
bundleTypes: [
/* RN_DEV, RN_PROD */
],
bundleTypes: [RN_DEV, RN_PROD],
config: {
destDir: 'build/',
moduleName: 'ReactNativeStack',
Expand All @@ -304,6 +302,7 @@ const bundles = [
'deepDiffer',
'deepFreezeAndThrowOnMutationInDev',
'flattenStyle',
'prop-types/checkPropTypes',
],
hasteName: 'ReactNativeStack',
isRenderer: true,
Expand All @@ -317,12 +316,11 @@ const bundles = [
'src/ReactVersion.js',
'src/shared/**/*.js',
],
useFiber: false,
},
{
babelOpts: babelOptsReact,
bundleTypes: [
/* RN_DEV, RN_PROD */
],
bundleTypes: [RN_DEV, RN_PROD],
config: {
destDir: 'build/',
moduleName: 'ReactNativeFiber',
Expand All @@ -340,6 +338,7 @@ const bundles = [
'deepDiffer',
'deepFreezeAndThrowOnMutationInDev',
'flattenStyle',
'prop-types/checkPropTypes',
],
hasteName: 'ReactNativeFiber',
isRenderer: true,
Expand All @@ -353,6 +352,7 @@ const bundles = [
'src/ReactVersion.js',
'src/shared/**/*.js',
],
useFiber: true,
},

/******* React Test Renderer *******/
Expand Down
1 change: 1 addition & 0 deletions scripts/rollup/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function getProvidesHeader(hasteFinalName, bundleType, fbDevCode) {
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @noflow
* @providesModule ${hasteFinalName}
*/${bundleType === FB_DEV ? fbDevCode : ''}
`;
Expand Down
31 changes: 18 additions & 13 deletions scripts/rollup/packaging.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

const basename = require('path').basename;
const ncp = require('ncp').ncp;
const fs = require('fs');
const join = require('path').join;
const resolve = require('path').resolve;
const Bundles = require('./bundles');
const asyncCopyTo = require('./utils').asyncCopyTo;

const UMD_DEV = Bundles.bundleTypes.UMD_DEV;
const UMD_PROD = Bundles.bundleTypes.UMD_PROD;
Expand All @@ -23,17 +23,12 @@ const facebookWWWSrcDependencies = [
'src/renderers/dom/shared/eventPlugins/TapEventPlugin.js',
];

function asyncCopyTo(from, to) {
return new Promise(_resolve => {
ncp(from, to, error => {
if (error) {
console.error(error);
process.exit(1);
}
_resolve();
});
});
}
// these files need to be copied to the react-native build
const reactNativeSrcDependencies = [
'src/shared/utils/PooledClass.js',
'src/renderers/shared/fiber/isomorphic/ReactTypes.js',
'src/renderers/native/ReactNativeTypes.js',
];

function getPackageName(name) {
if (name.indexOf('/') !== -1) {
Expand All @@ -51,7 +46,17 @@ function createReactNativeBuild() {
const from = join('scripts', 'rollup', 'shims', 'react-native');
const to = join('build', 'react-native', 'shims');

return asyncCopyTo(from, to);
return asyncCopyTo(from, to).then(() => {
let promises = [];
// we also need to copy over some specific files from src
// defined in reactNativeSrcDependencies
for (const srcDependency of reactNativeSrcDependencies) {
promises.push(
asyncCopyTo(resolve(srcDependency), join(to, basename(srcDependency)))
);
}
return Promise.all(promises);
});
}

function createFacebookWWWBuild() {
Expand Down
16 changes: 16 additions & 0 deletions scripts/rollup/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@
"ReactDOMServerStream-prod.js (FB_PROD)": {
"size": 345920,
"gzip": 83497
},
"ReactNativeStack-dev.js (RN_DEV)": {
"size": 350743,
"gzip": 63769
},
"ReactNativeStack-prod.js (RN_PROD)": {
"size": 269602,
"gzip": 46634
},
"ReactNativeFiber-dev.js (RN_DEV)": {
"size": 327677,
"gzip": 59441
},
"ReactNativeFiber-prod.js (RN_PROD)": {
"size": 248866,
"gzip": 43107
}
}
}
7 changes: 5 additions & 2 deletions scripts/rollup/shims/react-native/NativeMethodsMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ const {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
} = require('ReactNative');

module.exports =
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativeMethodsMixin;
import type {NativeMethodsMixinType} from 'ReactNativeTypes';

const {NativeMethodsMixin} = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;

module.exports = ((NativeMethodsMixin: any): $Exact<NativeMethodsMixinType>);
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule PooledClass
* @providesModule ReactGlobalSharedState
*/

'use strict';
Expand All @@ -15,4 +15,5 @@ const {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
} = require('ReactNative');

module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.PooledClass;
module.exports =
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactGlobalSharedState;
Loading