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: improve library support; make AnalyticsAdapter a library #8599

Merged
merged 6 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ selenium*.log
integrationExamples/gpt/gpt.html
integrationExamples/gpt/*-test.html
integrationExamples/implementations/
src/adapters/analytics/libraries
libraries/analyticsAdapter/examples/libraries

# Coverage reports
build/coverage/
Expand Down
3 changes: 3 additions & 0 deletions allowedModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ module.exports = {
'just-clone',
'dlv',
'dset'
],
'libraries': [
...sharedWhiteList // empty for now, but keep it to enable linting
]
};
77 changes: 22 additions & 55 deletions gulpHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ const MANIFEST = 'package.json';
const through = require('through2');
const _ = require('lodash');
const gutil = require('gulp-util');
const dependencyMap = require('./modules/.submodules.json');
const submodules = dependencyMap.parentModules;
const libraries = dependencyMap.libraries;
const submodules = require('./modules/.submodules.json').parentModules;

const MODULE_PATH = './modules';
const LIBRARY_PATH = './libraries';
const BUILD_PATH = './build/dist';
const DEV_PATH = './build/dev';
const ANALYTICS_PATH = '../analytics';
Expand Down Expand Up @@ -71,68 +68,34 @@ module.exports = {
}
});

Object.keys(libraries).forEach(library => {
if (!modules.includes(library) && modules.some(module => libraries[library].dependants.includes(module))) {
modules.unshift(library);
}
});

return modules;
},
getParentLibraries(moduleName) {
const libraryNames = [];
Object.keys(libraries).forEach(libraryName => {
const library = libraries[libraryName];
if (library.dependants.includes(moduleName)) {
libraryNames.push(libraryName);
}
});
return libraryNames;
},
getLibraryFiles(name) {
const library = libraries[name];
const files = library.files.map((file) => path.resolve('./libraries/', name, file))
return files;
},
isLibrary(name) {
return !!libraries[name];
},
getModules: _.memoize(function(externalModules) {
externalModules = externalModules || [];
var internalModules;
try {
var getInternalModules = function(absolutePath) {
return fs.readdirSync(absolutePath)
.filter(file => (/^[^\.]+(\.js)?$/).test(file))
.reduce((memo, file) => {
var moduleName = file.split(new RegExp('[.\\' + path.sep + ']'))[0];
var modulePath = path.join(absolutePath, file);
if (fs.lstatSync(modulePath).isDirectory()) {
modulePath = path.join(modulePath, 'index.js')
}
if (fs.existsSync(modulePath)) {
memo[modulePath] = moduleName;
}
return memo;
}, {});
};

var absoluteModulePath = path.join(__dirname, MODULE_PATH);
var absoluteLibraryPath = path.join(__dirname, LIBRARY_PATH);

internalModules = getInternalModules(absoluteModulePath);
var internalLibraries = getInternalModules(absoluteLibraryPath);
Object.assign(internalModules, internalLibraries);
internalModules = fs.readdirSync(absoluteModulePath)
.filter(file => (/^[^\.]+(\.js)?$/).test(file))
.reduce((memo, file) => {
var moduleName = file.split(new RegExp('[.\\' + path.sep + ']'))[0];
var modulePath = path.join(absoluteModulePath, file);
if (fs.lstatSync(modulePath).isDirectory()) {
modulePath = path.join(modulePath, 'index.js')
}
if (fs.existsSync(modulePath)) {
memo[modulePath] = moduleName;
}
return memo;
}, {});
} catch (err) {
internalModules = {};
}
return Object.assign(externalModules.reduce((memo, module) => {
try {
// prefer internal project modules before looking at project dependencies
var modulePath = require.resolve(module, {paths: [MODULE_PATH, LIBRARY_PATH]});
if (modulePath === '') {
modulePath = require.resolve(module);
}
var modulePath = require.resolve(module, {paths: ['./modules']});
if (modulePath === '') modulePath = require.resolve(module);

memo[modulePath] = module;
} catch (err) {
Expand All @@ -142,16 +105,20 @@ module.exports = {
}, internalModules));
}),

getBuiltPath(dev, assetPath) {
return path.join(__dirname, dev ? DEV_PATH : BUILD_PATH, assetPath)
},

getBuiltModules: function(dev, externalModules) {
var modules = this.getModuleNames(externalModules);
if (Array.isArray(externalModules)) {
modules = _.intersection(modules, externalModules);
}
return modules.map(name => path.join(__dirname, dev ? DEV_PATH : BUILD_PATH, name + '.js'));
return modules.map(name => this.getBuiltPath(dev, name + '.js'));
},

getBuiltPrebidCoreFile: function(dev) {
return path.join(__dirname, dev ? DEV_PATH : BUILD_PATH, 'prebid-core' + '.js');
return this.getBuiltPath(dev, 'prebid-core.js')
},

getModulePaths: function(externalModules) {
Expand Down
9 changes: 8 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,15 @@ function bundle(dev, moduleArr) {
});
}
}
const coreFile = helpers.getBuiltPrebidCoreFile(dev);
const moduleFiles = helpers.getBuiltModules(dev, modules);
const depGraph = require(helpers.getBuiltPath(dev, 'dependencies.json'));
const dependencies = new Set();
[coreFile].concat(moduleFiles).map(name => path.basename(name)).forEach((file) => {
(depGraph[file] || []).forEach((dep) => dependencies.add(helpers.getBuiltPath(dev, dep)));
})

var entries = [helpers.getBuiltPrebidCoreFile(dev)].concat(helpers.getBuiltModules(dev, modules));
const entries = [coreFile].concat(Array.from(dependencies), moduleFiles);

var outputFileName = argv.bundleName ? argv.bundleName : 'prebid.js';

Expand Down
5 changes: 5 additions & 0 deletions libraries/LIBRARIES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Cross-module libraries

Each directory under this one is packaged into a "library" during the build.

Modules may share code by simply importing from a common library file; if the module is included in the build, any libraries they import from will also be included.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CONSTANTS from './constants.json';
import { ajax } from './ajax.js';
import { logMessage, _each } from './utils.js';
import * as events from './events.js'
import CONSTANTS from '../../src/constants.json';
import { ajax } from '../../src/ajax.js';
import { logMessage, _each } from '../../src/utils.js';
import * as events from '../../src/events.js'

export const _internal = {
ajax
Expand Down Expand Up @@ -31,14 +31,13 @@ const {
const ENDPOINT = 'endpoint';
const BUNDLE = 'bundle';

var _sampled = true;

export default function AnalyticsAdapter({ url, analyticsType, global, handler }) {
const _queue = [];
let _eventCount = 0;
let _enableCheck = true;
let _handlers;
let _enabled = false;
let _sampled = true;

if (analyticsType === ENDPOINT || BUNDLE) {
_emptyQueue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* example.js - analytics adapter for Example Analytics Library example
*/

