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 & PBS adapter: Feature tags and optional compilation of native support #8219

Merged
merged 27 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d1dc13d
Upgrade webpack to 5; gulp build works
dgirardi Jan 12, 2022
fbfac81
Fix karma, except events
dgirardi Jan 12, 2022
1943cc7
Uniform access to events, import * or require (import * from 'events.…
dgirardi Jan 12, 2022
5caa247
Fix (?) adapters that use `this` inappropriately
dgirardi Jan 12, 2022
086c753
Update webpack-bundle-analyzer
dgirardi Jan 12, 2022
688cc68
Fix warnings
dgirardi Jan 12, 2022
8efd09a
Enable tree shaking
dgirardi Jan 12, 2022
b89d5b3
Set webpack mode 'none' (or else tests fail (!))
dgirardi Jan 12, 2022
e6672b9
Merge branch 'master' into upgrade-webpack
dgirardi Jan 26, 2022
5d26111
Update coreJS version in babelrc - https://github.com/prebid/Prebid.j…
dgirardi Jan 26, 2022
19c6286
Use babel to translate to commonjs only for unit tests; enable produc…
dgirardi Jan 26, 2022
9f27fe8
Define feature flags at compile time - starting with just "NATIVE"
dgirardi Jan 27, 2022
913b547
Add build-bundle-verbose
dgirardi Jan 27, 2022
c3d65cd
Run tests with all features disabled
dgirardi Jan 27, 2022
cba2ec0
Fix build-bundle-verbose
dgirardi Jan 27, 2022
34ff7ac
Tag native#nativeAdapters
dgirardi Jan 27, 2022
841311a
Merge branch 'master' into upgrade-webpack
dgirardi Mar 3, 2022
062e6bb
Merge master
dgirardi Mar 8, 2022
57dbb74
Merge branch 'master' into upgrade-webpack
dgirardi Mar 8, 2022
22a7b0c
Add fsevents as optional dep
dgirardi Mar 8, 2022
9f42bea
Merge branch 'master' into upgrade-webpack
dgirardi Mar 9, 2022
a9e2088
Merge branch 'master' into upgrade-webpack
dgirardi Mar 17, 2022
d270b6f
Merge branch 'upgrade-webpack' into feature-tags
dgirardi Mar 17, 2022
504cb10
Merge branch 'master' into feature-tags
dgirardi Mar 22, 2022
1c4dc4e
Merge branch 'master' into feature-tags
dgirardi Mar 25, 2022
80813f2
Merge branch 'master' into feature-tags
dgirardi Jun 16, 2022
d557978
Adjust syntax for node 12
dgirardi Jun 16, 2022
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
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module.exports = {
globals: {
'$$PREBID_GLOBAL$$': false,
'BROWSERSTACK_USERNAME': false,
'BROWSERSTACK_KEY': false
'BROWSERSTACK_KEY': false,
'FEATURES': 'readonly',
},
// use babel as parser for fancy syntax
parser: '@babel/eslint-parser',
Expand Down
10 changes: 7 additions & 3 deletions babelConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ function useLocal(module) {
})
}

module.exports = function (test = false) {
module.exports = function (options = {}) {
const {globalVarName, disableFeatures} = options;
return {
'presets': [
[
Expand All @@ -18,12 +19,15 @@ module.exports = function (test = false) {
'useBuiltIns': 'entry',
'corejs': '3.13.0',
// a lot of tests use sinon.stub & others that stopped working on ES6 modules with webpack 5
'modules': test ? 'commonjs' : 'auto',
'modules': options.test ? 'commonjs' : 'auto',
}
]
],
'plugins': [
path.resolve(__dirname, './plugins/pbjsGlobals.js'),
[
path.resolve(__dirname, './plugins/pbjsGlobals.js'),
{globalVarName, disableFeatures}
],
useLocal('babel-plugin-transform-object-assign'),
],
}
Expand Down
3 changes: 3 additions & 0 deletions features.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"NATIVE"
]
8 changes: 7 additions & 1 deletion gulpHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,11 @@ module.exports = {
}

return options;
}
},
getDisabledFeatures() {
return (argv.disable || '')
.split(',')
.map((s) => s.trim())
.filter((s) => s);
},
};
61 changes: 42 additions & 19 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var port = 9999;
const FAKE_SERVER_HOST = argv.host ? argv.host : 'localhost';
const FAKE_SERVER_PORT = 4444;
const { spawn } = require('child_process');
const TerserPlugin = require('terser-webpack-plugin');

// these modules must be explicitly listed in --modules to be included in the build, won't be part of "all" modules
var explicitModules = [
Expand Down Expand Up @@ -132,20 +133,22 @@ function makeDevpackPkg() {
.pipe(connect.reload());
}

function makeWebpackPkg() {
var cloned = _.cloneDeep(webpackConfig);
function makeWebpackPkg(extraConfig = {}) {
var cloned = _.merge(_.cloneDeep(webpackConfig), (extraConfig || {}));
delete cloned.devtool;

var externalModules = helpers.getArgModules();
return function buildBundle() {
var externalModules = helpers.getArgModules();

const analyticsSources = helpers.getAnalyticsSources();
const moduleSources = helpers.getModulePaths(externalModules);
const analyticsSources = helpers.getAnalyticsSources();
const moduleSources = helpers.getModulePaths(externalModules);

return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js'))
.pipe(helpers.nameModules(externalModules))
.pipe(webpackStream(cloned, webpack))
.pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid })))
.pipe(gulp.dest('build/dist'));
return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js'))
.pipe(helpers.nameModules(externalModules))
.pipe(webpackStream(cloned, webpack))
.pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, {prebid: prebid})))
.pipe(gulp.dest('build/dist'));
}
}

