@kaynooo/cli-wait 0.12.4 → 0.12.6

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/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env -S bun --no-env-file --config=/dev/null
2
- // @bun
1
+ #!/bin/sh
2
+ // @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
3
3
  var __esm = (fn, res, err) => () => {
4
4
  if (fn)
5
5
  try {
@@ -625,21 +625,32 @@ function wholeNumber(value, name, fallback, min = 1) {
625
625
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
626
626
  return number;
627
627
  }
628
+ function durationMs(text, unit) {
629
+ if (BARE_DURATION.test(text))
630
+ return Number(text) * UNIT_MS[unit];
631
+ if (!DURATION.test(text))
632
+ return 0;
633
+ let ms = 0;
634
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
635
+ ms += Number(amount) * UNIT_MS[part];
636
+ return ms;
637
+ }
628
638
  function duration(value, name, fallback, unit = "s") {
629
639
  if (value === undefined)
630
640
  return fallback;
631
- const match = DURATION.exec(value.trim());
632
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
641
+ const ms = durationMs(value.trim(), unit);
633
642
  if (ms < 1)
634
643
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
635
644
  return ms;
636
645
  }
637
- var WHOLE, DURATION, UNIT_MS;
646
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
638
647
  var init_input = __esm(() => {
639
648
  init_args();
640
649
  WHOLE = /^\d+$/;
641
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
642
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
650
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
651
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
652
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
653
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
643
654
  });
644
655
 
645
656
  // ../kit/src/args.ts
package/dist/slot-cli.js CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env -S bun --no-env-file --config=/dev/null
2
- // @bun
1
+ #!/bin/sh
2
+ // @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
3
3
  var __esm = (fn, res, err) => () => {
4
4
  if (fn)
5
5
  try {
@@ -625,21 +625,32 @@ function wholeNumber(value, name, fallback, min = 1) {
625
625
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
626
626
  return number;
627
627
  }
628
+ function durationMs(text, unit) {
629
+ if (BARE_DURATION.test(text))
630
+ return Number(text) * UNIT_MS[unit];
631
+ if (!DURATION.test(text))
632
+ return 0;
633
+ let ms = 0;
634
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
635
+ ms += Number(amount) * UNIT_MS[part];
636
+ return ms;
637
+ }
628
638
  function duration(value, name, fallback, unit = "s") {
629
639
  if (value === undefined)
630
640
  return fallback;
631
- const match = DURATION.exec(value.trim());
632
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
641
+ const ms = durationMs(value.trim(), unit);
633
642
  if (ms < 1)
634
643
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
635
644
  return ms;
636
645
  }
637
- var WHOLE, DURATION, UNIT_MS;
646
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
638
647
  var init_input = __esm(() => {
639
648
  init_args();
640
649
  WHOLE = /^\d+$/;
641
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
642
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
650
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
651
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
652
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
653
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
643
654
  });
644
655
 
645
656
  // ../kit/src/args.ts
@@ -1860,11 +1871,23 @@ async function acquire(dir, resources, holder, deadline, timeoutMs) {
1860
1871
  }
1861
1872
  }
1862
1873
  }
1863
- async function runSlotted(args) {
1864
- const bare = args[0] !== undefined && !args[0].startsWith("-");
1865
- const parsed = parse(bare ? [] : args, RUN_USAGE, RUN_OPTIONS, { rest: true, exits: RUN_EXITS, replaces: "flock wrappers, hand-written heavy.sh queues and parallel runs fighting over one test database", examples: [["slot -- bunx vue-tsc", "wait for a free slot, then type-check"], ["slot --lock booki-test-db -- vendor/bin/phpunit", "one phpunit at a time on the shared test database"], "slot ls"] });
1866
- const { values } = parsed;
1867
- const rest = bare ? args : parsed.rest;
1874
+ function withSeparator(args) {
1875
+ const takesValue = (word) => Object.entries(RUN_OPTIONS).some(([name, option]) => option.type === "string" && (word === `--${name}` || ("short" in option) && word === `-${option.short}`));
1876
+ for (let at = 0;at < args.length; at++) {
1877
+ const word = args[at];
1878
+ if (word === "--")
1879
+ return args;
1880
+ if (!word.startsWith("-"))
1881
+ return [...args.slice(0, at), "--", ...args.slice(at)];
1882
+ if (takesValue(word))
1883
+ at++;
1884
+ }
1885
+ return args;
1886
+ }
1887
+ async function runSlotted(given) {
1888
+ const args = withSeparator(given);
1889
+ const parsed = parse(args, RUN_USAGE, RUN_OPTIONS, { rest: true, exits: RUN_EXITS, replaces: "flock wrappers, hand-written heavy.sh queues and parallel runs fighting over one test database", examples: [["slot -- bunx vue-tsc", "wait for a free slot, then type-check"], ["slot --lock booki-test-db -- vendor/bin/phpunit", "one phpunit at a time on the shared test database"], "slot ls"] });
1890
+ const { values, rest } = parsed;
1868
1891
  if (rest === undefined || rest.length === 0)
1869
1892
  fail(`give the command after --
1870
1893
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-wait",
3
3
  "type": "module",
4
- "version": "0.12.4",
4
+ "version": "0.12.6",
5
5
  "description": "waitfor and slot: waits for a log line, a listening port or a URL answering, and queues heavy commands behind machine-wide slots and named locks, for Claude Code, instead of sleep and polling loops.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -33,11 +33,11 @@
33
33
  "registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
34
34
  },
35
35
  "scripts": {
36
- "build": "$npm_execpath build src/cli.ts src/slot-cli.ts --target bun --outdir dist",
36
+ "build": "$npm_execpath build src/cli.ts src/slot-cli.ts --target bun --outdir dist && $npm_execpath ../../scripts/shell-shebang.ts",
37
37
  "slot": "$npm_execpath src/slot-cli.ts",
38
38
  "waitfor": "$npm_execpath src/cli.ts"
39
39
  },
40
40
  "devDependencies": {
41
- "@kaynooo/cli-kit": "0.46.1"
41
+ "@kaynooo/cli-kit": "0.46.4"
42
42
  }
43
43
  }