From ebc95ed34a94f9630678fcb4ff297441a8f8dfd7 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Wed, 12 Mar 2025 18:43:08 -0400 Subject: [PATCH] [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 --- scripts/rollup/build.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index 71bfb1c338..02aa167b63 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -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); }