Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"/types"
],
"devDependencies": {
"@financial-times/polyfill-useragent-normaliser": "^2.0.1",
"@iarna/toml": "^2.2.5",
"apicache": "^1.6.3",
"browserstack": "1.6.1",
Expand Down
8 changes: 3 additions & 5 deletions tasks/buildsources/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
const fs = require('node:fs');
const path = require('node:path');
const uglify = require('uglify-js');
const UA = require('@financial-times/polyfill-useragent-normaliser');
const TOML = require('@iarna/toml');

const validateSource = require('./validate-source');
const semver = require('semver');
const osiApproved = require('./osi-approved');

const uaBaselines = UA.getBaselines();
delete uaBaselines.ios_chr; // https://github.com/Financial-Times/polyfill-library/issues/1202#issuecomment-1193403165
const supportedBrowsers = Object.keys(uaBaselines).sort((a, b) => a.localeCompare(b));
const configTemplate = fs.readFileSync(path.join(__dirname, '..', 'polyfill-templates', 'config.toml'), { encoding: 'utf-8' });
const supportedBrowsers = Object.keys(TOML.parse(configTemplate).browsers).sort((a, b) => a.localeCompare(b));

/**
* Polyfill represents a single polyfill directory.
Expand Down Expand Up @@ -147,7 +145,7 @@ module.exports = class Polyfill {
.then(data => {
this.config = TOML.parse(data);

// Each internal polyfill needs to target all supported browsers at all versions.
// Each internal polyfill needs to target all default browsers at all versions.
if (this.path.relative.startsWith('_') && !supportedBrowsers.every(browser => this.config.browsers[browser] === "*")) {
const browserSupport = {};
for (const browser of supportedBrowsers) browserSupport[browser] = "*";
Expand Down
8 changes: 4 additions & 4 deletions test/end-to-end/generating-bundles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const test = require('node:test');
const { describe, it } = test;

const assert = require('node:assert');
const UA = require("@financial-times/polyfill-useragent-normaliser");
const ua_parser = require('../polyfills/ua-parser');
const polyfillLibrary = require('../..');

describe("polyfill-library", function () {
Expand All @@ -13,15 +13,15 @@ describe("polyfill-library", function () {
features: {
all: {}
},
ua: new UA('other/0.0.0'),
ua: ua_parser('other/0.0.0'),
unknown: 'polyfill'
});

const bundle2 = await polyfillLibrary.getPolyfillString({
features: {
all: {}
},
ua: new UA('other/0.0.0'),
ua: ua_parser('other/0.0.0'),
unknown: 'polyfill'
});

Expand All @@ -44,7 +44,7 @@ describe("polyfill-library", function () {
'__proto__': {},
'toLocaleString': {},
},
ua: new UA('other/0.0.0'),
ua: ua_parser('other/0.0.0'),
unknown: 'polyfill'
});
});
Expand Down
32 changes: 16 additions & 16 deletions test/node/lib/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const test = require('node:test');
const { describe, it } = test;

const assert = require('node:assert');
const UA = require("@financial-times/polyfill-useragent-normaliser");
const ua_parser = require('../../polyfills/ua-parser');

const appVersion = require("../../../package.json").version;

Expand All @@ -16,7 +16,7 @@ describe(".getPolyfills(features)", async () => {
features: {
'Promise': {}
},
ua: new UA('chrome/45')
ua: ua_parser('chrome/45')
};
return polyfillio.getPolyfills(input).then(result => assert.deepEqual(result, {}));
});
Expand All @@ -29,7 +29,7 @@ describe(".getPolyfills(features)", async () => {
'es7': {},
},
excludes: ['Array.prototype.values'],
ua: new UA('chrome/61')
ua: ua_parser('chrome/61')
};
return polyfillio.getPolyfills(input).then(result => assert.deepEqual(result, {
"Array.prototype.sort": {
Expand Down Expand Up @@ -65,7 +65,7 @@ describe(".getPolyfills(features)", async () => {
features: {
'Math.sign': {}
},
ua: new UA('')
ua: ua_parser('')
}).then(result => assert.deepEqual(result, {
'Math.sign': {
"flags": new Set(["gated"]),
Expand All @@ -87,7 +87,7 @@ describe(".getPolyfills(features)", async () => {
features: {
'Math.sign': {}
},
ua: new UA(''),
ua: ua_parser(''),
unknown: 'ignore',
}).then(result => assert.deepEqual(result, {}));
});
Expand All @@ -98,7 +98,7 @@ describe(".getPolyfills(features)", async () => {
'Math.sign': {}
},
unknown: 'polyfill',
ua: new UA('')
ua: ua_parser('')
}).then(result => assert.deepEqual(result, {
'Math.sign': {
"flags": new Set(["gated"]),
Expand Down Expand Up @@ -145,7 +145,7 @@ describe(".getPolyfills(features)", async () => {
flags: []
}
},
ua: new UA('ie/8')
ua: ua_parser('ie/8')
}).then(result => assert(Object.keys(result).length > 0));
});

Expand All @@ -154,7 +154,7 @@ describe(".getPolyfills(features)", async () => {
features: {
"Math.fround": {}
},
ua: new UA("ie/9")
ua: ua_parser("ie/9")
});

assert.deepEqual(noExcludes, {
Expand All @@ -180,7 +180,7 @@ describe(".getPolyfills(features)", async () => {
"Math.fround": {}
},
excludes: ["ArrayBuffer", "non-existent-feature"],
ua: new UA("ie/9")
ua: ua_parser("ie/9")
});

assert.deepEqual(excludes, {
Expand All @@ -206,15 +206,15 @@ describe('.getPolyfillString', async () => {
features: {
default: {}
},
ua: new UA('chrome/30')
ua: ua_parser('chrome/30')
}),
polyfillio.getPolyfillString({
features: {
default: {
flags: new Set(['gated'])
}
},
ua: new UA('chrome/30')
ua: ua_parser('chrome/30')
})
]).then(results => {
assert.notEqual(results[0], results[1]);
Expand All @@ -231,14 +231,14 @@ describe('.getPolyfillString', async () => {
features: {
default: {}
},
ua: new UA('chrome/30'),
ua: ua_parser('chrome/30'),
minify: false
}),
polyfillio.getPolyfillString({
features: {
default: {}
},
ua: new UA('chrome/30'),
ua: ua_parser('chrome/30'),
minify: true
})
]).then(results => {
Expand All @@ -260,7 +260,7 @@ describe('.getPolyfillString', async () => {
features: {
default: {}
},
ua: new UA('chrome/30'),
ua: ua_parser('chrome/30'),
stream: true,
minify: false
});
Expand Down Expand Up @@ -330,7 +330,7 @@ describe('.getPolyfillString', async () => {
features: {
default: {}
},
ua: new UA('ie/9'),
ua: ua_parser('ie/9'),
stream: true,
minify: false
});
Expand All @@ -345,7 +345,7 @@ describe('.getPolyfillString', async () => {
features: {
default: {}
},
ua: new UA('ie/9'),
ua: ua_parser('ie/9'),
stream: true,
minify: false
});
Expand Down
26 changes: 11 additions & 15 deletions test/polyfills/remotetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ const promisify = require("node:util").promisify;
const path = require("node:path");
const fs = require("node:fs");
const _ = require("lodash");
const normalizeUserAgent = require('@financial-times/polyfill-useragent-normaliser').normalize;
const TestJob = require("./test-job");
const Tunnel = require("browserstack-local").Local;
const modifiedPolyfillsWithTests = require('../utils/modified-polyfills-with-tests').modifiedPolyfillsWithTests;
const UA = require("@financial-times/polyfill-useragent-normaliser");
const ua_parser = require('./ua-parser');
const { URL } = require('node:url');

// Grab all the browsers from BrowserStack which are officially supported by the polyfill service.
Expand Down Expand Up @@ -50,7 +49,8 @@ async function main() {
.replace("browser=", "")
.split("/");

console.log({ browser, browserVersionRanges });
console.log('browser:', browser || '-');
console.log('browser version ranges:', browserVersionRanges || '-');

const browsers = browserlist
.filter(b => {
Expand All @@ -66,20 +66,18 @@ async function main() {
return true;
}

return semver.satisfies(
semver.coerce(b.split("/")[1]),
browserVersionRanges,
{

}
);
return semver.satisfies(semver.coerce(b.split("/")[1]), browserVersionRanges, {});
})
.filter(uaString => {
if (uaString.startsWith("ios/")) {
uaString = uaString.replace("ios", "ios_saf");
}

if (normalizeUserAgent(uaString) === "other/0.0.0") {
const ua = ua_parser(uaString);

if (ua.normalize() === "other/0.0.0") {
console.log(uaString, ua.normalize());

return false;
}

Expand All @@ -90,8 +88,6 @@ async function main() {
// - and this browser version satisfies the version range for the polyfill
// -> include this browser in the test run

const ua = new UA(uaString);

let isNeeded = false;
for (const polyfillName in modified.affectedPolyfills) {
const polyfill = modified.affectedPolyfills[polyfillName];
Expand All @@ -112,7 +108,7 @@ async function main() {
process.exit(0);
}

console.log({ browsers });
browsers.forEach((x) => { console.log(x) });

const useragentToBrowserObject = browserWithVersion => {
const [browser, version] = browserWithVersion.split("/");
Expand Down Expand Up @@ -334,7 +330,7 @@ async function main() {
.run()
.then(job => {
if (job.state === "complete") {
const [family, version] = normalizeUserAgent(job.useragent).split("/");
const [family, version] = ua_parser(job.useragent).normalize().split("/");
_.set(
testResults,
[family, version, job.mode],
Expand Down
Loading