Skip to content

Conversation

@daniel-statsig
Copy link

@daniel-statsig daniel-statsig commented May 8, 2024

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

> [email protected] 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

@daniel-statsig daniel-statsig changed the title fix issue with result parsing fix: allow parsing of custom script outputs May 8, 2024
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.

1 participant