Skip to content

Commit cc33448

Browse files
committed
Extract bundle flag calculations
1 parent d5784fb commit cc33448

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

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

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

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

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

0 commit comments

Comments
 (0)