1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

use deno_core::error::generic_error;
use deno_core::error::AnyError;
use deno_core::include_js_files;
use deno_core::normalize_path;
use deno_core::op;
use deno_core::url::Url;
use deno_core::Extension;
use deno_core::JsRuntimeInspector;
use deno_core::OpState;
use once_cell::sync::Lazy;
use std::collections::HashSet;
use std::path::Path;
use std::path::PathBuf;
use std::rc::Rc;

pub mod errors;
mod package_json;
mod path;
mod resolution;

pub use package_json::PackageJson;
pub use path::PathClean;
pub use resolution::get_closest_package_json;
pub use resolution::get_package_scope_config;
pub use resolution::legacy_main_resolve;
pub use resolution::package_exports_resolve;
pub use resolution::package_imports_resolve;
pub use resolution::package_resolve;
pub use resolution::path_to_declaration_path;
pub use resolution::NodeModuleKind;
pub use resolution::NodeResolutionMode;
pub use resolution::DEFAULT_CONDITIONS;
use std::cell::RefCell;

pub trait NodePermissions {
  fn check_read(&mut self, path: &Path) -> Result<(), AnyError>;
}

pub trait RequireNpmResolver {
  fn resolve_package_folder_from_package(
    &self,
    specifier: &str,
    referrer: &Path,
    mode: NodeResolutionMode,
  ) -> Result<PathBuf, AnyError>;

  fn resolve_package_folder_from_path(
    &self,
    path: &Path,
  ) -> Result<PathBuf, AnyError>;

  fn in_npm_package(&self, path: &Path) -> bool;

  fn ensure_read_permission(
    &self,
    permissions: &mut dyn NodePermissions,
    path: &Path,
  ) -> Result<(), AnyError>;
}

pub const MODULE_ES_SHIM: &str = include_str!("./module_es_shim.js");

pub static NODE_GLOBAL_THIS_NAME: Lazy<String> = Lazy::new(|| {
  let now = std::time::SystemTime::now();
  let seconds = now
    .duration_since(std::time::SystemTime::UNIX_EPOCH)
    .unwrap()
    .as_secs();
  // use a changing variable name to make it hard to depend on this
  format!("__DENO_NODE_GLOBAL_THIS_{}__", seconds)
});

pub static NODE_ENV_VAR_ALLOWLIST: Lazy<HashSet<String>> = Lazy::new(|| {
  // The full list of environment variables supported by Node.js is available
  // at https://nodejs.org/api/cli.html#environment-variables
  let mut set = HashSet::new();
  set.insert("NODE_DEBUG".to_string());
  set.insert("NODE_OPTIONS".to_string());
  set
});

pub fn init<P: NodePermissions + 'static>(
  maybe_npm_resolver: Option<Rc<dyn RequireNpmResolver>>,
) -> Extension {
  Extension::builder(env!("CARGO_PKG_NAME"))
    .js(include_js_files!(
      prefix "deno:ext/node",
      "01_node.js",
      "02_require.js",
    ))
    .ops(vec![
      op_require_init_paths::decl(),
      op_require_node_module_paths::decl::<P>(),
      op_require_proxy_path::decl(),
      op_require_is_deno_dir_package::decl(),
      op_require_resolve_deno_dir::decl(),
      op_require_is_request_relative::decl(),
      op_require_resolve_lookup_paths::decl(),
      op_require_try_self_parent_path::decl::<P>(),
      op_require_try_self::decl::<P>(),
      op_require_real_path::decl::<P>(),
      op_require_path_is_absolute::decl(),
      op_require_path_dirname::decl(),
      op_require_stat::decl::<P>(),
      op_require_path_resolve::decl(),
      op_require_path_basename::decl(),
      op_require_read_file::decl::<P>(),
      op_require_as_file_path::decl(),
      op_require_resolve_exports::decl::<P>(),
      op_require_read_closest_package_json::decl::<P>(),
      op_require_read_package_scope::decl::<P>(),
      op_require_package_imports_resolve::decl::<P>(),
      op_require_break_on_next_statement::decl(),
    ])
    .state(move |state| {
      if let Some(npm_resolver) = maybe_npm_resolver.clone() {
        state.put(npm_resolver);
      }
      Ok(())
    })
    .build()
}

