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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add scheme, mimetype, and resourceFragment rule condition #3238

Merged
merged 1 commit into from
May 22, 2023

Conversation

ahabhgk
Copy link
Collaborator

@ahabhgk ahabhgk commented May 20, 2023

Related issue (if exists)

fixes #3150

  • refactor resolveForScheme hook
  • add more module rule condition: scheme, mimetype, resourceFragment
  • refactor Filename::render, now query and fragment is parsed from filename

Summary

🤖 Generated by Copilot at 8d60263

This pull request adds a new hook to the rspack compiler that allows plugins to customize the resolution of resources with different schemes, such as data, file, or http. It also updates the node_binding crate to support the new hook in the Node.js integration, and adds or modifies several plugins to handle different types of asset modules. Additionally, it improves the code quality and readability of some structs and methods in the rspack_core, rspack_binding_options, and rspack_loader_runner crates.

Walkthrough

🤖 Generated by Copilot at 8d60263

  • Add new fields resource_fragment, scheme, and mimetype to the ModuleRule and RawModuleRule structs to allow specifying condition matchers for the resource fragment, the scheme, and the mimetype in the module rules (link, link, link, link, link, link, link)
  • Add a new hook normal_module_factory_resolve_for_scheme to the Hook enum and the Plugin trait to allow plugins to customize the resolution of resources with different schemes (link, link, link, link, link, link, link, link)
  • Change the output type of the normal_module_factory_resolve_for_scheme hook to include a flag to indicate whether to stop the resolution process (link, link, link, link, link, link, link, link, link)
  • Rename the Scheme::Normal variant to Scheme::None and handle the empty string case in the Scheme enum (link, link, link, link, link)
  • Use the mime_guess crate to guess the mime type of resources based on their file extensions (link, link, link)
  • Use the urlencoding crate to encode and decode binary data as URL-safe strings (link, link, link, link)
  • Use the let_chains feature to write if let and match expressions in a chain (link, link)
  • Use the serde_json crate to serialize the encoded source as a JSON string in the AssetParserAndGenerator struct (link, link)
  • Simplify the JsPathData struct by removing the query and fragment fields and updating the methods accordingly (link, link)
  • Simplify the Debug implementation for the ModuleRule struct by using the derivative crate and a custom format_with attribute for the r#use field (link)
  • Implement the logic for parsing and generating the asset modules based on the resource data and the encoding option in the AssetParserAndGenerator struct (link, link, link, link, link)
  • Implement the logic for running the normal_module_factory_resolve_for_scheme hook for each plugin and returning the final resolved data and the flag in the PluginDriver struct (link)
  • Implement the logic for calling the normal_module_factory_resolve_for_scheme hook from the Rust and JavaScript sides using the napi crate in the JsPlugin and JsHooks structs (link, link, link, link)
  • Implement the logic for converting the resource_fragment, scheme, and mimetype fields from the RawModuleRule struct to the ModuleRule struct in the try_into method (link, link)
  • Implement the logic for matching the condition matchers for the resource fragment, the scheme, and the mimetype in the try_match method of the ModuleRule struct (link)
  • Implement the logic for templating the output filename based on the resource data and handling the data scheme in the mut function of the Filename struct (link)
  • Handle the data scheme in the parse method of the ImportDependency struct by using the parse_resource function (link)
  • Handle the data scheme in the copy method of the CopyPlugin struct by skipping the asset path generation and the asset info insertion (link)
  • Fix a type mismatch error in the copy method of the CopyPlugin struct by using the to_string_lossy method for the source_filename (link)
  • Derive the Debug implementation for the ModuleIdentifier struct (link)
  • Rename the struct SchemeAndJsResourceData to JsResolveForSchemeInput to make the name more descriptive and consistent with the new hook name (link, link, link)
  • Remove the unused import of std::path::Path in the path_data.rs file (link)
  • Remove the unused import of PluginNormalModuleFactoryResolveForSchemeOutput in the plugin_driver.rs file (link)
  • Remove a redundant comment in the parse method of the ImportDependency struct (link)

@github-actions github-actions bot added release: feature team The issue/pr is created by the member of Rspack. labels May 20, 2023
@ahabhgk
Copy link
Collaborator Author

ahabhgk commented May 22, 2023

!eco-ci

@rspack-bot
Copy link

rspack-bot commented May 22, 2023

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
nx ❌ failure

@ahabhgk ahabhgk changed the title feat: data uri part 2 feat: add scheme, mimetype, and resourceFragment rule condition May 22, 2023
@ahabhgk ahabhgk added this pull request to the merge queue May 22, 2023
Merged via the queue into main with commit 7127f01 May 22, 2023
19 checks passed
@ahabhgk ahabhgk deleted the data-uri-2 branch May 22, 2023 04:15
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.

resolver not work properly while dealing with data-url?
3 participants