fix(node): Correctly resolve module name#10001
Conversation
06636e5 to
8179837
Compare
|
|
||
| function getBasePath(): string { | ||
| if (!basePath) { | ||
| const baseDir = |
There was a problem hiding this comment.
l: This is not really related to this PR, but it would be nice to have a comment explaining what & why we actually do here - e.g. why use require.main.filename over global.process.cwd() etc. Feel free to ignore this, but as somebody with little to no historical context on this, this appears very magic to me 😅
There was a problem hiding this comment.
I have no idea other than this has been like this for 11+ years from raven-node:
https://github.com/getsentry/raven-node/blame/7019cb30efda40704105b7b510bc428ec0c1ee01/lib/utils.js#L87
There was a problem hiding this comment.
It is a good point though which is worth considering as it will be important for #9072.
I guess the issue with process.cwd() is that it might give us the repository root rather than the runtime root. For example, the app might be run from process.cwd() + '/packages/my-app/dist/' so if we use cwd, paths (and therefore modules, will always start packages.my-app.dist.*.
dirname(require.main.filename) will only give us an accurate runtime root if the entry point is in the root. I suspect this is true the majority of the time.
In the Deno SDK, due to permissions we might not have have access to cwd() or the file system. To work around this, we parse a new Error().stack from init and pick the common root path from the stack trace.
|
💯 01, nice! |
Closes #10000
basePathsodirname(require.main.filename)only gets called oncenode_modules