Skip to content

Conversation

@LingyuCoder
Copy link
Contributor

Summary

As discussed in #10573, to support the parsing of import.meta.filename/dirname in the NodeStuffPlugin, interop with the ImportMetaPlugin is required.

Since webpack's parser plugins are implemented in the compiler plugins, compilation hooks can be added on the compiler plugin. However, rspack's parser plugins are implemented in javascript parser, and also the compilation id cannot be obtained inside. It needs to be passed in step by step from the outside. Moreover, the processing of the parser and the execution of hooks are synchronous, but on rspack's Rust side, only asynchronous hooks are retained, and synchronous hooks are only privately implemented inside the parser hook.

Therefore, a hook is added to the parser hook for interop between the ImportMetaPlugin and the NodeStuffPlugin, and the name is changed to import_meta_property_in_desctructuring to indicate that it is a plugin interop hook.

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings November 20, 2025 10:37
@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Nov 20, 2025
@netlify
Copy link

netlify bot commented Nov 20, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 127450f
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/691ef29f21f1770008968f0e

Copilot finished reviewing on behalf of LingyuCoder November 20, 2025 10:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new parser hook import_meta_property_in_destructuring to enable interoperation between the ImportMetaPlugin and NodeStuffPlugin for handling import.meta.filename/dirname in destructuring contexts.

Key Changes

  • Introduces a plugin interop hook mechanism to the JavaScript parser trait
  • Adds import_meta_property_in_destructuring method to handle special import.meta properties during destructuring
  • Implements the hook call chain through the plugin drive system

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
crates/rspack_plugin_javascript/src/parser_plugin/trait.rs Adds the new import_meta_property_in_destructuring trait method with documentation, and imports DestructuringAssignmentProperty type
crates/rspack_plugin_javascript/src/parser_plugin/node_stuff_plugin.rs Implements stub for the new hook method (marked as TODO), and adds necessary import for DestructuringAssignmentProperty
crates/rspack_plugin_javascript/src/parser_plugin/import_meta_plugin.rs Calls the new hook when processing destructuring of import.meta, allowing other plugins to handle specific properties before falling back to default behavior
crates/rspack_plugin_javascript/src/parser_plugin/drive.rs Implements the plugin drive logic to invoke the hook across all registered plugins using SyncBailHook pattern, and adds necessary imports

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 20, 2025

📦 Binary Size-limit

Comparing 127450f to feat: support SRI with experiments.css and CssExtractRspackPlugin (#12239) by harpsealjs

❌ Size increased by 2.25KB from 47.63MB to 47.63MB (⬆️0.00%)

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 20, 2025

CodSpeed Performance Report

Merging #12255 will not alter performance

Comparing chore/add-import-meta-desctructuring-hook (127450f) with main (480f74a)

Summary

✅ 17 untouched

@LingyuCoder LingyuCoder requested a review from ahabhgk November 21, 2025 02:45
@LingyuCoder
Copy link
Contributor Author

Can this PR meet your needs? @magic-akari

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.

2 participants