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

clients(viewer): remove polyfills #9553

Merged
merged 2 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions build/build-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,15 @@ async function safeWriteFileAsync(filePath, data) {
* Copy static assets.
* @return {Promise<void>}
*/
async function copyAssets() {
await cpy([
function copyAssets() {
return cpy([
'images/**/*',
'sw.js',
'manifest.json',
], distDir, {
cwd: `${sourceDir}/app/`,
parents: true,
});

// Copy polyfills.
return cpy([
'../node_modules/url-search-params/build/url-search-params.js',
'../node_modules/whatwg-fetch/fetch.js',
], `${distDir}/src/polyfills`, {cwd: sourceDir});
}

/**
Expand Down
31 changes: 4 additions & 27 deletions lighthouse-viewer/app/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,7 @@

/* global LighthouseReportViewer, Logger */

/**
* @param {string} src
* @return {Promise}
*/
function loadScript(src) {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = src;
script.onload = resolve;
script.onerror = reject;
// document.head is defined.
/** @type {HTMLHeadElement} */ (document.head).appendChild(script);
});
}

const loadPolyfillPromises = [];
if (!('fetch' in window)) {
loadPolyfillPromises.push(loadScript('./src/polyfills/fetch.js'));
}
if (!('URLSearchParams' in window)) {
loadPolyfillPromises.push(loadScript('./src/polyfills/url-search-params.js'));
}

// Lazy load polyfills that are needed. If any of the load promises fails,
// stop and don't create a report.
Promise.all(loadPolyfillPromises).then(_ => {
function main() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cheeky little trick to not lose any blame. it's a main script so it deserves a main fn.

const logEl = document.querySelector('#lh-log');
if (!logEl) {
throw new Error('logger element not found');
Expand Down Expand Up @@ -71,7 +46,9 @@ Promise.all(loadPolyfillPromises).then(_ => {
});

window.viewer = new LighthouseReportViewer();
});
}

main();

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js');
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@
"puppeteer": "^1.10.0",
"typescript": "3.5.3",
"uglify-es": "3.0.15",
"url-search-params": "0.6.1",
"whatwg-fetch": "2.0.1",
"zone.js": "^0.7.3"
},
"dependencies": {
Expand Down
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7654,11 +7654,6 @@ url-parse-lax@^1.0.0:
dependencies:
prepend-http "^1.0.1"

[email protected]:
version "0.6.1"
resolved "https://registry.yarnpkg.com/url-search-params/-/url-search-params-0.6.1.tgz#3adb7858b807d56b81e7abf3b9dae4978c03f99d"
integrity sha1-Ott4WLgH1WuB56vzudrkl4wD+Z0=

url@~0.11.0:
version "0.11.0"
resolved "https://registry.yarnpkg.com/url/-/url-0.11.0.tgz#3838e97cfc60521eb73c525a8e55bfdd9e2e28f1"
Expand Down Expand Up @@ -7777,11 +7772,6 @@ whatwg-encoding@^1.0.1, whatwg-encoding@^1.0.3, whatwg-encoding@^1.0.5:
dependencies:
iconv-lite "0.4.24"

[email protected]:
version "2.0.1"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.1.tgz#078b9461bbe91cea73cbce8bb122a05f9e92b772"
integrity sha1-B4uUYbvpHOpzy86LsSKgX56St3I=

whatwg-fetch@>=0.10.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#fc804e458cc460009b1a2b966bc8817d2578aefb"
Expand Down