From e8390692da1abf34b9bb09ed3f1c8c8aca0648c3 Mon Sep 17 00:00:00 2001 From: Marc Huffnagle Date: Wed, 30 Aug 2023 15:56:46 -0400 Subject: [PATCH 1/4] Fix broken build Error was: TypeError: Cannot read properties of undefined (reading 'getAllComments') Occurred while linting /home/x/src/del-cli/cli.js:2 Rule: "unicorn/expiring-todo-comments" --- .github/workflows/main.yml | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d50ada6..1ed55d5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,9 +10,9 @@ jobs: fail-fast: false matrix: node-version: + - 20 - 18 - 16 - - 14 steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 diff --git a/package.json b/package.json index 507f606..970af31 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "del": "./cli.js" }, "engines": { - "node": ">=14.16" + "node": ">=16" }, "scripts": { "test": "xo && ava" @@ -57,6 +57,6 @@ "ava": "^4.3.1", "execa": "^6.1.0", "temp-write": "^5.0.0", - "xo": "^0.50.0" + "xo": "^0.56.0" } } From 66cb47d80f5443ad0a3dc29b0c4910969e52bef3 Mon Sep 17 00:00:00 2001 From: Marc Huffnagle Date: Wed, 30 Aug 2023 16:20:48 -0400 Subject: [PATCH 2/4] Revert node engine change --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 970af31..1e7ebac 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "del": "./cli.js" }, "engines": { - "node": ">=16" + "node": ">=14.16" }, "scripts": { "test": "xo && ava" From 37cefc07f5c32b06166d15ce2c522c1de77c2cf3 Mon Sep 17 00:00:00 2001 From: Marc Huffnagle <6790070+marchuffnagle@users.noreply.github.com> Date: Wed, 30 Aug 2023 20:18:22 -0400 Subject: [PATCH 3/4] Add verbose output --- cli.js | 19 ++++++++++++++++++- package.json | 2 +- readme.md | 1 + test.js | 11 +++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/cli.js b/cli.js index cf7059d..a27e2e9 100755 --- a/cli.js +++ b/cli.js @@ -3,6 +3,14 @@ import process from 'node:process'; import meow from 'meow'; import {deleteAsync} from 'del'; +const logEvent = event => { + if (event.path !== undefined) { + console.log(event.path); + } +}; + +const noop = () => {}; + const cli = meow(` Usage $ del … @@ -10,6 +18,7 @@ const cli = meow(` Options --force, -f Allow deleting the current working directory and outside --dry-run, -d List what would be deleted instead of deleting + --verbose, -v Display the absolute path of files and directories as they are deleted Examples $ del unicorn.png rainbow.png @@ -25,6 +34,10 @@ const cli = meow(` type: 'boolean', alias: 'd', }, + verbose: { + type: 'boolean', + alias: 'v', + }, }, }); @@ -32,7 +45,11 @@ if (cli.input.length === 0) { console.error('Specify at least one path'); process.exitCode = 1; } else { - const files = await deleteAsync(cli.input, cli.flags); + const {verbose, ...flags} = cli.flags; + + const onProgress = verbose ? logEvent : noop; + + const files = await deleteAsync(cli.input, {onProgress, ...flags}); if (cli.flags.dryRun) { console.log(files.join('\n')); diff --git a/package.json b/package.json index 1e7ebac..5e50428 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "cross-platform" ], "dependencies": { - "del": "^7.0.0", + "del": "^7.1.0", "meow": "^10.1.3" }, "devDependencies": { diff --git a/readme.md b/readme.md index edd6aee..1b57b4b 100644 --- a/readme.md +++ b/readme.md @@ -23,6 +23,7 @@ $ del --help Options --force, -f Allow deleting the current working directory and outside --dry-run, -d List what would be deleted instead of deleting + --verbose, -v Display the absolute path of files and directories as they are deleted Examples $ del unicorn.png rainbow.png diff --git a/test.js b/test.js index 9266673..a619a3a 100644 --- a/test.js +++ b/test.js @@ -8,3 +8,14 @@ test('main', async t => { await execa('./cli.js', ['--force', filename]); t.false(fs.existsSync(filename)); }); + +test('verbose file exists', async t => { + const filename = tempWrite.sync('foo'); + const {stdout} = await execa('./cli.js', ['--force', '--verbose', filename]); + t.is(stdout, filename); +}); + +test('verbose file does not exist', async t => { + const {stdout} = await execa('./cli.js', ['--verbose', 'does-not-exist.txt']); + t.is(stdout, ''); +}); From 8423f81f11bb9d609b6a9ff1f6974cf12e78cbc9 Mon Sep 17 00:00:00 2001 From: Marc Huffnagle <6790070+marchuffnagle@users.noreply.github.com> Date: Wed, 30 Aug 2023 20:20:43 -0400 Subject: [PATCH 4/4] Fix whitespace --- cli.js | 2 +- readme.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli.js b/cli.js index a27e2e9..9d76ac9 100755 --- a/cli.js +++ b/cli.js @@ -18,7 +18,7 @@ const cli = meow(` Options --force, -f Allow deleting the current working directory and outside --dry-run, -d List what would be deleted instead of deleting - --verbose, -v Display the absolute path of files and directories as they are deleted + --verbose, -v Display the absolute path of files and directories as they are deleted Examples $ del unicorn.png rainbow.png diff --git a/readme.md b/readme.md index 1b57b4b..35bb8bd 100644 --- a/readme.md +++ b/readme.md @@ -23,7 +23,7 @@ $ del --help Options --force, -f Allow deleting the current working directory and outside --dry-run, -d List what would be deleted instead of deleting - --verbose, -v Display the absolute path of files and directories as they are deleted + --verbose, -v Display the absolute path of files and directories as they are deleted Examples $ del unicorn.png rainbow.png