diff --git a/cli/main.rs b/cli/main.rs index 05748f5ab19535..525ab20c658b5d 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -200,6 +200,7 @@ fn fetch_or_info_command( let main_future = lazy(move || { // Setup runtime. js_check(worker.execute("denoMain()")); + println!("main_module {}", main_module); debug!("main_module {}", main_module); worker diff --git a/core/module_specifier.rs b/core/module_specifier.rs index 1bdd5beee2b4ea..24db3cbc32fb5f 100644 --- a/core/module_specifier.rs +++ b/core/module_specifier.rs @@ -1,6 +1,19 @@ use std::fmt; +use std::path::PathBuf; use url::Url; +//fn normalize_path(path: &Path) -> PathBuf { +// let s = String::from(path.to_str().unwrap()); +// let normalized_string = if cfg!(windows) { +// // TODO This isn't correct. Probbly should iterate over components. +// s.replace("\\", "/") +// } else { +// s +// }; +// +// PathBuf::from(normalized_string) +//} + #[derive(Debug, Clone, PartialEq)] /// Resolved module specifier pub struct ModuleSpecifier(Url); @@ -52,12 +65,23 @@ impl ModuleSpecifier { pub fn resolve_root( root_specifier: &str, ) -> Result { + // println!("root specifier {}", root_specifier); + let path = PathBuf::from(root_specifier); + // println!("file path {:?}", path); + + if let Ok(url) = Url::from_file_path(&path) { + // println!("from file path {:?}", url); + return Ok(ModuleSpecifier(url)); + } + if let Ok(url) = Url::parse(root_specifier) { + // println!("url parse was successful {:?}", url); Ok(ModuleSpecifier(url)) } else { let cwd = std::env::current_dir().unwrap(); let base = Url::from_directory_path(cwd).unwrap(); let url = base.join(root_specifier)?; + // println!("from apth {:?}", url); Ok(ModuleSpecifier(url)) } } @@ -80,3 +104,34 @@ impl PartialEq for ModuleSpecifier { &self.to_string() == other } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn absolute_file_path() { + if cfg!(target_os = "windows") { + assert_eq!( + ModuleSpecifier::resolve_root(r"C:/deno/tests/006_url_imports.ts") + .unwrap() + .to_string(), + "file:///c:/deno/tests/006_url_imports.ts", + ); + } else { + assert_eq!( + ModuleSpecifier::resolve_root("/deno/tests/006_url_imports.ts") + .unwrap() + .to_string(), + "file:///deno/tests/006_url_imports.ts", + ); + } + assert_eq!( + ModuleSpecifier::resolve_root( + "http://deno.land/core/tests/006_url_imports.ts" + ).unwrap() + .to_string(), + "http://deno.land/core/tests/006_url_imports.ts", + ); + } +} diff --git a/tools/fetch_test.py b/tools/fetch_test.py index b4bf1836c95e1f..459c8a7456dd9b 100755 --- a/tools/fetch_test.py +++ b/tools/fetch_test.py @@ -14,9 +14,11 @@ def test_fetch(self): deno_dir = mkdtemp() try: t = os.path.join(tests_path, "006_url_imports.ts") - result = run_output([self.deno_exe, "fetch", t], - quiet=True, - merge_env={"DENO_DIR": deno_dir}) + result = run_output( + [self.deno_exe, "fetch", t], + # quiet=True, + merge_env={"DENO_DIR": deno_dir}) + print "test_fetch", result.code, result.out, result.err self.assertEqual(result.out, "") self.assertEqual(result.code, 0) # Check that we actually did the prefetch. diff --git a/tools/target_test.py b/tools/target_test.py index 98eb4a0eb8146a..18027bd1ed54d1 100644 --- a/tools/target_test.py +++ b/tools/target_test.py @@ -46,9 +46,12 @@ def test_ts_library_builder(self): def test_no_color(self): t = os.path.join(tests_path, "no_color.js") - result = run_output([self.deno_exe, "run", t], - merge_env={"NO_COLOR": "1"}, - quiet=True) + result = run_output( + [self.deno_exe, "run", t], + merge_env={"NO_COLOR": "1"}, + # quiet=True + ) + print "no_color", result.code, result.out, result.err assert result.out.strip() == "noColor true" t = os.path.join(tests_path, "no_color.js") result = run_output([self.deno_exe, "run", t], quiet=True)