tsc-watch
Advanced tools
Comparing version 6.1.0 to 6.2.0
@@ -14,2 +14,3 @@ /// <reference types="node" /> | ||
runOnSuccessCommand(): void; | ||
runOnEmitCommand(): void; | ||
} |
@@ -77,2 +77,7 @@ "use strict"; | ||
} | ||
runOnEmitCommand() { | ||
if (this.tsc) { | ||
this.tsc.send('run-on-emit-command'); | ||
} | ||
} | ||
} | ||
@@ -79,0 +84,0 @@ exports.TscWatchClient = TscWatchClient; |
@@ -47,2 +47,4 @@ "use strict"; | ||
const onFailureCommand = extractCommandWithValue(args, '--onFailure'); | ||
const onEmitCommand = extractCommandWithValue(args, '--onEmit'); | ||
const onEmitDebounceMs = Number(extractCommandWithValue(args, '--onEmitDebounceMs')) || 300; | ||
const onCompilationStarted = extractCommandWithValue(args, '--onCompilationStarted'); | ||
@@ -63,2 +65,11 @@ const onCompilationComplete = extractCommandWithValue(args, '--onCompilationComplete'); | ||
} | ||
if (signalEmittedFiles || requestedToListEmittedFiles) { | ||
if (args[0] === '--build' || args[0] === '-b') { | ||
// TS6369: Option '--build' must be the first command line argument. | ||
args.splice(1, 0, '--listEmittedFiles'); | ||
} | ||
else { | ||
args.unshift('--listEmittedFiles'); | ||
} | ||
} | ||
return { | ||
@@ -68,2 +79,4 @@ onFirstSuccessCommand, | ||
onFailureCommand, | ||
onEmitCommand, | ||
onEmitDebounceMs, | ||
onCompilationStarted, | ||
@@ -70,0 +83,0 @@ onCompilationComplete, |
@@ -19,2 +19,4 @@ "use strict"; | ||
' --onFailure COMMAND Executes `COMMAND` on **every failed** compilation.', | ||
' --onEmit COMMAND Executes debounced `COMMAND` on **every emitted file**, ignoring unchanged files and disregards compilation success or failure.', | ||
' --onEmitDebounceMs DELAY Delay by which to debounce `--onEmit` (default: 300).', | ||
' --onCompilationStarted COMMAND Executes `COMMAND` on **every compilation start** event.', | ||
@@ -21,0 +23,0 @@ ' --onCompilationComplete COMMAND Executes `COMMAND` on **every successful or failed** compilation.', |
@@ -34,2 +34,3 @@ #!/usr/bin/env node | ||
const args_manager_1 = require("./args-manager"); | ||
const debounce_1 = require("./debounce"); | ||
const stdout_manipulator_1 = require("./stdout-manipulator"); | ||
@@ -41,5 +42,6 @@ const readline_1 = require("readline"); | ||
let failureKiller = null; | ||
let emitKiller = null; | ||
let compilationStartedKiller = null; | ||
let compilationCompleteKiller = null; | ||
const { onFirstSuccessCommand, onSuccessCommand, onFailureCommand, onCompilationStarted, onCompilationComplete, maxNodeMem, noColors, noClear, requestedToListEmittedFiles, signalEmittedFiles, silent, compiler, args, } = (0, args_manager_1.extractArgs)(process.argv); | ||
const { onFirstSuccessCommand, onSuccessCommand, onFailureCommand, onEmitCommand, onEmitDebounceMs, onCompilationStarted, onCompilationComplete, maxNodeMem, noColors, noClear, requestedToListEmittedFiles, signalEmittedFiles, silent, compiler, args, } = (0, args_manager_1.extractArgs)(process.argv); | ||
let runningKillProcessesPromise = null; | ||
@@ -77,2 +79,19 @@ function killProcesses(currentCompilationId, killAll) { | ||
} | ||
let runningKillEmitProcessesPromise = null; | ||
// The same as `killProcesses`, but we separate it to avoid canceling each other | ||
function killEmitProcesses(currentEmitId) { | ||
if (runningKillEmitProcessesPromise) { | ||
return runningKillEmitProcessesPromise.then(() => currentEmitId); | ||
} | ||
let emitKilled = Promise.resolve(); | ||
if (emitKiller) { | ||
emitKilled = emitKiller(); | ||
emitKiller = null; | ||
} | ||
runningKillEmitProcessesPromise = emitKilled.then(() => { | ||
runningKillEmitProcessesPromise = null; | ||
return currentEmitId; | ||
}); | ||
return runningKillEmitProcessesPromise; | ||
} | ||
function runOnCompilationStarted() { | ||
@@ -103,2 +122,8 @@ if (onCompilationStarted) { | ||
} | ||
const debouncedEmit = onEmitCommand | ||
? (0, debounce_1.debounce)(() => { emitKiller = (0, runner_1.run)(onEmitCommand); }, onEmitDebounceMs) | ||
: undefined; | ||
function runOnEmitCommand() { | ||
debouncedEmit === null || debouncedEmit === void 0 ? void 0 : debouncedEmit(); | ||
} | ||
function getTscPath() { | ||
@@ -122,3 +147,2 @@ let tscBin; | ||
tscBin, | ||
...((signalEmittedFiles || requestedToListEmittedFiles) ? ['--listEmittedFiles'] : []), | ||
...args | ||
@@ -145,2 +169,8 @@ ]; | ||
let compilationId = 0; | ||
let emitId = 0; | ||
function triggerOnEmit() { | ||
if (onEmitCommand) { | ||
killEmitProcesses(++emitId).then((previousEmitId) => previousEmitId === emitId && runOnEmitCommand()); | ||
} | ||
} | ||
rl.on('line', function (input) { | ||
@@ -162,2 +192,3 @@ if (noClear) { | ||
Signal.emitFile(state.fileEmitted); | ||
triggerOnEmit(); | ||
} | ||
@@ -190,2 +221,3 @@ if (compilationStarted) { | ||
runOnFirstSuccessCommand(); | ||
triggerOnEmit(); | ||
} | ||
@@ -226,2 +258,7 @@ Signal.emitSuccess(); | ||
break; | ||
case 'run-on-emit-command': | ||
if (emitKiller) { | ||
emitKiller().then(runOnEmitCommand); | ||
} | ||
break; | ||
default: | ||
@@ -228,0 +265,0 @@ console.log('Unknown message', msg); |
{ | ||
"name": "tsc-watch", | ||
"version": "6.1.0", | ||
"version": "6.2.0", | ||
"description": "The TypeScript compiler with onSuccess command", | ||
"scripts": { | ||
"clean": "rimraf dist && rimraf tmp", | ||
"prepublish": "crlf --set=LF index.js client.js dist/**/*", | ||
"prepublishOnly": "npm run build && crlf --set=LF index.js client.js dist/**/*", | ||
"test": "npm run build && jest --verbose --runInBand", | ||
@@ -9,0 +9,0 @@ "build": "npm run clean && npm run build-lib && npm run build-client", |
34850
17
649