Skip to content

Commit

Permalink
Attempt to fix #318
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed May 3, 2022
1 parent 797c876 commit 0e13d1c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
25 changes: 17 additions & 8 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,12 @@ export class Images {
const properties = flattenIconOptions(iconOptions);

if (path.extname(name) === ".ico" || properties.length !== 1) {
const images = await Promise.all(
properties.map((props) =>
this.createPlaneFavicon(
sourceset,
props,
`${props.width}x${props.height}.rawdata`,
true
)
const images = await promiseAllSequentially(properties, (props) =>
this.createPlaneFavicon(
sourceset,
props,
`${props.width}x${props.height}.rawdata`,
true
)
);
const contents = toIco(images.map((image) => image.contents as RawImage));
Expand All @@ -265,3 +263,14 @@ export class Images {
return await this.createPlaneFavicon(sourceset, properties[0], name, false);
}
}

export async function promiseAllSequentially<T, U>(
inputs: T[],
computation: (input: T) => Promise<U>
): Promise<U[]> {
const result: U[] = [];
for (const input of inputs) {
result.push(await computation(input));
}
return result;
}
7 changes: 4 additions & 3 deletions src/platforms/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
filterKeys,
Images,
mapValues,
promiseAllSequentially,
relativeTo,
SourceImage,
} from "../helpers";
Expand Down Expand Up @@ -62,10 +63,10 @@ export class Platform<IO extends IconOptions = IconOptions> {

async createImages(sourceset: SourceImage[]): Promise<FaviconImage[]> {
const images = new Images();
return await Promise.all(
Object.entries(this.iconOptions).map(([iconName, iconOption]) =>
return await promiseAllSequentially(
Object.entries(this.iconOptions),
([iconName, iconOption]) =>
images.createFavicon(sourceset, iconName, iconOption)
)
);
}

Expand Down

0 comments on commit 0e13d1c

Please sign in to comment.