Skip to content

Conversation

matt-oakes
Copy link

Fixes #2972.

This PR fixes the reading of the package.json for the @serialport/list and @serialport/terminal packages.

The issue was that is was attempting to read one level up from the current working directory, rather than from the location of the javascript file. This was causing it to not be able to find the file, or find the wrong file.

The fix is to use __dirname to get the full path to the javascript files location so we can construct a full path to the package.json file to read it.

@vicovaro
Copy link

Oh wait I did a duplicate Pull Request for the same problem... #3070

@@ -4,7 +4,7 @@ import { autoDetect, PortInfo } from '@serialport/bindings-cpp'
import { program, Option } from 'commander'
import { readFileSync } from 'node:fs'

const { version } = JSON.parse(readFileSync('../package.json', 'utf8'))
const { version } = JSON.parse(readFileSync(__dirname + '/../package.json', 'utf8'))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I humbly submit it might be better to use path.join(__dirname, '..', 'package.json');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

@serialport/list, @serialport/terminal requires 'package.json' to run
3 participants