Skip to content

Commit

Permalink
load version with package-json-from-dist
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jul 10, 2024
1 parent 6de86bf commit d3881ad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 3 additions & 7 deletions src/bin.mts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -54,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<string>(res => rl.question(q, res))
Expand Down

0 comments on commit d3881ad

Please sign in to comment.