-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
2,827 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} |
Oops, something went wrong.