preactjs / compressed-size-action

GitHub Action that adds compressed size changes to your PRs.
https://github.com/marketplace/actions/compressed-size-action
MIT License
602 stars 84 forks source link

Inaccurate looking reports #30

Closed necolas closed 4 years ago

necolas commented 4 years ago

I'm having trouble producing reports that look accurate.

I have a build that outputs a dist directory containing compiled (not minified) files structured like this:

index.js
A/
  index.js
  some.js
  helper.js
  files.js
B/
  index.js
  some.js
  helper.js
  files.js

I have a workflow setup like this:

name: Compressed Size
on: [pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: preactjs/compressed-size-action@v2
      with:
        pattern: "./dist/{index.js,**/index.js}"
        repo-token: "${{ secrets.GITHUB_TOKEN }}"

And it produces reports like this:

/index.js | 821 B
/A/index.js | 833 B
/B/index.js | 444 B

Users are expected to import the modules like this:

import A from 'package/A'

Some of the modules share the same internal dependencies, or have dependencies on each other. That's fine because I'm more interested in what the maximum potential cost of each module is, rather than showing that using A + B is less than the sum of their bundle sizes.

However, I know the values in the report are wrong in terms of the actual size contributes to bundles from importing say A/index.js. At first I assumed the action was only looking at the files themselves and not including their internal imports in the size calculation. But if I change the pattern to dist/**, not only do the reported sizes of the index.js files change but the plugin also reports size values for the directory itself (i.e., A). And some of the internal helper files also seem to have incorrect values. One standalone helper file was reported as being 4.5KB, but it's a small file and compressing it myself showed it to be 476 bytes.

necolas commented 4 years ago

Seems best to let this tool run over all the files in each directory and use it just for ballpark estimates of what is getting bigger/smaller