Created
February 23, 2022 17:57
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: `tsc > ./tsc_no_checks.js
It will modify the original source files