@@ -8,14 +8,18 @@ const {spawnSync} = require('child_process'); |
8 | 8 | const path = require('path'); |
9 | 9 | const tmp = require('tmp'); |
10 | 10 |
|
| 11 | +const { |
| 12 | + ReactVersion, |
| 13 | + stablePackages, |
| 14 | + experimentalPackages, |
| 15 | +} = require('../../ReactVersions'); |
| 16 | + |
11 | 17 | // Runs the build script for both stable and experimental release channels, |
12 | 18 | // by configuring an environment variable. |
13 | 19 |
|
14 | 20 | const sha = ( |
15 | 21 | spawnSync('git', ['show', '-s', '--format=%h']).stdout + '' |
16 | 22 | ).trim(); |
17 | | -const ReactVersion = JSON.parse(fs.readFileSync('packages/react/package.json')) |
18 | | - .version; |
19 | 23 |
|
20 | 24 | if (process.env.CIRCLE_NODE_TOTAL) { |
21 | 25 | // In CI, we use multiple concurrent processes. Allocate half the processes to |
@@ -27,19 +31,17 @@ if (process.env.CIRCLE_NODE_TOTAL) { |
27 | 31 | if (index < halfTotal) { |
28 | 32 | const nodeTotal = halfTotal; |
29 | 33 | const nodeIndex = index; |
30 | | - const version = '0.0.0-' + sha; |
31 | 34 | updateTheReactVersionThatDevToolsReads(ReactVersion + '-' + sha); |
32 | 35 | buildForChannel('stable', nodeTotal, nodeIndex); |
33 | | - processStable('./build', version); |
| 36 | + processStable('./build'); |
34 | 37 | } else { |
35 | 38 | const nodeTotal = total - halfTotal; |
36 | 39 | const nodeIndex = index - halfTotal; |
37 | | - const version = '0.0.0-experimental-' + sha; |
38 | 40 | updateTheReactVersionThatDevToolsReads( |
39 | 41 | ReactVersion + '-experimental-' + sha |
40 | 42 | ); |
41 | 43 | buildForChannel('experimental', nodeTotal, nodeIndex); |
42 | | - processExperimental('./build', version); |
| 44 | + processExperimental('./build'); |
43 | 45 | } |
44 | 46 |
|
45 | 47 | // TODO: Currently storing artifacts as `./build2` so that it doesn't conflict |
@@ -48,17 +50,16 @@ if (process.env.CIRCLE_NODE_TOTAL) { |
48 | 50 | } else { |
49 | 51 | // Running locally, no concurrency. Move each channel's build artifacts into |
50 | 52 | // a temporary directory so that they don't conflict. |
51 | | - const stableVersion = '0.0.0-' + sha; |
| 53 | + updateTheReactVersionThatDevToolsReads(ReactVersion + '-' + sha); |
52 | 54 | buildForChannel('stable', '', ''); |
53 | 55 | const stableDir = tmp.dirSync().name; |
54 | 56 | crossDeviceRenameSync('./build', stableDir); |
55 | | - processStable(stableDir, stableVersion); |
56 | | - |
57 | | - const experimentalVersion = '0.0.0-experimental-' + sha; |
| 57 | + processStable(stableDir); |
| 58 | + updateTheReactVersionThatDevToolsReads(ReactVersion + '-experimental-' + sha); |
58 | 59 | buildForChannel('experimental', '', ''); |
59 | 60 | const experimentalDir = tmp.dirSync().name; |
60 | 61 | crossDeviceRenameSync('./build', experimentalDir); |
61 | | - processExperimental(experimentalDir, experimentalVersion); |
| 62 | + processExperimental(experimentalDir); |
62 | 63 |
|
63 | 64 | // Then merge the experimental folder into the stable one. processExperimental |
64 | 65 | // will have already removed conflicting files. |
@@ -84,9 +85,21 @@ function buildForChannel(channel, nodeTotal, nodeIndex) { |
84 | 85 | }); |
85 | 86 | } |
86 | 87 |
|
87 | | -function processStable(buildDir, version) { |
| 88 | +function processStable(buildDir) { |
88 | 89 | if (fs.existsSync(buildDir + '/node_modules')) { |
89 | | - updatePackageVersions(buildDir + '/node_modules', version); |
| 90 | + const defaultVersionIfNotFound = '0.0.0' + '-' + sha; |
| 91 | + const versionsMap = new Map(); |
| 92 | + for (const moduleName in stablePackages) { |
| 93 | + // TODO: Use version declared in ReactVersions module instead of 0.0.0. |
| 94 | + // const version = stablePackages[moduleName]; |
| 95 | + // versionsMap.set(moduleName, version + '-' + nextChannelLabel + '-' + sha); |
| 96 | + versionsMap.set(moduleName, defaultVersionIfNotFound); |
| 97 | + } |
| 98 | + updatePackageVersions( |
| 99 | + buildDir + '/node_modules', |
| 100 | + versionsMap, |
| 101 | + defaultVersionIfNotFound |
| 102 | + ); |
90 | 103 | fs.renameSync(buildDir + '/node_modules', buildDir + '/oss-stable'); |
91 | 104 | } |
92 | 105 |
|
@@ -107,7 +120,19 @@ function processStable(buildDir, version) { |
107 | 120 |
|
108 | 121 | function processExperimental(buildDir, version) { |
109 | 122 | if (fs.existsSync(buildDir + '/node_modules')) { |
110 | | - updatePackageVersions(buildDir + '/node_modules', version); |
| 123 | + const defaultVersionIfNotFound = '0.0.0' + '-' + 'experimental' + '-' + sha; |
| 124 | + const versionsMap = new Map(); |
| 125 | + for (const moduleName in stablePackages) { |
| 126 | + versionsMap.set(moduleName, defaultVersionIfNotFound); |
| 127 | + } |
| 128 | + for (const moduleName of experimentalPackages) { |
| 129 | + versionsMap.set(moduleName, defaultVersionIfNotFound); |
| 130 | + } |
| 131 | + updatePackageVersions( |
| 132 | + buildDir + '/node_modules', |
| 133 | + versionsMap, |
| 134 | + defaultVersionIfNotFound |
| 135 | + ); |
111 | 136 | fs.renameSync(buildDir + '/node_modules', buildDir + '/oss-experimental'); |
112 | 137 | } |
113 | 138 |
|
@@ -151,9 +176,18 @@ function crossDeviceRenameSync(source, destination) { |
151 | 176 | * to match this version for all of the 'React' packages |
152 | 177 | * (packages available in this repo). |
153 | 178 | */ |
154 | | -function updatePackageVersions(modulesDir, version) { |
155 | | - const allReactModuleNames = fs.readdirSync('packages'); |
| 179 | +function updatePackageVersions( |
| 180 | + modulesDir, |
| 181 | + versionsMap, |
| 182 | + defaultVersionIfNotFound |
| 183 | +) { |
156 | 184 | for (const moduleName of fs.readdirSync(modulesDir)) { |
| 185 | + let version = versionsMap.get(moduleName); |
| 186 | + if (version === undefined) { |
| 187 | + // TODO: If the module is not in the version map, we should exclude it |
| 188 | + // from the build artifacts. |
| 189 | + version = defaultVersionIfNotFound; |
| 190 | + } |
157 | 191 | const packageJSONPath = path.join(modulesDir, moduleName, 'package.json'); |
158 | 192 | const stats = fs.statSync(packageJSONPath); |
159 | 193 | if (stats.isFile()) { |
@@ -164,16 +198,14 @@ function updatePackageVersions(modulesDir, version) { |
164 | 198 |
|
165 | 199 | if (packageInfo.dependencies) { |
166 | 200 | for (const dep of Object.keys(packageInfo.dependencies)) { |
167 | | - // if it's a react package (available in the current repo), update the version |
168 | | - // TODO: is this too broad? Assumes all of the packages were built. |
169 | | - if (allReactModuleNames.includes(dep)) { |
| 201 | + if (modulesDir.includes(dep)) { |
170 | 202 | packageInfo.dependencies[dep] = version; |
171 | 203 | } |
172 | 204 | } |
173 | 205 | } |
174 | 206 | if (packageInfo.peerDependencies) { |
175 | 207 | for (const dep of Object.keys(packageInfo.peerDependencies)) { |
176 | | - if (allReactModuleNames.includes(dep)) { |
| 208 | + if (modulesDir.includes(dep)) { |
177 | 209 | packageInfo.peerDependencies[dep] = version; |
178 | 210 | } |
179 | 211 | } |
|