8
const path = require('path');
9
const tmp = require('tmp');
10
11
+const {
12
+ ReactVersion,
13
+ stablePackages,
14
+ experimentalPackages,
15
+} = require('../../ReactVersions');
16
+
17
// Runs the build script for both stable and experimental release channels,
18
// by configuring an environment variable.
19
20
const sha = (
21
spawnSync('git', ['show', '-s', '--format=%h']).stdout + ''
22
).trim();
17
-const ReactVersion = JSON.parse(fs.readFileSync('packages/react/package.json'))
18
- .version;
23
24
if (process.env.CIRCLE_NODE_TOTAL) {
25
// In CI, we use multiple concurrent processes. Allocate half the processes to
31
if (index < halfTotal) {
32
const nodeTotal = halfTotal;
33
const nodeIndex = index;
30
- const version = '0.0.0-' + sha;
34
updateTheReactVersionThatDevToolsReads(ReactVersion + '-' + sha);
35
buildForChannel('stable', nodeTotal, nodeIndex);
33
- processStable('./build', version);
36
+ processStable('./build');
37
} else {
38
const nodeTotal = total - halfTotal;
39
const nodeIndex = index - halfTotal;
37
- const version = '0.0.0-experimental-' + sha;
40
updateTheReactVersionThatDevToolsReads(
41
ReactVersion + '-experimental-' + sha
42
);
43
buildForChannel('experimental', nodeTotal, nodeIndex);
42
- processExperimental('./build', version);
44
+ processExperimental('./build');
45
}
46
47
// TODO: Currently storing artifacts as `./build2` so that it doesn't conflict
50
} else {
51
// Running locally, no concurrency. Move each channel's build artifacts into
52
// a temporary directory so that they don't conflict.
51
- const stableVersion = '0.0.0-' + sha;
53
+ updateTheReactVersionThatDevToolsReads(ReactVersion + '-' + sha);
54
buildForChannel('stable', '', '');
55
const stableDir = tmp.dirSync().name;
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);
59
buildForChannel('experimental', '', '');
60
const experimentalDir = tmp.dirSync().name;
61
crossDeviceRenameSync('./build', experimentalDir);
61
- processExperimental(experimentalDir, experimentalVersion);
62
+ processExperimental(experimentalDir);
63
64
// Then merge the experimental folder into the stable one. processExperimental
65
// will have already removed conflicting files.
85
});
86
}
87
87
-function processStable(buildDir, version) {
88
+function processStable(buildDir) {
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
+ );
103
fs.renameSync(buildDir + '/node_modules', buildDir + '/oss-stable');
104
}
105
120
121
function processExperimental(buildDir, version) {
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
+ );
136
fs.renameSync(buildDir + '/node_modules', buildDir + '/oss-experimental');
137
}
138
176
* to match this version for all of the 'React' packages
177
* (packages available in this repo).
178
*/
154
-function updatePackageVersions(modulesDir, version) {
155
- const allReactModuleNames = fs.readdirSync('packages');
179
+function updatePackageVersions(
180
+ modulesDir,
181
+ versionsMap,
182
+ defaultVersionIfNotFound
183
+) {
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
+ }
191
const packageJSONPath = path.join(modulesDir, moduleName, 'package.json');
192
const stats = fs.statSync(packageJSONPath);
193
if (stats.isFile()) {
198
199
if (packageInfo.dependencies) {
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)) {
202
packageInfo.dependencies[dep] = version;
203
}
204
}
205
}
206
if (packageInfo.peerDependencies) {
207
for (const dep of Object.keys(packageInfo.peerDependencies)) {
176
- if (allReactModuleNames.includes(dep)) {
208
+ if (modulesDir.includes(dep)) {
209
packageInfo.peerDependencies[dep] = version;
210
}
211
}