From fff8ae1516a08559f071abbb27f2fbe786279a69 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Tue, 29 May 2018 13:55:17 -0700 Subject: [PATCH 1/7] extension: allow use of ES2018 features --- .../gather/gatherers/dobetterweb/optimized-images.js | 3 +-- lighthouse-extension/gulpfile.js | 7 +++++++ lighthouse-extension/package.json | 4 +++- lighthouse-extension/yarn.lock | 12 ++++-------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js index 7dee469fe2a9..90e131570a7e 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 diff --git a/lighthouse-extension/gulpfile.js b/lighthouse-extension/gulpfile.js index 8a7e0d5f2ef5..ace721e2526c 100644 --- a/lighthouse-extension/gulpfile.js +++ b/lighthouse-extension/gulpfile.js @@ -1,6 +1,7 @@ // generated on 2016-03-19 using generator-chrome-extension 0.5.4 'use strict'; +const fs = require('fs'); const del = require('del'); const gutil = require('gulp-util'); const runSequence = require('run-sequence'); @@ -20,6 +21,12 @@ const pkg = require('../package.json'); const distDir = 'dist'; +// HACK: patch astw, see https://github.com/GoogleChrome/lighthouse/issues/5152 +const ASTW_PATH = require.resolve('astw/index.js'); +const astwOriginalContent = fs.readFileSync(ASTW_PATH, 'utf8'); +const astwPatchedContent = astwOriginalContent.replace(/ecmaVersion: .* 8,/, 'ecmaVersion: 2018,'); +fs.writeFileSync(ASTW_PATH, astwPatchedContent); + const VERSION = pkg.version; const COMMIT_HASH = require('child_process') .execSync('git rev-parse HEAD') diff --git a/lighthouse-extension/package.json b/lighthouse-extension/package.json index 30d8d21c2194..d8ccacd30db8 100644 --- a/lighthouse-extension/package.json +++ b/lighthouse-extension/package.json @@ -7,6 +7,7 @@ "scripts": { "watch": "gulp watch", "build": "gulp build:production", + "debug-build": "node --inspect-brk ./node_modules/.bin/gulp build:production", "test": "mocha test/extension-test.js" }, "devDependencies": { @@ -28,7 +29,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..9f5fb8cd3fa5 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: + 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" From b338c9b8323ae0fa4a21afa21b88896ab1a0b49c Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Tue, 29 May 2018 14:45:22 -0700 Subject: [PATCH 2/7] force acorn --- lighthouse-extension/gulpfile.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lighthouse-extension/gulpfile.js b/lighthouse-extension/gulpfile.js index ace721e2526c..30207e3be6cb 100644 --- a/lighthouse-extension/gulpfile.js +++ b/lighthouse-extension/gulpfile.js @@ -2,6 +2,15 @@ 'use strict'; const fs = require('fs'); +// HACK: patch astw, 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: .* 8,/, 'ecmaVersion: 2018,') + .replace(/require\('acorn'\)/, `require("${acornPath}")`); +fs.writeFileSync(astwPath, astwPatchedContent); + const del = require('del'); const gutil = require('gulp-util'); const runSequence = require('run-sequence'); @@ -21,12 +30,6 @@ const pkg = require('../package.json'); const distDir = 'dist'; -// HACK: patch astw, see https://github.com/GoogleChrome/lighthouse/issues/5152 -const ASTW_PATH = require.resolve('astw/index.js'); -const astwOriginalContent = fs.readFileSync(ASTW_PATH, 'utf8'); -const astwPatchedContent = astwOriginalContent.replace(/ecmaVersion: .* 8,/, 'ecmaVersion: 2018,'); -fs.writeFileSync(ASTW_PATH, astwPatchedContent); - const VERSION = pkg.version; const COMMIT_HASH = require('child_process') .execSync('git rev-parse HEAD') From a951d5d7f44a27418f5b4424c8a2786be6d1391c Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Tue, 29 May 2018 14:56:20 -0700 Subject: [PATCH 3/7] windows compat --- lighthouse-extension/gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lighthouse-extension/gulpfile.js b/lighthouse-extension/gulpfile.js index 30207e3be6cb..2a833bcc37fd 100644 --- a/lighthouse-extension/gulpfile.js +++ b/lighthouse-extension/gulpfile.js @@ -8,7 +8,7 @@ const astwPath = require.resolve('astw/index.js'); const astwOriginalContent = fs.readFileSync(astwPath, 'utf8'); const astwPatchedContent = astwOriginalContent .replace(/ecmaVersion: .* 8,/, 'ecmaVersion: 2018,') - .replace(/require\('acorn'\)/, `require("${acornPath}")`); + .replace(/require\('acorn'\)/, `require(${JSON.stringify(acornPath)})`); fs.writeFileSync(astwPath, astwPatchedContent); const del = require('del'); From f043414c3e46380300e5397c66ea9aa637475e37 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Tue, 29 May 2018 14:59:26 -0700 Subject: [PATCH 4/7] update comments and such --- lighthouse-extension/gulpfile.js | 4 +++- lighthouse-extension/package.json | 1 + lighthouse-extension/yarn.lock | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lighthouse-extension/gulpfile.js b/lighthouse-extension/gulpfile.js index 2a833bcc37fd..c45b76665c0c 100644 --- a/lighthouse-extension/gulpfile.js +++ b/lighthouse-extension/gulpfile.js @@ -1,8 +1,10 @@ // generated on 2016-03-19 using generator-chrome-extension 0.5.4 'use strict'; + const fs = require('fs'); -// HACK: patch astw, see https://github.com/GoogleChrome/lighthouse/issues/5152 +// HACK: patch astw before it's required to use acorn with ES2018 +// 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'); diff --git a/lighthouse-extension/package.json b/lighthouse-extension/package.json index d8ccacd30db8..b9207e0ddf9c 100644 --- a/lighthouse-extension/package.json +++ b/lighthouse-extension/package.json @@ -11,6 +11,7 @@ "test": "mocha test/extension-test.js" }, "devDependencies": { + "acorn": "^5.5.3", "babel-plugin-syntax-object-rest-spread": "^6.13.0", "brfs": "^1.6.1", "browserify": "^16.2.0", diff --git a/lighthouse-extension/yarn.lock b/lighthouse-extension/yarn.lock index 9f5fb8cd3fa5..87b249957342 100644 --- a/lighthouse-extension/yarn.lock +++ b/lighthouse-extension/yarn.lock @@ -22,7 +22,7 @@ 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, 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" From 2d8fded44e63f9653871250d1ef59bfc7ab72e2b Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Fri, 1 Jun 2018 10:46:07 -0700 Subject: [PATCH 5/7] remove extra todo --- .../gather/gatherers/dobetterweb/optimized-images.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js index 90e131570a7e..8279f8ee188a 100644 --- a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js +++ b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js @@ -198,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); } } From 1840d4b64a151c1f96937e00c2e9b8604e1e8f24 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Fri, 8 Jun 2018 09:20:54 -0700 Subject: [PATCH 6/7] feedback --- lighthouse-extension/gulpfile.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lighthouse-extension/gulpfile.js b/lighthouse-extension/gulpfile.js index c45b76665c0c..fdf3fbf71b7f 100644 --- a/lighthouse-extension/gulpfile.js +++ b/lighthouse-extension/gulpfile.js @@ -4,13 +4,15 @@ 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: .* 8,/, 'ecmaVersion: 2018,') - .replace(/require\('acorn'\)/, `require(${JSON.stringify(acornPath)})`); + .replace('ecmaVersion: opts.ecmaVersion || 8', 'ecmaVersion: 2018,') + .replace(`require('acorn')`, `require(${JSON.stringify(acornPath)})`); fs.writeFileSync(astwPath, astwPatchedContent); const del = require('del'); From fe792396cfd9cbee3b3d789968d31dbb4e3c8245 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Fri, 8 Jun 2018 13:43:04 -0700 Subject: [PATCH 7/7] nuke extra comma --- lighthouse-extension/gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lighthouse-extension/gulpfile.js b/lighthouse-extension/gulpfile.js index 326162d93540..6a7b7f172145 100644 --- a/lighthouse-extension/gulpfile.js +++ b/lighthouse-extension/gulpfile.js @@ -11,7 +11,7 @@ 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('ecmaVersion: opts.ecmaVersion || 8', 'ecmaVersion: 2018') .replace(`require('acorn')`, `require(${JSON.stringify(acornPath)})`); fs.writeFileSync(astwPath, astwPatchedContent);