From f8b2dcead7b1001d10f3ad5050304090a1f39898 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 5 Apr 2024 18:25:30 +0200 Subject: [PATCH] feat: add a `--fix` option Fixes #89 --- README.md | 3 +++ cli.js | 7 ++++++- package.json | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 18fb93e..09b2b4b 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,9 @@ Use [installed-check-core](https://github.com/voxpelli/node-installed-check-core * `--ignore-dev` / `-d` – if set then dev dependencies won't be included in the non-version checks. * `--strict` / `-s` – treats warnings as errors +## Fix options + * `--fix` – tries to apply all suggestions and write them back to disk + ## Workspace options * `--no-include-workspace-root` – excludes the workspace root package. Negated equivalent of npm's [`--include-workspace-root`](https://docs.npmjs.com/cli/v10/commands/npm-run-script#include-workspace-root) diff --git a/cli.js b/cli.js index ba99f17..4ae039d 100755 --- a/cli.js +++ b/cli.js @@ -25,6 +25,9 @@ const cli = meow(` -d, --ignore-dev Excludes dev dependencies from non-version checks -s, --strict Treat warnings as errors + Fix options + --fix Tries to apply all suggestions and write them back to disk + Workspace options --no-include-workspace-root Will exclude the workspace root package --no-workspaces Will exclude workspace packages @@ -45,6 +48,7 @@ const cli = meow(` engineCheck: { shortFlag: 'e', type: 'boolean' }, engineIgnore: { type: 'string', isMultiple: true }, engineNoDev: { type: 'boolean' }, + fix: { type: 'boolean' }, ignore: { shortFlag: 'i', type: 'string', isMultiple: true }, ignoreDev: { shortFlag: 'd', type: 'boolean' }, includeWorkspaceRoot: { type: 'boolean', 'default': true }, @@ -69,6 +73,7 @@ const { engineCheck, engineIgnore, // deprecated engineNoDev, // deprecated + fix = false, includeWorkspaceRoot, peerCheck, strict, @@ -129,7 +134,7 @@ if (debug) { } try { - const result = await installedCheck(checks, lookupOptions, checkOptions); + const result = await installedCheck(checks, lookupOptions, { ...checkOptions, fix }); if (verbose && result.warnings.length) { console.log('\n' + chalk.bgYellow.black('Warnings:') + '\n\n' + result.warnings.join('\n') + '\n'); diff --git a/package.json b/package.json index 8d1ff7f..260467e 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ }, "dependencies": { "chalk": "^5.3.0", - "installed-check-core": "^8.2.3", + "installed-check-core": "^8.3.0", "meow": "^12.1.1", "pony-cause": "^2.1.10", "version-guard": "^1.1.1"