feat: hashFunction, hashDigest, hashDigestLength, and hashSalt and refactor lots of code #3255
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issue (if exists)
closes #3088, #2937
options.output.hash_function
andXxh3
Summary
馃 Generated by Copilot at ef12886
This pull request adds support for different hash functions and digest formats in the
rspack
crate and its dependencies. It introduces a new crate,rspack_hash
, that provides a common interface for hashing and encoding. It also updates the existing crates to use therspack_hash
crate and the hash options from theBuildContext
andOutputOptions
structs. It also refactors some code to improve consistency and reusability.Walkthrough
馃 Generated by Copilot at ef12886
data-encoding
crate and enable thexxh3
feature of thexxhash-rust
crate inCargo.toml
(link, link)OutputOptions
andRawOutputOptions
structs to configure the hash function, digest, length, and salt for the output files (link, link, link)rspack_hash
that provides a common interface for hashing and encoding, and define theHashFunction
,HashDigest
,RspackHash
,RspackHashDigest
, andEncodedHashDigest
types (link, link, link)data-encoding
crate inrspack_plugin_css
to use the workspace version (link)hash
field of theBuildInfo
andCodeGenerationResult
structs fromu64
toRspackHashDigest
, and change the return type of theget_module_hash
method of theModuleGraph
struct fromOption<u64>
toOption<&RspackHashDigest>
(link, link, link)Hash
andHasher
fromstd::hash
torspack_hash::Hash
andrspack_hash::RspackHash
, and remove the imports ofxxhash_rust::xxh3::Xxh3
(link, link)set_hash
method of theCodeGenerationResult
struct to use theRspackHash
type and take a reference to theHashFunction
enum as a parameter (link)build
method of theModule
trait fromu64
toRspackHashDigest
, and change the default implementation of thebuild
method to use theRspackHash
type and theBuildInfo::new
method (link, link)collect_changed_modules
function from(u64, String)
to(RspackHashDigest, String)
, and add a dereference operator to themodule_hash
variable (link, link)BuildContext
to thebuild
method of theModule
trait and its implementations, which is used to access the hash function option (link, link, link, link, link, link)&HashFunction
to theset_hash
method of theCodeGenerationResult
struct in thebuild
method of theModule
trait and its implementations, which is passed from thecompilation
variable (link, link, link, link, link, link)Xxh3
hasher with theRspackHash
hasher, and pass the hash function option from thebuild_context
variable in thebuild
method of theContextModule
struct (link)BuildResult
struct to use theBuildInfo::new
method and theBuildMeta::default
method, instead of theDefault::default
method, in thebuild
method of theModule
trait and its implementations ( link, link, link)BuildInfo
struct, which provides a constructor method and a builder method for setting thecacheable
field (link)AsAny
trait from therspack_util
crate, and remove the import of theAsAny
trait from therspack_core
crate, in thedependency
module (link, link)RspackHashDigest
type from therspack_hash
crate, and remove the imports ofHash
andHasher
fromstd::hash
, in thecode_generation_results
,hmr
,context_module
,external_module
,missing_module
,module_graph
,module
, andraw_module
modules (link, link, link, link, link, link, link, link)RspackHash
type from therspack_hash
crate, and remove the import of theXxh3
type from thexxhash_rust
crate, in thenormal_module
module (link, link)BuildInfo
andBuildMeta
types from therspack_core
crate, and remove the import of theAsAny
trait from therspack_core
crate, in thecontext_module
,external_module
, andmissing_module
modules (link, link, link)ext
module and its re-export from theutils
module, as it is now moved to therspack_util
crate (link)CompilerOptions
struct in the test fixture ofrspack_loader_sass
, which are used to set the hash function and digest options for the output files (link)