Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

fix: stop warning about invalid Linux target on every default build

Luís Migueldff46345d58d
diff --git a/bin/helpers/merge.ts b/bin/helpers/merge.ts
index 252e37bb..4f392cee 100644
--- a/bin/helpers/merge.ts
+++ b/bin/helpers/merge.ts
@@ -17,7 +17,7 @@ import {
WindowConfig,
} from '@/types';
import { tauriConfigDirectory, npmDirectory } from '@/utils/dir';
-import { LINUX_TARGET_TYPES } from '@/utils/targets';
+import { LINUX_TARGET_TYPES, resolveLinuxBundleTargets } from '@/utils/targets';
/**
* Pure transform from CLI options to the window-config slice that gets
@@ -200,20 +200,20 @@ async function mergeLinuxConfig(
[desktopInstallPath]: `assets/${desktopFileName}`,
};
- const validTargets = [
- ...LINUX_TARGET_TYPES,
- ...LINUX_TARGET_TYPES.map((target) => `${target}-arm64`),
- ];
- const baseTarget = options.targets.includes('-arm64')
- ? options.targets.replace('-arm64', '')
- : options.targets;
+ // options.targets reaches here already stripped of any -arm64 suffix by the
+ // LinuxBuilder constructor, and may carry several comma-separated formats
+ // (e.g. the distro-aware default "deb,appimage"). Validate the parsed list
+ // rather than string-matching the whole value, so a valid multi-target
+ // default no longer trips the "must be one of ..." warning on every build.
+ const { bundleTargets, hasValidTarget } = resolveLinuxBundleTargets(
+ options.targets,
+ );
- if (validTargets.includes(options.targets)) {
- // zst is repacked from the deb payload, so Tauri itself bundles a deb.
- tauriConf.bundle.targets = [baseTarget === 'zst' ? 'deb' : baseTarget];
+ if (hasValidTarget) {
+ tauriConf.bundle.targets = bundleTargets;
} else {
logger.warn(
- `✼ The target must be one of ${validTargets.join(', ')}, the default 'deb' will be used.`,
+ `✼ The target must be one of ${LINUX_TARGET_TYPES.join(', ')}, the default 'deb' will be used.`,
);
}
}
diff --git a/bin/utils/targets.ts b/bin/utils/targets.ts
index 99599d0e..fb77777a 100644
--- a/bin/utils/targets.ts
+++ b/bin/utils/targets.ts
@@ -10,3 +10,19 @@ export function filterLinuxTargets(targets: string): string[] {
export function needsTemporaryDebForZst(targets: string[]): boolean {
return targets.includes('zst') && !targets.includes('deb');
}
+
+// Resolves the Tauri `bundle.targets` list for a Linux build from a
+// comma-separated --targets string (e.g. the distro-aware default
+// "deb,appimage"). zst is repacked from the deb payload, so it maps to a deb
+// bundle. hasValidTarget is false only when no known target is present, which
+// is the single case that should warn and fall back to the default.
+export function resolveLinuxBundleTargets(targets: string): {
+ bundleTargets: string[];
+ hasValidTarget: boolean;
+} {
+ const requested = filterLinuxTargets(targets);
+ const bundleTargets = [
+ ...new Set(requested.map((target) => (target === 'zst' ? 'deb' : target))),
+ ];
+ return { bundleTargets, hasValidTarget: requested.length > 0 };
+}
diff --git a/dist/cli.js b/dist/cli.js
index 06cae53b..c8640f78 100644
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -512,6 +512,18 @@ function filterLinuxTargets(targets) {
function needsTemporaryDebForZst(targets) {
return targets.includes('zst') && !targets.includes('deb');
}
+// Resolves the Tauri `bundle.targets` list for a Linux build from a
+// comma-separated --targets string (e.g. the distro-aware default
+// "deb,appimage"). zst is repacked from the deb payload, so it maps to a deb
+// bundle. hasValidTarget is false only when no known target is present, which
+// is the single case that should warn and fall back to the default.
+function resolveLinuxBundleTargets(targets) {
+ const requested = filterLinuxTargets(targets);
+ const bundleTargets = [
+ ...new Set(requested.map((target) => (target === 'zst' ? 'deb' : target))),
+ ];
+ return { bundleTargets, hasValidTarget: requested.length > 0 };
+}
/**
* Pure transform from CLI options to the window-config slice that gets
@@ -639,19 +651,17 @@ async function mergeLinuxConfig(options, name, tauriConf, linuxBinaryName) {
linuxBundle.rpm.files = {
[desktopInstallPath]: `assets/${desktopFileName}`,
};
- const validTargets = [
- ...LINUX_TARGET_TYPES,
- ...LINUX_TARGET_TYPES.map((target) => `${target}-arm64`),
- ];
- const baseTarget = options.targets.includes('-arm64')
- ? options.targets.replace('-arm64', '')
- : options.targets;
- if (validTargets.includes(options.targets)) {
- // zst is repacked from the deb payload, so Tauri itself bundles a deb.
- tauriConf.bundle.targets = [baseTarget === 'zst' ? 'deb' : baseTarget];
+ // options.targets reaches here already stripped of any -arm64 suffix by the
+ // LinuxBuilder constructor, and may carry several comma-separated formats
+ // (e.g. the distro-aware default "deb,appimage"). Validate the parsed list
+ // rather than string-matching the whole value, so a valid multi-target
+ // default no longer trips the "must be one of ..." warning on every build.
+ const { bundleTargets, hasValidTarget } = resolveLinuxBundleTargets(options.targets);
+ if (hasValidTarget) {
+ tauriConf.bundle.targets = bundleTargets;
}
else {
- logger.warn(`✼ The target must be one of ${validTargets.join(', ')}, the default 'deb' will be used.`);
+ logger.warn(`✼ The target must be one of ${LINUX_TARGET_TYPES.join(', ')}, the default 'deb' will be used.`);
}
}
async function resolveSystemTrayIconPath(systemTrayIcon, defaultTrayIconPath, safeAppName, iconOutputDir = path.join(npmDirectory, 'src-tauri/png')) {
diff --git a/tests/unit/builders.test.ts b/tests/unit/builders.test.ts
index cafe1e05..6965c477 100644
--- a/tests/unit/builders.test.ts
+++ b/tests/unit/builders.test.ts
@@ -3,6 +3,7 @@ import {
LINUX_TARGET_TYPES,
filterLinuxTargets,
needsTemporaryDebForZst,
+ resolveLinuxBundleTargets,
} from '../../bin/utils/targets.js';
describe('Linux target filtering', () => {
@@ -66,3 +67,40 @@ describe('Linux target filtering', () => {
expect(needsTemporaryDebForZst(['deb', 'appimage'])).toBe(false);
});
});
+
+describe('resolveLinuxBundleTargets', () => {
+ it('treats the default multi-target value as valid (no fallback warning)', () => {
+ expect(resolveLinuxBundleTargets('deb,appimage')).toEqual({
+ bundleTargets: ['deb', 'appimage'],
+ hasValidTarget: true,
+ });
+ });
+
+ it('treats the RPM-distro default as valid (canonical target order)', () => {
+ expect(resolveLinuxBundleTargets('rpm,appimage')).toEqual({
+ bundleTargets: ['appimage', 'rpm'],
+ hasValidTarget: true,
+ });
+ });
+
+ it('maps zst to a deb bundle (zst is repacked from the deb payload)', () => {
+ expect(resolveLinuxBundleTargets('zst')).toEqual({
+ bundleTargets: ['deb'],
+ hasValidTarget: true,
+ });
+ });
+
+ it('deduplicates when zst and deb are both requested', () => {
+ expect(resolveLinuxBundleTargets('deb,zst')).toEqual({
+ bundleTargets: ['deb'],
+ hasValidTarget: true,
+ });
+ });
+
+ it('reports no valid target when nothing matches', () => {
+ expect(resolveLinuxBundleTargets('invalid')).toEqual({
+ bundleTargets: [],
+ hasValidTarget: false,
+ });
+ });
+});