Skip to content

Commit b393678

Browse files
committed
rewrite the core logic with a for...of loop instead
- 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)
1 parent 064aee2 commit b393678

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,17 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
254254
// handle all type-only imports by resolving + loading all of TS's references
255255
// Rollup can't see these otherwise, because they are "emit-less" and produce no JS
256256
if (result.references) {
257-
const modules = await Promise.all(result.references
258-
.filter(ref => !ref.endsWith(".d.ts"))
259-
.map(ref => this.resolve(ref, id)));
257+
for (const ref of result.references) {
258+
if (ref.endsWith(".d.ts"))
259+
continue;
260260

261-
// wait for all to be loaded (otherwise, as this is async, some may end up only loading after `generateBundle`)
262-
await Promise.all(modules.map(async module => {
261+
const module = await this.resolve(ref, id);
263262
if (!module || transformedFiles.has(module.id)) // check for circular references (per https://rollupjs.org/guide/en/#thisload)
264-
return;
263+
continue;
264+
265+
// wait for all to be loaded (otherwise, as this is async, some may end up only loading after `generateBundle`)
265266
await this.load({id: module.id});
266-
}));
267+
}
267268
}
268269

269270
// 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

0 commit comments

Comments
 (0)