fn ensure_read_permission<P>(
  state: &mut OpState,
  file_path: &Path,
) -> Result<(), AnyError>
where
  P: NodePermissions + 'static,
{
  let resolver = {
    let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>();
    resolver.clone()
  };
  let permissions = state.borrow_mut::<P>();
  resolver.ensure_read_permission(permissions, file_path)
}

#[op]
pub fn op_require_init_paths() -> Vec<String> {
  // todo(dsherret): this code is node compat mode specific and
  // we probably don't want it for small mammal, so ignore it for now

  // let (home_dir, node_path) = if cfg!(windows) {
  //   (
  //     std::env::var("USERPROFILE").unwrap_or_else(|_| "".into()),
  //     std::env::var("NODE_PATH").unwrap_or_else(|_| "".into()),
  //   )
  // } else {
  //   (
  //     std::env::var("HOME").unwrap_or_else(|_| "".into()),
  //     std::env::var("NODE_PATH").unwrap_or_else(|_| "".into()),
  //   )
  // };

  // let mut prefix_dir = std::env::current_exe().unwrap();
  // if cfg!(windows) {
  //   prefix_dir = prefix_dir.join("..").join("..")
  // } else {
  //   prefix_dir = prefix_dir.join("..")
  // }

  // let mut paths = vec![prefix_dir.join("lib").join("node")];

  // if !home_dir.is_empty() {
  //   paths.insert(0, PathBuf::from(&home_dir).join(".node_libraries"));
  //   paths.insert(0, PathBuf::from(&home_dir).join(".nod_modules"));
  // }

  // let mut paths = paths
  //   .into_iter()
  //   .map(|p| p.to_string_lossy().to_string())
  //   .collect();

  // if !node_path.is_empty() {
  //   let delimiter = if cfg!(windows) { ";" } else { ":" };
  //   let mut node_paths: Vec<String> = node_path
  //     .split(delimiter)
  //     .filter(|e| !e.is_empty())
  //     .map(|s| s.to_string())
  //     .collect();
  //   node_paths.append(&mut paths);
  //   paths = node_paths;
  // }

  vec![]
}

#[op]
pub fn op_require_node_module_paths<P>(
  state: &mut OpState,
  from: String,
) -> Result<Vec<String>, AnyError>
where
  P: NodePermissions + 'static,
{
  // Guarantee that "from" is absolute.
  let from = deno_core::resolve_path(&from)
    .unwrap()
    .to_file_path()
    .unwrap();

  ensure_read_permission::<P>(state, &from)?;

  if cfg!(windows) {
    // return root node_modules when path is 'D:\\'.
    let from_str = from.to_str().unwrap();
    if from_str.len() >= 3 {
      let bytes = from_str.as_bytes();
      if bytes[from_str.len() - 1] == b'\\' && bytes[from_str.len() - 2] == b':'
      {
        let p = from_str.to_owned() + "node_modules";
        return Ok(vec![p]);
      }
    }
  } else {
    // Return early not only to avoid unnecessary work, but to *avoid* returning
    // an array of two items for a root: [ '//node_modules', '/node_modules' ]
    if from.to_string_lossy() == "/" {
      return Ok(vec!["/node_modules".to_string()]);
    }
  }

  let mut paths = vec![];
  let mut current_path = from.as_path();
  let mut maybe_parent = Some(current_path);
  while let Some(parent) = maybe_parent {
    if !parent.ends_with("/node_modules") {
      paths.push(parent.join("node_modules").to_string_lossy().to_string());
      current_path = parent;
      maybe_parent = current_path.parent();
    }
  }

  if !cfg!(windows) {
    // Append /node_modules to handle root paths.
    paths.push("/node_modules".to_string());
  }

  Ok(paths)
}

