Skip to content

Instantly share code, notes, and snippets.

@andresesfm
Created February 23, 2022 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andresesfm/b29497a06ea826f134118ac7114a7620 to your computer and use it in GitHub Desktop.
Save andresesfm/b29497a06ea826f134118ac7114a7620 to your computer and use it in GitHub Desktop.
Takes the output of tsc (Typescript compiler) and marks the files with type errors with the no-check flag
#!/usr/bin/env node
const fs = require("fs");
const through = require('through');
const split = require('split');
/**
* Takes the output of tsc (Typescript compiler) and marks the files with type errors
* with the no-check flag
*/
function main() {
let files = new Set()
process.stdin
.pipe(split())
.pipe(fileswithError())
.pipe(uniqueFiles())
.pipe(noCheckFiles())
.pipe(process.stdout);
function fileswithError() {
return through(function (line) {
if (line.search(/error.*TS/) > -1) {
let filename = line.split('(')[0]
//console.log(filename + '!')
this.emit('data', filename);
}
});
}
function uniqueFiles() {
return through(function (filename) {
if (!files.has(filename)) {
this.emit('data', filename);
files.add(filename);
//console.log(filename + '!')
}
});
}
function noCheckFiles() {
return through(function (filename) {
var data = fs.readFileSync(filename); //read existing contents into data
var fd = fs.openSync(filename, 'w+');
var buffer = Buffer.from('//@ts-nocheck \n');
fs.writeSync(fd, buffer, 0, buffer.length, 0); //write new data
fs.writeSync(fd, data, 0, data.length, buffer.length); //append old data
// or fs.appendFile(fd, data);
fs.close(fd);
this.emit('data', filename + '\n');
});
}
}
main()
@andresesfm
Copy link
Author

Usage: `tsc > ./tsc_no_checks.js
It will modify the original source files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment