Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Babel 7 plugins compatibility with Babel 8 core #16332

Merged
merged 10 commits into from
Mar 7, 2024
3 changes: 0 additions & 3 deletions babel-7-8-compatibility.json

This file was deleted.

2 changes: 1 addition & 1 deletion babel.config.js
Expand Up @@ -14,7 +14,7 @@ const pathUtils = require("path");
const fs = require("fs");
const { parseSync } = require("@babel/core");
const packageJson = require("./package.json");
const babel7_8compat = require("./babel-7-8-compatibility.json");
const babel7_8compat = require("./test/babel-7-8-compat/data.json");

function normalize(src) {
return src.replace(/\//, pathUtils.sep);
Expand Down
42 changes: 42 additions & 0 deletions test/babel-7-8-compat/babel-7-plugins-with-babel-8-core.sh
@@ -0,0 +1,42 @@
#!/bin/bash

# Usage: BABEL_8_VERSION=next ./test/babel-7-8-compat/babel-7-plugins-with-babel-8-core.sh
# NOTE: This will change files in your monorepo, make sure to commit/stage
# everything before running it.

#==============================================================================#
# SETUP #
#==============================================================================#

# Start in test/babel-7-8-compat even if run from root directory
cd "$(dirname "$0")" || exit

# Echo every command being executed
set -x

# Go to the root of the monorepo
cd ../..

#==============================================================================#
# TEST #
#==============================================================================#

node -e '
if (!process.env.BABEL_8_VERSION) throw new Error("Please specify BABEL_8_VERSION=x.y.z env var");

const pluginsList = require("./test/babel-7-8-compat/data.json")["babel7plugins-babel8core"];

for (const plugin of pluginsList) {
const pkgJsonPath = path.join("./packages", plugin, "package.json");
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath));
pkgJson.devDependencies["@babel/core"] = process.env.BABEL_8_VERSION;
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2) + "\n");
}
' || exit

export YARN_ENABLE_IMMUTABLE_INSTALLS=false
export SKIP_YARN_CORE_DEP_CHECK=true

# Build and test
make -j use-cjs
yarn jest $(node -p 'require("./test/babel-7-8-compat/data.json")["babel7plugins-babel8core"].join(" ")' || exit)
6 changes: 6 additions & 0 deletions test/babel-7-8-compat/data.json
@@ -0,0 +1,6 @@
{
"babel7plugins-babel8core": [
"babel-plugin-external-helpers",
"babel-plugin-transform-json-strings"
]
}
1 change: 1 addition & 0 deletions yarn.config.cjs
Expand Up @@ -268,6 +268,7 @@ function enforceBabelCoreNotInDeps({ Yarn }) {
workspace.pkg.peerDependencies.has("@babel/core") &&
!workspace.manifest.dependencies?.["@babel/core"]
) {
if (process.env.SKIP_YARN_CORE_DEP_CHECK) continue;
workspace.set("devDependencies['@babel/core']", "workspace:^");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pass the BABEL_8_VERSION here and let yarn constraints --fix update the dependencies for us?

}
if (
Expand Down