Skip to content

Commit cdc48a0

Browse files
committed
Merge branch 'release/1.3.0'
2 parents 340541b + 2d047d2 commit cdc48a0

File tree

9 files changed

+5373
-3800
lines changed

9 files changed

+5373
-3800
lines changed

.babelrc

Lines changed: 0 additions & 22 deletions
This file was deleted.

.browserslistrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
chrome >= 61
2+
safari >=8
3+
edge >= 14
4+
ff >= 57
5+
ie >= 10
6+
ios >= 9

karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const webpackConfig = require('./webpack.config')();
1+
const webpackConfig = require('./webpack.config')(undefined, {mode: 'development'});
22
webpackConfig.mode = 'development';
33

44
module.exports = (config) => {
@@ -13,7 +13,7 @@ module.exports = (config) => {
1313
'test/**/*.spec.js': ['webpack', 'sourcemap']
1414
},
1515

16-
webpack: webpackConfig,
16+
webpack: webpackConfig[0],
1717

1818
reporters: ['mocha', 'bamboo'],
1919

karma.saucelabs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const webpackConfig = require('./webpack.config')();
1+
const webpackConfig = require('./webpack.config')(undefined, {mode: 'development'});
22
const browsers = require('./browsers.json');
33
const pkg = require('./package.json');
44

@@ -15,7 +15,7 @@ module.exports = function(config) {
1515
'test/**/*.spec.js': ['webpack', 'sourcemap']
1616
},
1717

18-
webpack: webpackConfig,
18+
webpack: webpackConfig[0],
1919

2020
reporters: ['mocha', 'saucelabs', 'bamboo'],
2121

package-lock.json

Lines changed: 5261 additions & 3725 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "pubcid",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Publisher Common ID",
55
"scripts": {
66
"lint": "eslint src/**/*.js",
77
"start": "webpack-dev-server --mode=development",
88
"build": "webpack --mode=production",
99
"test": "npm run lint && karma start --single-run",
1010
"test-bamboo": "npm run lint && npm run sauce",
11-
"sauce": "karma start karma.saucelabs.js"
11+
"sauce": "karma start karma.saucelabs.js",
12+
"bundle-report": "webpack-bundle-analyzer --port 4200 dist/stats.json"
1213
},
1314
"repository": {
1415
"type": "git",
@@ -18,32 +19,32 @@
1819
"author": "Paul Yang <[email protected]>",
1920
"license": "Apache-2.0",
2021
"devDependencies": {
21-
"@babel/core": "^7.2.2",
22-
"@babel/plugin-transform-object-assign": "^7.2.0",
23-
"@babel/preset-env": "^7.3.1",
24-
"babel-loader": "^8.0.5",
22+
"@babel/core": "^7.9.0",
23+
"@babel/plugin-transform-object-assign": "^7.8.3",
24+
"@babel/preset-env": "^7.9.5",
25+
"babel-loader": "^8.1.0",
2526
"chai": "^4.2.0",
2627
"chai-as-promised": "^7.1.1",
2728
"clean-webpack-plugin": "^3.0.0",
28-
"core-js": "^3.5.0",
29+
"core-js": "^3.6.5",
2930
"eslint": "^5.16.0",
3031
"html-webpack-exclude-assets-plugin": "0.0.7",
3132
"html-webpack-plugin": "^3.2.0",
32-
"karma": "^4.0.0",
33+
"karma": "^4.4.1",
3334
"karma-bamboo-reporter": "^0.1.2",
3435
"karma-chrome-launcher": "^2.2.0",
3536
"karma-mocha": "^1.3.0",
3637
"karma-mocha-reporter": "^2.2.5",
3738
"karma-sauce-launcher": "^2.0.2",
3839
"karma-sourcemap-loader": "^0.3.7",
3940
"karma-webpack": "^4.0.2",
40-
"mocha": "^6.2.2",
41+
"mocha": "^6.2.3",
4142
"sinon": "^7.5.0",
42-
"sinon-chai": "^3.3.0",
43-
"terser-webpack-plugin": "^2.0.1",
44-
"webpack": "^4.29.0",
43+
"sinon-chai": "^3.5.0",
44+
"webpack": "^4.42.1",
45+
"webpack-bundle-analyzer": "^3.7.0",
4546
"webpack-cli": "^3.3.5",
46-
"webpack-dev-server": "^3.1.14"
47+
"webpack-dev-server": "^3.10.3"
4748
},
4849
"dependencies": {},
4950
"main": "dist/index.js",

test/lib/consenthandler/localProxy.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ describe("Local Proxy test", ()=> {
9595

9696
it("create Proxy", () => {
9797
const fCmp = function(cmd, args, callback) {
98-
console.log('cmd: ' + cmd);
9998
if (sampleData[cmd])
10099
callback(sampleData[cmd], true);
101100
else

test/lib/pubcidHandler.spec.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,15 @@ describe('PubcidHandler', ()=> {
397397
});
398398

399399
describe('pixels and extend', ()=>{
400-
let pixelSpy, cookieSpy;
400+
let pixelStub, cookieSpy;
401401
before(()=>{
402-
pixelSpy = sinon.spy(utils, 'firePixel');
402+
pixelStub = sinon.stub(utils, 'firePixel');
403403
cookieSpy = sinon.spy(cookieUtils, 'setCookie');
404404
clearAll();
405405
});
406406

407407
beforeEach(() => {
408-
pixelSpy.resetHistory();
408+
pixelStub.resetHistory();
409409
cookieSpy.resetHistory();
410410
});
411411

@@ -423,7 +423,7 @@ describe('PubcidHandler', ()=> {
423423
cookieSpy.resetHistory();
424424
handler.fetchPubcid();
425425
sinon.assert.callCount(cookieSpy, 1);
426-
sinon.assert.callCount(pixelSpy, 0);
426+
sinon.assert.callCount(pixelStub, 0);
427427
});
428428

429429
it('extend is disabled', () => {
@@ -436,7 +436,7 @@ describe('PubcidHandler', ()=> {
436436
cookieSpy.resetHistory();
437437
handler.fetchPubcid();
438438
sinon.assert.callCount(cookieSpy, 0);
439-
sinon.assert.callCount(pixelSpy, 0);
439+
sinon.assert.callCount(pixelStub, 0);
440440
});
441441

442442
it('fire pixel once', () => {
@@ -446,14 +446,14 @@ describe('PubcidHandler', ()=> {
446446
let pubcid = handler.fetchPubcid();
447447
expect(pubcid).to.match(uuidPattern);
448448
sinon.assert.callCount(cookieSpy, 1);
449-
sinon.assert.callCount(pixelSpy, 1);
449+
sinon.assert.callCount(pixelStub, 1);
450450

451-
expect(pixelSpy.getCall(0).args[0]).to.equal('/any/url/?id=' + encodeURIComponent('pubcid:' + pubcid));
451+
expect(pixelStub.getCall(0).args[0]).to.equal('/any/url/?id=' + encodeURIComponent('pubcid:' + pubcid));
452452

453453
// There should be no increment in counts after the 2nd call
454454
handler.fetchPubcid();
455455
sinon.assert.callCount(cookieSpy, 1);
456-
sinon.assert.callCount(pixelSpy, 1);
456+
sinon.assert.callCount(pixelStub, 1);
457457
});
458458

459459
it('fire pixel every time', () => {
@@ -463,15 +463,15 @@ describe('PubcidHandler', ()=> {
463463
let pubcid = handler.fetchPubcid();
464464
expect(pubcid).to.match(uuidPattern);
465465
sinon.assert.callCount(cookieSpy, 1);
466-
sinon.assert.callCount(pixelSpy, 1);
466+
sinon.assert.callCount(pixelStub, 1);
467467

468-
expect(pixelSpy.getCall(0).args[0]).to.equal('/any/url/?id=' + encodeURIComponent('pubcid:' + pubcid));
468+
expect(pixelStub.getCall(0).args[0]).to.equal('/any/url/?id=' + encodeURIComponent('pubcid:' + pubcid));
469469

470470
// There should be an increment in firePixel count only
471471
let pubcid2 = handler.fetchPubcid();
472472
sinon.assert.callCount(cookieSpy, 1);
473-
sinon.assert.callCount(pixelSpy, 2);
474-
expect(pixelSpy.getCall(1).args[0]).to.equal('/any/url/?id=' + encodeURIComponent('pubcid:' + pubcid2));
473+
sinon.assert.callCount(pixelStub, 2);
474+
expect(pixelStub.getCall(1).args[0]).to.equal('/any/url/?id=' + encodeURIComponent('pubcid:' + pubcid2));
475475
});
476476
});
477477
});

webpack.config.js

Lines changed: 76 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,104 @@
11
'use strict';
22

3-
const webpack = require('webpack');
43
const HtmlWebpackPlugin = require('html-webpack-plugin');
54
const HtmlWebpackExcludeAssetsPlugin = require('html-webpack-exclude-assets-plugin');
6-
const TerserPlugin = require('terser-webpack-plugin');
75
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
6+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
87

98
module.exports = (env = {}, args = {}) => {
10-
console.log('Mode is ' + args.mode);
9+
const mode = args.mode;
10+
const mapType = (mode === 'production') ? 'hidden-source-map' : 'inline-source-map';
1111

12-
const isProd = args.mode === 'production';
12+
console.log('Mode: ' + mode);
13+
console.log('Map: ' + mapType);
1314

14-
let config = {
15+
// Return 2 configs in an array. First one is a minimized script that is placed in CDN,
16+
// and the second one as a library used by other projects.
17+
18+
const scriptConfig = {
19+
mode: mode,
1520
entry: {
16-
'pubcid.min': './src/pubcid.js',
17-
'index':'./src/index.js'
21+
'pubcid.min': './src/pubcid.js'
1822
},
1923
output: {
2024
filename: '[name].js',
21-
path: __dirname + '/dist',
22-
libraryTarget: 'umd'
25+
path: __dirname + '/dist'
2326
}
2427
,
2528
module: {
2629
rules: [
2730
{
2831
test: /\.js$/,
29-
exclude: /(node_modules|bower_components)/,
32+
exclude: /node_modules/,
3033
use: {
31-
loader: 'babel-loader'
34+
loader: 'babel-loader',
35+
options: {
36+
// Turn on polyfill with core-js
37+
presets: [['@babel/preset-env', {
38+
// debug: true,
39+
useBuiltIns: "usage",
40+
corejs: 3,}]],
41+
42+
// Transform to commonjs modules so sinon spies can work in unit tests
43+
plugins: ['@babel/plugin-transform-modules-commonjs'],
44+
},
3245
}
3346
}
3447
]
3548
},
3649
plugins: [
37-
new CleanWebpackPlugin()
50+
new CleanWebpackPlugin(
51+
// Only clean up files related to scripts before build
52+
{cleanOnceBeforeBuildPatterns: ['pubcid.*', 'stats.json']}
53+
)
3854
]
3955
,
4056
devServer: {
4157
host: 'mockpub'
4258
},
43-
optimization: {
44-
minimize: true,
45-
minimizer: [
46-
new TerserPlugin({
47-
include: /\.min\.js$/
48-
}),
49-
]
59+
devtool: mapType
60+
};
61+
62+
const libConfig = {
63+
mode: mode,
64+
entry: {
65+
'index':'./src/index.js'
66+
},
67+
output: {
68+
filename: 'index.js',
69+
path: __dirname + '/dist',
70+
libraryTarget: 'umd'
5071
},
51-
devtool: 'hidden-source-map'
72+
module: {
73+
rules: [
74+
{
75+
test: /\.(js)$/,
76+
exclude: /node_modules/,
77+
use: {
78+
loader: 'babel-loader',
79+
options: {
80+
// No polyfill
81+
// Transform to commonjs module so that clients can call exported functions
82+
plugins: ['@babel/plugin-transform-modules-commonjs'],
83+
},
84+
}
85+
},
86+
],
87+
},
88+
plugins: [
89+
new CleanWebpackPlugin(
90+
// Only clean up files related to library before build
91+
{cleanOnceBeforeBuildPatterns: ['index.*']}
92+
)
93+
],
94+
devtool: mapType
5295
};
5396

5497
// Generate the test page if in dev mode
5598

56-
if (!isProd) {
57-
config.plugins.push(
99+
if (mode !== 'production') {
100+
scriptConfig.plugins = scriptConfig.plugins || [];
101+
scriptConfig.plugins.push(
58102
new HtmlWebpackPlugin({
59103
filename: 'pubcid.html',
60104
template: 'src/pubcid.html',
@@ -63,6 +107,15 @@ module.exports = (env = {}, args = {}) => {
63107
new HtmlWebpackExcludeAssetsPlugin()
64108
);
65109
}
110+
else {
111+
scriptConfig.plugins.push(
112+
new BundleAnalyzerPlugin({
113+
analyzerMode: 'disabled',
114+
generateStatsFile: true,
115+
statsOptions: { source: false }
116+
})
117+
)
118+
}
66119

67-
return config;
120+
return [scriptConfig, libConfig];
68121
};

0 commit comments

Comments
 (0)