Comparing version 4.6.1 to 4.6.2
# @gilamran/tsc-watch CHANGELOG | ||
## v4.6.2 - 10/01/2022 | ||
- Added `file_emitted` signal support when `--listEmittedFiles` is used [issue](https://github.com/gilamran/tsc-watch/issues/138) | ||
- Added client new event `file_emitted` with the emitted file path | ||
## v4.6.1 - 10/3/2022 | ||
- Add --maxNodeMem param to tweak node tsc allocated memory - (Thanks to @pp0rtal for the idea and the PR!) | ||
- Added `--maxNodeMem` param to set manually node allocated memory [issue](https://github.com/gilamran/tsc-watch/issues/137) - (Thanks to @pp0rtal for the idea and the PR!) | ||
## v4.6.0 - 20/12/2021 | ||
@@ -7,0 +13,0 @@ |
@@ -1,2 +0,2 @@ | ||
const { fork } = require('child_process'); | ||
const child_process = require('child_process'); | ||
const EventEmitter = require('events'); | ||
@@ -6,4 +6,5 @@ | ||
start(...args) { | ||
this.tsc = fork(require.resolve('./tsc-watch.js'), args, { stdio: 'inherit' }); | ||
this.tsc.on('message', (msg) => this.emit(msg)); | ||
this.tsc = child_process.fork(require.resolve('./tsc-watch.js'), args, { stdio: 'inherit' }); | ||
this.tsc.on('message', (msg) => this.emit(...deserializeTscMessage(msg))); | ||
this.tsc.on('exit', (code, signal) => this.emit('exit', code, signal)); | ||
} | ||
@@ -49,2 +50,11 @@ | ||
function deserializeTscMessage(strMsg){ | ||
const indexOfSeparator = strMsg.indexOf(':'); | ||
if(indexOfSeparator === -1){ | ||
return [strMsg]; | ||
} | ||
return [strMsg.substring(0, indexOfSeparator), strMsg.substring(indexOfSeparator + 1)] | ||
} | ||
module.exports = TscWatchClient; |
@@ -6,2 +6,3 @@ const stripAnsi = require('strip-ansi'); | ||
const typescriptErrorRegex = /\(\d+,\d+\): error TS\d+: /; | ||
const typescriptEmittedFileRegex = /(TSFILE:)\s*(.*)/; | ||
@@ -39,2 +40,5 @@ const compilationCompleteWithErrorRegex = / Found [^0][0-9]* error[s]?\. Watching for file changes\./; | ||
// file emitted | ||
line = line.replace(typescriptEmittedFileRegex, (_0, stdPrefix, file) => `\u001B[30m\u001B[4m${stdPrefix}\u001B[0m \u001B[30m${file}\u001B[0m`); // Grey underlined / Grey | ||
if (noClear && compilationStartedRegex.test(line)) { | ||
@@ -71,2 +75,4 @@ return '\n\n----------------------\n' + line; | ||
const compilationComplete = compilationCompleteRegex.test(clearLine); | ||
const fileEmittedExec = typescriptEmittedFileRegex.exec(clearLine); | ||
const fileEmitted = fileEmittedExec !== null ? fileEmittedExec[2] : null; // if the regex is not null it will return an array with 3 elements | ||
@@ -77,2 +83,3 @@ return { | ||
compilationComplete: compilationComplete, | ||
fileEmitted: fileEmitted, | ||
}; | ||
@@ -79,0 +86,0 @@ } |
@@ -113,2 +113,6 @@ #!/usr/bin/env node | ||
if (state.fileEmitted !== null){ | ||
Signal.emitFile(state.fileEmitted); | ||
} | ||
if (compilationStarted) { | ||
@@ -188,2 +192,3 @@ killProcesses(false).then(() => { | ||
emitFail: () => Signal.send('compile_errors'), | ||
emitFile: (path) => Signal.send(`file_emitted:${path}`), | ||
}; | ||
@@ -190,0 +195,0 @@ |
{ | ||
"name": "tsc-watch", | ||
"version": "4.6.1", | ||
"version": "4.6.2", | ||
"description": "The TypeScript compiler with onSuccess command", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -15,3 +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. | | ||
| `--maxNodeMem` | Calls `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. | | ||
@@ -74,2 +74,3 @@ | `--noClear` | In watch mode the `tsc` compiler clears the screen before reporting<br>Add this argument to prevent that. | | ||
- `compile_errors` - Emitted upon every failing compilation. | ||
- `file_emitted` - Emitted upon every file transpiled if `--listEmittedFiles` is used. | ||
@@ -76,0 +77,0 @@ Once subscribed to the relevant events, start the client by running `watch.start()` |
@@ -0,1 +1,2 @@ | ||
const child_process = require('child_process'); | ||
const { expect } = require('chai'); | ||
@@ -10,2 +11,3 @@ const sinon = require('sinon'); | ||
let callback; | ||
let sandbox; | ||
@@ -15,4 +17,8 @@ beforeEach(() => { | ||
callback = sinon.stub(); | ||
sandbox = sinon.createSandbox(); | ||
}); | ||
afterEach(() => watchClient.kill()); | ||
afterEach(() => { | ||
watchClient.kill(); | ||
sandbox.restore(); | ||
}); | ||
@@ -44,2 +50,12 @@ describe('Events', () => { | ||
it('Should deserialize and emit a "file_emitted" with the emitted file path', async function () { | ||
const forkSpy = sandbox.spy(child_process, 'fork'); | ||
watchClient.on('file_emitted', callback); | ||
watchClient.start('--noClear', '--out', './tmp/output.js', './tmp/fixtures/passing.ts'); | ||
const [ tscProcess ] = forkSpy.returnValues; | ||
tscProcess.emit('message', 'file_emitted:/dist/tmp/fixtures/passing.js') | ||
expect(callback.args).to.deep.equal([[ '/dist/tmp/fixtures/passing.js' ]]); | ||
}); | ||
it('Should fire "compile_errors" on when tsc compile errors occur', async () => { | ||
@@ -46,0 +62,0 @@ watchClient.on('compile_errors', callback); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41876
27
778
115
5