Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
new: Support categories and channels for packages. (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Sep 5, 2023
1 parent 50791c3 commit e3f429b
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 21 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ starbase = { version = "0.2.5" }
starbase_archive = { version = "0.2.0", default-features = false }
starbase_sandbox = { version = "0.1.8" }
starbase_styles = "0.1.13"
starbase_utils = { version = "0.2.20", default-features = false, features = [
starbase_utils = { version = "0.2.21", default-features = false, features = [
"glob",
] }
thiserror = "1.0.47"
thiserror = "1.0.48"
tokio = { version = "1.32.0", features = ["full", "tracing"] }
tracing = "0.1.37"
url = { version = "2.4.1", features = ["serde"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false
clap = { workspace = true }
miette = { workspace = true }
once_cell = { workspace = true }
regex = "1.9.4"
regex = "1.9.5"
schematic = { workspace = true }
semver = { workspace = true }
serde = { workspace = true }
Expand Down
121 changes: 121 additions & 0 deletions crates/common/src/category.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Initial list based on Cargo: https://crates.io/category_slugs

use schematic::{derive_enum, ConfigEnum};

derive_enum!(
#[derive(ConfigEnum)]
pub enum Category {
// General categories
#[serde(alias = "a11y")]
Accessibility,
Algorithm,
Architecture,
#[serde(alias = "async")]
Asynchronous,
Authentication,
Authorization,
Automation,
Blockchain,
Caching,
#[serde(alias = "cli")]
CommandLineInterface,
CommandLineUtilities,
Compiler,
Compression,
Concurrency,
Configuration,
#[serde(alias = "ci")]
ContinuousIntegration,
#[serde(alias = "cd")]
ContinuousDeployment,
#[serde(alias = "cms")]
ContentManagementSystem,
Crypto,
Cryptography,
Database,
DataStructure,
DateTime,
Debugging,
#[serde(alias = "devx")]
DeveloperExperience,
DevelopmentTool,
Encoding,
#[serde(alias = "e2e")]
EndToEnd,
ErrorHandling,
FileSystem,
Finance,
Gaming,
Graphics,
#[serde(alias = "gui")]
GraphicalInterface,
InternalTool,
#[serde(alias = "i18n")]
Internationalization,
#[serde(alias = "l10n")]
Localization,
Logging,
Mathematics,
MediaProcessing,
MediaAudio,
MediaImage,
MediaVideo,
Mobile,
Networking,
Os,
Parser,
Profiling,
Publishing,
Rendering,
Security,
Social,
TemplateEngine,
Testing,
TestingUtilities,
TextProcessing,
#[serde(alias = "ux")]
UserExperience,
#[serde(alias = "ui")]
UserInterface,
Virtualization,
Visualization,
Wasm,
WebServer,
Websocket,
// Frontend specific
ApplicationFramework,
Bundler,
ClientFramework,
CloudPlatform,
CodeFormatter,
CodeGenerator,
ComponentLibrary,
CssFramework,
CssInJs,
DependencyGraph,
Deployment,
DesignSystem,
EditorExtension,
Environment,
Linter,
LintRules,
MonorepoTool,
MonorepoUtilities,
Plugin,
Primitives,
Reactivity,
ServerFramework,
#[serde(alias = "ssr")]
ServerSideRenderer,
#[serde(alias = "ssg")]
StaticSiteGenerator,
Styles,
StyleGuide,
TaskRunner,
Theme,
TestRunner,
Toolchain,
TypeChecker,
TypeUtilities,
}
);
12 changes: 12 additions & 0 deletions crates/common/src/channel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use clap::ValueEnum;
use schematic::{derive_enum, ConfigEnum};

derive_enum!(
#[derive(ConfigEnum, ValueEnum)]
pub enum Channel {
Stable, // latest
Unstable, // next, beta, alpha, etc
Experimental, // one-off
Nightly,
}
);
4 changes: 4 additions & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#![allow(clippy::from_over_into)]

mod category;
mod channel;
mod license_type;
mod package_name;
mod target;

pub use category::*;
pub use channel::*;
pub use license_type::*;
pub use package_name::*;
pub use semver::{Version, VersionReq};
Expand Down
11 changes: 10 additions & 1 deletion crates/manifest/src/package_manifest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{build_setting::*, common_settings::*, install_setting::*};
use espresso_common::{LicenseType, PackageName, Version};
use espresso_common::{Category, LicenseType, PackageName, Version};
use schematic::{validate, Config};
use url::Url;

Expand All @@ -8,15 +8,24 @@ use url::Url;
pub struct PackageManifestMetadata {
#[setting(validate = validate::not_empty)]
pub name: PackageName,

pub version: Option<Version>,

pub description: String,

#[setting(validate = validate::max_length(5))]
pub keywords: Vec<String>,

pub license: Option<LicenseType>,

#[setting(validate = validate::max_length(5))]
pub categories: Vec<Category>,

#[setting(validate = validate::url_secure)]
pub repository: Option<Url>,

pub homepage: Option<Url>,

pub documentation: Option<Url>,

#[setting(default = true)]
Expand Down
56 changes: 56 additions & 0 deletions crates/manifest/tests/package_manifest_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,22 @@ publish = false
);
}

#[test]
#[should_panic(expected = "length is greater than 5")]
fn errors_too_many_keywords() {
let sandbox = create_empty_sandbox();
sandbox.create_file(
MANIFEST_NAME,
r#"
[package]
name = "ns/pkg"
keywords = ["a", "b", "c", "d", "e", "f"]
"#,
);

ManifestLoader::load_package(sandbox.path()).unwrap();
}

#[test]
fn parses_license() {
let sandbox = create_empty_sandbox();
Expand Down Expand Up @@ -479,5 +495,45 @@ documentation = "invalid/url"

ManifestLoader::load_package(sandbox.path()).unwrap();
}

#[test]
fn parses_categories() {
let sandbox = create_empty_sandbox();
sandbox.create_file(
MANIFEST_NAME,
r#"
[package]
name = "ns/pkg"
categories = ["async", "file-system", "lint-rules"]
"#,
);

let manifest = ManifestLoader::load_package(sandbox.path()).unwrap();

assert_eq!(
manifest.package.categories,
vec![
Category::Asynchronous,
Category::FileSystem,
Category::LintRules
]
);
}

#[test]
#[should_panic(expected = "length is greater than 5")]
fn errors_too_many_categories() {
let sandbox = create_empty_sandbox();
sandbox.create_file(
MANIFEST_NAME,
r#"
[package]
name = "ns/pkg"
categories = ["async", "file-system", "lint-rules", "ci", "cd", "application-framework"]
"#,
);

ManifestLoader::load_package(sandbox.path()).unwrap();
}
}
}
7 changes: 4 additions & 3 deletions crates/store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ impl Store {

drop(locks);

let _ = entry.lock().await;
let _entry_lock = entry.lock().await;

// After we've acquired the lock, we can check if the item already
// exists in the store. If we do this before the lock, other processes would
// return true while the archive is being unpacked, resulting in breakages!
let output_dir = self.packages_dir.join(item.to_file_path());
let _fs_lock = fs::lock_directory(&output_dir)?;

if output_dir.exists() {
if output_dir.exists() && !output_dir.join(".lock").exists() {
return Ok(output_dir);
}

Expand Down Expand Up @@ -160,7 +161,7 @@ impl Store {
) -> miette::Result<PathBuf> {
let output_dir = self.packages_dir.join(item.to_file_path());

if output_dir.exists() {
if output_dir.exists() && !output_dir.join(".lock").exists() {
debug!(
item = item.get_label(),
output_dir = ?output_dir,
Expand Down

0 comments on commit e3f429b

Please sign in to comment.