import Parser from 'ua-parser-js' ; import nativeModules from '@babel/compat-data/native-modules' ; import compareVersions from 'compare-versions' ; import { ModernServerContext } from '../../context' ; import { NativeModuleNameMap } from './browser-list' ; export const supportModern = ( context ) => { if ( context . query . modern_es6 ) { return true ; } const userAgent = context . headers [ 'user-agent' ] ; if ( ! userAgent || typeof userAgent !== 'string' ) { return false ; } const parsedUA = Parser ( userAgent ) ; const browserName = parsedUA . browser . name ; const browserVersion = parsedUA . browser . version ; if ( ! browserName || ! browserVersion ) { return false ; } const nativeUAName = NativeModuleNameMap [ browserName ] ; if ( ! nativeUAName ) { return false ; } const version = nativeModules [ 'es6.module' ] [ nativeUAName ] ; if ( ! version ) { return false ; } const result = compareVersions ( browserVersion , version ) ; return result >= 0 ; } ; export const getModernEntry = ( filepath ) => filepath . replace ( /\.html$/ , '-es6.html' ) ;