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

Watch-run doesn't update correctly #1082

Closed
Zn4rK opened this issue Apr 7, 2020 · 0 comments · Fixed by #1083
Closed

Watch-run doesn't update correctly #1082

Zn4rK opened this issue Apr 7, 2020 · 0 comments · Fixed by #1083

Comments

@Zn4rK
Copy link
Contributor

Zn4rK commented Apr 7, 2020

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.

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

Successfully merging a pull request may close this issue.

1 participant