1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

Normalize windows paths.

Add resolve_module test
This commit is contained in:
Ryan Dahl 2018-08-23 03:58:59 -04:00
parent e2f9b0e6fd
commit ecb955929f
3 changed files with 31 additions and 27 deletions

View file

@ -250,29 +250,15 @@ impl DenoDir {
match j.scheme() {
"file" => {
let mut p = j
.to_file_path()
.unwrap()
.into_os_string()
.into_string()
.unwrap();
if cfg!(target_os = "windows") {
// On windows, replace backward slashes to forward slashes.
// TODO(piscisaureus): This may not me be right, I just did it to make
// the tests pass.
p = p.replace("\\", "/");
}
module_name = p.to_string();
filename = p.to_string();
let mut p = fs::normalize_path(j.to_file_path().unwrap().as_ref());
module_name = p.clone();
filename = p;
}
_ => {
module_name = module_specifier.to_string();
filename = get_cache_filename(self.deps.as_path(), j)
.to_str()
.unwrap()
.to_string();
filename = fs::normalize_path(
get_cache_filename(self.deps.as_path(), j).as_ref(),
)
}
}
@ -422,6 +408,13 @@ fn test_src_file_to_url() {
fn test_resolve_module() {
let (_temp_dir, deno_dir) = test_setup();
let d = fs::normalize_path(
deno_dir
.deps
.join("localhost/testdata/subdir/print_hello.ts")
.as_ref(),
);
let test_cases = [
(
"./subdir/print_hello.ts",
@ -453,13 +446,13 @@ fn test_resolve_module() {
add_root!("/this/module/got/imported.js"),
add_root!("/this/module/got/imported.js"),
),
(
"http://localhost:4545/testdata/subdir/print_hello.ts",
add_root!("/Users/rld/go/src/github.com/denoland/deno/testdata/006_url_imports.ts"),
"http://localhost:4545/testdata/subdir/print_hello.ts",
d.as_ref(),
),
/*
(
"http://localhost:4545/testdata/subdir/print_hello.ts",
add_root!("/Users/rld/go/src/github.com/denoland/deno/testdata/006_url_imports.ts"),
"http://localhost:4545/testdata/subdir/print_hello.ts",
path.Join(SrcDir, "localhost:4545/testdata/subdir/print_hello.ts"),
),
(
path.Join(SrcDir, "unpkg.com/liltest@0.0.5/index.ts"),
".",

View file

@ -34,3 +34,13 @@ pub fn mkdir(path: &Path) -> std::io::Result<()> {
}
})
}
pub fn normalize_path(path: &Path) -> String {
let s = String::from(path.to_str().unwrap());
if cfg!(windows) {
// TODO This isn't correct. Probbly should iterate over components.
s.replace("\\", "/")
} else {
s
}
}

View file

@ -127,7 +127,8 @@ fn handle_start(
let argv_off = builder.create_vector_of_strings(argv.as_slice());
let cwd_path = std::env::current_dir().unwrap();
let cwd_off = builder.create_string(cwd_path.to_str().unwrap());
let cwd_off =
builder.create_string(fs::normalize_path(cwd_path.as_ref()).as_ref());
let msg = msg::StartRes::create(
builder,