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

Using Prebid.js as npm dependency #3435

Merged
merged 20 commits into from
Jan 15, 2019
Merged

Using Prebid.js as npm dependency #3435

merged 20 commits into from
Jan 15, 2019

Conversation

snapwich
Copy link
Collaborator

@snapwich snapwich commented Jan 10, 2019

Type of change

  • Feature
  • Refactoring (no functional changes, no api changes)

Description of change

This updates the code base to be useable directly from npm as a library within another application. The README is updated with instructions for using Prebid.js with both Babel 6 and 7. After implementing the proper babel-loader within the external application, Prebid.js can be used like so

import prebid from 'prebid.js';
import 'prebid.js/modules/rubiconBidAdapter'; // imported modules will register themselves automatically with prebid
import 'prebid.js/modules/appnexusBidAdapter';
prebid.processQueue();  // required to process existing pbjs.queue blocks and setup any further pbjs.queue execution

prebid.requestBids({
  ...
})

This updates the local Prebid.js build to the latest version of Babel. This required refactoring to ES6 modules for many of the files (no mix-matched commonjs and es6 imports/exports).

It also replaces the string-replace-webpack-plugin with a Babel Plugin for doing all the global search and replacing for things such as the $$PREBID_GLOBAL$$.

Other information

ES6 modules affect some of the capabilities of sinon stubbing. To allow stubbing for some features, in utils for example, an internals export was added to allow stubbing features (similar to how commonjs exports object was being used). I investigated using something like babel-plugin-rewire to do stubbing, however it's incompatible with our instanbul setup and fixing it to work correctly would be an even larger refactor; however, it might be worth investigating in the future.

Going forward, any build features that we would added with Gulp or Webpack should probably be implemented as Babel Plugins to maintain compatibility for applications using Prebid.js directly from npm. It might be worthwhile creating another repo that pulls in Prebid.js as an npm dependency and tests functionality to avoid breaking integrations.

All file imports withinsrc and modules files were updated to use relative pathing. This is required since any application pulling in Prebid.js will most likely not have the same webpack resolver to properly locate resources. Any new pull-requests adding features should use relative paths for any files within src or modules. It's still fine to use the webpack resolver for imports within test.

I updated the README to mention that using this feature requires Prebid.js 1.38.0+, so it'd be nice to add this in the next release so that is accurate.

Closes #1853

@mkendall07
Copy link
Member

This pull request introduces 1 alert when merging f5b8f32 into c07e60d - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

Comment posted by LGTM.com

@snapwich snapwich mentioned this pull request Jan 10, 2019
1 task
@mkendall07 mkendall07 self-assigned this Jan 14, 2019
@mkendall07 mkendall07 requested review from mike-chowla and jsnellbaker and removed request for mike-chowla January 14, 2019 14:42
@jsnellbaker jsnellbaker added needs 2nd review Core module updates require two approvals from the core team and removed needs review labels Jan 15, 2019
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.

LGTM. Major props @snapwich !

@mkendall07 mkendall07 merged commit 8635c91 into master Jan 15, 2019
@snapwich snapwich deleted the prebid-as-library branch January 15, 2019 21:00
amuraco pushed a commit to amuraco/Prebid.js that referenced this pull request Jan 28, 2019
* added babel plugin to replace webpack StringReplacementPlugin

* remove ignore-loader in favor of filtering non .js files as modules

* make all imports relative for projects not using our resolver

* refactor adaptermanager to adapterManager

* convert adapterManager to be compatible with latest version of babel

* refactored utils with es6 exports

* fixing tests

* fixing stubs and tests

* babelrc updated to be used externally from parent project

* remove $prebid.version$ from gulp and add to babel plugin

* fix tests to use actual prebid.version rather than string literal

* refactor all modules to use relative imports w/o webpack resolver

* fix test in old safari

* update package-lock.json

* remove unnecessary json-loader

* update babel plugin to use same @babel/core

* add instructions for using prebid as npm depenedency added to readme

* remove unused variable in global babel plugin

* fixed missing internal.createTrackPixelIframeHtml

* fix relative pathing for new modules
ghost pushed a commit to devunrulymedia/Prebid.js that referenced this pull request Jan 30, 2019
* added babel plugin to replace webpack StringReplacementPlugin

* remove ignore-loader in favor of filtering non .js files as modules

* make all imports relative for projects not using our resolver

* refactor adaptermanager to adapterManager

* convert adapterManager to be compatible with latest version of babel

* refactored utils with es6 exports

* fixing tests

* fixing stubs and tests

* babelrc updated to be used externally from parent project

* remove $prebid.version$ from gulp and add to babel plugin

* fix tests to use actual prebid.version rather than string literal

* refactor all modules to use relative imports w/o webpack resolver

* fix test in old safari

* update package-lock.json

* remove unnecessary json-loader

* update babel plugin to use same @babel/core

* add instructions for using prebid as npm depenedency added to readme

* remove unused variable in global babel plugin

* fixed missing internal.createTrackPixelIframeHtml

* fix relative pathing for new modules
pedrolopezmrf pushed a commit to Marfeel/Prebid.js that referenced this pull request Mar 18, 2019
* added babel plugin to replace webpack StringReplacementPlugin

* remove ignore-loader in favor of filtering non .js files as modules

* make all imports relative for projects not using our resolver

* refactor adaptermanager to adapterManager

* convert adapterManager to be compatible with latest version of babel

* refactored utils with es6 exports

* fixing tests

