misc: get LH_ROOT via new file root.js #12724
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 )