-
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: get LH_ROOT via new file root.js #12724
Conversation
Any chance we can use module aliases? |
|
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 looks good, but I'm not a huge fan of root.js
, especially if it grows to have dirname/filename substitutes. I don't have a better suggestion than my pretty bad module-utils.js
one, though.
Replaces all the
LH_ROOT = '../../../'
madness withconst {LH_ROOT} = require('../../../root.js')
. This does a few things:LH_ROO+<enter>
to auto-import this value to a file__dirname
, so having the code in one place means less future boilerplate)Beyond changing all instances of
LH_ROOT = ...
, I also grokked for lines that use__dirname
to form a path that goes to the root, and changed them to useLH_ROOT
.I did not modify any files that use
__dirname
w/o crossing over the root directory (ex:report-assets.js
does__dirname + '/renderer/util.js'
)–I have some ideas for that, maybe worth discussing here:getRelativePathEsm(importMeta, ...pathSegments)
(usage:getRelativePathEsm(import.meta, 'somefile.json')
)root.js
could also export all the top-level directories (LH_CORE
,LH_CLI
, etc...)LH_ROOT
for everything, and have all paths used in code be relative to root( the motivation is to avoid this code everywhere https://stackoverflow.com/a/50052194/2788187 )