import adapter from '../../AnalyticsAdapter.js';
import adapter from '../AnalyticsAdapter.js';

export default adapter(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ajax } from '../../../src/ajax.js';
* example2.js - analytics adapter for Example2 Analytics Endpoint example
*/

import adapter from '../../AnalyticsAdapter.js';
import adapter from '../AnalyticsAdapter.js';

const url = 'https://httpbin.org/post';
const analyticsType = 'endpoint';
Expand Down
12 changes: 0 additions & 12 deletions modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,5 @@
"enrichmentFpdModule",
"validationFpdModule"
]
},
"libraries": {
"getOrigin": {
"files": [
"./index.js"
],
"dependants": [
"ooloAnalyticsAdapter",
"resetdigitalBidAdapter",
"rtbhouseBidAdapter.js"
]
}
}
}
2 changes: 1 addition & 1 deletion modules/adWMGAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';
import { ajax } from '../src/ajax.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/adagioAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Analytics Adapter for Adagio
*/

import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';
import { getWindowTop } from '../src/utils.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/adkernelAdnAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import CONSTANTS from '../src/constants.json';
import adapterManager from '../src/adapterManager.js';
import { logError, parseUrl, _each } from '../src/utils.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/adlooxAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import adapterManager from '../src/adapterManager.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import {loadExternalScript} from '../src/adloader.js';
import {auctionManager} from '../src/auctionManager.js';
import {AUCTION_COMPLETED} from '../src/auction.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/adomikAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import CONSTANTS from '../src/constants.json';
import adapterManager from '../src/adapterManager.js';
import {logInfo} from '../src/utils.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/adxcgAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parseSizesInput, uniques, buildUrl, logError } from '../src/utils.js';
import { ajax } from '../src/ajax.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';

