diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-04-21 21:02:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-21 21:02:46 -0400 |
commit | a615eb3b56545960ec9684991442dd34a8b2abfc (patch) | |
tree | 05e134487fd3e8aadfe513a70ee246c95633fa34 /ext/node/polyfill.rs | |
parent | 779d379c68d1489cc01f6a2bfbcf677e08ca6d40 (diff) |
refactor(node): move most of cli/node to ext/node (#18797)
This is just a straight refactor and I didn't do any cleanup in
ext/node. After this PR we can start to clean it up and make things
private that don't need to be public anymore.
Diffstat (limited to 'ext/node/polyfill.rs')
-rw-r--r-- | ext/node/polyfill.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/ext/node/polyfill.rs b/ext/node/polyfill.rs index 1fbb4afa3..b334d2d34 100644 --- a/ext/node/polyfill.rs +++ b/ext/node/polyfill.rs @@ -1,8 +1,22 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -pub fn find_builtin_node_module( - module_name: &str, -) -> Option<&NodeModulePolyfill> { +use deno_core::error::generic_error; +use deno_core::error::AnyError; +use deno_core::url::Url; +use deno_core::ModuleSpecifier; + +// TODO(bartlomieju): seems super wasteful to parse the specifier each time +pub fn resolve_builtin_node_module(module_name: &str) -> Result<Url, AnyError> { + if let Some(module) = find_builtin_node_module(module_name) { + return Ok(ModuleSpecifier::parse(module.specifier).unwrap()); + } + + Err(generic_error(format!( + "Unknown built-in \"node:\" module: {module_name}" + ))) +} + +fn find_builtin_node_module(module_name: &str) -> Option<&NodeModulePolyfill> { SUPPORTED_BUILTIN_NODE_MODULES .iter() .find(|m| m.name == module_name) |