-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Reorganize $DENO_DIR/deps folder and split by protocol #971
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,9 @@ pub struct DenoDir { | |
// This is where we cache compilation outputs. Example: | ||
// /Users/rld/.deno/gen/f39a473452321cacd7c346a870efb0e3e1264b43.js | ||
pub deps: PathBuf, | ||
// This splits to http and https deps | ||
pub deps_http: PathBuf, | ||
pub deps_https: PathBuf, | ||
// If remote resources should be reloaded. | ||
reload: bool, | ||
} | ||
|
@@ -49,19 +52,27 @@ impl DenoDir { | |
}; | ||
let gen = root.as_path().join("gen"); | ||
let deps = root.as_path().join("deps"); | ||
let deps_http = deps.join("http"); | ||
let deps_https = deps.join("https"); | ||
|
||
let deno_dir = DenoDir { | ||
root, | ||
gen, | ||
deps, | ||
deps_http, | ||
deps_https, | ||
reload, | ||
}; | ||
deno_fs::mkdir(deno_dir.gen.as_ref(), 0o755)?; | ||
deno_fs::mkdir(deno_dir.deps.as_ref(), 0o755)?; | ||
deno_fs::mkdir(deno_dir.deps_http.as_ref(), 0o755)?; | ||
deno_fs::mkdir(deno_dir.deps_https.as_ref(), 0o755)?; | ||
|
||
debug!("root {}", deno_dir.root.display()); | ||
debug!("gen {}", deno_dir.gen.display()); | ||
debug!("deps {}", deno_dir.deps.display()); | ||
debug!("deps_http {}", deno_dir.deps_http.display()); | ||
debug!("deps_https {}", deno_dir.deps_https.display()); | ||
|
||
Ok(deno_dir) | ||
} | ||
|
@@ -225,13 +236,22 @@ impl DenoDir { | |
fn src_file_to_url(self: &DenoDir, filename: &str) -> String { | ||
let filename_path = Path::new(filename); | ||
if filename_path.starts_with(&self.deps) { | ||
let rest = filename_path.strip_prefix(&self.deps).unwrap(); | ||
let (rest, prefix) = if filename_path.starts_with(&self.deps_https) { | ||
let rest = filename_path.strip_prefix(&self.deps_https).unwrap(); | ||
let prefix = "https://".to_string(); | ||
(rest, prefix) | ||
} else { | ||
// TODO(kevinkassimo): change this to support other protocols than http | ||
let rest = filename_path.strip_prefix(&self.deps_http).unwrap(); | ||
let prefix = "http://".to_string(); | ||
(rest, prefix) | ||
}; | ||
// Windows doesn't support ":" in filenames, so we represent port using a | ||
// special string. | ||
// TODO(ry) This current implementation will break on a URL that has | ||
// the default port but contains "_PORT" in the path. | ||
let rest = rest.to_str().unwrap().replacen("_PORT", ":", 1); | ||
"http://".to_string() + &rest | ||
prefix + &rest | ||
} else { | ||
String::from(filename) | ||
} | ||
|
@@ -279,10 +299,17 @@ impl DenoDir { | |
module_name = p.clone(); | ||
filename = p; | ||
} | ||
"https" => { | ||
module_name = j.to_string(); | ||
filename = deno_fs::normalize_path( | ||
get_cache_filename(self.deps_https.as_path(), j).as_ref(), | ||
) | ||
} | ||
// TODO(kevinkassimo): change this to support other protocols than http | ||
_ => { | ||
module_name = j.to_string(); | ||
filename = deno_fs::normalize_path( | ||
get_cache_filename(self.deps.as_path(), j).as_ref(), | ||
get_cache_filename(self.deps_http.as_path(), j).as_ref(), | ||
) | ||
} | ||
} | ||
|
@@ -480,7 +507,7 @@ fn test_src_file_to_url_1() { | |
let (_temp_dir, deno_dir) = test_setup(); | ||
assert_eq!("hello", deno_dir.src_file_to_url("hello")); | ||
assert_eq!("/hello", deno_dir.src_file_to_url("/hello")); | ||
let x = deno_dir.deps.join("hello/world.txt"); | ||
let x = deno_dir.deps_http.join("hello/world.txt"); | ||
assert_eq!( | ||
"http://hello/world.txt", | ||
deno_dir.src_file_to_url(x.to_str().unwrap()) | ||
|
@@ -490,13 +517,35 @@ fn test_src_file_to_url_1() { | |
#[test] | ||
fn test_src_file_to_url_2() { | ||
let (_temp_dir, deno_dir) = test_setup(); | ||
let x = deno_dir.deps.join("localhost_PORT4545/world.txt"); | ||
assert_eq!("hello", deno_dir.src_file_to_url("hello")); | ||
assert_eq!("/hello", deno_dir.src_file_to_url("/hello")); | ||
let x = deno_dir.deps_https.join("hello/world.txt"); | ||
assert_eq!( | ||
"https://hello/world.txt", | ||
deno_dir.src_file_to_url(x.to_str().unwrap()) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_src_file_to_url_3() { | ||
let (_temp_dir, deno_dir) = test_setup(); | ||
let x = deno_dir.deps_http.join("localhost_PORT4545/world.txt"); | ||
assert_eq!( | ||
"http://localhost:4545/world.txt", | ||
deno_dir.src_file_to_url(x.to_str().unwrap()) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_src_file_to_url_4() { | ||
let (_temp_dir, deno_dir) = test_setup(); | ||
let x = deno_dir.deps_https.join("localhost_PORT4545/world.txt"); | ||
assert_eq!( | ||
"https://localhost:4545/world.txt", | ||
deno_dir.src_file_to_url(x.to_str().unwrap()) | ||
); | ||
} | ||
|
||
// https://github.com/denoland/deno/blob/golang/os_test.go#L16-L87 | ||
#[test] | ||
fn test_resolve_module_1() { | ||
|
@@ -556,7 +605,7 @@ fn test_resolve_module_2() { | |
"http://localhost:4545/testdata/subdir/print_hello.ts"; | ||
let expected_filename = deno_fs::normalize_path( | ||
deno_dir | ||
.deps | ||
.deps_http | ||
.join("localhost_PORT4545/testdata/subdir/print_hello.ts") | ||
.as_ref(), | ||
); | ||
|
@@ -573,14 +622,14 @@ fn test_resolve_module_3() { | |
let (_temp_dir, deno_dir) = test_setup(); | ||
|
||
let module_specifier_ = | ||
deno_dir.deps.join("unpkg.com/[email protected]/index.ts"); | ||
deno_dir.deps_http.join("unpkg.com/[email protected]/index.ts"); | ||
let module_specifier = module_specifier_.to_str().unwrap(); | ||
let containing_file = "."; | ||
|
||
let expected_module_name = "http://unpkg.com/[email protected]/index.ts"; | ||
let expected_filename = deno_fs::normalize_path( | ||
deno_dir | ||
.deps | ||
.deps_http | ||
.join("unpkg.com/[email protected]/index.ts") | ||
.as_ref(), | ||
); | ||
|
@@ -597,12 +646,17 @@ fn test_resolve_module_4() { | |
let (_temp_dir, deno_dir) = test_setup(); | ||
|
||
let module_specifier = "./util"; | ||
let containing_file_ = deno_dir.deps.join("unpkg.com/[email protected]/index.ts"); | ||
let containing_file_ = | ||
deno_dir.deps_http.join("unpkg.com/[email protected]/index.ts"); | ||
let containing_file = containing_file_.to_str().unwrap(); | ||
|
||
// http containing files -> load relative import with http | ||
let expected_module_name = "http://unpkg.com/[email protected]/util"; | ||
let expected_filename = deno_fs::normalize_path( | ||
deno_dir.deps.join("unpkg.com/[email protected]/util").as_ref(), | ||
deno_dir | ||
.deps_http | ||
.join("unpkg.com/[email protected]/util") | ||
.as_ref(), | ||
); | ||
|
||
let (module_name, filename) = deno_dir | ||
|
@@ -616,12 +670,37 @@ fn test_resolve_module_4() { | |
fn test_resolve_module_5() { | ||
let (_temp_dir, deno_dir) = test_setup(); | ||
|
||
let module_specifier = "./util"; | ||
let containing_file_ = | ||
deno_dir.deps_https.join("unpkg.com/[email protected]/index.ts"); | ||
let containing_file = containing_file_.to_str().unwrap(); | ||
|
||
// https containing files -> load relative import with https | ||
let expected_module_name = "https://unpkg.com/[email protected]/util"; | ||
let expected_filename = deno_fs::normalize_path( | ||
deno_dir | ||
.deps_https | ||
.join("unpkg.com/[email protected]/util") | ||
.as_ref(), | ||
); | ||
|
||
let (module_name, filename) = deno_dir | ||
.resolve_module(module_specifier, containing_file) | ||
.unwrap(); | ||
assert_eq!(module_name, expected_module_name); | ||
assert_eq!(filename, expected_filename); | ||
} | ||
|
||
#[test] | ||
fn test_resolve_module_6() { | ||
let (_temp_dir, deno_dir) = test_setup(); | ||
|
||
let module_specifier = "http://localhost:4545/tests/subdir/mod2.ts"; | ||
let containing_file = add_root!("/deno/tests/006_url_imports.ts"); | ||
let expected_module_name = "http://localhost:4545/tests/subdir/mod2.ts"; | ||
let expected_filename = deno_fs::normalize_path( | ||
deno_dir | ||
.deps | ||
.deps_http | ||
.join("localhost_PORT4545/tests/subdir/mod2.ts") | ||
.as_ref(), | ||
); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps should do:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.