Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add private field to package manifest #76

Merged
merged 3 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Wally Changelog

## Unreleased Changes
* Added private field to package manifest ([#9])

[#9]: https://github.com/UpliftGames/wally/issues/9

## 0.3.1 (2021-11-12)
* Support for dev dependencies ([#63][63])
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ registry = "https://github.com/upliftgames/wally-index"
# include = []
exclude = ["node_modules"]

# Packages can be marked as private to prevent them from being published.
private = true

[dependencies]
# Most dependencies will look like this.
#
Expand Down
7 changes: 6 additions & 1 deletion src/commands/publish.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::{Path, PathBuf};

use anyhow::Context;
use anyhow::{bail, Context};
use structopt::StructOpt;
use url::Url;

Expand All @@ -22,6 +22,11 @@ pub struct PublishSubcommand {
impl PublishSubcommand {
pub fn run(self, global: GlobalOptions) -> anyhow::Result<()> {
let manifest = Manifest::load(&self.project_path)?;

if manifest.package.private {
bail!("Cannot publish private package.");
}

let auth_store = AuthStore::load()?;

let index_url = if global.test_registry {
Expand Down
6 changes: 6 additions & 0 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ pub struct Package {
/// Example: ["/Packages", "/node_modules"]
#[serde(default)]
pub exclude: Vec<String>,

/// Indicates whether the package can be published or not.
///
/// Example: true
#[serde(default)]
pub private: bool,
}

// Metadata we require when this manifest will be used to generate package folders
Expand Down
1 change: 1 addition & 0 deletions src/test_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl PackageBuilder {
authors: Vec::new(),
include: Vec::new(),
exclude: Vec::new(),
private: false,
},
place: Default::default(),
dependencies: Default::default(),
Expand Down
6 changes: 6 additions & 0 deletions test-projects/private-package/default.project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "private-package",
"tree": {
"$path": "src"
}
}
1 change: 1 addition & 0 deletions test-projects/private-package/src/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return "Private Package"
7 changes: 7 additions & 0 deletions test-projects/private-package/wally.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "biff/private-package"
version = "0.1.0"
license = "MIT"
realm = "server"
registry = "test-registries/primary-registry"
private = true
26 changes: 26 additions & 0 deletions tests/integration/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,29 @@ fn check_mismatched_names() {
// default.project.json should now contain mismatched-name instead of Mismatched-name
assert_eq!(project_name, "mismatched-name");
}

/// If the private field in wally.toml is set to true, it should not publish
/// the package.
#[test]
fn check_private_field() {
let test_projects = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/test-projects",));

let args = Args {
global: GlobalOptions {
test_registry: true,
use_temp_index: true,
..Default::default()
},
subcommand: Subcommand::Publish(PublishSubcommand {
project_path: test_projects.join("private-package"),
}),
};

let error = args.run().expect_err("Expected publish to return an error");

assert!(
error.to_string().contains("Cannot publish"),
"Expected error message that a private package cannot be published. Instead we got: {:#}",
error
)
}