Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modules support now requires dynamic import and import.meta #191

Merged
merged 13 commits into from
Apr 24, 2018
2 changes: 2 additions & 0 deletions packages/browser-capabilities/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Change Log

## [Unreleased]
- Modules support now requires dynamic import and import.meta.
- Latest Safari now supports service workers and modules.

## [0.2.2] - 2018-01-01
- Add Chrome Headless browser.
Expand Down
4 changes: 1 addition & 3 deletions packages/browser-capabilities/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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`)

19 changes: 14 additions & 5 deletions packages/browser-capabilities/src/browser-capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type BrowserCapability =
'push'|
// Service Worker API.
'serviceworker'|
// JavaScript modules.
// JavaScript modules, including dynamic import and import.meta.
'modules';

export type UserAgentPredicate = (ua: InstanceType<typeof UAParser>) => boolean;
Expand All @@ -33,7 +33,7 @@ const chrome = {
es2015: since(49),
push: since(41),
serviceworker: since(45),
modules: since(61),
modules: since(64),
};

const browserPredicates: {
Expand All @@ -52,13 +52,21 @@ const browserPredicates: {
es2015: since(1),
push: since(1),
serviceworker: since(1),
modules: () => false,
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),
serviceworker: since(11, 3),
modules: since(10, 3),
modules: (ua) => {
return versionAtLeast([11], parseVersion(ua.getBrowser().version)) &&
versionAtLeast([11, 3], parseVersion(ua.getOS().version));
},
},
'Safari': {
es2015: since(10),
Expand All @@ -68,8 +76,9 @@ const browserPredicates: {
// caniuse.com.
versionAtLeast([10, 11], parseVersion(ua.getOS().version));
},
// https://webkit.org/status/#specification-service-workers
serviceworker: since(11, 1),
modules: since(10, 1),
modules: since(11, 1),
},
'Edge': {
// Edge versions before 15.15063 may contain a JIT bug affecting ES6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});

Expand All @@ -49,9 +49,18 @@ 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']);
});

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']);
});

Expand Down
4 changes: 4 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* `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).
* Added `--auto-base-path` flag. Sets the entrypoint `<base>` tag for all builds to match the name of that build. Unlike other flags, does not necessarily trigger a single one-off build.
* `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.
<!-- Add new, unreleased items here. -->

## v1.7.0-pre.13 [04-19-2018]
Expand Down
5 changes: 4 additions & 1 deletion packages/polyserve/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
## 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.
<!-- Add new, unreleased items here. -->

## [0.27.6] (2018-04-18)
Expand Down
11 changes: 6 additions & 5 deletions packages/polyserve/src/test/compile-middleware_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down