* fixing stubs and tests

* babelrc updated to be used externally from parent project

* remove $prebid.version$ from gulp and add to babel plugin

* fix tests to use actual prebid.version rather than string literal

* refactor all modules to use relative imports w/o webpack resolver

* fix test in old safari

* update package-lock.json

* remove unnecessary json-loader

* update babel plugin to use same @babel/core

* add instructions for using prebid as npm depenedency added to readme

* remove unused variable in global babel plugin

* fixed missing internal.createTrackPixelIframeHtml

* fix relative pathing for new modules
AlessandroDG added a commit to simplaex/Prebid.js that referenced this pull request Mar 28, 2019
AlessandroDG added a commit to simplaex/Prebid.js that referenced this pull request Mar 28, 2019
AlessandroDG pushed a commit to simplaex/Prebid.js that referenced this pull request Mar 28, 2019
## Type of change
- [x] Refactoring (no functional changes, no api changes)

## Description of change

Refactor rivrAnalyticsAdapter.js events handling.


## History

* RVR-2087 - update adapterManager dependency

* RVR-2369 - Update package-lock.json

* RVR-2369 - Revert changes in main Analytics adapter

It will be handled in a separate PR

* RVR-2369 - Use relative import paths

Needed for prebid#3435
jsnellbaker pushed a commit that referenced this pull request Apr 1, 2019
* Rvr 2369 Refactor events handling (#9)

* RVR-2177 - Refactor events handling

* RVR-2087 - Inject pbjsGlobalVariable into rivraddon

* RVR-2087 - update adapterManager dependency

* RVR-2087 - Add ADD_AD_UNITS to Prebid.JS trackable events

* RVR-2369 - Update package-lock.json

* Rvr 2369 prevent duplicate events (#10)

## Type of change
- [x] Refactoring (no functional changes, no api changes)

## Description of change

Refactor rivrAnalyticsAdapter.js events handling.


## History

* RVR-2087 - update adapterManager dependency

* RVR-2369 - Update package-lock.json

* RVR-2369 - Revert changes in main Analytics adapter

It will be handled in a separate PR

* RVR-2369 - Use relative import paths

Needed for #3435
pycnvr pushed a commit to conversant/Prebid.js that referenced this pull request Apr 4, 2019
* Rvr 2369 Refactor events handling (#9)

* RVR-2177 - Refactor events handling

* RVR-2087 - Inject pbjsGlobalVariable into rivraddon

* RVR-2087 - update adapterManager dependency

* RVR-2087 - Add ADD_AD_UNITS to Prebid.JS trackable events

* RVR-2369 - Update package-lock.json

* Rvr 2369 prevent duplicate events (#10)

## Type of change
- [x] Refactoring (no functional changes, no api changes)

## Description of change

Refactor rivrAnalyticsAdapter.js events handling.


## History

* RVR-2087 - update adapterManager dependency

* RVR-2369 - Update package-lock.json

* RVR-2369 - Revert changes in main Analytics adapter

It will be handled in a separate PR

* RVR-2369 - Use relative import paths

Needed for prebid#3435
@jsnellbaker jsnellbaker mentioned this pull request Apr 22, 2019
9 tasks
@jsnellbaker jsnellbaker mentioned this pull request May 14, 2019
2 tasks
jacekburys-quantcast pushed a commit to jacekburys-quantcast/Prebid.js that referenced this pull request May 15, 2019
* added babel plugin to replace webpack StringReplacementPlugin

* remove ignore-loader in favor of filtering non .js files as modules

* make all imports relative for projects not using our resolver

* refactor adaptermanager to adapterManager

* convert adapterManager to be compatible with latest version of babel

* refactored utils with es6 exports

* fixing tests

* fixing stubs and tests

* babelrc updated to be used externally from parent project

* remove $prebid.version$ from gulp and add to babel plugin

* fix tests to use actual prebid.version rather than string literal

* refactor all modules to use relative imports w/o webpack resolver

* fix test in old safari

* update package-lock.json

* remove unnecessary json-loader

* update babel plugin to use same @babel/core

* add instructions for using prebid as npm depenedency added to readme

* remove unused variable in global babel plugin

* fixed missing internal.createTrackPixelIframeHtml

* fix relative pathing for new modules
jacekburys-quantcast pushed a commit to jacekburys-quantcast/Prebid.js that referenced this pull request May 15, 2019
* Rvr 2369 Refactor events handling (prebid#9)

* RVR-2177 - Refactor events handling

* RVR-2087 - Inject pbjsGlobalVariable into rivraddon

* RVR-2087 - update adapterManager dependency

* RVR-2087 - Add ADD_AD_UNITS to Prebid.JS trackable events

* RVR-2369 - Update package-lock.json

* Rvr 2369 prevent duplicate events (prebid#10)

## Type of change
- [x] Refactoring (no functional changes, no api changes)

## Description of change

Refactor rivrAnalyticsAdapter.js events handling.


## History

* RVR-2087 - update adapterManager dependency

* RVR-2369 - Update package-lock.json

* RVR-2369 - Revert changes in main Analytics adapter

It will be handled in a separate PR

* RVR-2369 - Use relative import paths

Needed for prebid#3435
@jsnellbaker jsnellbaker mentioned this pull request May 17, 2019
10 tasks
@jsnellbaker jsnellbaker mentioned this pull request Jul 10, 2019
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs 2nd review Core module updates require two approvals from the core team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How best to include Prebid.js as part of a bigger project?
3 participants