diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index d9cf2c66ef..2f01f1a5ac 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -34,7 +34,7 @@ function getAliases(paths, bundleType) { } function getBanner(bundleType, hastName) { - if (bundleType === bundleTypes.FB) { + if (bundleType === bundleTypes.FB || bundleType === bundleTypes.RN) { return ( // intentionally not indented correctly, as whitespace is literal `/** @@ -59,6 +59,7 @@ function updateBabelConfig(babelOpts, bundleType) { case bundleTypes.PROD: case bundleTypes.DEV: case bundleTypes.NODE: + case bundleTypes.RN: newOpts = Object.assign({}, babelOpts); // we add the objectAssign transform for these bundles @@ -106,6 +107,7 @@ function getFormat(bundleType) { return `umd`; case bundleTypes.NODE: case bundleTypes.FB: + case bundleTypes.RN: return `cjs`; } } @@ -119,6 +121,7 @@ function getFilename(name, hasteName, bundleType) { case bundleTypes.NODE: return `${name}.cjs.js`; case bundleTypes.FB: + case bundleTypes.RN: return `${hasteName}.js`; } } @@ -146,6 +149,7 @@ function getCommonJsConfig(bundleType) { return {}; case bundleTypes.NODE: // TODO: why does it share settings with FB? case bundleTypes.FB: + case bundleTypes.RN: // TODO: I haven't checked if this is right // Modules we don't want to inline in the bundle. // Force them to stay as require()s in the output. return { @@ -207,15 +211,27 @@ function getPlugins(entry, babelOpts, paths, filename, bundleType) { const inputBundleType = argv.type; -function createBundle({babelOpts, entry, fbEntry, config, paths, name, hasteName}, bundleType) { +function createBundle({babelOpts, entry, fbEntry, rnEntry, config, paths, name, hasteName}, bundleType) { if (inputBundleType && inputBundleType !== bundleType) { return Promise.resolve(); } + + switch (bundleType) { + case bundleTypes.FB: + entry = fbEntry; + break; + case bundleTypes.RN: + entry = rnEntry; + break; + } + if (!entry) { + return Promise.resolve(); + } + const filename = getFilename(name, hasteName, bundleType); const format = getFormat(bundleType); - return rollup({ - entry: bundleType === bundleTypes.FB ? fbEntry : entry, + entry: entry, plugins: getPlugins(entry, babelOpts, paths, filename, bundleType), onwarn: handleRollupWarnings, }).then(({write}) => write( @@ -234,7 +250,9 @@ bundles.forEach(bundle => { ); } else { createBundle(bundle, bundleTypes.NODE).then(() => - createBundle(bundle, bundleTypes.FB) + createBundle(bundle, bundleTypes.FB).then(() => + createBundle(bundle, bundleTypes.RN) + ) ); } }); diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index 32f1685d6b..84f99ddba8 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -7,6 +7,7 @@ const bundleTypes = { PROD: 'PROD', NODE: 'NODE', FB: 'FB', + RN: 'RN', }; const babelOptsReact = { @@ -183,28 +184,25 @@ const bundles = [ }, /******* React Native *******/ - // { - // babelOpts: babelOptsReact, - // config: { - // destDir: 'build/rollup/', - // moduleName: 'ReactNative', - // sourceMap: false, - // }, - // entry: 'src/umd/ReactDOMUMDEntry.js', - // name: 'react-native-renderer', - // paths: [ - // 'src/umd/ReactDOMUMDEntry.js', - // 'src/umd/ReactDOMServerUMDEntry.js', + { + babelOpts: babelOptsReact, + config: { + destDir: 'build/rollup/', + moduleName: 'ReactNative', + sourceMap: false, + }, + rnEntry: 'src/renderers/native/ReactNative.js', + hasteName: 'ReactNative', + name: 'react-native-renderer', + paths: [ + 'src/renderers/native/**/*.js', + 'src/renderers/shared/**/*.js', - // 'src/renderers/dom/**/*.js', - // 'src/renderers/shared/**/*.js', - // 'src/test/**/*.js', // ReactTestUtils is currently very coupled to DOM. - - // 'src/ReactVersion.js', - // 'src/shared/**/*.js', - // ], - // umd: false, - // }, + 'src/ReactVersion.js', + 'src/shared/**/*.js', + ], + umd: false, + }, ]; module.exports = { diff --git a/scripts/rollup/forwarding/DOMProperty.js b/scripts/rollup/forwarding-dom/DOMProperty.js similarity index 100% rename from scripts/rollup/forwarding/DOMProperty.js rename to scripts/rollup/forwarding-dom/DOMProperty.js diff --git a/scripts/rollup/forwarding/EventPluginHub.js b/scripts/rollup/forwarding-dom/EventPluginHub.js similarity index 100% rename from scripts/rollup/forwarding/EventPluginHub.js rename to scripts/rollup/forwarding-dom/EventPluginHub.js diff --git a/scripts/rollup/forwarding/EventPluginUtils.js b/scripts/rollup/forwarding-dom/EventPluginUtils.js similarity index 100% rename from scripts/rollup/forwarding/EventPluginUtils.js rename to scripts/rollup/forwarding-dom/EventPluginUtils.js diff --git a/scripts/rollup/forwarding/EventPropagators.js b/scripts/rollup/forwarding-dom/EventPropagators.js similarity index 100% rename from scripts/rollup/forwarding/EventPropagators.js rename to scripts/rollup/forwarding-dom/EventPropagators.js diff --git a/scripts/rollup/forwarding/PooledClass.js b/scripts/rollup/forwarding-dom/PooledClass.js similarity index 100% rename from scripts/rollup/forwarding/PooledClass.js rename to scripts/rollup/forwarding-dom/PooledClass.js diff --git a/scripts/rollup/forwarding/ReactBrowserEventEmitter.js b/scripts/rollup/forwarding-dom/ReactBrowserEventEmitter.js similarity index 100% rename from scripts/rollup/forwarding/ReactBrowserEventEmitter.js rename to scripts/rollup/forwarding-dom/ReactBrowserEventEmitter.js diff --git a/scripts/rollup/forwarding/ReactChildren.js b/scripts/rollup/forwarding-dom/ReactChildren.js similarity index 100% rename from scripts/rollup/forwarding/ReactChildren.js rename to scripts/rollup/forwarding-dom/ReactChildren.js diff --git a/scripts/rollup/forwarding/ReactDOMComponentTree.js b/scripts/rollup/forwarding-dom/ReactDOMComponentTree.js similarity index 100% rename from scripts/rollup/forwarding/ReactDOMComponentTree.js rename to scripts/rollup/forwarding-dom/ReactDOMComponentTree.js diff --git a/scripts/rollup/forwarding/ReactDOMInputSelection.js b/scripts/rollup/forwarding-dom/ReactDOMInputSelection.js similarity index 100% rename from scripts/rollup/forwarding/ReactDOMInputSelection.js rename to scripts/rollup/forwarding-dom/ReactDOMInputSelection.js diff --git a/scripts/rollup/forwarding/ReactDOMSelection.js b/scripts/rollup/forwarding-dom/ReactDOMSelection.js similarity index 100% rename from scripts/rollup/forwarding/ReactDOMSelection.js rename to scripts/rollup/forwarding-dom/ReactDOMSelection.js diff --git a/scripts/rollup/forwarding/ReactElement.js b/scripts/rollup/forwarding-dom/ReactElement.js similarity index 100% rename from scripts/rollup/forwarding/ReactElement.js rename to scripts/rollup/forwarding-dom/ReactElement.js diff --git a/scripts/rollup/forwarding/ReactFiberErrorLogger.js b/scripts/rollup/forwarding-dom/ReactFiberErrorLogger.js similarity index 100% rename from scripts/rollup/forwarding/ReactFiberErrorLogger.js rename to scripts/rollup/forwarding-dom/ReactFiberErrorLogger.js diff --git a/scripts/rollup/forwarding/ReactInputSelection.js b/scripts/rollup/forwarding-dom/ReactInputSelection.js similarity index 100% rename from scripts/rollup/forwarding/ReactInputSelection.js rename to scripts/rollup/forwarding-dom/ReactInputSelection.js diff --git a/scripts/rollup/forwarding/ReactInstanceMap.js b/scripts/rollup/forwarding-dom/ReactInstanceMap.js similarity index 100% rename from scripts/rollup/forwarding/ReactInstanceMap.js rename to scripts/rollup/forwarding-dom/ReactInstanceMap.js diff --git a/scripts/rollup/forwarding/ReactPerf.js b/scripts/rollup/forwarding-dom/ReactPerf.js similarity index 100% rename from scripts/rollup/forwarding/ReactPerf.js rename to scripts/rollup/forwarding-dom/ReactPerf.js diff --git a/scripts/rollup/forwarding/ReactTestUtils.js b/scripts/rollup/forwarding-dom/ReactTestUtils.js similarity index 100% rename from scripts/rollup/forwarding/ReactTestUtils.js rename to scripts/rollup/forwarding-dom/ReactTestUtils.js diff --git a/scripts/rollup/forwarding/SyntheticEvent.js b/scripts/rollup/forwarding-dom/SyntheticEvent.js similarity index 100% rename from scripts/rollup/forwarding/SyntheticEvent.js rename to scripts/rollup/forwarding-dom/SyntheticEvent.js diff --git a/scripts/rollup/forwarding/SyntheticKeyboardEvent.js b/scripts/rollup/forwarding-dom/SyntheticKeyboardEvent.js similarity index 100% rename from scripts/rollup/forwarding/SyntheticKeyboardEvent.js rename to scripts/rollup/forwarding-dom/SyntheticKeyboardEvent.js diff --git a/scripts/rollup/forwarding/SyntheticMouseEvent.js b/scripts/rollup/forwarding-dom/SyntheticMouseEvent.js similarity index 100% rename from scripts/rollup/forwarding/SyntheticMouseEvent.js rename to scripts/rollup/forwarding-dom/SyntheticMouseEvent.js diff --git a/scripts/rollup/forwarding/SyntheticUIEvent.js b/scripts/rollup/forwarding-dom/SyntheticUIEvent.js similarity index 100% rename from scripts/rollup/forwarding/SyntheticUIEvent.js rename to scripts/rollup/forwarding-dom/SyntheticUIEvent.js diff --git a/scripts/rollup/forwarding/ViewportMetrics.js b/scripts/rollup/forwarding-dom/ViewportMetrics.js similarity index 100% rename from scripts/rollup/forwarding/ViewportMetrics.js rename to scripts/rollup/forwarding-dom/ViewportMetrics.js diff --git a/scripts/rollup/forwarding/adler32.js b/scripts/rollup/forwarding-dom/adler32.js similarity index 100% rename from scripts/rollup/forwarding/adler32.js rename to scripts/rollup/forwarding-dom/adler32.js diff --git a/scripts/rollup/forwarding/findDOMNode.js b/scripts/rollup/forwarding-dom/findDOMNode.js similarity index 100% rename from scripts/rollup/forwarding/findDOMNode.js rename to scripts/rollup/forwarding-dom/findDOMNode.js diff --git a/scripts/rollup/forwarding/flattenChildren.js b/scripts/rollup/forwarding-dom/flattenChildren.js similarity index 100% rename from scripts/rollup/forwarding/flattenChildren.js rename to scripts/rollup/forwarding-dom/flattenChildren.js diff --git a/scripts/rollup/forwarding/getComponentName.js b/scripts/rollup/forwarding-dom/getComponentName.js similarity index 100% rename from scripts/rollup/forwarding/getComponentName.js rename to scripts/rollup/forwarding-dom/getComponentName.js diff --git a/scripts/rollup/forwarding/getEventCharCode.js b/scripts/rollup/forwarding-dom/getEventCharCode.js similarity index 100% rename from scripts/rollup/forwarding/getEventCharCode.js rename to scripts/rollup/forwarding-dom/getEventCharCode.js diff --git a/scripts/rollup/forwarding/getEventKey.js b/scripts/rollup/forwarding-dom/getEventKey.js similarity index 100% rename from scripts/rollup/forwarding/getEventKey.js rename to scripts/rollup/forwarding-dom/getEventKey.js diff --git a/scripts/rollup/forwarding/getEventTarget.js b/scripts/rollup/forwarding-dom/getEventTarget.js similarity index 100% rename from scripts/rollup/forwarding/getEventTarget.js rename to scripts/rollup/forwarding-dom/getEventTarget.js diff --git a/scripts/rollup/forwarding/getVendorPrefixedEventName.js b/scripts/rollup/forwarding-dom/getVendorPrefixedEventName.js similarity index 100% rename from scripts/rollup/forwarding/getVendorPrefixedEventName.js rename to scripts/rollup/forwarding-dom/getVendorPrefixedEventName.js diff --git a/scripts/rollup/forwarding/isEventSupported.js b/scripts/rollup/forwarding-dom/isEventSupported.js similarity index 100% rename from scripts/rollup/forwarding/isEventSupported.js rename to scripts/rollup/forwarding-dom/isEventSupported.js diff --git a/scripts/rollup/forwarding/onlyChild.js b/scripts/rollup/forwarding-dom/onlyChild.js similarity index 100% rename from scripts/rollup/forwarding/onlyChild.js rename to scripts/rollup/forwarding-dom/onlyChild.js diff --git a/scripts/rollup/forwarding/renderSubtreeIntoContainer.js b/scripts/rollup/forwarding-dom/renderSubtreeIntoContainer.js similarity index 100% rename from scripts/rollup/forwarding/renderSubtreeIntoContainer.js rename to scripts/rollup/forwarding-dom/renderSubtreeIntoContainer.js diff --git a/scripts/rollup/forwarding/setInnerHTML.js b/scripts/rollup/forwarding-dom/setInnerHTML.js similarity index 100% rename from scripts/rollup/forwarding/setInnerHTML.js rename to scripts/rollup/forwarding-dom/setInnerHTML.js diff --git a/scripts/rollup/forwarding/setTextContent.js b/scripts/rollup/forwarding-dom/setTextContent.js similarity index 100% rename from scripts/rollup/forwarding/setTextContent.js rename to scripts/rollup/forwarding-dom/setTextContent.js diff --git a/scripts/rollup/forwarding-native/NativeMethodsMixin.js b/scripts/rollup/forwarding-native/NativeMethodsMixin.js new file mode 100644 index 0000000000..6b42c6b279 --- /dev/null +++ b/scripts/rollup/forwarding-native/NativeMethodsMixin.js @@ -0,0 +1,20 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * 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 NativeMethodsMixin + * @flow + */ + +'use strict'; + +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; + \ No newline at end of file diff --git a/scripts/rollup/forwarding-native/ReactDebugTool.js b/scripts/rollup/forwarding-native/ReactDebugTool.js new file mode 100644 index 0000000000..ace94621c9 --- /dev/null +++ b/scripts/rollup/forwarding-native/ReactDebugTool.js @@ -0,0 +1,20 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * 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 ReactDebugTool + * @flow + */ + +'use strict'; + +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.ReactDebugTool; + \ No newline at end of file diff --git a/scripts/rollup/forwarding-native/ReactErrorUtils.js b/scripts/rollup/forwarding-native/ReactErrorUtils.js new file mode 100644 index 0000000000..974f7d5b89 --- /dev/null +++ b/scripts/rollup/forwarding-native/ReactErrorUtils.js @@ -0,0 +1,20 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * 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 ReactErrorUtils + * @flow + */ + +'use strict'; + +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.ReactErrorUtils; + \ No newline at end of file diff --git a/scripts/rollup/forwarding-native/ReactNativePropRegistry.js b/scripts/rollup/forwarding-native/ReactNativePropRegistry.js new file mode 100644 index 0000000000..e4cfeb3ed9 --- /dev/null +++ b/scripts/rollup/forwarding-native/ReactNativePropRegistry.js @@ -0,0 +1,19 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * 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 ReactNativePropRegistry + * @flow + */ + +'use strict'; + +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.ReactNativePropRegistry; diff --git a/scripts/rollup/forwarding-native/TouchHistoryMath.js b/scripts/rollup/forwarding-native/TouchHistoryMath.js new file mode 100644 index 0000000000..3ec4f9629a --- /dev/null +++ b/scripts/rollup/forwarding-native/TouchHistoryMath.js @@ -0,0 +1,20 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * 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 TouchHistoryMath + * @flow + */ + +'use strict'; + +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.TouchHistoryMath; + \ No newline at end of file diff --git a/scripts/rollup/forwarding-native/createReactNativeComponentClass.js b/scripts/rollup/forwarding-native/createReactNativeComponentClass.js new file mode 100644 index 0000000000..05dde97e39 --- /dev/null +++ b/scripts/rollup/forwarding-native/createReactNativeComponentClass.js @@ -0,0 +1,20 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * 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 createReactNativeComponentClass + * @flow + */ + +'use strict'; + +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.createReactNativeComponentClass; + \ No newline at end of file diff --git a/scripts/rollup/forwarding-native/findNodeHandle.js b/scripts/rollup/forwarding-native/findNodeHandle.js new file mode 100644 index 0000000000..501da7a412 --- /dev/null +++ b/scripts/rollup/forwarding-native/findNodeHandle.js @@ -0,0 +1,20 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * 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 findNodeHandle + * @flow + */ + +'use strict'; + +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.findNodeHandle; + \ No newline at end of file diff --git a/scripts/rollup/modules.js b/scripts/rollup/modules.js index 91c21c8712..abb602918b 100644 --- a/scripts/rollup/modules.js +++ b/scripts/rollup/modules.js @@ -36,6 +36,7 @@ function getExternalModules(bundleType) { }; case bundleTypes.NODE: case bundleTypes.FB: + case bundleTypes.RN: return {}; } } @@ -58,6 +59,7 @@ function getInternalModules(bundleType) { }; case bundleTypes.NODE: case bundleTypes.FB: + case bundleTypes.RN: // TODO: I haven't checked if this is right return { // we tell Rollup where these files are located internally, otherwise // it doesn't pick them up and assumes they're external @@ -76,6 +78,7 @@ function replaceInternalModules(bundleType) { case bundleTypes.PROD: case bundleTypes.NODE: case bundleTypes.FB: + case bundleTypes.RN: // we inline these modules in the bundles rather than leave them as external return { 'react-dom/lib/ReactPerf': resolve('./src/renderers/shared/ReactPerf.js'), @@ -112,6 +115,7 @@ function getFbjsModuleAliases(bundleType) { }; case bundleTypes.NODE: case bundleTypes.FB: + case bundleTypes.RN: // for FB we don't want to bundle the above modules, instead keep them // as external require() calls in the bundle return {}; @@ -123,6 +127,7 @@ function replaceFbjsModuleAliases(bundleType) { case bundleTypes.DEV: case bundleTypes.PROD: case bundleTypes.NODE: + case bundleTypes.RN: return {}; case bundleTypes.FB: // the diff for Haste to support fbjs/lib/* hasn't landed, so this diff --git a/src/renderers/native/ReactNative.js b/src/renderers/native/ReactNative.js index 27c56d54ba..764acd8086 100644 --- a/src/renderers/native/ReactNative.js +++ b/src/renderers/native/ReactNative.js @@ -7,9 +7,16 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule ReactNative - * @flow */ 'use strict'; +var ReactNativeStack = require('ReactNativeStack'); + // TODO (bvaughn) Enable Fiber experiement via ReactNativeFeatureFlags -module.exports = require('ReactNativeStack'); +var ReactNative = ReactNativeStack; + +ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = { + ReactNativePropRegistry: require('ReactNativePropRegistry'), +}; + +module.exports = ReactNative;