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

handle initially null driver when instantiating Mongoose for Rollup support #14577

Merged
merged 2 commits into from
May 9, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #12335

Summary

lib/index.js and lib/mongoose.js contain the significant changes here. The issue is that, because of how Rollup hoists imports when you don't set strictRequires: true, the setDriver() call in lib/mongoose.js will always run after the Mongoose singleton is initialized in lib/index.js. So the Mongoose constructor needs to handle null driver case, and lib/mongoose.js needs to call setDriver() to make sure the driver change propagates to the newly created Mongoose singleton.

In regular Node.js, that second setDriver() call is a no-op because setDriver() checks to see if new driver is === old driver.

On a related note, I also cleaned up some circular imports in lib/error/*.js. lib/error/index.js imports lib/error/cast.js and lib/error/cast.js imports lib/error/index.js. I was trying to see if cleaning up circular imports would help with Rollup support, but experimentation and further reading convinced me that it wasn't necessary for Rollup support. But still a nice to have since fixing the circular import is a bunch of one-liners.

Examples

@vkarpov15 vkarpov15 added this to the 8.4 milestone May 7, 2024
@vkarpov15 vkarpov15 merged commit 55564e1 into 8.4 May 9, 2024
34 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-12335 branch May 9, 2024 15:18
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