Skip to content

Commit 3f3339c

Browse files
Merge pull request #37 from prebid/master
Update remote fork
2 parents 375f902 + 59e830f commit 3f3339c

File tree

899 files changed

+69869
-62669
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

899 files changed

+69869
-62669
lines changed

.circleci/config.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ aliases:
77
- &environment
88
docker:
99
# specify the version you desire here
10-
- image: cimg/node:16.20-browsers
10+
- image: cimg/node:20.14.0-browsers
1111
resource_class: xlarge
1212
# Specify service dependencies here if necessary
1313
# CircleCI maintains a library of pre-built images
@@ -18,8 +18,6 @@ aliases:
1818
- &restore_dep_cache
1919
keys:
2020
- v1-dependencies-{{ checksum "package.json" }}
21-
# fallback to using the latest cache if no exact match is found
22-
- v1-dependencies-
2321

2422
- &save_dep_cache
2523
paths:

.devcontainer/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG VARIANT="12"
1+
ARG VARIANT="20"
22
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:${VARIANT}
33

44
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor > /usr/share/keyrings/yarn-archive-keyring.gpg

.eslintrc.js

+38
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ module.exports = {
6161
'no-useless-escape': 'off',
6262
'no-console': 'error',
6363
'jsdoc/check-types': 'off',
64+
'jsdoc/no-defaults': 'off',
6465
'jsdoc/newline-after-description': 'off',
6566
'jsdoc/require-jsdoc': 'off',
6667
'jsdoc/require-param': 'off',
@@ -89,11 +90,48 @@ module.exports = {
8990
name: 'require',
9091
message: 'use import instead'
9192
}
93+
],
94+
'prebid/no-global': [
95+
'error',
96+
...['localStorage', 'sessionStorage'].map(name => ({name, message: 'use storageManager instead'})),
97+
{
98+
name: 'XMLHttpRequest',
99+
message: 'use ajax.js instead'
100+
},
101+
],
102+
'prebid/no-member': [
103+
'error',
104+
{
105+
name: 'cookie',
106+
target: 'document',
107+
message: 'use storageManager instead'
108+
},
109+
{
110+
name: 'sendBeacon',
111+
target: 'navigator',
112+
message: 'use ajax.js instead'
113+
},
114+
...['outerText', 'innerText'].map(name => ({
115+
name,
116+
message: 'use .textContent instead'
117+
}))
92118
]
93119
}
94120
})).concat([{
95121
// code in other packages (such as plugins/eslint) is not "seen" by babel and its parser will complain.
96122
files: 'plugins/*/**/*.js',
97123
parser: 'esprima'
124+
}, {
125+
files: '**BidAdapter.js',
126+
rules: {
127+
'no-restricted-imports': [
128+
'error', {
129+
patterns: [
130+
'**/src/events.js',
131+
'**/src/adloader.js'
132+
]
133+
}
134+
]
135+
}
98136
}])
99137
};

