Skip to content

Commit

Permalink
fix: preemptively filter type-only files to workaround Rollup bug
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
agilgur5 committed Oct 9, 2022
1 parent f6db596 commit 61ef625
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,11 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
// Rollup can't see these otherwise, because they are "emit-less" and produce no JS
if (result.references && supportsThisLoad) {
for (const ref of result.references) {
// pre-emptively filter out some files (for efficiency, as well as to workaround a Rollup bug: https://github.com/ezolenko/rollup-plugin-typescript2/issues/426#issuecomment-1264812897)
if (ref.endsWith(".d.ts"))
continue;
if (!filter(ref))
continue;

const module = await this.resolve(ref, id);
if (!module || transformedFiles.has(module.id)) // check for circular references (per https://rollupjs.org/guide/en/#thisload)
Expand Down

0 comments on commit 61ef625

Please sign in to comment.