From 660e41557956b42c409863d1f660dabfb72ef76d Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Fri, 5 Mar 2021 00:12:58 +0100 Subject: [PATCH 1/2] chore(build): Throw if `rsync` fails --- scripts/rollup/build-all-release-channels.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/rollup/build-all-release-channels.js b/scripts/rollup/build-all-release-channels.js index badd6f7c9ff02..10339efa23b03 100644 --- a/scripts/rollup/build-all-release-channels.js +++ b/scripts/rollup/build-all-release-channels.js @@ -64,7 +64,19 @@ if (process.env.CIRCLE_NODE_TOTAL) { // will have already removed conflicting files. // // In CI, merging is handled automatically by CircleCI's workspace feature. - spawnSync('rsync', ['-ar', experimentalDir + '/', stableDir + '/']); + const {error} = spawnSync('rsync', [ + '-ar', + experimentalDir + '/', + stableDir + '/', + ]); + if (error !== undefined) { + if (error.code === 'ENOENT') { + throw new Error( + `${process.argv[1]} needs the \`rsync\` CLI installed to work.` + ); + } + throw error; + } // Now restore the combined directory back to its original name // TODO: Currently storing artifacts as `./build2` so that it doesn't conflict From b772bfee1b23e28b2325ecaef6973ba5b482b8b0 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Fri, 5 Mar 2021 01:21:41 +0100 Subject: [PATCH 2/2] did not get cwrsync to work --- scripts/rollup/build-all-release-channels.js | 34 ++++++++++++-------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/scripts/rollup/build-all-release-channels.js b/scripts/rollup/build-all-release-channels.js index 10339efa23b03..279d957475939 100644 --- a/scripts/rollup/build-all-release-channels.js +++ b/scripts/rollup/build-all-release-channels.js @@ -64,19 +64,7 @@ if (process.env.CIRCLE_NODE_TOTAL) { // will have already removed conflicting files. // // In CI, merging is handled automatically by CircleCI's workspace feature. - const {error} = spawnSync('rsync', [ - '-ar', - experimentalDir + '/', - stableDir + '/', - ]); - if (error !== undefined) { - if (error.code === 'ENOENT') { - throw new Error( - `${process.argv[1]} needs the \`rsync\` CLI installed to work.` - ); - } - throw error; - } + mergeDirsSync(experimentalDir + '/', stableDir + '/'); // Now restore the combined directory back to its original name // TODO: Currently storing artifacts as `./build2` so that it doesn't conflict @@ -198,3 +186,23 @@ function updateTheReactVersionThatDevToolsReads(version) { `export default '${version}';\n` ); } + +/** + * cross-platform alternative to `rsync -ar` + * @param {string} source + * @param {string} destination + */ +function mergeDirsSync(source, destination) { + for (const sourceFileBaseName of fs.readdirSync(source)) { + const sourceFileName = path.join(source, sourceFileBaseName); + const targetFileName = path.join(destination, sourceFileBaseName); + + const sourceFile = fs.statSync(sourceFileName); + if (sourceFile.isDirectory()) { + fse.ensureDirSync(targetFileName); + mergeDirsSync(sourceFileName, targetFileName); + } else { + fs.copyFileSync(sourceFileName, targetFileName); + } + } +}