Skip to content

Commit 582fe82

Browse files
authored
feat: add a way to get the library version (#652)
1 parent 32e6e61 commit 582fe82

File tree

11 files changed

+113
-89
lines changed

11 files changed

+113
-89
lines changed

.changeset/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,30 @@
1414
- Commit the changed files
1515
- Run `pnpm changeset publish` to publish the packages to npm
1616
- `git push && git push --tags`
17+
18+
# Release Rust Crates
19+
20+
- Run `pnpm release-rust <target-version>` to get the command that can update the version of the rust crates.
21+
22+
```
23+
cargo release version -x --workspace 1.4.1 --exclude loro-rle --exclude loro-delta --exclude loro_fractional_index
24+
```
25+
26+
- Commit the changes
27+
- Replace the `version` command with `publish`
28+
29+
```
30+
cargo release publish -x --workspace --exclude loro-rle --exclude loro-delta --exclude loro_fractional_index
31+
```
32+
33+
- Add git tags by replacing `publish` with `tag`
34+
35+
```
36+
cargo release tag -x --workspace --exclude loro-rle --exclude loro-delta --exclude loro_fractional_index
37+
```
38+
39+
- Push the changes
40+
41+
```
42+
git push && git push --tags
43+
```

crates/loro-ffi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use loro::{
66
CounterSpan, EventTriggerKind, ExpandType, FractionalIndex, IdLp, IdSpan, JsonChange,
77
JsonFutureOp, JsonFutureOpWrapper, JsonListOp, JsonMapOp, JsonMovableListOp, JsonOp,
88
JsonOpContent, JsonPathError, JsonSchema, JsonTextOp, JsonTreeOp, Lamport, LoroEncodeError,
9-
LoroError, PeerID, StyleConfig, TreeID, UpdateOptions, UpdateTimeoutError, ID,
9+
LoroError, PeerID, StyleConfig, TreeID, UpdateOptions, UpdateTimeoutError, ID, LORO_VERSION,
1010
};
1111
pub use std::cmp::Ordering;
1212
use std::sync::Arc;

crates/loro-internal/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.4.2

crates/loro-internal/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,6 @@ pub struct LoroDocInner {
143143
local_update_subs: SubscriberSetWithQueue<(), LocalUpdateCallback, Vec<u8>>,
144144
peer_id_change_subs: SubscriberSetWithQueue<(), PeerIdUpdateCallback, ID>,
145145
}
146+
147+
/// The version of the loro crate
148+
pub const LORO_VERSION: &str = include_str!("../VERSION");

crates/loro-wasm/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ pub use awareness::AwarenessWasm;
4747

4848
mod convert;
4949

50+
/// Get the version of Loro
51+
#[wasm_bindgen]
52+
pub fn LORO_VERSION() -> String {
53+
loro_internal::LORO_VERSION.to_string()
54+
}
55+
5056
#[wasm_bindgen(start)]
5157
fn run() {
5258
console_error_panic_hook::set_once();

crates/loro/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub use loro_internal::diff::diff_impl::UpdateTimeoutError;
3636
pub use loro_internal::subscription::LocalUpdateCallback;
3737
pub use loro_internal::subscription::PeerIdUpdateCallback;
3838
pub use loro_internal::ChangeMeta;
39+
pub use loro_internal::LORO_VERSION;
3940
pub mod event;
4041
pub use loro_internal::awareness;
4142
pub use loro_internal::change::Timestamp;

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
"test-all": "pnpm test && pnpm test-wasm",
1212
"test-wasm": "cd crates/loro-wasm && pnpm i && pnpm build-dev",
1313
"coverage": "mkdir -p coverage && cargo llvm-cov nextest --features test_utils,jsonpath --lcov > coverage/lcov-nextest.info && cargo llvm-cov report",
14-
"release-wasm": "cd crates/loro-wasm && pnpm i && pnpm build-release",
14+
"release-wasm": "deno run -A ./scripts/sync-loro-version.ts && cd crates/loro-wasm && pnpm i && pnpm build-release",
1515
"check": "cargo clippy --all-features -- -Dwarnings",
1616
"run-fuzz-corpus": "cd crates/fuzz && cargo +nightly fuzz run all -- -max_total_time=1",
1717
"fix": "cargo clippy --fix --features=test_utils",
18-
"vet": "cargo vet"
18+
"vet": "cargo vet",
19+
"release-rust": "deno run -A ./scripts/cargo-release.ts"
1920
},
2021
"keywords": [],
2122
"author": "",

scripts/bump-rust-crates.ts

Lines changed: 0 additions & 86 deletions
This file was deleted.

scripts/cargo-release.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env -S deno run --allow-run
22

33
import { defineCommand, runMain } from "npm:citty";
4+
import { runSyncLoroVersion } from "./sync-loro-version.ts";
45

56
async function runCargoRelease(version: string): Promise<string> {
67
const process = new Deno.Command("cargo", {
@@ -62,6 +63,7 @@ const main = defineCommand({
6263
throw new Error("Version must be in format x.y.z (e.g., 1.2.3)");
6364
}
6465

66+
runSyncLoroVersion(version);
6567
const output = await runCargoRelease(version);
6668
console.log("Original output:");
6769
console.log(output);

scripts/deno.lock

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

0 commit comments

Comments
 (0)