Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yarnpkg/monorepo",
"packageManager": "yarn@6.0.0-rc.19",
"packageManager": "yarn@6.0.0-git.20260814.hash-4421e301548e85d07d894540f89adc1345b1374a",
"scripts": {
"codegen:daemon-types": "cargo run -p zpm --bin generate_daemon_types",
"codegen:daemon-types:check": "cargo run -p zpm --bin generate_daemon_types -- --check",
Expand Down
24 changes: 22 additions & 2 deletions packages/zpm-config/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ struct Field {
title: Option<String>,
description: Option<String>,
default: Option<Expression>,
/// Set on array fields that also accept a single item, which then gets
/// treated as a list of one (`supportedArchitectures`, for instance).
one_or_many: Option<bool>,
property_aliases: Option<BTreeMap<String, Vec<String>>>,
properties: Option<BTreeMap<String, Field>>,
additional_keys: Option<Box<Field>>,
Expand Down Expand Up @@ -162,6 +165,7 @@ impl Field {
type_: field.get_type(),
aliases: field_aliases,
default: field_default,
one_or_many: field.one_or_many.unwrap_or(false),
});
}

Expand Down Expand Up @@ -258,6 +262,7 @@ struct GeneratorField {
type_: InternalType,
aliases: Vec<String>,
default: String,
one_or_many: bool,
}

struct Generator {
Expand Down Expand Up @@ -300,7 +305,13 @@ impl Generator {
writeln!(writer, " #[serde(alias = \"{alias_camel_case}\")]").unwrap();
}

writeln!(writer, " #[serde(default)] pub {lc_snake_name}: Partial<{}>,", type_.to_intermediate_type_string()).unwrap();
let deserialize_with = if field.one_or_many {
", deserialize_with = \"crate::deserialize_one_or_many\""
} else {
""
};

writeln!(writer, " #[serde(default{deserialize_with})] pub {lc_snake_name}: Partial<{}>,", type_.to_intermediate_type_string()).unwrap();
}

writeln!(writer, " }}").unwrap();
Expand Down Expand Up @@ -412,8 +423,17 @@ impl Generator {
let lc_snake_name
= name.to_case(Case::Snake);

// A one-or-many field is a single logical value, so the project
// configuration must replace the user one rather than extend it
// like regular list settings do.
let user_expr = if field.one_or_many {
format!("if let Partial::Value(_) = &project.{lc_snake_name} {{ Partial::Missing }} else {{ user.{lc_snake_name} }}")
} else {
format!("user.{lc_snake_name}")
};

let merge_expr
= format!("MergeSettings::merge(context, user.{lc_snake_name}, project.{lc_snake_name}, {default})");
= format!("MergeSettings::merge(context, {user_expr}, project.{lc_snake_name}, {default})");

if struct_name == &self.root_name {
writeln!(writer, " {lc_snake_name}: {{").unwrap();
Expand Down
44 changes: 21 additions & 23 deletions packages/zpm-config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -628,29 +628,27 @@
"default": 5000
},
"supportedArchitectures": {
"type": "object",
"title": "SupportedArchitectures",
"description": "The list of architectures we need to download in the cache.",
"properties": {
"cpu": {
"type": "array",
"description": "List of CPU architectures to cover.",
"items": {
"type": "zpm_utils::Cpu"
}
},
"libc": {
"type": "array",
"description": "The list of standard C libraries to cover.",
"items": {
"type": "zpm_utils::Libc"
}
},
"os": {
"type": "array",
"description": "The list of operating systems to cover.",
"items": {
"type": "zpm_utils::Os"
Comment thread
cursor[bot] marked this conversation as resolved.
"type": "array",
"oneOrMany": true,
"description": "The list of architectures we need to download in the cache. Can either be a single entry (whose fields are combined together as a cross product) or a list of entries (each entry being matched independently).",
"items": {
"type": "object",
"title": "SupportedArchitectures",
"properties": {
"cpu": {
"type": "crate::ArchitectureFilter<zpm_utils::Cpu>",
"description": "The CPU architecture (or list of architectures) to cover, or null to cover them all.",
"default": "current"
},
"libc": {
"type": "crate::ArchitectureFilter<zpm_utils::Libc>",
"description": "The standard C library (or list of libraries) to cover, or null to cover them all.",
"default": "current"
},
"os": {
"type": "crate::ArchitectureFilter<zpm_utils::Os>",
"description": "The operating system (or list of systems) to cover, or null to cover them all.",
"default": "current"
}
}
}
Expand Down
Loading
Loading