Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite publish logic #132

Merged
merged 17 commits into from
May 28, 2024
Merged

Rewrite publish logic #132

merged 17 commits into from
May 28, 2024

Conversation

confused-Techie
Copy link
Member

After numerous issues and reports and pain points of this publish logic, we hit a point after enabling strict versioning on the backend to discover that the original logic completely fails now.

I'll try to update this with more details with more time, but for now, here's an attempt that should resolve our woes.

@DeeDeeG
Copy link
Member

DeeDeeG commented May 27, 2024

Posting this feedback from the Discord thread, in case it gets lost otherwise:


ppm publish --tag isn't working with this branch:

% ~/ppm/bin/ppm publish --tag v0.3.0
A version, tag, or new package name is required

Working on master branch:

% ~/ppm/bin/ppm publish --tag v0.3.0
Publishing deedeeg-my-package-10982367019823@v0.3.0 ✓

Sadly it's seeming like we might not have any unit tests for this?

@DeeDeeG
Copy link
Member

DeeDeeG commented May 27, 2024

Speaking of which, the Discord thread: https://discord.com/channels/992103415163396136/1241217301529886853

And the start of the recent round of discussion around this topic, preceding the formal Discord thread about it by a bit: https://discord.com/channels/992103415163396136/992109539346370661/1240836443299905606

src/publish.js Outdated
let originalName;
if (version?.length <= 0) { version = 'patch'; }
if (rename?.length > 0) { originalName = pack.name; }
if (version?.length === 0 && tag?.length === 0 && rename?.length === 0) {
Copy link
Member

@DeeDeeG DeeDeeG May 28, 2024

Choose a reason for hiding this comment

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

I think it would be a benefit to know this is somehow still ending up undefined (despite the normalization we're doing) sooner, due to undefined.length giving an error Uncaught TypeError: Cannot read properties of undefined (reading 'length').

Rather than end up silently doing some tricky comparisons of undefined vs 0 (undefined === 0 specifically, which would be false, seeming to imply that the length is greater than 1 as it's "not 0", which I think puts us on the wrong code flow path in the if, right?)

Suggested change
if (version?.length === 0 && tag?.length === 0 && rename?.length === 0) {
if (version.length === 0 && tag.length === 0 && rename.length === 0) {

Sort of theoretical, since it shouldn't be possible.

But also, I like to avoid more complicated syntax if it's not needed, for ease of reading.

Also: Given the head-scratcher this issue was to solve, correctness and surfacing error messages in as straight-forward a way as possible is kind of my top priority, rather than avoiding errors in this case. Unless we want to try/catch and print the error and exit gracefully, but... I don't think that helps anything anyway in this case.

tl;dr: Hitting a simple error message would be better than not hitting it, in this case, I think? So, optional chaining not a benefit here?

Not a blocker, since it should all be hypothetical with all the normalizing done in this PR. But the goose-chase tracking down strange behavior makes me a tad paranoid, not gonna lie.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for all the nitpicking, just inclined to make this code very tidy if possible after what had to be thought through to get here.

Copy link
Member

Choose a reason for hiding this comment

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

Note: If moving away from optional chaining for the varName.length checks, there are three more in the diff for this PR, I just didn't individually comment them all.

Copy link
Member

@DeeDeeG DeeDeeG May 28, 2024

Choose a reason for hiding this comment

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

P.S. I suppose these instances of optional chaining mirror what was there before this PR, but while we're addressing tiny subtleties of behavior that were unintuitive, I think it's worth deciding whether to move away from the optional chaining or not.

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.

Giving the ol' "Approve with optional feedback".

Looks Good to Me, tested thoroughly in the linked Discord thread. Worked for both of us on separate machines, should be in good shape now. 👍

if (code === 0) {
if (code !== 0) {
Copy link
Member

@DeeDeeG DeeDeeG May 28, 2024

Choose a reason for hiding this comment

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

Just commentary, no action needed:

Kind of odd to see that this check was coded wrong from before this PR, I believe it was inadvertently changed as part of the utterly massive promisification PRs, from looking at the blame history.

This change seems legit. All other calls to logFailure() are when code !== 0, as in error code rather than clean exit code. So yeah, seems legit IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

Was surprised to see this one broken for so long tbh

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.

Approving, since this fixes the various intended use-cases, such as ppm publish patch for a first publish, while keeping --tag working, and fixing --rename which may have been broken for some time on master branch.

Might be a good idea either in this PR to do a follow-up to handle invalid combos of CLI args, such as doing patch, --tag, and --rename all at once? But I'm not sure that's actually invalid or if someone could intentionally do something useful with combining them? So, this is optional to address, IMO. We can tell people to do just one at a time without having the code print an error message about it for now?

If you do limit to only one of them being set at a time, that could be reasonable, but honestly I think it's good enough for now without that as well.

@confused-Techie
Copy link
Member Author

Thanks for the approval, gonna go ahead and merge this one for now, then we just gotta get it updated in pulsar sometime soon

@confused-Techie confused-Techie marked this pull request as ready for review May 28, 2024 07:08
@confused-Techie confused-Techie merged commit 3542dee into master May 28, 2024
11 checks passed
@confused-Techie confused-Techie deleted the refactor-publication-logic branch May 28, 2024 07:09
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.

None yet

2 participants