summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/compat/esm_resolver.rs2
-rw-r--r--cli/compat/mod.rs9
-rw-r--r--cli/tests/integration/compat_tests.rs17
3 files changed, 24 insertions, 4 deletions
diff --git a/cli/compat/esm_resolver.rs b/cli/compat/esm_resolver.rs
index c0366c27b..49b0bb9e6 100644
--- a/cli/compat/esm_resolver.rs
+++ b/cli/compat/esm_resolver.rs
@@ -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",
));
}
diff --git a/cli/compat/mod.rs b/cli/compat/mod.rs
index b95b65ddb..ad820c14c 100644
--- a/cli/compat/mod.rs
+++ b/cli/compat/mod.rs
@@ -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
diff --git a/cli/tests/integration/compat_tests.rs b/cli/tests/integration/compat_tests.rs
index 17388a78e..2886056ec 100644
--- a/cli/tests/integration/compat_tests.rs
+++ b/cli/tests/integration/compat_tests.rs
@@ -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"));
+}