-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
misc: convert lighthouse-core/scripts to ES modules #13121
Conversation
getNodeSelector: getNodeSelector, | ||
getNodeLabel: getNodeLabel, | ||
getNodeSelector, | ||
getNodeLabel, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drive by changes... I was hoping these changes would be enough to pass Node's commonjs named exports heuristics, but it was not. Anyhow, these properties don't need to use renaming syntax.
@@ -0,0 +1,18 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file may later find its way into lighthouse-core
, depending on if it also needs require.resolve
(I think it will?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely will though I imagine might need more context/bundle awareness
root.js
Outdated
readJson(path) { | ||
// TODO: could be nice to accept paths relative to LH_ROOT ? this would still | ||
// allow absolute paths. | ||
// return JSON.parse(fs.readFileSync(path.resolve(__dirname, path), 'utf-8')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thoughts? this would simplify a lot of call sites.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wfm 👍
the bigger issue that's become clear to me is the pain introduced by LH_ROOT
. makes me think a dirname
method that accepts import.meta.url
might have preserved the original intention better in most cases, but I'll leave that up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I've found that when I have the choice of a dirname
replacement and an equivalent to LH_ROOT
, I end up usually reaching for the LH_ROOT
, especially when the subdirectories are well separated and I have to go way up and back down again anyways :)
OTOH, I've also found as I've gotten used to them that dealing with import.meta.url
and fileURLToPath
to be increasingly not an impediment to writing or reading code. I wonder how much this appeals in a mass refactor as a way to centralize an annoying step, while it's no big deal authoring individual files. It sucks to lose json require
(until import assertions finally land), but in the past when I couldn't require
a json file (needing to mutate it or whatever), it really has never been a big deal to throw in a JSON.parse(fs.readFileSync)
line.
Not objecting to adding any helpful utilities, just saying we should maintain an open mind as the codebase continues to adapt to full ESM :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
especially when the subdirectories are well separated and I have to go way up and back down again anyways
Yes, definitely the situation where LH_ROOT is preferred. Many of the usages here though are for a local file in the same directory or an immediate neighbor, in which case the respecifying of the entire path to the subdir is suboptimal IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about readJson(path, baseDirOrImportMeta=LH_ROOT)
?
:D
@@ -45,7 +48,8 @@ function saveTraceFromCLI() { | |||
const lhrObject = JSON.parse(fs.readFileSync(filename, 'utf8')); | |||
const jsonStr = createTraceString(lhrObject); | |||
|
|||
const traceFilePath = `${filename}.timing.trace.json`; | |||
const pathObj = path.parse(filename); | |||
const traceFilePath = path.join(path.dirname(filename), `${pathObj.name}.timing.trace.json`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drive by changes (after noticing it didn't handle lhr.report.json
as expected)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
any issues should be easily fixable for next person needing to run these scripts
Depending on who the poor soul that runs these next is, I'm not 100% sure this is true 😉 but OK with that gamble given the usage frequency
@@ -0,0 +1,18 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely will though I imagine might need more context/bundle awareness
root.js
Outdated
readJson(path) { | ||
// TODO: could be nice to accept paths relative to LH_ROOT ? this would still | ||
// allow absolute paths. | ||
// return JSON.parse(fs.readFileSync(path.resolve(__dirname, path), 'utf-8')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wfm 👍
the bigger issue that's become clear to me is the pain introduced by LH_ROOT
. makes me think a dirname
method that accepts import.meta.url
might have preserved the original intention better in most cases, but I'll leave that up to you.
import expect from 'expect'; | ||
import tsc from 'typescript'; | ||
import MessageParser from 'intl-messageformat-parser'; | ||
import esMain from 'es-main'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to add this to our dev deps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
es-main
is already there tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
es-main
is already there tho
haha oh right
root.js
Outdated
readJson(path) { | ||
// TODO: could be nice to accept paths relative to LH_ROOT ? this would still | ||
// allow absolute paths. | ||
// return JSON.parse(fs.readFileSync(path.resolve(__dirname, path), 'utf-8')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I've found that when I have the choice of a dirname
replacement and an equivalent to LH_ROOT
, I end up usually reaching for the LH_ROOT
, especially when the subdirectories are well separated and I have to go way up and back down again anyways :)
OTOH, I've also found as I've gotten used to them that dealing with import.meta.url
and fileURLToPath
to be increasingly not an impediment to writing or reading code. I wonder how much this appeals in a mass refactor as a way to centralize an annoying step, while it's no big deal authoring individual files. It sucks to lose json require
(until import assertions finally land), but in the past when I couldn't require
a json file (needing to mutate it or whatever), it really has never been a big deal to throw in a JSON.parse(fs.readFileSync)
line.
Not objecting to adding any helpful utilities, just saying we should maintain an open mind as the codebase continues to adapt to full ESM :)
ref #12689
notes from manual testing: