diff --git a/babel.config.js b/babel.config.js index 45a7c55167cee9..c6910c0afa717e 100644 --- a/babel.config.js +++ b/babel.config.js @@ -93,7 +93,7 @@ module.exports = function getBabelConfig(api) { { useESModules, // any package needs to declare 7.25.0 as a runtime dependency. default is ^7.0.0 - version: '^7.25.0', + version: process.env.MUI_BABEL_RUNTIME_VERSION || '^7.25.0', }, ], [ diff --git a/packages/mui-material-pigment-css/package.json b/packages/mui-material-pigment-css/package.json index 85426d9b892f2a..61cb768157ff0c 100644 --- a/packages/mui-material-pigment-css/package.json +++ b/packages/mui-material-pigment-css/package.json @@ -39,6 +39,7 @@ "typescript:module-augmentation": "node scripts/testModuleAugmentation.js" }, "dependencies": { + "@babel/runtime": "^7.25.0", "@mui/system": "workspace:*", "@pigment-css/react": "0.0.20" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 79bfb27adb220e..0f6ca93fa65c20 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1851,6 +1851,9 @@ importers: packages/mui-material-pigment-css: dependencies: + '@babel/runtime': + specifier: ^7.25.0 + version: 7.25.0 '@mui/system': specifier: workspace:* version: link:../mui-system/build diff --git a/scripts/build.mjs b/scripts/build.mjs index 47c7b66ab13378..27054ee0ac17fe 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -3,6 +3,7 @@ import glob from 'fast-glob'; import path from 'path'; import { promisify } from 'util'; import yargs from 'yargs'; +import * as fs from 'fs/promises'; import { getVersionEnvVariables, getWorkspaceRoot } from './utils.mjs'; const exec = promisify(childProcess.exec); @@ -25,10 +26,21 @@ async function run(argv) { ); } + const packageJsonPath = path.resolve('./package.json'); + const packageJson = JSON.parse(await fs.readFile(packageJsonPath, { encoding: 'utf8' })); + + const babelRuntimeVersion = packageJson.dependencies['@babel/runtime']; + if (!babelRuntimeVersion) { + throw new Error( + 'package.json needs to have a dependency on `@babel/runtime` when building with `@babel/plugin-transform-runtime`.', + ); + } + const env = { NODE_ENV: 'production', BABEL_ENV: bundle, MUI_BUILD_VERBOSE: verbose, + MUI_BABEL_RUNTIME_VERSION: babelRuntimeVersion, ...(await getVersionEnvVariables()), };