Skip to content

feat: Add ResolverFactory hooks for webpack compatibility #10964

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 9, 2025

This PR implements ResolverFactory hooks to provide webpack compatibility, allowing plugins to intercept and modify resolver creation.

Changes

Added ResolverFactory Hooks

  • resolveOptions - SyncWaterfallHook<[ResolveOptionsWithDependencyType, { type: string }]>

    • Called before resolver creation to allow modification of resolve options
    • Plugins can modify options and return updated configuration
  • resolver - SyncHook<[Resolver, ResolveOptionsWithDependencyType, { type: string }]>

    • Called after resolver creation to allow plugins to access the resolver instance
    • Provides access to the created resolver and the options used

Implementation Details

  • Integrated hooks into the existing ResolverFactory.get() method
  • Maintains full backward compatibility with existing code
  • Follows existing hook patterns used throughout the codebase
  • Properly typed with TypeScript declarations
  • Passes all linting and formatting checks

Usage Example

class MyResolverPlugin {
  apply(compiler) {
    // Modify resolve options before resolver creation
    compiler.resolverFactory.hooks.resolveOptions.tap('MyPlugin', (options, context) => {
      if (context.type === 'normal') {
        return {
          ...options,
          mainFields: [...(options.mainFields || []), 'custom-main']
        };
      }
      return options;
    });

    // Access created resolver instances
    compiler.resolverFactory.hooks.resolver.tap('MyPlugin', (resolver, options, context) => {
      console.log(`Resolver created for type: ${context.type}`);
    });
  }
}

Benefits

  • Enables webpack plugins that rely on ResolverFactory hooks to work with Rspack
  • Provides fine-grained control over resolver creation and configuration
  • Maintains consistency with webpack's plugin API

Fixes #7463.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link

netlify bot commented Jul 9, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 835c4d9
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/686e388296b0680008db7713

@CLAassistant
Copy link

CLAassistant commented Jul 9, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ SyMind
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI and others added 2 commits July 9, 2025 09:12
Co-authored-by: SyMind <19852293+SyMind@users.noreply.github.com>
Co-authored-by: SyMind <19852293+SyMind@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [Feature]: ResolverFactory hooks feat: Add ResolverFactory hooks for webpack compatibility Jul 9, 2025
@Copilot Copilot AI requested a review from SyMind July 9, 2025 09:17
Copilot finished work on behalf of SyMind July 9, 2025 09:17
@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Jul 9, 2025
Copy link
Contributor

github-actions bot commented Jul 9, 2025

📦 Binary Size-limit

Comparing 835c4d9 to fix: improve error message in paralelLoader (#10961) by hardfist

🙈 Size remains the same at 59.49MB

Copy link

codspeed-hq bot commented Jul 9, 2025

CodSpeed Performance Report

Merging #10964 will not alter performance

Comparing copilot/fix-7463 (835c4d9) with main (e45c178)

Summary

✅ 16 untouched benchmarks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: feature release: feature related release(mr only)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: ResolverFactory hooks
3 participants