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: Library support #8527

Merged
merged 7 commits into from
Jun 14, 2022
Merged

Conversation

karimMourra
Copy link
Collaborator

@karimMourra karimMourra commented Jun 6, 2022

Type of change

  • Build related changes

Description of change

This PR allows modules to share code outside of core by introducing Libraries. With these changes, code outside of core can be shared without duplication in the build.

As an example, the extraUtils library is introduced. The getOrigin function from the core utils has been moved to this library, and the library is now listed as a dependency of the 3 modules that use the util.

Note that when the dist is built or bundled, the getOrigin function is not duplicated.
You can test with:
gulp build --modules=ooloAnalyticsAdapter,resetdigitalBidAdapter
gulp bundle --modules=ooloAnalyticsAdapter,resetdigitalBidAdapter

Other information

Helps with issue #7936
Needed for #7264
@dgirardi for review

@muuki88
Copy link
Collaborator

muuki88 commented Jun 7, 2022

This is amazing work. Thanks a lot 🎉

Copy link
Collaborator

@dgirardi dgirardi left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together! I disagree only with the name choice for the first library.
Also noting that this does not completely address #7936 (which is perfectly fine - I just wouldn't want that to be closed prematurely).

/**
* Returns the origin
*/
export function getOrigin() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO the library should just be named 'getOrigin' - 'extraUtils' invites us to dump more unrelated stuff in here, which will eventually bring about the same problem that utils has :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

addressed

"files": [
"./index.js"
],
"dependants": [
Copy link
Collaborator

Choose a reason for hiding this comment

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

in principle we should be able to calculate these automatically by looking at imports. I think webpack's chunking feature does it under the hood but I don't see an easy way to extract the graph for us to use in bundle.

We can easily add it later so no request for this PR, just noting it here in case you are familiar with that feature.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

makes sense, I'm happy to explore that in the near future when cycles free up

Copy link
Member

Choose a reason for hiding this comment

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

👍 I could see this dependents list getting out of hand quickly.

Copy link
Collaborator

@dgirardi dgirardi left a comment

Choose a reason for hiding this comment

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

LGTM! I'll note again that this could potentially break 3rd party vendors if they're using the build output as it is now - but I don't actually know of any concrete case where that would be a problem.

@dgirardi dgirardi added the needs 2nd review Core module updates require two approvals from the core team label Jun 7, 2022
@patmmccann patmmccann requested review from mkendall07 and removed request for robertrmartinez June 9, 2022 14:53
Copy link
Member

@mkendall07 mkendall07 left a comment

Choose a reason for hiding this comment

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

Overall looks great. Just left one question. Good work solving a long standing problem with the build system!

"files": [
"./index.js"
],
"dependants": [
Copy link
Member

Choose a reason for hiding this comment

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

👍 I could see this dependents list getting out of hand quickly.

/**
* Returns the origin
*/
export function getOrigin() {
Copy link
Member

Choose a reason for hiding this comment

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

is there any restrictions on library files? What happens if you want to import another file from the library file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When I initially envisioned this, the maintainer of the library would determine which files are necessary.
If users were to find the library too heavy, the maintainer could either split the library (i.e by feature or by light vs advanced) or a competitor could offer a lighter library.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We'll probably need to cover this at a later date, with some best practices or boundaries

@mkendall07 mkendall07 removed the needs 2nd review Core module updates require two approvals from the core team label Jun 13, 2022
@patmmccann patmmccann changed the title Library support Prebid Core: Library support Jun 14, 2022
@patmmccann patmmccann merged commit 90c9d77 into prebid:master Jun 14, 2022
renebaudisch pushed a commit to renebaudisch/Prebid.js that referenced this pull request Jun 28, 2022
* adds extra utils

* imports from extra utils

* adds libraries to .submodules

* adds libraries to build process

* renames extraUtils

* update userId submodules list
bwhisp pushed a commit to bwhisp/Prebid.js that referenced this pull request Jul 13, 2022
* adds extra utils

* imports from extra utils

* adds libraries to .submodules

* adds libraries to build process

* renames extraUtils

* update userId submodules list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants