mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 18:38:33 +00:00
refactor(ext/node): allow injecting NodeFs
from CLI (#18829)
This allows providing a `NodeFs` as part of the `WorkerOptions`.
This commit is contained in:
parent
bb74e75a04
commit
aa286fdecb
24 changed files with 1631 additions and 1687 deletions
|
@ -62,16 +62,18 @@ impl PackageJson {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn load<Fs: NodeFs>(
|
||||
pub fn load(
|
||||
fs: &dyn NodeFs,
|
||||
resolver: &dyn NpmResolver,
|
||||
permissions: &mut dyn NodePermissions,
|
||||
path: PathBuf,
|
||||
) -> Result<PackageJson, AnyError> {
|
||||
resolver.ensure_read_permission(permissions, &path)?;
|
||||
Self::load_skip_read_permission::<Fs>(path)
|
||||
Self::load_skip_read_permission(fs, path)
|
||||
}
|
||||
|
||||
pub fn load_skip_read_permission<Fs: NodeFs>(
|
||||
pub fn load_skip_read_permission(
|
||||
fs: &dyn NodeFs,
|
||||
path: PathBuf,
|
||||
) -> Result<PackageJson, AnyError> {
|
||||
assert!(path.is_absolute());
|
||||
|
@ -80,7 +82,7 @@ impl PackageJson {
|
|||
return Ok(CACHE.with(|cache| cache.borrow()[&path].clone()));
|
||||
}
|
||||
|
||||
let source = match Fs::read_to_string(&path) {
|
||||
let source = match fs.read_to_string(&path) {
|
||||
Ok(source) => source,
|
||||
Err(err) if err.kind() == ErrorKind::NotFound => {
|
||||
return Ok(PackageJson::empty(path));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue