SethEden / haystacks-sync

A basic synchronous NodeJS framework that can be easily re-used and forked to make many different kinds of apps written with ES6 syntax.
Other
2 stars 2 forks source link

Fix the prompt to work on cross-platform environments (Mac & Linux) #10

Closed SethEden closed 1 year ago

SethEden commented 2 years ago

Ensure that the prompt interface works on multi-OS environments (Mac & Linux)

SethEden commented 1 year ago

I thought it would be interesting to try and feed the code that is related to this bug into ChatGPT3 and see if it could tell me why it wasn't working for Mac or Linux. I mean I did source the relevant code from another npm prompt module in an attempt to reduce 3rd party dependencies and security vulnerabilities that kept showing up in my dependabot alerts from github, and that other npm module was working on Windows, Mac and Linux. So where did I go wrong with my implementation? Or how can the relevant code in the promptOperations.js business rules file be fixed so that it does work on Windows, Mac AND Linux? I cleaned up the code a bit and made everything hard-coded so that it would be easier for ChatGPT to understand the code as literal values.

This was the response that ChatGPT gave me back, I am commenting it here, because I thought it was insightful and could possibly lead to a solution to this problem. ChatGPT: This code uses the 'fs' module to read input from the command line, but it only works on Windows machines because it uses the 'devtty' file descriptor, which is specific to Windows and not present on Mac or Linux machines. On Mac and Linux machines, the code should use the '/dev/tty' file descriptor instead of 'devtty'. Additionally, the code uses the 'process.stdin.fd' property, which is specific to Windows and not present on Mac or Linux machines. On Mac and Linux machines, the code should use '0' as file descriptor instead of 'process.stdin.fd'.

The ChatGPT program is correct abut its first point, but I'm not sure its a relevant point because I think the code I fed it just had a type-o in how the constant for devtty is resolved. The second point seems to also be correct, so I asked ChatGPT to re-write the code for me with the recommended changes and I have pushed the recommended code changes to the promptOperations.js file on a branch with all of these comments. I believe this could be an actual solution, but it will need further testing to prove that it really does solve the cross-platform use case for Mac & Linux.