Skip to content

Commit d3881ad

Browse files
committed
load version with package-json-from-dist
1 parent 6de86bf commit d3881ad

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

package-lock.json

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
"node": "20 || >=22"
7373
},
7474
"dependencies": {
75-
"glob": "^11.0.0"
75+
"glob": "^11.0.0",
76+
"package-json-from-dist": "^1.0.0"
7677
},
7778
"keywords": [
7879
"rm",

src/bin.mts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#!/usr/bin/env node
2-
import { readFile } from 'fs/promises'
32
import type { RimrafAsyncOptions } from './index.js'
43
import { rimraf } from './index.js'
54

6-
const pj = fileURLToPath(new URL('../package.json', import.meta.url))
7-
const pjDist = fileURLToPath(new URL('../../package.json', import.meta.url))
8-
const { version } = JSON.parse(
9-
await readFile(pjDist, 'utf8').catch(() => readFile(pj, 'utf8')),
10-
) as { version: string }
5+
import { loadPackageJson } from 'package-json-from-dist'
6+
7+
const { version } = loadPackageJson(import.meta.url, '../package.json')
118

129
const runHelpForUsage = () =>
1310
console.error('run `rimraf --help` for usage information')
@@ -54,7 +51,6 @@ const cwd = process.cwd()
5451

5552
import { Dirent, Stats } from 'fs'
5653
import { createInterface, Interface } from 'readline'
57-
import { fileURLToPath } from 'url'
5854

5955
const prompt = async (rl: Interface, q: string) =>
6056
new Promise<string>(res => rl.question(q, res))

0 commit comments

Comments
 (0)