Skip to content

test(pack): add import type case for modularizeImport#2679

Merged
xusd320 merged 2 commits into
nextfrom
fix-modularize-import-type
Mar 11, 2026
Merged

test(pack): add import type case for modularizeImport#2679
xusd320 merged 2 commits into
nextfrom
fix-modularize-import-type

Conversation

@fireairforce

Copy link
Copy Markdown
Member

Summary

Add more test case for align with babel-plugin-import.

For example:

// Button is component
import { Button } from 'antd';

// UploadProps is type
import { UploadProps } from 'antd';

Under modularizeImport(swc plugin) + turbopack build, config:

"modularizeImports": {
       "antd": {
            "transform": "antd/es/{{ kebabCase member }}",
            "preventFullImport": false,
            "skipDefaultConversion": false,
            "style": "style"
        }
},

It will convert into:

// component ✅
import Button from 'antd/es/button';
import 'antd/style/button'

// type ❌ it will not resolve
import UploadProps from 'antd/es/upload-props';
import 'antd/style/upload-props';

We need to correct the user's input into:

import { Button } from 'antd';
imort type { UploadProps } from 'antd';

From some real project case:

image

Test Plan

Test case updated.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 introduces a new test case to highlight and address an issue within the modularizeImport optimization when processing type-only imports from libraries like antd. Currently, the optimization incorrectly transforms type imports into value imports, causing module resolution failures. The added test case aims to replicate this behavior and serve as a baseline for future fixes, ensuring that modularizeImport correctly handles import type declarations.

Highlights

  • New Test Case for Modularize Imports: Added a comprehensive test case to specifically address how modularizeImport handles type-only imports from libraries like antd.
  • Demonstrated Type Import Issue: The new test case explicitly shows the current incorrect behavior where modularizeImport transforms import { Type } from 'module' into a value import, leading to module not found errors for the generated paths.
  • Mock Type Definitions: Included mock antd type definitions (index.d.ts) to provide a realistic environment for the test case, defining UploadProps and UploadFile interfaces.
Changelog
  • crates/pack-tests/tests/snapshot/node_modules/antd/index.d.ts
    • Added a new declaration file for antd to define UploadProps and UploadFile interfaces.
  • crates/pack-tests/tests/snapshot/optimization/modularize_imports_keba_case/config.json
    • Updated the test configuration to use a TypeScript entry file instead of JavaScript.
  • crates/pack-tests/tests/snapshot/optimization/modularize_imports_keba_case/input/index.js
    • Removed the old JavaScript test input file.
  • crates/pack-tests/tests/snapshot/optimization/modularize_imports_keba_case/input/index.ts
    • Added a new TypeScript test input file demonstrating both value and type imports from antd.
  • crates/pack-tests/tests/snapshot/optimization/modularize_imports_keba_case/issues/Module-not-found-Can-t-resolve-antd-es-upload-prop-65101e.txt
    • Added a snapshot of a module resolution error for antd/es/upload-props.
  • crates/pack-tests/tests/snapshot/optimization/modularize_imports_keba_case/issues/Module-not-found-Can-t-resolve-antd-es-upload-prop-f9631d.txt
    • Added a snapshot of a module resolution error for antd/es/upload-props/style.
  • crates/pack-tests/tests/snapshot/optimization/modularize_imports_keba_case/output/_project___acb58d5a.js
    • Renamed to _project___2fe66d90.js and updated to reflect the new TypeScript input and expected errors.
  • crates/pack-tests/tests/snapshot/optimization/modularize_imports_keba_case/output/_project___acb58d5a.js.map
    • Renamed to _project___2fe66d90.js.map and updated its content.
  • crates/pack-tests/tests/snapshot/optimization/modularize_imports_keba_case/output/main.js
    • Updated the runtime module ID to reference the new TypeScript input file.
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
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.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds a snapshot test to verify the behavior of modularizeImport with kebabCase transforms, specifically for TypeScript type imports. The changes are self-contained and effectively demonstrate the issue described. I have one suggestion regarding a typo in a directory name to improve maintainability.

