Socket
Socket
Sign inDemoInstall

tsc-watch

Package Overview
Dependencies
20
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.4.0 to 4.5.0

43

CHANGELOG.md
# @gilamran/tsc-watch CHANGELOG
## v4.5.0 - 19/8/2021
- Added `onCompilationStarted` option - (Thanks to @axtk for the idea and @dko-slapdash for the PR)
- Fix: enable unit tests which were turned off accidentally
## v4.4.0 - 26/5/ 2021
tsc-watch is now listenning to message and reacts to them.
- tsc-watch is now listening to message and reacts to them
## v4.3.1 - 26/5/2021
fix: compiler resolving - (Thanks to @merceyz for the PR)
- Fix: compiler resolving - (Thanks to @merceyz for the PR)
## v4.2.9 - 23/6/2020
fix: upgrade cross-spawn and strip-ansi (node 8+) - (Thanks to @FauxFaux for the PR)
- Fix: upgrade cross-spawn and strip-ansi (node 8+) - (Thanks to @FauxFaux for the PR)
## v4.2.8 - 23/5/2020
Fix: spawn compiler using node, this fixes issues with yarn v2 (pnp) - (Thanks to @merceyz)
- Fix: spawn compiler using node, this fixes issues with yarn v2 (pnp) - (Thanks to @merceyz)
## v4.2.6 - 18/5/2020
Using number 15 instead of SIGTERM to support POSIX standard - (Thanks to @Asarew)
- Using number 15 instead of SIGTERM to support POSIX standard - (Thanks to @Asarew)
## v4.2.0 - 29/2/2020
Using readline instead of raw stdout buffer - (Thanks to @Janpot for the idea)
- Using readline instead of raw stdout buffer - (Thanks to @Janpot for the idea)
## v4.1.0 - 22/1/2020
Added the `onCompilationComplete` option - (Thanks to @ackvf for the idea)
- Added the `onCompilationComplete` option - (Thanks to @ackvf for the idea)
## v4.0.0 - 19/9/2019
Terminating previous processes is now done with `SIGTERM` instead of `SIGUSR2`. - (Thanks to @zontarian)
- Terminating previous processes is now done with `SIGTERM` instead of `SIGUSR2` - (Thanks to @zontarian)
## v3.0.0 - 9/9/2019
onSuccess will run on EVERY successful compilation, also on the first success. - (Thanks to @mchl-hub for the idea)
- onSuccess will run on EVERY successful compilation, also on the first success - (Thanks to @mchl-hub for the idea)
## v2.2.1 - 19/5/2019
Force kill when on windows - (Thanks to @hwwi)
- Force kill when on windows - (Thanks to @hwwi)
## v2.2.0 - 13/5/2019
Waiting for all the child processes to showdown before closing - (Thanks to @MartinLoeper)
- Waiting for all the child processes to showdown before closing - (Thanks to @MartinLoeper)
## v2.1.0 - 12/2/2019
Exporting TscWatchClient for multiple instance of `tsc-watch` - (Thanks to @pronebird)
- Exporting TscWatchClient for multiple instance of `tsc-watch` - (Thanks to @pronebird)
## v2.0.0 - 12/2/2019
As many users requested, from now on `--onFirstSuccess` process will not get killed, only when tsc-watch is killed. (Based on @amir-arad's PR)
- As many users requested, from now on `--onFirstSuccess` process will not get killed, only when tsc-watch is killed. (Based on @amir-arad's PR)
This version fixes Issue #20, #21 and #50.

@@ -56,19 +63,19 @@

Fixed coloring issues
- Fixed coloring issues
## v1.1.36 - 31/1/2019
`--watch` will be added to the end of the arguments (Thanks to @barkayal)
- `--watch` will be added to the end of the arguments (Thanks to @barkayal)
## v1.1.35 - 28/1/2019
Clean code
- Clean code
## v1.1.32 - 27/11/2018
Added --noClear command to prevent clearing the screen after each compilation
- Added --noClear command to prevent clearing the screen after each compilation
## v1.0.32 - 27/11/2018
Removed chalk dependency - (Thanks to @frank-orellana)
- Removed chalk dependency - (Thanks to @frank-orellana)

@@ -75,0 +82,0 @@ ## v1.0.31 - 27/11/2018

module.exports = require('./lib/client');
console.log('Generating random number every sec');
setInterval(() => console.log(Math.random()), 1000);
console.log('Generating random number every sec');
setInterval(() => console.log(Math.random()), 1000);

@@ -0,0 +0,0 @@ {

@@ -51,2 +51,3 @@ function removeRunnerArgs(args) {

const onFailureCommand = extractCommandWithValue(allArgs, '--onFailure');
const onCompilationStarted = extractCommandWithValue(allArgs, '--onCompilationStarted');
const onCompilationComplete = extractCommandWithValue(allArgs, '--onCompilationComplete');

@@ -66,2 +67,3 @@ const noColors = extractCommand(allArgs, '--noColors');

onFailureCommand: onFailureCommand,
onCompilationStarted: onCompilationStarted,
onCompilationComplete: onCompilationComplete,

@@ -68,0 +70,0 @@ noColors: noColors,

@@ -17,2 +17,8 @@ const { fork } = require('child_process');

runOnCompilationStartedCommand() {
if (this.tsc) {
this.tsc.send('run-on-compilation-started-command');
}
}
runOnCompilationCompleteCommand() {

@@ -19,0 +25,0 @@ if (this.tsc) {

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

@@ -0,0 +0,0 @@ const spawn = require('cross-spawn');

@@ -10,3 +10,3 @@ const stripAnsi = require('strip-ansi');

const compilationCompleteRegex = /( Compilation complete\. Watching for file changes\.| Found \d+ error[s]?\. Watching for file changes\.)/;
const newCompilationRegex = /( Starting compilation in watch mode\.\.\.| File change detected\. Starting incremental compilation\.\.\.)/;
const compilationStartedRegex = /( Starting compilation in watch mode\.\.\.| File change detected\. Starting incremental compilation\.\.\.)/;

@@ -18,2 +18,3 @@ const newAdditionToSyntax = [

' --onFailure COMMAND Executes `COMMAND` on **every failed** compilation.',
' --onCompilationStarted COMMAND Executes `COMMAND` on **every compilation start** event.',
' --onCompilationComplete COMMAND Executes `COMMAND` on **every successful or failed** compilation.',

@@ -39,3 +40,3 @@ ' --noColors Removes the red/green colors from the compiler output',

if (noClear && newCompilationRegex.test(line)) {
if (noClear && compilationStartedRegex.test(line)) {
return '\n\n----------------------\n' + line;

@@ -65,3 +66,3 @@ }

const clearLine = stripAnsi(line);
const newCompilation = newCompilationRegex.test(clearLine);
const compilationStarted = compilationStartedRegex.test(clearLine);
const compilationError =

@@ -74,3 +75,3 @@ compilationCompleteWithErrorRegex.test(clearLine) ||

return {
newCompilation: newCompilation,
compilationStarted: compilationStarted,
compilationError: compilationError,

@@ -77,0 +78,0 @@ compilationComplete: compilationComplete,

@@ -15,2 +15,3 @@ #!/usr/bin/env node

let failureKiller = null;
let compilationStartedKiller = null;
let compilationCompleteKiller = null;

@@ -22,2 +23,3 @@

onFailureCommand,
onCompilationStarted,
onCompilationComplete,

@@ -35,2 +37,3 @@ noColors,

failureKiller ? failureKiller() : null,
compilationStartedKiller ? compilationStartedKiller() : null,
compilationCompleteKiller ? compilationCompleteKiller() : null,

@@ -40,2 +43,8 @@ ]);

function runOnCompilationStarted() {
if (onCompilationStarted) {
compilationStartedKiller = run(onCompilationStarted);
}
}
function runOnCompilationComplete() {

@@ -90,8 +99,15 @@ if (onCompilationComplete) {

const state = detectState(line);
const newCompilation = state.newCompilation;
const compilationStarted = state.compilationStarted;
const compilationError = state.compilationError;
const compilationComplete = state.compilationComplete;
compilationErrorSinceStart = (!newCompilation && compilationErrorSinceStart) || compilationError;
compilationErrorSinceStart = (!compilationStarted && compilationErrorSinceStart) || compilationError;
if (compilationStarted) {
killProcesses(false).then(() => {
runOnCompilationStarted();
Signal.emitStarted();
});
}
if (compilationComplete) {

@@ -123,5 +139,10 @@ killProcesses(false).then(() => {

switch (msg) {
case 'run-on-compilation-started-command':
promise = compilationStartedKiller ? compilationStartedKiller() : Promise.resolve();
func = runOnCompilationStarted;
break;
case 'run-on-compilation-complete-command':
promise = compilationCompleteKiller ? compilationCompleteKiller() : Promise.resolve();
func = runonCompilationComplete;
func = runOnCompilationComplete;
break;

@@ -155,3 +176,4 @@

const Signal = {
send: typeof process.send === 'function' ? (...e) => process.send(...e) : () => {},
send: typeof process.send === 'function' ? (...e) => process.send(...e) : () => { },
emitStarted: () => Signal.send('started'),
emitFirstSuccess: () => Signal.send('first_success'),

@@ -158,0 +180,0 @@ emitSuccess: () => Signal.send('success'),

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

@@ -9,3 +9,3 @@ "scripts": {

"bin": {
"tsc-watch": "./index.js"
"tsc-watch": "index.js"
},

@@ -12,0 +12,0 @@ "repository": {

@@ -13,2 +13,3 @@ [![Build Status](https://travis-ci.com/gilamran/tsc-watch.svg?branch=master)](https://travis-ci.com/gilamran/tsc-watch)

| `--onFailure COMMAND` | Executes `COMMAND` on **every failed** compilation. |
| `--onCompilationStarted COMMAND` | Executes `COMMAND` on **every compilation start** event (initial and incremental). |
| `--onCompilationComplete COMMAND` | Executes `COMMAND` on **every successful or failed** compilation. |

@@ -56,3 +57,3 @@ | `--noColors` | By default tsc-watch adds colors the output with green<br>on success, and in red on failure. <br>Add this argument to prevent that. |

### From javacript
### From javascript

@@ -63,2 +64,3 @@ You can see a detailed example [here](https://github.com/gilamran/tsc-watch/blob/master/tsc-watch-client-example.js)

- `started` - Emitted upon the compilation start (initial or incremental).
- `first_success` - Emitted upon first successful compilation.

@@ -78,2 +80,6 @@ - `subsequent_success` - Emitted upon every subsequent successful compilation.

watch.on('started', () => {
console.log('Compilation started');
});
watch.on('first_success', () => {

@@ -80,0 +86,0 @@ console.log('First success!');

@@ -0,0 +0,0 @@ const fs = require('fs');

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

it('Should remove custom args', () => {
const { args } = extractArgs(['node', 'tsc-watch.js', '--compiler', 'MY_COMPILER', '--nocolors', '--noclear', '--onsuccess', 'MY_SUCCESS', '--onfailure', 'MY_FAILURE', '--onfirstsuccess', 'MY_FIRST', '-d', '1.ts']);
const { args } = extractArgs(['node', 'tsc-watch.js', '--compiler', 'typescript/bin/tsc', '--nocolors', '--noclear', '--onsuccess', 'MY_SUCCESS', '--onfailure', 'MY_FAILURE', '--onfirstsuccess', 'MY_FIRST', '-d', '1.ts']);
expect(args).to.deep.eq(['-d', '1.ts', '--watch']);

@@ -48,2 +48,7 @@ });

it('Should return the onCompilationStarted', () => {
expect(extractArgs(['node', 'tsc-watch.js', '1.ts']).onCompilationStarted).to.eq(null);
expect(extractArgs(['node', 'tsc-watch.js', '--onCompilationStarted', 'COMMAND_TO_RUN', '1.ts']).onCompilationStarted).to.eq('COMMAND_TO_RUN');
});
it('Should return the onCompilationComplete', () => {

@@ -66,4 +71,4 @@ expect(extractArgs(['node', 'tsc-watch.js', '1.ts']).onCompilationComplete).to.eq(null);

expect(extractArgs(['node', 'tsc-watch.js', '1.ts']).compiler).to.eq('typescript/bin/tsc');
expect(extractArgs(['node', 'tsc-watch.js', '--compiler', 'MY_COMPILER', '1.ts']).compiler).to.eq('MY_COMPILER');
expect(extractArgs(['node', 'tsc-watch.js', '--compiler', 'typescript/lib/tsc', '1.ts']).compiler).to.eq(require.resolve('typescript/lib/tsc'));
});
});

@@ -18,2 +18,9 @@ const { expect } = require('chai');

describe('Events', () => {
it('Should emit "started" on compilation start', () => {
watchClient.on('started', callback);
watchClient.start('--noClear', '--out', './tmp/output.js', './tmp/fixtures/failing.ts');
return eventually(() => expect(callback.calledOnce).to.be.true);
});
it('Should emit "first_success" on first success', () => {

@@ -20,0 +27,0 @@ watchClient.on('first_success', callback);

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

@@ -0,0 +0,0 @@ const fse = require('fs-extra');

const { expect } = require('chai');
const runner = require('../lib/runner');
describe.only('Runner', () => {
describe('Runner', () => {
it('Should start a long running process and kill it before it finishes', (done) => {
const kill = runner('sleep 10')
setTimeout(function() {
kill().then(function(result) {
expect(result).to.deep.equal([0,null])
setTimeout(function () {
kill().then(function (result) {
expect(result).to.deep.equal([0, null])
done()

@@ -16,5 +16,5 @@ })

const kill = runner('echo')
setTimeout(function() {
kill().then(function(result) {
expect(result).to.deep.equal([1,0])
setTimeout(function () {
kill().then(function (result) {
expect(result).to.deep.equal([1, 0])
done()

@@ -21,0 +21,0 @@ })

@@ -12,2 +12,11 @@ const { expect } = require('chai');

it('Should send "started" on compilation start', () => {
driver
.subscribe('started', this.listener)
.startWatch()
.modifyAndSucceedAfter(1000);
return eventually(() => expect(this.listener.callCount).to.be.equal(1));
});
it('Should send "first_success" on first success', () => {

@@ -14,0 +23,0 @@ driver

@@ -5,2 +5,6 @@ const readline = require('readline');

client.on('started', () => {
console.log('Compilation started');
});
client.on('first_success', () => {

@@ -7,0 +11,0 @@ console.log('Interactive mode');

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc