From 9b1997b8b6f82e17e42c43aae3621e2b932f5843 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Mon, 8 Jul 2019 09:55:24 +0200 Subject: core: clearly define when module lookup is path-based vs URL-based The rules are now as follows: * In `import` statements, as mandated by the WHATWG specification, the import specifier is always treated as a URL. If it is a relative URL, it must start with either / or ./ or ../ * A script name passed to deno as a command line argument may be either an absolute URL or a local path. - If the name starts with a valid URI scheme followed by a colon, e.g. 'http:', 'https:', 'file:', 'foo+bar:', it always interpreted as a URL (even if Deno doesn't support the indicated protocol). - Otherwise, the script name is interpreted as a local path. The local path may be relative, and operating system semantics determine how it is resolved. Prefixing a relative path with ./ is not required. --- cli/worker.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'cli/worker.rs') diff --git a/cli/worker.rs b/cli/worker.rs index 65da666e8..1cf38e295 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -141,7 +141,7 @@ mod tests { #[test] fn execute_mod_esm_imports_a() { let module_specifier = - ModuleSpecifier::resolve_root("tests/esm_imports_a.js").unwrap(); + ModuleSpecifier::resolve_url_or_path("tests/esm_imports_a.js").unwrap(); let argv = vec![String::from("./deno"), module_specifier.to_string()]; let state = ThreadSafeState::new( flags::DenoFlags::default(), @@ -169,7 +169,7 @@ mod tests { #[test] fn execute_mod_circular() { let module_specifier = - ModuleSpecifier::resolve_root("tests/circular1.js").unwrap(); + ModuleSpecifier::resolve_url_or_path("tests/circular1.js").unwrap(); let argv = vec![String::from("./deno"), module_specifier.to_string()]; let state = ThreadSafeState::new( flags::DenoFlags::default(), @@ -197,7 +197,7 @@ mod tests { #[test] fn execute_006_url_imports() { let module_specifier = - ModuleSpecifier::resolve_root("tests/006_url_imports.ts").unwrap(); + ModuleSpecifier::resolve_url_or_path("tests/006_url_imports.ts").unwrap(); let argv = vec![String::from("deno"), module_specifier.to_string()]; let mut flags = flags::DenoFlags::default(); flags.reload = true; @@ -327,7 +327,7 @@ mod tests { // "foo" is not a valid module specifier so this should return an error. let mut worker = create_test_worker(); let module_specifier = - ModuleSpecifier::resolve_root("does-not-exist").unwrap(); + ModuleSpecifier::resolve_url_or_path("does-not-exist").unwrap(); let result = worker.execute_mod_async(&module_specifier, false).wait(); assert!(result.is_err()); }) @@ -340,7 +340,7 @@ mod tests { // tests). let mut worker = create_test_worker(); let module_specifier = - ModuleSpecifier::resolve_root("./tests/002_hello.ts").unwrap(); + ModuleSpecifier::resolve_url_or_path("./tests/002_hello.ts").unwrap(); let result = worker.execute_mod_async(&module_specifier, false).wait(); assert!(result.is_ok()); }) -- cgit v1.2.3