Skip to content

change percventage to size in bytes#5385

Open
Joaco2603 wants to merge 2 commits into
relative-ci:masterfrom
Joaco2603:feature/duplicateCode_metric
Open

change percventage to size in bytes#5385
Joaco2603 wants to merge 2 commits into
relative-ci:masterfrom
Joaco2603:feature/duplicateCode_metric

Conversation

@Joaco2603

@Joaco2603 Joaco2603 commented Oct 7, 2025

Copy link
Copy Markdown

Change summary

  • Updated the Webpack duplicate-code metric to report duplicate module size in bytes instead of percentages.
  • Adjusted metric configuration to use file-size formatting and treat higher duplicate values as regressions.
  • Refreshed extractor tests, duplicate-package insights, and report snapshots to align with the new byte-based metric.

Summary by CodeRabbit

  • New Features
    • Duplicate code is now reported as total size (file size) instead of a percentage, with clearer labeling that smaller is better.
  • Bug Fixes
    • Duplicate package insights are downgraded from error to warning, with updated wording (e.g., “Bundle contains X duplicate packages”).
  • Tests
    • Re-enabled a previously isolated test and updated expectations to align with new duplicate code sizing and insight severity.
  • Chores
    • Added ignore rules for test output artifacts to reduce noise in version control.

@coderabbitai

coderabbitai Bot commented Oct 7, 2025

Copy link
Copy Markdown

Walkthrough

  • Added packages/utils/jest-output.txt containing a single whitespace and updated .gitignore to ignore **/jest-output.txt.
  • In packages/utils/src/webpack/extract/modules.ts, switched duplicateCode from a percentage to a raw duplicate code size; removed lodash/round, totalCodeSize accumulation, and percentage calculations.
  • Updated metrics in packages/utils/src/webpack/metrics.ts: DUPLICATE_CODE now describes total duplicate size, type changed from Percentage to FileSize, biggerIsBetter set to false.
  • Adjusted tests:
    • modules-packages-duplicate.ts: removed describe.only; changed expected insight type from error to warning; updated message wording/counts.
    • modules.ts: updated expected duplicateCode values to large absolute sizes (e.g., 600, 5000).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly summarizes the main change of reporting the duplicate-code metric in bytes instead of a percentage. It is concise, clear, and directly aligned with the pull request's objectives. This focus helps teammates quickly grasp the core update when scanning PR history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e719850 and a702f49.

