diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-12-14 16:09:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-14 15:09:05 +0000 |
commit | ac04787c30b67ba9c7fb800eae8361ba419e7f4e (patch) | |
tree | 0260d7b5ac0c94c1ec1220813c16ef9318be102e /ext/node/polyfill.rs | |
parent | 19d52b9a55a6d5a67f27cbcc6cbe9c6c15865d63 (diff) |
fix(node): support resolving a package.json import to a builtin node module (#21576)
Closes https://github.com/denoland/deno/issues/21501
Diffstat (limited to 'ext/node/polyfill.rs')
-rw-r--r-- | ext/node/polyfill.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ext/node/polyfill.rs b/ext/node/polyfill.rs index 7772e3a16..a4c87bef7 100644 --- a/ext/node/polyfill.rs +++ b/ext/node/polyfill.rs @@ -1,5 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use deno_core::ModuleSpecifier; + /// e.g. `is_builtin_node_module("assert")` pub fn is_builtin_node_module(module_name: &str) -> bool { SUPPORTED_BUILTIN_NODE_MODULES @@ -7,6 +9,18 @@ pub fn is_builtin_node_module(module_name: &str) -> bool { .any(|m| *m == module_name) } +/// Ex. returns `fs` for `node:fs` +pub fn get_module_name_from_builtin_node_module_specifier( + specifier: &ModuleSpecifier, +) -> Option<&str> { + if specifier.scheme() != "node" { + return None; + } + + let (_, specifier) = specifier.as_str().split_once(':')?; + Some(specifier) +} + macro_rules! generate_builtin_node_module_lists { ($( $module_name:literal ,)+) => { pub static SUPPORTED_BUILTIN_NODE_MODULES: &[&str] = &[ |