-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into feat/lyy_unused_spe…
…cifier
- Loading branch information
Showing
40 changed files
with
324 additions
and
136 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
|
@@ -88,7 +88,19 @@ lazy_static! { | |
impl File { | ||
pub fn new(path: String, context: Arc<Context>) -> Self { | ||
let path = PathBuf::from(path); | ||
let (pathname, search, params, fragment) = parse_path(&path.to_string_lossy()).unwrap(); | ||
// if path exists, it has no search and fragment | ||
// support ./a#b.ts when a#b.ts is a real file | ||
// e.g. https://unpkg.com/browse/[email protected]/string/ | ||
let (pathname, search, params, fragment) = if path.exists() { | ||
( | ||
path.to_string_lossy().to_string(), | ||
"".to_string(), | ||
vec![], | ||
None, | ||
) | ||
} else { | ||
parse_path(&path.to_string_lossy()).unwrap() | ||
}; | ||
let pathname = PathBuf::from(pathname); | ||
let is_virtual = path.starts_with(&*VIRTUAL) || | ||
// TODO: remove this specific logic | ||
|
@@ -178,15 +190,15 @@ impl File { | |
} | ||
|
||
pub fn get_file_size(&self) -> Result<u64> { | ||
let metadata = std::fs::metadata(&self.path)?; | ||
let metadata = std::fs::metadata(&self.pathname)?; | ||
Ok(metadata.len()) | ||
} | ||
|
||
pub fn get_base64(&self) -> Result<String> { | ||
let content = std::fs::read(&self.path)?; | ||
let content = std::fs::read(&self.pathname)?; | ||
let engine = engine::GeneralPurpose::new(&STANDARD, engine::general_purpose::PAD); | ||
let content = engine.encode(content); | ||
let guess = mime_guess::from_path(&self.path); | ||
let guess = mime_guess::from_path(&self.pathname); | ||
if let Some(mime) = guess.first() { | ||
Ok(format!( | ||
"data:{};base64,{}", | ||
|
@@ -201,7 +213,7 @@ impl File { | |
} | ||
|
||
pub fn get_content_hash(&self) -> Result<String> { | ||
let file = std::fs::File::open(&self.path)?; | ||
let file = std::fs::File::open(&self.pathname)?; | ||
let len = file.metadata()?.len(); | ||
// Decide on a reasonable buffer size (1MB in this case, fastest will depend on hardware) | ||
let buf_len = len.min(1_000_000) as usize; | ||
|
This file contains 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 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 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 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 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 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 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 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 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
Oops, something went wrong.