Skip to content

Commit

Permalink
followup for issues in #2000
Browse files Browse the repository at this point in the history
also update closure for mid-month release
  • Loading branch information
brendankenny committed Apr 28, 2017
1 parent fd507b3 commit eeb4ae5
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 22 deletions.
8 changes: 7 additions & 1 deletion lighthouse-core/closure/closure-type-checking.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ gulp.task('compile-report', () => {
return gulp.src([
// externs
'closure/third_party/commonjs.js',
'lib/filer-namer.js',

'lib/file-namer.js',
'report/v2/renderer/*.js',
])

// Ignore `module.exports` and `self.ClassName = ClassName` statements.
.pipe(replace(/^\s\smodule\.exports = \w+;$/gm, ';'))
.pipe(replace(/^\s\sself\.(\w+) = \1;$/gm, ';'))

// Remove node-specific code from file-namer so it can be included in report.
.pipe(replace(/^\s\smodule\.exports = {\w+};$/gm, ';'))
.pipe(replace('require(\'./url-shim\');', 'null;'))
.pipe(replace('(URLConstructor || URL)', 'URL'))

.pipe(closureCompiler({
compilation_level: 'SIMPLE',
// new_type_inf: true,
Expand Down
5 changes: 3 additions & 2 deletions lighthouse-core/closure/third_party/commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/

/**
* Read-only externs for module checks. Will fail if written to.
* @externs
*/

/** @const */
const module = {};

/** @type {*} */
module.exports;
/** @const */
module.exports = {};
11 changes: 5 additions & 6 deletions lighthouse-core/lib/file-namer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
*/
'use strict';

/* global URL */

/**
* 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 {!{url: string, generatedTime: string}} results
* @returns string
* @param {{url: string, generatedTime: string}} results
* @return {string}
*/
function getFilenamePrefix(results) {
// eslint-disable-next-line no-undef
const hostname = new (URLConstructor || URL)(results.url).hostname;
const date = (results.generatedTime && new Date(results.generatedTime)) || new Date();

Expand All @@ -44,7 +45,5 @@ let URLConstructor;
if (typeof module !== 'undefined' && module.exports) {
URLConstructor = require('./url-shim');

module.exports = {
getFilenamePrefix
};
module.exports = {getFilenamePrefix};
}
2 changes: 1 addition & 1 deletion lighthouse-core/report/v2/renderer/report-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ReportRenderer {
/**
* @param {!DOM} dom
* @param {!CategoryRenderer} categoryRenderer
* @param {ReportUIFeatures=} uiFeatures
* @param {?ReportUIFeatures=} uiFeatures
*/
constructor(dom, categoryRenderer, uiFeatures = null) {
/** @private {!DOM} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* the report.
*/

/* globals self URL Blob CustomEvent */
/* globals self URL Blob CustomEvent getFilenamePrefix */

class ReportUIFeatures {

Expand Down Expand Up @@ -64,7 +64,7 @@ class ReportUIFeatures {
* Fires a custom DOM event on target.
* @param {string} name Name of the event.
* @param {!Node=} target DOM node to fire the event on.
* @param {Object<{detail: Object<string, *>}>=} detail Custom data to include.
* @param {*=} detail Custom data to include.
*/
_fireEventOn(name, target = this._document, detail) {
const event = new CustomEvent(name, detail ? {detail} : null);
Expand Down Expand Up @@ -262,7 +262,7 @@ class ReportUIFeatures {
* @param {!Blob|!File} blob The file to save.
*/
_saveFile(blob) {
const filename = self.getFilenamePrefix({
const filename = getFilenamePrefix({
url: this.json.url,
generatedTime: this.json.generatedTime
});
Expand All @@ -286,7 +286,4 @@ if (typeof module !== 'undefined' && module.exports) {
module.exports = ReportUIFeatures;
} else {
self.ReportUIFeatures = ReportUIFeatures;

/** @type {function({url: string, generatedTime: string}): string} */
self.getFilenamePrefix; // eslint-disable-line no-unused-expressions
}
2 changes: 1 addition & 1 deletion lighthouse-core/report/v2/report-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const REPORT_JAVASCRIPT = [
fs.readFileSync(__dirname + '/renderer/details-renderer.js', 'utf8'),
fs.readFileSync(__dirname + '/../../lib/file-namer.js', 'utf8'),
fs.readFileSync(__dirname + '/renderer/logger.js', 'utf8'),
fs.readFileSync(__dirname + '/renderer/report-features.js', 'utf8'),
fs.readFileSync(__dirname + '/renderer/report-ui-features.js', 'utf8'),
fs.readFileSync(__dirname + '/renderer/category-renderer.js', 'utf8'),
fs.readFileSync(__dirname + '/renderer/report-renderer.js', 'utf8'),
].join(';\n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Util = require('../../../../report/v2/renderer/util.js');
const URL = require('../../../../lib/url-shim');
const DOM = require('../../../../report/v2/renderer/dom.js');
const DetailsRenderer = require('../../../../report/v2/renderer/details-renderer.js');
const ReportUIFeatures = require('../../../../report/v2/renderer/report-features.js');
const ReportUIFeatures = require('../../../../report/v2/renderer/report-ui-features.js');
const CategoryRenderer = require('../../../../report/v2/renderer/category-renderer.js');
const ReportRenderer = require('../../../../report/v2/renderer/report-renderer.js');
const sampleResults = require('../../../results/sample_v2.json');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"coveralls": "^2.11.9",
"eslint": "^3.12.0",
"eslint-config-google": "^0.7.1",
"google-closure-compiler": "20170409.0.0",
"google-closure-compiler": "20170423.0.0",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1",
"gulp-declare": "^0.3.0",
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1237,9 +1237,9 @@ glogg@^1.0.0:
dependencies:
sparkles "^1.0.0"

google-closure-compiler@20170409.0.0:
version "20170409.0.0"
resolved "https://registry.yarnpkg.com/google-closure-compiler/-/google-closure-compiler-20170409.0.0.tgz#dc1be29a9f7eef8611364533b271b9fac757c970"
google-closure-compiler@20170423.0.0:
version "20170423.0.0"
resolved "https://registry.yarnpkg.com/google-closure-compiler/-/google-closure-compiler-20170423.0.0.tgz#475c6a2f4512fd7fdbacb32997b2e1ab1ca6fff8"
dependencies:
chalk "^1.0.0"
vinyl "^2.0.1"
Expand Down

0 comments on commit eeb4ae5

Please sign in to comment.