Skip to content

Commit

Permalink
Extract bundle flag calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Mar 24, 2023
1 parent d5784fb commit cc33448
Showing 1 changed file with 44 additions and 29 deletions.
73 changes: 44 additions & 29 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit cc33448

Please sign in to comment.