Skip to content

Commit 9f9213d

Browse files
authoredNov 13, 2021
fix: read version number from lint-staged package.json instead of package.json in cwd (#1043) (#1044)
If the package.json did not have a version number, it would cause lint-staged to crash.
1 parent 7240f61 commit 9f9213d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed
 

‎bin/lint-staged.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env node
22

33
import fs from 'fs'
4+
import path from 'path'
5+
import { fileURLToPath } from 'url'
46

57
import cmdline from 'commander'
68
import debug from 'debug'
@@ -17,7 +19,8 @@ if (supportsColor.stdout) {
1719
// Do not terminate main Listr process on SIGINT
1820
process.on('SIGINT', () => {})
1921

20-
const packageJson = JSON.parse(fs.readFileSync('package.json'))
22+
const packageJsonPath = path.join(fileURLToPath(import.meta.url), '../../package.json')
23+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath))
2124
const version = packageJson.version
2225

2326
cmdline

0 commit comments

Comments
 (0)
Please sign in to comment.