Expand Down
2 changes: 1 addition & 1 deletion modules/adxpremiumAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {deepClone, logError, logInfo} from '../src/utils.js';
import {ajax} from '../src/ajax.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';
import {includes} from '../src/polyfill.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/appierAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ajax} from '../src/ajax.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import CONSTANTS from '../src/constants.json';
import adapterManager from '../src/adapterManager.js';
import {getGlobal} from '../src/prebidGlobal.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/atsAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { logError, logInfo } from '../src/utils.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import CONSTANTS from '../src/constants.json';
import adaptermanager from '../src/adapterManager.js';
import {ajax} from '../src/ajax.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/bidwatchAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';
import { ajax } from '../src/ajax.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/byDataAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { deepClone, logInfo, logError } from '../src/utils.js';
import Base64 from 'crypto-js/enc-base64';
import hmacSHA512 from 'crypto-js/hmac-sha512';
import enc from 'crypto-js/enc-utf8';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import CONSTANTS from '../src/constants.json';
import adapterManager from '../src/adapterManager.js';
import { getStorageManager } from '../src/storageManager.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/concertAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logMessage } from '../src/utils.js';
import {ajax} from '../src/ajax.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import CONSTANTS from '../src/constants.json';
import adapterManager from '../src/adapterManager.js';

Expand Down
2 changes: 1 addition & 1 deletion modules/datablocksAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Analytics Adapter for Datablocks
*/

import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';

var datablocksAdapter = adapter({
Expand Down
2 changes: 1 addition & 1 deletion modules/eplanningAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logError } from '../src/utils.js';
import {ajax} from '../src/ajax.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';

Expand Down
2 changes: 1 addition & 1 deletion modules/fintezaAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parseUrl, logError } from '../src/utils.js';
import { ajax } from '../src/ajax.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import { getStorageManager } from '../src/storageManager.js';
import CONSTANTS from '../src/constants.json';
Expand Down
2 changes: 1 addition & 1 deletion modules/hadronAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ajax } from '../src/ajax.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import * as utils from '../src/utils.js';
import CONSTANTS from '../src/constants.json';
Expand Down
2 changes: 1 addition & 1 deletion modules/id5AnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import buildAdapter from '../src/AnalyticsAdapter.js';
import buildAdapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import CONSTANTS from '../src/constants.json';
import adapterManager from '../src/adapterManager.js';
import { ajax } from '../src/ajax.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/invisiblyAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* invisiblyAdapterAdapter.js - analytics adapter for Invisibly
*/
import { ajaxBuilder } from '../src/ajax.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';

import { generateUUID, logInfo } from '../src/utils.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/kargoAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logError } from '../src/utils.js';
import { ajax } from '../src/ajax.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';

Expand Down
2 changes: 1 addition & 1 deletion modules/konduitAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parseSizesInput, logError, uniques } from '../src/utils.js';
import { ajax } from '../src/ajax.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import { targeting } from '../src/targeting.js';
import { config } from '../src/config.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/livewrappedAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { timestamp, logInfo, getWindowTop } from '../src/utils.js';
import {ajax} from '../src/ajax.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import CONSTANTS from '../src/constants.json';
import adapterManager from '../src/adapterManager.js';
import { getGlobal } from '../src/prebidGlobal.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/liveyieldAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { logError } from '../src/utils.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';

Expand Down
Loading