diff --git a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js index 7dee469fe2a9..8279f8ee188a 100644 --- a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js +++ b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js @@ -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 @@ -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); } } diff --git a/lighthouse-extension/gulpfile.js b/lighthouse-extension/gulpfile.js index 7cb8fb040104..6a7b7f172145 100644 --- a/lighthouse-extension/gulpfile.js +++ b/lighthouse-extension/gulpfile.js @@ -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'); diff --git a/lighthouse-extension/package.json b/lighthouse-extension/package.json index 5570561d74a8..bb2d726a5943 100644 --- a/lighthouse-extension/package.json +++ b/lighthouse-extension/package.json @@ -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", @@ -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": {} } diff --git a/lighthouse-extension/yarn.lock b/lighthouse-extension/yarn.lock index a56e78be224e..87b249957342 100644 --- a/lighthouse-extension/yarn.lock +++ b/lighthouse-extension/yarn.lock @@ -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"