-
Notifications
You must be signed in to change notification settings - Fork 545
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
fix: user-agent by making __filename check more resilient #2339
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2339 +/- ##
==========================================
+ Coverage 85.54% 92.28% +6.73%
==========================================
Files 76 41 -35
Lines 6858 3253 -3605
==========================================
- Hits 5867 3002 -2865
+ Misses 991 251 -740
☔ View full report in Codecov by Sentry. |
@KhafraDev previously commented that there isn't a difference between Unless someone else has a better idea, I think we rely on this undefined behavior to set the agent to (__filename ?? '').endsWith('index.js') ? 'undici' : 'node' or __filename ? 'undici' : 'node' I prefer the first so that if node ever enables __filename in its deps, then the code won't magically switch to WDYT? |
this would still throw an error if |
I prefer this with the |
or maybe just |
If Node.js changes its behavior that would break undici by reverting it back to |
a few tests are failing, the main entry point for undici is |
lol
|
Why is this so painful lol |
I can't believe I forgot this, but __filename isn't a global because it wouldn't work (how would it change for every file?), cjs modules are wrapped in an iife that has __filename, __dirname, etc. So I guess node core isn't doing that for dependencies. |
I think we should just make an esbuild plugin that injects a variable into |
Have you written one of those before? I have not but can start looking into it. |
I will have a PR fixing this soon |
I found this thread: evanw/esbuild#859 (comment) I don't love this solution mainly because I don't understand what the plugin is really doing. Would love some more input before we ship this |
Closing in favor of #2341 |
Rel: #2310 nodejs/node#50145
For some reason
__filename
is undefined when this gets loaded into node.jsTrying something else that might be more resilient. This also just falls back to
index.js
so that if all goes wrong at least we don't get a runtime error. WDYT? Should we switch the default to result in'node'
?