From fc147c1bd9f18a7b8973c71827f30a87456c7c5e Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Thu, 11 Apr 2019 14:55:21 -0700 Subject: [PATCH 01/13] Made /lightrider client folder. Added lightrider-ui-features and generates a report-generator for lightrider. --- build/build-lr-files.js | 25 +++++++++++ clients/{ => lightrider}/lightrider-entry.js | 14 +++---- clients/lightrider/lightrider-ui-features.js | 44 ++++++++++++++++++++ lighthouse-core/report/report-generator.js | 4 +- package.json | 2 +- 5 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 build/build-lr-files.js rename clients/{ => lightrider}/lightrider-entry.js (86%) create mode 100644 clients/lightrider/lightrider-ui-features.js diff --git a/build/build-lr-files.js b/build/build-lr-files.js new file mode 100644 index 000000000000..e3fee000c7c6 --- /dev/null +++ b/build/build-lr-files.js @@ -0,0 +1,25 @@ +/** + * @license Copyright 2019 Google Inc. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ +'use strict'; + +const browserify = require('browserify'); +const fs = require('fs'); +const path = require('path'); +const makeDir = require('make-dir'); + +const distDir = path.join(__dirname, '..', 'dist', 'lightrider'); +const bundleOutFile = `${distDir}/report-generator.js`; +const generatorFilename = `./lighthouse-core/report/report-generator.js`; + +makeDir.sync(path.dirname(distDir)); + +browserify(generatorFilename, {standalone: 'ReportGenerator'}) + // Transform the fs.readFile etc into inline strings. + .transform('brfs', {global: true, parserOpts: {ecmaVersion: 10}}) + .bundle((err, src) => { + if (err) throw err; + fs.writeFileSync(bundleOutFile, src.toString()); + }); diff --git a/clients/lightrider-entry.js b/clients/lightrider/lightrider-entry.js similarity index 86% rename from clients/lightrider-entry.js rename to clients/lightrider/lightrider-entry.js index 01223693c5b7..d6b86d10710a 100644 --- a/clients/lightrider-entry.js +++ b/clients/lightrider/lightrider-entry.js @@ -5,19 +5,19 @@ */ 'use strict'; -const lighthouse = require('../lighthouse-core/index.js'); +const lighthouse = require('../../lighthouse-core/index.js'); -const assetSaver = require('../lighthouse-core/lib/asset-saver.js'); -const LHError = require('../lighthouse-core/lib/lh-error.js'); -const preprocessor = require('../lighthouse-core/lib/proto-preprocessor.js'); +const assetSaver = require('../../lighthouse-core/lib/asset-saver.js'); +const LHError = require('../../lighthouse-core/lib/lh-error.js'); +const preprocessor = require('../../lighthouse-core/lib/proto-preprocessor.js'); /** @type {Record<'mobile'|'desktop', LH.Config.Json>} */ const LR_PRESETS = { - mobile: require('../lighthouse-core/config/lr-mobile-config.js'), - desktop: require('../lighthouse-core/config/lr-desktop-config.js'), + mobile: require('../../lighthouse-core/config/lr-mobile-config.js'), + desktop: require('../../lighthouse-core/config/lr-desktop-config.js'), }; -/** @typedef {import('../lighthouse-core/gather/connections/connection.js')} Connection */ +/** @typedef {import('../../lighthouse-core/gather/connections/connection.js')} Connection */ /** * Run lighthouse for connection and provide similar results as in CLI. diff --git a/clients/lightrider/lightrider-ui-features.js b/clients/lightrider/lightrider-ui-features.js new file mode 100644 index 000000000000..44cb1eeff355 --- /dev/null +++ b/clients/lightrider/lightrider-ui-features.js @@ -0,0 +1,44 @@ +/** + * Copyright 2019 Google Inc. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ +'use strict'; + +/* global ReportUIFeatures, ReportGenerator */ + +/** + * Extends ReportUIFeatures to add an (optional) ability to save to a gist and + * generates the saved report from a browserified ReportGenerator. + */ +class LightriderUIFeatures extends ReportUIFeatures { + + /** + * @param {DOM} dom + */ + constructor(dom) { + super(dom); + } + + /** + * @param {LH.Result} report + * @override + */ + initFeatures(report) { + super.initFeatures(report); + } + + /** + * Uses ReportGenerator to create the html that recreates this report. + * @return {string} + * @override + */ + getReportHtml() { + return window.ReportGenerator.generateReportHtml(this.json); + } +} + +// node export for testing. +if (typeof module !== 'undefined' && module.exports) { + module.exports = LightriderUIFeatures; +} diff --git a/lighthouse-core/report/report-generator.js b/lighthouse-core/report/report-generator.js index 09d653a30106..3e60f66856d3 100644 --- a/lighthouse-core/report/report-generator.js +++ b/lighthouse-core/report/report-generator.js @@ -57,14 +57,14 @@ class ReportGenerator { * - the score value of the audit * * @param {LH.Result} lhr - * @returns {string} + * @return {string} */ static generateReportCSV(lhr) { // To keep things "official" we follow the CSV specification (RFC4180) // The document describes how to deal with escaping commas and quotes etc. const CRLF = '\r\n'; const separator = ','; - /** @param {string} value @returns {string} */ + /** @param {string} value @return {string} */ const escape = value => `"${value.replace(/"/g, '""')}"`; // Possible TODO: tightly couple headers and row values diff --git a/package.json b/package.json index 0a8f1fc8fa3a..fe6008dd2657 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "build-all:task:windows": "yarn build-extension && yarn build-devtools && yarn build-lr && yarn build-viewer", "build-extension": "node ./build/build-extension.js", "build-devtools": "node ./build/build-bundle.js clients/devtools-entry.js dist/lighthouse-dt-bundle.js && node ./build/build-dt-report-resources.js", - "build-lr": "node ./build/build-bundle.js clients/lightrider-entry.js dist/lighthouse-lr-bundle.js", + "build-lr": "node ./build/build-bundle.js clients/lightrider/lightrider-entry.js dist/lightrider/lighthouse-lr-bundle.js && node ./build/build-lr-files.js", "build-viewer": "node ./build/build-viewer.js", "clean": "rimraf dist proto/scripts/*.json proto/scripts/*_pb2.* proto/scripts/*_pb.* proto/scripts/__pycache__ proto/scripts/*.pyc *.report.html *.report.dom.html *.report.json *.devtoolslog.json *.trace.json || true", "lint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .", From d7064dafd04e16f34e8319dff8ed764a1e8f330a Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Thu, 11 Apr 2019 15:05:11 -0700 Subject: [PATCH 02/13] Removed blank overrides. --- clients/lightrider/lightrider-ui-features.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/clients/lightrider/lightrider-ui-features.js b/clients/lightrider/lightrider-ui-features.js index 44cb1eeff355..24609c6e2c6f 100644 --- a/clients/lightrider/lightrider-ui-features.js +++ b/clients/lightrider/lightrider-ui-features.js @@ -12,22 +12,6 @@ * generates the saved report from a browserified ReportGenerator. */ class LightriderUIFeatures extends ReportUIFeatures { - - /** - * @param {DOM} dom - */ - constructor(dom) { - super(dom); - } - - /** - * @param {LH.Result} report - * @override - */ - initFeatures(report) { - super.initFeatures(report); - } - /** * Uses ReportGenerator to create the html that recreates this report. * @return {string} From c09d10909b70d85f900c313acf4c74fcae03ef10 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Thu, 11 Apr 2019 15:31:05 -0700 Subject: [PATCH 03/13] Added lr file namer. --- clients/lightrider/lightrider-file-namer.js | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 clients/lightrider/lightrider-file-namer.js diff --git a/clients/lightrider/lightrider-file-namer.js b/clients/lightrider/lightrider-file-namer.js new file mode 100644 index 000000000000..e27ccf4618e6 --- /dev/null +++ b/clients/lightrider/lightrider-file-namer.js @@ -0,0 +1,50 @@ +/** + * @license Copyright 2019 Google Inc. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ +'use strict'; + +/* global URL */ + +/** + * @fileoverview + * @suppress {reportUnknownTypes} + */ + +/** + * Generate a filenamePrefix of hostname_YYYY-MM-DD_HH-MM-SS + * Date/time uses the local timezone, however Node has unreliable ICU + * support, so we must construct a YYYY-MM-DD date format manually. :/ + * @param {{finalUrl: string, fetchTime: string}} lhr + * @return {string} + */ +function getFilenamePrefix(lhr) { + const hostname = new (getUrlConstructor())(lhr.finalUrl).hostname; + const date = (lhr.fetchTime && new Date(lhr.fetchTime)) || new Date(); + + const timeStr = date.toLocaleTimeString('en-US', {hour12: false}); + const dateParts = date.toLocaleDateString('en-US', { + year: 'numeric', month: '2-digit', day: '2-digit', + }).split('/'); + // @ts-ignore - parts exists + dateParts.unshift(dateParts.pop()); + const dateStr = dateParts.join('-'); + + const filenamePrefix = `${hostname}_${dateStr}_${timeStr}`; + // replace characters that are unfriendly to filenames + return filenamePrefix.replace(/[/?<>\\:*|":]/g, '-'); +} + +/** + * Get a new URL object. + * @return {URL!} + */ +function getUrlConstructor() { + return URL; +} + +// don't attempt to export in the browser. +if (typeof module !== 'undefined' && module.exports) { + module.exports = {getFilenamePrefix}; +} From 02b3b3a9dba1918059cc707ac6019054b6b19f79 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Thu, 11 Apr 2019 17:45:17 -0700 Subject: [PATCH 04/13] Brendan's foodback. --- build/build-lightrider.js | 70 ++++++++++++++++++++ build/build-lr-files.js | 25 ------- clients/lightrider/lightrider-file-namer.js | 50 -------------- clients/lightrider/lightrider-ui-features.js | 7 +- lighthouse-core/lib/file-namer.js | 10 +-- package.json | 2 +- 6 files changed, 74 insertions(+), 90 deletions(-) create mode 100644 build/build-lightrider.js delete mode 100644 build/build-lr-files.js delete mode 100644 clients/lightrider/lightrider-file-namer.js diff --git a/build/build-lightrider.js b/build/build-lightrider.js new file mode 100644 index 000000000000..c8fc93d5d21a --- /dev/null +++ b/build/build-lightrider.js @@ -0,0 +1,70 @@ +/** + * @license Copyright 2019 Google Inc. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ +'use strict'; + +const browserify = require('browserify'); +const cpy = require('cpy'); +const fs = require('fs'); +const path = require('path'); +const makeDir = require('make-dir'); +const bundleBuilder = require('./build-bundle.js'); + +const LHROOT = path.join(__dirname, '..'); +const distDir = path.join(__dirname, '..', 'dist', 'lightrider'); +const sourceDir = __dirname + '/../clients/lightrider'; + +const bundleOutFile = `${distDir}/report-generator.js`; +const generatorFilename = `./lighthouse-core/report/report-generator.js`; + +const entrySourceName = 'lightrider-entry.js'; +const entryDistName = 'lighthouse-lr-bundle.js'; + +makeDir.sync(path.dirname(distDir)); + +/** + * @return {Promise} + */ +async function copyAssets() { + return cpy([ + 'clients/lightrider/lightrider-ui-features.js', + 'lighthouse-core/lib/file-namer.js', + ], distDir, { + cwd: LHROOT, + parents: false, + }); +} + +/** + * Browserify and minify entry point. + */ +function buildEntryPoint() { + const inFile = `${sourceDir}/${entrySourceName}`; + const outFile = `${distDir}/${entryDistName}`; + return bundleBuilder.build(inFile, outFile); +} + +/** + * Browserify and minify the LR report generator. + */ +function buildReportGenerator() { + browserify(generatorFilename, {standalone: 'ReportGenerator'}) + // Transform the fs.readFile etc into inline strings. + .transform('brfs', {global: true, parserOpts: {ecmaVersion: 10}}) + .bundle((err, src) => { + if (err) throw err; + fs.writeFileSync(bundleOutFile, src.toString()); + }); +} + +async function run() { + await Promise.all([ + buildEntryPoint(), + copyAssets(), + buildReportGenerator(), + ]); +} + +run(); diff --git a/build/build-lr-files.js b/build/build-lr-files.js deleted file mode 100644 index e3fee000c7c6..000000000000 --- a/build/build-lr-files.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @license Copyright 2019 Google Inc. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - */ -'use strict'; - -const browserify = require('browserify'); -const fs = require('fs'); -const path = require('path'); -const makeDir = require('make-dir'); - -const distDir = path.join(__dirname, '..', 'dist', 'lightrider'); -const bundleOutFile = `${distDir}/report-generator.js`; -const generatorFilename = `./lighthouse-core/report/report-generator.js`; - -makeDir.sync(path.dirname(distDir)); - -browserify(generatorFilename, {standalone: 'ReportGenerator'}) - // Transform the fs.readFile etc into inline strings. - .transform('brfs', {global: true, parserOpts: {ecmaVersion: 10}}) - .bundle((err, src) => { - if (err) throw err; - fs.writeFileSync(bundleOutFile, src.toString()); - }); diff --git a/clients/lightrider/lightrider-file-namer.js b/clients/lightrider/lightrider-file-namer.js deleted file mode 100644 index e27ccf4618e6..000000000000 --- a/clients/lightrider/lightrider-file-namer.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @license Copyright 2019 Google Inc. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - */ -'use strict'; - -/* global URL */ - -/** - * @fileoverview - * @suppress {reportUnknownTypes} - */ - -/** - * Generate a filenamePrefix of hostname_YYYY-MM-DD_HH-MM-SS - * Date/time uses the local timezone, however Node has unreliable ICU - * support, so we must construct a YYYY-MM-DD date format manually. :/ - * @param {{finalUrl: string, fetchTime: string}} lhr - * @return {string} - */ -function getFilenamePrefix(lhr) { - const hostname = new (getUrlConstructor())(lhr.finalUrl).hostname; - const date = (lhr.fetchTime && new Date(lhr.fetchTime)) || new Date(); - - const timeStr = date.toLocaleTimeString('en-US', {hour12: false}); - const dateParts = date.toLocaleDateString('en-US', { - year: 'numeric', month: '2-digit', day: '2-digit', - }).split('/'); - // @ts-ignore - parts exists - dateParts.unshift(dateParts.pop()); - const dateStr = dateParts.join('-'); - - const filenamePrefix = `${hostname}_${dateStr}_${timeStr}`; - // replace characters that are unfriendly to filenames - return filenamePrefix.replace(/[/?<>\\:*|":]/g, '-'); -} - -/** - * Get a new URL object. - * @return {URL!} - */ -function getUrlConstructor() { - return URL; -} - -// don't attempt to export in the browser. -if (typeof module !== 'undefined' && module.exports) { - module.exports = {getFilenamePrefix}; -} diff --git a/clients/lightrider/lightrider-ui-features.js b/clients/lightrider/lightrider-ui-features.js index 24609c6e2c6f..122b4b693588 100644 --- a/clients/lightrider/lightrider-ui-features.js +++ b/clients/lightrider/lightrider-ui-features.js @@ -5,7 +5,7 @@ */ 'use strict'; -/* global ReportUIFeatures, ReportGenerator */ +/* global ReportUIFeatures */ /** * Extends ReportUIFeatures to add an (optional) ability to save to a gist and @@ -22,7 +22,4 @@ class LightriderUIFeatures extends ReportUIFeatures { } } -// node export for testing. -if (typeof module !== 'undefined' && module.exports) { - module.exports = LightriderUIFeatures; -} +module.exports = LightriderUIFeatures; diff --git a/lighthouse-core/lib/file-namer.js b/lighthouse-core/lib/file-namer.js index 6ed093a10bb9..e742b857b2d6 100644 --- a/lighthouse-core/lib/file-namer.js +++ b/lighthouse-core/lib/file-namer.js @@ -20,7 +20,7 @@ * @return {string} */ function getFilenamePrefix(lhr) { - const hostname = new (getUrlConstructor())(lhr.finalUrl).hostname; + const hostname = new URL(lhr.finalUrl).hostname; const date = (lhr.fetchTime && new Date(lhr.fetchTime)) || new Date(); const timeStr = date.toLocaleTimeString('en-US', {hour12: false}); @@ -36,14 +36,6 @@ function getFilenamePrefix(lhr) { return filenamePrefix.replace(/[/?<>\\:*|":]/g, '-'); } -function getUrlConstructor() { - if (typeof module !== 'undefined' && module.exports) { - return require('./url-shim'); - } else { - return URL; - } -} - // don't attempt to export in the browser. if (typeof module !== 'undefined' && module.exports) { module.exports = {getFilenamePrefix}; diff --git a/package.json b/package.json index fe6008dd2657..29c2f5bf3445 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "build-all:task:windows": "yarn build-extension && yarn build-devtools && yarn build-lr && yarn build-viewer", "build-extension": "node ./build/build-extension.js", "build-devtools": "node ./build/build-bundle.js clients/devtools-entry.js dist/lighthouse-dt-bundle.js && node ./build/build-dt-report-resources.js", - "build-lr": "node ./build/build-bundle.js clients/lightrider/lightrider-entry.js dist/lightrider/lighthouse-lr-bundle.js && node ./build/build-lr-files.js", + "build-lr": "node ./build/build-lightrider.js", "build-viewer": "node ./build/build-viewer.js", "clean": "rimraf dist proto/scripts/*.json proto/scripts/*_pb2.* proto/scripts/*_pb.* proto/scripts/__pycache__ proto/scripts/*.pyc *.report.html *.report.dom.html *.report.json *.devtoolslog.json *.trace.json || true", "lint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .", From 9bf50ba0ceb3aced86614d1646006c16fa3b20c8 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Thu, 11 Apr 2019 17:48:05 -0700 Subject: [PATCH 05/13] I read all the feedback b4 submitting, sure. --- clients/lightrider/lightrider-ui-features.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clients/lightrider/lightrider-ui-features.js b/clients/lightrider/lightrider-ui-features.js index 122b4b693588..3ffa6eccc71c 100644 --- a/clients/lightrider/lightrider-ui-features.js +++ b/clients/lightrider/lightrider-ui-features.js @@ -8,8 +8,7 @@ /* global ReportUIFeatures */ /** - * Extends ReportUIFeatures to add an (optional) ability to save to a gist and - * generates the saved report from a browserified ReportGenerator. + * Extends ReportUIFeatures to use the saved report from a browserified ReportGenerator. */ class LightriderUIFeatures extends ReportUIFeatures { /** From b2b95f9ea01dc497a0420de8f20e404b6c01657f Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Thu, 11 Apr 2019 17:57:23 -0700 Subject: [PATCH 06/13] ts-ignore window.ReportGen --- clients/lightrider/lightrider-ui-features.js | 1 + 1 file changed, 1 insertion(+) diff --git a/clients/lightrider/lightrider-ui-features.js b/clients/lightrider/lightrider-ui-features.js index 3ffa6eccc71c..2ce3ba03e7e1 100644 --- a/clients/lightrider/lightrider-ui-features.js +++ b/clients/lightrider/lightrider-ui-features.js @@ -17,6 +17,7 @@ class LightriderUIFeatures extends ReportUIFeatures { * @override */ getReportHtml() { + // @ts-ignore This is only called in browser in Lightrider where this exists. return window.ReportGenerator.generateReportHtml(this.json); } } From 066d3236141953eeb146c3da61c17dd4cc3921ad Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Thu, 11 Apr 2019 18:17:28 -0700 Subject: [PATCH 07/13] fix test to point to new entry location. --- clients/test/lightrider-entry-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/test/lightrider-entry-test.js b/clients/test/lightrider-entry-test.js index 35fb0f0b3fc5..7042d47fde2a 100644 --- a/clients/test/lightrider-entry-test.js +++ b/clients/test/lightrider-entry-test.js @@ -6,7 +6,7 @@ 'use strict'; const assert = require('assert'); -const lhBackground = require('../lightrider-entry.js'); +const lhBackground = require('../lightrider/lightrider-entry.js'); const Runner = require('../../lighthouse-core/runner.js'); const LHError = require('../../lighthouse-core/lib/lh-error.js'); From fffc38b960f75be05b84bbc5cdc9fa39cd10043d Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Fri, 12 Apr 2019 10:19:30 -0700 Subject: [PATCH 08/13] Removed comment about node testing. --- clients/lightrider/lightrider-ui-features.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clients/lightrider/lightrider-ui-features.js b/clients/lightrider/lightrider-ui-features.js index 2ce3ba03e7e1..5d120d18551c 100644 --- a/clients/lightrider/lightrider-ui-features.js +++ b/clients/lightrider/lightrider-ui-features.js @@ -22,4 +22,6 @@ class LightriderUIFeatures extends ReportUIFeatures { } } -module.exports = LightriderUIFeatures; +if (typeof module !== 'undefined' && module.exports) { + module.exports = LightriderUIFeatures; +} From e12115d5f71e5548c66c46937396ee77c5e83044 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Fri, 12 Apr 2019 10:27:26 -0700 Subject: [PATCH 09/13] Add @license and new comment. --- clients/lightrider/lightrider-ui-features.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clients/lightrider/lightrider-ui-features.js b/clients/lightrider/lightrider-ui-features.js index 5d120d18551c..d381b7ac7701 100644 --- a/clients/lightrider/lightrider-ui-features.js +++ b/clients/lightrider/lightrider-ui-features.js @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google Inc. All Rights Reserved. + * @license Copyright 2019 Google Inc. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ @@ -8,7 +8,7 @@ /* global ReportUIFeatures */ /** - * Extends ReportUIFeatures to use the saved report from a browserified ReportGenerator. + * Extends ReportUIFeatures to get html from a browserified ReportGenerator. */ class LightriderUIFeatures extends ReportUIFeatures { /** From 319dd9415d22a953f57500d05188df0114c01e21 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Fri, 12 Apr 2019 13:49:07 -0700 Subject: [PATCH 10/13] Better comments. --- clients/lightrider/lightrider-ui-features.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clients/lightrider/lightrider-ui-features.js b/clients/lightrider/lightrider-ui-features.js index d381b7ac7701..6ffb407f399f 100644 --- a/clients/lightrider/lightrider-ui-features.js +++ b/clients/lightrider/lightrider-ui-features.js @@ -8,7 +8,7 @@ /* global ReportUIFeatures */ /** - * Extends ReportUIFeatures to get html from a browserified ReportGenerator. + * Extends ReportUIFeatures for a Lightrider viewer to get html from a browserified ReportGenerator. */ class LightriderUIFeatures extends ReportUIFeatures { /** @@ -17,7 +17,7 @@ class LightriderUIFeatures extends ReportUIFeatures { * @override */ getReportHtml() { - // @ts-ignore This is only called in browser in Lightrider where this exists. + // @ts-ignore ReportGenerator is put on window by the host page. return window.ReportGenerator.generateReportHtml(this.json); } } From 9c17270e21770ee884eab8f4ff9ef0371205253b Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Mon, 15 Apr 2019 15:31:06 -0700 Subject: [PATCH 11/13] Removed unecessary files from report generator. --- build/build-lightrider.js | 14 ---------- clients/lightrider/lightrider-ui-features.js | 27 -------------------- 2 files changed, 41 deletions(-) delete mode 100644 clients/lightrider/lightrider-ui-features.js diff --git a/build/build-lightrider.js b/build/build-lightrider.js index c8fc93d5d21a..3a34e9633175 100644 --- a/build/build-lightrider.js +++ b/build/build-lightrider.js @@ -24,19 +24,6 @@ const entryDistName = 'lighthouse-lr-bundle.js'; makeDir.sync(path.dirname(distDir)); -/** - * @return {Promise} - */ -async function copyAssets() { - return cpy([ - 'clients/lightrider/lightrider-ui-features.js', - 'lighthouse-core/lib/file-namer.js', - ], distDir, { - cwd: LHROOT, - parents: false, - }); -} - /** * Browserify and minify entry point. */ @@ -62,7 +49,6 @@ function buildReportGenerator() { async function run() { await Promise.all([ buildEntryPoint(), - copyAssets(), buildReportGenerator(), ]); } diff --git a/clients/lightrider/lightrider-ui-features.js b/clients/lightrider/lightrider-ui-features.js deleted file mode 100644 index 6ffb407f399f..000000000000 --- a/clients/lightrider/lightrider-ui-features.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * @license Copyright 2019 Google Inc. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - */ -'use strict'; - -/* global ReportUIFeatures */ - -/** - * Extends ReportUIFeatures for a Lightrider viewer to get html from a browserified ReportGenerator. - */ -class LightriderUIFeatures extends ReportUIFeatures { - /** - * Uses ReportGenerator to create the html that recreates this report. - * @return {string} - * @override - */ - getReportHtml() { - // @ts-ignore ReportGenerator is put on window by the host page. - return window.ReportGenerator.generateReportHtml(this.json); - } -} - -if (typeof module !== 'undefined' && module.exports) { - module.exports = LightriderUIFeatures; -} From 27b07e912dab4275cfe3828f1939c5f730676591 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Mon, 15 Apr 2019 16:06:00 -0700 Subject: [PATCH 12/13] removed unused lines. --- build/build-lightrider.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/build/build-lightrider.js b/build/build-lightrider.js index 3a34e9633175..8429404b24a8 100644 --- a/build/build-lightrider.js +++ b/build/build-lightrider.js @@ -6,13 +6,11 @@ 'use strict'; const browserify = require('browserify'); -const cpy = require('cpy'); const fs = require('fs'); const path = require('path'); const makeDir = require('make-dir'); const bundleBuilder = require('./build-bundle.js'); -const LHROOT = path.join(__dirname, '..'); const distDir = path.join(__dirname, '..', 'dist', 'lightrider'); const sourceDir = __dirname + '/../clients/lightrider'; From 390f54316ed45e421531fcbb0ba82749b93041f4 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Tue, 16 Apr 2019 14:17:40 -0700 Subject: [PATCH 13/13] Renames --- build/{build-lightrider.js => build-lightrider-bundles.js} | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename build/{build-lightrider.js => build-lightrider-bundles.js} (96%) diff --git a/build/build-lightrider.js b/build/build-lightrider-bundles.js similarity index 96% rename from build/build-lightrider.js rename to build/build-lightrider-bundles.js index 8429404b24a8..5a040d5338a5 100644 --- a/build/build-lightrider.js +++ b/build/build-lightrider-bundles.js @@ -14,7 +14,7 @@ const bundleBuilder = require('./build-bundle.js'); const distDir = path.join(__dirname, '..', 'dist', 'lightrider'); const sourceDir = __dirname + '/../clients/lightrider'; -const bundleOutFile = `${distDir}/report-generator.js`; +const bundleOutFile = `${distDir}/report-generator-bundle.js`; const generatorFilename = `./lighthouse-core/report/report-generator.js`; const entrySourceName = 'lightrider-entry.js'; diff --git a/package.json b/package.json index b3b7ad511402..a5dfa775709f 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "build-all:task:windows": "yarn build-extension && yarn build-devtools && yarn build-lr && yarn build-viewer", "build-extension": "node ./build/build-extension.js", "build-devtools": "node ./build/build-bundle.js clients/devtools-entry.js dist/lighthouse-dt-bundle.js && node ./build/build-dt-report-resources.js", - "build-lr": "node ./build/build-lightrider.js", + "build-lr": "node ./build/build-lightrider-bundles.js", "build-viewer": "node ./build/build-viewer.js", "clean": "rimraf dist proto/scripts/*.json proto/scripts/*_pb2.* proto/scripts/*_pb.* proto/scripts/__pycache__ proto/scripts/*.pyc *.report.html *.report.dom.html *.report.json *.devtoolslog.json *.trace.json || true", "lint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .",