New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@fezvrasta/tsc-silent

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fezvrasta/tsc-silent - npm Package Compare versions

Comparing version

to
1.3.1

57

dist/tsc-silent.js

@@ -21,11 +21,26 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var 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")
.parse(process.argv);
var arg = require("arg");
var _a = arg({
"--suppress": [String],
"--compiler": String,
"--project": String,
"-p": "--project",
"--createSourceFile": String,
"--watch": Boolean,
"-w": "--watch",
"--stats": Boolean,
"--help": Boolean,
suppressConfig: Boolean,
}), arg_ = _a._, _b = _a["--suppress"], argSuppress = _b === void 0 ? [] : _b, argCompiler = _a["--compiler"], argProject = _a["--project"], argCreateSourceFile = _a["--createSourceFile"], _c = _a["--watch"], argWatch = _c === void 0 ? false : _c, _d = _a["--stats"], argStats = _d === void 0 ? false : _d, _e = _a["--help"], argHelp = _e === void 0 ? false : _e, _f = _a["--suppressCOnfig"], argSuppressConfig = _f === void 0 ? false : _f;
var argv = {
_: arg_,
suppress: argSuppress,
compiler: argCompiler,
project: argProject,
createSourceFile: argCreateSourceFile,
watch: argWatch,
stats: argStats,
help: argHelp,
suppressConfig: argSuppressConfig,
};
if (!argv.project || argv.help || argv._.length > 2) {

@@ -40,8 +55,8 @@ printUsage();

ts = require(path.resolve(argv.compiler));
var config = (argv.suppressConfig
var config = argv.suppressConfig
? require(path.resolve(argv.suppressConfig))
: null);
var supressConfig = (config
: null;
var supressConfig = config
? parseSuppressRules(config.suppress)
: argv.suppress.map(prepareSuppressArg));
: argv.suppress.map(prepareSuppressArg);
console.log("Using TypeScript compiler version " + ts.version + " from " + path.resolve(argv.compiler));

@@ -51,3 +66,3 @@ var formatHost = {

getCurrentDirectory: ts.sys.getCurrentDirectory,
getNewLine: function () { return ts.sys.newLine; }
getNewLine: function () { return ts.sys.newLine; },
};

@@ -65,3 +80,4 @@ if (argv.createSourceFile) {

}, function reportWatchStatusChanged(diagnostic) {
if (diagnostic.code === 6031 || diagnostic.code === 6032) { // Starting compilation | File change detected
if (diagnostic.code === 6031 || diagnostic.code === 6032) {
// Starting compilation | File change detected
process.stdout.write("\u001b[2J\u001b[0;0H"); // clear console

@@ -71,3 +87,4 @@ watchDiagnostics_1 = [];

}
else if (diagnostic.code === 6194) { // Compilation done
else if (diagnostic.code === 6194) {
// Compilation done
assertDiagnostics(diagnostic, formatHost, false);

@@ -97,3 +114,3 @@ assertDiagnostics(watchDiagnostics_1, formatHost);

host: compilerHost,
configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics(configParseResult)
configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics(configParseResult),
};

@@ -204,5 +221,7 @@ var program = ts.createProgram(programOptions);

var suppressedDiag = suppressedDiagnostics_1[_c];
if (suppress.pathRegExp && suppress.pathRegExp.test(suppressedDiag.file.fileName)) {
if (suppress.pathRegExp &&
suppress.pathRegExp.test(suppressedDiag.file.fileName)) {
statisticsItem.total++;
if (suppress.codes.length && suppress.codes.indexOf(suppressedDiag.code) !== -1) {
if (suppress.codes.length &&
suppress.codes.indexOf(suppressedDiag.code) !== -1) {
statisticsItemCodes[suppressedDiag.code]++;

@@ -209,0 +228,0 @@ }

{
"name": "@fezvrasta/tsc-silent",
"version": "1.3.0",
"version": "1.3.1",
"description": "tsc with --supress",

@@ -30,7 +30,6 @@ "main": "dist/index.js",

"@types/node": "10.12.7",
"yargs": "12 - 15"
"arg": "^4.1.3"
},
"peerDependencies": {
"typescript": ">=2.9",
"yargs": "12 - 15"
"typescript": ">=2.9"
},

@@ -37,0 +36,0 @@ "devDependencies": {

@@ -13,12 +13,38 @@ // tslint:disable no-console

}
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")
.parse(process.argv);
const arg = require("arg");
const {
_: arg_,
"--suppress": argSuppress = [],
"--compiler": argCompiler,
"--project": argProject,
"--createSourceFile": argCreateSourceFile,
"--watch": argWatch = false,
"--stats": argStats = false,
"--help": argHelp = false,
"--suppressCOnfig": argSuppressConfig = false,
} = arg({
"--suppress": [String],
"--compiler": String,
"--project": String,
"-p": "--project",
"--createSourceFile": String,
"--watch": Boolean,
"-w": "--watch",
"--stats": Boolean,
"--help": Boolean,
suppressConfig: Boolean,
});
const argv = {
_: arg_,
suppress: argSuppress,
compiler: argCompiler,
project: argProject,
createSourceFile: argCreateSourceFile,
watch: argWatch,
stats: argStats,
help: argHelp,
suppressConfig: argSuppressConfig,
};
if (!argv.project || argv.help || argv._.length > 2) {

@@ -58,25 +84,27 @@ printUsage();

const config = (
argv.suppressConfig
? require(path.resolve(argv.suppressConfig)) as SupressConfigFile
: null
);
const config = argv.suppressConfig
? (require(path.resolve(argv.suppressConfig)) as SupressConfigFile)
: null;
const supressConfig = (
config
? parseSuppressRules(config.suppress)
: argv.suppress.map(prepareSuppressArg)
const supressConfig = config
? parseSuppressRules(config.suppress)
: argv.suppress.map(prepareSuppressArg);
console.log(
`Using TypeScript compiler version ${ts.version} from ${path.resolve(
argv.compiler
)}`
);
console.log(`Using TypeScript compiler version ${ts.version} from ${path.resolve(argv.compiler)}`);
const formatHost: ts.FormatDiagnosticsHost = {
getCanonicalFileName: (filename: string) => filename,
getCurrentDirectory: ts.sys.getCurrentDirectory,
getNewLine: () => ts.sys.newLine
getNewLine: () => ts.sys.newLine,
};
if (argv.createSourceFile) {
const originalCreateSourceFile = ts.createSourceFile;
// @ts-ignore
ts.createSourceFile = require(`${process.cwd()}/${argv.createSourceFile}`)(originalCreateSourceFile);
const originalCreateSourceFile = ts.createSourceFile;
// @ts-ignore
ts.createSourceFile = require(`${process.cwd()}/${argv.createSourceFile}`)(
originalCreateSourceFile
);
}

@@ -96,7 +124,9 @@

function reportWatchStatusChanged(diagnostic: ts.Diagnostic) {
if (diagnostic.code === 6031 || diagnostic.code === 6032) { // Starting compilation | File change detected
if (diagnostic.code === 6031 || diagnostic.code === 6032) {
// Starting compilation | File change detected
process.stdout.write("\u001b[2J\u001b[0;0H"); // clear console
watchDiagnostics = [];
assertDiagnostics(diagnostic, formatHost, false);
} else if (diagnostic.code === 6194) { // Compilation done
} else if (diagnostic.code === 6194) {
// Compilation done
assertDiagnostics(diagnostic, formatHost, false);

@@ -116,3 +146,3 @@ assertDiagnostics(watchDiagnostics, formatHost);

const origPostProgramCreate = watchCompilerHost.afterProgramCreate;
watchCompilerHost.afterProgramCreate = program => {
watchCompilerHost.afterProgramCreate = (program) => {
origPostProgramCreate!(program);

@@ -122,7 +152,15 @@ };

} else {
const configObject = ts.parseConfigFileTextToJson(argv.project, fs.readFileSync(argv.project).toString());
const configObject = ts.parseConfigFileTextToJson(
argv.project,
fs.readFileSync(argv.project).toString()
);
assertDiagnostics(configObject.error, formatHost, false);
const configParseResult
= ts.parseJsonConfigFileContent(configObject.config, ts.sys, process.cwd(), undefined, argv.project);
const configParseResult = ts.parseJsonConfigFileContent(
configObject.config,
ts.sys,
process.cwd(),
undefined,
argv.project
);
assertDiagnostics(configParseResult.errors, formatHost, false);

@@ -136,3 +174,5 @@

host: compilerHost,
configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics(configParseResult)
configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics(
configParseResult
),
};

@@ -142,3 +182,6 @@ const program = ts.createProgram(programOptions);

process.exit(
assertDiagnostics(ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics), compilerHost),
assertDiagnostics(
ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics),
compilerHost
)
);

@@ -148,4 +191,4 @@ }

// @ts-ignore // ********************************
return; // Only functions follow this point
// ********************************
return; // Only functions follow this point
// ********************************

@@ -155,3 +198,3 @@ function assertDiagnostics(

formatDiagnosticsHost: ts.FormatDiagnosticsHost,
allowSuppress = true,
allowSuppress = true
): number {

@@ -185,9 +228,18 @@ if (!diagnostics) {

// console.(error | warn) does not allow to grep output (OS X)
console.log(ts.formatDiagnosticsWithColorAndContext(diagnosticsToShow, formatDiagnosticsHost));
console.log(
ts.formatDiagnosticsWithColorAndContext(
diagnosticsToShow,
formatDiagnosticsHost
)
);
}
if (allowSuppress) {
if (argv.stats) {
console.log(JSON.stringify(getStatistics(suppressedDiagnostics), null, " "));
console.log(
JSON.stringify(getStatistics(suppressedDiagnostics), null, " ")
);
}
console.warn(`Visible errors: ${diagnosticsToShow.length}, suppressed errors: ${suppressedDiagnostics.length}`);
console.warn(
`Visible errors: ${diagnosticsToShow.length}, suppressed errors: ${suppressedDiagnostics.length}`
);
}

@@ -220,3 +272,5 @@ if (diagnosticsToShow.length) {

function parseSuppressRules(suppressRules: RawSupressConfig[]): SupressConfig[] {
function parseSuppressRules(
suppressRules: RawSupressConfig[]
): SupressConfig[] {
return suppressRules.map((rule) => ({

@@ -244,3 +298,5 @@ ...rule,

function getStatistics(suppressedDiagnostics: ts.Diagnostic[]): StatisticsItem[] {
function getStatistics(
suppressedDiagnostics: ts.Diagnostic[]
): StatisticsItem[] {
const statistics = [];

@@ -259,5 +315,11 @@ for (const suppress of supressConfig) {

for (let suppressedDiag of suppressedDiagnostics) {
if (suppress.pathRegExp && suppress.pathRegExp.test(suppressedDiag.file!.fileName)) {
if (
suppress.pathRegExp &&
suppress.pathRegExp.test(suppressedDiag.file!.fileName)
) {
statisticsItem.total++;
if (suppress.codes.length && suppress.codes.indexOf(suppressedDiag.code) !== -1) {
if (
suppress.codes.length &&
suppress.codes.indexOf(suppressedDiag.code) !== -1
) {
statisticsItemCodes[suppressedDiag.code]++;

@@ -273,3 +335,5 @@ }

console.log("Usage:");
console.log(" tsc-silent --project <path> [--suppress config | --suppressConfig path] [--compiler path]");
console.log(
" tsc-silent --project <path> [--suppress config | --suppressConfig path] [--compiler path]"
);
console.log(" [--watch]");

@@ -281,6 +345,10 @@ console.log();

console.log(" --compiler Path to typescript.js.");
console.log(" By default, uses `./node_modules/typescript/lib/typescript.js`.");
console.log(
" By default, uses `./node_modules/typescript/lib/typescript.js`."
);
console.log();
console.log(" --suppress Suppressed erros.");
console.log(" E.g. `--suppress 7017@src/js/ 2322,2339,2344@/src/legacy/`.")
console.log(
" E.g. `--suppress 7017@src/js/ 2322,2339,2344@/src/legacy/`."
);
console.log();

@@ -292,13 +360,27 @@ console.log(" --suppressConfig Path to supressed errors config.");

console.log();
console.log(" --stats Print number of suppressed errors per path and error code.");
console.log(
" --stats Print number of suppressed errors per path and error code."
);
console.log();
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(
". --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");
console.log("coming from certain files/folders. For example, this can be used to enable `noImplicitAny` in");
console.log("some parts of the project while keeping it disabled in others.");
console.log(
"The purpose of the wrapper is to execute TypeScript compiler but suppress some error messages"
);
console.log(
"coming from certain files/folders. For example, this can be used to enable `noImplicitAny` in"
);
console.log(
"some parts of the project while keeping it disabled in others."
);
console.log();
}