#[op]
fn op_require_proxy_path(filename: String) -> String {
  // Allow a directory to be passed as the filename
  let trailing_slash = if cfg!(windows) {
    // Node also counts a trailing forward slash as a
    // directory for node on Windows, but not backslashes
    // on non-Windows platforms
    filename.ends_with('\\') || filename.ends_with('/')
  } else {
    filename.ends_with('/')
  };

  if trailing_slash {
    let p = PathBuf::from(filename);
    p.join("noop.js").to_string_lossy().to_string()
  } else {
    filename
  }
}

#[op]
fn op_require_is_request_relative(request: String) -> bool {
  if request.starts_with("./") || request.starts_with("../") || request == ".."
  {
    return true;
  }

  if cfg!(windows) {
    if request.starts_with(".\\") {
      return true;
    }

    if request.starts_with("..\\") {
      return true;
    }
  }

  false
}

#[op]
fn op_require_resolve_deno_dir(
  state: &mut OpState,
  request: String,
  parent_filename: String,
) -> Option<String> {
  let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>();
  resolver
    .resolve_package_folder_from_package(
      &request,
      &PathBuf::from(parent_filename),
      NodeResolutionMode::Execution,
    )
    .ok()
    .map(|p| p.to_string_lossy().to_string())
}

#[op]
fn op_require_is_deno_dir_package(state: &mut OpState, path: String) -> bool {
  let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>();
  resolver.in_npm_package(&PathBuf::from(path))
}

#[op]
fn op_require_resolve_lookup_paths(
  request: String,
  maybe_parent_paths: Option<Vec<String>>,
  parent_filename: String,
) -> Option<Vec<String>> {
  if !request.starts_with('.')
    || (request.len() > 1
      && !request.starts_with("..")
      && !request.starts_with("./")
      && (!cfg!(windows) || !request.starts_with(".\\")))
  {
    let module_paths = vec![];
    let mut paths = module_paths;
    if let Some(mut parent_paths) = maybe_parent_paths {
      if !parent_paths.is_empty() {
        paths.append(&mut parent_paths);
      }
    }

    if !paths.is_empty() {
      return Some(paths);
    } else {
      return None;
    }
  }

  // In REPL, parent.filename is null.
  // if (!parent || !parent.id || !parent.filename) {
  //   // Make require('./path/to/foo') work - normally the path is taken
  //   // from realpath(__filename) but in REPL there is no filename
  //   const mainPaths = ['.'];

  //   debug('looking for %j in %j', request, mainPaths);
  //   return mainPaths;
  // }

  let p = PathBuf::from(parent_filename);
  Some(vec![p.parent().unwrap().to_string_lossy().to_string()])
}

#[op]
fn op_require_path_is_absolute(p: String) -> bool {
  PathBuf::from(p).is_absolute()
}

#[op]
fn op_require_stat<P>(
  state: &mut OpState,
  path: String,
) -> Result<i32, AnyError>
where
  P: NodePermissions + 'static,
{
  let path = PathBuf::from(path);
  ensure_read_permission::<P>(state, &path)?;
  if let Ok(metadata) = std::fs::metadata(&path) {
    if metadata.is_file() {
      return Ok(0);
    } else {
      return Ok(1);
    }
  }

  Ok(-1)
}

#[op]
fn op_require_real_path<P>(
  state: &mut OpState,
  request: String,
) -> Result<String, AnyError>
where
  P: NodePermissions + 'static,
{
  let path = PathBuf::from(request);
  ensure_read_permission::<P>(state, &path)?;
  let mut canonicalized_path = path.canonicalize()?;
  if cfg!(windows) {
    canonicalized_path = PathBuf::from(
      canonicalized_path
        .display()
        .to_string()
        .trim_start_matches("\\\\?\\"),
    );
  }
  Ok(canonicalized_path.to_string_lossy().to_string())
}

fn path_resolve(parts: Vec<String>) -> String {
  assert!(!parts.is_empty());
  let mut p = PathBuf::from(&parts[0]);
  if parts.len() > 1 {
    for part in &parts[1..] {
      p = p.join(part);
    }
  }
  normalize_path(p).to_string_lossy().to_string()
}

#[op]
fn op_require_path_resolve(parts: Vec<String>) -> String {
  path_resolve(parts)
}

