1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

cli: generate default file name for bundle when URL ends in a slash

This commit is contained in:
Bert Belder 2019-07-08 23:05:00 +02:00
parent f4c9b31405
commit afd66bb010
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461

View file

@ -632,7 +632,7 @@ pub enum DenoSubcommand {
fn get_default_bundle_filename(source_file: &str) -> String { fn get_default_bundle_filename(source_file: &str) -> String {
let specifier = ModuleSpecifier::resolve_url_or_path(source_file).unwrap(); let specifier = ModuleSpecifier::resolve_url_or_path(source_file).unwrap();
let path_segments = specifier.as_url().path_segments().unwrap(); let path_segments = specifier.as_url().path_segments().unwrap();
let file_name = path_segments.last().unwrap(); let file_name = path_segments.filter(|s| !s.is_empty()).last().unwrap();
let file_stem = file_name.trim_end_matches(".ts").trim_end_matches(".js"); let file_stem = file_name.trim_end_matches(".ts").trim_end_matches(".js");
format!("{}.bundle.js", file_stem) format!("{}.bundle.js", file_stem)
} }
@ -649,6 +649,10 @@ fn test_get_default_bundle_filename() {
get_default_bundle_filename("http://example.com/blah.js"), get_default_bundle_filename("http://example.com/blah.js"),
"blah.bundle.js" "blah.bundle.js"
); );
assert_eq!(
get_default_bundle_filename("http://zombo.com/stuff/"),
"stuff.bundle.js"
);
} }
pub fn flags_from_vec( pub fn flags_from_vec(