Skip to content

Commit f575715

Browse files
authored
feat: Install tauri cli depending on tauri config version (#929)
* feat: Install tauri cli depending on tauri config version * lint * rm cli from packagejson * v2
1 parent 7ea2a14 commit f575715

File tree

8 files changed

+46
-150
lines changed

8 files changed

+46
-150
lines changed

.changes/feat-cli-version.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
action: patch
3+
---
4+
5+
The action will now try to check for the tauri version before installing the tauri cli fallback (if no tauri cli was found) instead of always installing the latest stable version.

.github/fixtures/example-with-tauri-v1/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,5 @@
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
99
"author": "",
10-
"license": "MIT",
11-
"dependencies": {
12-
"@tauri-apps/cli": "^1.5.6"
13-
}
10+
"license": "MIT"
1411
}

.github/fixtures/example-with-tauri-v1/pnpm-lock.yaml

Lines changed: 0 additions & 125 deletions
This file was deleted.

.github/fixtures/example-with-tauri-v2/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,5 @@
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
99
"author": "",
10-
"license": "MIT",
11-
"dependencies": {
12-
"@tauri-apps/cli": "next"
13-
}
10+
"license": "MIT"
1411
}

.github/workflows/test-action.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ jobs:
3636
node-version: lts/*
3737
cache: pnpm
3838

39-
# TODO: test the auto installation of the tauri cli
4039
- name: install example dependencies
4140
run: |
4241
cd ./.github/fixtures/example-v1
4342
pnpm install
44-
cd ../example-with-tauri-v1
45-
pnpm install
43+
# Testing cli fallback install
44+
# cd ../example-with-tauri-v1
45+
# pnpm install
4646

4747
# rust
4848
- name: install Rust stable
@@ -129,13 +129,13 @@ jobs:
129129
node-version: lts/*
130130
cache: pnpm
131131

132-
# TODO: test the auto installation of the tauri cli
133132
- name: install example dependencies
134133
run: |
135134
cd ./.github/fixtures/example-v2
136135
pnpm install
137-
cd ../example-with-tauri-v2
138-
pnpm install
136+
# Testing cli fallback install
137+
# cd ../example-with-tauri-v2
138+
# pnpm install
139139

140140
# rust
141141
- name: install Rust stable

dist/index.js

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ export class TauriConfig {
132132
this._isV2 = isV2;
133133
}
134134

135+
public isV2(): boolean {
136+
return this._isV2;
137+
}
138+
135139
public static fromBaseConfig(tauriDir: string): TauriConfig {
136140
if (existsSync(join(tauriDir, 'tauri.conf.json'))) {
137141
const contents = readFileSync(

src/runner.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { TauriConfig } from './config';
12
import {
23
execCommand,
4+
getTauriDir,
35
hasDependency,
46
usesBun,
57
usesPnpm,
@@ -59,7 +61,23 @@ async function getRunner(
5961
return new Runner('npm', ['run', 'tauri']);
6062
}
6163

62-
await execCommand('npm', ['install', '-g', '@tauri-apps/cli'], {
64+
// TODO: Change to v2 after a while.
65+
let tag = 'v1';
66+
67+
try {
68+
const tauriDir = getTauriDir(root);
69+
if (tauriDir) {
70+
const baseConf = TauriConfig.fromBaseConfig(tauriDir);
71+
72+
if (baseConf && baseConf.isV2()) {
73+
tag = 'v2';
74+
}
75+
}
76+
} catch {
77+
// ignore
78+
}
79+
80+
await execCommand('npm', ['install', '-g', `@tauri-apps/cli@${tag}`], {
6381
cwd: undefined,
6482
});
6583

0 commit comments

Comments
 (0)