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.33 to 1.1.34

lib/args-manager.js

48

lib/tsc-watch.js

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

const stringArgv = require('string-argv');
const { extractArgs } = require('./args-manager');

@@ -31,2 +32,4 @@ const compilationStartedRegex = /Starting incremental compilation/;

let { onFirstSuccessCommand, onSuccessCommand, onFailureCommand, noColors, noClear, compiler, args } = extractArgs(process.argv);
function color(line) {

@@ -52,23 +55,2 @@ if (typescriptErrorRegex.test(line)) {

function processArgs(inputArgs) {
const result = inputArgs
.splice(2)
.map(arg => arg.toLowerCase())
.filter(arg => arg !== '-w')
.filter(arg => arg !== '--watch')
.filter(arg => arg !== '--compiler')
.filter(arg => arg !== '--nocolors')
.filter(arg => arg !== '--noclear')
.filter(arg => arg !== '--onsuccess')
.filter(arg => arg !== '--onfailure')
.filter(arg => arg !== '--onfirstsuccess');
result.push('--watch'); // force watch
return result;
}
function getCommandIdx(inputArgs, command) {
return inputArgs.indexOf(command);
}
function runCommand(fullCommand) {

@@ -115,25 +97,2 @@ if (fullCommand) {

function getCustomeCommand(commandStr) {
const allArgs = process.argv;
let onCommandIdx = getCommandIdx(allArgs, commandStr);
let resultCommand = null;
if (onCommandIdx > -1) {
resultCommand = allArgs[onCommandIdx + 1];
allArgs.splice(onCommandIdx, 2);
}
return resultCommand;
}
const onFirstSuccessCommand = getCustomeCommand('--onFirstSuccess');
const onSuccessCommand = getCustomeCommand('--onSuccess');
const onFailureCommand = getCustomeCommand('--onFailure');
const noColors = getCommandIdx(process.argv, '--noColors') > -1;
const noClear = getCommandIdx(process.argv, '--noClear') > -1;
let compiler = getCustomeCommand('--compiler');
if (!compiler) {
compiler = 'typescript/bin/tsc';
}
const args = processArgs(process.argv);
let bin;

@@ -153,2 +112,3 @@ try {

}
const tscProcess = spawn(bin, [...args]);

@@ -155,0 +115,0 @@ tscProcess.stdout.on('data', buffer => {

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

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

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

beforeEach(() => this.callback = sinon.stub());
beforeEach(() => (this.callback = sinon.stub()));
afterEach(() => tscWatchClient.kill());

@@ -21,3 +21,3 @@

tscWatchClient.on('first_success', this.callback);
tscWatchClient.start('--out', './tmp/output.js', './tmp/fixtures/passing.ts');
tscWatchClient.start('--noClear', '--out', './tmp/output.js', './tmp/fixtures/passing.ts');

@@ -29,3 +29,3 @@ return eventually(() => expect(this.callback.calledOnce).to.be.true);

tscWatchClient.on('subsequent_success', this.callback);
tscWatchClient.start('--out', './tmp/output.js', './tmp/fixtures/passing.ts');
tscWatchClient.start('--noClear', '--out', './tmp/output.js', './tmp/fixtures/passing.ts');
tscWatchDriver.modifyAndSucceedAfter(1500);

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

tscWatchClient.on('compile_errors', this.callback);
tscWatchClient.start('--out', './tmp/output.js', './tmp/fixtures/failing.ts');
tscWatchClient.start('--noClear', '--out', './tmp/output.js', './tmp/fixtures/failing.ts');

@@ -41,0 +41,0 @@ return eventually(() => expect(this.callback.calledOnce).to.be.true);

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

constructor() {
this.subscriptions = new Map();
this.subscriptions = new Map();
}

@@ -19,4 +19,4 @@

startWatch({failFirst, pretty} = {}) {
const params = ['--out', './tmp/output.js', failFirst ? FAIL_FILE_PATH : SUCCESS_FILE_PATH];
startWatch({ failFirst, pretty } = {}) {
const params = ['--noClear', '--out', './tmp/output.js', failFirst ? FAIL_FILE_PATH : SUCCESS_FILE_PATH];
if (pretty) {

@@ -27,6 +27,3 @@ params.push('--pretty');

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

@@ -58,5 +55,5 @@ return this;

return new Promise(resolve => setTimeout(resolve, ms));
}
}
}
module.exports.driver = new Driver();

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

describe('TSC-Watch child process messages', () => {
beforeEach(() => this.listener = sinon.stub());
afterEach(() => driver.reset());
beforeEach(() => (this.listener = sinon.stub()));
afterEach(() => driver.reset());
it('Should send "first_success" on first success', () => {
driver
.subscribe('first_success', this.listener)
.startWatch();
it('Should send "first_success" on first success', () => {
driver.subscribe('first_success', this.listener).startWatch();
return eventually(() =>
expect(this.listener.callCount).to.be.equal(1));
});
return eventually(() => expect(this.listener.callCount).to.be.equal(1));
});
it('Should send "subsequent_success" on subsequent successes', () => {
driver
.subscribe('subsequent_success', this.listener)
.startWatch()
.modifyAndSucceedAfter(1000)
.modifyAndSucceedAfter(3000)
it('Should send "subsequent_success" on subsequent successes', () => {
driver
.subscribe('subsequent_success', this.listener)
.startWatch()
.modifyAndSucceedAfter(1000)
.modifyAndSucceedAfter(3000);
return eventually(() =>
expect(this.listener.callCount).to.be.equal(2));
});
return eventually(() => expect(this.listener.callCount).to.be.equal(2));
});
it('Should send "compile_errors" when tsc compile errors occur', () => {
driver
.subscribe('compile_errors', this.listener)
.startWatch({ failFirst: true })
.modifyAndFailAfter(1500);
it('Should send "compile_errors" when tsc compile errors occur', () => {
driver
.subscribe('compile_errors', this.listener)
.startWatch({ failFirst: true })
.modifyAndFailAfter(1500);
return eventually(() =>
expect(this.listener.callCount).to.be.equal(2));
});
return eventually(() => expect(this.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 });
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));
});
return eventually(() => expect(this.listener.callCount).to.be.equal(1));
});
});
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