Skip to content

Commit 3da7a99

Browse files
committed
Extract bundle flag calculations
1 parent f118b7c commit 3da7a99

File tree

1 file changed

+44
-29
lines changed

1 file changed

+44
-29
lines changed

scripts/rollup/build.js

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,45 @@ function isProfilingBundleType(bundleType) {
315315
}
316316
}
317317

318+
function getBundleTypeFlags(bundleType) {
319+
const isUMDBundle =
320+
bundleType === UMD_DEV ||
321+
bundleType === UMD_PROD ||
322+
bundleType === UMD_PROFILING;
323+
const isFBWWWBundle =
324+
bundleType === FB_WWW_DEV ||
325+
bundleType === FB_WWW_PROD ||
326+
bundleType === FB_WWW_PROFILING;
327+
const isRNBundle =
328+
bundleType === RN_OSS_DEV ||
329+
bundleType === RN_OSS_PROD ||
330+
bundleType === RN_OSS_PROFILING ||
331+
bundleType === RN_FB_DEV ||
332+
bundleType === RN_FB_PROD ||
333+
bundleType === RN_FB_PROFILING;
334+
335+
const isFBRNBundle =
336+
bundleType === RN_FB_DEV ||
337+
bundleType === RN_FB_PROD ||
338+
bundleType === RN_FB_PROFILING;
339+
340+
const shouldStayReadable = isFBWWWBundle || isRNBundle || forcePrettyOutput;
341+
342+
const shouldBundleDependencies =
343+
bundleType === UMD_DEV ||
344+
bundleType === UMD_PROD ||
345+
bundleType === UMD_PROFILING;
346+
347+
return {
348+
isUMDBundle,
349+
isFBWWWBundle,
350+
isRNBundle,
351+
isFBRNBundle,
352+
shouldBundleDependencies,
353+
shouldStayReadable,
354+
};
355+
}
356+
318357
function forbidFBJSImports() {
319358
return {
320359
name: 'forbidFBJSImports',
@@ -344,22 +383,9 @@ function getPlugins(
344383
const forks = Modules.getForks(bundleType, entry, moduleType, bundle);
345384
const isProduction = isProductionBundleType(bundleType);
346385
const isProfiling = isProfilingBundleType(bundleType);
347-
const isUMDBundle =
348-
bundleType === UMD_DEV ||
349-
bundleType === UMD_PROD ||
350-
bundleType === UMD_PROFILING;
351-
const isFBWWWBundle =
352-
bundleType === FB_WWW_DEV ||
353-
bundleType === FB_WWW_PROD ||
354-
bundleType === FB_WWW_PROFILING;
355-
const isRNBundle =
356-
bundleType === RN_OSS_DEV ||
357-
bundleType === RN_OSS_PROD ||
358-
bundleType === RN_OSS_PROFILING ||
359-
bundleType === RN_FB_DEV ||
360-
bundleType === RN_FB_PROD ||
361-
bundleType === RN_FB_PROFILING;
362-
const shouldStayReadable = isFBWWWBundle || isRNBundle || forcePrettyOutput;
386+
387+
const {isUMDBundle, shouldStayReadable} = getBundleTypeFlags(bundleType);
388+
363389
return [
364390
// Keep dynamic imports as externals
365391
dynamicImports(),
@@ -568,25 +594,14 @@ async function createBundle(bundle, bundleType) {
568594
const format = getFormat(bundleType);
569595
const packageName = Packaging.getPackageName(bundle.entry);
570596

571-
const isFBWWWBundle =
572-
bundleType === FB_WWW_DEV ||
573-
bundleType === FB_WWW_PROD ||
574-
bundleType === FB_WWW_PROFILING;
575-
576-
const isFBRNBundle =
577-
bundleType === RN_FB_DEV ||
578-
bundleType === RN_FB_PROD ||
579-
bundleType === RN_FB_PROFILING;
597+
const {isFBWWWBundle, isFBRNBundle, shouldBundleDependencies} =
598+
getBundleTypeFlags(bundleType);
580599

581600
let resolvedEntry = resolveEntryFork(
582601
require.resolve(bundle.entry),
583602
isFBWWWBundle || isFBRNBundle
584603
);
585604

586-
const shouldBundleDependencies =
587-
bundleType === UMD_DEV ||
588-
bundleType === UMD_PROD ||
589-
bundleType === UMD_PROFILING;
590605
const peerGlobals = Modules.getPeerGlobals(bundle.externals, bundleType);
591606
let externals = Object.keys(peerGlobals);
592607
if (!shouldBundleDependencies) {

0 commit comments

Comments
 (0)