소스 검색

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
Lucas Fernandes Nogueira 4 년 전
부모
커밋
8be35ced78

+ 5 - 0
.changes/cli.js-empty-args.md

@@ -0,0 +1,5 @@
+---
+"cli.js": patch
+---
+
+Allow empty argument when running `cli.rs`.

+ 5 - 0
.changes/fix-bundle-targets-config.md

@@ -0,0 +1,5 @@
+---
+"cli.rs": patch
+---
+
+Fixes `tauri.conf.json > tauri > bundle > targets` not applying to the bundler.

+ 5 - 5
tooling/cli.js/src/api/cli.ts

@@ -20,9 +20,9 @@ function toKebabCase(value: string): string {
     .toLowerCase()
 }
 
-async function runCliCommand(command: string, args: Args): Promise<Cmd> {
+async function runCliCommand(command: string, args?: Args): Promise<Cmd> {
   const argsArray = []
-  for (const [argName, argValue] of Object.entries(args)) {
+  for (const [argName, argValue] of Object.entries(args ?? {})) {
     if (argValue === false) {
       continue
     }
@@ -37,9 +37,9 @@ async function runCliCommand(command: string, args: Args): Promise<Cmd> {
   return await runOnRustCli(command, argsArray)
 }
 
-export const init = async (args: Args): Promise<Cmd> =>
+export const init = async (args?: Args): Promise<Cmd> =>
   await runCliCommand('init', args)
-export const dev = async (args: Args): Promise<Cmd> =>
+export const dev = async (args?: Args): Promise<Cmd> =>
   await runCliCommand('dev', args)
-export const build = async (args: Args): Promise<Cmd> =>
+export const build = async (args?: Args): Promise<Cmd> =>
   await runCliCommand('build', args)

+ 1 - 9
tooling/cli.js/test/jest/__tests__/template.spec.js

@@ -30,15 +30,7 @@ describe('[CLI] cli.js template', () => {
       `workspace = { }\n[patch.crates-io]\ntao = { git = "https://github.com/tauri-apps/tao", rev = "a3f533232df25dc30998809094ed5431b449489c" }\n\n${manifestFile}`
     )
 
-    const { promise: buildPromise } = await build({
-      config: {
-        tauri: {
-          bundle: {
-            targets: ['deb', 'app', 'msi', 'appimage'] // we can't bundle dmg on CI so we remove it here
-          }
-        }
-      }
-    })
+    const { promise: buildPromise } = await build()
     await buildPromise
     process.chdir(cwd)
   })

+ 10 - 0
tooling/cli.rs/config_definition.rs

@@ -18,6 +18,16 @@ pub enum BundleTarget {
   One(String),
 }
 
+impl BundleTarget {
+  #[allow(dead_code)]
+  pub fn to_vec(&self) -> Vec<String> {
+    match self {
+      Self::All(list) => list.clone(),
+      Self::One(i) => vec![i.clone()],
+    }
+  }
+}
+
 #[skip_serializing_none]
 #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
 #[serde(rename_all = "camelCase", deny_unknown_fields)]

+ 19 - 0
tooling/cli.rs/src/build.rs

@@ -192,6 +192,25 @@ impl Build {
         }
 
         settings_builder = settings_builder.package_types(types);
+      } else if let Some(targets) = &config_.tauri.bundle.targets {
+        let mut types = vec![];
+        let targets = targets.to_vec();
+        if !targets.contains(&"all".into()) {
+          for name in targets {
+            match PackageType::from_short_name(&name) {
+              Some(package_type) => {
+                types.push(package_type);
+              }
+              None => {
+                return Err(anyhow::anyhow!(format!(
+                  "Unsupported bundle format: {}",
+                  name
+                )));
+              }
+            }
+          }
+          settings_builder = settings_builder.package_types(types);
+        }
       }
 
       // Bundle the project