Skip to content

Commit

Permalink
extension: allow use of ES2018 features (#5377)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Jun 8, 2018
1 parent 13a133d commit e02d517
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ class OptimizedImages extends Gatherer {
}

/** @type {LH.Artifacts.OptimizedImage} */
// @ts-ignore TODO(bckenny): fix browserify/Object.spread. See https://github.com/GoogleChrome/lighthouse/issues/5152
const image = Object.assign({failed: false}, stats, record);
const image = {failed: false, ...stats, ...record};
results.push(image);
} catch (err) {
// Track this with Sentry since these errors aren't surfaced anywhere else, but we don't
Expand All @@ -199,8 +198,7 @@ class OptimizedImages extends Gatherer {
});

/** @type {LH.Artifacts.OptimizedImageError} */
// @ts-ignore TODO(bckenny): see above browserify/Object.spread TODO.
const imageError = Object.assign({failed: true, errMsg: err.message}, record);
const imageError = {failed: true, errMsg: err.message, ...record};
results.push(imageError);
}
}
Expand Down
14 changes: 14 additions & 0 deletions lighthouse-extension/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
// generated on 2016-03-19 using generator-chrome-extension 0.5.4

'use strict';

const fs = require('fs');
// HACK: patch astw before it's required to use acorn with ES2018
// We add the right acorn version to package.json deps, resolve the path to it here,
// and then inject the modified require statement into astw's code.
// see https://github.com/GoogleChrome/lighthouse/issues/5152
const acornPath = require.resolve('acorn');
const astwPath = require.resolve('astw/index.js');
const astwOriginalContent = fs.readFileSync(astwPath, 'utf8');
const astwPatchedContent = astwOriginalContent
.replace('ecmaVersion: opts.ecmaVersion || 8', 'ecmaVersion: 2018')
.replace(`require('acorn')`, `require(${JSON.stringify(acornPath)})`);
fs.writeFileSync(astwPath, astwPatchedContent);

const del = require('del');
const gutil = require('gulp-util');
const runSequence = require('run-sequence');
Expand Down
5 changes: 4 additions & 1 deletion lighthouse-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"scripts": {
"watch": "gulp watch",
"build": "gulp build:production",
"debug-build": "node --inspect-brk ./node_modules/.bin/gulp build:production",
"test": "mocha test/**/*-test.js"
},
"devDependencies": {
"acorn": "^5.5.3",
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
"brfs": "^1.6.1",
"browserify": "^16.2.0",
Expand All @@ -28,7 +30,8 @@
"through2": "^2.0.1"
},
"resolutions": {
"browserify/insert-module-globals/lexical-scope/astw": "2.2.0"
"browserify/insert-module-globals/lexical-scope/astw": "2.2.0",
"**/astw/acorn": "5.5.3"
},
"dependencies": {}
}
12 changes: 4 additions & 8 deletions lighthouse-extension/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@ acorn-node@^1.2.0, acorn-node@^1.3.0:
acorn "^5.4.1"
xtend "^4.0.1"

acorn@5.5.3, acorn@^4.0.3, acorn@^5.0.0, acorn@^5.4.1, acorn@^5.5.3:
version "5.5.3"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.5.3.tgz#f473dd47e0277a08e28e9bec5aeeb04751f0b8c9"

acorn@^3.0.4:
version "3.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"

acorn@^4.0.3:
version "4.0.13"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787"

acorn@^5.0.0, acorn@^5.4.1:
version "5.5.3"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.5.3.tgz#f473dd47e0277a08e28e9bec5aeeb04751f0b8c9"

acorn@^5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.1.2.tgz#911cb53e036807cf0fa778dc5d370fbd864246d7"
Expand Down

0 comments on commit e02d517

Please sign in to comment.