@nice-code/commander 0.71.0 → 0.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/cli.cjs CHANGED
@@ -23846,13 +23846,43 @@ async function cmdRun(ctx) {
23846
23846
  try {
23847
23847
  const pumps = single ? [] : procs.map((proc) => startPump(out, proc));
23848
23848
  if (tasks.length > 0 && services.length === 0) {
23849
- const queue = [...tasks];
23850
- const workers = Array.from({ length: Math.min(parallel ?? 1, queue.length) }, async () => {
23849
+ const pending = [...tasks];
23850
+ const succeeded = /* @__PURE__ */ new Set();
23851
+ const failed = /* @__PURE__ */ new Set();
23852
+ const running = /* @__PURE__ */ new Set();
23853
+ const selected = new Set(tasks.map((def) => def.id));
23854
+ const depsOf = (def) => def.dependsOn.filter((id) => selected.has(id));
23855
+ let wake = () => {};
23856
+ const settled = () => new Promise((resolve) => {
23857
+ wake = resolve;
23858
+ });
23859
+ const workers = Array.from({ length: Math.min(parallel ?? 1, pending.length) }, async () => {
23851
23860
  for (;;) {
23852
23861
  if (failFast && failures.length > 0) return;
23853
- const def = queue.shift();
23854
- if (def == null) return;
23862
+ const index = pending.findIndex((def) => depsOf(def).every((id) => succeeded.has(id) || failed.has(id)));
23863
+ if (index < 0) {
23864
+ if (running.size === 0) return;
23865
+ await settled();
23866
+ continue;
23867
+ }
23868
+ const [def] = pending.splice(index, 1);
23869
+ const blockedBy = depsOf(def).find((id) => failed.has(id));
23870
+ if (blockedBy != null) {
23871
+ out.print(`${out.paint("yellow", "⊘")} ${out.accent(def.id, def.id)} blocked: "${blockedBy}" failed`);
23872
+ failed.add(def.id);
23873
+ failures.push({
23874
+ id: def.id,
23875
+ code: 1,
23876
+ failed: true
23877
+ });
23878
+ wake();
23879
+ continue;
23880
+ }
23881
+ running.add(def.id);
23855
23882
  const result = await runTask(def);
23883
+ running.delete(def.id);
23884
+ (result.failed ? failed : succeeded).add(def.id);
23885
+ wake();
23856
23886
  if (result.failed) {
23857
23887
  failures.push(result);
23858
23888
  if (failFast) {
@@ -23863,6 +23893,15 @@ async function cmdRun(ctx) {
23863
23893
  }
23864
23894
  });
23865
23895
  await Promise.all(workers);
23896
+ for (const def of pending) {
23897
+ const blockedBy = depsOf(def).find((id) => !succeeded.has(id)) ?? "a dependency";
23898
+ out.print(`${out.paint("yellow", "⊘")} ${out.accent(def.id, def.id)} blocked: "${blockedBy}" did not succeed`);
23899
+ failures.push({
23900
+ id: def.id,
23901
+ code: 1,
23902
+ failed: true
23903
+ });
23904
+ }
23866
23905
  await drainPumps(pumps);
23867
23906
  return failures.length > 0 ? failures[0]?.code ?? 1 : EXIT.ok;
23868
23907
  }