Skip to content

Commit 8be35ce

Browse files
authored
fix(cli.rs): tauri.conf.json > tauri > bundle > targets being ignored (#1945)
* fix(cli.rs): `tauri.conf.json > tauri > bundle > targets` being ignored * fix: cli.ts run
1 parent ae74518 commit 8be35ce

File tree

6 files changed

+45
-14
lines changed

6 files changed

+45
-14
lines changed

Diff for: .changes/cli.js-empty-args.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.js": patch
3+
---
4+
5+
Allow empty argument when running `cli.rs`.

Diff for: .changes/fix-bundle-targets-config.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.rs": patch
3+
---
4+
5+
Fixes `tauri.conf.json > tauri > bundle > targets` not applying to the bundler.

Diff for: tooling/cli.js/src/api/cli.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ function toKebabCase(value: string): string {
2020
.toLowerCase()
2121
}
2222

23-
async function runCliCommand(command: string, args: Args): Promise<Cmd> {
23+
async function runCliCommand(command: string, args?: Args): Promise<Cmd> {
2424
const argsArray = []
25-
for (const [argName, argValue] of Object.entries(args)) {
25+
for (const [argName, argValue] of Object.entries(args ?? {})) {
2626
if (argValue === false) {
2727
continue
2828
}
@@ -37,9 +37,9 @@ async function runCliCommand(command: string, args: Args): Promise<Cmd> {
3737
return await runOnRustCli(command, argsArray)
3838
}
3939

40-
export const init = async (args: Args): Promise<Cmd> =>
40+
export const init = async (args?: Args): Promise<Cmd> =>
4141
await runCliCommand('init', args)
42-
export const dev = async (args: Args): Promise<Cmd> =>
42+
export const dev = async (args?: Args): Promise<Cmd> =>
4343
await runCliCommand('dev', args)
44-
export const build = async (args: Args): Promise<Cmd> =>
44+
export const build = async (args?: Args): Promise<Cmd> =>
4545
await runCliCommand('build', args)

Diff for: tooling/cli.js/test/jest/__tests__/template.spec.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,7 @@ describe('[CLI] cli.js template', () => {
3030
`workspace = { }\n[patch.crates-io]\ntao = { git = "https://github.com/tauri-apps/tao", rev = "a3f533232df25dc30998809094ed5431b449489c" }\n\n${manifestFile}`
3131
)
3232

33-
const { promise: buildPromise } = await build({
34-
config: {
35-
tauri: {
36-
bundle: {
37-
targets: ['deb', 'app', 'msi', 'appimage'] // we can't bundle dmg on CI so we remove it here
38-
}
39-
}
40-
}
41-
})
33+
const { promise: buildPromise } = await build()
4234
await buildPromise
4335
process.chdir(cwd)
4436
})

Diff for: tooling/cli.rs/config_definition.rs

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ pub enum BundleTarget {
1818
One(String),
1919
}
2020

21+
impl BundleTarget {
22+
#[allow(dead_code)]
23+
pub fn to_vec(&self) -> Vec<String> {
24+
match self {
25+
Self::All(list) => list.clone(),
26+
Self::One(i) => vec![i.clone()],
27+
}
28+
}
29+
}
30+
2131
#[skip_serializing_none]
2232
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
2333
#[serde(rename_all = "camelCase", deny_unknown_fields)]

Diff for: tooling/cli.rs/src/build.rs

+19
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,25 @@ impl Build {
192192
}
193193

194194
settings_builder = settings_builder.package_types(types);
195+
} else if let Some(targets) = &config_.tauri.bundle.targets {
196+
let mut types = vec![];
197+
let targets = targets.to_vec();
198+
if !targets.contains(&"all".into()) {
199+
for name in targets {
200+
match PackageType::from_short_name(&name) {
201+
Some(package_type) => {
202+
types.push(package_type);
203+
}
204+
None => {
205+
return Err(anyhow::anyhow!(format!(
206+
"Unsupported bundle format: {}",
207+
name
208+
)));
209+
}
210+
}
211+
}
212+
settings_builder = settings_builder.package_types(types);
213+
}
195214
}
196215

197216
// Bundle the project

0 commit comments

Comments
 (0)