Skip to content

Commit b0fbfe0

Browse files
Add merged type defintions for index.d.ts
1 parent c951864 commit b0fbfe0

File tree

2 files changed

+5
-29
lines changed

2 files changed

+5
-29
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"prepublishOnly": "yarn npm-run-all clean build"
2828
},
2929
"dependencies": {
30+
"@kristoferbaxter/async": "0.0.4",
3031
"bytes": "3.1.0",
3132
"fast-glob": "3.2.2",
3233
"kleur": "3.0.3",
@@ -53,7 +54,7 @@
5354
"typescript": "3.8.3"
5455
},
5556
"volta": {
56-
"node": "12.16.2",
57+
"node": "14.0.0",
5758
"yarn": "1.22.4"
5859
},
5960
"filesize": {

src/compress.ts

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { cpus } from 'os';
1817
import { Context, Compression, OrderedCompressionValues, maxSize } from './validation/Condition';
1918
import { readFile } from './helpers/fs';
2019
import { Report } from './log/report';
2120
import { compressor } from './compressor';
22-
23-
const COMPRESSION_CONCURRENCY = cpus().length;
21+
import { pool } from '@kristoferbaxter/async';
2422

2523
export interface CompressionItem {
2624
path: string;
@@ -84,31 +82,8 @@ export default async function compress(
8482
return true;
8583
}
8684

87-
const returnable: Array<Promise<boolean>> = [];
88-
const executing: Array<Promise<boolean>> = [];
8985
const reportInstance: Report | null = report ? new report(context) : null;
90-
let success = true;
91-
for (const item of toCompress) {
92-
const promise: Promise<boolean> = Promise.resolve(item).then((item) => compressor(context, reportInstance, item));
93-
returnable.push(promise);
94-
95-
if (COMPRESSION_CONCURRENCY <= toCompress.length) {
96-
const execute: any = promise.then((successful) => {
97-
if (!successful) {
98-
success = successful;
99-
}
100-
executing.splice(executing.indexOf(execute), 1);
101-
});
102-
executing.push(execute);
103-
if (executing.length >= COMPRESSION_CONCURRENCY) {
104-
await Promise.race(executing);
105-
}
106-
}
107-
}
108-
if ((await Promise.all(returnable)).includes(false)) {
109-
success = false;
110-
}
111-
86+
const successful = await pool(toCompress, (item: CompressionItem) => compressor(context, reportInstance, item));
11287
reportInstance?.end();
113-
return success;
88+
return successful.every((success) => success);
11489
}

0 commit comments

Comments
 (0)