What is the best way to save the results of `yarn audit` to a text file?

Viewed 4708

I have tried using yarn-audit-html but it outputs a .html file.

I would like the output audit table results from the audit in a text or json file.

Here is the data I am looking for: enter image description here

Note: copy/paste from the terminal is not an option because of the # of results that are returned.

2 Answers

You can redirect the output of yarn audit into a file on the command line.

yarn audit > audit-output.txt

The default output of audit contains lots of color sequences that make it difficult to read but could probably be stripped out in post-processing. To get the output as JSON, add the --json flag.

yarn audit --json > audit-output.json

Use this command to output a text file without color codes:

yarn audit --groups dependencies --no-color > .yarn-audit

Use this command in a build to output text without color and ignore the return code.

yarn audit --groups dependencies --no-color > .yarn-audit || true 
Related