Skip to content

Commit 8f41ede

Browse files
authored
fix: install tauri-cli using cargo (#242)
* fix: install tauri-cli using cargo Signed-off-by: Soorya U <sooryau7@gmail.com> * chore: better error message and updated function name * change file --------- Signed-off-by: Soorya U <sooryau7@gmail.com>
1 parent a8eb631 commit 8f41ede

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

.changes/cargo-tauri-cli.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-vscode": patch
3+
---
4+
5+
Install `cargo tauri` if not installed.

src/extension.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ function runTauriInit(): void {
160160
let onInstall = () => {};
161161
if (__isVueCliApp(projectPath)) {
162162
installCommand = 'vue add tauri';
163-
} else {
163+
} else if (__isNodeProject(projectPath)) {
164164
installCommand = __usePnpm(projectPath)
165165
? 'pnpm add -D @tauri-apps/cli'
166166
: __useYarn(projectPath)
@@ -185,6 +185,8 @@ function runTauriInit(): void {
185185
noOutputWindow: true,
186186
});
187187
};
188+
} else {
189+
installCommand = 'cargo install tauri-cli';
188190
}
189191

190192
const [command, ...args] = installCommand.split(' ');
@@ -196,7 +198,7 @@ function runTauriInit(): void {
196198
() => {
197199
const paths = __getNpmProjectsPaths();
198200
return paths.filter((p) => {
199-
return !fs.existsSync(path.join(p, 'src-tauri'));
201+
return fs.existsSync(path.join(p, 'src-tauri'));
200202
});
201203
}
202204
);
@@ -225,6 +227,10 @@ function __isVueCliApp(cwd: string): boolean {
225227
return '@vue/cli-service' in (packageJson?.devDependencies ?? {});
226228
}
227229

230+
function __isNodeProject(cwd: string): boolean {
231+
return existsSync(join(cwd, 'package.json'));
232+
}
233+
228234
interface PackageJson {
229235
dependencies: {
230236
[name: string]: any;
@@ -418,7 +424,7 @@ function __getPackageManagerCommand(projectPath: string): string | null {
418424

419425
if (!m) {
420426
vscode.window.showErrorMessage(
421-
"Couldn't detect package manager for current project."
427+
"Couldn't detect package manager for current project. Try running Tauri: Init Command"
422428
);
423429
}
424430

0 commit comments

Comments
 (0)