Skip to content

Commit

Permalink
Merge pull request meteor#11671 from meteor/feature/firefox-mobile-br…
Browse files Browse the repository at this point in the history
…owser-alias

Added `firefoxMobile` as an alias for `firefox` in modern-broswers
  • Loading branch information
filipenevola authored Oct 8, 2021
2 parents bb6ec6a + 5257602 commit 08039d5
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 89 deletions.
3 changes: 3 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
* `[email protected]`
- Revert `core-js` to v3.15.2 due to issues in legacy build with arrays, [see issue for more details](https://github.com/meteor/meteor/issues/11662)

* `[email protected]`
- Added `firefoxMobile` as an alias for `firefox`

## v2.4, 2021-09-15

#### Highlights
Expand Down
2 changes: 1 addition & 1 deletion packages/ecmascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ Here is a list of the Babel transformers that are currently enabled:

The ECMAScript 2015 standard library has grown to include new APIs and
data structures, some of which can be implemented ("polyfilled") using
JavaScript that runs in all engines and browsers today. Here are three new
JavaScript that runs in all engines and browsers today. Here are four new
constructors that are guaranteed to be available when the `ecmascript`
package is installed:

Expand Down
170 changes: 93 additions & 77 deletions packages/modern-browsers/modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const hasOwn = Object.prototype.hasOwnProperty;
const browserAliases = {
chrome: [
// chromeMobile*, per https://github.com/meteor/meteor/pull/9793,
"chromeMobile",
"chromeMobileIOS",
"chromeMobileWebView",
'chromeMobile',
'chromeMobileIOS',
'chromeMobileWebView',

// The major version number of Chromium and Headless Chrome track with the
// releases of Chrome Dev, Canary and Stable, so we should be okay to
Expand All @@ -18,19 +18,21 @@ const browserAliases = {
// Chromium is particularly important to list here since, unlike macOS
// builds, Linux builds list Chromium in the userAgent along with Chrome:
// e.g. Chromium/70.0.3538.77 Chrome/70.0.3538.77
"chromium",
"headlesschrome",
'chromium',
'headlesschrome',
],

// If a call to setMinimumBrowserVersions specifies Edge 12 as a minimum
// version, that means no version of Internet Explorer pre-Edge should
// be classified as modern. This edge:["ie"] alias effectively enforces
// that logic, because there is no IE12. #9818 #9839
edge: ["ie"],
edge: ['ie'],

firefox: ['firefoxMobile'],

// The webapp package converts browser names to camel case, so
// mobile_safari and mobileSafari should be synonymous.
mobile_safari: ["mobileSafari", "mobileSafariUI", "mobileSafariUI/WKWebView"],
mobile_safari: ['mobileSafari', 'mobileSafariUI', 'mobileSafariUI/WKWebView'],
};

// Expand the given minimum versions by reusing chrome versions for
Expand All @@ -49,7 +51,7 @@ function applyAliases(versions) {
if (hasOwn.call(lowerCaseVersions, original)) {
aliases.forEach(alias => {
alias = alias.toLowerCase();
if (! hasOwn.call(lowerCaseVersions, alias)) {
if (!hasOwn.call(lowerCaseVersions, alias)) {
lowerCaseVersions[alias] = lowerCaseVersions[original];
}
});
Expand All @@ -66,17 +68,17 @@ function applyAliases(versions) {
// webapp via request.browser, return true if that browser qualifies as
// "modern" according to all requested version constraints.
function isModern(browser) {
const lowerCaseName = browser &&
typeof browser.name === "string" &&
browser.name.toLowerCase();
const lowerCaseName =
browser && typeof browser.name === 'string' && browser.name.toLowerCase();

return !!lowerCaseName &&
return (
!!lowerCaseName &&
hasOwn.call(minimumVersions, lowerCaseName) &&
greaterThanOrEqualTo([
~~browser.major,
~~browser.minor,
~~browser.patch,
], minimumVersions[lowerCaseName].version);
greaterThanOrEqualTo(
[~~browser.major, ~~browser.minor, ~~browser.patch],
minimumVersions[lowerCaseName].version
)
);
}

// Any package that depends on the modern-browsers package can call this
Expand All @@ -90,22 +92,24 @@ function setMinimumBrowserVersions(versions, source) {
Object.keys(lowerCaseVersions).forEach(lowerCaseName => {
const version = lowerCaseVersions[lowerCaseName];

if (hasOwn.call(minimumVersions, lowerCaseName) &&
! greaterThan(version, minimumVersions[lowerCaseName].version)) {
if (
hasOwn.call(minimumVersions, lowerCaseName) &&
!greaterThan(version, minimumVersions[lowerCaseName].version)
) {
return;
}

minimumVersions[lowerCaseName] = {
version: copy(version),
source: source || getCaller("setMinimumBrowserVersions")
source: source || getCaller('setMinimumBrowserVersions'),
};
});
}

function getCaller(calleeName) {
const error = new Error;
const error = new Error();
Error.captureStackTrace(error);
const lines = error.stack.split("\n");
const lines = error.stack.split('\n');
let caller;
lines.some((line, i) => {
if (line.indexOf(calleeName) >= 0) {
Expand All @@ -120,17 +124,17 @@ Object.assign(exports, {
isModern,
setMinimumBrowserVersions,
calculateHashOfMinimumVersions() {
const { createHash } = require("crypto");
return createHash("sha1").update(
JSON.stringify(minimumVersions)
).digest("hex");
}
const { createHash } = require('crypto');
return createHash('sha1')
.update(JSON.stringify(minimumVersions))
.digest('hex');
},
});

// For making defensive copies of [major, minor, ...] version arrays, so
// they don't change unexpectedly.
function copy(version) {
if (typeof version === "number") {
if (typeof version === 'number') {
return version;
}

Expand All @@ -142,17 +146,17 @@ function copy(version) {
}

function greaterThanOrEqualTo(a, b) {
return ! greaterThan(b, a);
return !greaterThan(b, a);
}

function greaterThan(a, b) {
const as = (typeof a === "number") ? [a] : a;
const bs = (typeof b === "number") ? [b] : b;
const as = typeof a === 'number' ? [a] : a;
const bs = typeof b === 'number' ? [b] : b;
const maxLen = Math.max(as.length, bs.length);

for (let i = 0; i < maxLen; ++i) {
a = (i < as.length) ? as[i] : 0;
b = (i < bs.length) ? bs[i] : 0;
a = i < as.length ? as[i] : 0;
b = i < bs.length ? bs[i] : 0;

if (a > b) {
return true;
Expand All @@ -167,49 +171,61 @@ function greaterThan(a, b) {
}

function makeSource(feature) {
return module.id + " (" + feature + ")";
return module.id + ' (' + feature + ')';
}

setMinimumBrowserVersions({
chrome: 49,
edge: 12,
firefox: 45,
mobileSafari: [9, 2],
opera: 36,
safari: 9,
// Electron 1.0.0+ matches Chromium 49, per
// https://github.com/Kilian/electron-to-chromium/blob/master/full-versions.js
electron: 1,
}, makeSource("classes"));

setMinimumBrowserVersions({
chrome: 39,
edge: 13,
firefox: 26,
mobileSafari: 10,
opera: 26,
safari: 10,
// Disallow any version of PhantomJS.
phantomjs: Infinity,
electron: [0, 20],
}, makeSource("generator functions"));

setMinimumBrowserVersions({
chrome: 41,
edge: 13,
firefox: 34,
mobileSafari: [9, 2],
opera: 29,
safari: [9, 1],
electron: [0, 24],
}, makeSource("template literals"));

setMinimumBrowserVersions({
chrome: 38,
edge: 12,
firefox: 36,
mobileSafari: 9,
opera: 25,
safari: 9,
electron: [0, 20],
}, makeSource("symbols"));
setMinimumBrowserVersions(
{
chrome: 49,
edge: 12,
firefox: 45,
mobileSafari: [9, 2],
opera: 36,
safari: 9,
// Electron 1.0.0+ matches Chromium 49, per
// https://github.com/Kilian/electron-to-chromium/blob/master/full-versions.js
electron: 1,
},
makeSource('classes')
);

setMinimumBrowserVersions(
{
chrome: 39,
edge: 13,
firefox: 26,
mobileSafari: 10,
opera: 26,
safari: 10,
// Disallow any version of PhantomJS.
phantomjs: Infinity,
electron: [0, 20],
},
makeSource('generator functions')
);

setMinimumBrowserVersions(
{
chrome: 41,
edge: 13,
firefox: 34,
mobileSafari: [9, 2],
opera: 29,
safari: [9, 1],
electron: [0, 24],
},
makeSource('template literals')
);

setMinimumBrowserVersions(
{
chrome: 38,
edge: 12,
firefox: 36,
mobileSafari: 9,
opera: 25,
safari: 9,
electron: [0, 20],
},
makeSource('symbols')
);
23 changes: 12 additions & 11 deletions packages/modern-browsers/package.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
Package.describe({
name: "modern-browsers",
version: "0.1.6",
summary: "API for defining the boundary between modern and legacy " +
"JavaScript clients",
documentation: "README.md"
name: 'modern-browsers',
version: '0.1.7',
summary:
'API for defining the boundary between modern and legacy ' +
'JavaScript clients',
documentation: 'README.md',
});

Package.onUse(function(api) {
api.use("modules");
api.mainModule("modern.js", "server");
api.use('modules');
api.mainModule('modern.js', 'server');
});

Package.onTest(function(api) {
api.use("ecmascript");
api.use("tinytest");
api.use("modern-browsers");
api.mainModule("modern-tests.js", "server");
api.use('ecmascript');
api.use('tinytest');
api.use('modern-browsers');
api.mainModule('modern-tests.js', 'server');
});

0 comments on commit 08039d5

Please sign in to comment.