@kaynooo/cli-base 0.12.2 → 0.12.3

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +21 -10
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -20,7 +20,7 @@ base --keep tests/NewTest.php -- vendor/bin/phpunit tests/NewTest.php
20
20
 
21
21
  ## base proof
22
22
 
23
- `base proof` shows that a test fails before a change and passes after it, the check `base` makes by hand: it runs the command at HEAD (or `--ref <rev>`) in the same temporary worktree as `base`, then in the working tree, both captured.
23
+ `base proof` shows that a test fails before a change and passes after it, the check `base` makes by hand: it runs the command at the merge base with origin's default branch when HEAD is on a branch ahead of it, else at HEAD (or `--ref <rev>`), in the same temporary worktree as `base`, then in the working tree, both captured.
24
24
 
25
25
  ```sh
26
26
  base proof --keep tests/NewTest.php -- vendor/bin/phpunit tests/NewTest.php
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 {
@@ -500,21 +500,32 @@ function wholeNumber(value, name, fallback, min = 1) {
500
500
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
501
501
  return number;
502
502
  }
503
+ function durationMs(text, unit) {
504
+ if (BARE_DURATION.test(text))
505
+ return Number(text) * UNIT_MS[unit];
506
+ if (!DURATION.test(text))
507
+ return 0;
508
+ let ms = 0;
509
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
510
+ ms += Number(amount) * UNIT_MS[part];
511
+ return ms;
512
+ }
503
513
  function duration(value, name, fallback, unit = "s") {
504
514
  if (value === undefined)
505
515
  return fallback;
506
- const match = DURATION.exec(value.trim());
507
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
516
+ const ms = durationMs(value.trim(), unit);
508
517
  if (ms < 1)
509
518
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
510
519
  return ms;
511
520
  }
512
- var WHOLE, DURATION, UNIT_MS;
521
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
513
522
  var init_input = __esm(() => {
514
523
  init_args();
515
524
  WHOLE = /^\d+$/;
516
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
517
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
525
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
526
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
527
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
528
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
518
529
  });
519
530
 
520
531
  // ../kit/src/args.ts
@@ -1792,7 +1803,7 @@ ${USAGE}`);
1792
1803
 
1793
1804
  // src/proof.ts
1794
1805
  import process19 from "process";
1795
- var USAGE2 = `base proof [--ref <rev>] [--runs <n>] [--keep <path>...] [--timeout <duration>] [--no-link] [--json] -- <command> [args...]: runs the command at HEAD or another ref in a temporary worktree, then in the working tree, to show that a test fails before a change and passes after it
1806
+ var USAGE2 = `base proof [--ref <rev>] [--runs <n>] [--keep <path>...] [--timeout <duration>] [--no-link] [--json] -- <command> [args...]: runs the command at the ref below in a temporary worktree, then in the working tree, to show that a test fails before a change and passes after it
1796
1807
 
1797
1808
  The ignored env files, node_modules, vendor and .venv of the working tree are linked into the temporary worktree, writes included; --no-link runs fully apart. The ref defaults to the merge base with the default branch of origin (origin/main unless origin/HEAD names another) when HEAD is on a branch ahead of it, else HEAD. --runs <n> runs the command n times now, for a flaky test, and every run must pass. --timeout kills a run that lasts longer (a hung test), which says nothing about the change and ends with exit 2.`;
1798
1809
  var EXITS = [[0, "the command fails before and passes in every run now"], [1, "it passes before too, fails in any run now, or passes before and fails now"], [2, "a usage error, an unknown ref, a command that cannot start, ends with exit 126, 127, 125 or a signal, or runs past --timeout"], [130, "interrupted (128 plus the signal)"]];
@@ -1897,10 +1908,10 @@ process20.exitCode = await runCli({
1897
1908
  name: "base",
1898
1909
  about: "runs a command at HEAD or another ref in a temporary worktree, sharing node_modules and env files with the working tree unless --no-link",
1899
1910
  replaces: "git stash, a test run, then git stash pop",
1900
- examples: [["base -- bun test tests/api.test.ts", "the test at HEAD, the working tree changes left out"], ["base proof -- bun test tests/new.test.ts", "it fails at HEAD and passes in the working tree"]],
1911
+ examples: [["base -- bun test tests/api.test.ts", "the test at HEAD, the working tree changes left out"], ["base proof -- bun test tests/new.test.ts", "it fails before the change and passes in the working tree"]],
1901
1912
  commands: {
1902
1913
  run: { summary: "the command at HEAD or --ref, exiting with its code (the command when none is named)", run: base },
1903
- proof: { summary: "the command at HEAD or --ref, then in the working tree: proves a test fails before a change and passes after it", run: proof }
1914
+ proof: { summary: "the command at the merge base with origin's default branch on a branch ahead of it (else HEAD, or --ref), then in the working tree: proves a test fails before a change and passes after it", run: proof }
1904
1915
  },
1905
1916
  defaultCommand: "run"
1906
1917
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-base",
3
3
  "type": "module",
4
- "version": "0.12.2",
4
+ "version": "0.12.3",
5
5
  "description": "base: a command run at HEAD or another ref in a temporary worktree, sharing node_modules and env files with the working tree.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -32,10 +32,10 @@
32
32
  "registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
33
33
  },
34
34
  "scripts": {
35
- "build": "$npm_execpath build src/cli.ts --target bun --outdir dist",
35
+ "build": "$npm_execpath build src/cli.ts --target bun --outdir dist && $npm_execpath ../../scripts/shell-shebang.ts",
36
36
  "base": "$npm_execpath src/cli.ts"
37
37
  },
38
38
  "devDependencies": {
39
- "@kaynooo/cli-kit": "0.46.0"
39
+ "@kaynooo/cli-kit": "0.46.4"
40
40
  }
41
41
  }