Skip to content

fix(pack): deal node_modules alias correctly#2237

Merged
xusd320 merged 1 commit intonextfrom
fix-2221
Oct 10, 2025
Merged

fix(pack): deal node_modules alias correctly#2237
xusd320 merged 1 commit intonextfrom
fix-2221

Conversation

@fireairforce
Copy link
Contributor

Summary

closes: #2221

这种 case webpack 是支持处理的,参考下面的能通过的 test case:

image

调试发现是 resolve 的 alias extension 在处理 foreign(node_modules 模块)跟 internal(项目内部模块) extension 配置好像没统一导致的(例如假设项目的 alias extension 是要找一个 *.ts 文件,但 node_modules 里面的产物是 js,这样 node_modules 中的依赖内容 resolve alias 的时候在没有配置 enable_typescript 的情况下会找不到对应的文件)。

Test Plan

新增了对应的快照测试

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @fireairforce, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical bug impacting how module aliases are processed within node_modules dependencies. Previously, there was an inconsistency in how resolution extensions were applied, leading to failures when node_modules attempted to resolve aliased paths, especially in mixed TypeScript/JavaScript environments. The changes unify the resolution context configuration, guaranteeing that all necessary extension-related options are correctly enabled for both internal and external modules. This ensures reliable alias resolution across the entire project, and the fix is verified by a new, dedicated snapshot test.

Highlights

  • Node.js Modules Alias Resolution Fix: Corrected an issue where alias extensions were not uniformly applied when resolving modules within node_modules compared to internal project modules, particularly affecting TypeScript/JavaScript files.
  • Unified Resolve Options: Ensured that key resolve options such as enable_typescript, enable_react, enable_mjs_extension, and custom_extensions are consistently configured for the client's module resolution context.
  • New Snapshot Test Case: Added a comprehensive snapshot test to validate the proper resolution of aliased paths originating from within node_modules.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

你好,感谢你的贡献。本次 PR 旨在修复 node_modules 中的模块在使用项目别名时因解析配置不一致而导致解析失败的问题。你通过将 enable_typescriptenable_react 等选项应用到 foreign 模块(即 node_modules 中的模块)的解析上下文中,统一了内外部模块的解析行为,从根本上解决了这个问题。代码改动清晰、准确。同时,你还将测试代码中的 tt.run 更新为 tt.run_once 并简化了错误处理,这是一个很好的重构。新增的快照测试也充分验证了修复的有效性。整体来看,这是一个高质量的提交,我没有发现需要修改的地方。做得很好!

@xusd320 xusd320 merged commit 26043d2 into next Oct 10, 2025
16 checks passed
@xusd320 xusd320 deleted the fix-2221 branch October 10, 2025 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Utoopack] node_modules 依赖中的 alias 代码不会被处理

2 participants