Socket
Socket
Sign inDemoInstall

tsc-watch

Package Overview
Dependencies
5
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.6.0 to 4.6.1

3

CHANGELOG.md
# @gilamran/tsc-watch CHANGELOG
## v4.6.1 - 10/3/2022
- Add --maxNodeMem param to tweak node tsc allocated memory - (Thanks to @pp0rtal for the idea and the PR!)
## v4.6.0 - 20/12/2021

@@ -4,0 +7,0 @@

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

const onCompilationComplete = extractCommandWithValue(allArgs, '--onCompilationComplete');
const maxNodeMem = extractCommandWithValue(allArgs, '--maxNodeMem');
const noColors = extractCommand(allArgs, '--noColors');

@@ -70,2 +71,3 @@ const noClear = extractCommand(allArgs, '--noClear');

onCompilationComplete: onCompilationComplete,
maxNodeMem: maxNodeMem,
noColors: noColors,

@@ -72,0 +74,0 @@ noClear: noClear,

27

lib/tsc-watch.js

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

onCompilationComplete,
maxNodeMem,
noColors,

@@ -72,15 +73,23 @@ noClear,

let bin;
try {
bin = require.resolve(compiler);
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
console.error(e.message);
process.exit(9);
function buildNodeParams(allArgs, { maxNodeMem }){
let tscBin;
try {
tscBin = require.resolve(compiler);
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
console.error(e.message);
process.exit(9);
}
throw e;
}
throw e;
return [
...((maxNodeMem) ? [`--max_old_space_size=${maxNodeMem}`] : []),
tscBin,
...allArgs,
];
}
let compilationErrorSinceStart = false;
const tscProcess = spawn('node', [bin, ...args]);
const tscProcess = spawn('node', buildNodeParams(args, { maxNodeMem }));
const rl = readline.createInterface({

@@ -87,0 +96,0 @@ input: tscProcess.stdout,

{
"name": "tsc-watch",
"version": "4.6.0",
"version": "4.6.1",
"description": "The TypeScript compiler with onSuccess command",
"scripts": {
"test": "mocha test/**/*.js"
"test": "mocha --timeout 10000 test/**/*.js"
},

@@ -45,9 +45,8 @@ "bin": {

"devDependencies": {
"chai": "^4.2.0",
"fs-extra": "^8.1.0",
"mocha": "^7.1.2",
"mocha-eventually": "^1.1.0",
"sinon": "^9.0.2",
"typescript": "^3.3.3"
"chai": "^4.3.4",
"fs-extra": "^10.0.0",
"mocha": "^9.1.3",
"sinon": "^12.0.1",
"typescript": "^4.5.4"
}
}

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

| `--onCompilationComplete COMMAND` | Executes `COMMAND` on **every successful or failed** compilation. |
| `--maxNodeMem` | Call `node` with a specific memory limit `max_old_space_size`, to use if your project needs more memory. |
| `--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. |

@@ -35,2 +36,7 @@ | `--noClear` | In watch mode the `tsc` compiler clears the screen before reporting<br>Add this argument to prevent that. |

```sh
## for command-line usage
npm install -g typescript tsc-watch
```
## Usage

@@ -37,0 +43,0 @@

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

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

@@ -67,3 +72,3 @@ expect(extractArgs(['node', 'tsc-watch.js', '1.ts']).noColors).to.eq(false);

});
it('Should return the silent', () => {

@@ -70,0 +75,0 @@ expect(extractArgs(['node', 'tsc-watch.js', '1.ts']).silent).to.eq(false);

const { expect } = require('chai');
const sinon = require('sinon');
const mochaEventually = require('mocha-eventually');
const eventually = fn => mochaEventually(fn, 8000, 50);
const TscWatchClient = require('../lib/client');
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
describe('Client Events', () => {

@@ -18,30 +18,34 @@ let watchClient;

describe('Events', () => {
it('Should emit "started" on compilation start', () => {
it('Should emit "started" on compilation start', async () => {
watchClient.on('started', callback);
watchClient.start('--noClear', '--out', './tmp/output.js', './tmp/fixtures/failing.ts');
await wait(2000)
return eventually(() => expect(callback.calledOnce).to.be.true);
expect(callback.calledOnce).to.be.true;
});
it('Should emit "first_success" on first success', () => {
it('Should emit "first_success" on first success', async () => {
watchClient.on('first_success', callback);
watchClient.start('--noClear', '--out', './tmp/output.js', './tmp/fixtures/passing.ts');
await wait(2000)
return eventually(() => expect(callback.calledOnce).to.be.true);
expect(callback.calledOnce).to.be.true;
});
it('Should emit "success" on first success', () => {
it('Should emit "success" on first success', async () => {
watchClient.on('success', callback);
watchClient.start('--noClear', '--out', './tmp/output.js', './tmp/fixtures/passing.ts');
await wait(2000)
return eventually(() => expect(callback.calledOnce).to.be.true);
expect(callback.calledOnce).to.be.true;
});
it('Should fire "compile_errors" on when tsc compile errors occur', () => {
it('Should fire "compile_errors" on when tsc compile errors occur', async () => {
watchClient.on('compile_errors', callback);
watchClient.start('--noClear', '--out', './tmp/output.js', './tmp/fixtures/failing.ts');
await wait(2000)
return eventually(() => expect(callback.calledOnce).to.be.true);
expect(callback.calledOnce).to.be.true;
});
});
});

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

}
this.proc = fork('./lib/tsc-watch.js', params, { stdio: 'ignore' });
this.proc = fork('./lib/tsc-watch.js', params, { stdio: 'inherit' });

@@ -32,3 +32,3 @@ this.subscriptions.forEach((handler, evName) => this.proc.on('message', event => (evName === event ? handler(event) : noop())));

modifyAndSucceedAfter(timeToWait = 0, isFailingPath) {
this._wait(timeToWait).then(() => fs.appendFileSync(SUCCESS_FILE_PATH, ' '));
this.wait(timeToWait).then(() => fs.appendFileSync(SUCCESS_FILE_PATH, '\n '));
return this;

@@ -38,3 +38,3 @@ }

modifyAndFailAfter(timeToWait = 0) {
this._wait(timeToWait).then(() => fs.appendFileSync(FAIL_FILE_PATH, '{{{'));
this.wait(timeToWait).then(() => fs.appendFileSync(FAIL_FILE_PATH, '{{{'));
return this;

@@ -53,3 +53,3 @@ }

_wait(ms) {
wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));

@@ -56,0 +56,0 @@ }

const { expect } = require('chai');
const sinon = require('sinon');
const mochaEventually = require('mocha-eventually');
const { driver } = require('./driver');
const eventually = fn => mochaEventually(fn, 8000, 10);
describe('TSC-Watch child process messages', () => {
beforeEach(() => (this.listener = sinon.stub()));
afterEach(() => driver.reset());
it('Should send "started" on compilation start', () => {
driver
.subscribe('started', this.listener)
.startWatch()
.modifyAndSucceedAfter(1000);
it('Should send "started" on compilation start', async () => {
const listener = sinon.stub();
driver.subscribe('started', listener).startWatch().modifyAndSucceedAfter(1000);
await driver.wait(4000);
return eventually(() => expect(this.listener.callCount).to.be.equal(1));
expect(listener.callCount).to.be.equal(2);
});
it('Should send "first_success" on first success', () => {
driver
.subscribe('first_success', this.listener)
.startWatch()
.modifyAndSucceedAfter(1000);
return eventually(() => expect(this.listener.callCount).to.be.equal(1));
it('Should send "first_success" on first success', async () => {
const listener = sinon.stub();
driver.subscribe('first_success', listener).startWatch().modifyAndSucceedAfter(1000);
await driver.wait(3000);
expect(listener.callCount).to.be.equal(1);
});
it('Should send "success" on subsequent successes', () => {
driver
.subscribe('success', this.listener)
.startWatch()
.modifyAndSucceedAfter(1000);
return eventually(() => expect(this.listener.callCount).to.be.equal(2));
it('Should send "success" on subsequent successes', async () => {
const listener = sinon.stub();
driver.subscribe('success', listener).startWatch().modifyAndSucceedAfter(1000);
await driver.wait(3000);
expect(listener.callCount).to.be.equal(2);
});
it('Should send "compile_errors" when tsc compile errors occur', () => {
it('Should send "compile_errors" when tsc compile errors occur', async () => {
const listener = sinon.stub();
driver
.subscribe('compile_errors', this.listener)
.subscribe('compile_errors', listener)
.startWatch({ failFirst: true })
.modifyAndFailAfter(1500);
return eventually(() => expect(this.listener.callCount).to.be.equal(2));
await driver.wait(3000);
expect(listener.callCount).to.be.equal(2);
});
it('Should send "compile_errors" when pretty param was set', () => {
driver.subscribe('compile_errors', this.listener).startWatch({ failFirst: true, pretty: true });
return eventually(() => expect(this.listener.callCount).to.be.equal(1));
it('Should send "compile_errors" when pretty param was set', async () => {
const listener = sinon.stub();
driver.subscribe('compile_errors', listener).startWatch({ failFirst: true, pretty: true });
await driver.wait(3000);
expect(listener.callCount).to.be.equal(1);
});
});
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