summaryrefslogtreecommitdiff
path: root/ext/node
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node')
-rw-r--r--ext/node/Cargo.toml5
-rw-r--r--ext/node/errors.rs2
-rw-r--r--ext/node/lib.rs2
-rw-r--r--ext/node/package_json.rs33
-rw-r--r--ext/node/resolution.rs4
5 files changed, 31 insertions, 15 deletions
diff --git a/ext/node/Cargo.toml b/ext/node/Cargo.toml
index dafb3a0c8..ed168eace 100644
--- a/ext/node/Cargo.toml
+++ b/ext/node/Cargo.toml
@@ -13,6 +13,9 @@ description = "Node compatibility for Deno"
[lib]
path = "lib.rs"
+[features]
+sync_fs = ["deno_package_json/sync"]
+
[dependencies]
aead-gcm-stream = "0.1"
aes.workspace = true
@@ -23,13 +26,13 @@ bytes.workspace = true
cbc.workspace = true
const-oid = "0.9.5"
data-encoding.workspace = true
-deno_config = { workspace = true, default-features = false, features = ["package_json"] }
deno_core.workspace = true
deno_fetch.workspace = true
deno_fs.workspace = true
deno_io.workspace = true
deno_media_type.workspace = true
deno_net.workspace = true
+deno_package_json.workspace = true
deno_permissions.workspace = true
deno_whoami = "0.1.0"
digest = { version = "0.10.5", features = ["core-api", "std"] }
diff --git a/ext/node/errors.rs b/ext/node/errors.rs
index 98b207e86..11bb011f8 100644
--- a/ext/node/errors.rs
+++ b/ext/node/errors.rs
@@ -315,7 +315,7 @@ impl NodeJsErrorCoded for PathToDeclarationUrlError {
pub struct PackageJsonLoadError(
#[source]
#[from]
- pub deno_config::package_json::PackageJsonLoadError,
+ pub deno_package_json::PackageJsonLoadError,
);
impl NodeJsErrorCoded for PackageJsonLoadError {
diff --git a/ext/node/lib.rs b/ext/node/lib.rs
index 5be0fffa1..6f7185148 100644
--- a/ext/node/lib.rs
+++ b/ext/node/lib.rs
@@ -32,7 +32,7 @@ mod path;
mod polyfill;
mod resolution;
-pub use deno_config::package_json::PackageJson;
+pub use deno_package_json::PackageJson;
pub use ops::ipc::ChildPipeFd;
pub use ops::ipc::IpcJsonStreamResource;
use ops::vm;
diff --git a/ext/node/package_json.rs b/ext/node/package_json.rs
index b28207db8..877acfc7a 100644
--- a/ext/node/package_json.rs
+++ b/ext/node/package_json.rs
@@ -1,8 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
-use deno_config::package_json::PackageJson;
-use deno_config::package_json::PackageJsonRc;
-use deno_fs::DenoConfigFsAdapter;
+use deno_package_json::PackageJson;
+use deno_package_json::PackageJsonRc;
use std::cell::RefCell;
use std::collections::HashMap;
use std::io::ErrorKind;
@@ -24,9 +23,7 @@ impl PackageJsonThreadLocalCache {
}
}
-impl deno_config::package_json::PackageJsonCache
- for PackageJsonThreadLocalCache
-{
+impl deno_package_json::PackageJsonCache for PackageJsonThreadLocalCache {
fn get(&self, path: &Path) -> Option<PackageJsonRc> {
CACHE.with(|cache| cache.borrow().get(path).cloned())
}
@@ -36,6 +33,20 @@ impl deno_config::package_json::PackageJsonCache
}
}
+pub struct DenoPkgJsonFsAdapter<'a>(pub &'a dyn deno_fs::FileSystem);
+
+impl<'a> deno_package_json::fs::DenoPkgJsonFs for DenoPkgJsonFsAdapter<'a> {
+ fn read_to_string_lossy(
+ &self,
+ path: &Path,
+ ) -> Result<String, std::io::Error> {
+ self
+ .0
+ .read_text_file_lossy_sync(path, None)
+ .map_err(|err| err.into_io_error())
+ }
+}
+
/// Helper to load a package.json file using the thread local cache
/// in deno_node.
pub fn load_pkg_json(
@@ -44,14 +55,16 @@ pub fn load_pkg_json(
) -> Result<Option<PackageJsonRc>, PackageJsonLoadError> {
let result = PackageJson::load_from_path(
path,
- &DenoConfigFsAdapter::new(fs),
+ &DenoPkgJsonFsAdapter(fs),
Some(&PackageJsonThreadLocalCache),
);
match result {
Ok(pkg_json) => Ok(Some(pkg_json)),
- Err(deno_config::package_json::PackageJsonLoadError::Io {
- source, ..
- }) if source.kind() == ErrorKind::NotFound => Ok(None),
+ Err(deno_package_json::PackageJsonLoadError::Io { source, .. })
+ if source.kind() == ErrorKind::NotFound =>
+ {
+ Ok(None)
+ }
Err(err) => Err(PackageJsonLoadError(err)),
}
}
diff --git a/ext/node/resolution.rs b/ext/node/resolution.rs
index cf30305a9..476b4f59c 100644
--- a/ext/node/resolution.rs
+++ b/ext/node/resolution.rs
@@ -5,7 +5,6 @@ use std::collections::HashMap;
use std::path::Path;
use std::path::PathBuf;
-use deno_config::package_json::PackageJsonRc;
use deno_core::anyhow::bail;
use deno_core::error::AnyError;
use deno_core::serde_json::Map;
@@ -14,6 +13,7 @@ use deno_core::url::Url;
use deno_core::ModuleSpecifier;
use deno_fs::FileSystemRc;
use deno_media_type::MediaType;
+use deno_package_json::PackageJsonRc;
use crate::errors;
use crate::errors::CanonicalizingPkgJsonDirError;
@@ -56,7 +56,7 @@ use crate::PathClean;
pub static DEFAULT_CONDITIONS: &[&str] = &["deno", "node", "import"];
pub static REQUIRE_CONDITIONS: &[&str] = &["require", "node"];
-pub type NodeModuleKind = deno_config::package_json::NodeModuleKind;
+pub type NodeModuleKind = deno_package_json::NodeModuleKind;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NodeResolutionMode {