Skip to content

Commit de1f898

Browse files
committed
refactor: replace merge.ts tauriConf: any with PakeTauriConfig
Introduce a shared PakeTauriConfig that composes the existing PakeConfig (now including the optional inject field) with narrow typings for the bundle and app subtrees we actually touch. Replace all six tauriConf parameter signatures in bin/helpers/merge.ts, narrow the platform-map key cast where PlatformSpecific is indexed, and hoist the Linux bundle into a local so the non-null assertion stays at the entry of the platform-guarded helper instead of being repeated at every access.
1 parent 7a7c804 commit de1f898

3 files changed

Lines changed: 61 additions & 20 deletions

File tree

bin/helpers/merge.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import {
99
getSafeAppName,
1010
generateLinuxPackageName,
1111
} from '@/utils/name';
12-
import { PakeAppOptions, PlatformMap, WindowConfig } from '@/types';
12+
import {
13+
PakeAppOptions,
14+
PakeTauriConfig,
15+
PlatformMap,
16+
PlatformSpecific,
17+
WindowConfig,
18+
} from '@/types';
1319
import { tauriConfigDirectory, npmDirectory } from '@/utils/dir';
1420

1521
async function copyTemplateConfigs(): Promise<void> {
@@ -41,7 +47,7 @@ async function copyTemplateConfigs(): Promise<void> {
4147
async function handleLocalFile(
4248
url: string,
4349
useLocalFile: boolean,
44-
tauriConf: any,
50+
tauriConf: PakeTauriConfig,
4551
): Promise<void> {
4652
const pathExists = await fsExtra.pathExists(url);
4753
if (pathExists) {
@@ -77,10 +83,11 @@ async function handleLocalFile(
7783
async function mergeLinuxConfig(
7884
options: PakeAppOptions,
7985
name: string,
80-
tauriConf: any,
86+
tauriConf: PakeTauriConfig,
8187
linuxBinaryName: string,
8288
): Promise<void> {
83-
delete tauriConf.bundle.linux.deb.files;
89+
const linuxBundle = tauriConf.bundle.linux!;
90+
delete linuxBundle.deb.files;
8491

8592
const linuxName = generateLinuxPackageName(name);
8693
const desktopFileName = `com.pake.${linuxName}.desktop`;
@@ -108,14 +115,14 @@ Terminal=false
108115
await fsExtra.writeFile(srcDesktopFilePath, desktopContent);
109116

110117
const desktopInstallPath = `/usr/share/applications/${desktopFileName}`;
111-
tauriConf.bundle.linux.deb.files = {
118+
linuxBundle.deb.files = {
112119
[desktopInstallPath]: `assets/${desktopFileName}`,
113120
};
114121

115-
if (!tauriConf.bundle.linux.rpm) {
116-
tauriConf.bundle.linux.rpm = {};
122+
if (!linuxBundle.rpm) {
123+
linuxBundle.rpm = {};
117124
}
118-
tauriConf.bundle.linux.rpm.files = {
125+
linuxBundle.rpm.files = {
119126
[desktopInstallPath]: `assets/${desktopFileName}`,
120127
};
121128

@@ -143,7 +150,7 @@ Terminal=false
143150
async function mergeIcons(
144151
options: PakeAppOptions,
145152
name: string,
146-
tauriConf: any,
153+
tauriConf: PakeTauriConfig,
147154
platform: string,
148155
safeAppName: string,
149156
): Promise<void> {
@@ -218,7 +225,7 @@ async function mergeIcons(
218225

219226
// Set tray icon path.
220227
let trayIconPath =
221-
platform === 'darwin' ? 'png/icon_512.png' : tauriConf.bundle.icon[0];
228+
platform === 'darwin' ? 'png/icon_512.png' : tauriConf.bundle.icon![0];
222229
if (options.systemTrayIcon.length > 0) {
223230
try {
224231
await fsExtra.pathExists(options.systemTrayIcon);
@@ -250,7 +257,7 @@ async function mergeIcons(
250257

251258
async function injectCustomCode(
252259
options: PakeAppOptions,
253-
tauriConf: any,
260+
tauriConf: PakeTauriConfig,
254261
): Promise<void> {
255262
const { inject, proxyUrl, multiInstance, multiWindow, wasm } = options;
256263
const injectFilePath = path.join(
@@ -324,7 +331,7 @@ ${entitlementEntries.join('\n')}
324331
}
325332

326333
async function writeAllConfigs(
327-
tauriConf: any,
334+
tauriConf: PakeTauriConfig,
328335
platform: string,
329336
): Promise<void> {
330337
const platformConfigPaths: PlatformMap = {
@@ -355,7 +362,7 @@ async function writeAllConfigs(
355362
export async function mergeConfig(
356363
url: string,
357364
options: PakeAppOptions,
358-
tauriConf: any,
365+
tauriConf: PakeTauriConfig,
359366
) {
360367
await copyTemplateConfigs();
361368

@@ -435,7 +442,7 @@ export async function mergeConfig(
435442
: `pake-${generateIdentifierSafeName(name)}`;
436443

437444
if (platform === 'win32') {
438-
tauriConf.bundle.windows.wix.language[0] = installerLanguage;
445+
tauriConf.bundle.windows!.wix.language[0] = installerLanguage;
439446
}
440447

441448
await handleLocalFile(url, useLocalFile, tauriConf);
@@ -445,7 +452,9 @@ export async function mergeConfig(
445452
linux: 'linux',
446453
darwin: 'macos',
447454
};
448-
const currentPlatform = platformMap[platform];
455+
const currentPlatform = platformMap[platform] as keyof PlatformSpecific<
456+
string | boolean
457+
>;
449458

450459
if (userAgent.length > 0) {
451460
tauriConf.pake.user_agent[currentPlatform] = userAgent;

bin/types.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,35 @@ export interface PakeConfig {
183183
proxy_url: string;
184184
multi_instance: boolean;
185185
multi_window: boolean;
186+
inject?: string[];
187+
}
188+
189+
export interface PakeTauriConfig {
190+
productName?: string;
191+
identifier?: string;
192+
version?: string;
193+
mainBinaryName?: string;
194+
pake: PakeConfig;
195+
bundle: {
196+
icon?: string[];
197+
resources?: string[];
198+
targets?: string[];
199+
linux?: {
200+
deb: { files?: Record<string, string> };
201+
rpm?: { files?: Record<string, string> };
202+
[key: string]: unknown;
203+
};
204+
windows?: {
205+
wix: { language: string[] };
206+
[key: string]: unknown;
207+
};
208+
[key: string]: unknown;
209+
};
210+
app: {
211+
security?: { headers?: Record<string, string> };
212+
trayIcon?: unknown;
213+
[key: string]: unknown;
214+
};
215+
build?: unknown;
216+
[key: string]: unknown;
186217
}

dist/cli.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,8 @@ async function handleLocalFile(url, useLocalFile, tauriConf) {
525525
}
526526
}
527527
async function mergeLinuxConfig(options, name, tauriConf, linuxBinaryName) {
528-
delete tauriConf.bundle.linux.deb.files;
528+
const linuxBundle = tauriConf.bundle.linux;
529+
delete linuxBundle.deb.files;
529530
const linuxName = generateLinuxPackageName(name);
530531
const desktopFileName = `com.pake.${linuxName}.desktop`;
531532
const iconName = `${linuxName}_512`;
@@ -549,13 +550,13 @@ Terminal=false
549550
await fsExtra.ensureDir(srcAssetsDir);
550551
await fsExtra.writeFile(srcDesktopFilePath, desktopContent);
551552
const desktopInstallPath = `/usr/share/applications/${desktopFileName}`;
552-
tauriConf.bundle.linux.deb.files = {
553+
linuxBundle.deb.files = {
553554
[desktopInstallPath]: `assets/${desktopFileName}`,
554555
};
555-
if (!tauriConf.bundle.linux.rpm) {
556-
tauriConf.bundle.linux.rpm = {};
556+
if (!linuxBundle.rpm) {
557+
linuxBundle.rpm = {};
557558
}
558-
tauriConf.bundle.linux.rpm.files = {
559+
linuxBundle.rpm.files = {
559560
[desktopInstallPath]: `assets/${desktopFileName}`,
560561
};
561562
const validTargets = [

0 commit comments

Comments
 (0)