function getModulesListToAddInBanner(modules) {
Expand Down Expand Up @@ -224,9 +227,11 @@ function bundle(dev, moduleArr) {

function testTaskMaker(options = {}) {
['watch', 'e2e', 'file', 'browserstack', 'notest'].forEach(opt => {
options[opt] = options[opt] || argv[opt];
options[opt] = options.hasOwnProperty(opt) ? options[opt] : argv[opt];
})

options.disableFeatures = options.disableFeatures || helpers.getDisabledFeatures();

return function test(done) {
if (options.notest) {
done();
Expand Down Expand Up @@ -270,13 +275,15 @@ function testTaskMaker(options = {}) {
process.exit(1);
});
} else {
var karmaConf = karmaConfMaker(false, options.browserstack, options.watch, options.file);
var karmaConf = karmaConfMaker(false, options.browserstack, options.watch, options.file, options.disableFeatures);

var browserOverride = helpers.parseBrowserArgs(argv);
if (browserOverride.length > 0) {
karmaConf.browsers = browserOverride;
}

if (options.oneBrowser) {
karmaConf.browsers = [karmaConf.browsers.find((b) => b.toLowerCase().includes(options.oneBrowser.toLowerCase())) || karmaConf.browsers[0]]
}
new KarmaServer(karmaConf, newKarmaCallback(done)).start();
}
}
Expand All @@ -293,9 +300,6 @@ function newKarmaCallback(done) {
}
} else {
done();
if (argv.browserstack) {
process.exit(exitCode);
}
}
}
}
Expand Down Expand Up @@ -398,11 +402,30 @@ gulp.task(clean);
gulp.task(escapePostbidConfig);

gulp.task('build-bundle-dev', gulp.series(makeDevpackPkg, gulpBundle.bind(null, true)));
gulp.task('build-bundle-prod', gulp.series(makeWebpackPkg, gulpBundle.bind(null, false)));
gulp.task('build-bundle-prod', gulp.series(makeWebpackPkg(), gulpBundle.bind(null, false)));
// build-bundle-verbose - prod bundle except names and comments are preserved. Use this to see the effects
// of dead code elimination.
gulp.task('build-bundle-verbose', gulp.series(makeWebpackPkg({
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
mangle: false,
format: {
comments: 'all'
}
},
extractComments: false,
}),
],
}
}), gulpBundle.bind(null, false)));

// public tasks (dependencies are needed for each task since they can be ran on their own)
gulp.task('test-only', test);
gulp.task('test', gulp.series(clean, lint, 'test-only'));
gulp.task('test-all-features-disabled', testTaskMaker({disableFeatures: require('./features.json'), oneBrowser: 'chrome', watch: false}))
gulp.task('test', gulp.series(clean, lint, 'test-all-features-disabled', 'test-only'));

gulp.task('test-coverage', gulp.series(clean, testCoverage));
gulp.task(viewCoverage);
Expand All @@ -417,7 +440,7 @@ gulp.task('serve-fast', gulp.series(clean, gulp.parallel('build-bundle-dev', wat
gulp.task('serve-and-test', gulp.series(clean, gulp.parallel('build-bundle-dev', watchFast, testTaskMaker({watch: true}))));
gulp.task('serve-fake', gulp.series(clean, gulp.parallel('build-bundle-dev', watch), injectFakeServerEndpointDev, test, startFakeServer));

gulp.task('default', gulp.series(clean, makeWebpackPkg));
gulp.task('default', gulp.series(clean, makeWebpackPkg()));

gulp.task('e2e-test', gulp.series(clean, setupE2e, gulp.parallel('build-bundle-prod', watch), injectFakeServerEndpoint, test));
// other tasks
Expand Down
8 changes: 4 additions & 4 deletions karma.conf.maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var _ = require('lodash');
var webpackConf = require('./webpack.conf.js');
var karmaConstants = require('karma').constants;

function newWebpackConfig(codeCoverage) {
function newWebpackConfig(codeCoverage, disableFeatures) {
// Make a clone here because we plan on mutating this object, and don't want parallel tasks to trample each other.
var webpackConfig = _.cloneDeep(webpackConf);

Expand All @@ -22,7 +22,7 @@ function newWebpackConfig(codeCoverage) {
.flatMap((r) => r.use)
.filter((use) => use.loader === 'babel-loader')
.forEach((use) => {
use.options = babelConfig(true);
use.options = babelConfig({test: true, disableFeatures: disableFeatures});
});

if (codeCoverage) {
Expand Down Expand Up @@ -117,8 +117,8 @@ function setBrowsers(karmaConf, browserstack) {
}
}

module.exports = function(codeCoverage, browserstack, watchMode, file) {
var webpackConfig = newWebpackConfig(codeCoverage);
module.exports = function(codeCoverage, browserstack, watchMode, file, disableFeatures) {
var webpackConfig = newWebpackConfig(codeCoverage, disableFeatures);
var plugins = newPluginsArray(browserstack);

var files = file ? ['test/test_deps.js', file] : ['test/test_index.js'];
Expand Down
Loading