[rollup] Add support for running prebuild commands

Extracting portions of #32416 for easier review.

Adds a new `prebuild` option to allow for a prebuild command to be run prior to building the bundle.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
This commit is contained in:
Lauren Tan
2025-03-12 18:44:06 -04:00
co-authored by michael faith
parent 2ada449f85
commit ebc95ed34a
+9
View File
@@ -12,6 +12,7 @@ const stripBanner = require('rollup-plugin-strip-banner');
const chalk = require('chalk');
const resolve = require('@rollup/plugin-node-resolve').nodeResolve;
const fs = require('fs');
const childProcess = require('child_process');
const argv = require('minimist')(process.argv.slice(2));
const Modules = require('./modules');
const Bundles = require('./bundles');
@@ -812,6 +813,11 @@ function handleRollupError(error) {
}
}
function runShellCommand(command) {
console.log(chalk.dim('Running: ') + chalk.cyan(command));
childProcess.execSync(command, {stdio: 'inherit', shell: true});
}
async function buildEverything() {
if (!argv['unsafe-partial']) {
await asyncRimRaf('build');
@@ -859,6 +865,9 @@ async function buildEverything() {
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
for (const [bundle, bundleType] of bundles) {
if (bundle.prebuild) {
runShellCommand(bundle.prebuild);
}
await createBundle(bundle, bundleType);
}