From 9678aa9090453a9d0d8f09039422119d1695b1f4 Mon Sep 17 00:00:00 2001 From: Alexander Marks Date: Thu, 19 Apr 2018 20:50:18 -0700 Subject: [PATCH 1/8] Modules support now requires dynamic import and import.meta. Specifically, this means: - Safari no longer supports modules. Recent Technology Preview builds have support, but I'm not confident about what user agent matching we can rely on there. - Chrome modules support is now from 64 instead of 61. - Vivaldi supports modules (tested). Part of #117 --- packages/browser-capabilities/CHANGELOG.md | 1 + packages/browser-capabilities/README.md | 4 +--- .../browser-capabilities/src/browser-capabilities.ts | 10 +++++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/browser-capabilities/CHANGELOG.md b/packages/browser-capabilities/CHANGELOG.md index b0087ab63..e183d25ad 100644 --- a/packages/browser-capabilities/CHANGELOG.md +++ b/packages/browser-capabilities/CHANGELOG.md @@ -1,6 +1,7 @@ # Change Log ## [Unreleased] +- Modules support now requires dynamic import and import.meta. ## [0.2.2] - 2018-01-01 - Add Chrome Headless browser. diff --git a/packages/browser-capabilities/README.md b/packages/browser-capabilities/README.md index fc48e2259..182b5a9f2 100644 --- a/packages/browser-capabilities/README.md +++ b/packages/browser-capabilities/README.md @@ -1,5 +1,3 @@ -[![Travis Build Status](https://travis-ci.org/Polymer/browser-capabilities.svg?branch=master)](https://travis-ci.org/Polymer/browser-capabilities) -[![Build status](https://ci.appveyor.com/api/projects/status/gn1iuc8qgx8l86yf?svg=true)](https://ci.appveyor.com/project/aomarks/browser-capabilities) [![NPM version](http://img.shields.io/npm/v/browser-capabilities.svg)](https://www.npmjs.com/package/browser-capabilities) # browser-capabilities @@ -13,5 +11,5 @@ The following keywords are supported. See [browser-capabilities.ts](https://gith | es2015 | [ECMAScript 2015 (aka ES6)](https://developers.google.com/web/shows/ttt/series-2/es2015) | push | [HTTP/2 Server Push](https://developers.google.com/web/fundamentals/performance/http2/#server-push) | serviceworker | [Service Worker API](https://developers.google.com/web/fundamentals/getting-started/primers/service-workers) -| modules | [JavaScript Modules](https://www.chromestatus.com/feature/5365692190687232) +| modules | [JavaScript Modules](https://www.chromestatus.com/feature/5365692190687232) (including dynamic `import()` and `import.meta`) diff --git a/packages/browser-capabilities/src/browser-capabilities.ts b/packages/browser-capabilities/src/browser-capabilities.ts index 8dabeee9d..afa065d1e 100644 --- a/packages/browser-capabilities/src/browser-capabilities.ts +++ b/packages/browser-capabilities/src/browser-capabilities.ts @@ -24,7 +24,7 @@ export type BrowserCapability = 'push'| // Service Worker API. 'serviceworker'| - // JavaScript modules. + // JavaScript modules, including dynamic import and import.meta. 'modules'; // TODO: This should have type UAParser, but its typings are wrong so that @@ -35,7 +35,7 @@ const chrome = { es2015: since(49), push: since(41), serviceworker: since(45), - modules: since(61), + modules: since(64), }; const browserPredicates: { @@ -54,13 +54,13 @@ const browserPredicates: { es2015: since(1), push: since(1), serviceworker: since(1), - modules: () => false, + modules: since(1, 14), }, 'Mobile Safari': { es2015: since(10), push: since(9, 2), serviceworker: () => false, - modules: since(10, 3), + modules: () => false, }, 'Safari': { es2015: since(10), @@ -72,7 +72,7 @@ const browserPredicates: { }, // https://webkit.org/status/#specification-service-workers serviceworker: () => false, - modules: since(10, 1), + modules: () => false, }, 'Edge': { // Edge versions before 15.15063 may contain a JIT bug affecting ES6 From e13a0c68223140d6aa08aefe63b865c4df114ed8 Mon Sep 17 00:00:00 2001 From: Alexander Marks Date: Fri, 20 Apr 2018 13:58:24 -0700 Subject: [PATCH 2/8] Fix tests. --- .../src/test/browser-capabilities_test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/browser-capabilities/src/test/browser-capabilities_test.ts b/packages/browser-capabilities/src/test/browser-capabilities_test.ts index e16887041..c559e9f60 100644 --- a/packages/browser-capabilities/src/test/browser-capabilities_test.ts +++ b/packages/browser-capabilities/src/test/browser-capabilities_test.ts @@ -27,13 +27,13 @@ suite('capabilities', function() { test('chrome has all the capabilities', () => { assertBrowserCapabilities( - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.31 Safari/537.36', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36', ['es2015', 'push', 'serviceworker', 'modules']); }); test('chrome headless has all the capabilities', () => { assertBrowserCapabilities( - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/61.0.3163.31 Safari/537.36', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/66.0.3359.117 Safari/537.36', ['es2015', 'push', 'serviceworker', 'modules']); }); @@ -49,10 +49,10 @@ suite('capabilities', function() { test('safari push capability is predicated on macOS version', () => { assertBrowserCapabilities( 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30', - ['es2015', 'modules']); + ['es2015']); assertBrowserCapabilities( 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30', - ['es2015', 'push', 'modules']); + ['es2015', 'push']); }); test('parseVersion parses with fallback to -1', () => { From f52927db1625df81e28986915dbda186ada1a88e Mon Sep 17 00:00:00 2001 From: Alexander Marks Date: Fri, 20 Apr 2018 14:00:40 -0700 Subject: [PATCH 3/8] Remove irrelevant test. --- .../src/test/browser-capabilities_test.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/browser-capabilities/src/test/browser-capabilities_test.ts b/packages/browser-capabilities/src/test/browser-capabilities_test.ts index c559e9f60..097e5e869 100644 --- a/packages/browser-capabilities/src/test/browser-capabilities_test.ts +++ b/packages/browser-capabilities/src/test/browser-capabilities_test.ts @@ -46,15 +46,6 @@ suite('capabilities', function() { ['es2015', 'push']); }); - test('safari push capability is predicated on macOS version', () => { - assertBrowserCapabilities( - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30', - ['es2015']); - assertBrowserCapabilities( - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30', - ['es2015', 'push']); - }); - test('parseVersion parses with fallback to -1', () => { assert.deepEqual(capabilities.parseVersion('37'), [37]); assert.deepEqual(capabilities.parseVersion('10.987.00.1'), [10, 987, 0, 1]); From e74f17d451bf058522e187c6b1dcc9174a8a93f4 Mon Sep 17 00:00:00 2001 From: Alexander Marks Date: Fri, 20 Apr 2018 14:03:26 -0700 Subject: [PATCH 4/8] Add more CHANGELOG entries. --- packages/cli/CHANGELOG.md | 4 ++++ packages/polyserve/CHANGELOG.md | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 5483133d8..f2335e679 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -4,6 +4,10 @@ ## Unreleased * `build`: * Disable Babel `minify-constant-folding` plugin when minifying. This plugin has a bug that breaks when a constant is exported from a module (https://github.com/babel/minify/issues/820). +* `serve`, `test`: + * Stricter requirements for determining when a browser supports modules, and + hence when to automatically transform modules to AMD. We now require support + for dynamic import and import.meta. ## v1.7.0-pre.13 [04-19-2018] diff --git a/packages/polyserve/CHANGELOG.md b/packages/polyserve/CHANGELOG.md index cec5b7bad..6eca8d229 100644 --- a/packages/polyserve/CHANGELOG.md +++ b/packages/polyserve/CHANGELOG.md @@ -5,7 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). - +## Unreleased +* Stricter requirements for determining when a browser supports modules, and + hence when to automatically transform modules to AMD. We now require support + for dynamic import and import.meta. ## [0.27.6] (2018-04-18) From 172dca264ecc43386d80354f4c1e1015ab226610 Mon Sep 17 00:00:00 2001 From: Alexander Marks Date: Fri, 20 Apr 2018 14:04:35 -0700 Subject: [PATCH 5/8] add CHANGELOG for service workers --- packages/browser-capabilities/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/browser-capabilities/CHANGELOG.md b/packages/browser-capabilities/CHANGELOG.md index e183d25ad..f2b46c51d 100644 --- a/packages/browser-capabilities/CHANGELOG.md +++ b/packages/browser-capabilities/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] - Modules support now requires dynamic import and import.meta. +- Latest Safari now supports service workers. ## [0.2.2] - 2018-01-01 - Add Chrome Headless browser. From 7e84cd989b1441d99923e6ab305e095026dcd388 Mon Sep 17 00:00:00 2001 From: Alexander Marks Date: Mon, 23 Apr 2018 17:18:54 -0700 Subject: [PATCH 6/8] Latest Safaris do support modules. --- packages/browser-capabilities/CHANGELOG.md | 2 +- packages/browser-capabilities/src/browser-capabilities.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/browser-capabilities/CHANGELOG.md b/packages/browser-capabilities/CHANGELOG.md index f2b46c51d..3234f1e38 100644 --- a/packages/browser-capabilities/CHANGELOG.md +++ b/packages/browser-capabilities/CHANGELOG.md @@ -2,7 +2,7 @@ ## [Unreleased] - Modules support now requires dynamic import and import.meta. -- Latest Safari now supports service workers. +- Latest Safari now supports service workers and modules. ## [0.2.2] - 2018-01-01 - Add Chrome Headless browser. diff --git a/packages/browser-capabilities/src/browser-capabilities.ts b/packages/browser-capabilities/src/browser-capabilities.ts index e63c06608..f44439ed7 100644 --- a/packages/browser-capabilities/src/browser-capabilities.ts +++ b/packages/browser-capabilities/src/browser-capabilities.ts @@ -58,7 +58,10 @@ const browserPredicates: { es2015: since(10), push: since(9, 2), serviceworker: since(11, 3), - modules: () => false, + modules: (ua) => { + return versionAtLeast([11], parseVersion(ua.getBrowser().version)) && + versionAtLeast([11, 3], parseVersion(ua.getOS().version)); + }, }, 'Safari': { es2015: since(10), @@ -70,7 +73,7 @@ const browserPredicates: { }, // https://webkit.org/status/#specification-service-workers serviceworker: since(11, 1), - modules: () => false, + modules: since(11, 1), }, 'Edge': { // Edge versions before 15.15063 may contain a JIT bug affecting ES6 From e45e83d81826e3cfd00d0e319a9f1a2d816973cb Mon Sep 17 00:00:00 2001 From: Alexander Marks Date: Mon, 23 Apr 2018 17:28:08 -0700 Subject: [PATCH 7/8] Add Safari OS tests. --- .../src/test/browser-capabilities_test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/browser-capabilities/src/test/browser-capabilities_test.ts b/packages/browser-capabilities/src/test/browser-capabilities_test.ts index 097e5e869..c69a4c7da 100644 --- a/packages/browser-capabilities/src/test/browser-capabilities_test.ts +++ b/packages/browser-capabilities/src/test/browser-capabilities_test.ts @@ -46,6 +46,24 @@ suite('capabilities', function() { ['es2015', 'push']); }); + test('safari push capability is predicated on macOS version', () => { + assertBrowserCapabilities( + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30', + ['es2015']); + assertBrowserCapabilities( + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30', + ['es2015', 'push']); + }); + + test('safari mobile modules capability is predicated on iOS version', () => { + assertBrowserCapabilities( + 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1', + ['es2015', 'push']); + assertBrowserCapabilities( + 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1', + ['es2015', 'push', 'modules']); + }); + test('parseVersion parses with fallback to -1', () => { assert.deepEqual(capabilities.parseVersion('37'), [37]); assert.deepEqual(capabilities.parseVersion('10.987.00.1'), [10, 987, 0, 1]); From eae9bf046ff0857fa7d0b2c049670b2f1d64932b Mon Sep 17 00:00:00 2001 From: Alexander Marks Date: Mon, 23 Apr 2018 18:01:02 -0700 Subject: [PATCH 8/8] Fix polyserve tests and add note about Safari. --- .../browser-capabilities/src/browser-capabilities.ts | 5 +++++ .../polyserve/src/test/compile-middleware_test.ts | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/browser-capabilities/src/browser-capabilities.ts b/packages/browser-capabilities/src/browser-capabilities.ts index f44439ed7..db0d93295 100644 --- a/packages/browser-capabilities/src/browser-capabilities.ts +++ b/packages/browser-capabilities/src/browser-capabilities.ts @@ -54,6 +54,11 @@ const browserPredicates: { serviceworker: since(1), modules: since(1, 14), }, + // Note that Safari intends to stop changing their user agent strings + // (https://twitter.com/rmondello/status/943545865204989953). The details of + // this are not yet clear, since recent versions do seem to be changing (at + // least the OS bit). Be sure to actually test real user agents rather than + // making assumptions based on release notes. 'Mobile Safari': { es2015: since(10), push: since(9, 2), diff --git a/packages/polyserve/src/test/compile-middleware_test.ts b/packages/polyserve/src/test/compile-middleware_test.ts index 1378bae79..08081b97d 100644 --- a/packages/polyserve/src/test/compile-middleware_test.ts +++ b/packages/polyserve/src/test/compile-middleware_test.ts @@ -33,12 +33,13 @@ const userAgentsThatDontSupportES2015OrModules = [ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.14986', ]; -const chrome61UA = - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.39 Safari/537.36'; +const chrome66UA = + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36'; const userAgentsThatSupportES2015AndModules = [ - chrome61UA, - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8', + chrome66UA, + 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15', ]; function readTestFile(p: string) { @@ -255,7 +256,7 @@ suite('compile-middleware', () => { }); suite('module specifier rewriting', () => { - const userAgent = chrome61UA; + const userAgent = chrome66UA; async function assertGolden(requestPath: string, goldenPath: string) { const golden = readTestFile(goldenPath);