Skip to content

Commit c76a7d2

Browse files
committed
use package-json-from-dist to look up package.json
1 parent 3cb1ed7 commit c76a7d2

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

package-lock.json

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

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"jackspeak": "^3.1.2",
7272
"minimatch": "^9.0.4",
7373
"minipass": "^7.1.2",
74+
"package-json-from-dist": "^1.0.0",
7475
"path-scurry": "^1.11.1"
7576
},
7677
"devDependencies": {

src/bin.mts

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
11
#!/usr/bin/env node
22
import { foregroundChild } from 'foreground-child'
33
import { existsSync } from 'fs'
4-
import { readFile } from 'fs/promises'
54
import { jack } from 'jackspeak'
5+
import { loadPackageJson } from 'package-json-from-dist'
66
import { join } from 'path'
7-
import { fileURLToPath } from 'url'
87
import { globStream } from './index.js'
98

10-
/* c8 ignore start */
11-
const { version } = JSON.parse(
12-
await readFile(
13-
fileURLToPath(new URL('../../package.json', import.meta.url)),
14-
'utf8',
15-
).catch(() =>
16-
readFile(
17-
fileURLToPath(new URL('../../package.json', import.meta.url)),
18-
'utf8',
19-
),
20-
),
21-
) as { version: string }
22-
/* c8 ignore stop */
9+
const { version } = loadPackageJson(import.meta.url, '../package.json')
2310

2411
const j = jack({
2512
usage: 'glob [options] [<pattern> [<pattern> ...]]',

test/bin.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { spawn, SpawnOptions } from 'child_process'
2+
import { readFileSync } from 'fs'
23
import { sep } from 'path'
34
import t from 'tap'
45
import { fileURLToPath } from 'url'
5-
import pkg from '../package.json' assert { type: 'json' }
6-
const { version } = pkg
6+
const { version } = JSON.parse(
7+
readFileSync(
8+
fileURLToPath(new URL('../package.json', import.meta.url)),
9+
'utf8',
10+
),
11+
)
712
const bin = fileURLToPath(new URL('../dist/esm/bin.mjs', import.meta.url))
813

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

0 commit comments

Comments
 (0)