Skip to content
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
8 changes: 0 additions & 8 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ function watch(done) {
done();
};

function makeModuleList(modules) {
return modules.map(module => {
return '"' + module + '"'
});
}

function makeDevpackPkg() {
var cloned = _.cloneDeep(webpackConfig);
cloned.devtool = 'source-map';
Expand All @@ -158,7 +152,6 @@ function makeDevpackPkg() {
return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js'))
.pipe(helpers.nameModules(externalModules))
.pipe(webpackStream(cloned, webpack))
.pipe(replace(/('|")v\$prebid\.modulesList\$('|")/g, makeModuleList(externalModules)))
.pipe(gulp.dest('build/dev'))
.pipe(connect.reload());
}
Expand All @@ -176,7 +169,6 @@ function makeWebpackPkg() {
.pipe(helpers.nameModules(externalModules))
.pipe(webpackStream(cloned, webpack))
.pipe(terser())
.pipe(replace(/('|")v\$prebid\.modulesList\$('|")/g, makeModuleList(externalModules)))
.pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid })))
.pipe(gulp.dest('build/dist'));
}
Expand Down
29 changes: 28 additions & 1 deletion plugins/pbjsGlobals.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@

let t = require('@babel/core').types;
let prebid = require('../package.json');
const path = require('path');

module.exports = function(api, options) {
const pbGlobal = options.globalVarName || prebid.globalVarName;
let replace = {
'$prebid.version$': prebid.version,
'$$PREBID_GLOBAL$$': options.globalVarName || prebid.globalVarName,
'$$PREBID_GLOBAL$$': pbGlobal,
'$$REPO_AND_VERSION$$': `${prebid.repository.url.split('/')[3]}_prebid_${prebid.version}`
};

let identifierToStringLiteral = [
'$$REPO_AND_VERSION$$'
];

const PREBID_ROOT = path.resolve(__dirname, '..');

function getModuleName(filename) {
const modPath = path.parse(path.relative(PREBID_ROOT, filename));
if (modPath.ext.toLowerCase() !== '.js') {
return null;
}
if (modPath.dir === 'modules') {
// modules/moduleName.js -> moduleName
return modPath.name;
}
if (modPath.name.toLowerCase() === 'index' && path.dirname(modPath.dir) === 'modules') {
// modules/moduleName/index.js -> moduleName
return path.basename(modPath.dir);
}
return null;
}

return {
visitor: {
Program(path, state) {
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);
}
},
StringLiteral(path) {
Object.keys(replace).forEach(name => {
if (path.node.value.includes(name)) {
Expand Down
3 changes: 1 addition & 2 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ $$PREBID_GLOBAL$$.libLoaded = true;
$$PREBID_GLOBAL$$.version = 'v$prebid.version$';
logInfo('Prebid.js v$prebid.version$ loaded');

// modules list generated from build
$$PREBID_GLOBAL$$.installedModules = ['v$prebid.modulesList$'];
$$PREBID_GLOBAL$$.installedModules = $$PREBID_GLOBAL$$.installedModules || [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I like that change! ❤️


// create adUnit array
$$PREBID_GLOBAL$$.adUnits = $$PREBID_GLOBAL$$.adUnits || [];
Expand Down