From ad27af7d2c56d03840c600635437585f2555e82d Mon Sep 17 00:00:00 2001 From: Michael Moschovas Date: Thu, 15 Apr 2021 13:27:31 -0400 Subject: [PATCH 1/5] - Remove module list comment on build - Add pbjs.installedModules with macro to prebid.js - Update gruntfile to replace macro with module array (if empty array all modules included)) --- gulpfile.js | 25 ++++++++++++++++++++----- src/prebid.js | 3 +++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index ac8b8c2dcd5..456994ef6d7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -31,7 +31,7 @@ const execa = require('execa'); var prebid = require('./package.json'); var dateString = 'Updated : ' + (new Date()).toISOString().substring(0, 10); -var banner = '/* <%= prebid.name %> v<%= prebid.version %>\n' + dateString + '\nModules: <%= modules %> */\n'; +var banner = '/* <%= prebid.name %> v<%= prebid.version %>\n' + dateString + '*/\n'; var port = 9999; const FAKE_SERVER_HOST = argv.host ? argv.host : 'localhost'; const FAKE_SERVER_PORT = 4444; @@ -141,10 +141,14 @@ function makeDevpackPkg() { const analyticsSources = helpers.getAnalyticsSources(); const moduleSources = helpers.getModulePaths(externalModules); + const moduleList = externalModules.map(module => { + return '"' + module + '"' + }); return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js')) .pipe(helpers.nameModules(externalModules)) .pipe(webpackStream(cloned, webpack)) + .pipe(replace(/"v\$prebid\.modulesList\$"/g, moduleList)) .pipe(gulp.dest('build/dev')) .pipe(connect.reload()); } @@ -157,13 +161,16 @@ function makeWebpackPkg() { const analyticsSources = helpers.getAnalyticsSources(); const moduleSources = helpers.getModulePaths(externalModules); - const modulesString = getModulesListToAddInBanner(externalModules); + const moduleList = externalModules.map(module => { + return '"' + module + '"' + }); return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js')) .pipe(helpers.nameModules(externalModules)) .pipe(webpackStream(cloned, webpack)) .pipe(uglify()) - .pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid, modules: modulesString }))) + .pipe(replace(/"v\$prebid\.modulesList\$"/g, moduleList)) + .pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid}))) .pipe(gulp.dest('build/dist')); } @@ -208,6 +215,10 @@ function bundle(dev, moduleArr) { var outputFileName = argv.bundleName ? argv.bundleName : 'prebid.js'; + const moduleList = helpers.getArgModules().map(module => { + return '"' + module + '"' + }); + // change output filename if argument --tag given if (argv.tag && argv.tag.length) { outputFileName = outputFileName.replace(/\.js$/, `.${argv.tag}.js`); @@ -224,8 +235,12 @@ function bundle(dev, moduleArr) { .pipe(replace(/(Modules: )(.*?)(\*\/)/, ('$1' + getModulesListToAddInBanner(helpers.getArgModules()) + ' $3'))) .pipe(gulpif(dev, sourcemaps.init({ loadMaps: true }))) .pipe(concat(outputFileName)) + // .pipe(gulpif(!argv.manualEnable, footer('\n<%= global %>.installedModules = <%= list %>', { + // global: prebid.globalVarName, + // list: "[" + moduleList + "];" + // }))) .pipe(gulpif(!argv.manualEnable, footer('\n<%= global %>.processQueue();', { - global: prebid.globalVarName + global: prebid.globalVarName, } ))) .pipe(gulpif(dev, sourcemaps.write('.'))); @@ -286,7 +301,7 @@ function test(done) { } else { var karmaConf = karmaConfMaker(false, argv.browserstack, argv.watch, argv.file); - var browserOverride = helpers.parseBrowserArgs(argv); + var browserOverride = helpers.parseBrowserArgs(argv).map(helpers.toCapitalCase); if (browserOverride.length > 0) { karmaConf.browsers = browserOverride; } diff --git a/src/prebid.js b/src/prebid.js index 7211371366e..f87628d7d00 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -43,6 +43,9 @@ $$PREBID_GLOBAL$$.libLoaded = true; $$PREBID_GLOBAL$$.version = 'v$prebid.version$'; utils.logInfo('Prebid.js v$prebid.version$ loaded'); +// modules list generated from build +$$PREBID_GLOBAL$$.installedModules = ['v$prebid.modulesList$']; + // create adUnit array $$PREBID_GLOBAL$$.adUnits = $$PREBID_GLOBAL$$.adUnits || []; From 5d45d11eb89114c681b4793a65360313e1964c9f Mon Sep 17 00:00:00 2001 From: Michael Moschovas Date: Thu, 15 Apr 2021 13:48:55 -0400 Subject: [PATCH 2/5] Removed unused code --- gulpfile.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 456994ef6d7..486a9e5a8e4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -215,10 +215,6 @@ function bundle(dev, moduleArr) { var outputFileName = argv.bundleName ? argv.bundleName : 'prebid.js'; - const moduleList = helpers.getArgModules().map(module => { - return '"' + module + '"' - }); - // change output filename if argument --tag given if (argv.tag && argv.tag.length) { outputFileName = outputFileName.replace(/\.js$/, `.${argv.tag}.js`); @@ -235,10 +231,6 @@ function bundle(dev, moduleArr) { .pipe(replace(/(Modules: )(.*?)(\*\/)/, ('$1' + getModulesListToAddInBanner(helpers.getArgModules()) + ' $3'))) .pipe(gulpif(dev, sourcemaps.init({ loadMaps: true }))) .pipe(concat(outputFileName)) - // .pipe(gulpif(!argv.manualEnable, footer('\n<%= global %>.installedModules = <%= list %>', { - // global: prebid.globalVarName, - // list: "[" + moduleList + "];" - // }))) .pipe(gulpif(!argv.manualEnable, footer('\n<%= global %>.processQueue();', { global: prebid.globalVarName, } From 848f1981a131b0230fc226f32e2bca9b67a2aa72 Mon Sep 17 00:00:00 2001 From: Michael Moschovas Date: Thu, 15 Apr 2021 13:49:43 -0400 Subject: [PATCH 3/5] Removed comma --- gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index 486a9e5a8e4..55a488f7fef 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -232,7 +232,7 @@ function bundle(dev, moduleArr) { .pipe(gulpif(dev, sourcemaps.init({ loadMaps: true }))) .pipe(concat(outputFileName)) .pipe(gulpif(!argv.manualEnable, footer('\n<%= global %>.processQueue();', { - global: prebid.globalVarName, + global: prebid.globalVarName } ))) .pipe(gulpif(dev, sourcemaps.write('.'))); From 8a72a78f7a881de7fbe0467ca428f4e80d82a8ca Mon Sep 17 00:00:00 2001 From: Michael Moschovas Date: Thu, 15 Apr 2021 14:00:26 -0400 Subject: [PATCH 4/5] Recommitting changes --- gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index 55a488f7fef..4c6ae444a84 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -293,7 +293,7 @@ function test(done) { } else { var karmaConf = karmaConfMaker(false, argv.browserstack, argv.watch, argv.file); - var browserOverride = helpers.parseBrowserArgs(argv).map(helpers.toCapitalCase); + var browserOverride = helpers.parseBrowserArgs(argv); if (browserOverride.length > 0) { karmaConf.browsers = browserOverride; } From 0d9acd0a87161ce1f989f101f7414e61a9fb9c07 Mon Sep 17 00:00:00 2001 From: Michael Moschovas Date: Thu, 15 Apr 2021 15:36:29 -0400 Subject: [PATCH 5/5] Updated regex to look for either '|" in macro name. Seems there is a difference between dev/prod --- gulpfile.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 4c6ae444a84..9bf378779d1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -134,6 +134,12 @@ function watch(done) { done(); }; +function makeModuleList(modules) { + return modules.map(module => { + return '"' + module + '"' + }); +} + function makeDevpackPkg() { var cloned = _.cloneDeep(webpackConfig); cloned.devtool = 'source-map'; @@ -141,14 +147,11 @@ function makeDevpackPkg() { const analyticsSources = helpers.getAnalyticsSources(); const moduleSources = helpers.getModulePaths(externalModules); - const moduleList = externalModules.map(module => { - return '"' + module + '"' - }); return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js')) .pipe(helpers.nameModules(externalModules)) .pipe(webpackStream(cloned, webpack)) - .pipe(replace(/"v\$prebid\.modulesList\$"/g, moduleList)) + .pipe(replace(/('|")v\$prebid\.modulesList\$('|")/g, makeModuleList(externalModules))) .pipe(gulp.dest('build/dev')) .pipe(connect.reload()); } @@ -161,15 +164,12 @@ function makeWebpackPkg() { const analyticsSources = helpers.getAnalyticsSources(); const moduleSources = helpers.getModulePaths(externalModules); - const moduleList = externalModules.map(module => { - return '"' + module + '"' - }); return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js')) .pipe(helpers.nameModules(externalModules)) .pipe(webpackStream(cloned, webpack)) .pipe(uglify()) - .pipe(replace(/"v\$prebid\.modulesList\$"/g, moduleList)) + .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')); }