summaryrefslogtreecommitdiff
path: root/ext/node
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node')
-rw-r--r--ext/node/lib.rs2
-rw-r--r--ext/node/package_json.rs5
-rw-r--r--ext/node/path.rs38
-rw-r--r--ext/node/resolution.rs2
4 files changed, 46 insertions, 1 deletions
diff --git a/ext/node/lib.rs b/ext/node/lib.rs
index 42348915e..5178d81f7 100644
--- a/ext/node/lib.rs
+++ b/ext/node/lib.rs
@@ -15,9 +15,11 @@ use std::rc::Rc;
pub mod errors;
mod package_json;
+mod path;
mod resolution;
pub use package_json::PackageJson;
+pub use path::PathClean;
pub use resolution::get_closest_package_json;
pub use resolution::get_package_scope_config;
pub use resolution::legacy_main_resolve;
diff --git a/ext/node/package_json.rs b/ext/node/package_json.rs
index 95d773aeb..81daa7ca7 100644
--- a/ext/node/package_json.rs
+++ b/ext/node/package_json.rs
@@ -22,6 +22,7 @@ pub struct PackageJson {
main: Option<String>, // use .main(...)
module: Option<String>, // use .main(...)
pub name: Option<String>,
+ pub version: Option<String>,
pub path: PathBuf,
pub typ: String,
pub types: Option<String>,
@@ -37,6 +38,7 @@ impl PackageJson {
main: None,
module: None,
name: None,
+ version: None,
path,
typ: "none".to_string(),
types: None,
@@ -71,6 +73,7 @@ impl PackageJson {
let main_val = package_json.get("main");
let module_val = package_json.get("module");
let name_val = package_json.get("name");
+ let version_val = package_json.get("version");
let type_val = package_json.get("type");
let bin = package_json.get("bin").map(ToOwned::to_owned);
let exports = package_json.get("exports").map(|exports| {
@@ -88,6 +91,7 @@ impl PackageJson {
.map(|imp| imp.to_owned());
let main = main_val.and_then(|s| s.as_str()).map(|s| s.to_string());
let name = name_val.and_then(|s| s.as_str()).map(|s| s.to_string());
+ let version = version_val.and_then(|s| s.as_str()).map(|s| s.to_string());
let module = module_val.and_then(|s| s.as_str()).map(|s| s.to_string());
// Ignore unknown types for forwards compatibility
@@ -116,6 +120,7 @@ impl PackageJson {
path,
main,
name,
+ version,
module,
typ,
types,
diff --git a/ext/node/path.rs b/ext/node/path.rs
new file mode 100644
index 000000000..8477fe713
--- /dev/null
+++ b/ext/node/path.rs
@@ -0,0 +1,38 @@
+use std::path::Component;
+use std::path::PathBuf;
+
+/// Extenion to path_clean::PathClean
+pub trait PathClean<T> {
+ fn clean(&self) -> T;
+}
+
+impl PathClean<PathBuf> for PathBuf {
+ fn clean(&self) -> PathBuf {
+ let path = path_clean::PathClean::clean(self);
+ if cfg!(windows) && path.to_string_lossy().contains("..\\") {
+ // temporary workaround because path_clean::PathClean::clean is
+ // not good enough on windows
+ let mut components = Vec::new();
+
+ for component in path.components() {
+ match component {
+ Component::CurDir => {
+ // skip
+ }
+ Component::ParentDir => {
+ let poped_component = components.pop();
+ if !matches!(poped_component, Some(Component::Normal(_))) {
+ panic!("Error normalizing: {}", path.display());
+ }
+ }
+ Component::Normal(_) | Component::RootDir | Component::Prefix(_) => {
+ components.push(component);
+ }
+ }
+ }
+ components.into_iter().collect::<PathBuf>()
+ } else {
+ path
+ }
+ }
+}
diff --git a/ext/node/resolution.rs b/ext/node/resolution.rs
index 52ed06116..1bde99709 100644
--- a/ext/node/resolution.rs
+++ b/ext/node/resolution.rs
@@ -10,11 +10,11 @@ use deno_core::serde_json::Map;
use deno_core::serde_json::Value;
use deno_core::url::Url;
use deno_core::ModuleSpecifier;
-use path_clean::PathClean;
use regex::Regex;
use crate::errors;
use crate::package_json::PackageJson;
+use crate::path::PathClean;
use crate::RequireNpmResolver;
pub static DEFAULT_CONDITIONS: &[&str] = &["deno", "node", "import"];