From f534cc6ea4e7cffbfd53b00e14cd0b1849b291f1 Mon Sep 17 00:00:00 2001 From: Luna Ruan Date: Tue, 31 May 2022 12:23:44 -0400 Subject: [PATCH] [DevTools] Add --replaceBuild option to Older React Builds Download Script (#24621) This PR adds a `--replaceBuild` option to the script that downloads older React version builds. If this flag is true, we will replace the contents of the `build` folder with the contents of the `build-regression` folder and remove the `build-regression` folder after, which was the original behavior. However, for e2e tests, we need both the original build (for DevTools) and the new build (for the React Apps), so we need both the `build` and the `build-regression` folders. Not adding the `--replaceBuild` option will do this. This PR also modifies the circle CI config to reflect this change. --- .circleci/config.yml | 2 +- .../download_devtools_regression_build.js | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 31d52c7e6a..d0c2bd9918 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -238,7 +238,7 @@ jobs: - run: name: Install nested packages from Yarn cache command: yarn --frozen-lockfile --cache-folder ~/.cache/yarn - - run: ./scripts/circleci/download_devtools_regression_build.js << parameters.version >> + - run: ./scripts/circleci/download_devtools_regression_build.js << parameters.version >> --replaceBuild - run: node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion << parameters.version >> --ci yarn_lint_build: diff --git a/scripts/circleci/download_devtools_regression_build.js b/scripts/circleci/download_devtools_regression_build.js index d8b7c88a0a..01ef377094 100755 --- a/scripts/circleci/download_devtools_regression_build.js +++ b/scripts/circleci/download_devtools_regression_build.js @@ -6,6 +6,7 @@ const {exec} = require('child-process-promise'); const chalk = require('chalk'); const {join} = require('path'); const semver = require('semver'); +const yargs = require('yargs'); const fs = require('fs'); const INSTALL_PACKAGES = ['react-dom', 'react', 'react-test-renderer']; @@ -16,7 +17,10 @@ const ROOT_PATH = join(__dirname, '..', '..'); const buildPath = join(ROOT_PATH, `build`, 'oss-experimental'); const regressionBuildPath = join(ROOT_PATH, REGRESSION_FOLDER); +const argv = yargs(process.argv.slice(2)).argv; + const version = process.argv[2]; +const shouldReplaceBuild = !!argv.replaceBuild; async function downloadRegressionBuild() { console.log(chalk.bold.white(`Downloading React v${version}\n`)); @@ -39,6 +43,12 @@ async function downloadRegressionBuild() { `npm install --prefix ${REGRESSION_FOLDER} ${downloadPackagesStr}` ); + // If we shouldn't replace the build folder, we can stop here now + // before we modify anything + if (!shouldReplaceBuild) { + return; + } + // Remove all the packages that we downloaded in the original build folder // so we can move the modules from the regression build over const removePackagesStr = INSTALL_PACKAGES.reduce( @@ -102,12 +112,20 @@ async function downloadRegressionBuild() { async function main() { try { + if (!version) { + console.log(chalk.red('Must specify React version to download')); + return; + } await downloadRegressionBuild(); } catch (e) { console.log(chalk.red(e)); } finally { - console.log(chalk.bold.white(`Removing regression build`)); - await exec(`rm -r ${regressionBuildPath}`); + // We shouldn't remove the regression-build folder unless we're using + // it to replace the build folder + if (shouldReplaceBuild) { + console.log(chalk.bold.white(`Removing regression build`)); + await exec(`rm -r ${regressionBuildPath}`); + } } }