#[op]
fn op_require_path_dirname(request: String) -> Result<String, AnyError> {
  let p = PathBuf::from(request);
  if let Some(parent) = p.parent() {
    Ok(parent.to_string_lossy().to_string())
  } else {
    Err(generic_error("Path doesn't have a parent"))
  }
}

#[op]
fn op_require_path_basename(request: String) -> Result<String, AnyError> {
  let p = PathBuf::from(request);
  if let Some(path) = p.file_name() {
    Ok(path.to_string_lossy().to_string())
  } else {
    Err(generic_error("Path doesn't have a file name"))
  }
}

#[op]
fn op_require_try_self_parent_path<P>(
  state: &mut OpState,
  has_parent: bool,
  maybe_parent_filename: Option<String>,
  maybe_parent_id: Option<String>,
) -> Result<Option<String>, AnyError>
where
  P: NodePermissions + 'static,
{
  if !has_parent {
    return Ok(None);
  }

  if let Some(parent_filename) = maybe_parent_filename {
    return Ok(Some(parent_filename));
  }

  if let Some(parent_id) = maybe_parent_id {
    if parent_id == "<repl>" || parent_id == "internal/preload" {
      if let Ok(cwd) = std::env::current_dir() {
        ensure_read_permission::<P>(state, &cwd)?;
        return Ok(Some(cwd.to_string_lossy().to_string()));
      }
    }
  }
  Ok(None)
}

#[op]
fn op_require_try_self<P>(
  state: &mut OpState,
  parent_path: Option<String>,
  request: String,
) -> Result<Option<String>, AnyError>
where
  P: NodePermissions + 'static,
{
  if parent_path.is_none() {
    return Ok(None);
  }

  let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>().clone();
  let permissions = state.borrow_mut::<P>();
  let pkg = resolution::get_package_scope_config(
    &Url::from_file_path(parent_path.unwrap()).unwrap(),
    &*resolver,
    permissions,
  )
  .ok();
  if pkg.is_none() {
    return Ok(None);
  }

  let pkg = pkg.unwrap();
  if pkg.exports.is_none() {
    return Ok(None);
  }
  if pkg.name.is_none() {
    return Ok(None);
  }

  let pkg_name = pkg.name.as_ref().unwrap().to_string();
  let mut expansion = ".".to_string();

  if request == pkg_name {
    // pass
  } else if request.starts_with(&format!("{}/", pkg_name)) {
    expansion += &request[pkg_name.len()..];
  } else {
    return Ok(None);
  }

  let referrer = deno_core::url::Url::from_file_path(&pkg.path).unwrap();
  if let Some(exports) = &pkg.exports {
    resolution::package_exports_resolve(
      &pkg.path,
      expansion,
      exports,
      &referrer,
      NodeModuleKind::Cjs,
      resolution::REQUIRE_CONDITIONS,
      NodeResolutionMode::Execution,
      &*resolver,
      permissions,
    )
    .map(|r| Some(r.to_string_lossy().to_string()))
  } else {
    Ok(None)
  }
}

#[op]
fn op_require_read_file<P>(
  state: &mut OpState,
  file_path: String,
) -> Result<String, AnyError>
where
  P: NodePermissions + 'static,
{
  let file_path = PathBuf::from(file_path);
  ensure_read_permission::<P>(state, &file_path)?;
  Ok(std::fs::read_to_string(file_path)?)
}

#[op]
pub fn op_require_as_file_path(file_or_url: String) -> String {
  if let Ok(url) = Url::parse(&file_or_url) {
    if let Ok(p) = url.to_file_path() {
      return p.to_string_lossy().to_string();
    }
  }

  file_or_url
}

