@kaynooo/cli-pkg 0.13.1 → 0.13.2

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 +2 -1
  2. package/dist/cli.js +53 -34
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -29,6 +29,7 @@ pkg outdated
29
29
 
30
30
  - `licenses` is the allowlist of SPDX ids, compared without regard to case. An expression is allowed when one side of an `OR` is and every term of an `AND` is; a `WITH` exception is ignored. With an allowlist set, `pkg check` refuses a package whose licence is outside it or missing (a legacy `SEE LICENSE IN` or `UNLICENSED` counts as outside), so the `bun add` the guard checks through `pkg check` is refused with it. Without the key the licence is only printed.
31
31
  - `minAge` (a whole number of days, 14 when no config sets it) is how old a version must be when `--min-age` is not given, in `check`, `audit` and `outdated`.
32
+ - `concurrency` (a positive whole number, 8 when no config sets it) is how many registry lookups `audit` and `outdated` run at once.
32
33
  - `blockSeverity` (`low`, `moderate`, `high` or `critical`, `high` when no config sets it) makes `pkg check` ask the registry for the advisories of the exact `name@version` and refuse it when one is at that severity or above. The request is the one `bun audit` makes: a `POST` of `{"name": ["version"]}` to `<registry>/-/npm/v1/security/advisories/bulk`. A registry without that endpoint (a private one, say) leaves the version unrefused with a warning, while an advisory request that fails (unreachable, a 5xx, not JSON) exits 2, since the advisories could not be read.
33
34
 
34
35
  ## Auditing a lockfile
@@ -55,7 +56,7 @@ pkg consumers @kaynooo/cli-kit
55
56
  pkg bump @kaynooo/cli-kit 0.8.0 --dry-run
