From 8677c3a73090a9179b00db7f0fffb6572d941f7c Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Wed, 15 Mar 2023 13:52:51 -0400 Subject: [PATCH] Extract bundle flag calculations --- scripts/rollup/build.js | 73 +++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index 15295a11b9ec9..94683b30e39ab 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -311,6 +311,45 @@ function isProfilingBundleType(bundleType) { } } +function getBundleTypeFlags(bundleType) { + const isUMDBundle = + bundleType === UMD_DEV || + bundleType === UMD_PROD || + bundleType === UMD_PROFILING; + const isFBWWWBundle = + 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_PROFILING; + + const isFBRNBundle = + bundleType === RN_FB_DEV || + bundleType === RN_FB_PROD || + bundleType === RN_FB_PROFILING; + + const shouldStayReadable = isFBWWWBundle || isRNBundle || forcePrettyOutput; + + const shouldBundleDependencies = + bundleType === UMD_DEV || + bundleType === UMD_PROD || + bundleType === UMD_PROFILING; + + return { + isUMDBundle, + isFBWWWBundle, + isRNBundle, + isFBRNBundle, + shouldBundleDependencies, + shouldStayReadable, + }; +} + function forbidFBJSImports() { return { name: 'forbidFBJSImports', @@ -340,22 +379,9 @@ function getPlugins( const forks = Modules.getForks(bundleType, entry, moduleType, bundle); const isProduction = isProductionBundleType(bundleType); const isProfiling = isProfilingBundleType(bundleType); - const isUMDBundle = - bundleType === UMD_DEV || - bundleType === UMD_PROD || - bundleType === UMD_PROFILING; - const isFBWWWBundle = - 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_PROFILING; - const shouldStayReadable = isFBWWWBundle || isRNBundle || forcePrettyOutput; + + const {isUMDBundle, shouldStayReadable} = getBundleTypeFlags(bundleType); + return [ // Keep dynamic imports as externals dynamicImports(), @@ -564,25 +590,14 @@ async function createBundle(bundle, bundleType) { const format = getFormat(bundleType); const packageName = Packaging.getPackageName(bundle.entry); - const isFBWWWBundle = - bundleType === FB_WWW_DEV || - bundleType === FB_WWW_PROD || - bundleType === FB_WWW_PROFILING; - - const isFBRNBundle = - bundleType === RN_FB_DEV || - bundleType === RN_FB_PROD || - bundleType === RN_FB_PROFILING; + const {isFBWWWBundle, isFBRNBundle, shouldBundleDependencies} = + getBundleTypeFlags(bundleType); let resolvedEntry = resolveEntryFork( require.resolve(bundle.entry), isFBWWWBundle || isFBRNBundle ); - const shouldBundleDependencies = - bundleType === UMD_DEV || - bundleType === UMD_PROD || - bundleType === UMD_PROFILING; const peerGlobals = Modules.getPeerGlobals(bundle.externals, bundleType); let externals = Object.keys(peerGlobals); if (!shouldBundleDependencies) {