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

build-combined: Fix failures when renaming across devices (#20620)

Sebastian Silbermann committed Jan 19, 2021 at 17:14 UTC 2b6985114f660f3d0ad4c3eb8efece2cbdb44eb8
1 file changed +8 -3
scripts/rollup/build-all-release-channels.js
+8 -3
@@ -3,6 +3,7 @@
3 /* eslint-disable no-for-of-loops/no-for-of-loops */
4
5 const fs = require('fs');
6 +const fse = require('fs-extra');
7 const {spawnSync} = require('child_process');
8 const path = require('path');
9 const tmp = require('tmp');
@@ -50,13 +51,13 @@ if (process.env.CIRCLE_NODE_TOTAL) {
51 const stableVersion = '0.0.0-' + sha;
52 buildForChannel('stable', '', '');
53 const stableDir = tmp.dirSync().name;
53 - fs.renameSync('./build', stableDir);
54 + crossDeviceRenameSync('./build', stableDir);
55 processStable(stableDir, stableVersion);
56
57 const experimentalVersion = '0.0.0-experimental-' + sha;
58 buildForChannel('experimental', '', '');
59 const experimentalDir = tmp.dirSync().name;
59 - fs.renameSync('./build', experimentalDir);
60 + crossDeviceRenameSync('./build', experimentalDir);
61 processExperimental(experimentalDir, experimentalVersion);
62
63 // Then merge the experimental folder into the stable one. processExperimental
@@ -68,7 +69,7 @@ if (process.env.CIRCLE_NODE_TOTAL) {
69 // Now restore the combined directory back to its original name
70 // TODO: Currently storing artifacts as `./build2` so that it doesn't conflict
71 // with old build job. Remove once we migrate rest of build/test pipeline.
71 - fs.renameSync(stableDir, './build2');
72 + crossDeviceRenameSync(stableDir, './build2');
73 }
74
75 function buildForChannel(channel, nodeTotal, nodeIndex) {
@@ -139,6 +140,10 @@ function processExperimental(buildDir, version) {
140 }
141 }
142
143 +function crossDeviceRenameSync(source, destination) {
144 + return fse.moveSync(source, destination, {overwrite: true});
145 +}
146 +
147 function updatePackageVersions(modulesDir, version) {
148 const allReactModuleNames = fs.readdirSync('packages');
149 for (const moduleName of fs.readdirSync(modulesDir)) {