.github/PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ For any user facing change, submit a link to a PR on the docs repo at https://gi
4141
}
4242
```
4343
44-
Be sure to test the integration with your adserver using the [Hello World](/integrationExamples/gpt/hello_world.html) sample page. -->
44+
Be sure to test the integration with your adserver using the [Hello World](https://github.com/prebid/Prebid.js/blob/master/integrationExamples/gpt/hello_world.html) sample page. -->
4545

4646

4747
## Other information

.github/codeql/codeql-config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ paths:
22
- src
33
- modules
44
- libraries
5+
queries:
6+
- name: Prebid queries
7+
uses: ./.github/codeql/queries
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @id prebid/device-memory
3+
* @name Access to navigator.deviceMemory
4+
* @kind problem
5+
* @problem.severity warning
6+
* @description Finds uses of deviceMemory
7+
*/
8+
9+
import prebid
10+
11+
from SourceNode nav
12+
where
13+
nav = windowPropertyRead("navigator")
14+
select nav.getAPropertyRead("deviceMemory"), "deviceMemory is an indicator of fingerprinting"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @id prebid/hardware-concurrency
3+
* @name Access to navigator.hardwareConcurrency
4+
* @kind problem
5+
* @problem.severity warning
6+
* @description Finds uses of hardwareConcurrency
7+
*/
8+
9+
import prebid
10+
11+
from SourceNode nav
12+
where
13+
nav = windowPropertyRead("navigator")
14+
select nav.getAPropertyRead("hardwareConcurrency"), "hardwareConcurrency is an indicator of fingerprinting"

.github/codeql/queries/prebid.qll

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import javascript
2+
import DataFlow
3+
4+
SourceNode otherWindow() {
5+
result = globalVarRef("top") or
6+
result = globalVarRef("self") or
7+
result = globalVarRef("parent") or
8+
result = globalVarRef("frames").getAPropertyRead() or
9+
result = DOM::documentRef().getAPropertyRead("defaultView")
10+
}
11+
12+
SourceNode connectedWindow(SourceNode win) {
13+
result = win.getAPropertyRead("self") or
14+
result = win.getAPropertyRead("top") or
15+
result = win.getAPropertyRead("parent") or
16+
result = win.getAPropertyRead("frames").getAPropertyRead() or
17+
result = win.getAPropertyRead("document").getAPropertyRead("defaultView")
18+
}
19+
20+
SourceNode relatedWindow(SourceNode win) {
21+
result = connectedWindow(win) or
22+
result = relatedWindow+(connectedWindow(win))
23+
}
24+
25+
SourceNode anyWindow() {
26+
result = otherWindow() or
27+
result = relatedWindow(otherWindow())
28+
}
29+
30+
/*
31+
Matches uses of property `prop` done on any window object.
32+
*/
33+
SourceNode windowPropertyRead(string prop) {
34+
result = globalVarRef(prop) or
35+
result = anyWindow().getAPropertyRead(prop)
36+
}

.github/codeql/queries/qlpack.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
library: false
3+
warnOnImplicitThis: false
4+
name: queries
5+
version: 0.0.1
6+
dependencies:
7+
codeql/javascript-all: ^1.1.1
8+
codeql/javascript-queries: ^1.1.0

.github/release-drafter.yml

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
name-template: 'Prebid $RESOLVED_VERSION Release'
33
tag-template: '$RESOLVED_VERSION'
4+
autolabeler:
5+
- label: 'maintenance'
6+
title:
7+
- '/^(?!.*(bug|initial|release|fix)).*$/i'
48
categories:
59
- title: '🚀 New Features'
610
label: 'feature'

.github/workflows/jscpd.yml

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Check for Duplicated Code
2+
3+
on:
4+
pull_request_target:
5+
branches:
6+
- master
7+
8+
jobs:
9+
check-duplication:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0 # Fetch all history for all branches
17+
ref: ${{ github.event.pull_request.head.sha }}
18+
19+
- name: Set up Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20'
23+
24+
- name: Install dependencies
25+
run: |
26+
npm install -g jscpd diff-so-fancy
27+
28+
- name: Create jscpd config file
29+
run: |
30+
echo '{
31+
"threshold": 20,
32+
"minTokens": 100,
33+
"reporters": [
34+
"json"
35+
],
36+
"output": "./",
37+
"pattern": "**/*.js",
38+
"ignore": "**/*spec.js"
39+
}' > .jscpd.json
40+
41+
- name: Run jscpd on entire codebase
42+
run: jscpd
43+
44+
- name: Fetch base and target branches
45+
run: |
46+
git fetch origin +refs/heads/${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }}
47+
git fetch origin +refs/pull/${{ github.event.pull_request.number }}/merge:refs/remotes/pull/${{ github.event.pull_request.number }}/merge
48+
49+
- name: Get the diff
50+
run: git diff --name-only origin/${{ github.event.pull_request.base.ref }}...refs/remotes/pull/${{ github.event.pull_request.number }}/merge > changed_files.txt
51+
52+
- name: List generated files (debug)
53+
run: ls -l
54+
55+
- name: Upload unfiltered jscpd report
56+
if: always()
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: unfiltered-jscpd-report
60+
path: ./jscpd-report.json
61+
62+
- name: Filter jscpd report for changed files
63+
run: |
64+
if [ ! -f ./jscpd-report.json ]; then
65+
echo "jscpd-report.json not found"
66+
exit 1
67+
fi
68+
echo "Filtering jscpd report for changed files..."
69+
CHANGED_FILES=$(jq -R -s -c 'split("\n")[:-1]' changed_files.txt)
70+
echo "Changed files: $CHANGED_FILES"
71+
jq --argjson changed_files "$CHANGED_FILES" '
72+
.duplicates | map(select(
73+
(.firstFile?.name as $fname | $changed_files | any(. == $fname)) or
74+
(.secondFile?.name as $sname | $changed_files | any(. == $sname))
75+
))
76+
' ./jscpd-report.json > filtered-jscpd-report.json
77+
cat filtered-jscpd-report.json
78+
79+
- name: Check if filtered jscpd report exists
80+
id: check_filtered_report
81+
run: |
82+
if [ $(wc -l < ./filtered-jscpd-report.json) -gt 1 ]; then
83+
echo "filtered_report_exists=true" >> $GITHUB_ENV
84+
else
85+
echo "filtered_report_exists=false" >> $GITHUB_ENV
86+
fi
87+
88+
- name: Upload filtered jscpd report
89+
if: env.filtered_report_exists == 'true'
90+
uses: actions/upload-artifact@v4
91+
with:
92+
name: filtered-jscpd-report
93+
path: ./filtered-jscpd-report.json
94+
95+
- name: Post GitHub comment
96+
if: env.filtered_report_exists == 'true'
97+
uses: actions/github-script@v7
98+
with:
99+
script: |
100+
const fs = require('fs');
101+
const filteredReport = JSON.parse(fs.readFileSync('filtered-jscpd-report.json', 'utf8'));
102+
let comment = "Whoa there, partner! 🌵🤠 We wrangled some duplicated code in your PR:\n\n";
103+
function link(dup) {
104+
return `https://github.com/${{ github.event.repository.full_name }}/blob/${{ github.event.pull_request.head.sha }}/${dup.name}#L${dup.start + 1}-L${dup.end - 1}`
105+
}
106+
filteredReport.forEach(duplication => {
107+
const firstFile = duplication.firstFile;
108+
const secondFile = duplication.secondFile;
109+
const lines = duplication.lines;
110+
comment += `- [\`${firstFile.name}\`](${link(firstFile)}) has ${lines} duplicated lines with [\`${secondFile.name}\`](${link(secondFile)})\n`;
111+
});
112+
comment += "\nReducing code duplication by importing common functions from a library not only makes our code cleaner but also easier to maintain. Please move the common code from both files into a library and import it in each. We hate that we have to mention this, however, commits designed to hide from this utility by renaming variables or reordering an object are poor conduct. We will not look upon them kindly! Keep up the great work! 🚀";
113+
github.rest.issues.createComment({
114+
owner: context.repo.owner,
115+
repo: context.repo.repo,
116+
issue_number: context.issue.number,
117+
body: comment
118+
});
119+
120+
- name: Fail if duplications are found
121+
if: env.filtered_report_exists == 'true'
122+
run: |
123+
echo "Duplications found, failing the check."
124+
exit 1

0 commit comments

Comments
 (0)