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

createWatchCompilerHost watch status Diagnostic code success/failure is indiscernible #32542

Closed
casieber opened this issue Jul 24, 2019 · 5 comments · Fixed by #33082
Closed
Assignees
Labels
API Relates to the public API for TypeScript Good First Issue Well scoped, documented and has the green light Help Wanted You can do this

Comments

@casieber
Copy link

TypeScript Version: 3.6.0-dev.20190724

Search Terms:
Compiler API, createWatchCompilerHost, watch Diagnostic

Code

const host = ts.createWatchCompilerHost(
    'C://path/to/my/tsconfig.json',
    {},
    ts.sys,
    ts.createEmitAndSemanticDiagnosticsBuilderProgram,
    () => {},
    handleWatchStatusChanged,
);

function handleWatchStatusChanged( diagnostic: Diagnostic )
{
    switch ( diagnostic.code )
    {
        case 6031:    // Initial build
        case 6032:    // Incremental build
            console.log( 'Building...' );
        case 6193:    // 1 Error
            console.log( 'Build Failure. There was 1 error while building.' );
        case 6194:    // 0 errors or 2+ errors
            console.log( 'Maybe success?' );
}

Expected behavior:
The watch status changed diagnostic.code would differentiate between a successful build and a build with errors.

Actual behavior:
Currently diagnostic.code can differentiate between:

  • There was one single error with the build.
  • There were either no errors or more than one error.

It looks like this code in watch.ts is where the explict errorCount === 1 check happens.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jul 26, 2019
@sheetalkamat
Copy link
Member

I think we could add another parameter to this to pass errorCount instead of changing diagnostics. PRs welcome for the change.

export type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount: number) => void;

@sheetalkamat sheetalkamat added API Relates to the public API for TypeScript Good First Issue Well scoped, documented and has the green light Help Wanted You can do this and removed Needs Investigation This issue needs a team member to investigate its status. labels Aug 14, 2019
@sheetalkamat sheetalkamat added this to the TypeScript 3.7.0 milestone Aug 14, 2019
@fr3shw3b
Copy link
Contributor

I have made an attempt at addressing this as my first contribution to the project. The pull request is #33082
I think I do however need some guidance on unit testing functionality in the watch component.

@fr3shw3b
Copy link
Contributor

I've added the unit test in the latest commit in the pull request

@okep
Copy link

okep commented Sep 19, 2019

When this is going to be released? I have to parse the message at the moment :(

@orta
Copy link
Contributor

orta commented Sep 19, 2019

You could use a nightly build (see in the NPM releases) or wait till #33352 is shipped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript Good First Issue Well scoped, documented and has the green light Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants