-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
POC: webpack-based automatic refactoring of bid adapters #7705
Conversation
This adds build preprocessing that replaces certain import declaration in adapters' source files. The idea is to automatically "refactor" them to allow components like config or storageManager to always know who the bidder calling them is.
CircleCI is failing to understand the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You added more than 30K lines in package-lock.json
file, is this really needed?
Source maps are not working properly (like you already mentioned in your comment), which would make pbjs harder to debug.
I do understand meaning of this POC (although, not entirely, I'm still not sure why you would fail when bidder imports config
). You want to make sure that all bidders have passed their name in getStorageManager
function?
But, why doing this at runtime? I think we can add some custom build (or lint) rule that says bid adapter must pass arguments in getStorageManager
function. And if that doesn't happen then build (or lint) will fail.
What do you think?
@@ -3,11 +3,11 @@ | |||
# Check https://circleci.com/docs/2.0/language-javascript/ for more details | |||
# | |||
|
|||
aliases: | |||
aliases: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CircleCI updates should be in separate PR
export function configFactory(bidderCode) { | ||
ensureBidderCode(bidderCode); | ||
return config; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this for config
?
I understand for storageManager
, but I don't get it for config.
How will this work for analyticsAdapters, rtbModules, idSystems, or any other module that is not bidder
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because config
does things like this:
Lines 293 to 301 in 95ab11e
/** | |
* Returns base config with bidder overrides (if there is currently a bidder) | |
* @private | |
*/ | |
function _getConfig() { | |
if (currBidder && bidderConfig && isPlainObject(bidderConfig[currBidder])) { | |
let currBidderConfig = bidderConfig[currBidder]; | |
const configTopicSet = new Set(Object.keys(config).concat(Object.keys(currBidderConfig))); | |
non-bidder modules are not affected by this, I don't know enough about them to know if it makes sense to do something similar to them. I tried to make this general enough that it should be relatively easy to extend for other use cases.
export function storageManagerFactory(bidderCode) { | ||
ensureBidderCode(bidderCode); | ||
return getStorageManager; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole purpose of this function is to throw an exception if some bid adapter calls getStorageManager
without providing their bidder code?
Why not throwing an exception from the getStorageManager
function itself? Is it because we would want to throw an exception only for bid adapters, but not for other modules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just to prove that the whole thing works as a POC, the contents of this file are useless right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, getStorageManager
is completely unaware of bidders - that's the point of this PR; we can't do anything* about bidders from there unless we change the interface to take in the bidder code. This is an attempt at a low-effort way to refactor the interface.
*Except for config's currentBidder
"context", which does not work in some cases. I only consider bidders and not other modules because bidders are the only ones that have that special case already spread out through the codebase.
@FilipStamenkovic with a recent version of My hope with this pr is to replace the |
Closing this in favor of #7992 |
Type of change
Description of change
This adds build preprocessing that replaces certain import declaration in adapters' source files. The idea is to automatically refactor them to allow components like config or storageManager to always know who the bidder calling them is.
The strategy is:
registerBidder
(pre-processing is also filtered just to files undermodules/
).import
s with an import for a factory function instead, and re-bind the imported name to a call to that factory function. For example, this:Since
import
statements are entirely static this translation is pretty robust.Caveats
import *
is not supported and will fail the build. it's not impossible to support but relatively complex and there are no adapters using it right now.import(...)
) or commonJSrequire
s. I found two other adapters that usedrequire
and I replaced them with normalimports
. If we decide to go ahead with this approach I believe we should try to block that either with eslint or in this translation step.Translation example
Compare the original:
Prebid.js/modules/adagioBidAdapter.js
Lines 1 to 30 in 51f9244
with the generated: