CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-rollup-plugin-sizes

Show info about files/packages included with your rollup bundle

94

1.09x
Overview
Eval results
Files

task.mdevals/scenario-1/

Bundle Size Percentage Calculator

Build a module that calculates percentage distributions for bundle size analysis data.

Requirements

Create a function that takes bundle data and calculates what percentage each package and file contributes to the total.

Input Format

{
  packages: [
    {
      name: "lodash",
      size: 24000,
      files: [
        { path: "core.js", size: 15000 },
        { path: "utils.js", size: 9000 }
      ]
    },
    {
      name: "react",
      size: 6000,
      files: [
        { path: "index.js", size: 6000 }
      ]
    }
  ]
}

Expected Behavior

Calculate two types of percentages:

  1. Package percentage: Each package's size as a percentage of the total bundle size
  2. File percentage: Each file's size as a percentage of its parent package size

All percentages must be formatted to 2 decimal places.

Output Format

{
  totalSize: 30000,
  packages: [
    {
      name: "lodash",
      size: 24000,
      percentage: 80.00,  // 24000/30000 * 100
      files: [
        { path: "core.js", size: 15000, percentage: 62.50 },  // 15000/24000 * 100
        { path: "utils.js", size: 9000, percentage: 37.50 }
      ]
    },
    {
      name: "react",
      size: 6000,
      percentage: 20.00,
      files: [
        { path: "index.js", size: 6000, percentage: 100.00 }
      ]
    }
  ]
}

Implementation

@generates

API

/**
 * Calculates percentage distributions for bundle analysis data
 * @param {Object} bundleData - The bundle analysis data
 * @param {Array} bundleData.packages - Array of package objects
 * @returns {Object} Analysis summary with percentages
 */
function calculatePercentages(bundleData) {
  // Implementation here
}

module.exports = { calculatePercentages };

Test Cases

  • Given bundle data with multiple packages, calculates correct package percentages relative to total @test
  • Given packages with multiple files, calculates correct file percentages relative to parent package @test
  • Formats all percentages to exactly 2 decimal places @test
  • Handles edge case where total size is zero @test

Dependencies { .dependencies }

rollup-plugin-sizes { .dependency }

Provides bundle size analysis and visualization capabilities for Rollup bundler

Install with Tessl CLI

npx tessl i tessl/npm-rollup-plugin-sizes

tile.json