fix: use npm exec instead of npm run if no tauri script can be detected (#1174)

This commit is contained in:
Fabian-Lars
2025-11-13 20:20:31 +01:00
committed by GitHub
parent af2966305d
commit 2e37e06369
4 changed files with 24 additions and 12 deletions
+5
View File
@@ -0,0 +1,5 @@
---
action: patch
---
Use `npm exec` instead of `npm run` if `@tauri-apps/cli` was detected with no `tauri` script in `package.json`.
+2 -2
View File
File diff suppressed because one or more lines are too long
+7 -10
View File
@@ -1,6 +1,7 @@
import {
execCommand,
hasDependency,
hasTauriScript,
retry,
usesBun,
usesPnpm,
@@ -25,15 +26,7 @@ class Runner {
env?: Record<string, string>,
retryAttempts: number = 0,
): Promise<void> {
const args: string[] = [];
if (this.bin === 'npm' && this.tauriScript[0] !== 'run') {
args.push('run');
}
args.push(...this.tauriScript);
args.push(...command);
const args = [...this.tauriScript, ...command];
if (this.bin === 'npm' && commandOptions.length) {
args.push('--');
@@ -62,9 +55,13 @@ async function getRunner(
if (usesYarn(root)) return new Runner('yarn', ['tauri']);
if (usesPnpm(root)) return new Runner('pnpm', ['tauri']);
if (usesBun(root)) return new Runner('bun', ['tauri']);
return new Runner('npm', ['run', 'tauri']);
return new Runner('npm', [hasTauriScript(root) ? 'run' : 'exec', 'tauri']);
}
console.warn(
'Could not detect `@tauri-apps/cli` installation. Proceeding to install global npm package...',
);
await execCommand('npm', ['install', '-g', `@tauri-apps/cli@v2`], {
cwd: undefined,
});
+10
View File
@@ -345,6 +345,16 @@ export function hasDependency(dependencyName: string, root: string): boolean {
);
}
export function hasTauriScript(root: string): boolean {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const packageJson = getPackageJson(root);
return (
!!packageJson &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
!!packageJson.scripts?.['tauri']
);
}
export function usesYarn(root: string): boolean {
return existsSync(join(root, 'yarn.lock'));
}