From 9f9213d5fbc74e3c3fb11db2a1bd239888c2960c Mon Sep 17 00:00:00 2001 From: Michael Coleman Date: Sat, 13 Nov 2021 16:27:02 -0500 Subject: [PATCH] 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. --- bin/lint-staged.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/lint-staged.js b/bin/lint-staged.js index 6770b9626..7b52b0899 100755 --- a/bin/lint-staged.js +++ b/bin/lint-staged.js @@ -1,6 +1,8 @@ #!/usr/bin/env node import fs from 'fs' +import path from 'path' +import { fileURLToPath } from 'url' import cmdline from 'commander' import debug from 'debug' @@ -17,7 +19,8 @@ if (supportsColor.stdout) { // Do not terminate main Listr process on SIGINT process.on('SIGINT', () => {}) -const packageJson = JSON.parse(fs.readFileSync('package.json')) +const packageJsonPath = path.join(fileURLToPath(import.meta.url), '../../package.json') +const packageJson = JSON.parse(fs.readFileSync(packageJsonPath)) const version = packageJson.version cmdline