deno/ext/node/polyfills
Yoshiya Hinosawa c538f44fa0
fix(ext/node): improve comparison of faked objects in deepStrictEqual (#29819)
This commit improves the handling of objects with faked prototypes in
`deepStrictEqual`. This enables `parallel/test-assert-checktag.js`

- `Date` objects are checked by `core.isDate`
- In object comparison, now it checks `obj.toString()` output (The
difference of `Symbol.toStringTag` is now detected).
- Stoped using std's assertion error message for `deepStrictEqual`, but
started using Node.js version of diff string. Now the diff expression is
more compatible with Node.
2025-06-20 23:33:18 +09:00
..
_fs fix(ext/node): add fchmod and fchmodSync (#29791) 2025-06-18 12:48:14 +02:00
_process fix: process.stdin.pause() (#29330) 2025-05-17 18:46:26 +05:30
_util fix(ext/node): improve comparison of faked objects in deepStrictEqual (#29819) 2025-06-20 23:33:18 +09:00
assert chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
dns chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
fs chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
inspector chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
internal fix(ext/node): support KeyObject in publicEncrypt/privateDecrypt (#29798) 2025-06-19 09:48:29 +09:00
internal_binding fix(ext/node): crypto.timingSafeEqual (#29758) 2025-06-16 21:33:49 +09:00
path fix(ext/node): use primordials in ext/node/polyfills/path/separator.ts (#28669) 2025-04-08 10:42:58 +09:00
readline chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
stream fix(ext/node): upgrade node:stream (#28855) 2025-04-14 21:35:34 +05:30
timers chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
util chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
00_globals.js chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
01_require.js fix(ext/node): Module.wrap cleanup for npm:v8-code-cache (#29725) 2025-06-17 02:32:10 +02:00
02_init.js feat: use a single 'performance' global (#29323) 2025-05-17 00:11:11 +02:00
_brotli.js fix(ext/node): fix async variant of brotliDecompress (#27815) 2025-01-27 09:13:47 +05:30
_events.d.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_events.mjs refactor(ext/node): remove setProcess workaround (#29813) 2025-06-19 21:20:50 +09:00
_global.d.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_http_agent.mjs chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_http_common.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_http_outgoing.ts fix(ext/node): enable Buffer pool for strings (#29592) 2025-06-05 12:04:32 +09:00
_http_server.ts fix(ext/node): correct STATUS_CODES strings (#28489) 2025-03-13 14:21:08 -04:00
_next_tick.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_readline.d.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_readline.mjs fix(ext/node): createInterface doesn't require env permission (#29472) 2025-05-28 11:59:26 +02:00
_readline_shared_types.d.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_stream.d.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_tls_common.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_tls_wrap.ts fix(ext/node): TLS server unref (#29279) 2025-05-13 21:38:41 +05:30
_utils.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_zlib.mjs fix(ext/node): expose brotli stream APIs (#27943) 2025-02-04 07:47:02 +05:30
_zlib_binding.mjs fix(ext/node): verbose zlib error messages (#28831) 2025-04-11 17:17:32 +05:30
assert.ts fix(ext/node): improve comparison of faked objects in deepStrictEqual (#29819) 2025-06-20 23:33:18 +09:00
assertion_error.ts fix(ext/node): improve comparison of faked objects in deepStrictEqual (#29819) 2025-06-20 23:33:18 +09:00
async_hooks.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
buffer.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
child_process.ts refactor(ext/node): use Promise.withResolvers (#28917) 2025-04-15 17:33:53 -04:00
cluster.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
console.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
constants.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
crypto.ts fix(ext/node): deprecate Hash and Hmac constructors (#29774) 2025-06-18 10:37:03 +09:00
dgram.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
diagnostics_channel.js chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
dns.ts fix(ext/node): improve getaddrinfo compatibility (#29501) 2025-06-02 11:34:36 +09:00
domain.ts fix(ext/node): update interaction between event emitters and domains (#29632) 2025-06-09 12:06:43 +09:00
events.ts fix(ext/node): add events getMaxListeners (#29636) 2025-06-08 04:07:03 +00:00
fs.ts fix(ext/node): add fchmod and fchmodSync (#29791) 2025-06-18 12:48:14 +02:00
http.ts fix(ext/node): handle null ssl options in node:https (#29365) 2025-05-19 07:55:15 +02:00
http2.ts fix(ext/node): add "internal/http2/util" module (#29474) 2025-05-28 21:46:36 +09:00
https.ts fix(ext/node): Support mTLS connections node compatibility (#28937) 2025-05-06 14:25:18 +05:30
inspector.js chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
net.ts fix: process.stdin.pause() (#29330) 2025-05-17 18:46:26 +05:30
os.ts refactor: add 'deno_os' crate (#27655) 2025-01-14 17:29:36 +01:00
path.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
perf_hooks.js fix(ext/node): add back perf_hooks.markResourceTiming (#29562) 2025-06-02 17:53:38 +05:30
process.ts refactor(ext/node): remove setProcess workaround (#29813) 2025-06-19 21:20:50 +09:00
punycode.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
querystring.js fix(ext/node): querystring fallback to default decoder (#28838) 2025-04-14 15:17:28 +05:30
readline.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
README.md chore: move tools/node_compat to tests/node_compat/runner (#23025) 2024-04-03 09:24:55 +11:00
repl.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
sqlite.ts fix(ext/node): export StatementSync from node:sqlite (#29563) 2025-06-02 11:34:41 +00:00
stream.ts fix(ext/node): upgrade node:stream (#28855) 2025-04-14 21:35:34 +05:30
string_decoder.ts fix(ext/node): enable Buffer pool for strings (#29592) 2025-06-05 12:04:32 +09:00
sys.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
testing.ts fix(ext/node): include assert.ok in node:test (#29383) 2025-05-20 04:05:19 +00:00
timers.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
tls.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
trace_events.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
tty.js chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
url.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
util.ts refactor(ext/node): use Promise.withResolvers (#28917) 2025-04-15 17:33:53 -04:00
v8.ts fix(ext/node): support DEP0005 deprecation warning (#29530) 2025-06-04 12:25:32 +09:00
vm.js chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
wasi.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
worker_threads.ts fix: remove WorkerGlobalScope from global middleware (#29543) 2025-06-11 17:19:15 +02:00
zlib.ts fix(ext/node): expose brotli stream APIs (#27943) 2025-02-04 07:47:02 +05:30

Deno Node.js compatibility

This module is meant to have a compatibility layer for the Node.js standard library.

Warning: Any function of this module should not be referred anywhere in the Deno standard library as it's a compatibility module.

Supported modules

  • assert
  • assert/strict partly
  • async_hooks partly
  • buffer
  • child_process partly
  • cluster partly
  • console partly
  • constants partly
  • crypto partly
  • dgram partly
  • diagnostics_channel partly
  • dns partly
  • events
  • fs partly
  • fs/promises partly
  • http partly
  • http2
  • https partly
  • inspector partly
  • module
  • net
  • os partly
  • path
  • path/posix
  • path/win32
  • perf_hooks
  • process partly
  • punycode
  • querystring
  • readline
  • repl partly
  • stream
  • stream/promises
  • stream/web partly
  • string_decoder
  • sys
  • timers
  • timers/promises
  • tls
  • trace_events
  • tty partly
  • url
  • util partly
  • util/types partly
  • v8
  • vm partly
  • wasi
  • webcrypto
  • worker_threads
  • zlib
  • node globals partly

Deprecated

These modules are deprecated in Node.js and will probably not be polyfilled:

  • domain
  • freelist

Experimental

These modules are experimental in Node.js and will not be polyfilled until they are stable:

  • diagnostics_channel
  • async_hooks
  • policies
  • trace_events
  • wasi
  • webcrypto

CommonJS modules loading

createRequire(...) is provided to create a require function for loading CJS modules. It also sets supported globals.

import { createRequire } from "node:module";

const require = createRequire(import.meta.url);
// Loads native module polyfill.
const path = require("path");
// Loads extensionless module.
const cjsModule = require("./my_mod");
// Visits node_modules.
const leftPad = require("left-pad");

Contributing

Setting up the test runner and running tests

See tests/node_compat/runner/README.md.

Best practices

When converting from promise-based to callback-based APIs, the most obvious way is like this:

promise.then((value) => callback(null, value)).catch(callback);

This has a subtle bug - if the callback throws an error, the catch statement will also catch that error, and the callback will be called twice. The correct way to do it is like this:

promise.then((value) => callback(null, value), callback);

The second parameter of then can also be used to catch errors, but only errors from the existing promise, not the new one created by the callback.

If the Deno equivalent is actually synchronous, there's a similar problem with try/catch statements:

try {
  const value = process();
  callback(null, value);
} catch (err) {
  callback(err);
}

Since the callback is called within the try block, any errors from it will be caught and call the callback again.

The correct way to do it is like this:

let err, value;
try {
  value = process();
} catch (e) {
  err = e;
}
if (err) {
  callback(err); // Make sure arguments.length === 1
} else {
  callback(null, value);
}

It's not as clean, but prevents the callback being called twice.

Remaining Tests

Node compatibility can be measured by how many native Node tests pass. If you'd like to know what you can work on, check out the list of Node tests remaining here.