Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hashFunction, hashDigest, hashDigestLength, and hashSalt and refactor lots of code #3255

Merged
merged 3 commits into from
May 25, 2023

Conversation

ahabhgk
Copy link
Collaborator

@ahabhgk ahabhgk commented May 22, 2023

Related issue (if exists)

closes #3088, #2937

  • refactor Xxh3 hash usage
  • add hashFunction, hashDigest, hashDigestLength, and hashSalt
  • introduce RspackHash: a thin wrapper for options.output.hash_function and Xxh3
  • refactor createHash, and align part of logic with webpack

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 the rspack_hash crate and the hash options from the BuildContext and OutputOptions structs. It also refactors some code to improve consistency and reusability.

Walkthrough

馃 Generated by Copilot at ef12886

  • Add a dependency on the data-encoding crate and enable the xxh3 feature of the xxhash-rust crate in Cargo.toml (link, link)
  • Add fields to the OutputOptions and RawOutputOptions structs to configure the hash function, digest, length, and salt for the output files (link, link, link)
  • Add a new crate rspack_hash that provides a common interface for hashing and encoding, and define the HashFunction, HashDigest, RspackHash, RspackHashDigest, and EncodedHashDigest types (link, link, link)
  • Change the dependency on the data-encoding crate in rspack_plugin_css to use the workspace version (link)
  • Change the type of the hash field of the BuildInfo and CodeGenerationResult structs from u64 to RspackHashDigest, and change the return type of the get_module_hash method of the ModuleGraph struct from Option<u64> to Option<&RspackHashDigest> (link, link, link)
  • Change the imports of Hash and Hasher from std::hash to rspack_hash::Hash and rspack_hash::RspackHash, and remove the imports of xxhash_rust::xxh3::Xxh3 (link, link)
  • Change the implementation of the set_hash method of the CodeGenerationResult struct to use the RspackHash type and take a reference to the HashFunction enum as a parameter (link)
  • Change the type of the first element of the tuple returned by the build method of the Module trait from u64 to RspackHashDigest, and change the default implementation of the build method to use the RspackHash type and the BuildInfo::new method (link, link)
  • Change the type of the first element of the tuple returned by the collect_changed_modules function from (u64, String) to (RspackHashDigest, String), and add a dereference operator to the module_hash variable (link, link)
  • Add a parameter of type BuildContext to the build method of the Module trait and its implementations, which is used to access the hash function option (link, link, link, link, link, link)
  • Add a parameter of type &HashFunction to the set_hash method of the CodeGenerationResult struct in the build method of the Module trait and its implementations, which is passed from the compilation variable (link, link, link, link, link, link)
  • Replace the use of the Xxh3 hasher with the RspackHash hasher, and pass the hash function option from the build_context variable in the build method of the ContextModule struct (link)
  • Change the construction of the BuildResult struct to use the BuildInfo::new method and the BuildMeta::default method, instead of the Default::default method, in the build method of the Module trait and its implementations ( link, link, link)
  • Add an implementation of the BuildInfo struct, which provides a constructor method and a builder method for setting the cacheable field (link)
  • Add an import of the AsAny trait from the rspack_util crate, and remove the import of the AsAny trait from the rspack_core crate, in the dependency module (link, link)
  • Add an import of the RspackHashDigest type from the rspack_hash crate, and remove the imports of Hash and Hasher from std::hash, in the code_generation_results, hmr, context_module, external_module, missing_module, module_graph, module, and raw_module modules (link, link, link, link, link, link, link, link)
  • Add an import of the RspackHash type from the rspack_hash crate, and remove the import of the Xxh3 type from the xxhash_rust crate, in the normal_module module (link, link)
  • Add an import of the BuildInfo and BuildMeta types from the rspack_core crate, and remove the import of the AsAny trait from the rspack_core crate, in the context_module, external_module, and missing_module modules (link, link, link)
  • Remove the ext module and its re-export from the utils module, as it is now moved to the rspack_util crate (link)
  • Add fields to the CompilerOptions struct in the test fixture of rspack_loader_sass, which are used to set the hash function and digest options for the output files (link)

@github-actions github-actions bot added release: feature team The issue/pr is created by the member of Rspack. labels May 22, 2023
@ahabhgk ahabhgk linked an issue May 22, 2023 that may be closed by this pull request
@ahabhgk ahabhgk marked this pull request as ready for review May 24, 2023 10:55
@ahabhgk ahabhgk changed the title feat: hashFunction, hashDigest, hashDigestLength, and hashSalt feat: hashFunction, hashDigest, hashDigestLength, and hashSalt and refactor lots of code May 24, 2023
wip2

wip3

wow

rebase

fix scheme

remove crate

add test

revert example

fix cargo t

fix

fix
@underfin underfin added this pull request to the merge queue May 25, 2023
Merged via the queue into main with commit e526831 May 25, 2023
13 checks passed
@underfin underfin deleted the rspack_hash branch May 25, 2023 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

output.hashFunction and hashDigestLength css-loader enable module generate error local name
2 participants