#[op]
fn op_require_resolve_exports<P>(
  state: &mut OpState,
  uses_local_node_modules_dir: bool,
  modules_path: String,
  _request: String,
  name: String,
  expansion: String,
  parent_path: String,
) -> Result<Option<String>, AnyError>
where
  P: NodePermissions + 'static,
{
  let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>().clone();
  let permissions = state.borrow_mut::<P>();

  let pkg_path = if resolver.in_npm_package(&PathBuf::from(&modules_path))
    && !uses_local_node_modules_dir
  {
    modules_path
  } else {
    path_resolve(vec![modules_path, name])
  };
  let pkg = PackageJson::load(
    &*resolver,
    permissions,
    PathBuf::from(&pkg_path).join("package.json"),
  )?;

  if let Some(exports) = &pkg.exports {
    let referrer = Url::from_file_path(parent_path).unwrap();
    resolution::package_exports_resolve(
      &pkg.path,
      format!(".{}", expansion),
      exports,
      &referrer,
      NodeModuleKind::Cjs,
      resolution::REQUIRE_CONDITIONS,
      NodeResolutionMode::Execution,
      &*resolver,
      permissions,
    )
    .map(|r| Some(r.to_string_lossy().to_string()))
  } else {
    Ok(None)
  }
}

#[op]
fn op_require_read_closest_package_json<P>(
  state: &mut OpState,
  filename: String,
) -> Result<PackageJson, AnyError>
where
  P: NodePermissions + 'static,
{
  ensure_read_permission::<P>(
    state,
    PathBuf::from(&filename).parent().unwrap(),
  )?;
  let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>().clone();
  let permissions = state.borrow_mut::<P>();
  resolution::get_closest_package_json(
    &Url::from_file_path(filename).unwrap(),
    &*resolver,
    permissions,
  )
}

#[op]
fn op_require_read_package_scope<P>(
  state: &mut OpState,
  package_json_path: String,
) -> Option<PackageJson>
where
  P: NodePermissions + 'static,
{
  let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>().clone();
  let permissions = state.borrow_mut::<P>();
  let package_json_path = PathBuf::from(package_json_path);
  PackageJson::load(&*resolver, permissions, package_json_path).ok()
}

#[op]
fn op_require_package_imports_resolve<P>(
  state: &mut OpState,
  parent_filename: String,
  request: String,
) -> Result<Option<String>, AnyError>
where
  P: NodePermissions + 'static,
{
  let parent_path = PathBuf::from(&parent_filename);
  ensure_read_permission::<P>(state, &parent_path)?;
  let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>().clone();
  let permissions = state.borrow_mut::<P>();
  let pkg = PackageJson::load(
    &*resolver,
    permissions,
    parent_path.join("package.json"),
  )?;

  if pkg.imports.is_some() {
    let referrer =
      deno_core::url::Url::from_file_path(&parent_filename).unwrap();
    let r = resolution::package_imports_resolve(
      &request,
      &referrer,
      NodeModuleKind::Cjs,
      resolution::REQUIRE_CONDITIONS,
      NodeResolutionMode::Execution,
      &*resolver,
      permissions,
    )
    .map(|r| Some(Url::from_file_path(r).unwrap().to_string()));
    state.put(resolver);
    r
  } else {
    Ok(None)
  }
}

#[op]
fn op_require_break_on_next_statement(state: &mut OpState) {
  let inspector = state.borrow::<Rc<RefCell<JsRuntimeInspector>>>();
  inspector
    .borrow_mut()
    .wait_for_session_and_break_on_next_statement()
}

pub struct NodeModulePolyfill {
  /// Name of the module like "assert" or "timers/promises"
  pub name: &'static str,

  /// Specifier relative to the root of `deno_std` repo, like "node/assert.ts"
  pub specifier: &'static str,
}

