Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extension: allow use of ES2018 features #5377

Merged
merged 9 commits into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget about line 202 - 203

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch thanks @underbyte! :)

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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure but imo ndb gulp build is the besttt

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it is, but seeing as the only ndb I have access to is 7 years old https://www.npmjs.com/package/ndb us pleebs have to make due with this 😛

"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