From 00bf2084962ef22305b3896abf57326c01744713 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Mon, 29 Jul 2024 18:44:16 -0400 Subject: [PATCH] Update (base update) [ghstack-poisoned] --- scripts/rollup/build-all-release-channels.js | 28 ++++++++++-- scripts/rollup/build.js | 48 ++++++++++---------- 2 files changed, 47 insertions(+), 29 deletions(-) diff --git a/scripts/rollup/build-all-release-channels.js b/scripts/rollup/build-all-release-channels.js index ceb6467bba7ea..5615b5949c73e 100644 --- a/scripts/rollup/build-all-release-channels.js +++ b/scripts/rollup/build-all-release-channels.js @@ -16,7 +16,6 @@ const { rcNumber, } = require('../../ReactVersions'); const yargs = require('yargs'); -const {buildEverything} = require('./build'); const Bundles = require('./bundles'); // Runs the build script for both stable and experimental release channels, @@ -111,7 +110,7 @@ const argv = yargs.wrap(yargs.terminalWidth()).options({ async function main() { if (argv.ci === 'github') { - await buildEverything(argv.releaseChannel, argv.index, argv.total); + buildForChannel(argv.releaseChannel, argv.total, argv.index); switch (argv.releaseChannel) { case 'stable': { processStable('./build'); @@ -127,11 +126,11 @@ async function main() { } else { // Running locally, no concurrency. Move each channel's build artifacts into // a temporary directory so that they don't conflict. - await buildEverything('stable'); + buildForChannel('stable', '', ''); const stableDir = tmp.dirSync().name; crossDeviceRenameSync('./build', stableDir); processStable(stableDir); - await buildEverything('experimental'); + buildForChannel('experimental', '', ''); const experimentalDir = tmp.dirSync().name; crossDeviceRenameSync('./build', experimentalDir); processExperimental(experimentalDir); @@ -147,6 +146,27 @@ async function main() { } } +function buildForChannel(channel, total, index) { + const {status} = spawnSync( + 'node', + ['./scripts/rollup/build.js', ...process.argv.slice(2)], + { + stdio: ['pipe', process.stdout, process.stderr], + env: { + ...process.env, + RELEASE_CHANNEL: channel, + CI_TOTAL: total, + CI_INDEX: index, + }, + } + ); + + if (status !== 0) { + // Error of spawned process is already piped to this stderr + process.exit(status); + } +} + function processStable(buildDir) { if (fs.existsSync(buildDir + '/node_modules')) { // Identical to `oss-stable` but with real, semver versions. This is what diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index ab02392426533..5a709b5979ae1 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -23,6 +23,15 @@ const {asyncRimRaf} = require('./utils'); const codeFrame = require('@babel/code-frame'); const Wrappers = require('./wrappers'); +const RELEASE_CHANNEL = process.env.RELEASE_CHANNEL; + +// Default to building in experimental mode. If the release channel is set via +// an environment variable, then check if it's "experimental". +const __EXPERIMENTAL__ = + typeof RELEASE_CHANNEL === 'string' + ? RELEASE_CHANNEL === 'experimental' + : true; + // Errors in promises should be fatal. let loggedErrors = new Set(); process.on('unhandledRejection', err => { @@ -357,8 +366,7 @@ function getPlugins( globalName, moduleType, pureExternalModules, - bundle, - isExperimental + bundle ) { try { const forks = Modules.getForks(bundleType, entry, moduleType, bundle); @@ -420,7 +428,7 @@ function getPlugins( 'process.env.NODE_ENV': isProduction ? "'production'" : "'development'", - __EXPERIMENTAL__: isExperimental, + __EXPERIMENTAL__, }, }), { @@ -563,7 +571,7 @@ function shouldSkipBundle(bundle, bundleType) { return false; } -function resolveEntryFork(resolvedEntry, isFBBundle, isExperimental) { +function resolveEntryFork(resolvedEntry, isFBBundle) { // Pick which entry point fork to use: // .modern.fb.js // .classic.fb.js @@ -576,7 +584,7 @@ function resolveEntryFork(resolvedEntry, isFBBundle, isExperimental) { if (isFBBundle) { const resolvedFBEntry = resolvedEntry.replace( '.js', - isExperimental ? '.modern.fb.js' : '.classic.fb.js' + __EXPERIMENTAL__ ? '.modern.fb.js' : '.classic.fb.js' ); const developmentFBEntry = resolvedFBEntry.replace( '.js', @@ -603,7 +611,7 @@ function resolveEntryFork(resolvedEntry, isFBBundle, isExperimental) { } const resolvedForkedEntry = resolvedEntry.replace( '.js', - isExperimental ? '.experimental.js' : '.stable.js' + __EXPERIMENTAL__ ? '.experimental.js' : '.stable.js' ); const devForkedEntry = resolvedForkedEntry.replace('.js', '.development.js'); if (fs.existsSync(devForkedEntry)) { @@ -616,7 +624,7 @@ function resolveEntryFork(resolvedEntry, isFBBundle, isExperimental) { return resolvedEntry; } -async function createBundle(bundle, bundleType, isExperimental) { +async function createBundle(bundle, bundleType) { const filename = getFilename(bundle, bundleType); const logKey = chalk.white.bold(filename) + chalk.dim(` (${bundleType.toLowerCase()})`); @@ -629,7 +637,7 @@ async function createBundle(bundle, bundleType, isExperimental) { require.resolve(bundle.entry), isFBWWWBundle || isFBRNBundle, !isProductionBundleType(bundleType), - isExperimental + __EXPERIMENTAL__ ); const peerGlobals = Modules.getPeerGlobals(bundle.externals, bundleType); @@ -680,8 +688,7 @@ async function createBundle(bundle, bundleType, isExperimental) { bundle.global, bundle.moduleType, pureExternalModules, - bundle, - isExperimental + bundle ), output: { externalLiveBindings: false, @@ -807,14 +814,7 @@ function handleRollupError(error) { } } -async function buildEverything(releaseChannel, index, total) { - // Default to building in experimental mode. If the release channel is set via - // an environment variable, then check if it's "experimental". - const isExperimental = - typeof releaseChannel === 'string' - ? releaseChannel === 'experimental' - : true; - +async function buildEverything(index, total) { if (!argv['unsafe-partial']) { await asyncRimRaf('build'); } @@ -851,15 +851,15 @@ async function buildEverything(releaseChannel, index, total) { return !shouldSkipBundle(bundle, bundleType); }); - if (index != null && total != null) { - const nodeTotal = parseInt(total, 10); - const nodeIndex = parseInt(index, 10); + if (process.env.CI_TOTAL != null && process.env.CI_INDEX != null) { + const nodeTotal = parseInt(process.env.CI_TOTAL, 10); + const nodeIndex = parseInt(process.env.CI_INDEX, 10); bundles = bundles.filter((_, i) => i % nodeTotal === nodeIndex); } // eslint-disable-next-line no-for-of-loops/no-for-of-loops for (const [bundle, bundleType] of bundles) { - await createBundle(bundle, bundleType, isExperimental); + await createBundle(bundle, bundleType); } await Packaging.copyAllShims(); @@ -877,6 +877,4 @@ async function buildEverything(releaseChannel, index, total) { } } -module.exports = { - buildEverything, -}; +buildEverything();