-
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
CORE: allow to disable setting the pbjs global variable #9568
Merged
ChrisHuie
merged 12 commits into
prebid:master
from
olafbuitelaar:configure_disable_global
Mar 29, 2023
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7fa7642
allow to disable settings the pbjs global variable
olafbuitelaar 424d591
factored out all references to $$PREBID_GLOBAL$$ to use getGlobal ins…
olafbuitelaar a6795e5
fix comments
olafbuitelaar 7a21b57
make module use getGlobal
olafbuitelaar 1a3e72e
Isolate `installedModules` management from module namespaces
dgirardi 1159fe7
Merge remote-tracking branch 'origin/master' into configure_disable_g…
olafbuitelaar d8c717e
Merge branch 'configure_disable_global' of https://github.com/olafbui…
olafbuitelaar c49fbf0
Use relative import paths in autogenerated code for `installedModules`
dgirardi b529357
Merge branch 'master' into configure_disable_global
dgirardi 16e25dd
Remove $$PREBID_GLOBAL$$ macro ref from rubicon adapter
dgirardi 0639341
Revert "Remove $$PREBID_GLOBAL$$ macro ref from rubicon adapter"
dgirardi 91e16e5
Merge branch 'master' into configure_disable_global
dgirardi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
// if $$PREBID_GLOBAL$$ already exists in global document scope, use it, if not, create the object | ||
// global defination should happen BEFORE imports to avoid global undefined errors. | ||
window.$$PREBID_GLOBAL$$ = (window.$$PREBID_GLOBAL$$ || {}); | ||
window.$$PREBID_GLOBAL$$.cmd = window.$$PREBID_GLOBAL$$.cmd || []; | ||
window.$$PREBID_GLOBAL$$.que = window.$$PREBID_GLOBAL$$.que || []; | ||
const scope = !$$DEFINE_PREBID_GLOBAL$$ ? {} : window; | ||
scope.$$PREBID_GLOBAL$$ = (scope.$$PREBID_GLOBAL$$ || {}); | ||
scope.$$PREBID_GLOBAL$$.cmd = scope.$$PREBID_GLOBAL$$.cmd || []; | ||
scope.$$PREBID_GLOBAL$$.que = scope.$$PREBID_GLOBAL$$.que || []; | ||
|
||
// create a pbjs global pointer | ||
window._pbjsGlobals = window._pbjsGlobals || []; | ||
window._pbjsGlobals.push('$$PREBID_GLOBAL$$'); | ||
if (scope === window) { | ||
scope._pbjsGlobals = scope._pbjsGlobals || []; | ||
scope._pbjsGlobals.push('$$PREBID_GLOBAL$$'); | ||
} | ||
|
||
export function getGlobal() { | ||
return window.$$PREBID_GLOBAL$$; | ||
return scope.$$PREBID_GLOBAL$$; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I am uneasy about this putting names in the module's scope without checking for conflicts, and the fact that - if I understand this right - this has the "side effect" of removing references to the global from module code; by that I mean that it's not clear from this code that that's the intent; it appears to be dealing with
installedModules
only. I think its better to be explicit.What do you think about this strategy:
$$PREBID_GLOBAL$$
macro, with the exception ofprebidGlobal.js
, to be simple and explicit uses ofgetGlobal()
.const pbjs = getGlobal()
seems to me much better thanconst $$PREBID_GLOBAL$$ = getGlobal()
or just direct use of$$PREBID_GLOBAL$$
that are covertly translated to the first form through this black magic.$$PREBID_GLOBAL$$
to stop future circumvention ofgetGlobal()
. Also, do not add one for$$USE_PREBID_GLOBAL$$
, both can be single-file comment exceptions.installedModules
, I think this should try to stay invisible to the code's namespace. that means generating code likeimport {getGlobal as __r} from 'src/prebidGlobal.js; __r().installedModules.push(...)
, with some logic to use__r2
instead of__r
if the latter is taken and so on (throughscope.hasBinding
, there's an example in here when dealing withFEATURES
).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.
$$PREBID_GLOBAL$$
, except in theprebidGlobal.js
. There was 1 module (rivrAnalyticsAdapter.js
) which requires the global variable name.$$PREBID_GLOBAL$$.version
, maybe an utility function should be introduced for this, or maybe encourage the usage of'v$prebid.version$'
?getGlobal()
directly to set the modules, also i removed the different paths for using a global variable, or only use the internal instance.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.
forget my comment about
rivrAnalyticsAdapter.js
, it uses the reference after allThere 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.
I like the first idea because it would work better with the minifier, but I don't think it has to be part of this PR. (I don't like using
v$prebid.version$
because these macros are already more of a hack than I'd like).The approach you have here is still in my opinion technically incorrect (the best kind of incorrect) because a module could theoretically use the name
getGlobal
for its own unrelated purposes, which makes the autogeneratedimport
intrusive. It's not a huge deal but I think solving the problem also makes the code overall simpler: i pushed this update do demonstrate, which should also convince circleCI to run the tests.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.
fair point, only right now it's possible to import getGlobal twice (once by the module, and once auto-generated), not sure how well this would finally get minimized. otherwise maybe the 2 solutions could get merged, where this new variable is only introduced in this if 1a3e72e#diff-d38260cead55420ead0e3bc806c91343b780d84c61577742edb484a4add1dc22L96 but i'm fine with it as it right now, as well.
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.
i would also prefer the utility function to resolve the version, but agree this shouldn't be part of this PR
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.
I stole the same utility function idea for
registerModule
, so even if the minifier could not deal with the double import (I don't know either) it should not be an issue now. In fact there is an improvement as until now it could not touch the.installedModules
property accessor, but it can rename the utility function.