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

Prebid Core: add filename to pbjsGlobals module append #7969

Merged
merged 3 commits into from
Feb 10, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/pbjsGlobals.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = function(api, options) {
const modName = getModuleName(state.filename);
if (modName != null) {
// append "registration" of module file to $$PREBID_GLOBAL$$.installedModules
path.node.body.push(...api.parse(`window.${pbGlobal}.installedModules.push('${modName}');`).program.body);
path.node.body.push(...api.parse(`window.${pbGlobal}.installedModules.push('${modName}');`, {filename: modName}).program.body);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for figuring this out!
The actual filename is under state.filename. Reading through https://babeljs.io/docs/en/options#filename it seems better to use that, because I can imagine a situation where modName clashes with some actual file in your build and babel makes the wrong decision on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense! Haven't tested it yet, but what do you think about appending the modName to the state.filename so each module keeps its own name? '${state.filename}.${modName}'. I don't know if having all modules with the same file name creates some conflict in this case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

this piece of code runs once for each module file, so that should not be a problem - state.filename will be different for each instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ab779ed updates the filename and the build continues to work as expected locally

}
},
StringLiteral(path) {
Expand Down