Skip to content

fix: clean up shrinkwrap code - #6998

Merged
wraithgar merged 1 commit into
latestfrom
gar/arborist-cleanup
Dec 1, 2023
Merged

fix: clean up shrinkwrap code#6998
wraithgar merged 1 commit into
latestfrom
gar/arborist-cleanup

Conversation

@wraithgar

Copy link
Copy Markdown
Contributor

Moves to @npmcli/package-json for parsing
Removes symbols in favor of private methods/attributes.
Moves "maybe" symbols to getters so they can be accessed during reset
Removes complicated nested ternaries
Inlines some single-use functions

@wraithgar
wraithgar marked this pull request as ready for review November 15, 2023 18:45
@wraithgar
wraithgar requested a review from a team as a code ownerNovember 15, 2023 18:45
Comment threadworkspaces/arborist/lib/shrinkwrap.js
Comment threadworkspaces/arborist/lib/shrinkwrap.js
Comment on lines +1006 to +1009
let spec = rSpec
if (edge) {
spec = npa.resolve(node.name, edge.spec, edge.from.realpath)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
letspec=rSpec
if(edge){
spec=npa.resolve(node.name,edge.spec,edge.from.realpath)
}
constspec=edge ? npa.resolve(node.name,edge.spec,edge.from.realpath) : rSpec

I 💯% appreciate the de-ternaryifying happenening in this PR. But that does make me want to call out that I think in this case the ternary is easier for me to read. I'm not asking for changes here, just showing my preference for the ternary operator in some cases.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Would an if/else be better here? Is it the overloading of the let declaration?

@lukekarryslukekarrysDec 1, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's mostly the order of operations. My inline suggestion is even different than the original ternary because it reverses the order. This is getting in the weeds, but I read the ternary as: if we have an edge, resolve from edge, otherwise its rSpec where the if statement I read as spec is usually rSpec, but if we have an edge, then resolve from the edge.

I think even using let spec and adding an else branch reads better to me. But when writing code like that I usually opt for the ternary because then I don't have to name another intermediate variable. I think naming fatigue is real for me, so it's not that the let declaration is overloaded, it's that I have to Name One More Thing.

I think it should be kept as you have it in the PR since it matches the rest of the file which was in need of this refactor. This was just an excuse to give a little love that I have for ternaries.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Rules are guidelines and should serve their purpose. If we find a case where ternaries are easier to read then let's do it. Use them in your prs and let's find out.

@lukekarrys

Copy link
Copy Markdown
Contributor

Approved with take-it-or-leave-it comments.

@wraithgar

Copy link
Copy Markdown
ContributorAuthor

Gonna land as-is and we can shave the ternary operator yak in a chatroom somewhere.

@wraithgar
wraithgar merged commit f875caa into latestDec 1, 2023
@wraithgar
wraithgar deleted the gar/arborist-cleanup branch December 1, 2023 20:39
@github-actionsgithub-actionsBot mentioned this pull request Dec 1, 2023
Sign up for freeto 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.

2 participants

@wraithgar@lukekarrys