Skip to content

Commit

Permalink
use package-json-from-dist to look up package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jun 19, 2024
1 parent 3cb1ed7 commit c76a7d2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"jackspeak": "^3.1.2",
"minimatch": "^9.0.4",
"minipass": "^7.1.2",
"package-json-from-dist": "^1.0.0",
"path-scurry": "^1.11.1"
},
"devDependencies": {
Expand Down
17 changes: 2 additions & 15 deletions src/bin.mts
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
#!/usr/bin/env node
import { foregroundChild } from 'foreground-child'
import { existsSync } from 'fs'
import { readFile } from 'fs/promises'
import { jack } from 'jackspeak'
import { loadPackageJson } from 'package-json-from-dist'
import { join } from 'path'
import { fileURLToPath } from 'url'
import { globStream } from './index.js'

/* c8 ignore start */
const { version } = JSON.parse(
await readFile(
fileURLToPath(new URL('../../package.json', import.meta.url)),
'utf8',
).catch(() =>
readFile(
fileURLToPath(new URL('../../package.json', import.meta.url)),
'utf8',
),
),
) as { version: string }
/* c8 ignore stop */
const { version } = loadPackageJson(import.meta.url, '../package.json')

const j = jack({
usage: 'glob [options] [<pattern> [<pattern> ...]]',
Expand Down
9 changes: 7 additions & 2 deletions test/bin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { spawn, SpawnOptions } from 'child_process'
import { readFileSync } from 'fs'
import { sep } from 'path'
import t from 'tap'
import { fileURLToPath } from 'url'
import pkg from '../package.json' assert { type: 'json' }
const { version } = pkg
const { version } = JSON.parse(
readFileSync(
fileURLToPath(new URL('../package.json', import.meta.url)),
'utf8',
),
)
const bin = fileURLToPath(new URL('../dist/esm/bin.mjs', import.meta.url))

t.cleanSnapshot = s => s.split(version).join('{VERSION}')
Expand Down

0 comments on commit c76a7d2

Please sign in to comment.