@samitouri / QOS-React-2 / commits / f534cc6ea4

[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.

Luna Ruan committed May 31, 2022 at 12:23 UTC f534cc6ea4e7cffbfd53b00e14cd0b1849b291f1
2 files changed +21 -3
.circleci/config.yml
+1 -1
@@ -238,7 +238,7 @@ jobs:
238 - run:
239 name: Install nested packages from Yarn cache
240 command: yarn --frozen-lockfile --cache-folder ~/.cache/yarn
241 - - run: ./scripts/circleci/download_devtools_regression_build.js << parameters.version >>
241 + - run: ./scripts/circleci/download_devtools_regression_build.js << parameters.version >> --replaceBuild
242 - run: node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion << parameters.version >> --ci
243
244 yarn_lint_build:
scripts/circleci/download_devtools_regression_build.js
+20 -2
@@ -6,6 +6,7 @@ const {exec} = require('child-process-promise');
6 const chalk = require('chalk');
7 const {join} = require('path');
8 const semver = require('semver');
9 +const yargs = require('yargs');
10 const fs = require('fs');
11
12 const INSTALL_PACKAGES = ['react-dom', 'react', 'react-test-renderer'];
@@ -16,7 +17,10 @@ const ROOT_PATH = join(__dirname, '..', '..');
17 const buildPath = join(ROOT_PATH, `build`, 'oss-experimental');
18 const regressionBuildPath = join(ROOT_PATH, REGRESSION_FOLDER);
19
20 +const argv = yargs(process.argv.slice(2)).argv;
21 +
22 const version = process.argv[2];
23 +const shouldReplaceBuild = !!argv.replaceBuild;
24
25 async function downloadRegressionBuild() {
26 console.log(chalk.bold.white(`Downloading React v${version}\n`));
@@ -39,6 +43,12 @@ async function downloadRegressionBuild() {
43 `npm install --prefix ${REGRESSION_FOLDER} ${downloadPackagesStr}`
44 );
45
46 + // If we shouldn't replace the build folder, we can stop here now
47 + // before we modify anything
48 + if (!shouldReplaceBuild) {
49 + return;
50 + }
51 +
52 // Remove all the packages that we downloaded in the original build folder
53 // so we can move the modules from the regression build over
54 const removePackagesStr = INSTALL_PACKAGES.reduce(
@@ -102,12 +112,20 @@ async function downloadRegressionBuild() {
112
113 async function main() {
114 try {
115 + if (!version) {
116 + console.log(chalk.red('Must specify React version to download'));
117 + return;
118 + }
119 await downloadRegressionBuild();
120 } catch (e) {
121 console.log(chalk.red(e));
122 } finally {
109 - console.log(chalk.bold.white(`Removing regression build`));
110 - await exec(`rm -r ${regressionBuildPath}`);
123 + // We shouldn't remove the regression-build folder unless we're using
124 + // it to replace the build folder
125 + if (shouldReplaceBuild) {
126 + console.log(chalk.bold.white(`Removing regression build`));
127 + await exec(`rm -r ${regressionBuildPath}`);
128 + }
129 }
130 }
131