Use workerd node:process v2 when available#10577
Conversation
🦋 Changeset detectedLatest commit: 24047d6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
|
I believe that in most of the cases where unenv is providing an implementation of a function like For undocumented APIs, I notice For non-function bindings, like |
When you say "Simply copying over the throwing stub [...]" do you mean copying the implementation to workerd? If you rather mean copying the implementation to the unev preset in this repo then that would still be an hybrid polyfill and I don't really see the point?
I agree that the likeness those
Sorry, I'm not exactly sure where you'd want to create the issue and what the content should be. Feel free to start someone and I'll contribute if needed. |
4967ba8 to
c94f131
Compare
c94f131 to
0baeb4a
Compare
0782e55 to
57ed746
Compare
|
Thanks again for working on this. Happy to review further. We just landed comprehensive process stubs in cloudflare/workerd#5040 which may help the transition here when that is available. |
node:process v2 when availablenode:process v2 when available
57ed746 to
245574e
Compare
node:process v2 when availablenode:process v2 when available
node:process v2 when availablenode:process v2 when available
|
I did sync after the update of workerd in wrangler. @petebacondarwin and @guybedford could you please review this PR? |
guybedford
left a comment
There was a problem hiding this comment.
Left an initial review. I'll look into an upstream follow-up for _eventsCount, _maxListeners and _events as well.
There was a problem hiding this comment.
These are now all implemented in cloudflare/workerd#5040.
There was a problem hiding this comment.
Same comment as on line 106
There was a problem hiding this comment.
These are also now added in cloudflare/workerd#5040.
There was a problem hiding this comment.
See the comment line 64 and line 181
// API that are only implemented starting from v2 of workerd process
// They are retrieved from unenv when process v1 is used
export const {
[...]
} = isWorkerdProcessV2 ? workerdProcess : unenvProcess;I think the code is right. Am I missing something?
There was a problem hiding this comment.
I think it would be fine to leave these ones out at this point, or have a path to test that. In Node.js,
import * as process from 'node:process';
console.log('process._channel', '_channel' in process, process._channel);
// ...
Gives:
process._channel false undefined
process._disconnect false undefined
process._events true [Object: null prototype] {
newListener: [ [Function (anonymous)], [Function: startListeningIfSignal] ],
removeListener: [ [Function (anonymous)], [Function: stopListeningIfSignal] ],
warning: [Function: onWarning],
SIGWINCH: [
[Function: refreshStdoutOnSigWinch],
[Function: refreshStderrOnSigWinch]
]
}
process._eventsCount true 3
process._handleQueue false undefined
process._maxListeners true undefined
process._pendingMessage false undefined
process._send false undefined
process.assert false undefined
process.disconnect false undefined
process.mainModule false undefined
Maintaining compat that is just not Node.js doesn't make sense to me.
Where _eventsCount, _maxListeners and _events are thus the only ones worth even considering keeping here.
There was a problem hiding this comment.
In Node.js
In what version of Node.js ?
At least we know that they were there before so let's merge this now and cleanup later.
WDYT?
There was a problem hiding this comment.
domain should be updated here and below
I think it's ok to address those in a follow up PR because this should be merged soonish (merging in workerd, doing a release, updating workerd in this repo will take 2/3 days if everything goes well). Any objection? |
guybedford
left a comment
There was a problem hiding this comment.
Sure, absolutely makes sense to roll this one out sooner rather than later.
245574e to
24047d6
Compare
|
Rebased + added a fixup commit for comments only |
This PR enabled using workerd
node:processv2 when it is enabled (by flag or date).It depends on the implemntation being available:
Outdated comment:
Details
A few notes:
This PR still fails the remote tests as the v2 changes have not reached production yet.
Some of the v2 APIs are
undefined.For that reason we still need an hybrid polyfill pulling their implementation from
unenv. Otherwise the following code might break:Because we have to use an hybrid polyfill anyway, we keep all the APIs that are implemented in
unenvand missing fromworkerd:_...APIs (_channel,_debugEnd, ...)addListener,assert, ...addListener,assert, ... are not all documented on nodejs.org and a few are deprecated. But they all are available for Node 22.16.0 (tested in the REPL).Maybe we can refine and better handle deprecated APIs now that we have a dedicated workerd flag. Comments welcome.
@petebacondarwin @guybedford could you please review the PR, the API surface is quite large and having more eyes would be helpful.