Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compat: add DENO_NODE_COMPAT_URL env variable #12508

Merged
merged 5 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/compat/esm_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
));
}
Expand Down
9 changes: 6 additions & 3 deletions cli/compat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions cli/tests/integration/compat_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}