Skip to content

Commit

Permalink
feat: Install tauri cli depending on tauri config version (#929)
Browse files Browse the repository at this point in the history
* feat: Install tauri cli depending on tauri config version

* lint

* rm cli from packagejson

* v2
  • Loading branch information
FabianLars authored Oct 2, 2024
1 parent 7ea2a14 commit f575715
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 150 deletions.
5 changes: 5 additions & 0 deletions .changes/feat-cli-version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
action: patch
---

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.
5 changes: 1 addition & 4 deletions .github/fixtures/example-with-tauri-v1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"@tauri-apps/cli": "^1.5.6"
}
"license": "MIT"
}
125 changes: 0 additions & 125 deletions .github/fixtures/example-with-tauri-v1/pnpm-lock.yaml

This file was deleted.

5 changes: 1 addition & 4 deletions .github/fixtures/example-with-tauri-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"@tauri-apps/cli": "next"
}
"license": "MIT"
}
12 changes: 6 additions & 6 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ jobs:
node-version: lts/*
cache: pnpm

# TODO: test the auto installation of the tauri cli
- name: install example dependencies
run: |
cd ./.github/fixtures/example-v1
pnpm install
cd ../example-with-tauri-v1
pnpm install
# Testing cli fallback install
# cd ../example-with-tauri-v1
# pnpm install

# rust
- name: install Rust stable
Expand Down Expand Up @@ -129,13 +129,13 @@ jobs:
node-version: lts/*
cache: pnpm

# TODO: test the auto installation of the tauri cli
- name: install example dependencies
run: |
cd ./.github/fixtures/example-v2
pnpm install
cd ../example-with-tauri-v2
pnpm install
# Testing cli fallback install
# cd ../example-with-tauri-v2
# pnpm install

# rust
- name: install Rust stable
Expand Down
20 changes: 10 additions & 10 deletions dist/index.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ export class TauriConfig {
this._isV2 = isV2;
}

public isV2(): boolean {
return this._isV2;
}

public static fromBaseConfig(tauriDir: string): TauriConfig {
if (existsSync(join(tauriDir, 'tauri.conf.json'))) {
const contents = readFileSync(
Expand Down
20 changes: 19 additions & 1 deletion src/runner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { TauriConfig } from './config';
import {
execCommand,
getTauriDir,
hasDependency,
usesBun,
usesPnpm,
Expand Down Expand Up @@ -59,7 +61,23 @@ async function getRunner(
return new Runner('npm', ['run', 'tauri']);
}

await execCommand('npm', ['install', '-g', '@tauri-apps/cli'], {
// TODO: Change to v2 after a while.
let tag = 'v1';

try {
const tauriDir = getTauriDir(root);
if (tauriDir) {
const baseConf = TauriConfig.fromBaseConfig(tauriDir);

if (baseConf && baseConf.isV2()) {
tag = 'v2';
}
}
} catch {
// ignore
}

await execCommand('npm', ['install', '-g', `@tauri-apps/cli@${tag}`], {
cwd: undefined,
});

Expand Down

0 comments on commit f575715

Please sign in to comment.