Skip to content

Commit

Permalink
Include version and commit in lighthouse-background.js bundle (#2236)
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet authored and brendankenny committed Aug 14, 2017
1 parent 7097d5c commit 7fe3574
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lighthouse-extension/app/src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ function getLighthouseVersion() {
return chrome.runtime.getManifest().version;
}

function getLighthouseCommitHash() {
return '__COMMITHASH__';
}

function getChromeVersion() {
return /Chrome\/([0-9.]+)/.exec(navigator.userAgent)[1];
}
Expand All @@ -55,6 +59,7 @@ function hideRunningSubpage() {
function buildReportErrorLink(err) {
const issueBody = `
**Lighthouse Version**: ${getLighthouseVersion()}
**Lighthouse Commit**: ${getLighthouseCommitHash()}
**Chrome Version**: ${getChromeVersion()}
**Initial URL**: ${siteURL}
**Error Message**: ${err.message}
Expand Down
13 changes: 13 additions & 0 deletions lighthouse-extension/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ const livereload = require('gulp-livereload');
const babel = require('babel-core');
const tap = require('gulp-tap');
const zip = require('gulp-zip');
const gulpReplace = require('gulp-replace');
const header = require('gulp-header');
const LighthouseRunner = require('../lighthouse-core/runner');
const pkg = require('../package.json');

const distDir = 'dist';

const VERSION = pkg.version;
const COMMIT_HASH = require('child_process')
.execSync('git rev-parse HEAD')
.toString().trim();

const BANNER = `// lighthouse, browserified. ${VERSION} (${COMMIT_HASH})\n`;

const audits = LighthouseRunner.getAuditList()
.map(f => '../lighthouse-core/audits/' + f.replace(/\.js$/, ''));

Expand Down Expand Up @@ -144,9 +154,11 @@ gulp.task('browserify-other', () => {
.pipe(tap(file => {
let bundle = browserify(file.path); // , {debug: true}); // for sourcemaps
bundle = applyBrowserifyTransforms(bundle);

// Inject the new browserified contents back into our gulp pipeline
file.contents = bundle.bundle();
}))
.pipe(gulpReplace('__COMMITHASH__', COMMIT_HASH))
.pipe(gulp.dest('app/scripts'))
.pipe(gulp.dest(`${distDir}/scripts`));
});
Expand All @@ -170,6 +182,7 @@ gulp.task('compilejs', () => {
file.contents = new Buffer(minified);
return file;
}))
.pipe(header(BANNER))
.pipe(gulp.dest('dist/scripts'));
});

Expand Down
1 change: 1 addition & 0 deletions lighthouse-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"gulp-chrome-manifest": "0.0.13",
"gulp-debug": "^2.1.2",
"gulp-eslint": "^3.0.1",
"gulp-header": "^1.8.9",
"gulp-livereload": "^3.8.1",
"gulp-tap": "^0.1.3",
"gulp-util": "^3.0.7",
Expand Down
25 changes: 20 additions & 5 deletions lighthouse-extension/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,12 @@ concat-stream@~1.4.5:
readable-stream "~1.1.9"
typedarray "~0.0.5"

concat-with-sourcemaps@*:
version "1.0.4"
resolved "https://registry.yarnpkg.com/concat-with-sourcemaps/-/concat-with-sourcemaps-1.0.4.tgz#f55b3be2aeb47601b10a2d5259ccfb70fd2f1dd6"
dependencies:
source-map "^0.5.1"

console-browserify@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/console-browserify/-/console-browserify-1.1.0.tgz#f0241c45730a9fc6323b206dbf38edc741d0bb10"
Expand Down Expand Up @@ -1279,6 +1285,15 @@ gulp-eslint@^3.0.1:
eslint "^3.0.0"
gulp-util "^3.0.6"

gulp-header@^1.8.9:
version "1.8.9"
resolved "https://registry.yarnpkg.com/gulp-header/-/gulp-header-1.8.9.tgz#c9f10fee0632d81e939789c6ecf45a151bf3098b"
dependencies:
concat-with-sourcemaps "*"
gulp-util "*"
object-assign "*"
through2 "^2.0.0"

gulp-livereload@^3.8.1:
version "3.8.1"
resolved "https://registry.yarnpkg.com/gulp-livereload/-/gulp-livereload-3.8.1.tgz#00f744b2d749d3e9e3746589c8a44acac779b50f"
Expand Down Expand Up @@ -2093,14 +2108,14 @@ number-is-nan@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"

object-assign@*, object-assign@^4.0.1, object-assign@^4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"

object-assign@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-3.0.0.tgz#9bedd5ca0897949bca47e7ff408062d549f587f2"

object-assign@^4.0.1, object-assign@^4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"

object-inspect@~0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-0.4.0.tgz#f5157c116c1455b243b06ee97703392c5ad89fec"
Expand Down Expand Up @@ -2630,7 +2645,7 @@ sort-json@^1.2.0:
dependencies:
detect-indent "^4.0.0"

"source-map@>= 0.1.2", source-map@~0.5.3:
"source-map@>= 0.1.2", source-map@^0.5.1, source-map@~0.5.3:
version "0.5.6"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"

Expand Down

0 comments on commit 7fe3574

Please sign in to comment.