56
57
  ```
57
58
 
58
- - `pkg consumers <name>` lists every `package.json` under `--root` (the configured workspace folder, `~/Workspace` by default) depending on the package, `node_modules`, `dist`, `build`, `vendor`, `target`, `coverage` and dot folders left out and nothing deeper than 5 levels below `--root` (point `--root` at the folder to reach further): the folder, the kind of dependency, the version it asks for and the manager its nearest lockfile pins; `--json` for the rows.
59
+ - `pkg consumers <name>` lists every `package.json` under `--root` (the configured workspace folder, `~/Workspace` by default) depending on the package, `node_modules`, `dist`, `build`, `vendor`, `target`, `coverage`, the names in the `ignore` array of `~/.config/kaynooo-cli/config.json` and dot folders left out and nothing deeper than 5 levels below `--root` (point `--root` at the folder to reach further): the folder, the kind of dependency, the version it asks for and the manager its nearest lockfile pins; `--json` for the rows.
59
60
  - `pkg bump <name> [version]` waits until the package's registry serves the version (every 5 s, `-t 10m`; the latest when none is given, an exact version otherwise, never a range or a tag), then vets it with the checks of `pkg check` (advisories, licence allowlist) before any folder is touched, and runs `bun add --exact --no-cache <name>@<version>` in each of those folders, one after another, as the same kind of dependency (`--dev`, `--optional`), a line per folder. A version the vetting blocks is refused with its reasons and exit 1; `--force` bumps it anyway. A bump adopts a release on purpose, often one just made, so it checks no minimum age unless `--min-age <days>` asks for one. A dependency declared through an alias of the package (`"kay": "npm:@scope/name@~1.2.0"`) is found and bumped under its own key, keeping its `~` or `^`; `--only <name|glob>` and `--except <name|glob>` (repeatable) narrow the folders, and a package nothing depends on names similar dependencies. A dependency that is not a registry version (`workspace:`, `link:`, `file:`, `git`, a URL, another package's `npm:` alias, `catalog:`), a `peerDependencies` range, a folder already on the version and one whose lockfile pins another manager are left alone and said so; `--dry-run` prints what would run. On a terminal with no `--only` or `--except`, a checklist asks which consumers to bump (the ones left out last time unchecked, what is unchecked now remembered in `~/.config/kaynooo-cli/pkg-excluded.json`), then the plan is printed and confirmed; `--yes` skips both, as a pipe does. A transient registry error is retried until the timeout. It exits 1 when the vetting refuses the version, an install fails or the registry has no such package (at once, without waiting), 2 when the version never shows within the timeout.
60
61
  - `pkg bump <name> [version] --all-consumers` leaves alone a folder whose `package.json` or lockfile already has uncommitted changes, so that `gc` never commits them as the bump, and goes on in each folder whose install went through: it runs the folder's own `check` and, only when that passes, commits with `gc 'chore(deps): bump <name> to <version>' -- package.json <lockfile>` (the `bun.lock` or `bun.lockb` nearest the folder, a monorepo's at its root). A folder whose check fails stays uncommitted. It ends on a summary line of the folders bumped and committed, bumped and failing, and skipped, exits 1 when an install, a check or a commit failed, and never pushes. With `--dry-run` it lists the `bun add`, `check` and `gc` each folder would run.
61
62
  - `pkg <name>` alone still runs `pkg check`.
package/dist/cli.js CHANGED
@@ -189,7 +189,7 @@ var init_config = __esm(() => {
189
189
  });
190
190
 
191
191
  // ../kit/src/user-config.ts
192
- import { existsSync as existsSync2 } from "fs";
192
+ import { existsSync as existsSync2, readFileSync } from "fs";
193
193
  import { homedir } from "os";
194
194
  import { join as join2 } from "path";
195
195
  import process4 from "process";
@@ -207,10 +207,21 @@ function userConfigReadPath(bin, legacy = [], where = {}) {
207
207
  const base = configBase(where);
208
208
  return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
209
209
  }
210
+ function readUserConfig(bin, where = {}, legacy = []) {
211
+ const path = userConfigReadPath(bin, legacy, where);
212
+ if (!existsSync2(path))
213
+ return {};
214
+ try {
215
+ const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
216
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
217
+ } catch {
218
+ return {};
219
+ }
220
+ }
210
221
  var init_user_config = () => {};
211
222
 
212
223
  // ../kit/src/theme.ts
213
- import { existsSync as existsSync3, readFileSync, statSync } from "fs";
224
+ import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
214
225
  import { homedir as homedir2 } from "os";
215
226
  import { join as join3, resolve as resolve2 } from "path";
216
227
  import process5 from "process";
@@ -255,7 +266,7 @@ function readThemeFile(path, warn) {
255
266
  warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
256
267
  return;
257
268
  }
258
- const parsed = JSON.parse(readFileSync(path, "utf8"));
269
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
259
270
  if (isRecord(parsed))
260
271
  return parsed;
261
272
  warn(`${path} is not a JSON object, theme ignored`);
@@ -1233,7 +1244,7 @@ var init_usage = __esm(() => {
1233
1244
  });
1234
1245
 
1235
1246
  // ../kit/src/cli.ts
1236
- import { readFileSync as readFileSync2, realpathSync } from "fs";
1247
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
1237
1248
  import { dirname as dirname3, join as join5 } from "path";
1238
1249
  import process14 from "process";
1239
1250
  async function commandRows(all, colors) {
@@ -1475,7 +1486,7 @@ async function printCandidates(found) {
1475
1486
  function packageVersion(entry = Bun.main) {
1476
1487
  for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1477
1488
  try {
1478
- const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
1489
+ const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
1479
1490
  if (typeof version === "string")
1480
1491
  return version;
1481
1492
  } catch {}
@@ -1523,8 +1534,14 @@ var init_cli = __esm(() => {
1523
1534
  TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1524
1535
  });
1525
1536
  // ../kit/src/folders.ts
1537
+ function ignoredFolders(extra = [], where = {}) {
1538
+ const configured = readUserConfig("config", where).ignore;
1539
+ const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
1540
+ return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
1541
+ }
1526
1542
  var SKIPPED_FOLDERS;
1527
1543
  var init_folders = __esm(() => {
1544
+ init_user_config();
1528
1545
  SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
1529
1546
  });
1530
1547
 
@@ -1605,7 +1622,6 @@ var init_watch = __esm(() => {
1605
1622
  });
1606
1623
 
1607
1624
  // ../kit/src/workspace-root.ts
1608
- import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
1609
1625
  import { homedir as homedir4 } from "os";
1610
1626
  import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
1611
1627
  import process15 from "process";
@@ -1615,16 +1631,8 @@ function expandHome(path, home) {
1615
1631
  return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
1616
1632
  }
1617
1633
  function configured(env, home) {
1618
- const path = userConfigPath("config", { home, xdg: env.XDG_CONFIG_HOME });
1619
- if (!existsSync4(path))
1620
- return;
1621
- try {
1622
- const parsed = JSON.parse(readFileSync3(path, "utf8"));
1623
- const folder = typeof parsed === "object" && parsed !== null ? parsed.workspace : undefined;
1624
- return typeof folder === "string" && folder !== "" ? folder : undefined;
1625
- } catch {
1626
- return;
1627
- }
1634
+ const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
1635
+ return typeof folder === "string" && folder !== "" ? folder : undefined;
1628
1636
  }
1629
1637
  function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
1630
1638
  const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
@@ -2620,6 +2628,8 @@ function parseSettings(text) {
2620
2628
  settings.blockSeverity = raw.blockSeverity;
2621
2629
  if (typeof raw?.minAge === "number" && Number.isInteger(raw.minAge) && raw.minAge >= 0)
2622
2630
  settings.minAge = raw.minAge;
2631
+ if (typeof raw?.concurrency === "number" && Number.isInteger(raw.concurrency) && raw.concurrency > 0)
2632
+ settings.concurrency = raw.concurrency;
2623
2633
  return settings;
2624
2634
  }
2625
2635
  async function loadSettings(cwd = process17.cwd(), home) {
@@ -2636,6 +2646,7 @@ async function loadSettings(cwd = process17.cwd(), home) {
2636
2646
  settings.licenses ??= found.licenses;
2637
2647
  settings.blockSeverity ??= found.blockSeverity;
2638
2648
  settings.minAge ??= found.minAge;
2649
+ settings.concurrency ??= found.concurrency;
2639
2650
  }
2640
2651
  return settings;
2641
2652
  }
@@ -2738,9 +2749,9 @@ var init_pin = __esm(() => {
2738
2749
  });
2739
2750
 
2740
2751
  // src/consumers.ts
2741
- import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync4 } from "fs";
2752
+ import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync4 } from "fs";
2742
2753
  import { dirname as dirname6, join as join8, relative } from "path";
2743
- function packageFiles(dir, depth, found) {
2754
+ function packageFiles(dir, depth, found, ignored = ignoredFolders()) {
2744
2755
  let entries;
2745
2756
  try {
2746
2757
  entries = readdirSync(dir, { withFileTypes: true });
@@ -2750,14 +2761,14 @@ function packageFiles(dir, depth, found) {
2750
2761
  for (const entry of entries) {
2751
2762
  if (entry.isFile() && entry.name === "package.json")
2752
2763
  found.push(join8(dir, entry.name));
2753
- else if (entry.isDirectory() && depth < MAX_DEPTH && !entry.name.startsWith(".") && !SKIPPED_FOLDERS.has(entry.name))
2754
- packageFiles(join8(dir, entry.name), depth + 1, found);
2764
+ else if (entry.isDirectory() && depth < MAX_DEPTH && !entry.name.startsWith(".") && !ignored.has(entry.name))
2765
+ packageFiles(join8(dir, entry.name), depth + 1, found, ignored);
2755
2766
  }
2756
2767
  return found;
2757
2768
  }
2758
2769
  function managerFor(dir, root) {
2759
2770
  for (let at = dir;; at = dirname6(at)) {
2760
- const lockfile = LOCKFILES.find(([file]) => existsSync5(join8(at, file)));
2771
+ const lockfile = LOCKFILES.find(([file]) => existsSync4(join8(at, file)));
2761
2772
  if (lockfile !== undefined)
2762
2773
  return lockfile[1];
2763
2774
  if (at === root || at === dirname6(at))
@@ -3022,7 +3033,7 @@ async function auditPackages(packages, context) {
3022
3033
  packuments.set(key, fetchPackument(name, registry, context.fetcher));
3023
3034
  return packuments.get(key);
3024
3035
  };
3025
- const looked = await pool(packages, BATCH, async ({ name, version }) => {
3036
+ const looked = await pool(packages, context.settings.concurrency ?? BATCH, async ({ name, version }) => {
3026
3037
  const registry = registryFor(name, context.configs);
3027
3038
  const input = { spec: { name, request: version }, packument: await lookup(name, registry), registry: new URL(registry.url).host, now: context.now, minAgeDays: context.minAgeDays, licenses: context.settings.licenses };
3028
3039
  return { name, version, registry, input, safe: analyze(input).safe?.version };
@@ -3120,7 +3131,7 @@ var exports_outdated = {};
3120
3131
  __export(exports_outdated, {
3121
3132
  outdatedCommand: () => outdatedCommand
3122
3133
  });
3123
- import { existsSync as existsSync6 } from "fs";
3134
+ import { existsSync as existsSync5 } from "fs";
3124
3135
  import { join as join10, resolve as resolve6 } from "path";
3125
3136
  function currentOf(name, spec, locked) {
3126
3137
  const pinned = locked.filter((each) => each.name === name && Bun.semver.satisfies(each.version, spec)).map((each) => each.version).sort(Bun.semver.order).at(-1);
@@ -3136,7 +3147,7 @@ function changeOf(current, next) {
3136
3147
  async function outdated(manifest, context) {
3137
3148
  const configs = await loadConfigs();
3138
3149
  const dependencies = registryDependencies(manifest);
3139
- const looked = await pool(dependencies, BATCH2, async ({ name, kind, spec }) => {
3150
+ const looked = await pool(dependencies, context.concurrency ?? BATCH2, async ({ name, kind, spec }) => {
3140
3151
  const registry = registryFor(name, configs);
3141
3152
  const packument = await fetchPackument(name, registry, context.fetcher);
3142
3153
  if (packument === undefined) {
@@ -3159,8 +3170,9 @@ async function outdatedCommand(args) {
3159
3170
  if (!await manifest.exists())
3160
3171
  fail(`no package.json in ${folder}`);
3161
3172
  const lockPath = join10(folder, "bun.lock");
3162
- const locked = existsSync6(lockPath) ? parseBunLock(await Bun.file(lockPath).text()) : [];
3163
- const rows = await outdated(await manifest.text(), { minAgeDays: wholeNumber(values["min-age"], "min-age", (await loadSettings(folder)).minAge ?? DEFAULT_MIN_AGE_DAYS, 0), locked });
3173
+ const locked = existsSync5(lockPath) ? parseBunLock(await Bun.file(lockPath).text()) : [];
3174
+ const settings = await loadSettings(folder);
3175
+ const rows = await outdated(await manifest.text(), { minAgeDays: wholeNumber(values["min-age"], "min-age", settings.minAge ?? DEFAULT_MIN_AGE_DAYS, 0), concurrency: settings.concurrency, locked });
3164
3176
  const { shown, footer } = capped(rows, limitOf(values, OUTDATED_LIMIT));
3165
3177
  if (values.json === true)
3166
3178
  printJson(shown);
@@ -3200,9 +3212,15 @@ var init_score = __esm(() => {
3200
3212
  });
3201
3213
 
3202
3214
  // ../kit/src/picker/state.ts
3215
+ function repeat(value, count) {
3216
+ return Array.from({ length: count }).fill(value);
3217
+ }
3203
3218
  function parseKeys(input, paste = { active: false }, ctrls = []) {
3204
3219
  const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
3205
3220
  return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
3221
+ const wheel = MOUSE.exec(sequence)?.[1];
3222
+ if (wheel !== undefined)
3223
+ return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
3206
3224
  const named = codes.get(sequence);
3207
3225
  const key = named === undefined ? KEYS[sequence] : { ctrl: named };
3208
3226
  if (sequence === PASTE_START || sequence === PASTE_END) {
@@ -3217,11 +3235,12 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
3217
3235
  return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
3218
3236
  });
3219
3237
  }
3220
- var IS_CONTROL, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, KEYS;
3238
+ var IS_CONTROL, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS;
3221
3239
  var init_state = __esm(() => {
3222
3240
  init_score();
3223
3241
  IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
3224
- KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
3242
+ KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
3243
+ MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
3225
3244
  KEYS = {
3226
3245
  "\x1B[A": "up",
3227
3246
  "\x1BOA": "up",
@@ -3436,14 +3455,14 @@ var init_prompt = __esm(() => {
3436
3455
  });
3437
3456
 
3438
3457
  // src/excluded.ts
3439
- import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync2 } from "fs";
3458
+ import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync } from "fs";
3440
3459
  import { dirname as dirname7 } from "path";
3441
3460
  function excludedPath(home) {
3442
3461
  return userConfigPath("pkg-excluded", { home });
3443
3462
  }
3444
3463
  function loadExcluded(home) {
3445
3464
  const path = excludedPath(home);
3446
- if (!existsSync7(path))
3465
+ if (!existsSync6(path))
3447
3466
  return {};
3448
3467
  try {
3449
3468
  const raw = JSON.parse(readFileSync5(path, "utf8"));
@@ -3466,8 +3485,8 @@ function saveExcluded(name, dirs, home) {
3466
3485
  delete excluded[name];
3467
3486
  else
3468
3487
  excluded[name] = [...dirs].toSorted();
3469
- mkdirSync3(dirname7(path), { recursive: true });
3470
- writeFileSync2(path, `${JSON.stringify(excluded, null, 2)}
3488
+ mkdirSync2(dirname7(path), { recursive: true });
3489
+ writeFileSync(path, `${JSON.stringify(excluded, null, 2)}
3471
3490
  `);
