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
1 parent fda8387 commit 0d8c88c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 43 deletions.
25 changes: 3 additions & 22 deletions scripts/rollup/build-all-release-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const argv = yargs.wrap(yargs.terminalWidth()).options({

async function main() {
if (argv.ci === 'github') {
await buildEverything(argv.index, argv.total);
await buildEverything(argv.releaseChannel, argv.index, argv.total);
switch (argv.releaseChannel) {
case 'stable': {
processStable('./build');
Expand All @@ -127,11 +127,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.
buildForChannel('stable');
await buildEverything('stable');
const stableDir = tmp.dirSync().name;
crossDeviceRenameSync('./build', stableDir);
processStable(stableDir);
buildForChannel('experimental');
await buildEverything('experimental');
const experimentalDir = tmp.dirSync().name;
crossDeviceRenameSync('./build', experimentalDir);
processExperimental(experimentalDir);
Expand All @@ -147,25 +147,6 @@ async function main() {
}
}

function buildForChannel(channel) {
const {status} = spawnSync(
'node',
['./scripts/rollup/build.js', ...process.argv.slice(2)],
{
stdio: ['pipe', process.stdout, process.stderr],
env: {
...process.env,
RELEASE_CHANNEL: channel,
},
}
);

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
44 changes: 23 additions & 21 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ 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 @@ -366,7 +357,8 @@ function getPlugins(
globalName,
moduleType,
pureExternalModules,
bundle
bundle,
isExperimental
) {
try {
const forks = Modules.getForks(bundleType, entry, moduleType, bundle);
Expand Down Expand Up @@ -428,7 +420,7 @@ function getPlugins(
'process.env.NODE_ENV': isProduction
? "'production'"
: "'development'",
__EXPERIMENTAL__,
__EXPERIMENTAL__: isExperimental,
},
}),
{
Expand Down Expand Up @@ -571,7 +563,7 @@ function shouldSkipBundle(bundle, bundleType) {
return false;
}

function resolveEntryFork(resolvedEntry, isFBBundle) {
function resolveEntryFork(resolvedEntry, isFBBundle, isExperimental) {
// Pick which entry point fork to use:
// .modern.fb.js
// .classic.fb.js
Expand All @@ -584,7 +576,7 @@ function resolveEntryFork(resolvedEntry, isFBBundle) {
if (isFBBundle) {
const resolvedFBEntry = resolvedEntry.replace(
'.js',
__EXPERIMENTAL__ ? '.modern.fb.js' : '.classic.fb.js'
isExperimental ? '.modern.fb.js' : '.classic.fb.js'
);
const developmentFBEntry = resolvedFBEntry.replace(
'.js',
Expand All @@ -611,7 +603,7 @@ function resolveEntryFork(resolvedEntry, isFBBundle) {
}
const resolvedForkedEntry = resolvedEntry.replace(
'.js',
__EXPERIMENTAL__ ? '.experimental.js' : '.stable.js'
isExperimental ? '.experimental.js' : '.stable.js'
);
const devForkedEntry = resolvedForkedEntry.replace('.js', '.development.js');
if (fs.existsSync(devForkedEntry)) {
Expand All @@ -624,7 +616,7 @@ function resolveEntryFork(resolvedEntry, isFBBundle) {
return resolvedEntry;
}

async function createBundle(bundle, bundleType) {
async function createBundle(bundle, bundleType, isExperimental) {
const filename = getFilename(bundle, bundleType);
const logKey =
chalk.white.bold(filename) + chalk.dim(` (${bundleType.toLowerCase()})`);
Expand All @@ -636,7 +628,8 @@ async function createBundle(bundle, bundleType) {
let resolvedEntry = resolveEntryFork(
require.resolve(bundle.entry),
isFBWWWBundle || isFBRNBundle,
!isProductionBundleType(bundleType)
!isProductionBundleType(bundleType),
isExperimental
);

const peerGlobals = Modules.getPeerGlobals(bundle.externals, bundleType);
Expand Down Expand Up @@ -813,7 +806,14 @@ function handleRollupError(error) {
}
}

async function buildEverything(index, total) {
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;

if (!argv['unsafe-partial']) {
await asyncRimRaf('build');
}
Expand Down Expand Up @@ -850,13 +850,15 @@ async function buildEverything(index, total) {
return !shouldSkipBundle(bundle, bundleType);
});

const nodeTotal = parseInt(total, 10);
const nodeIndex = parseInt(index, 10);
bundles = bundles.filter((_, i) => i % nodeTotal === nodeIndex);
if (index != null && total != null) {
const nodeTotal = parseInt(total, 10);
const nodeIndex = parseInt(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);
await createBundle(bundle, bundleType, isExperimental);
}

await Packaging.copyAllShims();
Expand Down

0 comments on commit 0d8c88c

Please sign in to comment.