-
Notifications
You must be signed in to change notification settings - Fork 199
chore: add a script to simplify version update on release #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The script simplifies the update of the version in various files by running a single command, instead of modifying several files manually. In addition, lint `packages/core/package.json` to not introduce changes when the file is updated by the script.
WalkthroughThis pull request introduces a new script Changes
Sequence DiagramsequenceDiagram
participant Dev as Developer
participant Script as update-versions.mjs
participant Files as Project Files
Dev->>Script: Run script with new version
Script->>Files: Update package-lock.json
Script->>Files: Update core package.json
Script->>Files: Update Client.ts version constant
Script-->>Dev: Confirm version updates complete
Possibly related PRs
Suggested labels
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Nitpick comments (2)
scripts/update-versions.mjs (2)
60-62: Consider removing redundant utility function.The
readFileContentfunction adds unnecessary abstraction. Consider inlining it within the try-catch blocks where it's used.-function readFileContent(path) { - return readFileSync(path, 'utf8').toString(); -}
64-66: Add error handling to JSON writing utility.The function should handle potential JSON stringification errors.
function writeJsonContentToFile(path, obj) { - writeFileSync(path, JSON.stringify(obj, null, 2) + '\n'); + try { + const content = JSON.stringify(obj, null, 2) + '\n'; + writeFileSync(path, content); + } catch (error) { + console.error(`Failed to write to ${path}:`, error.message); + process.exit(1); + } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
packages/core/package.json(1 hunks)packages/core/src/Client.ts(1 hunks)packages/website/docs/development/release.md(1 hunks)scripts/update-versions.mjs(1 hunks)
✅ Files skipped from review due to trivial changes (2)
- packages/core/src/Client.ts
- packages/core/package.json
🧰 Additional context used
🪛 ESLint
scripts/update-versions.mjs
[error] 22-22: 'process' is not defined.
(no-undef)
[error] 24-24: Unexpected console statement.
(no-console)
[error] 28-28: Unexpected console statement.
(no-console)
[error] 32-32: Unexpected console statement.
(no-console)
[error] 41-41: Unexpected console statement.
(no-console)
[error] 50-50: Unexpected console statement.
(no-console)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: build (windows-2022)
- GitHub Check: build
- GitHub Check: build (macos-14)
- GitHub Check: build (ubuntu-22.04)
🔇 Additional comments (2)
scripts/update-versions.mjs (1)
1-19: LGTM! Good practices in imports and documentation.The use of the
node:protocol for importing core modules and the clear documentation about workflow dependencies are excellent practices.packages/website/docs/development/release.md (1)
38-38: LGTM! Clear documentation update.The new instruction for using the version update script is well-integrated into the release process documentation.
| function updateVersionInCorePackageJsonFile(newVersion) { | ||
| const path = 'packages/core/package.json'; | ||
| console.info('Updating', path); | ||
| const fileContent = readFileContent(path); | ||
| const packageJson = JSON.parse(fileContent); | ||
| packageJson.version = newVersion; | ||
| writeJsonContentToFile(path, packageJson); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for core package.json operations.
Similar to the previous function, add error handling and file validation.
Consider this implementation:
function updateVersionInCorePackageJsonFile(newVersion) {
const path = 'packages/core/package.json';
console.info('Updating', path);
- const fileContent = readFileContent(path);
- const packageJson = JSON.parse(fileContent);
- packageJson.version = newVersion;
- writeJsonContentToFile(path, packageJson);
+ try {
+ const fileContent = readFileContent(path);
+ const packageJson = JSON.parse(fileContent);
+ packageJson.version = newVersion;
+ writeJsonContentToFile(path, packageJson);
+ } catch (error) {
+ console.error(`Failed to update ${path}:`, error.message);
+ process.exit(1);
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function updateVersionInCorePackageJsonFile(newVersion) { | |
| const path = 'packages/core/package.json'; | |
| console.info('Updating', path); | |
| const fileContent = readFileContent(path); | |
| const packageJson = JSON.parse(fileContent); | |
| packageJson.version = newVersion; | |
| writeJsonContentToFile(path, packageJson); | |
| } | |
| function updateVersionInCorePackageJsonFile(newVersion) { | |
| const path = 'packages/core/package.json'; | |
| console.info('Updating', path); | |
| try { | |
| const fileContent = readFileContent(path); | |
| const packageJson = JSON.parse(fileContent); | |
| packageJson.version = newVersion; | |
| writeJsonContentToFile(path, packageJson); | |
| } catch (error) { | |
| console.error(`Failed to update ${path}:`, error.message); | |
| process.exit(1); | |
| } | |
| } |
🧰 Tools
🪛 ESLint
[error] 41-41: Unexpected console statement.
(no-console)
| // run from the root of the repository: node scripts/update-versions.mjs 0.12.0.alpha-1 | ||
| const newVersion = process.argv[2]; | ||
|
|
||
| console.info('Updating version in various files, version:', newVersion); | ||
| updateVersionInRootPackageLockJsonFile(newVersion); | ||
| updateVersionInCorePackageJsonFile(newVersion); | ||
| updateVersionInSourceFile(newVersion); | ||
| console.info('Files have been updated'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add version format validation.
The script should validate the version format and handle missing arguments gracefully.
Consider adding this validation:
const newVersion = process.argv[2];
+if (!newVersion) {
+ console.error('Error: Version argument is required');
+ console.error('Usage: node scripts/update-versions.mjs <version>');
+ process.exit(1);
+}
+if (!/^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/.test(newVersion)) {
+ console.error('Error: Invalid version format. Must follow semver (e.g., 1.2.3, 1.2.3-alpha.1)');
+ process.exit(1);
+}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // run from the root of the repository: node scripts/update-versions.mjs 0.12.0.alpha-1 | |
| const newVersion = process.argv[2]; | |
| console.info('Updating version in various files, version:', newVersion); | |
| updateVersionInRootPackageLockJsonFile(newVersion); | |
| updateVersionInCorePackageJsonFile(newVersion); | |
| updateVersionInSourceFile(newVersion); | |
| console.info('Files have been updated'); | |
| // run from the root of the repository: node scripts/update-versions.mjs 0.12.0.alpha-1 | |
| const newVersion = process.argv[2]; | |
| if (!newVersion) { | |
| console.error('Error: Version argument is required'); | |
| console.error('Usage: node scripts/update-versions.mjs <version>'); | |
| process.exit(1); | |
| } | |
| if (!/^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/.test(newVersion)) { | |
| console.error('Error: Invalid version format. Must follow semver (e.g., 1.2.3, 1.2.3-alpha.1)'); | |
| process.exit(1); | |
| } | |
| console.info('Updating version in various files, version:', newVersion); | |
| updateVersionInRootPackageLockJsonFile(newVersion); | |
| updateVersionInCorePackageJsonFile(newVersion); | |
| updateVersionInSourceFile(newVersion); | |
| console.info('Files have been updated'); |
🧰 Tools
🪛 ESLint
[error] 22-22: 'process' is not defined.
(no-undef)
[error] 24-24: Unexpected console statement.
(no-console)
[error] 28-28: Unexpected console statement.
(no-console)
| function updateVersionInRootPackageLockJsonFile(newVersion) { | ||
| const path = 'package-lock.json'; | ||
| console.info('Updating', path); | ||
| const fileContent = readFileContent(path); | ||
| const packageJson = JSON.parse(fileContent); | ||
| packageJson.packages['packages/core'].version = newVersion; | ||
| writeJsonContentToFile(path, packageJson); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for file operations and package structure validation.
The function should handle file operation errors and validate the package-lock.json structure.
Consider this implementation:
function updateVersionInRootPackageLockJsonFile(newVersion) {
const path = 'package-lock.json';
console.info('Updating', path);
- const fileContent = readFileContent(path);
- const packageJson = JSON.parse(fileContent);
- packageJson.packages['packages/core'].version = newVersion;
- writeJsonContentToFile(path, packageJson);
+ try {
+ const fileContent = readFileContent(path);
+ const packageJson = JSON.parse(fileContent);
+ if (!packageJson.packages?.['packages/core']) {
+ throw new Error('packages/core not found in package-lock.json');
+ }
+ packageJson.packages['packages/core'].version = newVersion;
+ writeJsonContentToFile(path, packageJson);
+ } catch (error) {
+ console.error(`Failed to update ${path}:`, error.message);
+ process.exit(1);
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function updateVersionInRootPackageLockJsonFile(newVersion) { | |
| const path = 'package-lock.json'; | |
| console.info('Updating', path); | |
| const fileContent = readFileContent(path); | |
| const packageJson = JSON.parse(fileContent); | |
| packageJson.packages['packages/core'].version = newVersion; | |
| writeJsonContentToFile(path, packageJson); | |
| } | |
| function updateVersionInRootPackageLockJsonFile(newVersion) { | |
| const path = 'package-lock.json'; | |
| console.info('Updating', path); | |
| try { | |
| const fileContent = readFileContent(path); | |
| const packageJson = JSON.parse(fileContent); | |
| if (!packageJson.packages?.['packages/core']) { | |
| throw new Error('packages/core not found in package-lock.json'); | |
| } | |
| packageJson.packages['packages/core'].version = newVersion; | |
| writeJsonContentToFile(path, packageJson); | |
| } catch (error) { | |
| console.error(`Failed to update ${path}:`, error.message); | |
| process.exit(1); | |
| } | |
| } |
🧰 Tools
🪛 ESLint
[error] 32-32: Unexpected console statement.
(no-console)
| function updateVersionInSourceFile(newVersion) { | ||
| const path = 'packages/core/src/Client.ts'; | ||
| console.info('Updating', path); | ||
| const content = readFileContent(path); | ||
| // replace the 1st occurrence, this is OK as the constant appears only once in the file | ||
| const updatedContent = content.replace( | ||
| /static VERSION =.*/, | ||
| `static VERSION = '${newVersion}';` | ||
| ); | ||
| writeFileSync(path, updatedContent); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve version replacement reliability in source file.
The current implementation could be more robust with better error handling and replacement verification.
Consider this enhanced implementation:
function updateVersionInSourceFile(newVersion) {
const path = 'packages/core/src/Client.ts';
console.info('Updating', path);
- const content = readFileContent(path);
- // replace the 1st occurrence, this is OK as the constant appears only once in the file
- const updatedContent = content.replace(
- /static VERSION =.*/,
- `static VERSION = '${newVersion}';`
- );
- writeFileSync(path, updatedContent);
+ try {
+ const content = readFileContent(path);
+ const versionRegex = /static\s+VERSION\s*=\s*['"]([^'"]+)['"]\s*;/;
+ if (!versionRegex.test(content)) {
+ throw new Error('VERSION constant not found in expected format');
+ }
+ const updatedContent = content.replace(
+ versionRegex,
+ `static VERSION = '${newVersion}';`
+ );
+ if (content === updatedContent) {
+ throw new Error('Failed to update version in file');
+ }
+ writeFileSync(path, updatedContent);
+ } catch (error) {
+ console.error(`Failed to update ${path}:`, error.message);
+ process.exit(1);
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function updateVersionInSourceFile(newVersion) { | |
| const path = 'packages/core/src/Client.ts'; | |
| console.info('Updating', path); | |
| const content = readFileContent(path); | |
| // replace the 1st occurrence, this is OK as the constant appears only once in the file | |
| const updatedContent = content.replace( | |
| /static VERSION =.*/, | |
| `static VERSION = '${newVersion}';` | |
| ); | |
| writeFileSync(path, updatedContent); | |
| } | |
| function updateVersionInSourceFile(newVersion) { | |
| const path = 'packages/core/src/Client.ts'; | |
| console.info('Updating', path); | |
| try { | |
| const content = readFileContent(path); | |
| const versionRegex = /static\s+VERSION\s*=\s*['"]([^'"]+)['"]\s*;/; | |
| if (!versionRegex.test(content)) { | |
| throw new Error('VERSION constant not found in expected format'); | |
| } | |
| const updatedContent = content.replace( | |
| versionRegex, | |
| `static VERSION = '${newVersion}';` | |
| ); | |
| if (content === updatedContent) { | |
| throw new Error('Failed to update version in file'); | |
| } | |
| writeFileSync(path, updatedContent); | |
| } catch (error) { | |
| console.error(`Failed to update ${path}:`, error.message); | |
| process.exit(1); | |
| } | |
| } |
🧰 Tools
🪛 ESLint
[error] 50-50: Unexpected console statement.
(no-console)



The script simplifies the update of the version in various files by running a single command, instead of modifying several files manually.
In addition, lint
packages/core/package.jsonto not introduce changes when the file is updated by the script.Notes
Script logs
Summary by CodeRabbit
Chores
Documentation