Skip to content

Commit dd13f2c

Browse files
authored
Merge pull request #29 from MatrixAI/feature-version_fix
feat: updating `cargo.toml` and `package.json` before version commit
2 parents 3747725 + 7e08698 commit dd13f2c

File tree

6 files changed

+56
-18
lines changed

6 files changed

+56
-18
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "quic"
3-
version = "0.0.1"
3+
version = "0.0.4-alpha.0"
44
authors = ["Roger Qiu <[email protected]>"]
55
license-file = "LICENSE"
66
edition = "2021"

benches/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import fs from 'fs';
44
import path from 'path';
55
import si from 'systeminformation';
66
import Stream1KB from './stream_1KB';
7-
// import Dummy from './dummy';
7+
// Import Dummy from './dummy';
88

99
async function main(): Promise<void> {
1010
await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true });
1111
// Running benches
1212
await Stream1KB();
13-
// await Dummy();
13+
// Await Dummy();
1414
const resultFilenames = await fs.promises.readdir(
1515
path.join(__dirname, 'results'),
1616
);

package-lock.json

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@matrixai/quic",
3-
"version": "0.0.2-alpha.0",
3+
"version": "0.0.4-alpha.0",
44
"bin": {
55
"server": "dist/bin/server.js"
66
},
@@ -20,7 +20,7 @@
2020
"prepare": "tsc -p ./tsconfig.build.json",
2121
"prebuild": "node ./scripts/prebuild.js",
2222
"build": "rimraf ./dist && tsc -p ./tsconfig.build.json",
23-
"postversion": "node ./scripts/postversion.js",
23+
"version": "node ./scripts/version.js",
2424
"prepublishOnly": "node ./scripts/prepublishOnly.js",
2525
"ts-node": "ts-node",
2626
"test": "jest",
@@ -40,10 +40,10 @@
4040
"ip-num": "^1.5.0"
4141
},
4242
"optionalDependencies": {
43-
"@matrixai/quic-linux-x64": "0.0.1",
44-
"@matrixai/quic-win32-x64": "0.0.1",
45-
"@matrixai/quic-darwin-x64": "0.0.1",
46-
"@matrixai/quic-darwin-arm64": "0.0.1"
43+
"@matrixai/quic-darwin-arm64": "0.0.4-alpha.0",
44+
"@matrixai/quic-darwin-x64": "0.0.4-alpha.0",
45+
"@matrixai/quic-linux-x64": "0.0.4-alpha.0",
46+
"@matrixai/quic-win32-x64": "0.0.4-alpha.0"
4747
},
4848
"devDependencies": {
4949
"@fast-check/jest": "^1.1.0",

scripts/postversion.js renamed to scripts/version.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env node
22

33
/**
4-
* This runs after `npm version` command.
5-
* This will update the `package.json` optional native dependencies
4+
* This runs after `npm version` command updates the version but before changes are commited.
5+
* This will update the `cargo.toml` version to match the new `package.json` verson.
6+
* This will also update the `package.json` optional native dependencies
67
* to match the same version as the version of this package.
78
* This maintains the same version between this master package
89
* and the optional native dependencies.
@@ -12,6 +13,8 @@
1213
* to prevent `npm` from attempting to download unpublished packages.
1314
*/
1415

16+
const path = require('path');
17+
const fs = require('fs');
1518
const os = require('os');
1619
const childProcess = require('child_process');
1720
const packageJSON = require('../package.json');
@@ -20,6 +23,37 @@ const platform = os.platform();
2023

2124
/* eslint-disable no-console */
2225
async function main() {
26+
console.error('Updating the cargo.toml version to match new version');
27+
const projectRoot = path.join(__dirname, '..');
28+
const cargoTOMLPath = path.join(projectRoot, 'Cargo.toml');
29+
const cargoTOML = await fs.promises.readFile(cargoTOMLPath, 'utf-8');
30+
const cargoTOMLMatch = cargoTOML.match(/version\s*=\s*"(.*)"/);
31+
const cargoTOMLUpdated = cargoTOML.replace(
32+
cargoTOMLMatch[0],
33+
`version = "${packageJSON.version}"`,
34+
);
35+
await fs.promises.writeFile(cargoTOMLPath, cargoTOMLUpdated, 'utf-8');
36+
37+
console.error('updating cargo lock file with change');
38+
childProcess.execFileSync('cargo', ['update', '--package', 'quic'], {
39+
stdio: ['inherit', 'inherit', 'inherit'],
40+
windowsHide: true,
41+
encoding: 'utf-8',
42+
shell: platform === 'win32' ? true : false,
43+
});
44+
45+
console.error('Staging changes in git');
46+
childProcess.execFileSync(
47+
'git',
48+
['add', cargoTOMLPath, path.join(projectRoot, 'Cargo.lock')],
49+
{
50+
stdio: ['inherit', 'inherit', 'inherit'],
51+
windowsHide: true,
52+
encoding: 'utf-8',
53+
shell: platform === 'win32' ? true : false,
54+
},
55+
);
56+
2357
console.error(
2458
'Updating the package.json with optional native dependencies and package-lock.json',
2559
);

0 commit comments

Comments
 (0)