andresz1 / size-limit-action

Compare the real cost to run your JS app or lib to keep good performance in every pull request
ISC License
449 stars 83 forks source link

fix: allow parsing of custom script outputs #115

Open daniel-statsig opened 4 months ago

daniel-statsig commented 4 months ago

Description

with:
  script: "npm run my-script"

is resulting in an output that starts with some preamble before the JSON array is printed.

This preamble is resulting in the JSON.parse failing.

Example

> package@0.0.1 size /path/to/repo
> size-limit "--json"

[
  {
    "name": "bundle-one",
    "passed": true,
    "size": 9319,
    "sizeLimit": 10000,
    "running": 0.23261666666666667,
    "loading": 0.18201171875
  },
  {
    "name": "bundle-two",
    "passed": true,
    "size": 11037,
    "sizeLimit": 12000,
    "running": 0.26038333333333336,
    "loading": 0.21556640625
  },
  {
    "name": "bundle-three",
    "passed": true,
    "size": 29620,
    "sizeLimit": 35000,
    "running": 0.25188333333333335,
    "loading": 0.578515625
  }
]

Fix

By finding the first '[' and last ']', we ensure we only try parse the JSON array part of the string