Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rspack_core/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub trait Cache: Debug + Send + Sync {
}

pub fn new_cache(
compiler_path: &String,
compiler_path: &str,
compiler_option: Arc<CompilerOptions>,
input_filesystem: Arc<dyn FileSystem>,
intermediate_filesystem: Arc<dyn IntermediateFileSystem>,
Expand Down
5 changes: 3 additions & 2 deletions crates/rspack_core/src/cache/persistent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{path::PathBuf, sync::Arc};
pub use cacheable_context::{CacheableContext, FromContext};
use occasion::MakeOccasion;
use rspack_fs::{FileSystem, IntermediateFileSystem, Result};
use rspack_macros::rspack_version;
use rspack_paths::ArcPath;
use rustc_hash::FxHashSet as HashSet;

Expand Down Expand Up @@ -36,7 +37,7 @@ pub struct PersistentCache {

impl PersistentCache {
pub fn new(
compiler_path: &String,
compiler_path: &str,
option: &PersistentCacheOptions,
compiler_options: Arc<CompilerOptions>,
input_filesystem: Arc<dyn FileSystem>,
Expand All @@ -45,7 +46,7 @@ impl PersistentCache {
let version = version::get_version(
input_filesystem.clone(),
&option.build_dependencies,
vec![compiler_path, &option.version],
vec![compiler_path, &option.version, rspack_version!()],
)?;
let storage = create_storage(option.storage.clone(), version, intermediate_filesystem);
let context = Arc::new(CacheableContext {
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/cache/persistent/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rspack_paths::AssertUtf8;
pub fn get_version(
fs: Arc<dyn FileSystem>,
dependencies: &Vec<PathBuf>,
salt: Vec<&String>,
salt: Vec<&str>,
) -> Result<String> {
let mut hasher = DefaultHasher::new();
for dep in dependencies {
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ proc-macro = true
[dependencies]
proc-macro2 = { workspace = true }
quote = { workspace = true }
regex = { workspace = true }
syn = { workspace = true, features = ["full"] }
7 changes: 7 additions & 0 deletions crates/rspack_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod cacheable_dyn;
mod hook;
mod merge;
mod plugin;
mod rspack_version;
mod runtime_module;
mod source_map_config;

Expand Down Expand Up @@ -101,3 +102,9 @@ pub fn disable_cacheable_dyn(
) -> proc_macro::TokenStream {
cacheable_dyn::disable_cacheable_dyn(tokens)
}

#[proc_macro]
pub fn rspack_version(_tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
let version = rspack_version::rspack_version();
quote::quote! { #version }.into()
}
9 changes: 9 additions & 0 deletions crates/rspack_macros/src/rspack_version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub fn rspack_version() -> String {
let re = regex::Regex::new(r#""version": ?"([0-9\.]+)""#).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()
}
Loading