summaryrefslogtreecommitdiff
path: root/ext/node/polyfills
AgeCommit message (Collapse)Author
2024-11-19feat(ext/node): perf_hooks.monitorEventLoopDelay() (#26905)Divy Srivastava
Fixes https://github.com/denoland/deno/issues/20961 Depends on https://github.com/denoland/deno_core/pull/965 and https://github.com/denoland/deno_core/pull/966
2024-11-19fix(node/crypto): support promisify on generateKeyPair (#26913)Marvin Hagemeister
Calling `promisify(generateKeyPair)` didn't work as expected. It requires a custom promisify implementation. This was easy to fix thanks to the excellent debugging investigation in https://github.com/denoland/deno/issues/26910 Fixes https://github.com/denoland/deno/issues/26910 Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-11-16fix(ext/node): New async setInterval function to improve the nodejs ↵/usr/bin/cat
compatibility (#26703) Closes #26499
2024-11-13feat(node): stabilize detecting if CJS via `"type": "commonjs"` in a ↵David Sherret
package.json (#26439) This will respect `"type": "commonjs"` in a package.json to determine if `.js`/`.jsx`/`.ts`/.tsx` files are CJS or ESM. If the file is found to be ESM it will be loaded as ESM though.
2024-11-13fix(ext/node): zlib.crc32() (#26856)Divy Srivastava
Fixes https://github.com/denoland/deno/issues/26845
2024-11-13fix(ext/node): use ERR_NOT_IMPLEMENTED for notImplemented (#26853)Divy Srivastava
2024-11-13feat(ext/fs): add ctime to Deno.stats and use it in node compat layer (#24801)Łukasz Czerniawski
This PR fixes #24453, by introducing a ctime (using ctime for UNIX and ChangeTime for Windows) to Deno.stats. Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
2024-11-13fix(ext/node): process.getBuiltinModule (#26833)Divy Srivastava
Closes https://github.com/denoland/deno/issues/26832
2024-11-12fix(ext/node): add autoSelectFamily option to net.createConnection (#26661)Yoshiya Hinosawa
2024-11-06fix(node:zlib): gzip & gzipSync should accept ArrayBuffer (#26762)Satya Rohith
Closes https://github.com/denoland/deno/issues/26638
2024-11-06fix(ext/node): better inspector support (#26471)snek
implement local inspector future changes: - wire up InspectorServer to enable open/close/url - wire up connectToMainThread Fixes https://github.com/denoland/deno/issues/25004
2024-11-04fix(ext/node): add `findSourceMap` to the default export of `node:module` ↵Nathan Whitaker
(#26720) Next.js 15.0.2 tries to use this and errors out
2024-11-04chore: update dlint to v0.68.0 for internal (#26711)Kenta Moriuchi
2024-11-01fix: improved support for cjs and cts modules (#26558)David Sherret
* cts support * better cjs/cts type checking * deno compile cjs/cts support * More efficient detect cjs (going towards stabilization) * Determination of whether .js, .ts, .jsx, or .tsx is cjs or esm is only done after loading * Support `import x = require(...);` Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-10-31fix(node): Implement `os.userInfo` properly, add missing `toPrimitive` (#24702)Nathan Whitaker
Fixes the implementation of `os.userInfo`, and adds a missing `toPrimitive` for `tmpdir`. This allows us to enable the corresponding node_compat test.
2024-10-31fix(ext/node): resolve exports even if parent module filename isn't present ↵Nathan Whitaker
(#26553) Fixes https://github.com/denoland/deno/issues/26505 I'm not exactly sure how this case comes about (I tried to write tests for it but couldn't manage to reproduce it), but what happens is the parent filename ends up null, and we bail out of resolving the specifier in package exports. I've checked, and in node the parent filename is also null (so that's not a bug on our part), but node continues to resolve even in that case. So this PR should match node's behavior more closely than we currently do.
2024-10-31fix(ext/node): convert errors from `fs.readFile/fs.readFileSync` to node ↵Nathan Whitaker
format (#26632) Fixes the original issue reported in #26404. storybook runs into other errors after this PR (the new errors will be fixed in other PRs). Some code used by a dependency of storybook does a [string comparison on the error message](https://github.com/chromaui/chromatic-cli/blob/ce30b2be343cb96a0826390b95ea42befb2be547/node-src/lib/getConfiguration.ts#L88-L92) thrown here to check for a file not found error.
2024-10-30fix(ext/node): return `this` from `http.Server.ref/unref()` (#26647)Nathan Whitaker
Fixes https://github.com/denoland/deno/issues/26642
2024-10-29Revert "fix(ext/node): fix dns.lookup result ordering (#26264)" (#26621)Yoshiya Hinosawa
This reverts commit d59599fc187c559ee231882773e1c5a2b932fc3d. Closes #26588
2024-10-29Revert "fix(ext/node): use primordials in `ext/node/polyfills/https.ts` ↵Bartek Iwańczuk
(#26323)" (#26613) …s` (#26323)" This reverts commit afb33b3c2597c9ec943f71218b236486fbc86e23. Reverting because it caused a regression - https://github.com/denoland/deno/issues/26612. Closes https://github.com/denoland/deno/issues/26612.
2024-10-28fix: report exceptions from nextTick (#26579)snek
Fixes: https://github.com/denoland/deno/issues/24713 Fixes: https://github.com/denoland/deno/issues/25855
2024-10-27fix(ext/node): add path to `fs.stat` and `fs.statSync` error (#26037)familyboat
2024-10-26fix(ext/node): use primordials in ↵Mayank Kumar
ext\node\polyfills\internal\crypto\_randomInt.ts (#26534) Towards #24236
2024-10-25fix(ext/node): refactor http.ServerResponse into function class (#26210)Nicola Bovolato
While testing, I found out that light-my-request relies on `ServerResponse.connection`, which is deprecated, so I added that and `socket`, the non deprecated property. It also relies on an undocumented `_header` property, apparently for [raw header processing](https://github.com/fastify/light-my-request/blob/v6.1.0/lib/response.js#L180-L186). I added it as an empty string, feel free to provide other approaches. Fixes #19901 Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-10-24fix(node/util): support array formats in `styleText` (#26507)Marvin Hagemeister
We missed adding support for an array of formats being passed to `util.styleText`. Fixes https://github.com/denoland/deno/issues/26496
2024-10-24fix(ext/node): cancel pending ipc writes on channel close (#26504)Nathan Whitaker
Fixes the issue described in https://github.com/denoland/deno/issues/23882#issuecomment-2423316362. The parent was starting to send a message right before the process would exit, and the channel closed in the middle of the write. Unlike with reads, we weren't cancelling the pending writes, which resulted in a `Broken pipe` error surfacing to the user.
2024-10-23fix(node:tls): set TLSSocket.alpnProtocol for client connections (#26476)Satya Rohith
Towards https://github.com/denoland/deno/issues/26127
2024-10-21fix(ext/node): use primordials in `ext/node/polyfills/https.ts` (#26323)jiang1997
Towards https://github.com/denoland/deno/issues/24236
2024-10-19perf: avoid multiple calls to runMicrotask (#26378)Divy Srivastava
Improves HTTP throughput by 8-9k rps on Linux: this patch ``` Requests/sec: 145001.69 Transfer/sec: 20.74MB ``` main ``` Requests/sec: 137866.61 Transfer/sec: 19.72MB ``` The improvements comes from the reduced number of calls to `op_run_microtask` per request. Returning `true` from a macrotask callback already calls `op_run_microtask` so the extra call was redundant. Here's `--strace-ops` output for a single request: main ``` [ 4.667] op_http_wait : CompletedAsync Async [ 4.667] op_run_microtasks : Dispatched Slow [ 4.668] op_http_try_wait : Dispatched Slow [ 4.668] op_http_try_wait : Completed Slow [ 4.668] op_http_wait : Dispatched Async [ 4.668] op_http_set_response_header : Dispatched Slow [ 4.668] op_http_set_response_header : Completed Slow [ 4.669] op_http_set_response_body_text : Dispatched Slow [ 4.669] op_http_set_response_body_text : Completed Slow [ 4.669] op_run_microtasks : Completed Slow [ 4.669] op_has_tick_scheduled : Dispatched Slow [ 4.669] op_has_tick_scheduled : Completed Slow [ 4.669] op_run_microtasks : Dispatched Slow [ 4.669] op_run_microtasks : Completed Slow [ 4.669] op_run_microtasks : Dispatched Slow [ 4.669] op_run_microtasks : Completed Slow ``` this pr ``` [ 3.726] op_http_wait : CompletedAsync Async [ 3.727] op_run_microtasks : Dispatched Slow [ 3.727] op_http_try_wait : Dispatched Slow [ 3.727] op_http_try_wait : Completed Slow [ 3.727] op_http_wait : Dispatched Async [ 3.727] op_http_set_response_header : Dispatched Slow [ 3.728] op_http_set_response_header : Completed Slow [ 3.728] op_http_set_response_body_text : Dispatched Slow [ 3.728] op_http_set_response_body_text : Completed Slow [ 3.728] op_run_microtasks : Completed Slow [ 3.728] op_run_microtasks : Dispatched Slow [ 3.728] op_run_microtasks : Completed Slow ```
2024-10-18fix(ext/node): stub HTTPParser internal binding (#26401)Nathan Whitaker
Fixes https://github.com/denoland/deno/issues/26394.
2024-10-18fix(ext/node): properly map reparse point error in readlink (#26375)Nathan Whitaker
2024-10-17fix(ext/node): add null check for kStreamBaseField (#26368)Bartek Iwańczuk
It's not guaranteed that `kStreamBaseField` is not undefined, so added a check for it. Closes https://github.com/denoland/deno/issues/26363
2024-10-17fix(node/fs): copyFile with `COPYFILE_EXCL` should not throw if the ↵Nathan Whitaker
destination doesn't exist (#26360) Fixes #26313. We were checking for the NotFound error, but still calling the callback with the error / throwing.
2024-10-17fix(net): don't try to set nodelay on upgrade streams (#26342)Nathan Whitaker
Fixes https://github.com/denoland/deno/issues/26341. We try to call `op_set_nodelay` on an `UpgradeStream`, which doesn't support that operation.
2024-10-16fix: don't warn on ignored signals on windows (#26332)Nathan Whitaker
Closes #26183. The warnings are super noisy and not actionable for the user
2024-10-17fix(node/http): normalize header names in `ServerResponse` (#26339)Nathan Whitaker
Fixes https://github.com/denoland/deno/issues/26115. We weren't normalizing the headers to lower case, so code that attempted to delete the `Content-Length` header (but used a different case) wasn't actually removing the header.
2024-10-16fix(child_process): map node `--no-warnings` flag to `--quiet` (#26288)Nathan Whitaker
Closes https://github.com/denoland/deno/issues/25899
2024-10-16fix(ext/node): fix dns.lookup result ordering (#26264)Yoshiya Hinosawa
partially unblocks #25470 This PR aligns the resolution of `localhost` hostname to Node.js behavior. In Node.js `dns.lookup("localhost", (_, addr) => console.log(addr))` prints ipv6 address `::1`, but it prints ipv4 address `127.0.0.1` in Deno. That difference causes some errors in the work of enabling `createConnection` option in `http.request` (#25470). This PR fixes the issue by aligning `dns.lookup` behavior to Node.js. This PR also changes the following behaviors (resolving TODOs): - `http.createServer` now listens on ipv6 address `[::]` by default on linux/mac - `net.createServer` now listens on ipv6 address `[::]` by default on linux/mac These changes are also alignments to Node.js behaviors.
2024-10-16fix(ext/node): timingSafeEqual account for AB byteOffset (#26292)Divy Srivastava
Fixes https://github.com/denoland/deno/issues/26276
2024-10-15fix(ext/node): use primordials in `ext/node/polyfills/internal/buffer.mjs` ↵Kenta Moriuchi
(#24993) Towards #24236
2024-10-15fix(ext/node): handle http2 server ending stream (#26235)Toby Ealden
Closes #24845
2024-10-15fix(ext/node): implement TCP.setNoDelay (#26263)Divy Srivastava
Fixes https://github.com/denoland/deno/issues/26177 The significant delay was caused by Nagel's algorithm + delayed ACKs in Linux kernels. Here's the [kernel patch](https://lwn.net/Articles/502585/) which added 40ms `tcp_default_delack_min` ``` $ deno run -A pg-bench.mjs # main Tue Oct 15 2024 12:27:22 GMT+0530 (India Standard Time): 42ms $ target/release/deno run -A pg-bench.mjs # this patch Tue Oct 15 2024 12:28:02 GMT+0530 (India Standard Time): 1ms ``` ```js import { Buffer } from "node:buffer"; import pg from 'pg' const { Client } = pg const client = new Client({ connectionString: 'postgresql://postgres:postgres@127.0.0.1:5432/postgres' }) await client.connect() async function fetch() { const startPerf = performance.now(); const res = await client.query(`select $1::int as int, $2 as string, $3::timestamp with time zone as timestamp, $4 as null, $5::bool as boolean, $6::bytea as bytea, $7::jsonb as json `, [ 1337, 'wat', new Date().toISOString(), null, false, Buffer.from('awesome'), JSON.stringify([{ some: 'json' }, { array: 'object' }]) ]) console.log(`${new Date()}: ${Math.round(performance.now() - startPerf)}ms`) } for(;;) await fetch(); ```
2024-10-14fix(ext/node): allow writing to tty columns (#26201)Divy Srivastava
Behave similar to Node.js where modifying `stdout.columns` doesn't really resize the terminal. Ref https://github.com/nodejs/node/issues/17529 Fixes https://github.com/denoland/deno/issues/26196
2024-10-12fix(node/util): export `styleText` from `node:util` (#26194)Nathan Whitaker
Fixes #26184. It was added but not publicly exported.
2024-10-11fix(node): make `process.stdout.isTTY` writable (#26130)Marvin Hagemeister
Fixes https://github.com/denoland/deno/issues/26123
2024-10-08fix(ext/node): internal buffer length in readSync (#26064)Satya Rohith
Closes https://github.com/denoland/deno/issues/26054
2024-10-04fix(node): fix worker_threads issues blocking Angular support (#26024)Nathan Whitaker
Fixes #22995. Fixes #23000. There were a handful of bugs here causing the hang (each with a corresponding minimized test): - We were canceling recv futures when `receiveMessageOnPort` was called, but this caused the "receive loop" in the message port to exit. This was due to the fact that `CancelHandle`s are never reset (i.e., once you `cancel` a `CancelHandle`, it remains cancelled). That meant that after `receieveMessageOnPort` was called, the subsequent calls to `op_message_port_recv_message` would throw `Interrupted` exceptions, and we would exit the loop. The cancellation, however, isn't actually necessary. `op_message_port_recv_message` only borrows the underlying port for long enough to poll the receiver, so the borrow there could never overlap with `op_message_port_recv_message_sync`. - Calling `MessagePort.unref()` caused the "receive loop" in the message port to exit. This was because we were setting `messageEventListenerCount` to 0 on unref. Not only does that break the counter when multiple `MessagePort`s are present in the same thread, but we also exited the "receive loop" whenever the listener count was 0. I assume this was to prevent the recv promise from keeping the event loop open. Instead of this, I chose to just unref the recv promise as needed to control the event loop. - The last bug causing the hang (which was a doozy to debug) ended up being an unfortunate interaction between how we implement our messageport "receive loop" and a pattern found in `npm:piscina` (which angular uses). The gist of it is that piscina uses an atomic wait loop along with `receiveMessageOnPort` in its worker threads, and as the worker is getting started, the following incredibly convoluted series of events occurs: 1. Parent sends a MessagePort `p` to worker 2. Parent sends a message `m` to the port `p` 3. Parent notifies the worker with `Atomics.notify` that a new message is available 4. Worker receives message, adds "message" listener to port `p` 5. Adding the listener triggers `MessagePort.start()` on `p` 6. Receive loop in MessagePort.start receives the message `m`, but then hits an await point and yields (before dispatching the "message" event) 7. Worker continues execution, starts the atomic wait loop, and immediately receives the existing notification from the parent that a message is available 8. Worker attempts to receive the new message `m` with `receiveMessageOnPort`, but this returns `undefined` because the receive loop already took the message in 6 9. Atomic wait loop continues to next iteration, waiting for the next message with `Atomic.wait` 10. `Atomic.wait` blocks the worker thread, which prevents the receive loop from continuing and dispatching the "message" event for the received message 11. The parent waits for the worker to respond to the first message, and waits 12. The thread can't make any more progress, and the whole process hangs The fix I've chosen here (which I don't particularly love, but it works) is to just delay the `MessagePort.start` call until the end of the event loop turn, so that the atomic wait loop receives the message first. This prevents the hang. --- Those were the main issues causing the hang. There ended up being a few other small bugs as well, namely `exit` being emitted multiple times, and not patching up the message port when it's received by `receiveMessageOnPort`.
2024-10-02feat(ext/node): buffer.transcode() (#25972)Satya Rohith
Closes https://github.com/denoland/deno/issues/25911
2024-10-02fix(ext/node): remove unimplemented promiseHook stubs (#25979)Divy Srivastava
`temporalio` sdk [will try to use](https://github.com/temporalio/sdk-typescript/blob/faa64225a7f57154931a38c1fe612fc6520943b2/packages/worker/src/workflow/vm-shared.ts#L199-L202) promiseHook if it is found. This patch removes the unimplemented stubs. ```ts if (promiseHooks) { // Node >=16.14 only this.stopPromiseHook = promiseHooks.createHook({ init: (promise: Promise<unknown>, parent: Promise<unknown>) => { ``` Fixes https://github.com/denoland/deno/issues/25977
2024-09-27fix(node): Pass NPM_PROCESS_STATE to subprocesses via temp file instead of ↵Nathan Whitaker
env var (#25896) Fixes https://github.com/denoland/deno/issues/25401. Fixes https://github.com/denoland/deno/issues/25841. Fixes https://github.com/denoland/deno/issues/25891.