diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index aaf7a66775..5c7d429058 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -54,8 +54,11 @@ function getAliases(paths, bundleType, isRenderer) { // the facebook-www directory const facebookWWW = 'facebook-www'; +// bundle types for shorthand +const { UMD_DEV, UMD_PROD, NODE_DEV, NODE_PROD, FB_DEV, FB_PROD, RN } = bundleTypes; + function getBanner(bundleType, hastName) { - if (bundleType === bundleTypes.FB || bundleType === bundleTypes.RN) { + if (bundleType === FB_DEV || bundleType === FB_PROD || bundleType === RN) { return ( // intentionally not indented correctly, as whitespace is literal `/** @@ -77,11 +80,11 @@ function updateBabelConfig(babelOpts, bundleType) { let newOpts; switch (bundleType) { - case bundleTypes.UMD_DEV: - case bundleTypes.UMD_PROD: - case bundleTypes.NODE_DEV: - case bundleTypes.NODE_PROD: - case bundleTypes.RN: + case UMD_DEV: + case UMD_PROD: + case NODE_DEV: + case NODE_PROD: + case RN: newOpts = Object.assign({}, babelOpts); // we add the objectAssign transform for these bundles @@ -90,7 +93,8 @@ function updateBabelConfig(babelOpts, bundleType) { resolve('./scripts/babel/transform-object-assign-require') ); return newOpts; - case bundleTypes.FB: + case FB_DEV: + case FB_PROD: newOpts = Object.assign({}, babelOpts); // for FB, we don't want the devExpressionWithCodes plugin to run @@ -110,11 +114,11 @@ function handleRollupWarnings(warning) { function updateBundleConfig(config, filename, format, bundleType, hastName) { let dest = config.destDir + filename; - if (bundleType === bundleTypes.FB) { + if (bundleType === FB_DEV || bundleType === FB_PROD) { dest = `${config.destDir}${facebookWWW}/${filename}`; - } else if (bundleType === bundleTypes.UMD_DEV || bundleType === bundleTypes.UMD_PROD) { + } else if (bundleType === UMD_DEV || bundleType === UMD_PROD) { dest = `${config.destDir}dist/${filename}`; - } else if (bundleType === bundleTypes.RN) { + } else if (bundleType === RN) { dest = `${config.destDir}react-native/${filename}`; } return Object.assign({}, config, { @@ -134,30 +138,34 @@ function stripEnvVariables(production) { function getFormat(bundleType) { switch (bundleType) { - case bundleTypes.UMD_DEV: - case bundleTypes.UMD_PROD: + case UMD_DEV: + case UMD_PROD: return `umd`; - case bundleTypes.NODE_DEV: - case bundleTypes.NODE_PROD: - case bundleTypes.FB: - case bundleTypes.RN: + case NODE_DEV: + case NODE_PROD: + case FB_DEV: + case FB_PROD: + case RN: return `cjs`; } } function getFilename(name, hasteName, bundleType) { switch (bundleType) { - case bundleTypes.UMD_DEV: + case UMD_DEV: return `${name}.development.js`; - case bundleTypes.UMD_PROD: + case UMD_PROD: return `${name}.production.min.js`; - case bundleTypes.NODE_DEV: + case NODE_DEV: return `${name}.node-development.js`; - case bundleTypes.NODE_PROD: + case NODE_PROD: return `${name}.node-production.min.js`; - case bundleTypes.FB: - case bundleTypes.RN: + case RN: return `${hasteName}.js`; + case FB_DEV: + return `${hasteName}-dev.js`; + case FB_PROD: + return `${hasteName}-prod.js`; } } @@ -179,16 +187,17 @@ function uglifyConfig() { function getCommonJsConfig(bundleType) { switch (bundleType) { - case bundleTypes.UMD_DEV: - case bundleTypes.UMD_PROD: - case bundleTypes.NODE_DEV: - case bundleTypes.NODE_PROD: + case UMD_DEV: + case UMD_PROD: + case NODE_DEV: + case NODE_PROD: return {}; - case bundleTypes.RN: + case RN: return { ignore: ignoreReactNativeModules(), }; - case bundleTypes.FB: + case FB_DEV: + case FB_PROD: // Modules we don't want to inline in the bundle. // Force them to stay as require()s in the output. return { @@ -259,7 +268,7 @@ function copyBundleIntoNodePackage(packageName, filename, bundleType) { // for UMD bundles we have to move the files into a dist directory // within the package directory. we also need to set the from // to be the root build from directory - if (bundleType === bundleTypes.UMD_DEV || bundleType === bundleTypes.UMD_PROD) { + if (bundleType === UMD_DEV || bundleType === UMD_PROD) { const distDirectory = `${packageDirectory}/dist`; // create a dist directory if not created if (!existsSync(distDirectory)) { @@ -270,7 +279,7 @@ function copyBundleIntoNodePackage(packageName, filename, bundleType) { } return asyncCopyTo(from, to).then(() => { // delete the old file if this is a not a UMD bundle - if (bundleType !== bundleTypes.UMD_DEV && bundleType !== bundleTypes.UMD_PROD) { + if (bundleType !== UMD_DEV && bundleType !== UMD_PROD) { unlinkSync(from); } }); @@ -281,7 +290,7 @@ function copyBundleIntoNodePackage(packageName, filename, bundleType) { function createNodePackage(bundleType, packageName, filename) { // the only case where we don't want to copy the package is for FB bundles - if (bundleType !== bundleTypes.FB) { + if (bundleType !== FB_DEV && bundleType !== FB_PROD) { return copyNodePackageTemplate(packageName).then( () => copyBundleIntoNodePackage(packageName, filename, bundleType) ); @@ -301,14 +310,14 @@ function getPlugins(entry, babelOpts, paths, filename, bundleType, isRenderer) { alias(getAliases(paths, bundleType, isRenderer)), commonjs(getCommonJsConfig(bundleType)), ]; - if (bundleType === bundleTypes.UMD_PROD || bundleType === bundleTypes.NODE_PROD) { + if (bundleType === UMD_PROD || bundleType === NODE_PROD || bundleType === FB_PROD) { plugins.push( uglify(uglifyConfig()), replace( stripEnvVariables(true) ) ); - } else if (bundleType === bundleTypes.UMD_DEV || bundleType === bundleTypes.NODE_DEV) { + } else if (bundleType === UMD_DEV || bundleType === NODE_DEV || FB_DEV) { plugins.push( replace( stripEnvVariables(false) @@ -345,15 +354,14 @@ function createBundle({ isRenderer, externals, }, bundleType) { - if ((inputBundleType && inputBundleType !== bundleType) + if ((inputBundleType && bundleType.indexOf(inputBundleType) === -1) || bundleTypesToUse.indexOf(bundleType) === -1) { return Promise.resolve(); } - const filename = getFilename(name, hasteName, bundleType); const format = getFormat(bundleType); return rollup({ - entry: bundleType === bundleTypes.FB ? fbEntry : entry, + entry: bundleType === FB_DEV || bundleType === FB_PROD ? fbEntry : entry, external: getExternalModules(externals, bundleType, isRenderer), onwarn: handleRollupWarnings, plugins: getPlugins(entry, babelOpts, paths, filename, bundleType, isRenderer), @@ -382,12 +390,13 @@ rimraf('build', async () => { // this helps improve console/warning/error output // and fixes a bunch of IO failures that sometimes occured for (const bundle of bundles) { - await createBundle(bundle, bundleTypes.UMD_DEV); - await createBundle(bundle, bundleTypes.UMD_PROD); - await createBundle(bundle, bundleTypes.NODE_DEV); - await createBundle(bundle, bundleTypes.NODE_PROD); - await createBundle(bundle, bundleTypes.FB); - await createBundle(bundle, bundleTypes.RN); + await createBundle(bundle, UMD_DEV); + 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); } if (argv.extractErrors) { console.warn( diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index ca76fd4df4..57eea11ccf 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -7,11 +7,12 @@ const bundleTypes = { UMD_PROD: 'UMD_PROD', NODE_DEV: 'NODE_DEV', NODE_PROD: 'NODE_PROD', - FB: 'FB', + FB_DEV: 'FB_DEV', + FB_PROD: 'FB_PROD', RN: 'RN', }; -const { UMD_DEV, UMD_PROD, NODE_DEV, NODE_PROD, FB, RN } = bundleTypes; +const { UMD_DEV, UMD_PROD, NODE_DEV, NODE_PROD, FB_DEV, FB_PROD, RN } = bundleTypes; const babelOptsReact = { exclude: 'node_modules/**', @@ -29,7 +30,7 @@ const bundles = [ /******* Isomorphic *******/ { babelOpts: babelOptsReact, - bundleTypes: [UMD_DEV, UMD_PROD, NODE_DEV, NODE_PROD, FB], + bundleTypes: [UMD_DEV, UMD_PROD, NODE_DEV, NODE_PROD, FB_DEV, FB_PROD], config: { destDir: 'build/', moduleName: 'React', @@ -38,7 +39,7 @@ const bundles = [ entry: 'src/umd/ReactUMDEntry.js', externals: [], fbEntry: 'src/fb/ReactFBEntry.js', - hasteName: 'React-build', + hasteName: 'React', isRenderer: false, name: 'react', paths: [ @@ -57,7 +58,7 @@ const bundles = [ /******* React DOM *******/ { babelOpts: babelOptsReact, - bundleTypes: [FB], + bundleTypes: [FB_DEV, FB_PROD], config: { destDir: 'build/', globals: { @@ -69,7 +70,7 @@ const bundles = [ entry: 'src/umd/ReactDOMUMDEntry.js', externals: [], fbEntry: 'src/fb/ReactDOMFBEntry.js', - hasteName: 'ReactDOMStack-build', + hasteName: 'ReactDOMStack', isRenderer: true, name: 'react-dom-stack', paths: [ @@ -85,7 +86,7 @@ const bundles = [ }, { babelOpts: babelOptsReact, - bundleTypes: [UMD_DEV, UMD_PROD, NODE_DEV, NODE_PROD, FB], + bundleTypes: [UMD_DEV, UMD_PROD, NODE_DEV, NODE_PROD, FB_DEV, FB_PROD], config: { destDir: 'build/', globals: { @@ -97,7 +98,7 @@ const bundles = [ entry: 'src/renderers/dom/fiber/ReactDOMFiber.js', externals: [], fbEntry: 'src/fb/ReactDOMFiberFBEntry.js', - hasteName: 'ReactDOMFiber-build', + hasteName: 'ReactDOMFiber', isRenderer: true, name: 'react-dom', paths: [ @@ -114,7 +115,7 @@ const bundles = [ { babelOpts: babelOptsReact, // TODO: deal with the Node version of react-dom-server package - bundleTypes: [UMD_DEV, UMD_PROD, FB], + bundleTypes: [UMD_DEV, UMD_PROD, FB_DEV, FB_PROD], config: { destDir: 'build/', globals: { @@ -126,7 +127,7 @@ const bundles = [ entry: 'src/umd/ReactDOMServerUMDEntry.js', externals: [], fbEntry: 'src/umd/ReactDOMServerUMDEntry.js', - hasteName: 'ReactDOMServerStack-build', + hasteName: 'ReactDOMServerStack', isRenderer: true, // TODO: this is taken. Do we change the build task // to understand react-dom/server? @@ -148,7 +149,7 @@ const bundles = [ babelOpts: babelOptsReactART, // TODO: we merge react-art repo into this repo so the NODE_DEV and NODE_PROD // builds sync up to the building of the package directories - bundleTypes: [FB], + bundleTypes: [FB_DEV, FB_PROD], config: { destDir: 'build/', globals: { @@ -164,7 +165,7 @@ const bundles = [ 'art/core/transform', ], fbEntry: 'src/renderers/art/ReactARTStack.js', - hasteName: 'ReactARTStack-build', + hasteName: 'ReactARTStack', isRenderer: true, name: 'react-art', nodePackageName: 'react-art', @@ -182,7 +183,7 @@ const bundles = [ babelOpts: babelOptsReactART, // TODO: we merge react-art repo into this repo so the NODE_DEV and NODE_PROD // builds sync up to the building of the package directories - bundleTypes: [UMD_DEV, UMD_PROD, FB], + bundleTypes: [UMD_DEV, UMD_PROD, FB_DEV, FB_PROD], config: { destDir: 'build/', globals: { @@ -198,7 +199,7 @@ const bundles = [ 'art/core/transform', ], fbEntry: 'src/renderers/art/ReactARTFiber.js', - hasteName: 'ReactARTFiber-build', + hasteName: 'ReactARTFiber', isRenderer: true, name: 'react-art', paths: [ @@ -246,7 +247,7 @@ const bundles = [ /******* React Test Renderer *******/ { babelOpts: babelOptsReact, - bundleTypes: [NODE_DEV, FB], + bundleTypes: [NODE_DEV, FB_DEV, FB_PROD], config: { destDir: 'build/', moduleName: 'ReactTestRenderer', @@ -255,7 +256,7 @@ const bundles = [ entry: 'src/renderers/testing/ReactTestRendererFiber', externals: [], fbEntry: 'src/renderers/testing/ReactTestRendererFiber', - hasteName: 'ReactTestRendererFiber-build', + hasteName: 'ReactTestRendererFiber', isRenderer: true, name: 'react-test-renderer', paths: [ @@ -270,7 +271,7 @@ const bundles = [ { babelOpts: babelOptsReact, - bundleTypes: [FB], + bundleTypes: [FB_DEV], config: { destDir: 'build/', moduleName: 'ReactTestRenderer', @@ -279,7 +280,7 @@ const bundles = [ entry: 'src/renderers/testing/stack/ReactTestRendererStack', externals: [], fbEntry: 'src/renderers/testing/stack/ReactTestRendererStack', - hasteName: 'ReactTestRendererStack-build', + hasteName: 'ReactTestRendererStack', isRenderer: true, name: 'react-test-renderer-stack', paths: [ diff --git a/scripts/rollup/modules.js b/scripts/rollup/modules.js index ec05391275..58edb628cd 100644 --- a/scripts/rollup/modules.js +++ b/scripts/rollup/modules.js @@ -12,6 +12,8 @@ const exclude = [ 'src/**/__mocks__/**/*.js', ]; +// bundle types for shorthand +const { UMD_DEV, UMD_PROD, NODE_DEV, NODE_PROD, FB_DEV, FB_PROD, RN } = bundleTypes; // these are the FBJS modules that are used throughout our bundles const fbjsModules = [ @@ -66,15 +68,16 @@ function getNodeModules(bundleType) { // we can instead deal with the only node module that is used // for UMD bundles - object-assign switch (bundleType) { - case bundleTypes.UMD_DEV: - case bundleTypes.UMD_PROD: + case UMD_DEV: + case UMD_PROD: return { 'object-assign': resolve('./node_modules/object-assign/index.js'), }; - case bundleTypes.NODE_DEV: - case bundleTypes.NODE_PROD: - case bundleTypes.FB: - case bundleTypes.RN: + case NODE_DEV: + case NODE_PROD: + case FB_DEV: + case FB_PROD: + case RN: return {}; } } @@ -109,17 +112,17 @@ function getExternalModules(externals, bundleType, isRenderer) { let externalModules = externals; switch (bundleType) { - case bundleTypes.UMD_DEV: - case bundleTypes.UMD_PROD: + case UMD_DEV: + case UMD_PROD: if (isRenderer) { externalModules.push( 'react' ); } break; - case bundleTypes.NODE_DEV: - case bundleTypes.NODE_PROD: - case bundleTypes.RN: + case NODE_DEV: + case NODE_PROD: + case RN: externalModules.push( 'object-assign', ...fbjsModules @@ -131,7 +134,8 @@ function getExternalModules(externals, bundleType, isRenderer) { ); } break; - case bundleTypes.FB: + case FB_DEV: + case FB_PROD: externalModules.push( ...fbjsModules ); @@ -166,8 +170,8 @@ function replaceInternalModules() { function getFbjsModuleAliases(bundleType) { switch (bundleType) { - case bundleTypes.UMD_DEV: - case bundleTypes.UMD_PROD: + case UMD_DEV: + case UMD_PROD: // we want to bundle these modules, so we re-alias them to the actual // file so Rollup can bundle them up const fbjsModulesAlias = {}; @@ -176,10 +180,11 @@ function getFbjsModuleAliases(bundleType) { }); return fbjsModulesAlias; - case bundleTypes.NODE_DEV: - case bundleTypes.NODE_PROD: - case bundleTypes.FB: - case bundleTypes.RN: + case NODE_DEV: + case NODE_PROD: + case FB_DEV: + case FB_PROD: + case RN: // for FB we don't want to bundle the above modules, instead keep them // as external require() calls in the bundle return {}; @@ -188,13 +193,14 @@ function getFbjsModuleAliases(bundleType) { function replaceFbjsModuleAliases(bundleType) { switch (bundleType) { - case bundleTypes.UMD_DEV: - case bundleTypes.UMD_PROD: - case bundleTypes.NODE_DEV: - case bundleTypes.NODE_PROD: - case bundleTypes.RN: + case UMD_DEV: + case UMD_PROD: + case NODE_DEV: + case NODE_PROD: + case RN: return {}; - case bundleTypes.FB: + case FB_DEV: + case FB_PROD: // additionally we add mappings for "react" // so they work correctly on FB, this will change soon return {