Skip to content

Commit 40dde41

Browse files
author
Brian Vaughn
committed
Update package JSONs automatically after stable release is publish
1 parent 3585929 commit 40dde41

File tree

3 files changed

+76
-25
lines changed

3 files changed

+76
-25
lines changed

scripts/release/publish-commands/print-follow-up-instructions.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,39 @@ const run = async ({cwd, packages, tags}) => {
2525
);
2626

2727
if (tags.includes('latest')) {
28+
console.log();
2829
console.log(
29-
theme.header`\nLocal versions may require updating after a stable release. Please verify the following files:`
30+
theme.header`Please review and commit all local, staged changes.`
3031
);
32+
33+
console.log();
34+
console.log('Version numbers have been updated in the following files:');
3135
for (let i = 0; i < packages.length; i++) {
3236
const packageName = packages[i];
3337
console.log(theme.path`• packages/%s/package.json`, packageName);
3438
}
3539
console.log(theme.path`• packages/shared/ReactVersion.js`);
40+
41+
console.log();
42+
if (environment === 'ci') {
43+
console.log('Auto-generated error codes have been updated as well:');
44+
console.log(theme.path`• scripts/error-codes/codes.json`);
45+
} else {
46+
console.log(
47+
theme`{caution The release that was just published was created locally.} ` +
48+
theme`Because of this, you will need to update the generated ` +
49+
theme`{path scripts/error-codes/codes.json} file manually:`
50+
);
51+
console.log(theme` {command git checkout} {version ${commit}}`);
52+
console.log(theme` {command yarn build -- --extract-errors}`);
53+
}
3654
}
3755

56+
console.log();
57+
console.log(
58+
theme`{header Don't forget to update and commit the }{path CHANGELOG}`
59+
);
60+
3861
// Prompt the release engineer to tag the commit and update the CHANGELOG.
3962
// (The script could automatically do this, but this seems safer.)
4063
console.log();
@@ -49,31 +72,8 @@ const run = async ({cwd, packages, tags}) => {
4972
);
5073
console.log(theme.command` git push origin --tags`);
5174

52-
if (tags.includes('latest')) {
53-
console.log();
54-
console.log(
55-
theme`{header Don't forget to commit the generated }{path scripts/error-codes/codes.json}`
56-
);
57-
if (environment === 'ci') {
58-
console.log(
59-
`This file has been updated locally. Please review it before committing.`
60-
);
61-
} else {
62-
console.log(
63-
`The release that was just published was created locally. ` +
64-
`Because of this, you will need to update error codes manually with the following commands:`
65-
);
66-
console.log(theme` {command git checkout} {version ${commit}}`);
67-
console.log(theme` {command yarn build -- --extract-errors}`);
68-
}
69-
}
70-
71-
console.log();
72-
console.log(
73-
theme`{header Don't forget to update and commit the }{path CHANGELOG}`
74-
);
7575
console.log();
76-
console.log(theme.header`Then fill in the release on GitHub:`);
76+
console.log(theme.header`Lastly, please fill in the release on GitHub:`);
7777
console.log(
7878
theme.link`https://github.com/facebook/react/releases/tag/v%s`,
7979
version
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
const {readFileSync, writeFileSync} = require('fs');
6+
const {readJson, writeJson} = require('fs-extra');
7+
const {join} = require('path');
8+
9+
const run = async ({cwd, packages, tags}) => {
10+
if (!tags.includes('latest')) {
11+
// Don't update version numbers for alphas.
12+
return;
13+
}
14+
15+
const nodeModulesPath = join(cwd, 'build/node_modules');
16+
const packagesPath = join(cwd, 'packages');
17+
18+
// Update package versions and dependencies (in source) to mirror what was published to NPM.
19+
for (let i = 0; i < packages.length; i++) {
20+
const packageName = packages[i];
21+
const publishedPackageJSON = await readJson(
22+
join(nodeModulesPath, packageName, 'package.json')
23+
);
24+
const sourcePackageJSONPath = join(
25+
packagesPath,
26+
packageName,
27+
'package.json'
28+
);
29+
const sourcePackageJSON = await readJson(sourcePackageJSONPath);
30+
sourcePackageJSON.version = publishedPackageJSON.version;
31+
sourcePackageJSON.dependencies = publishedPackageJSON.dependencies;
32+
sourcePackageJSON.peerDependencies = publishedPackageJSON.peerDependencies;
33+
34+
await writeJson(sourcePackageJSONPath, sourcePackageJSON, {spaces: 2});
35+
}
36+
37+
// Update the shared React version source file.
38+
const sourceReactVersionPath = join(cwd, 'packages/shared/ReactVersion.js');
39+
const {version} = await readJson(
40+
join(nodeModulesPath, 'react', 'package.json')
41+
);
42+
const sourceReactVersion = readFileSync(
43+
sourceReactVersionPath,
44+
'utf8'
45+
).replace(/module\.exports = '[^']+';/, `module.exports = '${version}';`);
46+
writeFileSync(sourceReactVersionPath, sourceReactVersion);
47+
};
48+
49+
module.exports = run;

scripts/release/publish.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const parseParams = require('./publish-commands/parse-params');
1212
const printFollowUpInstructions = require('./publish-commands/print-follow-up-instructions');
1313
const promptForOTP = require('./publish-commands/prompt-for-otp');
1414
const publishToNPM = require('./publish-commands/publish-to-npm');
15+
const updateStableVersionNumbers = require('./publish-commands/update-stable-version-numbers');
1516
const validateTags = require('./publish-commands/validate-tags');
1617

1718
const run = async () => {
@@ -26,6 +27,7 @@ const run = async () => {
2627
const otp = await promptForOTP(params);
2728
await publishToNPM(params, otp);
2829
await downloadErrorCodesFromCI(params);
30+
await updateStableVersionNumbers(params);
2931
await printFollowUpInstructions(params);
3032
} catch (error) {
3133
handleError(error);

0 commit comments

Comments
 (0)