Skip to content

Conversation

2colours
Copy link
Contributor

Read v4 declares a dependency on Node v18 at least and the bundled Node version is v16.0.0 still. The modifications aren't big but that upgrade would be the way even further. Other than that, this package didn't change a lot. It's supposed to "just work" if one exports the read function appropriately (not as a "default" import), with an async interface that we pretty much already had because of the promptX kind of methods.

Read v4 declares a dependency on Node v18 at least and the bundled Node version is v16.0.0 still. The modifications aren't big but that upgrade would be the way even further.
Other than that, this package didn't change a lot. It's supposed to "just work" if one exports the `read` function appropriately (not as a "default" import), with an async interface that we pretty much already had because of the promptX kind of methods.
@2colours 2colours reopened this Feb 20, 2025
Copy link
Contributor

@mauricioszabo mauricioszabo left a comment

Choose a reason for hiding this comment

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

👏

@DeeDeeG
Copy link
Member

DeeDeeG commented Mar 16, 2025

This removes error handling. read() can possibly error, and its usage documentation suggests to put it in a try/catch: https://github.com/npm/read/blob/main/README.md#usage

const { read } = require('read')
// or with ESM: import { read } from 'read'
try {
  const result = await read(options)
} catch (er) {
  console.error(er)
}

With ppm's code assuming a default "yes" answer from the user here, and then going on to do possibly sensitive things such as installing packages, I think its safer to error out than continue if read() didn't work.

Per StackOverflow (https://stackoverflow.com/questions/42453683/how-to-reject-in-async-await-syntax), we can try/catch and throw the error to make the async function we are in return a rejected promise with the error from read()... like this?:

      let answer;
      try {
        answer = await read({prompt: 'Would you like to install these updates? (yes)', edit: true});
      } catch (error) {
        throw(error);
      }

Or add a .catch( . . . ) to the read() call like:

      let answer = await read({prompt: 'Would you like to install these updates? (yes)', edit: true}).catch(error => throw(error));

Something like that.

Perhaps I can investigate the right way to restore error handing myself, but you are also free to attempt it.

@DeeDeeG
Copy link
Member

DeeDeeG commented Mar 17, 2025

My suggestion above was discussed on Discord, and it was pointed out to behave equivalently with or without try/catch. I can confirm that is true in my own testing now.

There is minimal logging of the error in this situation regardless, it looks like this if throwing just before read() would have been called in upgrade.js on this branch, or rejecting the promise just before read() would have been called on master branch:

% ./bin/ppm upgrade deedeeg-new-package-1
Package Updates Available (1)
└── deedeeg-new-package-1 0.0.1 -> 0.0.9

some error string (this is red)

Since it's the same as before this PR, there is no issue. Thanks for bearing with me while I test things locally.

Copy link
Member

@DeeDeeG DeeDeeG left a comment

Choose a reason for hiding this comment

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

Code looks reasonable, moreso after discussion on Discord. I confirmed it behaves equivalently, and it is functional (upgrading my package on the CLI works) just the same as master branch.

So, Approved from me as well. Merging. Thanks for the dependency bumps lately.

@DeeDeeG DeeDeeG merged commit a6f843f into pulsar-edit:master Mar 17, 2025
21 checks passed
@2colours 2colours deleted the upgrade-read-v3 branch March 17, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants