@kaynooo/cli-pkg 0.9.0 → 0.10.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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/dist/cli.js +23 -14
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -28,6 +28,7 @@ pkg outdated
28
28
  ```
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
+ - `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`.
31
32
  - `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.
32
33
 
33
34
  ## Auditing a lockfile
package/dist/cli.js CHANGED
@@ -1177,25 +1177,28 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
1177
1177
  } };
1178
1178
  const write = stream.write.bind(stream);
1179
1179
  let frame = 0;
1180
- let drawn = 0;
1180
+ let drawn = [];
1181
+ const columns = () => stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns;
1182
+ const rowsDrawn = () => drawn.reduce((sum, width) => sum + Math.max(1, Math.ceil(width / columns())), 0);
1181
1183
  const clear = () => {
1182
- if (drawn > 0)
1183
- write(`${CLEAR_LINE}${LINE_UP.repeat(drawn - 1)}`);
1184
- drawn = 0;
1184
+ if (drawn.length > 0)
1185
+ write(`${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}`);
1186
+ drawn = [];
1185
1187
  };
1186
1188
  const draw = () => {
1187
- const width = (stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns) - 1;
1189
+ const width = columns() - 1;
1188
1190
  const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
1189
1191
  const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
1190
1192
  if (lines.length === 0) {
1191
1193
  clear();
1192
1194
  return;
1193
1195
  }
1194
- write(`${drawn > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(drawn - 1)}` : CLEAR_LINE}${lines.join(`
1196
+ write(`${drawn.length > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}` : CLEAR_LINE}${lines.join(`
1195
1197
  `)}`);
1196
- drawn = lines.length;
1198
+ drawn = lines.map((line) => Bun.stringWidth(line));
1197
1199
  };
1198
1200
  const timer = setInterval(draw, FRAME_MS);
1201
+ stream.on?.("resize", draw);
1199
1202
  const restore = interceptOutput(clear);
1200
1203
  const release = swallowInput();
1201
1204
  const onExit = () => {
@@ -1205,6 +1208,7 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
1205
1208
  const signals = holdSignals(stop);
1206
1209
  function stop() {
1207
1210
  clearInterval(timer);
1211
+ stream.off?.("resize", draw);
1208
1212
  clear();
1209
1213
  restore();
1210
1214
  release();
@@ -2732,6 +2736,8 @@ function parseSettings(text) {
2732
2736
  settings.licenses = raw.licenses;
2733
2737
  if (isSeverity(raw?.blockSeverity))
2734
2738
  settings.blockSeverity = raw.blockSeverity;
2739
+ if (typeof raw?.minAge === "number" && Number.isInteger(raw.minAge) && raw.minAge >= 0)
2740
+ settings.minAge = raw.minAge;
2735
2741
  return settings;
2736
2742
  }
2737
2743
  async function loadSettings(cwd = process17.cwd(), home) {
@@ -2747,6 +2753,7 @@ async function loadSettings(cwd = process17.cwd(), home) {
2747
2753
  const found = readable(file, () => parseSettings(text));
2748
2754
  settings.licenses ??= found.licenses;
2749
2755
  settings.blockSeverity ??= found.blockSeverity;
2756
+ settings.minAge ??= found.minAge;
2750
2757
  }
2751
2758
  return settings;
2752
2759
  }
@@ -3017,7 +3024,8 @@ async function check(args) {
3017
3024
  fail(values.from === undefined ? `a package name is needed
3018
3025
 
3019
3026
  ${usage2}` : `${values.from} has no registry dependency to check`);
3020
- const context = { configs: await loadConfigs(), settings: await loadSettings(), minAgeDays: wholeNumber(values["min-age"], "min-age", DEFAULT_MIN_AGE_DAYS, 0) };
3027
+ const settings = await loadSettings();
3028
+ const context = { configs: await loadConfigs(), settings, minAgeDays: wholeNumber(values["min-age"], "min-age", settings.minAge ?? DEFAULT_MIN_AGE_DAYS, 0) };
3021
3029
  const reports = await Promise.all(positionals.map(async (text) => checkPackage(text, context)));
3022
3030
  if (values.json === true)
3023
3031
  printJson(reports.length === 1 ? reports[0] : reports);
@@ -3044,7 +3052,7 @@ var init_check = __esm(() => {
3044
3052
  EXITS = [[0, "every package passes"], [1, "one is blocked: missing, the version asked for is under the minimum age or has no date, its licence is outside the allowlist or an advisory reaches the threshold"], [2, "it could not check (the registry unreachable, slow or answering badly, a broken .pkgrc.json, bunfig.toml or .npmrc) or a usage error"]];
3045
3053
  options = {
3046
3054
  json: jsonOption(),
3047
- "min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS})` },
3055
+ "min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS}, or the minAge setting)` },
3048
3056
  from: { type: "string", description: "check the dependencies of this package.json" }
3049
3057
  };
3050
3058
  WORDS = /\s+/;
@@ -3184,10 +3192,11 @@ async function audit(args) {
3184
3192
  const text = await lock.text();
3185
3193
  const production = values.prod === true ? productionPackages(text) : undefined;
3186
3194
  const packages = parseBunLock(text).filter(({ name, version }) => production?.has(`${name}@${version}`) ?? true);
3195
+ const settings = await loadSettings(dir);
3187
3196
  const context = {
3188
3197
  configs: await loadConfigs(dir),
3189
- settings: await loadSettings(dir),
3190
- minAgeDays: wholeNumber(values["min-age"], "min-age", DEFAULT_MIN_AGE_DAYS, 0),
3198
+ settings,
3199
+ minAgeDays: wholeNumber(values["min-age"], "min-age", settings.minAge ?? DEFAULT_MIN_AGE_DAYS, 0),
3191
3200
  level,
3192
3201
  ignore: values.ignore ?? []
3193
3202
  };
@@ -3218,7 +3227,7 @@ var init_audit = __esm(() => {
3218
3227
  EXITS2 = [[0, "nothing blocks"], [1, "a package is missing, too fresh or outside the licence allowlist, or an advisory reaches --level"], [2, "the registry could not be reached or answered badly (a warning says which, and nothing is reported as clean), a usage error or no bun.lock"]];
3219
3228
  options2 = {
3220
3229
  json: jsonOption("[{name, version, license, blocked, warnings, advisories}] for the packages with a finding"),
3221
- "min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS})` },
3230
+ "min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS}, or the minAge setting)` },
3222
3231
  level: { type: "string", description: "lowest advisory severity listed and failing: low, moderate, high, critical (moderate)" },
3223
3232
  prod: { type: "boolean", description: "only the packages a production dependency or an optional one of a workspace reaches" },
3224
3233
  ignore: { type: "string", multiple: true, description: "an advisory skipped by GHSA or numeric id, repeatable" }
@@ -3270,7 +3279,7 @@ async function outdatedCommand(args) {
3270
3279
  fail(`no package.json in ${folder}`);
3271
3280
  const lockPath = join10(folder, "bun.lock");
3272
3281
  const locked = existsSync6(lockPath) ? parseBunLock(await Bun.file(lockPath).text()) : [];
3273
- const rows = await outdated(await manifest.text(), { minAgeDays: wholeNumber(values["min-age"], "min-age", DEFAULT_MIN_AGE_DAYS, 0), locked });
3282
+ const rows = await outdated(await manifest.text(), { minAgeDays: wholeNumber(values["min-age"], "min-age", (await loadSettings(folder)).minAge ?? DEFAULT_MIN_AGE_DAYS, 0), locked });
3274
3283
  const { shown, footer } = capped(rows, limitOf(values, OUTDATED_LIMIT));
3275
3284
  if (values.json === true)
3276
3285
  printJson(shown);
@@ -3296,7 +3305,7 @@ var init_outdated = __esm(() => {
3296
3305
  FIRST_VERSION = /\d+(?:\.\d+){0,2}(?:-[\w.-]+)?/;
3297
3306
  DOT = /[.-]/;
3298
3307
  options3 = {
3299
- "min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS})` },
3308
+ "min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS}, or the minAge setting)` },
3300
3309
  ...limitOptions(OUTDATED_LIMIT),
3301
3310
  json: jsonOption("[{name, kind, spec, current, safe, change, published, latest?}]")
3302
3311
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-pkg",
3
3
  "type": "module",
4
- "version": "0.9.0",
4
+ "version": "0.10.0",
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",
@@ -30,6 +30,6 @@
30
30
  "record": "$npm_execpath scripts/record.ts"
31
31
  },
32
32
  "devDependencies": {
33
- "@kaynooo/cli-kit": "0.23.0"
33
+ "@kaynooo/cli-kit": "0.25.0"
34
34
  }
35
35
  }