feat: enable tscTask promise interaction so it can fail gracefully
zachbryant opened this issue · 0 comments
zachbryant commented
Hi there, I recently tried to fix an issue in my watcher task but found it's not possible with the current setup.
My watcher task starts by compiling with Just's tscTask
, then to our own watcher function. If the typescript compiler encounters an error then ideally the task would move onto the watcher step. As it is right now, the uncaught error stops the task. There's no way to interact with the promise returned by exec
. I would love to be able to pass in Promise callbacks or something similar as below:
export function tscTask(options: TscTaskOptions = {}, execCallbacks): TaskFunction {
const tscCmd = resolve('typescript/lib/tsc.js');
const { thenCallback, catchFallback, finallyCallback } = execCallbacks;
if (!tscCmd) {
throw new Error('cannot find tsc');
}
return function tsc() {
// Read from options argument, if not there try the tsConfigFile found in root, if not then skip and use no config
options = { ...options, ...getProjectOrBuildOptions(options) };
if (isValidProject(options)) {
logger.info(`Running ${tscCmd} with ${options.project || options.build}`);
const args = argsFromOptions(tscCmd, options);
const cmd = encodeArgs([process.execPath, ...args]).join(' ');
logger.info(`Executing: ${cmd}`);
return exec(cmd).then(thenCallback).catch(catchCallback).finally(finallyCallback);
}
return Promise.resolve();
};
}
Specific implementation doesn't matter too much, but it would be very nice to delete the copy of tscTask
and supporting methods I brought into my repo