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

core(hreflang): remove eval, import axe valid-langs.js directly #13385

Merged
merged 9 commits into from
Feb 4, 2022

Conversation

connorjclark
Copy link
Collaborator

Fixes #13205

@connorjclark connorjclark requested a review from a team as a code owner November 16, 2021 21:53
@connorjclark connorjclark requested review from adamraine and removed request for a team November 16, 2021 21:53
@google-cla google-cla bot added the cla: yes label Nov 16, 2021
@connorjclark connorjclark changed the title core(hreflang): remove usage of eval, import axe-core/valid-langs.js core(hreflang): remove eval, import axe-core/valid-langs.js Nov 16, 2021
@connorjclark connorjclark changed the title core(hreflang): remove eval, import axe-core/valid-langs.js core(hreflang): remove eval, import axe valid-langs.js directly Nov 16, 2021
@connorjclark
Copy link
Collaborator Author

PASS lighthouse-core/test/audits/metrics-test.js
PASS lighthouse-core/test/lib/emulation-test.js
Segmentation fault (core dumped)
npm ERR! code ELIFECYCLE
npm ERR! errno 139
npm ERR! lighthouse@9.0.0 jest: `node --experimental-vm-modules ./node_modules/jest/bin/jest.js`
npm ERR! Exit status 139
npm ERR! 
npm ERR! Failed at the lighthouse@9.0.0 jest script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-11-16T21_58_00_618Z-debug.log
error Command failed with exit code 139.

oh no


echo '// @ts-nocheck' > "$OUT_FILE"
echo '// Auto-generated by lighthouse-core/scripts/copy-axe-valid-langs.sh' >> "$OUT_FILE"
sed 's/Sting/string/' "$LH_ROOT_DIR"/node_modules/axe-core/lib/core/utils/valid-langs.js >> "$OUT_FILE"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
sed 's/Sting/string/' "$LH_ROOT_DIR"/node_modules/axe-core/lib/core/utils/valid-langs.js >> "$OUT_FILE"
sed 's/String/string/' "$LH_ROOT_DIR"/node_modules/axe-core/lib/core/utils/valid-langs.js >> "$OUT_FILE"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, it is Sting.

image

Copy link
Member

Choose a reason for hiding this comment

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

I think they fixed it so it is String now

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

maybe we should talk to the axe folks about putting a package.json in e.g. the lib/ directory so it doesn't interfere with their main but allows importing modules under lib/?

@@ -50,6 +50,7 @@ jobs:
- run: yarn i18n:checks
- run: yarn dogfood-lhci
- run: bash lighthouse-core/scripts/copy-util-commonjs.sh
- run: bash lighthouse-core/scripts/copy-axe-valid-langs.sh
Copy link
Member

@brendankenny brendankenny Nov 16, 2021

Choose a reason for hiding this comment

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

can we skip introducing machinery to update? The list of langs hasn't changed since March 2018. The third-party directory needs a readme anyways, we could just put update instructions in there too. Ideally long term we just get the file to be importable from the node_modules/ dependency.

* @return {boolean}
*/
function isExpectedLanguageCode(hreflang) {
function isExpectedLanguageCode(hreflang, isValidLang) {
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to make this a callback? Could import where needed:

Suggested change
function isExpectedLanguageCode(hreflang, isValidLang) {
async function isExpectedLanguageCode(hreflang) {
// TODO(esmodules): use static import when file is esm.
const isValidLang = (await import('../../../third-party/axe/valid-langs.js')).default;
// ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was trying to limit the async from going where it made less sense.

@@ -0,0 +1,4 @@
{
"type": "module",
Copy link
Member

Choose a reason for hiding this comment

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

directory needs a license/readme (or metadata but readme is fine, honestly): go/thirdparty/non-google3

@connorjclark
Copy link
Collaborator Author

dequelabs/axe-core#3293

@connorjclark
Copy link
Collaborator Author

Get this error when running the integration recipe test: A dynamic import callback was not specified

I suppose this is related to jest, although apparently jest has supported dynamic imports for over a year now jestjs/jest#10620

@@ -12,7 +12,6 @@ docs/
lighthouse-core/lib/sd-validation/
lighthouse-core/scripts/*
lighthouse-core/test/
lighthouse-core/third_party/src/
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

drive by: this is not a folder

@@ -0,0 +1,4 @@
{
"license": "MPL-2.0",
"//": "Any directory that uses `import ... from` or `export ...` must be type module. Temporary file until root package.json is type: module"
Copy link
Member

Choose a reason for hiding this comment

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

There is no "type": "module" anymore, should this comment refer to the license or can we remove this file?

*/
static audit({LinkElements}) {
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't need to be async anymore


echo '// @ts-nocheck' > "$OUT_FILE"
echo '// Auto-generated by lighthouse-core/scripts/copy-axe-valid-langs.sh' >> "$OUT_FILE"
sed 's/Sting/string/' "$LH_ROOT_DIR"/node_modules/axe-core/lib/core/utils/valid-langs.js >> "$OUT_FILE"
Copy link
Member

Choose a reason for hiding this comment

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

I think they fixed it so it is String now

@connorjclark connorjclark merged commit 16248c1 into master Feb 4, 2022
@connorjclark connorjclark deleted the no-eval branch February 4, 2022 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove usage of eval in hreflang.js
4 participants