1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

compat: add DENO_NODE_COMPAT_URL env variable (#12508)

This commit is contained in:
Bartek Iwańczuk 2021-10-21 00:23:57 +02:00 committed by GitHub
parent 46bc1175e5
commit 8a0e206ede
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 4 deletions

View file

@ -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",
));
}

View file

@ -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

View file

@ -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"));
}