Skip to content

Commit ad869b4

Browse files
author
Brijesh Bittu
committed
Use babel/runtime version specified in pnpm-workspace.yaml
1 parent 14f91b3 commit ad869b4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

scripts/build.mjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,18 @@ async function run(argv) {
4141
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, { encoding: 'utf8' }));
4242

4343
let babelRuntimeVersion = packageJson.dependencies['@babel/runtime'];
44+
if (babelRuntimeVersion === 'catalog:') {
45+
// resolve the version from the given package
46+
// outputs the pnpm-workspace.yaml config as json
47+
const { stdout: configStdout } = await exec('pnpm config list --json');
48+
const pnpmWorkspaceConfig = JSON.parse(configStdout);
49+
babelRuntimeVersion = pnpmWorkspaceConfig.catalog['@babel/runtime'];
50+
}
51+
4452
if (!babelRuntimeVersion) {
4553
throw new Error(
4654
'package.json needs to have a dependency on `@babel/runtime` when building with `@babel/plugin-transform-runtime`.',
4755
);
48-
} else if (babelRuntimeVersion === 'catalog:') {
49-
// resolve the version from the given package
50-
const { stdout: listedBabelRuntime } = await exec('pnpm list "@babel/runtime" --json');
51-
const jsonListedDependencies = JSON.parse(listedBabelRuntime);
52-
babelRuntimeVersion = jsonListedDependencies[0].dependencies['@babel/runtime'].version;
5356
}
5457

5558
const babelConfigPath = path.resolve(getWorkspaceRoot(), 'babel.config.js');

0 commit comments

Comments
 (0)