Format 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.
From:
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:
::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:
To Grouped:
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:
src/index.ts: found 1 errors.
src/index2.ts: found 1 errors.
To Suppressed:
suppressed 2 tsc errors.
# NPM
npm install --save-dev tsc-output-format
# BUN
bun add -d tsc-output-format
-
--formatOnly
:boolean
-
--formatOutput
:raw
|gha
|grouped
|groupedMin
|json
|jsonPretty
|suppressed
- Other
tsc
cli options, such as:--watch
--noEmit
- etc.
# NODE
npx tsc-output-format --formatOutput=json
# BUN
bunx tsc-output-format --formatOutput=json
use -w
or --watch
flag for watch-mode.
# NODE
npx tsc-output-format --formatOutput=json --watch
# BUN
bunx tsc-output-format --formatOutput=json --watch
# NODE
npx -p typescript tsc | npx tsc-output-format --formatOnly --formatOutput=json
# BUN
bunx tsc | bunx tsc-output-format --formatOnly --formatOutput=json
use -w
or --watch
flag for watch-mode.
# NODE
npx -p typescript tsc --watch | npx tsc-output-format --formatOnly --formatOutput=json --watch
# BUN
bunx tsc --watch | bunx tsc-output-format --formatOnly --formatOutput=json --watch
Not available with CLI.
Not available with CLI.
Not available programmatically.
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 supressed = Formatter.suppressedFormatter.format(errors);
// do anything with all outputs...
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...
import { Blueprint } from "tsc-output-format";
const errors = `
src/index.ts(1,1): error TS1000: Unexpected error.
src/index.ts(2,1): error TS1001: Unknown error.
`;
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.