Skip to content

Commit

Permalink
rewrite the core logic with a for...of loop instead
Browse files Browse the repository at this point in the history
- simpler to follow than `map` + `filter` + `Promise.all`
  - might(?) be faster without `Promise.all` as well as more can happen async without waiting
    - (I'm not totally sure of the low-level implementation of async to know for sure though)
  • Loading branch information
agilgur5 committed Aug 30, 2022
1 parent 064aee2 commit b393678
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,17 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
// handle all type-only imports by resolving + loading all of TS's references
// Rollup can't see these otherwise, because they are "emit-less" and produce no JS
if (result.references) {
const modules = await Promise.all(result.references
.filter(ref => !ref.endsWith(".d.ts"))
.map(ref => this.resolve(ref, id)));
for (const ref of result.references) {
if (ref.endsWith(".d.ts"))
continue;

// wait for all to be loaded (otherwise, as this is async, some may end up only loading after `generateBundle`)
await Promise.all(modules.map(async module => {
const module = await this.resolve(ref, id);
if (!module || transformedFiles.has(module.id)) // check for circular references (per https://rollupjs.org/guide/en/#thisload)
return;
continue;

// wait for all to be loaded (otherwise, as this is async, some may end up only loading after `generateBundle`)
await this.load({id: module.id});
}));
}
}

// if a user sets this compilerOption, they probably want another plugin (e.g. Babel, ESBuild) to transform their TS instead, while rpt2 just type-checks and/or outputs declarations
Expand Down

0 comments on commit b393678

Please sign in to comment.