We need to investigate how hard is it to build a realistic node:net#Socket polyfill using what we currently have in workerd's cloudflare:socket and nodejs_compat layer.
This came out of a discusstion about brianc/node-postgres#3170 with @petebacondarwin this morning where we are trying to improve our pg specific node:net#Socket polyfill. This made me wonder if a better path wouldn't be to beef up our node:net#Socket polyfill so that things just work.
Looking at https://github.com/brianc/node-postgres/blob/master/packages/pg-cloudflare/src/index.ts it seems that we are essentially creating a bespoke polyfill for node Socket there. So why not upstream this to unenv (or eventually workerd)?
The unenv polyfill doesn't seem terribly complex: https://github.com/unjs/unenv/blob/main/src/runtime/node/net/socket.ts because it simply extends from node:stream#Duplex.
Note: workerd has native implementation of node:stream#Duplex but since this unenv polyfill exports it via a relative import, the unenv polyfill will end up ignoring our implementation. This is something that should be fixed in unenv as part of the hybrid polyfill effort: unjs/unenv#181
We need to investigate how hard is it to build a realistic node:net#Socket polyfill using what we currently have in workerd's cloudflare:socket and nodejs_compat layer.
This came out of a discusstion about brianc/node-postgres#3170 with @petebacondarwin this morning where we are trying to improve our pg specific node:net#Socket polyfill. This made me wonder if a better path wouldn't be to beef up our node:net#Socket polyfill so that things just work.
Looking at https://github.com/brianc/node-postgres/blob/master/packages/pg-cloudflare/src/index.ts it seems that we are essentially creating a bespoke polyfill for node Socket there. So why not upstream this to unenv (or eventually workerd)?
The unenv polyfill doesn't seem terribly complex: https://github.com/unjs/unenv/blob/main/src/runtime/node/net/socket.ts because it simply extends from
node:stream#Duplex.Note: workerd has native implementation of
node:stream#Duplexbut since this unenv polyfill exports it via a relative import, the unenv polyfill will end up ignoring our implementation. This is something that should be fixed in unenv as part of the hybrid polyfill effort: unjs/unenv#181