Skip to content

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

Closed

Description

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.

Activity

  1. added
    Needs Investigation
    on Jul 26, 2019
  2. sheetalkamat commented on Aug 14, 2019

    @sheetalkamat
    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;
  3. added
    Domain: API
    and removed
    Needs Investigation
    on Aug 14, 2019
  4. fr3shw3b commented on Aug 26, 2019

    @fr3shw3b
    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.

  5. fr3shw3b commented on Aug 27, 2019

    @fr3shw3b
    Contributor

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

  6. okep commented on Sep 19, 2019

    @okep

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

  7. orta commented on Sep 19, 2019

    @orta
    Contributor

    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

Metadata

Metadata

Labels

Domain: API

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions