Skip to content

Commit 9135f17

Browse files
committed
Extract bundle flag calculations
1 parent 312c4a4 commit 9135f17

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
@@ -310,6 +310,45 @@ function isProfilingBundleType(bundleType) {
310310
}
311311
}
312312

313+
function getBundleTypeFlags(bundleType) {
314+
const isUMDBundle =
315+
bundleType === UMD_DEV ||
316+
bundleType === UMD_PROD ||
317+
bundleType === UMD_PROFILING;
318+
const isFBWWWBundle =
319+
bundleType === FB_WWW_DEV ||
320+
bundleType === FB_WWW_PROD ||
321+
bundleType === FB_WWW_PROFILING;
322+
const isRNBundle =
323+
bundleType === RN_OSS_DEV ||
324+
bundleType === RN_OSS_PROD ||
325+
bundleType === RN_OSS_PROFILING ||
326+
bundleType === RN_FB_DEV ||
327+
bundleType === RN_FB_PROD ||
328+
bundleType === RN_FB_PROFILING;
329+
330+
const isFBRNBundle =
331+
bundleType === RN_FB_DEV ||
332+
bundleType === RN_FB_PROD ||
333+
bundleType === RN_FB_PROFILING;
334+
335+
const shouldStayReadable = isFBWWWBundle || isRNBundle || forcePrettyOutput;
336+
337+
const shouldBundleDependencies =
338+
bundleType === UMD_DEV ||
339+
bundleType === UMD_PROD ||
340+
bundleType === UMD_PROFILING;
341+
342+
return {
343+
isUMDBundle,
344+
isFBWWWBundle,
345+
isRNBundle,
346+
isFBRNBundle,
347+
shouldBundleDependencies,
348+
shouldStayReadable,
349+
};
350+
}
351+
313352
function forbidFBJSImports() {
314353
return {
315354
name: 'forbidFBJSImports',
@@ -339,22 +378,9 @@ function getPlugins(
339378
const forks = Modules.getForks(bundleType, entry, moduleType, bundle);
340379
const isProduction = isProductionBundleType(bundleType);
341380
const isProfiling = isProfilingBundleType(bundleType);
342-
const isUMDBundle =
343-
bundleType === UMD_DEV ||
344-
bundleType === UMD_PROD ||
345-
bundleType === UMD_PROFILING;
346-
const isFBWWWBundle =
347-
bundleType === FB_WWW_DEV ||
348-
bundleType === FB_WWW_PROD ||
349-
bundleType === FB_WWW_PROFILING;
350-
const isRNBundle =
351-
bundleType === RN_OSS_DEV ||
352-
bundleType === RN_OSS_PROD ||
353-
bundleType === RN_OSS_PROFILING ||
354-
bundleType === RN_FB_DEV ||
355-
bundleType === RN_FB_PROD ||
356-
bundleType === RN_FB_PROFILING;
357-
const shouldStayReadable = isFBWWWBundle || isRNBundle || forcePrettyOutput;
381+
382+
const {isUMDBundle, shouldStayReadable} = getBundleTypeFlags(bundleType);
383+
358384
return [
359385
// Keep dynamic imports as externals
360386
dynamicImports(),
@@ -563,25 +589,14 @@ async function createBundle(bundle, bundleType) {
563589
const format = getFormat(bundleType);
564590
const packageName = Packaging.getPackageName(bundle.entry);
565591

566-
const isFBWWWBundle =
567-
bundleType === FB_WWW_DEV ||
568-
bundleType === FB_WWW_PROD ||
569-
bundleType === FB_WWW_PROFILING;
570-
571-
const isFBRNBundle =
572-
bundleType === RN_FB_DEV ||
573-
bundleType === RN_FB_PROD ||
574-
bundleType === RN_FB_PROFILING;
592+
const {isFBWWWBundle, isFBRNBundle, shouldBundleDependencies} =
593+
getBundleTypeFlags(bundleType);
575594

576595
let resolvedEntry = resolveEntryFork(
577596
require.resolve(bundle.entry),
578597
isFBWWWBundle || isFBRNBundle
579598
);
580599

581-
const shouldBundleDependencies =
582-
bundleType === UMD_DEV ||
583-
bundleType === UMD_PROD ||
584-
bundleType === UMD_PROFILING;
585600
const peerGlobals = Modules.getPeerGlobals(bundle.externals, bundleType);
586601
let externals = Object.keys(peerGlobals);
587602
if (!shouldBundleDependencies) {

0 commit comments

Comments
 (0)