Skip to content

Watch-run doesn't update correctly #1082

@Zn4rK

Description

@Zn4rK

This issue is born from cevek/ttypescript#86. This comment in particular describes the problem a bit better: cevek/ttypescript#86 (comment)

It's not caused by some internal order that I wrote there.

Expected Behaviour

I expect that files that I've changed is updated correctly.

Steps to Reproduce the Problem

I've not managed to reliably reproduce this with the testing strategy that ts-loader uses.

Location of a Minimal Repository that Demonstrates the Issue.

Clone https://github.com/Zn4rK/ttypescript-repro

Run npm run start:webpack


So, this is a strange one. I've spent some time trying to understand what's happening.

Looking at the source for watch-run:

date > (lastTimes.get(filePath) || startTime) &&
filePath.match(constants.tsTsxJsJsxRegex) !== null

It basically says: If date is more than the lastTime AND filePath is a tsTsxJsJsx file, skip.

For modified files, date will always be more than the last time.

Looking at one of the tests that fails if I change the if-statement, I would argue that the current result is wrong.

If I understand the test suite correctly, we should see something along the lines of:

TS2322: Type '"foobar"' is not assignable to type 'boolean'.

In patch1/output.txt but right now that doesn't happen. There is no expected outputs for either patch0 or patch1.

There are a few more tests that has inconsistent results with what I would assume should be happening.

My suggestion is simply to change the first for-loop to:

    for (const [filePath, date] of times) {
      const lastTime = lastTimes.get(filePath) || startTime;

      if (date <= lastTime) {
        continue;
      }

      lastTimes.set(filePath, date);
      updateFile(instance, filePath);
    }

Which seems to fix my original issue, and get the expected test results for (some of) the existing tests as well. I don't really understand how the comparison tests works with the _WatchAPI syntax.

I've removed the match for tsTsxJsJsx files completely, because I don't think that the check was intentional.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions