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

fix: hardcode declaration extension check #456

Merged
merged 4 commits into from
Jul 10, 2023

Conversation

agilgur5
Copy link
Collaborator

@agilgur5 agilgur5 commented Jul 7, 2023

Summary

Follow-up to #451 (comment), ensure declarations are always ignored during resolution.

  • Technically, this fixes a tiny new regression whereby a user could have accidentally (or incorrectly) made rpt2 try to process a directly imported declaration

Details

  • rpt2 should always ignore declarations

    • regardless of the exclude; as in, if a user accidentally removes declarations in an override, rpt2 should still not directly read declarations
      • as they are normally read ambiently by TS and not directly by Rollup or TS
  • this also ensures that the resolveId check is the same as the type-only resolve pre-check

    • adds a comment referencing why this is done. see my commit message step-by-step details on that one, it's a bit complicated logic

Cherry-pick of two commits from October that I had on a different, incomplete branch for #426

agilgur5 added 4 commits July 7, 2023 15:11
- basically, right now, the addition of `this.load` on all `references` is causing Rollup to error out on JSON files
  - specifically, this is impacting `configPlugin` usage (i.e. `rollup.config.ts`), where previously one didn't need `@rollup/plugin-json`, but now it is erroring out without it
  - I tracked this down to be because of `this.load` specifically
  - to avoid this and similar such issues, we can preemptively `filter` out files before calling `this.resolve` / `this.load`, which should end up `exclude`ing JSON files and any other non-rpt2 files
    - this should also make it a bit more efficient to skip some recursion
    - and non-rpt2 files shouldn't include any type-only files

- confirmed that this change fixes the error
  - and that the type-only tests still pass
- since the same logic is used in `resolveId` and these _should_ be equivalent

- in the future, we might want to add more common logic to this function, e.g. `getAllReferences` removes `undefined` and uses `moduleNameResolver` as well, similar to `resolveId`
  - may not be so easy, so TBD
    - for instance, even moving the `undefined` check into the func required adding a type guard, as the compiler wasn't quite able to infer that passing the func meant it was not `undefined`
- support newer TS extensions

- rpt2 should _always_ ignore declarations
  - regardless of the `exclude`; as in, if a user accidentally removes declarations in an override, rpt2 should still not directly read declarations
    - as they are normally read ambiently by TS and not _directly_ by Rollup or TS
…rences

- we don't `return false` in `resolveId`, so any new file that wasn't previously in Rollup's pipeline _must_ be resolved
  - `return` just defers to the next plugin, so, for a declaration, it eventually causes Rollup to try and fail to resolve on its own, giving an `Unexptected token` error message
  - but we _don't_ want to `return false` in `resolveId` if they _intentionally_ imported a declaration for some reason (e.g. if they're going to transform it in some way)
    - if we did `return false`, no other plugin could process either
  - so as a result, we should just never call `this.resolve()` on anything we don't expect to be able to resolve
    - i.e. don't add anything new to the pipeline that we don't resolve ourselves
@agilgur5 agilgur5 added the kind: regression Specific type of bug -- past behavior that worked is now broken label Jul 7, 2023
@agilgur5 agilgur5 requested a review from ezolenko July 7, 2023 20:21
@agilgur5 agilgur5 mentioned this pull request Jul 7, 2023
@agilgur5 agilgur5 added the version: patch Increment the patch version when merged label Jul 7, 2023
@ezolenko ezolenko merged commit 976dadb into ezolenko:master Jul 10, 2023
@agilgur5 agilgur5 deleted the fix-hardcode-extension-check branch July 10, 2023 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: regression Specific type of bug -- past behavior that worked is now broken version: patch Increment the patch version when merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants