mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
compat: add DENO_NODE_COMPAT_URL env variable (#12508)
This commit is contained in:
parent
46bc1175e5
commit
8a0e206ede
3 changed files with 24 additions and 4 deletions
|
@ -198,7 +198,7 @@ fn finalize_resolution(
|
|||
} else if !is_file {
|
||||
return Err(errors::err_module_not_found(
|
||||
&path.display().to_string(),
|
||||
&to_file_path_string(base),
|
||||
base.as_str(),
|
||||
"module",
|
||||
));
|
||||
}
|
||||
|
|
|
@ -62,9 +62,11 @@ static SUPPORTED_MODULES: &[&str] = &[
|
|||
];
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref GLOBAL_URL_STR: String = format!("{}node/global.ts", STD_URL_STR);
|
||||
static ref NODE_COMPAT_URL: String = std::env::var("DENO_NODE_COMPAT_URL").map(String::into).ok()
|
||||
.unwrap_or_else(|| STD_URL_STR.to_string());
|
||||
static ref GLOBAL_URL_STR: String = format!("{}node/global.ts", NODE_COMPAT_URL.as_str());
|
||||
pub(crate) static ref GLOBAL_URL: Url = Url::parse(&GLOBAL_URL_STR).unwrap();
|
||||
static ref MODULE_URL_STR: String = format!("{}node/module.ts", STD_URL_STR);
|
||||
static ref MODULE_URL_STR: String = format!("{}node/module.ts", NODE_COMPAT_URL.as_str());
|
||||
pub(crate) static ref MODULE_URL: Url = Url::parse(&MODULE_URL_STR).unwrap();
|
||||
static ref COMPAT_IMPORT_URL: Url = Url::parse("flags:compat").unwrap();
|
||||
}
|
||||
|
@ -76,7 +78,8 @@ pub(crate) fn get_node_imports() -> Vec<(Url, Vec<String>)> {
|
|||
|
||||
fn try_resolve_builtin_module(specifier: &str) -> Option<Url> {
|
||||
if SUPPORTED_MODULES.contains(&specifier) {
|
||||
let module_url = format!("{}node/{}.ts", STD_URL_STR, specifier);
|
||||
let module_url =
|
||||
format!("{}node/{}.ts", NODE_COMPAT_URL.as_str(), specifier);
|
||||
Some(Url::parse(&module_url).unwrap())
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -29,3 +29,20 @@ fn globals_in_repl() {
|
|||
);
|
||||
assert!(out.contains("true"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn node_compat_url() {
|
||||
let (out, err) = util::run_and_collect_output_with_args(
|
||||
false,
|
||||
vec!["repl", "--compat", "--unstable", "--quiet"],
|
||||
None,
|
||||
Some(vec![(
|
||||
"DENO_NODE_COMPAT_URL".to_string(),
|
||||
"file:///non_existent/".to_string(),
|
||||
)]),
|
||||
false,
|
||||
);
|
||||
assert!(out.is_empty());
|
||||
assert!(!err.is_empty());
|
||||
assert!(err.contains("file:///non_existent/node/global.ts"));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue