Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable tscTask promise interaction so it can fail gracefully #720

Open
zachbryant opened this issue Jun 21, 2023 · 0 comments
Open

Comments

@zachbryant
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant