Skip to content

Commit 100cd52

Browse files
committed
chore: add script to sync crate version with npm version
1 parent 8f360f9 commit 100cd52

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
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.

crates/domparser/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
edition = "2021"
33
name = "domparser"
4-
version = "0.0.0"
4+
version = "0.0.3"
55

66
[dependencies]
77
html5ever = "0.27.0"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"build:debug": "napi build --platform --package domparser_napi --js index.js && node scripts/postbuild.js",
6464
"prepublishOnly": "napi prepublish -t npm",
6565
"universal": "napi universalize",
66-
"version": "napi version",
66+
"version": "napi version && node scripts/sync-version.js && git add crates/domparser/Cargo.toml",
6767
"test": "node --test",
6868
"benchmark": "node ./benchmark/benchmark.mjs",
6969
"prepare": "husky install"

scripts/sync-version.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const packageJson = require('../package.json');
5+
const version = packageJson.version;
6+
7+
const cargoTomlPath = path.join(__dirname, '../crates/domparser/Cargo.toml');
8+
let cargoToml = fs.readFileSync(cargoTomlPath, 'utf8');
9+
10+
// Replace version = "..." with version = "new_version"
11+
// We match the version key specifically under [package] section ideally,
12+
// but usually it's the first version key in the file.
13+
const newCargoToml = cargoToml.replace(/^version\s*=\s*".*?"/m, `version = "${version}"`);
14+
15+
if (cargoToml !== newCargoToml) {
16+
fs.writeFileSync(cargoTomlPath, newCargoToml);
17+
console.log(`Updated crates/domparser/Cargo.toml to version ${version}`);
18+
} else {
19+
console.log('crates/domparser/Cargo.toml version is already up to date.');
20+
}

0 commit comments

Comments
 (0)