mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-17 05:09:24 +08:00
- Enforce oxlint and oxfmt for owned JavaScript and TypeScript with independent CI checks. - Preserve compiler import boundaries and protected fixtures while cleaning up lint findings. - Standardize source formatting and validate import, fixture, and embedded-source protections.
24 lines
875 B
JavaScript
24 lines
875 B
JavaScript
/** Bounded build work that preserves manifest order and drains in-flight
|
|
* compilers before propagating a failure to the staging-directory cleanup. */
|
|
export async function parallelMap(items, width, task) {
|
|
if (!Number.isInteger(width) || width < 1) throw new Error("invalid build concurrency");
|
|
const results = new Array(items.length);
|
|
let next = 0;
|
|
let failed = false;
|
|
const workers = Array.from({ length: Math.min(width, items.length) }, async () => {
|
|
while (!failed && next < items.length) {
|
|
const index = next++;
|
|
try {
|
|
results[index] = await task(items[index]);
|
|
} catch (error) {
|
|
failed = true;
|
|
throw error;
|
|
}
|
|
}
|
|
});
|
|
const settled = await Promise.allSettled(workers);
|
|
const failure = settled.find((result) => result.status === "rejected");
|
|
if (failure) throw failure.reason;
|
|
return results;
|
|
}
|