Skip to content

Commit

Permalink
Add WIP package crate
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem committed Nov 21, 2024
1 parent 39b7671 commit 02e5f9a
Show file tree
Hide file tree
Showing 31 changed files with 2,827 additions and 4 deletions.
51 changes: 47 additions & 4 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"vector",
"lsp/nls",
"lsp/lsp-harness",
"package",
"utils",
"wasm-repl",
"pyckel",
Expand All @@ -25,6 +26,7 @@ readme = "README.md"
[workspace.dependencies]
nickel-lang-core = { version = "0.10.0", path = "./core", default-features = false }
nickel-lang-git = { version = "0.1.0", path = "./git" }
nickel-lang-package = { version = "0.1.0", path = "./package" }
nickel-lang-vector = { version = "0.1.0", path = "./vector" }
nickel-lang-utils = { version = "0.1.0", path = "./utils" }
lsp-harness = { version = "0.1.0", path = "./lsp/lsp-harness" }
Expand Down Expand Up @@ -58,6 +60,7 @@ directories = "4.0.1"
env_logger = "0.10"
git-version = "0.3.5"
gix = "0.67.0"
gix-hash = "0.15.0"
indexmap = "1.9.3"
indoc = "2"
insta = "1.29.0"
Expand Down
35 changes: 35 additions & 0 deletions package/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "nickel-lang-package"
description = "The Nickel Package Manager (npm)"
version = "0.1.0"

authors.workspace = true
edition.workspace = true
homepage.workspace = true
keywords.workspace = true
license.workspace = true
repository.workspace = true
readme.workspace = true

[features]

[dependencies]
anyhow.workspace = true
directories.workspace = true
gix.workspace = true
gix-hash = { workspace = true, features = ["serde"] }
nickel-lang-core = { workspace = true, default-features = false }
nickel-lang-git.workspace = true
pubgrub = { version = "0.2.1", features = ["serde"] }
regex.workspace = true
semver = { version = "1.0.23", features = ["serde"] }
serde.workspace = true
serde_json.workspace = true
serde_with.workspace = true
tempfile = { workspace = true }
thiserror.workspace = true

[dev-dependencies]
insta = { workspace = true, features = ["filters"] }
nickel-lang-utils.workspace = true
test-generator.workspace = true
66 changes: 66 additions & 0 deletions package/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use std::path::PathBuf;

use directories::ProjectDirs;
use std::collections::HashMap;

const DEFAULT_INDEX_URL: &str = "https://github.com/nickel-lang/nickel-mine.git";

/// Global configuration for the package manager.
#[derive(Clone, Debug)]
pub struct Config {
pub index_url: gix::Url,

pub cache_dir: PathBuf,

/// Defaults to `<cache_dir>/index`
pub index_dir: PathBuf,
/// Defaults to `<cache_dir>/index-packages`
pub index_package_dir: PathBuf,
/// Defaults to `<cache_dir>/git-packages`
pub git_package_dir: PathBuf,

/// Git source replacements: any git packages that we're supposed to
/// fetch from the original source will be transparently fetched from the
/// replacement source instead. The lock-file will not see this replacement;
/// it's intended for vendoring or mirroring, not changing the contents of
/// the package.
pub git_replacements: HashMap<gix::Url, gix::Url>,
// TODO: index replacments (and private indices)
}

impl Default for Config {
fn default() -> Self {
// unwrap: TODO
let cache_dir = ProjectDirs::from("org", "nickel-lang", "nickel")
.unwrap()
.cache_dir()
.to_owned();
Self {
// unwrap: it's a constant, and we know it's a valid url.
index_url: DEFAULT_INDEX_URL.try_into().unwrap(),
index_dir: PathBuf::default(),
index_package_dir: PathBuf::default(),
git_package_dir: PathBuf::default(),
cache_dir: PathBuf::default(),
git_replacements: HashMap::default(),
}
.with_cache_dir(cache_dir)
}
}

impl Config {
/// Configures the root cache directory, and reconfigures the various derived paths
/// based on the new root cache directory.
pub fn with_cache_dir(self, cache_dir: PathBuf) -> Self {
Self {
index_dir: cache_dir.join("index"),
index_package_dir: cache_dir.join("index-packages"),
git_package_dir: cache_dir.join("git-packages"),
..self
}
}

pub fn with_index_dir(self, index_dir: PathBuf) -> Self {
Self { index_dir, ..self }
}
}
Loading

0 comments on commit 02e5f9a

Please sign in to comment.