summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/node.rs2
-rw-r--r--cli/resolver.rs7
-rw-r--r--cli/util/gitignore.rs2
3 files changed, 8 insertions, 3 deletions
diff --git a/cli/node.rs b/cli/node.rs
index c696fcac9..5ecbacdc7 100644
--- a/cli/node.rs
+++ b/cli/node.rs
@@ -125,7 +125,7 @@ impl CjsCodeAnalyzer for CliCjsCodeAnalyzer {
None => {
self
.fs
- .read_text_file_async(specifier.to_file_path().unwrap(), None)
+ .read_text_file_lossy_async(specifier.to_file_path().unwrap(), None)
.await?
}
};
diff --git a/cli/resolver.rs b/cli/resolver.rs
index 301cd0666..3edc6f429 100644
--- a/cli/resolver.rs
+++ b/cli/resolver.rs
@@ -320,7 +320,12 @@ impl NpmModuleLoader {
let code = if self.cjs_resolutions.contains(specifier) {
// translate cjs to esm if it's cjs and inject node globals
- let code = String::from_utf8(code)?;
+ let code = match String::from_utf8_lossy(&code) {
+ Cow::Owned(code) => code,
+ // SAFETY: `String::from_utf8_lossy` guarantees that the result is valid
+ // UTF-8 if `Cow::Borrowed` is returned.
+ Cow::Borrowed(_) => unsafe { String::from_utf8_unchecked(code) },
+ };
ModuleSourceCode::String(
self
.node_code_translator
diff --git a/cli/util/gitignore.rs b/cli/util/gitignore.rs
index 12a450d64..4538e0912 100644
--- a/cli/util/gitignore.rs
+++ b/cli/util/gitignore.rs
@@ -105,7 +105,7 @@ impl GitIgnoreTree {
});
let current = self
.fs
- .read_text_file_sync(&dir_path.join(".gitignore"), None)
+ .read_text_file_lossy_sync(&dir_path.join(".gitignore"), None)
.ok()
.and_then(|text| {
let mut builder = ignore::gitignore::GitignoreBuilder::new(dir_path);