pub static SUPPORTED_BUILTIN_NODE_MODULES: &[NodeModulePolyfill] = &[
  NodeModulePolyfill {
    name: "assert",
    specifier: "node/assert.ts",
  },
  NodeModulePolyfill {
    name: "assert/strict",
    specifier: "node/assert/strict.ts",
  },
  NodeModulePolyfill {
    name: "async_hooks",
    specifier: "node/async_hooks.ts",
  },
  NodeModulePolyfill {
    name: "buffer",
    specifier: "node/buffer.ts",
  },
  NodeModulePolyfill {
    name: "child_process",
    specifier: "node/child_process.ts",
  },
  NodeModulePolyfill {
    name: "cluster",
    specifier: "node/cluster.ts",
  },
  NodeModulePolyfill {
    name: "console",
    specifier: "node/console.ts",
  },
  NodeModulePolyfill {
    name: "constants",
    specifier: "node/constants.ts",
  },
  NodeModulePolyfill {
    name: "crypto",
    specifier: "node/crypto.ts",
  },
  NodeModulePolyfill {
    name: "dgram",
    specifier: "node/dgram.ts",
  },
  NodeModulePolyfill {
    name: "dns",
    specifier: "node/dns.ts",
  },
  NodeModulePolyfill {
    name: "dns/promises",
    specifier: "node/dns/promises.ts",
  },
  NodeModulePolyfill {
    name: "domain",
    specifier: "node/domain.ts",
  },
  NodeModulePolyfill {
    name: "events",
    specifier: "node/events.ts",
  },
  NodeModulePolyfill {
    name: "fs",
    specifier: "node/fs.ts",
  },
  NodeModulePolyfill {
    name: "fs/promises",
    specifier: "node/fs/promises.ts",
  },
  NodeModulePolyfill {
    name: "http",
    specifier: "node/http.ts",
  },
  NodeModulePolyfill {
    name: "https",
    specifier: "node/https.ts",
  },
  NodeModulePolyfill {
    name: "module",
    // NOTE(bartlomieju): `module` is special, because we don't want to use
    // `deno_std/node/module.ts`, but instead use a special shim that we
    // provide in `ext/node`.
    specifier: "[USE `deno_node::MODULE_ES_SHIM` to get this module]",
  },
  NodeModulePolyfill {
    name: "net",
    specifier: "node/net.ts",
  },
  NodeModulePolyfill {
    name: "os",
    specifier: "node/os.ts",
  },
  NodeModulePolyfill {
    name: "path",
    specifier: "node/path.ts",
  },
  NodeModulePolyfill {
    name: "path/posix",
    specifier: "node/path/posix.ts",
  },
  NodeModulePolyfill {
    name: "path/win32",
    specifier: "node/path/win32.ts",
  },
  NodeModulePolyfill {
    name: "perf_hooks",
    specifier: "node/perf_hooks.ts",
  },
  NodeModulePolyfill {
    name: "process",
    specifier: "node/process.ts",
  },
  NodeModulePolyfill {
    name: "querystring",
    specifier: "node/querystring.ts",
  },
  NodeModulePolyfill {
    name: "readline",
    specifier: "node/readline.ts",
  },
  NodeModulePolyfill {
    name: "stream",
    specifier: "node/stream.ts",
  },
  NodeModulePolyfill {
    name: "stream/consumers",
    specifier: "node/stream/consumers.mjs",
  },
  NodeModulePolyfill {
    name: "stream/promises",
    specifier: "node/stream/promises.mjs",
  },
  NodeModulePolyfill {
    name: "stream/web",
    specifier: "node/stream/web.ts",
  },
  NodeModulePolyfill {
    name: "string_decoder",
    specifier: "node/string_decoder.ts",
  },
  NodeModulePolyfill {
    name: "sys",
    specifier: "node/sys.ts",
  },
  NodeModulePolyfill {
    name: "timers",
    specifier: "node/timers.ts",
  },
  NodeModulePolyfill {
    name: "timers/promises",
    specifier: "node/timers/promises.ts",
  },
  NodeModulePolyfill {
    name: "tls",
    specifier: "node/tls.ts",
  },
  NodeModulePolyfill {
    name: "tty",
    specifier: "node/tty.ts",
  },
  NodeModulePolyfill {
    name: "url",
    specifier: "node/url.ts",
  },
  NodeModulePolyfill {
    name: "util",
    specifier: "node/util.ts",
  },
  NodeModulePolyfill {
    name: "util/types",
    specifier: "node/util/types.ts",
  },
  NodeModulePolyfill {
    name: "v8",
    specifier: "node/v8.ts",
  },
  NodeModulePolyfill {
    name: "vm",
    specifier: "node/vm.ts",
  },
  NodeModulePolyfill {
    name: "worker_threads",
    specifier: "node/worker_threads.ts",
  },
  NodeModulePolyfill {
    name: "zlib",
    specifier: "node/zlib.ts",
  },
];