3472
3491
  }
3473
3492
  var init_excluded = __esm(() => {
@@ -3480,7 +3499,7 @@ __export(exports_bump, {
3480
3499
  ROOT_OPTION: () => ROOT_OPTION,
3481
3500
  bump: () => bump
3482
3501
  });
3483
- import { existsSync as existsSync8 } from "fs";
3502
+ import { existsSync as existsSync7 } from "fs";
3484
3503
  import { basename, dirname as dirname8, join as join11, relative as relative2 } from "path";
3485
3504
  async function lookup(name, registry, fetcher) {
3486
3505
  try {
@@ -3542,7 +3561,7 @@ async function vet(name, version, settings) {
3542
3561
  }
3543
3562
  function lockfileOf(dir, root) {
3544
3563
  for (let at = dir;; at = dirname8(at)) {
3545
- const found = ["bun.lock", "bun.lockb"].find((file) => existsSync8(join11(at, file)));
3564
+ const found = ["bun.lock", "bun.lockb"].find((file) => existsSync7(join11(at, file)));
3546
3565
  if (found !== undefined)
3547
3566
  return relative2(dir, join11(at, found));
3548
3567
  if (at === root || at === dirname8(at))
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-pkg",
3
3
  "type": "module",
4
- "version": "0.13.1",
4
+ "version": "0.13.2",
5
5
  "description": "pkg: check an npm package before it is added, for a guessed name, a version under two weeks old and install scripts.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",