Compare commits

...

1 Commits

Author SHA1 Message Date
Lucas Nogueira
9ed714334a feat(core): add capability devOnly field
a dev environment might need particular scope configurations (such as allowing a localhost API). This change allows marking a whole capability file as "dev only"
2025-04-18 09:45:57 -03:00
9 changed files with 39 additions and 1 deletions

View File

@@ -0,0 +1,7 @@
---
"tauri-utils": minor:feat
"tauri-codegen": minor:feat
"tauri": minor:feat
---
Added `devOnly` option to the capability that lets you define a capability only for development - for instance to allow local APIs in scopes.

View File

@@ -1409,6 +1409,10 @@
"items": {
"$ref": "#/definitions/Target"
}
},
"devOnly": {
"description": "Whether this capability is only applied on dev or not.",
"type": "boolean"
}
}
},

View File

@@ -103,6 +103,7 @@ pub fn command(options: Options) -> Result<()> {
})
.collect(),
platforms: None,
dev_only: false,
};
let path = match options.out {

View File

@@ -46,6 +46,7 @@ pub fn migrate(tauri_dir: &Path) -> Result<MigratedConfig> {
webviews: vec![],
permissions,
platforms: None,
dev_only: false,
})?,
)?;

View File

@@ -398,7 +398,10 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
Some(&capabilities_file_path),
additional_capabilities.as_deref(),
)
.unwrap();
.unwrap()
.into_iter()
.filter(|(_key, capability)| !capability.dev_only || dev)
.collect();
let resolved = Resolved::resolve(&acl, capabilities, target).expect("failed to resolve ACL");

View File

@@ -64,6 +64,10 @@
"items": {
"$ref": "#/definitions/Target"
}
},
"devOnly": {
"description": "Whether this capability is only applied on dev or not.",
"type": "boolean"
}
},
"definitions": {

View File

@@ -1409,6 +1409,10 @@
"items": {
"$ref": "#/definitions/Target"
}
},
"devOnly": {
"description": "Whether this capability is only applied on dev or not.",
"type": "boolean"
}
}
},

View File

@@ -202,6 +202,18 @@ pub struct Capability {
/// `["macOS","windows"]`
#[serde(skip_serializing_if = "Option::is_none")]
pub platforms: Option<Vec<Target>>,
/// Whether this capability is only applied on dev or not.
#[serde(
default,
skip_serializing_if = "is_false",
rename = "devOnly",
alias = "dev-only"
)]
pub dev_only: bool,
}
fn is_false(f: &bool) -> bool {
!f
}
impl Capability {
@@ -431,6 +443,7 @@ mod tests {
webviews: vec![],
permissions: vec![],
platforms: None,
dev_only: false,
};
let capability_json = serde_json::to_string(&capability).unwrap();

View File

@@ -95,6 +95,7 @@ impl CapabilityBuilder {
webviews: Vec::new(),
permissions: Vec::new(),
platforms: None,
dev_only: false,
})
}