-
Notifications
You must be signed in to change notification settings - Fork 244
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
Limit requireCordovaModule
to Cordova modules
#689
Comments
requireCordovaModule
to Cordova modules
After #706, I'm beginning to think we should consider rolling out the deprecation step even earlier than the next major. |
I would personally favor starting the deprecation now and limiting |
Shouldn't we consider dropping support for |
I'm not sure what you mean by In case you meant we should drop the method altogether: I actually considered that. But as long as the predominant usage of That being said, I would prefer that people require |
- Throw error if non-cordova module is required (Resolves #689) - Remove outdated compatibility layer from 2015 - Lazily load Context.cordova to avoid cyclical dependency - Use const for imports
The Context
The context provided to hooks has a method called
requireCordovaModule
.cordova-lib/src/hooks/Context.js
Lines 50 to 72 in 1bc9dd0
The apparent purpose of this method is to allow users to require modules of the exact version of Cordova that is running the hook. I guess that makes some sense, given how we currently use the Node module system to provide singletons.
The Problem
However, this method conceptually leaks all internals of
cordova-lib
, including any of its dependencies, to the hooks context. In fact, the only documentation on this method even encourages users to use it to require Q, which we could break, if we removed Q from our dependencies as part of #681. I can see how this might have seemed like a great idea when promises weren't available in native JS, but that has thankfully changed now.The Solution
I suggest we limit the modules allowed to import using
Context.prototype.requireCordovaModule
to a fixed whitelist containing onlycordova-*
dependencies ofcordova-lib
andcordova-lib
itself.As a first step, we should only issue a deprecation warning if anything not on the whitelist is required.
As an additional safety measure, we might warn users about using private interfaces when they deep-require something (like
require('cordova-lib/src/hooks/Context')
for example).What do you think? I'm looking forward to your feedback.
The text was updated successfully, but these errors were encountered: