Format Typescript compiler (tsc) diagnostic output into JSON, GHA Annotations, and more
npm install tsc-output-formatFormat Typescript compiler (tsc) diagnostic output into JSON, Github Actions Annotation and more.








- Supports CLI and programmatic use: Use it directly from the command line for quick compile and formatting, or integrate it into your workflows programmatically.
- TSC command friendly: Works with the existing tsc CLI options.
- Works on Pretty Mode: Works with --pretty flag enabled.
- Supports Watch Mode: Use it directly from the command line to enable watch mode.
- GitHub-Action Output: Format into GitHub-Action annotations for more visible and actionable error reporting in CI-environment.
- JSON Output: Format into a structured JSON format for easy integration with other tools or workflows.
- Customizable: Leverage the Formatter and Parser blueprint to create custom formatter and parser.
#### Format Example
From:
``text
src/index.ts(1,1): error TS1000: Unexpected Error.
1 const unexpected_error = unexpected_error;
~~~~~~~~~~~~~~~~
src/index2.ts:1:1 - error TS1000: Unexpected Error.
1 const unexpected_error = unexpected_error;
~~~~~~~~~~~~~~~~
`
To GHA annotations:
`text`
::error title=TS Diagnostic (TS1000),file=src/index.ts,line=1,endLine=1,col=1::Unexpected Error.
::error title=TS Diagnostic (TS1000),file=src/index2.ts,line=1,endLine=1,col=1::Unexpected Error.
To JSON Pretty:
`jsonc`
[
{
"file": "src/index.ts",
"line": "1",
"column": "1",
"errorCode": "TS1000",
"message": "Unexpected Error",
"source": "1 const unexpected_error = unexpected_error;\n ~~~~~~~~~~~~~~~~",
"sourceClean": "const unexpected_error = unexpected_error;"
},
{
"file": "src/index2.ts",
"line": "2",
"column": "2",
"errorCode": "TS1000",
"message": "Unexpected Error",
"source": "1 const unexpected_error = unexpected_error;\n ~~~~~~~~~~~~~~~~",
"sourceClean": "const unexpected_error = unexpected_error;"
}
]
To Grouped:
`txt
src/index.ts: found 1 errors.
src/index.ts(1,1): error TS1000: Unexpected Error.
1 const unexpected_error = unexpected_error;
~~~~~~~~~~~~~~~~
src/index2.ts: found 1 errors.
src/index.ts:1:1 - error TS1000: Unexpected Error.
1 const unexpected_error = unexpected_error;
~~~~~~~~~~~~~~~~
`
To Grouped Minify:
`txt`
src/index.ts: found 1 errors.
src/index2.ts: found 1 errors.
To Suppressed:
`text`
suppressed 2 tsc errors.
`bashNPM
npm install --save-dev tsc-output-format
Usage
$3
#### CLI Options
-
--formatOnly: boolean
- --formatOutput: raw | gha | grouped | groupedMin | json | jsonPretty | suppressed
- Other tsc cli options, such as:
- --watch
- --noEmit
- etc.#### Compile and Format
`bash
NODE
npx tsc-output-format --formatOutput=jsonBUN
bunx tsc-output-format --formatOutput=json
`use
-w or --watch flag for watch-mode.`bash
NODE
npx tsc-output-format --formatOutput=json --watchBUN
bunx tsc-output-format --formatOutput=json --watch
`#### Format Only
`bash
NODE
npx -p typescript tsc | npx tsc-output-format --formatOnly --formatOutput=jsonBUN
bunx tsc | bunx tsc-output-format --formatOnly --formatOutput=json
`use
-w or --watch flag for watch-mode.`bash
NODE
npx -p typescript tsc --watch | npx tsc-output-format --formatOnly --formatOutput=json --watchBUN
bunx tsc --watch | bunx tsc-output-format --formatOnly --formatOutput=json --watch
`#### Parse only
> Not available with CLI.
#### Custom
> Not available with CLI.
$3
#### Compile and Format
> Not available programmatically.
#### Format Only
`ts
import { Formatter } from "tsc-output-format";const errors =
src/index.ts(1,1): error TS1000: Unexpected error.;const gha = Formatter.ghaFormatter.format(errors);
const json = Formatter.jsonFormatter.format(errors);
const jsonPretty = Formatter.jsonPrettyFormatter.format(errors);
const grouped = Formatter.groupedFormatter.format(errors);
const groupedMin = Formatter.groupedMinFormatter.format(errors);
const suppressed = Formatter.suppressedFormatter.format(errors);
// do anything with all outputs...
`#### Parse only
`ts
import { Parser } from "tsc-output-format";const errors =
src/index.ts(1,1): error TS1000: Unexpected error.;const _default = Parser.defaultParser.parse(errors);
// do anything with parse result...
`#### Custom
`ts
import { Blueprint } from "tsc-output-format";const errors =
;const errorCodeParser = new Blueprint.Parser(/^.(TS\d+).$/gm, ['errorCode']);
const errorCodeFormatter = new Blueprint.Formatter(errorCodeParser, (parseResults) => {
return JSON.stringify(parseResults.map(result => result.errorCode));
})
const errorCodeList = errorCodeFormatter.format(errors); // [TS1000, TS1001]
``- Typescript - Strongly typed programming language that builds on JavaScript.
- Bun - All-in-one JavaScript runtime & toolkit designed for speed, complete with a bundler, test runner, and Node.js-compatible package manager.
The code in this project is released under the MIT License.