From faa04c1a0d6637e041b1c03ef1c03106f57bf023 Mon Sep 17 00:00:00 2001 From: Federico Zivolo <5382443+FezVrasta@users.noreply.github.com> Date: Thu, 30 Apr 2020 10:05:28 +0200 Subject: [PATCH 1/2] POC for custom createSourceFile option --- src/tsc-silent.ts | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/tsc-silent.ts b/src/tsc-silent.ts index 3dafbef..c569a58 100644 --- a/src/tsc-silent.ts +++ b/src/tsc-silent.ts @@ -13,6 +13,7 @@ const argv: Argv = require("yargs") .array("suppress").default("suppress", []) .string("compiler").default("compiler", "node_modules/typescript/lib/typescript.js") .string("project").alias("project", "p") + .string("createSourceFile") .boolean("watch").default("watch", false).alias("watch", "w") .boolean("stats").default("stats", false) .boolean("help") @@ -71,6 +72,11 @@ const formatHost: ts.FormatDiagnosticsHost = { getNewLine: () => ts.sys.newLine }; +if (argv.createSourceFile) { + const originalCreateSourceFile = ts.createSourceFile; + ts.createSourceFile = require(argv.createSourceFile)(originalCreateSourceFile); +} + if (argv.watch) { let watchDiagnostics: ts.Diagnostic[] = []; const createProgram = ts.createSemanticDiagnosticsBuilderProgram; @@ -253,20 +259,24 @@ function printUsage() { console.log(" [--watch]"); console.log(); console.log("Synopsis:"); - console.log(" --project, -p Path to tsconfig.json"); + console.log(" --project, -p Path to tsconfig.json"); + console.log(); + console.log(" --compiler Path to typescript.js."); + console.log(" By default, uses `./node_modules/typescript/lib/typescript.js`."); console.log(); - console.log(" --compiler Path to typescript.js."); - console.log(" By default, uses `./node_modules/typescript/lib/typescript.js`."); + console.log(" --suppress Suppressed erros."); + console.log(" E.g. `--suppress 7017@src/js/ 2322,2339,2344@/src/legacy/`.") console.log(); - console.log(" --suppress Suppressed erros."); - console.log(" E.g. `--suppress 7017@src/js/ 2322,2339,2344@/src/legacy/`.") + console.log(" --suppressConfig Path to supressed errors config."); + console.log(" See documentation for examples."); console.log(); - console.log(" --suppressConfig Path to supressed errors config."); - console.log(" See documentation for examples."); + console.log(" --watch, -w Run in watch mode."); console.log(); - console.log(" --watch, -w Run in watch mode."); + console.log(" --stats Print number of suppressed errors per path and error code."); console.log(); - console.log(" --stats Print number of suppressed errors per path and error code."); + console.log(". --createSourceFile Custom module to use in place of the default TypeScript logic, + console.log(" it expects a module that exports a single function, with the"); + console.log(" original TypeScript function as sole argument."); console.log(); console.log("Description:"); console.log("The purpose of the wrapper is to execute TypeScript compiler but suppress some error messages"); From 7a6499540e93fc293d347464175409165cfd6b30 Mon Sep 17 00:00:00 2001 From: Federico Zivolo <5382443+FezVrasta@users.noreply.github.com> Date: Thu, 30 Apr 2020 10:17:43 +0200 Subject: [PATCH 2/2] Update tsc-silent.ts --- src/tsc-silent.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tsc-silent.ts b/src/tsc-silent.ts index c569a58..5c373d0 100644 --- a/src/tsc-silent.ts +++ b/src/tsc-silent.ts @@ -74,7 +74,7 @@ const formatHost: ts.FormatDiagnosticsHost = { if (argv.createSourceFile) { const originalCreateSourceFile = ts.createSourceFile; - ts.createSourceFile = require(argv.createSourceFile)(originalCreateSourceFile); + ts.createSourceFile = require(`${process.cwd()}/${argv.createSourceFile}`)(originalCreateSourceFile); } if (argv.watch) {