Skip to content

Commit 1cfdbd8

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 fa63758 commit 1cfdbd8

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
@@ -258,16 +258,17 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
258258
// handle all type-only imports by resolving + loading all of TS's references
259259
// Rollup can't see these otherwise, because they are "emit-less" and produce no JS
260260
if (result.references) {
261-
const modules = await Promise.all(result.references
262-
.filter(ref => !ref.endsWith(".d.ts"))
263-
.map(ref => this.resolve(ref, id)));
261+
for (const ref of result.references) {
262+
if (ref.endsWith(".d.ts"))
263+
continue;
264264

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

273274
// 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)