perf(compile): read embedded files as static references when UTF-8 and reading as strings (#27033)

This commit is contained in:
David Sherret 2024-11-27 21:28:41 -05:00 committed by GitHub
parent 76daa03aa9
commit f161adf19e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 158 additions and 61 deletions

View file

@ -157,7 +157,10 @@ pub trait NodeRequireLoader {
path: &'a Path,
) -> Result<Cow<'a, Path>, AnyError>;
fn load_text_file_lossy(&self, path: &Path) -> Result<String, AnyError>;
fn load_text_file_lossy(
&self,
path: &Path,
) -> Result<Cow<'static, str>, AnyError>;
/// Get if the module kind is maybe CJS and loading should determine
/// if its CJS or ESM.
@ -873,6 +876,8 @@ impl deno_package_json::fs::DenoPkgJsonFs for DenoFsNodeResolverEnv {
self
.fs
.read_text_file_lossy_sync(path, None)
// todo(https://github.com/denoland/deno_package_json/pull/9): don't clone
.map(|text| text.into_owned())
.map_err(|err| err.into_io_error())
}
}
@ -887,6 +892,8 @@ impl<'a> deno_package_json::fs::DenoPkgJsonFs for DenoPkgJsonFsAdapter<'a> {
self
.0
.read_text_file_lossy_sync(path, None)
// todo(https://github.com/denoland/deno_package_json/pull/9): don't clone
.map(|text| text.into_owned())
.map_err(|err| err.into_io_error())
}
}