-
Notifications
You must be signed in to change notification settings - Fork 71
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
fix: type-check include
d files missed by transform
(type-only files)
#345
fix: type-check include
d files missed by transform
(type-only files)
#345
Conversation
aeb11a7
to
be34970
Compare
I think the main reason walkTree was in If it works in If you run in watch mode and break / fix / break / fix various files you would see if this behaves as expected. This applies to return code as well, ideally error caught at that stage behaves like error caught at transpile stage regarding rollup behavior and return code. For example with |
OOOHHHH... that makes so much more sense. It looked like a workaround for Confirmed in the Rollup changelog that I think some of the other legacy checks like I'll change those in separate PRs though, will keep this one independent and limited in its scope (as I usually do 🙂 )
Let me double-check this, but it should behave like that according to the Rollup spec.
Oh, is this meant as a workaround for watch mode clearing the terminal by default on a new cycle?
So I didn't go into this into that much detail in "Review Notes", but the type-errors here seem to never return So I could change That's some weird divergent behavior, so I'm not sure which is optimal. But I can do either, just want to call out those trade-offs explicitly because this is unique to these files.
Kinda unrelated, but this has popped up in the issues pretty often since TS defaults to |
Yep, The only problem I discovered during watch mode is that some errors can get printed twice 😕 . That's because the new So I'm gonna have to switch the ordering here. Which means I might as well move |
Ah, So I need to add a check for the error case and not |
Ok, turns out this isn't entirely correct. I thought my understanding of this was a bit off. Since But in this portion of code (both the new code I added and the existing I actually have been wondering about why one of the few remaining missing pieces in my current understanding of the codebase |
Completed moving
Handled the error case as well now. Because the error case is handled here now, I also moved Can read the commit messages for more details
So this is the only portion left remaining for this PR, that I'm actually not sure of myself (as it is historical, as far as I know), so could still use some input on this to finish up this PR |
The only reason So yeah, just using |
Yea, that's what I thought, but looking at it currently, I'm pretty sure
So I believe
Yea that was a central difference, but at least in
Yea with But, per above, I don't think those differences are ever meaningful either. So I'm pretty confident now that But if agreed, I'll remove it in a separate PR. For here, I'll just use |
Ah, nevermind, it looks like
|
I think some other PRs I merged today broke this one |
Yea #373 was expected to conflict with this one (as I noted there) due to both using I also still need to make that |
- type-only files never get processed by Rollup as their imports are elided/removed by TS in the resulting compiled JS file - so, as a workaround, make sure that all files in the `tsconfig` `include` (i.e. in `parsedConfig.fileNames`) are also type-checked - note that this will not catch _all_ type-only imports, in particular if one is using `tsconfig` `files` (or in general _not_ using glob patterns in `include`) -- this is just a workaround, that requires a separate fix - we do the same process for generating declarations for "missed" files right now in `_onwrite`, so basically do the same thing but for type-checking in `_ongenerate` (_technically_ speaking, there could be full TS files (i.e. _not_ type-only) that are in the `include` and weren't transformed - these would basically be independent TS files not part of the bundle that the user wanted type-checking and declarations for (as we _already_ generate declarations for those files))
- `buildEnd` is a more correct place for it, since this does not generate any output files - (unlike the missed declarations) - and this means it's only called once per build, vs. once per output - remove the check against the `declarations` dict as one can type-check without outputting declarations - i.e. if `declaration: false`; not the most common use-case for rpt2, but it is one
- since `parsedConfig.fileNames` could include files that were already checked during the `transform` hook - and because `declarations` dict is empty when `declaration: false`, so can't check against that
- because printing diagnostics can bail if the category was error - that can result in a file being type-checked but not added to checkedFiles
…rateBundle - per ezolenko, the whole generateRound etc stuff was a workaround because the buildEnd hook actually _didn't exist_ before - so now that it does, we can use it to simplify some logic - no longer need `_ongenerate` as that should be in `buildEnd`, and no longer need `_onwrite` as it is the only thing called in `generateBundle`, so just combine them - importantly, `buildEnd` also occurs before output generation, so this ensures that type-checking still occurs even if `bundle.generate()` is not called - also move the `walkTree` call to above the "missed" type-checking as it needs to come first - it does unconditional type-checking once per watch cycle, whereas "missed" only type-checks those that were, well, "missed" - so in order to not have duplication, make "missed" come after, when the `checkedFiles` Set has been filled by `walkTree` already - and for simplification, just return early on error to match the current behavior - in the future, may want to print the error and continue type-checking other files - so that all type-check errors are reported, not just the first one NOTE: this is WIP because the `cache.done()` call and the `!noErrors` message are incorrectly blocked behind the `pluginOptions.check` conditional right now - `cache.done()` needs to be called regardless of check or error or not, i.e. in all scenarios - but ideally it should be called after all the type-checking here - `!noErrors` should be logged regardless of check or not - and similarly, after the type-checking
- instead of making a big `if` statement, decided to split out a `buildDone` function - to always call at the end of the input phase - we can also move the `cache().done()` in `emitSkipped` into `buildEnd`, as `buildEnd` gets called when an error occurs as well - and this way we properly print for errors as well - `buildDone` will have more usage in other PRs as well, so I figure it makes sense to split it out now as well
- i.e. bail out when `abortOnError: true`, which `ConsoleContext` can't do - `ConsoleContext` is basically meant for everywhere `RollupContext` can't be used - which is effectively only in the `options` hook, per the Rollup docs: https://rollupjs.org/guide/en/#options
49b26f4
to
3a027ca
Compare
- now that the integration tests exist, we can actually test this scenario - refactor: give each test their own `onwarn` mock when necessary - while `restoreMocks` is set in the `jest.config.js`, Jest apparently has poor isolation of mocks: jestjs/jest#7136 - if two tests ran in parallel, `onwarn` was getting results from both, screwing up the `toBeCalledTimes` number - couldn't get the syntax error to work with `toBeCalledTimes` either - if no mock is given, it _does_ print warnings, but if a mock is given, it doesn't print, yet isn't called? - I think the mock is getting screwed up by the error being thrown here; maybe improperly saved or something
@ezolenko I think this PR is ready to go now. I fixed the merge conflict, used CI is currently failing due to #377, not the code from this PR. Also happened to stumble upon yet another bug (or two?) in an upstream codebase with this test: jestjs/jest#7136 roughly describes it, but basically mocks have poor isolation. Was able to workaround that one with a small refactor. Couldn't workaround another one, that mocks seem to lose state if an error is hit; see my commit message for more details. Unrelated, but @ezolenko can you give a 👍 / 👎 on the proposal in #228? Have a contributor waiting for approval from you before tackling. (for reference, the proposal is mine, the contributor was going to implement it). |
Somehow didn't think of that till now, but that should obviate the need for |
Summary
Type-check some type-only files that were missed in the
transform
hook but are inparsedConfig.fileNames
include
globs)failed to transpile
error --noEmitOnError: true
breaks rpt2 #254 (which usesinclude
globs)tsconfig
#211, but does not truly/completely fix it as it usesfiles
(see details below)Details
tsconfig
include
(i.e. inparsedConfig.fileNames
) are also type-checkedtsconfig
files
as in Declarations not generated for type-only files not explicitly specified intsconfig
#211 (or in general not using glob patterns ininclude
) -- this is just a workaround, that requires a separate fix_onwrite
, so basically do the same thing but for type-checking inEDIT: moved to_ongenerate
buildEnd
(see below)(Note: Technically speaking, there could be full TS files (i.e. not type-only) that are in the
include
and weren't transformed. These would basically be independent TS files not part of the bundle that the user wanted type-checking and declarations for (as we already generate declarations for those files))For more details, see my root cause analysis in #298 (comment)
Review Notes
This is built on top of refactor: split out a commontypecheckFile
func #344, please merge that first. Marked this as a draft for nowI'm using the.declarations
dict as a way to detect if a file has already run through thetransform
so as not to duplicate type-checking (both for performance and to not duplicate error messages)I'm not sure if this is optimal though, I merely copied._onwrite
's missed declaration checkSet
to track this insteadThis also runs for each Rollupoutput
, so de-duping is pretty important in that sense toobuildEnd
hook instead, so it doesn't run for eachoutput
anymore (and it doesn't generate any output files, unlike the missed declarations, sobuildEnd
is a more correct place for it as well)This exits successfully with zero on a type-error, while
tsc
will exit non-zero and not emit by default.emitSkipped
isfalse
too during the declaration output, despite the type-check error.this.error
in this case as well, but would have to be a different error messageMisc
Could the
walkTree
call be moved intobuildEnd
as well? That seems like it might be a better place for it, the!noErrors
output, and maybecache.done()
too, but I don't know if there was a reason for putting it in_ongenerate
.