-
-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: rspack_version macro use json to parse package.json (#8883)
- Loading branch information
1 parent
4542c8e
commit d3a3274
Showing
3 changed files
with
8 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
pub fn rspack_version() -> String { | ||
let re = regex::Regex::new(r#""version": ?"([0-9a-zA-Z\.-]+)""#).expect("should create regex"); | ||
// package.json in project root directory | ||
let package_json = include_str!("../../../package.json"); | ||
let version = re | ||
.captures(package_json) | ||
.expect("can not found version field in project package.json"); | ||
version[1].to_string() | ||
let mut pkg = | ||
json::parse(package_json).expect("can not parse package.json in project root directory"); | ||
let Some(version) = pkg["version"].take_string() else { | ||
panic!("version field in package.json is not a string"); | ||
}; | ||
version | ||
} |
d3a3274
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.
📝 Benchmark detail: Open