📒 Files selected for processing (1)
  • .gitignore (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .gitignore

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@socket-security

socket-security Bot commented Oct 7, 2025

Copy link
Copy Markdown

No dependency changes detected. Learn more about Socket for GitHub.

👍 No dependency changes detected in pull request

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/utils/src/webpack/extract/__tests__/modules-packages-duplicate.ts (1)

198-205: Clarify ambiguous duplicate package count messaging.

The text "Bundle contains 3 duplicate packages" (line 200) is ambiguous. Looking at the data:

  • package-c: 3 instances (2 extra copies)
  • package-a: 2 instances (1 extra copy)

This could mean:

  1. "3 duplicate instances" (2 + 1 extra copies)
  2. "3 duplicated packages" (counting distinct package names + instances)

The wording should clarify whether it refers to duplicate instances or distinct package names. Consider: "Bundle contains 2 packages with 3 duplicate instances" or "Bundle contains 3 total duplicate package instances (2 packages affected)".

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 59706bf and e719850.

⛔ Files ignored due to path filters (1)
  • packages/utils/src/report/__tests__/__snapshots__/create.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • README.md (1 hunks)
  • packages/utils/jest-output.txt (1 hunks)
  • packages/utils/src/webpack/extract/__tests__/modules-packages-duplicate.ts (3 hunks)
  • packages/utils/src/webpack/extract/__tests__/modules.ts (2 hunks)
  • packages/utils/src/webpack/extract/modules.ts (1 hunks)
  • packages/utils/src/webpack/metrics.ts (1 hunks)
🔇 Additional comments (7)
packages/utils/src/webpack/metrics.ts (1)

65-71: LGTM! Metric configuration correctly updated for byte-based duplicate code.

The changes appropriately reflect the transition from a percentage-based metric to a file-size metric:

  • Description accurately describes the total size measurement
  • Type change to FileSize ensures proper formatting
  • Setting biggerIsBetter: false correctly treats higher duplicate values as regressions
packages/utils/src/webpack/extract/__tests__/modules.ts (2)

72-72: LGTM! Test expectation correctly updated to byte-based metric.

The expected duplicateCode value of 600 bytes is correct:

  • ./module-b-c.css: 500 bytes × 1 duplicate instance = 500
  • ./module-b-c.js: 100 bytes × 1 duplicate instance = 100
  • Total: 600 bytes

162-162: LGTM! Test expectation correctly updated to byte-based metric.

The expected duplicateCode value of 5000 bytes is correct:

  • module-c: 5000 bytes appears in 2 chunks, resulting in 1 duplicate instance
  • Total: 5000 bytes
packages/utils/src/webpack/extract/modules.ts (2)

83-98: LGTM! Duplicate code calculation correctly updated to byte-based metric.

The refactored logic correctly calculates the total size of duplicate modules:

  • Line 83: duplicateCodeSize accumulator replaces the previous percentage-based calculation
  • Line 97: Correctly sums duplicateInstances * size for each duplicated module
  • For a module appearing in N chunks, it's duplicated (N-1) times, each contributing the full module size

This aligns with the updated test expectations and metric configuration.


112-112: LGTM! Metric value correctly returns raw byte size.

The change from a computed percentage to the raw duplicateCodeSize correctly implements the byte-based duplicate code metric as specified in the PR objectives.

packages/utils/src/webpack/extract/__tests__/modules-packages-duplicate.ts (2)

7-7: LGTM! Removed exclusive test marker.

Correctly removed describe.only - exclusive test blocks should not be committed as they skip other tests in the suite.


31-37: Code formatting change.

Reformatted function call to multi-line without changing logic.

@@ -0,0 +1 @@

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Remove test artifact file from version control.

This file appears to be a test output artifact and should not be committed. Test output files should be excluded via .gitignore.

Apply this diff to remove the file:

-1
- 

Additionally, ensure your .gitignore includes patterns to exclude test output files:

+# Test outputs
+**/jest-output.txt

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/utils/jest-output.txt at lines 1-1, this is a test output artifact
that should be removed from version control; delete the file from the repo and
add appropriate ignore patterns to .gitignore (e.g., jest-output.txt,
**/test-output/**, *.output, or a test artifacts rule) so future test outputs
are not committed; ensure you remove the tracked file (git rm or remove and
commit) and commit the updated .gitignore so the artifact stays excluded.

Comment thread README.md Outdated
@vio

vio commented Oct 8, 2025

Copy link
Copy Markdown
Member

@Joaco2603 Thank you for the PR! I will take a closer look at it in the coming days.

@relativeci

relativeci Bot commented Oct 8, 2025

Copy link
Copy Markdown

#12695 Bundle Size — 382.66KiB (-0.02%).

a702f49(current) vs 89d8cd8 master#12692(baseline)

Warning

Bundle contains 2 duplicate packages – View duplicate packages

Bundle metrics  Change 3 changes Regression 1 regression Improvement 1 improvement
                 Current
#12695
     Baseline
#12692
Regression  Initial JS 335.02KiB(~+0.01%) 335.01KiB
Improvement  Initial CSS 47.64KiB(-0.2%) 47.74KiB
Change  Cache Invalidation 41.09% 28.62%
No change  Chunks 3 3
No change  Assets 4 4
No change  Modules 701 701
No change  Duplicate Modules 0 0
No change  Duplicate Code 0% 0%
No change  Packages 39 39
No change  Duplicate Packages 1 1
Bundle size by type  Change 2 changes Regression 1 regression Improvement 1 improvement
                 Current
#12695
     Baseline
#12692
Regression  JS 335.02KiB (~+0.01%) 335.01KiB
Improvement  CSS 47.64KiB (-0.2%) 47.74KiB

Bundle analysis reportBranch Joaco2603:feature/duplicateCode_...Project dashboard


Generated by RelativeCIDocumentationReport issue

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