Socket
Socket
Sign inDemoInstall

tsc-watch

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsc-watch - npm Package Compare versions

Comparing version 1.1.34 to 1.1.35

4

CHANGELOG.md
# @gilamran/tsc-watch CHANGELOG
## v1.1.35 - 28/1/2019
Clean code
## v1.1.32 - 27/11/2018

@@ -4,0 +8,0 @@

setInterval(() => console.log(Math.random()), 1000);
setInterval(() => console.log(Math.random()), 1000);

@@ -0,0 +0,0 @@ function removeRunnerArgs(args) {

@@ -0,0 +0,0 @@ const { fork } = require('child_process');

@@ -0,0 +0,0 @@ const psTree = require('ps-tree');

@@ -0,1 +1,58 @@

const stripAnsi = require('strip-ansi');
const tscUsageSyntaxRegex = / -w, --watch.*Watch input files\./;
const typescriptPrettyErrorRegex = /:\d+:\d+ \- error TS\d+: /;
const typescriptErrorRegex = /\(\d+,\d+\): error TS\d+: /;
const compilationCompleteWithErrorRegex = / Found [^0][0-9]* error[s]?\. Watching for file changes\./;
const compilationCompleteWithoutErrorRegex = / Found 0 errors\. Watching for file changes\./;
const compilationCompleteRegex = / Found \d+ error[s]?\. Watching for file changes\./;
const newCompilationRegex = / File change detected\. Starting incremental compilation\.\.\./;
const newAdditionToSyntax = [
' -w, --watch Watch input files. [always on]',
' --onSuccess COMMAND Run the COMMAND on each successful compilation',
' --onFirstSuccess COMMAND Run the COMMAND on the first successful compilation (Will not run the onSuccess)',
' --onFailure COMMAND Run the COMMAND on each failed compilation',
' --noColors Removes the red/green colors from the compiler output',
' --noClear Prevents the compiler from clearing the screen',
' --compiler PATH The PATH will be used instead of typescript compiler. Defaults typescript/bin/tsc.',
].join('\n');
function isError(line) {
return typescriptErrorRegex.test(line) || typescriptPrettyErrorRegex.test(line);
}
function color(line) {
if (isError(line)) {
return `\u001B[36m${line}\u001B[39m`; // Cyan
}
if (compilationCompleteWithErrorRegex.test(line)) {
return `\u001B[31m${line}\u001B[39m`; // Red
}
if (compilationCompleteWithoutErrorRegex.test(line)) {
return `\u001B[32m${line}\u001B[39m`; // Green
}
if (tscUsageSyntaxRegex.test(line)) {
return `\u001B[33m${line}\u001B[39m`; // Yellow
}
if (newCompilationRegex.test(line)) {
return '\n\n----------------------\n' + line;
}
return line;
}
function print(noColors, lines) {
return lines.forEach(line => console.log(noColors ? line : color(line)));
}
function removeColors(lines) {
return lines.map(line => stripAnsi(line));
}
function isClear(buffer) {

@@ -5,8 +62,3 @@ return buffer && buffer.length === 2 && buffer[0] === 0x1b && buffer[1] === 0x63;

function manipulate(noClear, buffer) {
if (noClear && isClear(buffer)) {
console.log('\n');
return;
}
function manipulate(buffer) {
const lines = buffer

@@ -16,6 +68,23 @@ .toString()

.filter(a => a.length > 0)
.map(a => a.replace(typescriptWatchCommandRegex, newAdditionToSyntax));
.map(a => a.replace(tscUsageSyntaxRegex, newAdditionToSyntax));
print(lines);
const cleanLines = removeColors(lines);
return lines;
}
function detectState(lines) {
const clearLines = removeColors(lines);
const compilationError = clearLines.some(line => compilationCompleteWithErrorRegex.test(line));
const compilationComplete = clearLines.some(line => compilationCompleteRegex.test(line));
return {
compilationError: compilationError,
compilationComplete: compilationComplete,
};
}
module.exports = {
print: print,
isClear: isClear,
manipulate: manipulate,
detectState: detectState,
};

80

lib/tsc-watch.js

@@ -7,17 +7,6 @@ #!/usr/bin/env node

const spawn = require('cross-spawn');
const stripAnsi = require('strip-ansi');
const stringArgv = require('string-argv');
const { extractArgs } = require('./args-manager');
const { manipulate, detectState, isClear, print } = require('./stdout-manipulator');
const compilationStartedRegex = /Starting incremental compilation/;
const compilationCompleteRegex = /( Compilation complete\. Watching for file changes\.| Found \d+ error[s]?\. Watching for file changes\.)/;
const typescriptSuccessRegex = /Compilation complete|Found 0 errors/;
const typescriptWatchCommandRegex = /Watch input files\./;
const typescriptPrettyErrorRegex = /:\d+:\d+ \- error TS\d+: /;
const typescriptErrorRegex = /\(\d+,\d+\): error TS\d+: /;
const onSuccessCommandSyntax = ' --onSuccess COMMAND Run the COMMAND on each successful compilation';
const onFirstSuccessCommandSyntax = ' --onFirstSuccess COMMAND Run the COMMAND on the first successful compilation (Will not run the onSuccess)';
const onFailureCommandSyntax = ' --onFailure COMMAND Run the COMMAND on each failed compilation';
const newAdditionToSyntax = ['Watch input files. [always on]', onSuccessCommandSyntax, onFirstSuccessCommandSyntax, onFailureCommandSyntax].join('\n');
let hadErrors = false;

@@ -33,23 +22,2 @@ let firstTime = true;

let { onFirstSuccessCommand, onSuccessCommand, onFailureCommand, noColors, noClear, compiler, args } = extractArgs(process.argv);
function color(line) {
if (typescriptErrorRegex.test(line)) {
return `\u001B[31m${line}\u001B[39m`; //Red
}
if (typescriptSuccessRegex.test(line) || typescriptWatchCommandRegex.test(line)) {
return `\u001B[32m${line}\u001B[39m`; //Green
}
return line;
}
function print(lines) {
return lines.forEach(line => console.log(noColors ? line : color(line)));
}
function removeColors(lines) {
return lines.map(line => stripAnsi(line));
}
function runCommand(fullCommand) {

@@ -107,43 +75,19 @@ if (fullCommand) {

function isClear(buffer) {
return buffer && buffer.length === 2 && buffer[0] === 0x1b && buffer[1] === 0x63;
}
const tscProcess = spawn(bin, [...args]);
tscProcess.stdout.on('data', buffer => {
if (noClear && isClear(buffer)) {
console.log('\n');
return;
}
const lines = buffer
.toString()
.split('\n')
.filter(a => a.length > 0)
.map(a => a.replace(typescriptWatchCommandRegex, newAdditionToSyntax));
const lines = manipulate(buffer);
print(noColors, lines);
const { compilationError, compilationComplete } = detectState(lines);
print(lines);
const cleanLines = removeColors(lines);
const newCompilation = cleanLines.some(line => compilationStartedRegex.test(line));
if (newCompilation) {
hadErrors = false;
}
const error = cleanLines.some(line => typescriptErrorRegex.test(line) || typescriptPrettyErrorRegex.test(line));
if (error) {
hadErrors = true;
}
const compilationComplete = cleanLines.some(line => compilationCompleteRegex.test(line));
if (compilationComplete) {
killAllProcesses().then(() => {
if (hadErrors) {
if (compilationError) {
Signal.emitFail();
if (onFailureCommand) {
failureProcess = runCommand(onFailureCommand);
failureProcessExited = new Promise(resolve => {
failureProcess.on('exit', code => {
resolve(code);
});
});
failureProcessExited = new Promise(resolve => failureProcess.on('exit', resolve));
}

@@ -155,14 +99,6 @@ } else {

firstSuccessProcess = runCommand(onFirstSuccessCommand);
firstSuccessProcessExited = new Promise(resolve => {
firstSuccessProcess.on('exit', code => {
resolve(code);
});
});
firstSuccessProcessExited = new Promise(resolve => firstSuccessProcess.on('exit', resolve));
} else if (onSuccessCommand) {
successProcess = runCommand(onSuccessCommand);
successProcessExited = new Promise(resolve => {
successProcess.on('exit', code => {
resolve(code);
});
});
successProcessExited = new Promise(resolve => successProcess.on('exit', resolve));
}

@@ -169,0 +105,0 @@ }

{
"name": "tsc-watch",
"version": "1.1.34",
"version": "1.1.35",
"description": "The TypeScript compiler with onSuccess command",

@@ -5,0 +5,0 @@ "scripts": {

@@ -0,0 +0,0 @@ # The TypeScript compiler with `--onSuccess` argument

@@ -0,0 +0,0 @@ const { expect } = require('chai');

@@ -0,0 +0,0 @@ const { expect } = require('chai');

@@ -0,0 +0,0 @@ const { fork } = require('child_process');

@@ -0,0 +0,0 @@ const { expect } = require('chai');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc