microsoft / microsoft/just

feat: enable tscTask promise interaction so it can fail gracefully

Open
#720 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2k
Forks
97
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating tscTask and the exec implementation, then trace how rejected promises are handled by task execution. Compare this with the requested callback interaction and the watcher use case. Done means a TypeScript compiler failure can be handled without preventing the following watcher step, with behavior covered by the project's relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.