Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ pacquet_registry = { path = "crates/registry" }
pacquet_tarball = { path = "crates/tarball" }
pacquet_package_json = { path = "crates/package_json" }
pacquet_lockfile = { path = "crates/lockfile" }
pacquet_npmrc = { path = "crates/npmrc" }

anyhow = { version = "1.0.71" }
async-recursion = { version = "1.0.4" }
clap = { version = "4", features = ["derive"] }
elsa = { version = "1.8.1" }
home = { version = "0.5.5" }
flate2 = { version = "1.0.26" }
futures-util = { version = "0.3.28" }
reqwest = { version = "0.11", default-features = false, features = [
Expand All @@ -39,8 +41,9 @@ reqwest-middleware = { version = "0.2.2" }
reqwest-retry = { version = "0.2.2" }
node-semver = { version = "2.1.0" }
serde = { version = "1.0.164", features = ["derive"] }
serde_yaml = { version = "0.9.1" }
serde_ini = { version = "0.2.0" }
serde_json = { version = "1.0.99" }
serde_yaml = { version = "0.9.1" }
tar = { version = "0.4.38" }
thiserror = { version = "1.0.40" }
tracing = { version = "0.1.37" }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Experimental package manager for node.js written in rust.
- [x] Update package.json
- [ ] Create a shrink file like `pnpm-lock.json` or `package-lock.json`
- [ ] Workspace support
- [ ] `.npmrc` support
- [x] `.npmrc` support

### Commands

Expand Down
17 changes: 17 additions & 0 deletions crates/npmrc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "pacquet_npmrc"
version = "0.0.1"
publish = false
authors.workspace = true
description.workspace = true
edition.workspace = true
homepage.workspace = true
keywords.workspace = true
license.workspace = true
repository.workspace = true

[dependencies]
home = { workspace = true }
serde = { workspace = true }
serde_ini = { workspace = true }
thiserror = { workspace = true }
72 changes: 72 additions & 0 deletions crates/npmrc/src/custom_deserializer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use std::{env, path::Path, str::FromStr};

use serde::{de, Deserialize, Deserializer};

// This needs to be implemented because serde doesn't support default = "true" as
// a valid option, and throws "failed to parse" error.
pub fn bool_true() -> bool {
true
}

pub fn default_hoist_pattern() -> Vec<String> {
vec!["*".to_string()]
}

pub fn default_public_hoist_pattern() -> Vec<String> {
vec!["*eslint*".to_string(), "*prettier*".to_string()]
}

/// If the $PACQUET_HOME env variable is set, then $PACQUET_HOME/store
/// If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pacquet/store
/// On Windows: ~/AppData/Local/pacquet/store
/// On macOS: ~/Library/pacquet/store
/// On Linux: ~/.local/share/pacquet/store
Comment thread
steveklabnik marked this conversation as resolved.
pub fn default_store_dir() -> String {
if let Ok(pacquet_home) = env::var("$PACQUET_HOME") {
return Path::new(&pacquet_home).join("store").as_path().display().to_string();
}

if let Ok(xdg_data_home) = env::var("$XDG_DATA_HOME") {
return Path::new(&xdg_data_home).join("pacquet/store").as_path().display().to_string();
}

// https://doc.rust-lang.org/std/env/consts/constant.OS.html
match env::consts::OS {
"linux" => "~/.local/share/pacquet/store".to_string(),
"macos" => "~/Library/pacquet/store".to_string(),
"windows" => "~/AppData/Local/pacquet/store".to_string(),
_ => panic!("unsupported operating system: {0}", env::consts::OS),
}
}

pub fn default_modules_dir() -> String {
"node_modules".to_string()
}

pub fn default_virtual_store_dir() -> String {
"node_modules/.pacquet".to_string()
}

pub fn default_registry() -> String {
"https://registry.npmjs.org/".to_string()
}

pub fn default_modules_cache_max_age() -> u64 {
10080
}

pub fn deserialize_bool<'de, D>(deserializer: D) -> Result<bool, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
bool::from_str(&s).map_err(de::Error::custom)
}

pub fn deserialize_u64<'de, D>(deserializer: D) -> Result<u64, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
u64::from_str(&s).map_err(de::Error::custom)
}
Loading