"entry": [
{
"import": "input/index.js",
"import": "input/index.ts",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

There appears to be a typo in the test's directory name. It is named modularize_imports_keba_case, but given the test configuration uses {{ kebabCase member }}, it should likely be modularize_imports_kebab_case. Correcting this would improve discoverability and consistency across the test suite.

@github-actions

Copy link
Copy Markdown

📊 Performance Benchmark Report (with-antd)

Utoopack Performance Report (Intelligent)

Report ID: utoopack_performance_report_20260311_085228
Generated: 2026-03-11 08:52:28
Trace File: trace_antd.json (0.6GB, 3.35M events)
Test Project: examples/with-antd


Executive Summary

Key Findings

Metric Value Assessment
Total Wall Time 8,233.9 ms Baseline
Total Thread Work (de-duped) 26,541.2 ms Non-overlapping busy time
Effective Parallelism 3.2x thread_work / wall_time
Working Threads 5 Threads with actual spans
Thread Utilization 64.5% 🆗 Average
Total Spans 1,674,322 All B/E + X events
Meaningful Spans (>= 10us) 522,536 (31.2% of total)
Tracing Noise (< 10us) 1,151,786 (68.8% of total)

Workload Distribution by Tier

Category Tasks Total Time (ms) % of Thread Work
P0: Runtime/Resolution 0 0.0 0.0%
P1: I/O & Heavy Tasks 38,179 3,613.6 13.6%
P3: Asset Pipeline 34,758 3,410.2 12.8%
P4: Bridge/Interop 0 0.0 0.0%
Other 449,599 21,435.7 80.8%

🤖 AI Intelligent Attributions

New section mapping granular tasks to bottlenecks.

Top 10 Batching Candidates

These highly-called tasks are dominated by a single parent. If the parent can batch them into one call, it drastically reduces scheduler overhead.

Task Name Count Top Caller (Attribution) Avg P95 Total Time
analyze ecmascript module 35,426 process module (77%) 100.3 us 0.31 ms 3,554.5 ms

Top 20 Tasks by Total Duration

Total (ms) Count Avg (us) P95 (ms) Max (ms) % Work Task Name Top Caller
7,363.6 186,287 39.5 0.1 26.0 27.7% module write all entrypoints to disk (1%)
3,840.8 65,830 58.3 0.1 236.5 14.5% process module module (15%)
3,554.5 35,426 100.3 0.3 236.4 13.4% analyze ecmascript module process module (77%)
2,846.2 24,128 118.0 0.4 65.2 10.7% code generation chunking (7%)
1,769.0 62,123 28.5 0.0 9.3 6.7% resolving module (28%)
1,613.4 59,239 27.2 0.0 8.3 6.1% internal resolving resolving (31%)
1,367.2 13,782 99.2 0.3 56.6 5.2% chunking write all entrypoints to disk (0%)
1,313.5 8,444 155.6 0.1 251.0 4.9% write all entrypoints to disk None (0%)
1,299.0 26,916 48.3 0.1 6.4 4.9% precompute code generation code generation (37%)
1,089.6 13,425 81.2 0.3 124.3 4.1% compute async module info chunking (0%)
1,026.1 8,033 127.7 0.5 54.7 3.9% parse ecmascript analyze ecmascript module (26%)
638.6 10,814 59.1 0.1 47.7 2.4% compute async chunks compute async chunks (0%)
302.7 1,935 156.4 0.4 16.2 1.1% generate source map code generation (96%)
85.4 636 134.3 0.1 21.4 0.3% compute binding usage info write all entrypoints to disk (1%)
59.3 188 315.4 0.4 19.4 0.2% make production chunks chunking (2%)
52.5 2,164 24.3 0.0 2.8 0.2% read file parse ecmascript (91%)
45.6 1,868 24.4 0.0 8.7 0.2% collect mergeable modules compute merged modules (0%)
34.6 574 60.4 0.1 7.8 0.1% async reference write all entrypoints to disk (1%)
30.9 3 10289.2 18.5 19.4 0.1% compute merged modules make production chunks (100%)
27.6 15 1839.6 6.8 7.3 0.1% apply effects write all entrypoints to disk (13%)

Duration Distribution

Range Count Percentage
< 10us (noise) 1,151,786 68.8%
10us - 100us 495,111 29.6%
100us - 1ms 23,111 1.4%
1ms - 10ms 4,229 0.3%
10ms - 100ms 79 0.0%
> 100ms 6 0.0%

Action Items

  1. [P0] Use Batching Candidates to pinpoint specific files needing try_join or reduced #[turbo_tasks::function] limits.
  2. [P1] Inspect P95 (ms) for heavy monolith tasks. Focus on long-tail outliers rather than averages.

Report generated by Intelligent Utoopack Performance Analysis Agent

@fireairforce fireairforce requested a review from yuzheng14 March 11, 2026 09:04
@xusd320 xusd320 merged commit 3588728 into next Mar 11, 2026
21 checks passed
@xusd320 xusd320 deleted the fix-modularize-import-type branch March 11, 2026 09:41
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.

2 participants