diff --git a/.gitignore b/.gitignore index 3c8bd513..5ae2c2bf 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /.nyc_output /coverage /dist +/.tap !/typedoc.json !/tsconfig-*.json !/.prettierignore diff --git a/CHANGELOG.md b/CHANGELOG.md index 2304bbc2..eb80bcb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 6.0 - Drop support for nodes before v20 +- Add `--version` to CLI # 5.0 diff --git a/README.md b/README.md index 7ab1a5d6..5a30f68e 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,11 @@ Install with `npm install rimraf`. ## Major Changes +### v5 to v6 + +- Require node `20` or `>=22` +- Add `--version` to CLI + ### v4 to v5 - There is no default export anymore. Import the functions directly @@ -178,7 +183,7 @@ Synchronous form of `rimraf.moveRemove()` ### Command Line Interface ``` -rimraf version 4.3.0 +rimraf version 6.0.1 Usage: rimraf [ ...] Deletes all files and folders at "path", recursively. @@ -186,6 +191,7 @@ Deletes all files and folders at "path", recursively. Options: -- Treat all subsequent arguments as paths -h --help Display this usage info + --version Display version --preserve-root Do not remove '/' recursively (default) --no-preserve-root Do not treat '/' specially -G --no-glob Treat arguments as literal paths, not globs (default) diff --git a/package-lock.json b/package-lock.json index fd09380e..a9dfa573 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { "name": "rimraf", - "version": "6.0.0", + "version": "6.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rimraf", - "version": "6.0.0", + "version": "6.0.1", "license": "ISC", "dependencies": { - "glob": "^11.0.0" + "glob": "^11.0.0", + "package-json-from-dist": "^1.0.0" }, "bin": { "rimraf": "dist/esm/bin.mjs" diff --git a/package.json b/package.json index 6073aa7e..68b06e17 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rimraf", - "version": "6.0.0", + "version": "6.0.1", "type": "module", "tshy": { "main": true, @@ -72,7 +72,8 @@ "node": "20 || >=22" }, "dependencies": { - "glob": "^11.0.0" + "glob": "^11.0.0", + "package-json-from-dist": "^1.0.0" }, "keywords": [ "rm", diff --git a/src/bin.mts b/src/bin.mts index db47b660..3727ecf7 100755 --- a/src/bin.mts +++ b/src/bin.mts @@ -1,13 +1,10 @@ #!/usr/bin/env node -import { readFile } from 'fs/promises' import type { RimrafAsyncOptions } from './index.js' import { rimraf } from './index.js' -const pj = fileURLToPath(new URL('../package.json', import.meta.url)) -const pjDist = fileURLToPath(new URL('../../package.json', import.meta.url)) -const { version } = JSON.parse( - await readFile(pjDist, 'utf8').catch(() => readFile(pj, 'utf8')), -) as { version: string } +import { loadPackageJson } from 'package-json-from-dist' + +const { version } = loadPackageJson(import.meta.url, '../package.json') const runHelpForUsage = () => console.error('run `rimraf --help` for usage information') @@ -20,6 +17,7 @@ Deletes all files and folders at "path", recursively. Options: -- Treat all subsequent arguments as paths -h --help Display this usage info + --version Display version --preserve-root Do not remove '/' recursively (default) --no-preserve-root Do not treat '/' specially -G --no-glob Treat arguments as literal paths, not globs (default) @@ -53,7 +51,6 @@ const cwd = process.cwd() import { Dirent, Stats } from 'fs' import { createInterface, Interface } from 'readline' -import { fileURLToPath } from 'url' const prompt = async (rl: Interface, q: string) => new Promise(res => rl.question(q, res)) @@ -158,6 +155,9 @@ const main = async (...args: string[]) => { } else if (arg === '-h' || arg === '--help') { console.log(help) return 0 + } else if (arg === '--version') { + console.log(version) + return 0 } else if (arg === '--interactive' || arg === '-i') { interactive = true continue @@ -258,6 +258,7 @@ const main = async (...args: string[]) => { return 0 } main.help = help +main.version = version export default main diff --git a/test/bin.ts b/test/bin.ts index fcfbbe3f..665f92c8 100644 --- a/test/bin.ts +++ b/test/bin.ts @@ -50,6 +50,19 @@ t.test('basic arg parsing stuff', async t => { CALLS.length = 0 }) + t.test('binary version', t => { + const cases = [['--version'], ['a', 'b', '--version', 'c']] + for (const c of cases) { + t.test(c.join(' '), async t => { + t.equal(await bin(...c), 0) + t.same(LOGS, [[bin.version]]) + t.same(ERRS, []) + t.same(CALLS, []) + }) + } + t.end() + }) + t.test('helpful output', t => { const cases = [['-h'], ['--help'], ['a', 'b', '--help', 'c']] for (const c of cases) {