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

fix: clean up shrinkwrap code #6998

Merged
merged 1 commit into from
Dec 1, 2023
Merged

fix: clean up shrinkwrap code #6998

merged 1 commit into from
Dec 1, 2023

Conversation

wraithgar
Copy link
Member

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 owner November 15, 2023 18:45
workspaces/arborist/lib/shrinkwrap.js Show resolved Hide resolved
workspaces/arborist/lib/shrinkwrap.js Show resolved Hide resolved
Comment on lines +1006 to +1009
let spec = rSpec
if (edge) {
spec = npa.resolve(node.name, edge.spec, edge.from.realpath)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let spec = rSpec
if (edge) {
spec = npa.resolve(node.name, edge.spec, edge.from.realpath)
}
const spec = 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
Member Author

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?

Copy link
Contributor

@lukekarrys lukekarrys Dec 1, 2023

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
Member Author

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
Contributor

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

@wraithgar
Copy link
Member Author

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

@wraithgar wraithgar merged commit f875caa into latest Dec 1, 2023
20 checks passed
@wraithgar wraithgar deleted the gar/arborist-cleanup branch December 1, 2023 20:39
@github-actions github-actions bot mentioned this pull request Dec 1, 2023
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.

2 participants