node_resolver/
builtin_modules.rs

1// Copyright 2018-2025 the Deno authors. MIT license.
2
3pub trait IsBuiltInNodeModuleChecker: std::fmt::Debug {
4  /// e.g. `is_builtin_node_module("assert")`
5  fn is_builtin_node_module(&self, module_name: &str) -> bool;
6}
7
8/// An implementation of IsBuiltInNodeModuleChecker that uses
9/// the list of built-in node_modules that are supported by Deno
10/// in the `deno_node` crate (ext/node).
11#[derive(Debug)]
12pub struct DenoIsBuiltInNodeModuleChecker;
13
14impl IsBuiltInNodeModuleChecker for DenoIsBuiltInNodeModuleChecker {
15  #[inline(always)]
16  fn is_builtin_node_module(&self, module_name: &str) -> bool {
17    DENO_SUPPORTED_BUILTIN_NODE_MODULES
18      .binary_search(&module_name)
19      .is_ok()
20  }
21}
22
23/// Collection of built-in node_modules supported by Deno.
24pub static DENO_SUPPORTED_BUILTIN_NODE_MODULES: &[&str] = &[
25  // NOTE(bartlomieju): keep this list in sync with `ext/node/polyfills/01_require.js`
26  "_http_agent",
27  "_http_common",
28  "_http_outgoing",
29  "_http_server",
30  "_stream_duplex",
31  "_stream_passthrough",
32  "_stream_readable",
33  "_stream_transform",
34  "_stream_writable",
35  "_tls_common",
36  "_tls_wrap",
37  "assert",
38  "assert/strict",
39  "async_hooks",
40  "buffer",
41  "child_process",
42  "cluster",
43  "console",
44  "constants",
45  "crypto",
46  "dgram",
47  "diagnostics_channel",
48  "dns",
49  "dns/promises",
50  "domain",
51  "events",
52  "fs",
53  "fs/promises",
54  "http",
55  "http2",
56  "https",
57  "inspector",
58  "inspector/promises",
59  "module",
60  "net",
61  "os",
62  "path",
63  "path/posix",
64  "path/win32",
65  "perf_hooks",
66  "process",
67  "punycode",
68  "querystring",
69  "readline",
70  "readline/promises",
71  "repl",
72  "sqlite",
73  "stream",
74  "stream/consumers",
75  "stream/promises",
76  "stream/web",
77  "string_decoder",
78  "sys",
79  "test",
80  "timers",
81  "timers/promises",
82  "tls",
83  "tty",
84  "url",
85  "util",
86  "util/types",
87  "v8",
88  "vm",
89  "wasi",
90  "worker_threads",
91  "zlib",
92];
93
94#[cfg(test)]
95mod test {
96  use super::*;
97
98  #[test]
99  fn test_builtins_are_sorted() {
100    let mut builtins_list = DENO_SUPPORTED_BUILTIN_NODE_MODULES.to_vec();
101    builtins_list.sort();
102    assert_eq!(DENO_SUPPORTED_BUILTIN_NODE_MODULES, builtins_list);
103  }
104}