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

Also handle cloneProtoObject in mergeObject #45

Merged
merged 9 commits into from
Dec 22, 2024

Conversation

segevfiner
Copy link
Contributor

@segevfiner segevfiner commented Dec 2, 2024

This fixes not being able to set an instantiated logger in options.logger using fastify-cli, as it would try to merge a prototype object, the pino.Logger.

Checklist

This fixes not being able to set an instantiated logger in `options.logger` using `fastify-cli`, as it would try to merge a prototype object, the `pino.Logger`.
@segevfiner segevfiner marked this pull request as draft December 2, 2024 13:17
@segevfiner segevfiner marked this pull request as ready for review December 2, 2024 14:49
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Thanks for opening a PR! Can you please add a unit test?

Copy link
Contributor Author

@segevfiner segevfiner left a comment

Choose a reason for hiding this comment

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

Added a test. Also fixed a bug :P

@segevfiner segevfiner requested a review from mcollina December 7, 2024 21:08
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm with a nit

test/merge-proto-objects.test.js Outdated Show resolved Hide resolved
Co-authored-by: Matteo Collina <[email protected]>
Signed-off-by: Segev Finer <[email protected]>
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@Fdawgs Fdawgs requested a review from Copilot December 8, 2024 10:41

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no suggestions.

index.js Outdated
Comment on lines 112 to 117
isNotPrototypeKey(key = sourceKeys[i]) &&
(
key in target && (targetKeys.indexOf(key) !== -1 && (result[key] = _deepmerge(target[key], source[key])), true) || // eslint-disable-line no-mixed-operators
key in target && (targetKeys.indexOf(key) !== -1 && // eslint-disable-line no-mixed-operators
((isMergeableObject(source[key]) && cloneProtoObject && Object.getPrototypeOf(source[key]) !== JSON_PROTO && (result[key] = cloneProtoObject(source[key]))) ||
(result[key] = _deepmerge(target[key], source[key]))), true) || // eslint-disable-line no-mixed-operators
(result[key] = clone(source[key]))
Copy link
Member

Choose a reason for hiding this comment

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

This is illegible. Could you refactor it into legible if or switch statements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course. Just tried to maintain the same illegible style that was used here beforehand hehe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Take a look now. Hopefully I got it right thanks to the tests. But it was truly a confusing piece of code.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I know you were just following what was laid down previously. Thank you for taking on the clean up.

@segevfiner segevfiner requested a review from jsumners December 8, 2024 17:42
@jsumners jsumners requested a review from mcollina December 9, 2024 12:13
@Fdawgs Fdawgs merged commit bc2075c into fastify:master Dec 22, 2024
16 checks passed
@Fdawgs Fdawgs mentioned this pull request Dec 22, 2024
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.

4 participants