Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Commit 09e2be5

Browse files
Update versioning scripts for yarn 4
Consolidate all the new version logic to a single script that replicates the classic yarn process
1 parent dfb04a4 commit 09e2be5

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,8 @@ jobs:
5555
git config --global user.email "[email protected]"
5656
git config --global user.name "Github Bot"
5757
git add compiler
58-
yarn version ${{ env.COMPILER_VERSION_NUMBER }}.0.0
59-
git add package.json
60-
./build-scripts/version-packages.js
61-
git commit -m "v${{ env.COMPILER_VERSION_NUMBER }}.0.0"
58+
./build-scripts/version-packages.js --new-version ${{ env.COMPILER_VERSION_NUMBER }}.0.0
6259
git push origin master
63-
git tag -a v${{ env.COMPILER_VERSION_NUMBER }}.0.0 -m "v${{ env.COMPILER_VERSION_NUMBER }}.0.0"
6460
git push origin v${{ env.COMPILER_VERSION_NUMBER }}.0.0
6561
- name: Create GitHub Release
6662
if: ${{ env.COMPILER_VERSION_NUMBER != '' }}

build-scripts/version-packages.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,29 @@ import childProcess from 'node:child_process';
2626
import fs from 'node:fs';
2727
import path from 'node:path';
2828
import {fileURLToPath, URL} from 'node:url';
29+
import parseArgs from 'minimist';
30+
import semver from 'semver';
2931

32+
const flags = parseArgs(process.argv.slice(2));
33+
if (!flags['new-version']) {
34+
process.stderr.write(`No new version specified\n`);
35+
process.exit();
36+
}
3037
const __dirname = fileURLToPath(new URL('.', import.meta.url));
31-
const newVersion = process.env.npm_package_version;
38+
const rootPackageJsonPath = path.resolve(__dirname, '../package.json');
39+
const rootPackageJson = JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf-8'));
40+
const currentVersion = semver(rootPackageJson.version);
41+
const newVersion = semver(flags['new-version']);
42+
43+
if (!semver.gt(newVersion, currentVersion)) {
44+
process.stderr.write(`New version must be greater than current version\n`);
45+
process.exit();
46+
}
47+
48+
rootPackageJson.version = newVersion.toString();
49+
fs.writeFileSync(rootPackageJsonPath, `${JSON.stringify(rootPackageJson, null, 2)}\n`, 'utf8');
50+
childProcess.execSync(`git add "${rootPackageJsonPath}"`);
51+
3252
const packagesDirPath = path.resolve(__dirname, '../packages');
3353
const packages = fs.readdirSync(packagesDirPath);
3454

@@ -43,7 +63,7 @@ packages.forEach((packageName) => {
4363
return;
4464
}
4565
const pkgJson = JSON.parse(fs.readFileSync(packageJsonPath));
46-
pkgJson.version = newVersion;
66+
pkgJson.version = newVersion.toString();
4767

4868
['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']
4969
.forEach((dependencyType) =>{
@@ -52,10 +72,15 @@ packages.forEach((packageName) => {
5272
}
5373
Object.keys(pkgJson[dependencyType]).forEach((dependencyName) => {
5474
if (packages.includes(dependencyName)) {
55-
pkgJson[dependencyType][dependencyName] = `^${newVersion}`;
75+
pkgJson[dependencyType][dependencyName] = `^${newVersion.toString()}`;
5676
}
5777
});
5878
});
5979
fs.writeFileSync(packageJsonPath, `${JSON.stringify(pkgJson, null, 2)}\n`, 'utf8');
6080
childProcess.execSync(`git add "${packageJsonPath}"`);
6181
});
82+
83+
childProcess.execSync(`yarn install`);
84+
childProcess.execSync(`git add "${path.resolve(__dirname, '../yarn.lock')}"`);
85+
childProcess.execSync(`git commit -m "v${newVersion.toString()}"`);
86+
childProcess.execSync(`git tag -a v${newVersion.toString()} -m "v${newVersion.toString()}"`);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"graphlib": "2.x",
3535
"jasmine": "^5.6.0",
3636
"jasmine-console-reporter": "^3.1.0",
37+
"minimist": "1.x",
3738
"ncp": "2.x",
3839
"semver": "5.x"
3940
},
@@ -52,7 +53,6 @@
5253
"test": "./build-scripts/test.sh",
5354
"test:root": "./build-scripts/jasmine.sh --reporter=jasmine-console-reporter test/*.js",
5455
"clean": "./build-scripts/clean.sh",
55-
"version": "./build-scripts/version-packages.js",
5656
"publish-packages": "./build-scripts/publish.js"
5757
},
5858
"packageManager": "[email protected]"

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ __metadata:
581581
graphlib: "npm:2.x"
582582
jasmine: "npm:^5.6.0"
583583
jasmine-console-reporter: "npm:^3.1.0"
584+
minimist: "npm:1.x"
584585
ncp: "npm:2.x"
585586
semver: "npm:5.x"
586587
languageName: unknown

0 commit comments

Comments
 (0)