From 29c5bb651320f20bc17fea0bdfa4f1d130e83512 Mon Sep 17 00:00:00 2001 From: Ryan Lindskog Date: Mon, 10 Dec 2018 13:35:04 -0800 Subject: [PATCH] refactor: remove caniuse-lite dependency (#4419) --- packages/common/data/modern-browsers.json | 15 ++++++++------- packages/server/package.json | 5 +++-- packages/server/src/middleware/modern.js | 18 ++++++++++++------ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/packages/common/data/modern-browsers.json b/packages/common/data/modern-browsers.json index e1d2997e51..d8964e1b3b 100644 --- a/packages/common/data/modern-browsers.json +++ b/packages/common/data/modern-browsers.json @@ -1,9 +1,10 @@ { - "edge": "16", - "firefox": "60", - "chrome": "61", - "safari": "10.1", - "opera": "48", - "ios_saf": "10.3", - "and_ff": "60" + "Edge": "16", + "Firefox": "60", + "Chrome": "61", + "Chrome Headless": "61", + "Chromium": "61", + "Safari": "10.1", + "Opera": "48", + "Mobile Safari": "10.3" } diff --git a/packages/server/package.json b/packages/server/package.json index 26cb0931a6..7cb1d6da45 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -11,7 +11,6 @@ "@nuxt/common": "2.3.4", "@nuxt/config": "2.3.4", "@nuxtjs/youch": "^4.2.3", - "browserslist-useragent": "^2.0.1", "chalk": "^2.4.1", "compression": "^1.7.3", "connect": "^3.6.6", @@ -22,9 +21,11 @@ "ip": "^1.1.5", "launch-editor-middleware": "^2.2.1", "pify": "^4.0.1", + "semver": "^5.6.0", "serve-placeholder": "^1.1.0", "serve-static": "^1.13.2", - "server-destroy": "^1.0.1" + "server-destroy": "^1.0.1", + "ua-parser-js": "^0.7.19" }, "publishConfig": { "access": "public" diff --git a/packages/server/src/middleware/modern.js b/packages/server/src/middleware/modern.js index a0f3616cb6..a571a983ec 100644 --- a/packages/server/src/middleware/modern.js +++ b/packages/server/src/middleware/modern.js @@ -1,16 +1,22 @@ import chalk from 'chalk' import consola from 'consola' import { ModernBrowsers } from '@nuxt/common' -import { matchesUA } from 'browserslist-useragent' +import UAParser from 'ua-parser-js' +import semver from 'semver' const modernBrowsers = Object.keys(ModernBrowsers) - .map(browser => `${browser} >= ${ModernBrowsers[browser]}`) + .reduce((allBrowsers, browser) => { + allBrowsers[browser] = semver.coerce(ModernBrowsers[browser]) + return allBrowsers + }, {}) const isModernBrowser = (ua) => { - return Boolean(ua) && matchesUA(ua, { - allowHigherVersions: true, - browsers: modernBrowsers - }) + if (!ua) { + return false + } + const { browser } = UAParser(ua) + const browserVersion = semver.coerce(browser.version) + return modernBrowsers[browser.name] && semver.gte(browserVersion, modernBrowsers[browser.name]) } let detected = false