diff --git a/.changes/fix-cargo.md b/.changes/fix-cargo.md new file mode 100644 index 00000000..c430232c --- /dev/null +++ b/.changes/fix-cargo.md @@ -0,0 +1,5 @@ +--- +'tauri-vscode': patch +--- + +Fix extension trying to use npm instead of cargo. \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index 651cb0b9..d8cbe373 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -413,23 +413,30 @@ function __getNpmCommand() { } function __getPackageManagerCommand(projectPath: string): string | null { - const m = __usePnpm(projectPath) - ? 'pnpm' - : __useYarn(projectPath) - ? 'yarn' - : __useNpm(projectPath) - ? __getNpmCommand() - : __useCargo() - ? 'cargo' - : null - - if (!m) { - vscode.window.showErrorMessage( - "Couldn't detect package manager for current project. Try running Tauri: Init Command" + const isNodeProject = __isNodeProject(projectPath) + if (isNodeProject) { + if (__usePnpm(projectPath)) return 'pnpm' + if (__useYarn(projectPath)) return 'yarn' + + const packageJson = JSON.parse( + fs.readFileSync(`${projectPath}/package.json`, 'utf8') + ) + + if ( + __useNpm(projectPath) && + packageJson.script && + packageJson.script['tauri'] ) + return __getNpmCommand() } - return m + if (__useCargo()) return 'cargo' + + vscode.window.showErrorMessage( + "Couldn't detect package manager for current project. Try running Tauri: Init Command" + ) + + return null } interface RunOptions {