@samitouri / QOS-React-2 / commits / 8f37942765

Prepare semver (`@latest`) releases in CI (#21615)

Now that we track package versions in source, `@latest` builds should be fully reproducible for a given commit. We can prepare the packages in CI and store them as artifacts, the same way we do for `@next` and `@experimental`. Eventually this can replace the interactive script that we currently use to swap out the version numbers. The other nice thing about this approach is that we can run tests in CI to verify that the packages are releasable, instead of waiting until right before publish. I named the output directory `oss-stable-semver`, to distinguish from the `@next` prereleases that are located at `oss-stable`. I don't love this naming. I'd prefer to use the name of the corresponding npm dist tag. I'll do that in a follow-up, though, since the `oss-stable` name is referenced in a handful of places. Current naming (after this PR): - `oss-experimental` → `@experimental` - `oss-stable` → `@next` - `oss-stable-semver` → `@latest` Proposed naming (not yet implemented, requires more work): - `oss-experimental` → `@experimental` - `oss-next` → `@next` - `oss-latest` → `@latest`

Andrew Clark committed Jun 3, 2021 at 13:26 UTC 8f379427657ff1be5b25904864da54c7acfc8d64
1 file changed +31 -5
scripts/rollup/build-all-release-channels.js
+31 -5
@@ -98,9 +98,29 @@ function processStable(buildDir) {
98 updatePackageVersions(
99 buildDir + '/node_modules',
100 versionsMap,
101 - defaultVersionIfNotFound
101 + defaultVersionIfNotFound,
102 + true
103 );
104 fs.renameSync(buildDir + '/node_modules', buildDir + '/oss-stable');
105 +
106 + // Identical to `oss-stable` but with real, semver versions. This is what
107 + // will get published to @latest.
108 + spawnSync('cp', [
109 + '-r',
110 + buildDir + '/oss-stable',
111 + buildDir + '/oss-stable-semver',
112 + ]);
113 + const semverVersionsMap = new Map();
114 + for (const moduleName in stablePackages) {
115 + const version = stablePackages[moduleName];
116 + semverVersionsMap.set(moduleName, version);
117 + }
118 + updatePackageVersions(
119 + buildDir + '/oss-stable-semver',
120 + semverVersionsMap,
121 + defaultVersionIfNotFound,
122 + false
123 + );
124 }
125
126 if (fs.existsSync(buildDir + '/facebook-www')) {
@@ -131,7 +151,8 @@ function processExperimental(buildDir, version) {
151 updatePackageVersions(
152 buildDir + '/node_modules',
153 versionsMap,
134 - defaultVersionIfNotFound
154 + defaultVersionIfNotFound,
155 + true
156 );
157 fs.renameSync(buildDir + '/node_modules', buildDir + '/oss-experimental');
158 }
@@ -179,7 +200,8 @@ function crossDeviceRenameSync(source, destination) {
200 function updatePackageVersions(
201 modulesDir,
202 versionsMap,
182 - defaultVersionIfNotFound
203 + defaultVersionIfNotFound,
204 + pinToExactVersion
205 ) {
206 for (const moduleName of fs.readdirSync(modulesDir)) {
207 let version = versionsMap.get(moduleName);
@@ -199,14 +221,18 @@ function updatePackageVersions(
221 if (packageInfo.dependencies) {
222 for (const dep of Object.keys(packageInfo.dependencies)) {
223 if (versionsMap.has(dep)) {
202 - packageInfo.dependencies[dep] = version;
224 + packageInfo.dependencies[dep] = pinToExactVersion
225 + ? version
226 + : '^' + version;
227 }
228 }
229 }
230 if (packageInfo.peerDependencies) {
231 for (const dep of Object.keys(packageInfo.peerDependencies)) {
232 if (versionsMap.has(dep)) {
209 - packageInfo.peerDependencies[dep] = version;
233 + packageInfo.peerDependencies[dep] = pinToExactVersion
234 + ? version
235 + : '^' + version;
236 }
237 }
238 }