Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
[ghstack-poisoned]
  • Loading branch information
poteto committed Jul 29, 2024
2 parents b438a73 + 00bf208 commit 418b368
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 29 deletions.
28 changes: 24 additions & 4 deletions scripts/rollup/build-all-release-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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');
Expand All @@ -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);
Expand All @@ -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
Expand Down
48 changes: 23 additions & 25 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -357,8 +366,7 @@ function getPlugins(
globalName,
moduleType,
pureExternalModules,
bundle,
isExperimental
bundle
) {
try {
const forks = Modules.getForks(bundleType, entry, moduleType, bundle);
Expand Down Expand Up @@ -420,7 +428,7 @@ function getPlugins(
'process.env.NODE_ENV': isProduction
? "'production'"
: "'development'",
__EXPERIMENTAL__: isExperimental,
__EXPERIMENTAL__,
},
}),
{
Expand Down Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -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)) {
Expand All @@ -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()})`);
Expand All @@ -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);
Expand Down Expand Up @@ -680,8 +688,7 @@ async function createBundle(bundle, bundleType, isExperimental) {
bundle.global,
bundle.moduleType,
pureExternalModules,
bundle,
isExperimental
bundle
),
output: {
externalLiveBindings: false,
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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();
Expand All @@ -877,6 +877,4 @@ async function buildEverything(releaseChannel, index, total) {
}
}

module.exports = {
buildEverything,
};
buildEverything();

0 comments on commit 418b368

Please sign in to comment.