-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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: provide nodejs compat for dns methods wrapped with util.promisify #6748
Conversation
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.
Thank you for this
One small nitpicky comment but lets merge after that
src/js/node/dns.js
Outdated
@@ -1,6 +1,7 @@ | |||
// Hardcoded module "node:dns" | |||
// only resolve4, resolve, lookup, resolve6, resolveSrv, and reverse are implemented. | |||
const dns = Bun.dns; | |||
const util = require("node:util"); |
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.
Instead of loading all of node:util
, we can choose to instead load only the symbol we need:
const util = require("node:util"); | |
const utilPromisifyCustomSymbol = Symbol.for("nodejs.util.promisify.custom") |
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.
Hmm...
It turns out, there's a pair of symbols: nodejs.util.promisify.custom
and util.promisify.custom
https://github.com/oven-sh/bun/blob/main/src/js/node/util.js#L150
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.
// TODO: register shared symbol promisify.custom
— is it time?
src/js/node/dns.js
Outdated
[resolveTxt, promises.resolveTxt], | ||
[resolveNaptr, promises.resolveNaptr], | ||
]) { | ||
method[util.promisify.custom] = pMethod |
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.
method[util.promisify.custom] = pMethod | |
method[utilPromisifyCustomSymbol] = pMethod |
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.
Finally, it works on my machine
✓ uses `dns.promises` implementations for `util.promisify` factory > resolvePtr
✓ uses `dns.promises` implementations for `util.promisify` factory > resolveSoa
✓ uses `dns.promises` implementations for `util.promisify` factory > resolveSrv
✓ uses `dns.promises` implementations for `util.promisify` factory > resolveTxt
✓ uses `dns.promises` implementations for `util.promisify` factory > resolveNaptr
[Loop] ref
[FilePoll] register: machport (9735)
[Loop] unref x 1
[FilePoll] machport
[FilePoll] onUpdate kevent (fd: 2147483646) GetAddrInfoRequest
[GetAddrInfoRequest] getAddrInfoAsyncCallback: status=0
[FilePoll] unregister: machport (2147483646) skipped due to needs_rearm
[Loop] ref
[FilePoll] register: machport (9739)
[Loop] unref x 1
[FilePoll] machport
[FilePoll] onUpdate kevent (fd: 2147483646) GetAddrInfoRequest
[GetAddrInfoRequest] getAddrInfoAsyncCallback: status=0
[FilePoll] unregister: machport (2147483646) skipped due to needs_rearm
✓ uses `dns.promises` implementations for `util.promisify` factory > util.promisify(dns.lookup) acts like dns.promises.lookup [4.13ms]
Some docs are referencing to make js
, which seems useless. The required files are missing.
src/js/_codegen/index.ts
src/js/build-esm.ts
Thank you! |
What does this PR do?
Adds nodejs compatibility for
dns[methods]
wrapped withutil.promisify
nodejs
bun
How did you verify your code works?
UPD